From 92e82107767d04127d7f6c0d8296e62b26cc566a Mon Sep 17 00:00:00 2001 From: Sjef Verhoeven PE5PVB Date: Sat, 17 Jun 2023 20:07:48 +0200 Subject: [PATCH] Added battery+Wifi indicator Can't test battery indicator. No portable device here ;-) Please feedback. --- TEF6686_ESP32.ino | 58 +++++++++++++++----- src/constants.h | 132 ++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 154 insertions(+), 36 deletions(-) diff --git a/TEF6686_ESP32.ino b/TEF6686_ESP32.ino index 1c8e421..1d8e61b 100644 --- a/TEF6686_ESP32.ino +++ b/TEF6686_ESP32.ino @@ -21,6 +21,7 @@ #define ROTARY_PIN_B 36 #define ROTARY_BUTTON 39 #define PIN_POT 35 +#define BATTERY_PIN 13 #define PWRBUTTON 4 #define BWBUTTON 25 #define MODEBUTTON 26 @@ -38,6 +39,10 @@ TFT_eSPI tft = TFT_eSPI(320, 240); TFT_eSPI tft = TFT_eSPI(240, 320); #endif +byte battery; +byte batteryold; +int rssi; +int rssiold = 200; bool edgebeep; bool RDSSPYUSB; bool RDSSPYTCP; @@ -67,7 +72,6 @@ bool store; bool TPold; bool TAold; bool tuned; -bool USBstatus; bool USBmode = 1; bool XDRMute; bool XDRGTKdata; @@ -614,12 +618,14 @@ void GetData() { showRadioText(); ShowStereoStatus(); } + ShowRSSI(); + ShowBattery(); ShowOffset(); ShowSignalLevel(); ShowBW(); } - } + void PWRButtonPress() { if (menu == false) { unsigned long counterold = millis(); @@ -783,7 +789,7 @@ void ModeButtonPress() { if (counter - counterold <= 1000) { doTuneMode(); } else { - if (USBstatus == true && (XDRGTKUSB == true || XDRGTKTCP == true)) { + if (XDRGTKUSB == true || XDRGTKTCP == true) { ShowFreq(1); tft.setFreeFont(FONT14); tft.setTextColor(TFT_WHITE, TFT_BLACK); @@ -1122,6 +1128,8 @@ void ButtonPress() { tft.drawCentreString(myLanguage[language][53], 155, 50, GFXFF); tft.drawCentreString("ESP_" + String(ESP_getChipId()), 155, 90, GFXFF); tft.drawCentreString(myLanguage[language][54], 155, 130, GFXFF); + tft.setFreeFont(FONT7); + tft.drawCentreString("http://192.168.4.1", 155, 170, GFXFF); char key [9]; XDRGTK_key.toCharArray(key, 9); WiFiConnectParam XDRGTK_key_text("Set XDRGTK Password: (max 8 characters)"); @@ -2154,7 +2162,6 @@ void BuildDisplay() { ShowFreq(0); ShowTuneMode(); updateBW(); - ShowUSBstatus(); ShowStepSize(); ShowMemoryPos(); updateiMS(); @@ -2162,6 +2169,8 @@ void BuildDisplay() { Squelchold = -2; SStatusold = 2000; SStatus = 100; + rssiold = 2000; + batteryold = 6; rds_clockold = ""; strcpy(programTypePrevious, "0"); strcpy(radioIdPrevious, "0"); @@ -2791,8 +2800,36 @@ void ShowTuneMode() { } } -void ShowUSBstatus() { - if (USBstatus == true) tft.drawBitmap(272, 6, USBLogo, 43, 21, TFT_SKYBLUE); else tft.drawBitmap(272, 6, USBLogo, 43, 21, TFT_GREYOUT); +void ShowRSSI() { + if (wifi) rssi = WiFi.RSSI(); else rssi = 0; + if (rssiold != rssi) { + rssiold = rssi; + if (rssi == 0) { + tft.drawBitmap(272, 4, WiFi4, 25, 25, TFT_GREYOUT); + } else if (rssi > -50 && rssi < 0) { + tft.drawBitmap(272, 4, WiFi4, 25, 25, TFT_SKYBLUE); + } else if (rssi > -60) { + tft.drawBitmap(272, 4, WiFi4, 25, 25, TFT_GREYOUT); + tft.drawBitmap(272, 4, WiFi3, 25, 25, TFT_SKYBLUE); + } else if (rssi > -70) { + tft.drawBitmap(272, 4, WiFi4, 25, 25, TFT_GREYOUT); + tft.drawBitmap(272, 4, WiFi2, 25, 25, TFT_SKYBLUE); + } else if (rssi < -70) { + tft.drawBitmap(272, 4, WiFi4, 25, 25, TFT_GREYOUT); + tft.drawBitmap(272, 4, WiFi1, 25, 25, TFT_SKYBLUE); + } + } +} + +void ShowBattery() { + battery = map(constrain(analogRead(BATTERY_PIN), 1965, 2300), 1965, 2300, 0, 4); + if (batteryold != battery) { + 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); + batteryold = battery; + } } void Communication() { @@ -2859,12 +2896,7 @@ void Communication() { { String data_str = Serial.readStringUntil('\n'); int data = data_str.toInt(); - if (data_str.length() > 1 && data_str == ("*D*R?F")) - { - USBstatus = true; - RDSSPYUSB = true; - ShowUSBstatus(); - } + if (data_str.length() > 1 && data_str == ("*D*R?F")) RDSSPYUSB = true; int symPos = data_str.indexOf("*F"); if (symPos >= 5) { String freq = data_str.substring(0, symPos); @@ -2894,9 +2926,7 @@ void Communication() { SelectBand(); } Serial.print("OK\nT" + String(frequency * 10) + "\n"); - USBstatus = true; XDRGTKUSB = true; - ShowUSBstatus(); if (menu == true) ModeButtonPress(); if (Squelch != Squelchold) { if (screenmute == false) { diff --git a/src/constants.h b/src/constants.h index 1e2e9e2..3c0a86e 100644 --- a/src/constants.h +++ b/src/constants.h @@ -23,28 +23,116 @@ static const uint8_t RDSLogo[] PROGMEM = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; -static const uint8_t USBLogo[] PROGMEM = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x0b, 0xff, 0xff, 0xf0, 0x00, - 0x00, 0x3f, 0xff, 0xff, 0xf0, 0x00, - 0x00, 0xff, 0xff, 0xff, 0xe0, 0x00, - 0x01, 0xdf, 0xae, 0x5f, 0x7f, 0x80, - 0x03, 0x87, 0x08, 0x06, 0x00, 0x40, - 0x07, 0x8f, 0x18, 0x03, 0x00, 0x40, - 0x2f, 0x0e, 0x00, 0xc2, 0x10, 0x20, - 0x3f, 0x0f, 0x10, 0xfe, 0x3c, 0x40, - 0x7f, 0x0e, 0x18, 0x1e, 0x00, 0x80, - 0x7f, 0x1e, 0x18, 0x04, 0x00, 0x80, - 0x7f, 0x0e, 0x3e, 0x06, 0x30, 0x40, - 0x7e, 0x1c, 0x13, 0xc4, 0x38, 0x40, - 0xaf, 0x08, 0x21, 0xc4, 0x28, 0x40, - 0x0f, 0x00, 0x60, 0x04, 0x00, 0x80, - 0x0f, 0x00, 0xf0, 0x08, 0x01, 0x80, - 0x07, 0xeb, 0xfe, 0xbe, 0xf6, 0x00, - 0x03, 0xff, 0xff, 0xff, 0x80, 0x00, - 0x01, 0xff, 0xff, 0xff, 0x00, 0x00, - 0x00, 0x7f, 0xff, 0xff, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +static const uint8_t WiFi1[] PROGMEM = { +0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, +0x00, 0x08, 0x00, 0x00, +0x00, 0x3c, 0x00, 0x00, +0x00, 0x1c, 0x00, 0x00, +0x00, 0x18, 0x00, 0x00 +}; + +static const uint8_t WiFi2[] PROGMEM = { +0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, +0x00, 0x38, 0x00, 0x00, +0x00, 0xff, 0x00, 0x00, +0x01, 0xff, 0x80, 0x00, +0x03, 0xff, 0x80, 0x00, +0x03, 0xe7, 0x80, 0x00, +0x01, 0x83, 0x80, 0x00, +0x00, 0x00, 0x00, 0x00, +0x00, 0x18, 0x00, 0x00, +0x00, 0x3c, 0x00, 0x00, +0x00, 0x3c, 0x00, 0x00, +0x00, 0x18, 0x00, 0x00 +}; + +static const uint8_t WiFi3[] PROGMEM = { +0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, +0x00, 0x7f, 0x00, 0x00, +0x01, 0x80, 0xc0, 0x00, +0x02, 0x00, 0x20, 0x00, +0x04, 0x7e, 0x10, 0x00, +0x09, 0x80, 0x88, 0x00, +0x03, 0x00, 0x48, 0x00, +0x0c, 0x00, 0x20, 0x00, +0x04, 0x3e, 0x10, 0x00, +0x00, 0xc1, 0x00, 0x00, +0x01, 0x00, 0xc0, 0x00, +0x01, 0x36, 0x40, 0x00, +0x01, 0x43, 0x80, 0x00, +0x00, 0x80, 0x80, 0x00, +0x00, 0x00, 0x00, 0x00, +0x00, 0x1c, 0x00, 0x00, +0x00, 0x04, 0x00, 0x00, +0x00, 0x10, 0x00, 0x00, +0x00, 0x08, 0x00, 0x00 +}; + +static const uint8_t WiFi4[] PROGMEM = { +0x00, 0xff, 0x80, 0x00, +0x03, 0xff, 0xe0, 0x00, +0x0f, 0xff, 0xf8, 0x00, +0x1f, 0xff, 0xfc, 0x00, +0x3f, 0xc1, 0xfe, 0x00, +0x7e, 0x00, 0x3f, 0x80, +0xfc, 0x00, 0x0f, 0x80, +0xf0, 0x7f, 0x07, 0x80, +0x61, 0xff, 0xc3, 0x80, +0x63, 0xff, 0xe1, 0x00, +0x07, 0xff, 0xf0, 0x00, +0x0f, 0xc0, 0xf8, 0x00, +0x0f, 0x00, 0x7c, 0x00, +0x0e, 0x00, 0x38, 0x00, +0x04, 0x3e, 0x08, 0x00, +0x00, 0x7f, 0x80, 0x00, +0x01, 0xff, 0xc0, 0x00, +0x01, 0xff, 0xc0, 0x00, +0x00, 0xe1, 0xc0, 0x00, +0x00, 0x80, 0x80, 0x00, +0x00, 0x00, 0x00, 0x00, +0x00, 0x1c, 0x00, 0x00, +0x00, 0x1e, 0x00, 0x00, +0x00, 0x1c, 0x00, 0x00, +0x00, 0x08, 0x00, 0x00 }; static const uint16_t pe5pvblogo[] PROGMEM = {