Skip to content

Commit

Permalink
Rename headers
Browse files Browse the repository at this point in the history
  • Loading branch information
GOB52 committed Aug 20, 2024
1 parent 7c0e82a commit 04cc48d
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 48 deletions.
50 changes: 39 additions & 11 deletions .github/workflows/clang-format-check.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,51 @@
name: clang-format Check
on: [push, pull_request]

env:
INCLUDE_REGEX: ^.*\.((((c|C)(c|pp|xx|\+\+)?$)|((h|H)h?(pp|xx|\+\+)?$))|(inl|ino|pde|proto|cu))$

on:
push:
paths:
- '**.ino'
- '**.cpp'
- '**.hpp'
- '**.h'
- '**.c'
- '**.inl'
- '**clang-format-check.yml'
pull_request:
- '**.ino'
- '**.cpp'
- '**.hpp'
- '**.h'
- '**.c'
- '**.inl'
- '**clang-format-check.yml'

jobs:
formatting-check:
name: Formatting Check
runs-on: ubuntu-latest
strategy:
matrix:
path:
#- check: './' # path to include
# exclude: '' # path to exclude
- check: 'src'
exclude: ''
- check: 'test'
exclude: ''
- check: 'examples'
exclude: ''
# exclude: '(Fonts)' # Exclude file paths containing "Fonts"

