From df618b121e89b7d10dc662061ff9bfc002e04fee Mon Sep 17 00:00:00 2001 From: kevin Date: Tue, 4 Jul 2023 17:05:01 +0800 Subject: [PATCH] Bat icon adjust 1.Add slow down timer 2.if bat adc value < BAT_LEVEL_WARN, bat icon will turn red. --- TEF6686_ESP32.ino | 25 ++++++++++++++++++++----- src/constants.h | 1 + 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/TEF6686_ESP32.ino b/TEF6686_ESP32.ino index a68d824..c760810 100644 --- a/TEF6686_ESP32.ino +++ b/TEF6686_ESP32.ino @@ -84,6 +84,7 @@ byte audiomode; byte band; byte battery; byte batteryold; +int batupdatetimer; byte BWset; byte colorinvert; byte ContrastSet; @@ -3972,13 +3973,27 @@ void ShowRSSI() { } void ShowBattery() { - battery = map(constrain(analogRead(BATTERY_PIN), BAT_LEVEL_EMPTY, BAT_LEVEL_FULL), BAT_LEVEL_EMPTY, BAT_LEVEL_FULL, 0, BAT_LEVEL_STAGE); + if (millis() >= batupdatetimer + TIMER_BAT_TIMER) { + batupdatetimer = millis(); + } else { + return; + } + + int16_t batteryadc = analogRead(BATTERY_PIN); + battery = map(constrain(batteryadc, BAT_LEVEL_EMPTY, BAT_LEVEL_FULL), BAT_LEVEL_EMPTY, BAT_LEVEL_FULL, 0, BAT_LEVEL_STAGE); if (batteryold != battery) { if (batterydetect) { - tft.drawRect(300, 8, 12, 20, TFT_WHITE); - tft.fillRect(303, 4, 6, 4, TFT_WHITE); - tft.fillRect(302, 10, 8, 16, TFT_BLACK); - tft.fillRect(302, 26 - (battery * 4), 8, battery * 4, TFT_GREEN); + if (batteryadc < BAT_LEVEL_WARN) { + tft.drawRect(300, 8, 12, 20, TFT_RED); + tft.fillRect(303, 4, 6, 4, TFT_RED); + tft.fillRect(302, 10, 8, 16, TFT_BLACK); + tft.fillRect(302, 26 - (battery * 4), 8, battery * 4, TFT_GREEN); + } else { + tft.drawRect(300, 8, 12, 20, TFT_WHITE); + tft.fillRect(303, 4, 6, 4, TFT_WHITE); + tft.fillRect(302, 10, 8, 16, TFT_BLACK); + tft.fillRect(302, 26 - (battery * 4), 8, battery * 4, TFT_GREEN); + } } else { tft.drawRect(300, 8, 12, 20, TFT_GREYOUT); tft.fillRect(303, 4, 6, 4, TFT_GREYOUT); diff --git a/src/constants.h b/src/constants.h index 63bc92a..f734206 100644 --- a/src/constants.h +++ b/src/constants.h @@ -1,6 +1,7 @@ #define TIMER_OFFSET_TIMER (TIMER_500_TICK) #define TIMER_BW_TIMER (TIMER_500_TICK) #define TIMER_SNR_TIMER (TIMER_500_TICK) +#define TIMER_BAT_TIMER (TIMER_500_TICK) #define TIMER_500_TICK 500 #define BAT_LEVEL_EMPTY 1600