Add meter function with start and end scale values

This commit is contained in:
Bodmer
2023-02-06 00:31:51 +00:00
parent 07a570e331
commit a8610dad75
6 changed files with 36 additions and 10 deletions

View File

@ -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":

View File

@ -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

View File

@ -11,8 +11,16 @@
//Standard support
#include <Arduino.h>
// 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 <pgmspace.h>
#include <FS.h>
#include <LittleFS.h>

View File

@ -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;
}

View File

@ -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);

View File

@ -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];