Skip to content

Commit 6e3e9af

Browse files
committed
Add examples. GraphicalMeter,DualSensor
1 parent f1675b9 commit 6e3e9af

23 files changed

+1441
-5
lines changed

.github/workflows/arduino-esp-v2-build-check.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ jobs:
8080
archi:
8181
- esp32
8282

83+
include:
84+
# Specific sketches
85+
- sketch: GraphicalMeter
86+
unit: UnitHeart
87+
platform-url: https://espressif.github.io/arduino-esp32/package_esp32_index.json
88+
platform: esp32
89+
archi: esp32
90+
platform-version: 3.0.4
91+
board: m5stack-core-esp32
92+
93+
8394
steps:
8495
- name: Checkout
8596
uses: actions/checkout@v4

.github/workflows/arduino-esp-v3-build-check.yml

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ jobs:
9898
- esp32
9999

100100
include:
101-
# Specific sketches for sticks only
101+
# Specific sketches
102102
- sketch: PlotToSerial
103103
unit: HatHeart
104104
platform-url: https://espressif.github.io/arduino-esp32/package_esp32_index.json
@@ -113,6 +113,39 @@ jobs:
113113
archi: esp32
114114
platform-version: 3.0.4
115115
board: m5stack_stickc_plus2
116+
- sketch: GraphicalMeter
117+
unit:UnitHeart
118+
platform-url: https://espressif.github.io/arduino-esp32/package_esp32_index.json
119+
platform: esp32
120+
archi: esp32
121+
platform-version: 3.0.4
122+
board: m5stack_core
123+
- sketch: GraphicalMeter
124+
unit: HatHeart
125+
platform-url: https://espressif.github.io/arduino-esp32/package_esp32_index.json
126+
platform: esp32
127+
archi: esp32
128+
platform-version: 3.0.4
129+
board: m5stack_stickc_plus
130+
- sketch: GraphicalMeter
131+
unit: HatHeart
132+
platform-url: https://espressif.github.io/arduino-esp32/package_esp32_index.json
133+
platform: esp32
134+
archi: esp32
135+
platform-version: 3.0.4
136+
board: m5stack_stickc_plus2
137+
- sketch: DualSensor
138+
platform-url: https://espressif.github.io/arduino-esp32/package_esp32_index.json
139+
platform: esp32
140+
archi: esp32
141+
platform-version: 3.0.4
142+
board: m5stack_stickc_plus
143+
- sketch: DualSensor
144+
platform-url: https://espressif.github.io/arduino-esp32/package_esp32_index.json
145+
platform: esp32
146+
archi: esp32
147+
platform-version: 3.0.4
148+
board: m5stack_stickc_plus2
116149

117150
steps:
118151
- name: Checkout

.github/workflows/arduino-m5-build-check.yml

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ jobs:
9999
- esp32
100100

101101
include:
102-
# Specific sketches for sticks only
102+
# Specific sketches
103103
- sketch: PlotToSerial
104104
unit: HatHeart
105105
platform-url: https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/arduino/package_m5stack_index.json
@@ -114,6 +114,39 @@ jobs:
114114
archi: esp32
115115
platform-version: 2.1.2
116116
board: m5stack_stickc_plus2
117+
- sketch: GraphicalMeter
118+
unit: UnitHeart
119+
platform-url: https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/arduino/package_m5stack_index.json
120+
platform: esp32
121+
archi: esp32
122+
platform-version: 2.1.2
123+
board: m5stack_core
124+
- sketch: GraphicalMeter
125+
unit: HatHeart
126+
platform-url: https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/arduino/package_m5stack_index.json
127+
platform: esp32
128+
archi: esp32
129+
platform-version: 2.1.2
130+
board: m5stack_stickc_plus
131+
- sketch: GraphicalMeter
132+
unit: HatHeart
133+
platform-url: https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/arduino/package_m5stack_index.json
134+
platform: esp32
135+
archi: esp32
136+
platform-version: 2.1.2
137+
board: m5stack_stickc_plus2
138+
- sketch: DualSensor
139+
platform-url: https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/arduino/package_m5stack_index.json
140+
platform: esp32
141+
archi: esp32
142+
platform-version: 2.1.2
143+
board: m5stack_stickc_plus
144+
- sketch: DualSensor
145+
platform-url: https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/arduino/package_m5stack_index.json
146+
platform: esp32
147+
archi: esp32
148+
platform-version: 2.1.2
149+
board: m5stack_stickc_plus2
117150

