From 51d04ed742010cbe2057ee01d77d894324d24557 Mon Sep 17 00:00:00 2001 From: GOB Date: Thu, 12 Dec 2024 23:37:07 +0900 Subject: [PATCH 1/7] Add GraphicalMeter example --- .../GraphicalMeter/GraphicalMeter.ino | 13 ++ .../GraphicalMeter/main/GraphicalMeter.cpp | 193 ++++++++++++++++++ .../UnitUnified/GraphicalMeter/main/meter.cpp | 83 ++++++++ .../UnitUnified/GraphicalMeter/main/meter.hpp | 16 ++ .../GraphicalMeter/main/ui_plotter.cpp | 137 +++++++++++++ .../GraphicalMeter/main/ui_plotter.hpp | 111 ++++++++++ platformio.ini | 23 +++ 7 files changed, 576 insertions(+) create mode 100644 examples/UnitUnified/GraphicalMeter/GraphicalMeter.ino create mode 100644 examples/UnitUnified/GraphicalMeter/main/GraphicalMeter.cpp create mode 100644 examples/UnitUnified/GraphicalMeter/main/meter.cpp create mode 100644 examples/UnitUnified/GraphicalMeter/main/meter.hpp create mode 100644 examples/UnitUnified/GraphicalMeter/main/ui_plotter.cpp create mode 100644 examples/UnitUnified/GraphicalMeter/main/ui_plotter.hpp diff --git a/examples/UnitUnified/GraphicalMeter/GraphicalMeter.ino b/examples/UnitUnified/GraphicalMeter/GraphicalMeter.ino new file mode 100644 index 0000000..f8e5b3d --- /dev/null +++ b/examples/UnitUnified/GraphicalMeter/GraphicalMeter.ino @@ -0,0 +1,13 @@ +/* + * SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD + * + * SPDX-License-Identifier: MIT + */ +/* + Graphical meter example for Unit-AnyMeter + The core must be equipped with LCD +*/ +#include "main/GraphicalMeter.cpp" + + + diff --git a/examples/UnitUnified/GraphicalMeter/main/GraphicalMeter.cpp b/examples/UnitUnified/GraphicalMeter/main/GraphicalMeter.cpp new file mode 100644 index 0000000..a518148 --- /dev/null +++ b/examples/UnitUnified/GraphicalMeter/main/GraphicalMeter.cpp @@ -0,0 +1,193 @@ +/* + * SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD + * + * SPDX-License-Identifier: MIT + */ +/* + Graphical meter example for Unit-Meter + + The core must be equipped with LCD + Ameter,Vmeter,or KmeterISO unit must be connected +*/ +#include +#include +#include +#include +#include "meter.hpp" +#include + +// ******************************************************************************** +// *** Select the unit (override this source or specify in the compile options) *** +// ******************************************************************************** +#if !defined(USING_VMETER) && !defined(USING_AMETER) && !defined(USING_KMETER_ISO) +#define USING_VMETER +// #define USING_AMETER +// #define USING_KMETER_ISO +#endif + +namespace { +auto& lcd = M5.Display; +LGFX_Sprite strips[2]; +constexpr uint32_t SPLIT_NUM{4}; +int32_t strip_height{}; + +m5::unit::UnitUnified Units; +#if defined(USING_VMETER) +#pragma message "Using Vmeter" +m5::unit::UnitVmeter unit{}; +constexpr char tag[] = "Voltage"; +constexpr char val_unit[] = "V"; +constexpr m5gfx::rgb565_t theme_clr{45, 136, 218}; +#elif defined(USING_AMETER) +#pragma message "Using Ameter" +m5::unit::UnitAmeter unit{}; +constexpr char tag[] = "Current"; +constexpr char val_unit[] = "A"; +constexpr m5gfx::rgb565_t theme_clr{254, 79, 147}; +#elif defined(USING_KMETER_ISO) +m5::unit::UnitKmeterISO unit{}; +#pragma message "Using KmeterISO" +constexpr char tag[] = "Temp"; +constexpr char val_unit[] = "C"; +constexpr m5gfx::rgb565_t theme_clr{241, 188, 105}; +#else +#error "Choose unit" +#endif + +volatile SemaphoreHandle_t _updateLock{}; + +void update_meter(void*) +{ + for (;;) { + Units.update(); + if (xSemaphoreTake(_updateLock, 1)) { + while (unit.available()) { +#if defined(USING_VMETER) + store_value(unit.voltage()); +#elif defined(USING_AMETER) + store_value(unit.current()); +#elif defined(USING_KMETER_ISO) + store_value(unit.temperature()); +#else +#error "Choose unit" +#endif + unit.discard(); + } + xSemaphoreGive(_updateLock); + } + } +} + +} // namespace + +void setup() +{ + M5.begin(); + + // No LCD or display device? + if (lcd.width() == 0 || lcd.isEPD()) { + M5_LOGE("The core must be equipped with LCD"); + M5.Speaker.tone(1000, 20); + while (true) { + m5::utility::delay(10000); + } + } + + // The screen shall be in landscape mode + if (lcd.height() > lcd.width()) { + lcd.setRotation(1); + } + + // Make strips + strip_height = (lcd.height() + SPLIT_NUM - 1) / SPLIT_NUM; + uint32_t cnt{}; + for (auto&& spr : strips) { + spr.setPsram(false); + spr.setColorDepth(lcd.getColorDepth()); + cnt += spr.createSprite(lcd.width(), strip_height) ? 1 : 0; + spr.setAddrWindow(0, 0, lcd.width(), strip_height); + } + assert(cnt == 2 && "Failed to create sprite"); + + // UnitUnified + auto pin_num_sda = M5.getPin(m5::pin_name_t::port_a_sda); + auto pin_num_scl = M5.getPin(m5::pin_name_t::port_a_scl); + M5_LOGI("getPin: SDA:%u SCL:%u", pin_num_sda, pin_num_scl); + + auto cfg = unit.config(); +#if defined(USING_VMETER) || defined(USING_AMETER) + cfg.rate = m5::unit::ads111x::Sampling::Rate250; +#elif defined(USING_KMETER_ISO) + cfg.interval = 1000 / 250; +#else +#error "Choose unit" +#endif + unit.config(cfg); + auto ccfg = unit.component_config(); + ccfg.stored_size = 250; + unit.component_config(ccfg); + + Wire.begin(pin_num_sda, pin_num_scl, 400000U); + if (!Units.add(unit, Wire) || !Units.begin()) { + M5_LOGE("Failed to begin"); + lcd.clear(TFT_RED); + while (true) { + m5::utility::delay(10000); + } + } + + M5_LOGI("M5UnitUnified has been begun"); + M5_LOGI("%s", Units.debugInfo().c_str()); + + initialize_meter(lcd.width(), lcd.height(), lcd.width(), theme_clr); + + lcd.setAddrWindow(0, 0, lcd.width(), lcd.height()); + lcd.startWrite(); + + _updateLock = xSemaphoreCreateBinary(); + xSemaphoreGive(_updateLock); + xTaskCreateUniversal(update_meter, "meter", 8192, nullptr, 2, nullptr, APP_CPU_NUM); +} + +void loop() +{ +#if 0 + static uint32_t fpsCnt{}, fps{}; + static unsigned long start_at{m5::utility::millis()}; + + auto now = m5::utility::millis(); + if (now >= start_at + 1000) { + fps = fpsCnt; + M5_LOGW("loop FPS:%u", fps); + fpsCnt = 0; + start_at = now; + } +#endif + + M5.update(); + + // Draw strips with DMA transfer + while (lcd.dmaBusy()) { + m5::utility::delay(1); + } + + do { + if (xSemaphoreTake(_updateLock, 0)) { + //++fpsCnt; + + static uint32_t current{}; + int32_t offset{}; + uint32_t cnt{SPLIT_NUM}; + while (cnt--) { + auto& spr = strips[current]; + spr.clear(); + draw_meter(spr, offset, tag, val_unit); + spr.pushSprite(&lcd, 0, -offset); + + current ^= 1; + offset -= strip_height; + } + xSemaphoreGive(_updateLock); + } + } while (!lcd.dmaBusy()); +} diff --git a/examples/UnitUnified/GraphicalMeter/main/meter.cpp b/examples/UnitUnified/GraphicalMeter/main/meter.cpp new file mode 100644 index 0000000..b84f5dd --- /dev/null +++ b/examples/UnitUnified/GraphicalMeter/main/meter.cpp @@ -0,0 +1,83 @@ +/* + * SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD + * + * SPDX-License-Identifier: MIT + */ +#include "meter.hpp" +#include "ui_plotter.hpp" +#include +#include + +class EMA { +public: + explicit EMA(float factor = 0.92f) : _alpha(factor) + { + } + + inline void clear() + { + _ema_value = std::numeric_limits::quiet_NaN(); + } + + inline float update(float new_value) + { + if (!std::isnan(_ema_value)) { + _ema_value = _alpha * new_value + (1.0f - _alpha) * _ema_value; + } else { + _ema_value = new_value; + } + return _ema_value; + } + +private: + float _alpha{0.92f}, _ema_value{std::numeric_limits::quiet_NaN()}; +}; + +namespace { +m5::ui::Plotter* plotter{}; +EMA ema{}; +m5gfx::rgb565_t theme_color{}; +} // namespace + +void initialize_meter(const uint32_t swid, const uint32_t shgt, const uint32_t elements, + const m5gfx::rgb565_t theme_clr) +{ + delete plotter; + + auto hgt = shgt - 32; + plotter = new m5::ui::Plotter(nullptr, elements, swid, hgt, 100); + plotter->setGaugeTextDatum(textdatum_t::top_right); + plotter->setLineColor(theme_clr); + ema.clear(); + theme_color = theme_clr; +} + +void store_value(const float val) +{ + plotter->push_back(ema.update(val)); + // plotter->push_back(val); +} + +void draw_meter(LGFX_Sprite& spr, const int32_t offset, const char* tag, const char* unit) +{ + plotter->push(&spr, 0, offset); + + int32_t x{}, y{plotter->height() + offset}; + int32_t wid{spr.width()}, hgt{32}; + auto f = spr.getFont(); + auto td = spr.getTextDatum(); + + spr.fillRect(x, y, wid, 4, theme_color); + + spr.setFont(wid >= 240 ? &fonts::FreeSansBold12pt7b : &fonts::FreeSansBold9pt7b); + + spr.setTextDatum(textdatum_t::middle_left); + spr.drawString(tag, x, y + 32 / 2); + + auto s = m5::utility::formatString("%.2f", 0.01f * plotter->latest()); + spr.setTextDatum(textdatum_t::middle_right); + spr.drawString(s.c_str(), x + wid, y + 32 / 2); + + spr.setTextDatum(td); + spr.setFont(f); +} diff --git a/examples/UnitUnified/GraphicalMeter/main/meter.hpp b/examples/UnitUnified/GraphicalMeter/main/meter.hpp new file mode 100644 index 0000000..f13381d --- /dev/null +++ b/examples/UnitUnified/GraphicalMeter/main/meter.hpp @@ -0,0 +1,16 @@ +/* + * SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD + * + * SPDX-License-Identifier: MIT + */ +#ifndef M5_UNIT_METER_EXAMPLE_GRAPHICAL_METER_METER_HPP +#define M5_UNIT_METER_EXAMPLE_GRAPHICAL_METER_METER_HPP + +#include + +void initialize_meter(const uint32_t swid, const uint32_t shgt, const uint32_t elements, + const m5gfx::rgb565_t theme_clr); +void store_value(const float val); +void draw_meter(LGFX_Sprite& spr, const int32_t offset, const char* tag = "", const char* unit = ""); + +#endif diff --git a/examples/UnitUnified/GraphicalMeter/main/ui_plotter.cpp b/examples/UnitUnified/GraphicalMeter/main/ui_plotter.cpp new file mode 100644 index 0000000..5d21eac --- /dev/null +++ b/examples/UnitUnified/GraphicalMeter/main/ui_plotter.cpp @@ -0,0 +1,137 @@ +/* + * SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD + * + * SPDX-License-Identifier: MIT + */ +/*! + @file ui_plotter.cpp + @brief Plotter + */ + +#include "ui_plotter.hpp" +#include + +namespace m5 { +namespace ui { + +Plotter::Plotter(LovyanGFX* parent, const size_t maxPlot, const int32_t wid, const int32_t hgt, + const int32_t coefficient) + : _parent(parent), _wid{wid}, _hgt{hgt}, _coefficient(coefficient), _data(maxPlot), _autoScale{true} +{ +} + +Plotter::Plotter(LovyanGFX* parent, const size_t maxPlot, const int32_t minimum, const int32_t maximum, + const int32_t wid, const int32_t hgt, const int32_t coefficient) + : _parent(parent), + _min{minimum}, + _max{maximum}, + _wid{wid}, + _hgt{hgt}, + _coefficient(coefficient), + _data(maxPlot), + _autoScale{false} +{ +} + +void Plotter::push_back(const float val) +{ + push_back((int32_t)(val * _coefficient)); +} + +void Plotter::push_back(const int32_t val) +{ + auto v = _autoScale ? val : std::min(std::max(val, _min), _max); + _data.push_back(v); + + if (_autoScale && _data.size() >= 2) { + auto it = std::minmax_element(_data.cbegin(), _data.cend()); + _min = *(it.first); + _max = *(it.second); + if (_min == _max) { + ++_max; + } + } +} + +void Plotter::push(LovyanGFX* dst, const int32_t x, const int32_t y) +{ + dst->setClipRect(x, y, width(), height()); + + // gauge + dst->drawFastHLine(x, y, _wid, _gaugeClr); + dst->drawFastHLine(x, y + (_hgt >> 1), _wid, _gaugeClr); + dst->drawFastHLine(x, y + (_hgt >> 2), _wid, _gaugeClr); + dst->drawFastHLine(x, y + (_hgt >> 2) * 3, _wid, _gaugeClr); + dst->drawFastHLine(x, y + _hgt - 1, _wid, _gaugeClr); + + if (_data.size() >= 2) { + auto it = _data.cbegin(); + auto itend = --_data.cend(); + auto sz = _data.size(); + const float range{_max > _min ? (float)_max - _min : 1.0f}; + const int32_t hh{_hgt - 1}; + int32_t left{x}; + + // plot latest + if (sz > _wid) { + auto cnt{sz - _wid}; + while (cnt--) { + ++it; // Bidirectional iterator, so only ++/-- is available. + } + } + if (sz < _wid) { + left += _wid - sz; + } + + while (it != itend && left < _wid) { + int32_t s{*it}, e{*(++it)}; + dst->drawLine(left, y + hh - hh * (s - _min) / range, left + 1, y + hh - hh * (e - _min) / range, + _lineClr); + ++left; + } + } + + // + auto pf = dst->getFont(); + auto ptd = dst->getTextDatum(); + dst->setFont(&fonts::Font2); + dst->setTextColor(TFT_WHITE); + + int32_t tx{x}; + switch (_tdatum & 0x03) { + case 1: // center + tx = x + (_wid >> 1); + break; + case 2: // right: + tx = x + _wid; + break; + default: + break; + } + textdatum_t td{}; + + auto s = m5::utility::formatString("%d%s", _min / _coefficient, _ustr ? _ustr : ""); + td = static_cast(m5::stl::to_underlying(_tdatum) | 8); // bottom_xxx + dst->setTextDatum(td); + dst->drawString(s.c_str(), tx, y + _hgt); + + if (_min != _max) { + auto s = m5::utility::formatString("%d%s", _max / _coefficient, _ustr ? _ustr : ""); + td = static_cast(m5::stl::to_underlying(_tdatum) | 0); // top_xxx + dst->setTextDatum(td); + dst->drawString(s.c_str(), tx, y); + if (_max - _min > 1) { + s = m5::utility::formatString("%d%s", (_min + ((_max - _min) >> 1)) / _coefficient, _ustr ? _ustr : ""); + td = static_cast(m5::stl::to_underlying(_tdatum) | 4); // middle_xxx + dst->setTextDatum(td); + dst->drawString(s.c_str(), tx, y + (_hgt >> 1)); + } + } + + dst->setTextDatum(ptd); + dst->setFont(pf); + dst->clearClipRect(); +} + +} // namespace ui +} // namespace m5 diff --git a/examples/UnitUnified/GraphicalMeter/main/ui_plotter.hpp b/examples/UnitUnified/GraphicalMeter/main/ui_plotter.hpp new file mode 100644 index 0000000..6970c13 --- /dev/null +++ b/examples/UnitUnified/GraphicalMeter/main/ui_plotter.hpp @@ -0,0 +1,111 @@ +/* + * SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD + * + * SPDX-License-Identifier: MIT + */ +#ifndef UI_PLOTTER_HPP +#define UI_PLOTTER_HPP +#include +#include + +namespace m5 { +namespace ui { + +class Plotter { +public: + Plotter(LovyanGFX* parent, const size_t maxPlot, const int32_t wid, const int32_t hgt, + const int32_t coefficient = 1); + Plotter(LovyanGFX* parent, const size_t maxPlot, const int32_t minimum, const int32_t maximum, const int32_t wid, + const int32_t hgt, const int32_t coefficient = 1); + ~Plotter() + { + } + + inline int32_t width() const + { + return _wid; + } + inline int32_t height() const + { + return _hgt; + } + inline int32_t minimum() const + { + return _min; + } + inline int32_t maximum() const + { + return _max; + } + inline uint32_t size() const + { + return _data.size(); + } + inline int32_t latest() const + { + return !_data.empty() ? *(--_data.cend()) : 0; + } + + template + void setLineColor(const T& clr) + { + _lineClr = clr; + } + template + void setGaugeColor(const T& clr) + { + _gaugeClr = clr; + } + template + void setBackgroundColor(const T& clr) + { + _bgClr = clr; + } + + inline void setUnitString(const char* s) + { + _ustr = s; + } + inline void setGaugeTextDatum(const textdatum_t datum) + { + _tdatum = static_cast(m5::stl::to_underlying(datum) & 0x03); // only horizon + } + + void push_back(const float val); + void push_back(const int32_t val); + + inline void push(const int32_t x, const int32_t y) + { + push(_parent, x, y); + } + virtual void push(LovyanGFX* dst, const int32_t x, const int32_t y); + +protected: + m5gfx::rgb565_t lineColor() const + { + return _lineClr; + } + m5gfx::rgb565_t gaugeColor() const + { + return _gaugeClr; + } + m5gfx::rgb565_t backgroundColor() const + { + return _bgClr; + } + +protected: +private: + LovyanGFX* _parent{}; + int32_t _min{}, _max{}, _wid{}, _hgt{}, _coefficient{}; + m5::container::CircularBuffer _data; + + m5gfx::rgb565_t _lineClr{TFT_WHITE}, _gaugeClr{TFT_DARKGRAY}, _bgClr{TFT_BLACK}; + textdatum_t _tdatum{textdatum_t::top_left}; + const char* _ustr{}; + bool _autoScale{}; +}; + +} // namespace ui +} // namespace m5 +#endif diff --git a/platformio.ini b/platformio.ini index 020c846..d17f62d 100644 --- a/platformio.ini +++ b/platformio.ini @@ -685,3 +685,26 @@ build_src_filter = +<*> -<.git/> -<.svn/> +<../examples/UnitUnified/UnitKmeterIS [env:UnitKmeterISO_PlotToSerial_Fire_Arduino_4_4_0] extends=Fire, option_release, arduino_4_4_0 build_src_filter = +<*> -<.git/> -<.svn/> +<../examples/UnitUnified/UnitKmeterISO/PlotToSerial> + +; +; For the following samples, please refer to PlotToSerial to create env for your own environment +; 以下のサンプルは、PlotToSerial を参考にして、自分の環境にあった env を作成してください +; +[env:GraphicalMeter_Vmeter_Core] +extends=Core, option_release, arduino_latest +build_flags = ${option_release.build_flags} + -DUSING_VMETER +build_src_filter = +<*> -<.git/> -<.svn/> +<../examples/UnitUnified/GraphicalMeter> + +[env:GraphicalMeter_Ameter_Core] +extends=Core, option_release, arduino_latest +build_flags = ${option_release.build_flags} + -DUSING_AMETER +build_src_filter = +<*> -<.git/> -<.svn/> +<../examples/UnitUnified/GraphicalMeter> + +[env:GraphicalMeter_KmeterISO_Core] +extends=Core, option_release, arduino_latest +build_flags = ${option_release.build_flags} + -DUSING_KMETER_ISO +build_src_filter = +<*> -<.git/> -<.svn/> +<../examples/UnitUnified/GraphicalMeter> + From 15872ed2312f117552ad48258d1f41761262c8da Mon Sep 17 00:00:00 2001 From: GOB Date: Thu, 12 Dec 2024 23:41:41 +0900 Subject: [PATCH 2/7] Cosmetic change --- examples/UnitUnified/GraphicalMeter/GraphicalMeter.ino | 3 --- examples/UnitUnified/GraphicalMeter/main/ui_plotter.cpp | 3 +-- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/examples/UnitUnified/GraphicalMeter/GraphicalMeter.ino b/examples/UnitUnified/GraphicalMeter/GraphicalMeter.ino index f8e5b3d..653d356 100644 --- a/examples/UnitUnified/GraphicalMeter/GraphicalMeter.ino +++ b/examples/UnitUnified/GraphicalMeter/GraphicalMeter.ino @@ -8,6 +8,3 @@ The core must be equipped with LCD */ #include "main/GraphicalMeter.cpp" - - - diff --git a/examples/UnitUnified/GraphicalMeter/main/ui_plotter.cpp b/examples/UnitUnified/GraphicalMeter/main/ui_plotter.cpp index 5d21eac..de25236 100644 --- a/examples/UnitUnified/GraphicalMeter/main/ui_plotter.cpp +++ b/examples/UnitUnified/GraphicalMeter/main/ui_plotter.cpp @@ -85,8 +85,7 @@ void Plotter::push(LovyanGFX* dst, const int32_t x, const int32_t y) while (it != itend && left < _wid) { int32_t s{*it}, e{*(++it)}; - dst->drawLine(left, y + hh - hh * (s - _min) / range, left + 1, y + hh - hh * (e - _min) / range, - _lineClr); + dst->drawLine(left, y + hh - hh * (s - _min) / range, left + 1, y + hh - hh * (e - _min) / range, _lineClr); ++left; } } From a82139bc26aab083eb7b6b9c995848532be61a26 Mon Sep 17 00:00:00 2001 From: GOB Date: Fri, 13 Dec 2024 14:19:34 +0900 Subject: [PATCH 3/7] Add GraphicalMeter complie check on core --- .github/workflows/arduino-esp-v2-build-check.yml | 9 +++++++++ .github/workflows/arduino-esp-v3-build-check.yml | 9 +++++++++ .github/workflows/arduino-m5-build-check.yml | 9 +++++++++ 3 files changed, 27 insertions(+) diff --git a/.github/workflows/arduino-esp-v2-build-check.yml b/.github/workflows/arduino-esp-v2-build-check.yml index 67584b4..bcdf828 100644 --- a/.github/workflows/arduino-esp-v2-build-check.yml +++ b/.github/workflows/arduino-esp-v2-build-check.yml @@ -82,6 +82,15 @@ jobs: archi: - esp32 + include: + # Specific sketches for m5stack-core-esp32 only + - sketch: GraphicalMeter + platform-url: https://espressif.github.io/arduino-esp32/package_esp32_index.json + platform: esp32 + archi: esp32 + platform-version: 2.0.17 + board: m5stack-core-esp32 + steps: - name: Checkout uses: actions/checkout@v4 diff --git a/.github/workflows/arduino-esp-v3-build-check.yml b/.github/workflows/arduino-esp-v3-build-check.yml index bcbdf3f..61d2e56 100644 --- a/.github/workflows/arduino-esp-v3-build-check.yml +++ b/.github/workflows/arduino-esp-v3-build-check.yml @@ -98,6 +98,15 @@ jobs: archi: - esp32 + include: + # Specific sketches for m5stack-core-esp32 only + - sketch: GraphicalMeter + platform-url: https://espressif.github.io/arduino-esp32/package_esp32_index.json + platform-version: 3.0.4 + platform: esp32 + archi: esp32 + board: m5stack_core + steps: - name: Checkout uses: actions/checkout@v4 diff --git a/.github/workflows/arduino-m5-build-check.yml b/.github/workflows/arduino-m5-build-check.yml index 9bd03ff..f958732 100644 --- a/.github/workflows/arduino-m5-build-check.yml +++ b/.github/workflows/arduino-m5-build-check.yml @@ -100,6 +100,15 @@ jobs: archi: - esp32 + include: + # Specific sketches for m5stack-core-esp32 only + - sketch: GraphicalMeter + platform-url: https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/arduino/package_m5stack_index.json + platform-version: 2.1.2 + platform: m5stack + archi: esp32 + board: m5stack_core + steps: - name: Checkout uses: actions/checkout@v4 From e6984344517d7b6271965eb5ef8dba62e97297f7 Mon Sep 17 00:00:00 2001 From: GOB Date: Fri, 13 Dec 2024 15:47:33 +0900 Subject: [PATCH 4/7] Fixes compiler error on ArduinoIDE --- examples/UnitUnified/GraphicalMeter/main/GraphicalMeter.cpp | 2 +- examples/UnitUnified/GraphicalMeter/{main => src}/meter.cpp | 0 examples/UnitUnified/GraphicalMeter/{main => src}/meter.hpp | 0 .../UnitUnified/GraphicalMeter/{main => src}/ui_plotter.cpp | 0 .../UnitUnified/GraphicalMeter/{main => src}/ui_plotter.hpp | 0 5 files changed, 1 insertion(+), 1 deletion(-) rename examples/UnitUnified/GraphicalMeter/{main => src}/meter.cpp (100%) rename examples/UnitUnified/GraphicalMeter/{main => src}/meter.hpp (100%) rename examples/UnitUnified/GraphicalMeter/{main => src}/ui_plotter.cpp (100%) rename examples/UnitUnified/GraphicalMeter/{main => src}/ui_plotter.hpp (100%) diff --git a/examples/UnitUnified/GraphicalMeter/main/GraphicalMeter.cpp b/examples/UnitUnified/GraphicalMeter/main/GraphicalMeter.cpp index a518148..072b84a 100644 --- a/examples/UnitUnified/GraphicalMeter/main/GraphicalMeter.cpp +++ b/examples/UnitUnified/GraphicalMeter/main/GraphicalMeter.cpp @@ -13,7 +13,7 @@ #include #include #include -#include "meter.hpp" +#include "../src/meter.hpp" #include // ******************************************************************************** diff --git a/examples/UnitUnified/GraphicalMeter/main/meter.cpp b/examples/UnitUnified/GraphicalMeter/src/meter.cpp similarity index 100% rename from examples/UnitUnified/GraphicalMeter/main/meter.cpp rename to examples/UnitUnified/GraphicalMeter/src/meter.cpp diff --git a/examples/UnitUnified/GraphicalMeter/main/meter.hpp b/examples/UnitUnified/GraphicalMeter/src/meter.hpp similarity index 100% rename from examples/UnitUnified/GraphicalMeter/main/meter.hpp rename to examples/UnitUnified/GraphicalMeter/src/meter.hpp diff --git a/examples/UnitUnified/GraphicalMeter/main/ui_plotter.cpp b/examples/UnitUnified/GraphicalMeter/src/ui_plotter.cpp similarity index 100% rename from examples/UnitUnified/GraphicalMeter/main/ui_plotter.cpp rename to examples/UnitUnified/GraphicalMeter/src/ui_plotter.cpp diff --git a/examples/UnitUnified/GraphicalMeter/main/ui_plotter.hpp b/examples/UnitUnified/GraphicalMeter/src/ui_plotter.hpp similarity index 100% rename from examples/UnitUnified/GraphicalMeter/main/ui_plotter.hpp rename to examples/UnitUnified/GraphicalMeter/src/ui_plotter.hpp From 7f93b9861cc109e70e222d00ca9e746f283c043d Mon Sep 17 00:00:00 2001 From: GOB Date: Fri, 13 Dec 2024 16:46:25 +0900 Subject: [PATCH 5/7] Fixes compile error on workflow and add PIO check --- .github/workflows/platformio-build-check.yml | 7 +++++++ examples/UnitUnified/GraphicalMeter/src/ui_plotter.hpp | 2 +- platformio.ini | 6 +++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/platformio-build-check.yml b/.github/workflows/platformio-build-check.yml index f1b9b53..0d14d42 100644 --- a/.github/workflows/platformio-build-check.yml +++ b/.github/workflows/platformio-build-check.yml @@ -114,6 +114,13 @@ jobs: # - board: Paper # espressif32: '4_4_0' + include: + # Specific sketches for m5stack-core-esp32 only + - example: GraphicalMeter + board: Core + framework: Arduino + espressif32: latest + steps: - name: Checkout uses: actions/checkout@v4 diff --git a/examples/UnitUnified/GraphicalMeter/src/ui_plotter.hpp b/examples/UnitUnified/GraphicalMeter/src/ui_plotter.hpp index 6970c13..a9ad1ff 100644 --- a/examples/UnitUnified/GraphicalMeter/src/ui_plotter.hpp +++ b/examples/UnitUnified/GraphicalMeter/src/ui_plotter.hpp @@ -78,7 +78,7 @@ class Plotter { { push(_parent, x, y); } - virtual void push(LovyanGFX* dst, const int32_t x, const int32_t y); + void push(LovyanGFX* dst, const int32_t x, const int32_t y); protected: m5gfx::rgb565_t lineColor() const diff --git a/platformio.ini b/platformio.ini index d17f62d..0a8453a 100644 --- a/platformio.ini +++ b/platformio.ini @@ -690,19 +690,19 @@ build_src_filter = +<*> -<.git/> -<.svn/> +<../examples/UnitUnified/UnitKmeterIS ; For the following samples, please refer to PlotToSerial to create env for your own environment ; 以下のサンプルは、PlotToSerial を参考にして、自分の環境にあった env を作成してください ; -[env:GraphicalMeter_Vmeter_Core] +[env:GraphicalMeter_Core_Arduino_latest] extends=Core, option_release, arduino_latest build_flags = ${option_release.build_flags} -DUSING_VMETER build_src_filter = +<*> -<.git/> -<.svn/> +<../examples/UnitUnified/GraphicalMeter> -[env:GraphicalMeter_Ameter_Core] +[env:GraphicalMeter_Core_Arduino_latest] extends=Core, option_release, arduino_latest build_flags = ${option_release.build_flags} -DUSING_AMETER build_src_filter = +<*> -<.git/> -<.svn/> +<../examples/UnitUnified/GraphicalMeter> -[env:GraphicalMeter_KmeterISO_Core] +[env:GraphicalMeter_Core_Arduino_latest] extends=Core, option_release, arduino_latest build_flags = ${option_release.build_flags} -DUSING_KMETER_ISO From 5ac82df94b48cf866f38e08fd53c630abe076c19 Mon Sep 17 00:00:00 2001 From: GOB Date: Fri, 13 Dec 2024 17:13:08 +0900 Subject: [PATCH 6/7] Fixes for arduino-m5stack workflow --- examples/UnitUnified/GraphicalMeter/src/meter.cpp | 4 ++-- platformio.ini | 15 +++------------ 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/examples/UnitUnified/GraphicalMeter/src/meter.cpp b/examples/UnitUnified/GraphicalMeter/src/meter.cpp index b84f5dd..bfac1bd 100644 --- a/examples/UnitUnified/GraphicalMeter/src/meter.cpp +++ b/examples/UnitUnified/GraphicalMeter/src/meter.cpp @@ -72,11 +72,11 @@ void draw_meter(LGFX_Sprite& spr, const int32_t offset, const char* tag, const c spr.setFont(wid >= 240 ? &fonts::FreeSansBold12pt7b : &fonts::FreeSansBold9pt7b); spr.setTextDatum(textdatum_t::middle_left); - spr.drawString(tag, x, y + 32 / 2); + spr.drawString(tag, x, y + hgt / 2); auto s = m5::utility::formatString("%.2f", 0.01f * plotter->latest()); spr.setTextDatum(textdatum_t::middle_right); - spr.drawString(s.c_str(), x + wid, y + 32 / 2); + spr.drawString(s.c_str(), x + wid, y + hgt / 2); spr.setTextDatum(td); spr.setFont(f); diff --git a/platformio.ini b/platformio.ini index 0a8453a..0bc9f6c 100644 --- a/platformio.ini +++ b/platformio.ini @@ -692,19 +692,10 @@ build_src_filter = +<*> -<.git/> -<.svn/> +<../examples/UnitUnified/UnitKmeterIS ; [env:GraphicalMeter_Core_Arduino_latest] extends=Core, option_release, arduino_latest +; Choose unit define build_flags = ${option_release.build_flags} -DUSING_VMETER -build_src_filter = +<*> -<.git/> -<.svn/> +<../examples/UnitUnified/GraphicalMeter> - -[env:GraphicalMeter_Core_Arduino_latest] -extends=Core, option_release, arduino_latest -build_flags = ${option_release.build_flags} - -DUSING_AMETER -build_src_filter = +<*> -<.git/> -<.svn/> +<../examples/UnitUnified/GraphicalMeter> - -[env:GraphicalMeter_Core_Arduino_latest] -extends=Core, option_release, arduino_latest -build_flags = ${option_release.build_flags} - -DUSING_KMETER_ISO +; -DUSING_AMETER +; -DUSING_KMETER_ISO build_src_filter = +<*> -<.git/> -<.svn/> +<../examples/UnitUnified/GraphicalMeter> From 0ac9bb3ac78febd74ef2411c52818b6ab212f61d Mon Sep 17 00:00:00 2001 From: GOB Date: Fri, 13 Dec 2024 17:27:51 +0900 Subject: [PATCH 7/7] Raise version --- library.json | 2 +- library.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library.json b/library.json index 3e80f18..e6d341a 100644 --- a/library.json +++ b/library.json @@ -13,7 +13,7 @@ "dependencies": { "M5UnitUnified": "https://github.com/m5stack/M5UnitUnified.git" }, - "version": "0.0.2", + "version": "0.0.3", "frameworks": [ "arduino" ], diff --git a/library.properties b/library.properties index c3382d2..7003c51 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=M5Unit-METER -version=0.0.2 +version=0.0.3 author=M5Stack maintainer=M5Stack sentence=Library for M5Stack UNIT METER using M5UnitUnified