From a8610dad75c54bb04cacbace2cc6c729ef10a7e3 Mon Sep 17 00:00:00 2001 From: Bodmer Date: Mon, 6 Feb 2023 00:31:51 +0000 Subject: [PATCH] Add meter function with start and end scale values --- library.json | 2 +- library.properties | 2 +- src/TFT_eWidget.h | 10 +++++++++- src/widgets/graph/GraphWidget.cpp | 8 ++++++++ src/widgets/meter/Meter.cpp | 19 +++++++++++++------ src/widgets/meter/Meter.h | 5 ++++- 6 files changed, 36 insertions(+), 10 deletions(-) diff --git a/library.json b/library.json index 0ff06b6..77121f9 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "TFT_eWidget", - "version": "0.0.5", + "version": "0.0.6", "keywords": "Arduino, tft, display, button, gui, graph, meter, slider", "description": "A TFT GUI widget library", "repository": diff --git a/library.properties b/library.properties index b86f4af..3d9cefe 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=TFT_eWidget -version=0.0.5 +version=0.0.6 author=Bodmer maintainer=Bodmer sentence=A TFT GUI widget library diff --git a/src/TFT_eWidget.h b/src/TFT_eWidget.h index e570f2b..2fe9f77 100644 --- a/src/TFT_eWidget.h +++ b/src/TFT_eWidget.h @@ -11,8 +11,16 @@ //Standard support #include +// New ESP8266 board package uses ARDUINO_ARCH_ESP8266 +// old package defined ESP8266 +#if defined (ESP8266) + #ifndef ARDUINO_ARCH_ESP8266 + #define ARDUINO_ARCH_ESP8266 + #endif +#endif + // LittleFS is required for touch calibration in TFT_eSPI sketches -#if defined (ESP8266) || defined (ESP32) +#if defined (ARDUINO_ARCH_ESP8266) || defined (ESP32) #include #include #include diff --git a/src/widgets/graph/GraphWidget.cpp b/src/widgets/graph/GraphWidget.cpp index d3eb9d7..c8cc369 100644 --- a/src/widgets/graph/GraphWidget.cpp +++ b/src/widgets/graph/GraphWidget.cpp @@ -182,6 +182,14 @@ uint16_t GraphWidget::regionCode(float x, float y) code |= BOTTOM; else if (y > _yMax) // above the rectangle code |= TOP; + +// Reported 4 bit code values +// +// left central right +// top 1001 1000 1010 +// central 0001 0000 0010 +// bottom 0101 0100 0110 + return code; } diff --git a/src/widgets/meter/Meter.cpp b/src/widgets/meter/Meter.cpp index c97063d..627e300 100644 --- a/src/widgets/meter/Meter.cpp +++ b/src/widgets/meter/Meter.cpp @@ -15,6 +15,7 @@ my = 0; factor = 1.0; + scaleStart = 0.0; mlabel[8] = '\0'; @@ -40,14 +41,20 @@ // ######################################################################### // Draw meter meter at x, y and define full scale range & the scale labels // ######################################################################### -void MeterWidget::analogMeter(uint16_t x, uint16_t y, float fullScale, const char *label, const char *s0, const char *s1, const char *s2, const char *s3, const char *s4) +void MeterWidget::analogMeter(uint16_t x, uint16_t y, float fullScale, const char *units, const char *s0, const char *s1, const char *s2, const char *s3, const char *s4) +{ + analogMeter(x, y, 0.0, fullScale, units, s0, s1, s2, s3, s4); +} + +void MeterWidget::analogMeter(uint16_t x, uint16_t y, float startScale, float endScale, const char *units, const char *s0, const char *s1, const char *s2, const char *s3, const char *s4) { // Save offsets for needle plotting mx = x; my = y; - factor = 100.0/fullScale; + factor = 100.0/(endScale - startScale); + scaleStart = startScale; - strncpy(mlabel, label, 8); + strncpy(mlabel, units, 8); strncpy(ms0, s0, 4); strncpy(ms1, s1, 4); @@ -155,7 +162,7 @@ void MeterWidget::analogMeter(uint16_t x, uint16_t y, float fullScale, const cha updateNeedle(0, 0); } - + // ######################################################################### // Update needle position // This function is blocking while needle moves, time depends on ms_delay @@ -165,10 +172,10 @@ void MeterWidget::analogMeter(uint16_t x, uint16_t y, float fullScale, const cha // ######################################################################### void MeterWidget::updateNeedle(float val, uint32_t ms_delay) { - int value = val * factor; + int value = (val - scaleStart) * factor; ntft->setTextColor(TFT_BLACK, TFT_WHITE); - char buf[8]; dtostrf(value/factor, 5, 1, buf); + char buf[8]; dtostrf(val, 5, 1, buf); ntft->drawRightString(buf, mx + 50, my + 119 - 20, 2); diff --git a/src/widgets/meter/Meter.h b/src/widgets/meter/Meter.h index 7107f9b..700b558 100644 --- a/src/widgets/meter/Meter.h +++ b/src/widgets/meter/Meter.h @@ -17,7 +17,9 @@ class MeterWidget // Set red, orange, yellow and green start+end zones as a percentage of full scale void setZones(uint16_t rs, uint16_t re, uint16_t os, uint16_t oe, uint16_t ys, uint16_t ye, uint16_t gs, uint16_t ge); // Draw meter meter at x, y and define full scale range plus the scale labels - void analogMeter(uint16_t x, uint16_t y, float fullScale, const char *string, const char *s0, const char *s1, const char *s2, const char *s3, const char *s4); + void analogMeter(uint16_t x, uint16_t y, float fullScale, const char *units, const char *s0, const char *s1, const char *s2, const char *s3, const char *s4); + // Draw meter meter at x, y and define full scale range plus the scale labels + void analogMeter(uint16_t x, uint16_t y, float startScale, float endScale, const char *units, const char *s0, const char *s1, const char *s2, const char *s3, const char *s4); // Move needle to new position void updateNeedle(float value, uint32_t ms_delay); @@ -36,6 +38,7 @@ class MeterWidget // Scale factor float factor; + float scaleStart; // Scale label char mlabel[9];