118151
steps:
119152
- name: Checkout

.github/workflows/platformio-build-check.yml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ jobs:
113113
# espressif32: '4_4_0'
114114

115115
include:
116-
# Specific sketches for sticks only
116+
# Specific sketches
117117
- example: PlotToSerial
118118
unit: HatHeart
119119
board: StickCPlus
@@ -124,6 +124,29 @@ jobs:
124124
board: StickCPlus2
125125
framework: Arduino
126126
espressif32: latest
127+
- example: GraphicalMeter
128+
unit: UnitHeart
129+
board: Core
130+
framework: Arduino
131+
espressif32: latest
132+
- example: GraphicalMeter
133+
unit: HatHeart
134+
board: StickCPlus
135+
framework: Arduino
136+
espressif32: latest
137+
- example: GraphicalMeter
138+
unit: HatHeart
139+
board: StickCPlus2
140+
framework: Arduino
141+
espressif32: latest
142+
- example: DualSensor
143+
board: StickCPlus
144+
framework: Arduino
145+
espressif32: latest
146+
- example: DualSensor
147+
board: StickCPlus2
148+
framework: Arduino
149+
espressif32: latest
127150

128151

129152
steps:
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*/
6+
/*
7+
Example of using M5UnitUnified to connect both UnitHeart and HatHeart
8+
*/
9+
#include "main/DualSensor.cpp"
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*/
6+
/*
7+
Example of using M5UnitUnified to connect both UnitHeart and HatHeart
8+
*/
9+
#include <M5Unified.h>
10+
#include <M5UnitUnified.h>
11+
#include <M5UnitUnifiedHEART.h>
12+
#include <Wire.h>
13+
#include "../src/view.hpp"
14+
15+
namespace {
16+
auto& lcd = M5.Display;
17+
m5::unit::UnitUnified Units;
18+
m5::unit::UnitHeart unit;
19+
m5::unit::HatHeart hat;
20+
21+
View* view[2]{};
22+
23+
} // namespace
24+
25+
using namespace m5::unit::max30102;
26+
27+
void setup()
28+
{
29+
// Configuration for using Wire1
30+
auto m5cfg = M5.config();
31+
m5cfg.pmic_button = false; // Disable BtnPWR
32+
m5cfg.internal_imu = false; // Disable internal IMU
33+
m5cfg.internal_rtc = false; // Disable internal RTC
34+
M5.begin(m5cfg);
35+
36+
auto board = M5.getBoard();
37+
if (board != m5::board_t::board_M5StickCPlus && board != m5::board_t::board_M5StickCPlus2) {
38+
M5_LOGE("Example for StickCPlus/CPlus2");
39+
lcd.clear(TFT_RED);
40+
while (true) {
41+
m5::utility::delay(10000);
42+
}
43+
}
44+
45+
// The screen shall be in landscape mode
46+
if (lcd.height() > lcd.width()) {
47+
lcd.setRotation(1);
48+
}
49+
50+
// Setup required to use HatHEART
51+
pinMode(25, INPUT_PULLUP);
52+
pinMode(26, OUTPUT);
53+
54+
// Wire settings
55+
auto pin_num_sda = M5.getPin(m5::pin_name_t::port_a_sda);
56+
auto pin_num_scl = M5.getPin(m5::pin_name_t::port_a_scl);
57+
Wire.end();
58+
Wire.begin(pin_num_sda, pin_num_scl, 400 * 1000U);
59+
60+
Wire1.end();
61+
Wire1.begin(0, 26, 400 * 1000U);
62+
63+
// UnitHeart connected to GROOVE with Wire
64+
// HatHeart connected to PIN sockect with Wire1
65+
if (!Units.add(unit, Wire) || !Units.add(hat, Wire1) || !Units.begin()) {
66+
M5_LOGE("Failed to begin");
67+
lcd.clear(TFT_RED);
68+
while (true) {
69+
m5::utility::delay(10000);
70+
}
71+
}
72+
73+
M5_LOGI("M5UnitUnified has been begun");
74+
M5_LOGI("%s", Units.debugInfo().c_str());
75+
76+
lcd.startWrite();
77+
78+
view[0] = new View(lcd.width() >> 1, lcd.height(), true);
79+
view[1] = new View(lcd.width() >> 1, lcd.height(), false);
80+
view[0]->_monitor.setSamplingRate(unit.caluculateSamplingRate());
81+
view[1]->_monitor.setSamplingRate(hat.caluculateSamplingRate());
82+
view[0]->push(&lcd, lcd.width() >> 1, 0);
83+
view[1]->push(&lcd, 0, 0);
84+
}
85+
86+
void loop()
87+
{
88+
M5.update();
89+
Units.update();
90+
91+
if (unit.updated()) {
92+
if (unit.overflow()) {
93+
M5_LOGW("OVERFLOW U:%u", unit.overflow());
94+
}
95+
while (unit.available()) {
96+
view[0]->push_back(unit.ir(), unit.red());
97+
view[0]->update();
98+
unit.discard();
99+
}
100+
view[0]->render();
101+
view[0]->push(&lcd, lcd.width() >> 1, 0);
102+
}
103+
104+
if (hat.updated()) {
105+
if (hat.overflow()) {
106+
M5_LOGW("OVERFLOW H:%u", hat.overflow());
107+
}
108+
while (hat.available()) {
109+
view[1]->push_back(hat.ir(), hat.red());
110+
view[1]->update();
111+
hat.discard();
112+
}
113+
view[1]->render();
114+
view[1]->push(&lcd, 0, 0);
115+
}
116+
117+
if (M5.BtnA.wasClicked()) {
118+
view[0]->clear();
119+
view[1]->clear();
120+
}
121+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*/
6+
#ifndef M5_UNIT_HEART_EXAMPLE_METER_HPP
7+
#define M5_UNIT_HEART_EXAMPLE_METER_HPP
8+
9+
#include <M5GFX.h>
10+
#include "ui_plotter.hpp"
11+
#include <m5_utility/log/library_log.hpp>
12+
13+
class Meter {
14+
public:
15+
Meter(const uint32_t left, const uint32_t top, const uint32_t wid, const uint32_t hgt, m5gfx::rgb565_t tcolor)
16+
: _left(left), _top(top), _theme_color(tcolor)
17+
{
18+
_plotter = new m5::ui::Plotter(nullptr, wid, wid, hgt);
19+
_plotter->setGaugeTextDatum(textdatum_t::top_right);
20+
_plotter->setLineColor(_theme_color);
21+
}
22+
23+
inline void push_back(const float value)
24+
{
25+
_plotter->push_back(value);
26+
}
27+
28+
inline void push(LovyanGFX* target, const uint32_t x, const uint32_t y)
29+
{
30+
_plotter->push(target, _left, _top);
31+
}
32+
33+
inline void clear()
34+
{
35+
_plotter->clear();
36+
}
37+
38+
private:
39+
uint32_t _left{}, _top{};
40+
m5::ui::Plotter* _plotter{};
41+
m5gfx::rgb565_t _theme_color{};
42+
};
43+
#endif

0 commit comments

Comments
 (0)