steps:
- uses: actions/[email protected]
- name: Run clang-format style check for C/C++/Protobuf programs.
uses: jidicula/[email protected]
with:
clang-format-version: '13'
check-path: ${{ matrix.path['check'] }}
exclude-regex: ${{ matrix.path['exclude'] }}
- name: Checkout # When pull_request is used, include it in the checkout https://zenn.dev/hkusu/articles/c731862051438b
uses: actions/[email protected]
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Run clang-format style check for C/C++/Protobuf programs.
uses: jidicula/[email protected] # Using include-regex 10.x or later
with:
clang-format-version: '13'
check-path: ${{ matrix.path['check'] }}
exclude-regex: ${{ matrix.path['exclude'] }}
include-regex: ${{ env.INCLUDE_REGEX }}
26 changes: 13 additions & 13 deletions examples/UnitUnified/UnitHeart/UnitHeart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include <M5Unified.h>
#include <M5UnitUnified.h>
#include <unit/unit_MAX30100.hpp>
#include <M5UnitUnifiedHEART.h>
#include <utility/heart_rate.hpp>
#if !defined(USING_M5HAL)
#include <Wire.h>
Expand All @@ -20,7 +20,7 @@
namespace {
auto& lcd = M5.Display;
m5::unit::UnitUnified Units;
m5::unit::UnitMAX30100 unitMAX30100;
m5::unit::UnitHEART unitHeart;
m5::max30100::HeartRate heartRate(100);

uint32_t getSamplingRate(const m5::unit::max30100::Sampling rate) {
Expand All @@ -35,14 +35,14 @@ void setup() {

// Another settings
if (0) {
auto cfg = unitMAX30100.config();
auto cfg = unitHeart.config();
cfg.samplingRate = m5::unit::max30100::Sampling::Rate400;
cfg.pulseWidth = m5::unit::max30100::LedPulseWidth::PW400;
cfg.irCurrent = m5::unit::max30100::CurrentControl::mA7_6;
cfg.redCurrent = m5::unit::max30100::CurrentControl::mA7_6;
heartRate.setSamplingRate(getSamplingRate(cfg.samplingRate));
heartRate.setThreshold(25.0f); // depends on ir/redCurrent
unitMAX30100.config(cfg);
unitHeart.config(cfg);
}

auto pin_num_sda = M5.getPin(m5::pin_name_t::port_a_sda);
Expand All @@ -57,7 +57,7 @@ void setup() {
i2c_cfg.pin_scl = m5::hal::gpio::getPin(pin_num_scl);
auto i2c_bus = m5::hal::bus::i2c::getBus(i2c_cfg);
M5_LOGI("Bus:%d", i2c_bus.has_value());
if (!Units.add(unitMAX30100, i2c_bus ? i2c_bus.value() : nullptr) || !Units.begin()) {
if (!Units.add(unitHeart, i2c_bus ? i2c_bus.value() : nullptr) || !Units.begin()) {
M5_LOGE("Failed to begin");
lcd.clear(TFT_RED);
while (true) {
Expand All @@ -68,7 +68,7 @@ void setup() {
#pragma message "Using Wire"
// Using TwoWire
Wire.begin(pin_num_sda, pin_num_scl, 400000U);
if (!Units.add(unitMAX30100, Wire) || !Units.begin()) {
if (!Units.add(unitHeart, Wire) || !Units.begin()) {
M5_LOGE("Failed to begin");
lcd.clear(TFT_RED);
while (true) {
Expand All @@ -86,16 +86,16 @@ void setup() {
void loop() {
M5.update();
Units.update();
if (unitMAX30100.updated()) {
while (unitMAX30100.available()) {
// M5_LOGI("\n>IR:%u\n>RED:%u", unitMAX30100.ir(),
// unitMAX30100.red());
bool beat = heartRate.push_back((float)unitMAX30100.ir(), (float)unitMAX30100.red());
if (unitHeart.updated()) {
while (unitHeart.available()) {
// M5_LOGI("\n>IR:%u\n>RED:%u", unitHeart.ir(),
// unitHeart.red());
bool beat = heartRate.push_back((float)unitHeart.ir(), (float)unitHeart.red());
if (beat) {
M5_LOGI("Beat!");
}

unitMAX30100.discard();
unitHeart.discard();
}
auto bpm = heartRate.calculate();
M5_LOGW("\n>HRR:%f\n>SpO2:%f", bpm, heartRate.SpO2());
Expand All @@ -105,7 +105,7 @@ void loop() {
if (M5.BtnA.wasClicked()) {
heartRate.clear();
m5::unit::max30100::TemperatureData td{};
if (unitMAX30100.measureTemperatureSingleshot(td)) {
if (unitHeart.measureTemperatureSingleshot(td)) {
M5_LOGI("\n>Temp:%f", td.celsius());
}
}
Expand Down
16 changes: 0 additions & 16 deletions src/M5UnitHEART.h

This file was deleted.

16 changes: 16 additions & 0 deletions src/M5UnitUnifiedHEART.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
*
* SPDX-License-Identifier: MIT
*/
/*!
@file M5UnitHEART.h
*/
#ifndef M5_UNIT_UNIFIED_HEART_H
#define M5_UNIT_UNIFIED_HEART_H
#ifdef __cplusplus
#include "M5UnitUnifiedHEART.hpp"
#else
#error M5UnitUnifiedHEART requires a C++ compiler, please change file extension to .cc or .cpp
#endif
#endif
15 changes: 9 additions & 6 deletions src/M5UnitHEART.hpp → src/M5UnitUnifiedHEART.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
* SPDX-License-Identifier: MIT
*/
/*!
@file M5UnitHEART.hpp
@brief Main header of M5UnitHEART
@file M5UnitUnifiedHEART.hpp
@brief Main header of M5UnitUnifiedHEART
@mainpage M5UnitHEART
@mainpage M5Unit-HEART
Library for UnitHEART using M5UnitUnified.
*/
#ifndef M5_UNIT_HEART_HPP
#define M5_UNIT_HEART_HPP

#include "unit/unit_Ameter.hpp"
#include "unit/unit_Vmeter.hpp"
#include "unit/unit_MAX30100.hpp"

/*!
@namespace m5
Expand All @@ -26,7 +25,11 @@ namespace m5 {
@namespace unit
@brief Unit-related namespace
*/
namespace unit {} // namespace unit
namespace unit {

using UnitHEART = m5::unit::UnitMAX30100;

} // namespace unit
} // namespace m5

#endif
4 changes: 2 additions & 2 deletions src/unit/unit_MAX30100.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#define M5_UNIT_HEART_UNIT_MAX30100_HPP

#include <M5UnitComponent.hpp>
#include "m5_utility/stl/extension.hpp"
#include "m5_utility/container/circular_buffer.hpp"
#include <m5_utility/stl/extension.hpp>
#include <m5_utility/container/circular_buffer.hpp>
#include <limits> // NaN

namespace m5 {
Expand Down

0 comments on commit 04cc48d

Please sign in to comment.