From 6d7cdeb9aeafca39fde5b6266a81634eeb271fdc Mon Sep 17 00:00:00 2001 From: Sjef Verhoeven PE5PVB Date: Fri, 25 Oct 2024 12:32:14 +0200 Subject: [PATCH] Added Invert screen option (BW+BAND button) Updated DP66X default settings --- TEF6686_ESP32.ino | 90 +++++++++++++++++++++-------------------------- src/config.h | 2 +- src/constants.h | 9 ++--- src/language.h | 56 +++++++++++++++++++---------- 4 files changed, 84 insertions(+), 73 deletions(-) diff --git a/TEF6686_ESP32.ino b/TEF6686_ESP32.ino index 9d7639c..e2b15bb 100644 --- a/TEF6686_ESP32.ino +++ b/TEF6686_ESP32.ino @@ -38,12 +38,10 @@ #define STANDBYLED 19 #define SMETERPIN 27 #define TOUCHIRQ 33 +#define EXT_IRQ 14 #define DYNAMIC_SPI_SPEED // uncomment to enable dynamic SPI Speed https://github.com/ohmytime/TFT_eSPI_DynamicSpeed -#ifdef DEEPELEC_DP_66X -#define EXT_IRQ 14 -#endif #ifdef ARS TFT_eSPI tft = TFT_eSPI(320, 240); @@ -86,6 +84,7 @@ bool haseonold; bool hasrtplusold; bool hastmcold; bool initdxscan; +bool invertdisplay; bool leave; bool LowLevelInit; bool memorystore; @@ -157,12 +156,7 @@ byte BWset; byte BWsetAM; byte BWsetFM; byte charwidth = 8; - -#if defined(CHINA_PORTABLE) || defined(DEEPELEC_DP_66X) -byte hardwaremodel = PORTABLE_ILI9341; -#else -byte hardwaremodel = BASE_ILI9341; -#endif +byte hardwaremodel; byte ContrastSet; byte CurrentSkin; byte CurrentTheme; @@ -450,7 +444,7 @@ void setup() { setupmode = true; EEPROM.begin(EE_TOTAL_CNT); - if (EEPROM.readByte(EE_BYTE_CHECKBYTE) != EE_CHECKBYTE_VALUE) DefaultSettings(hardwaremodel); + if (EEPROM.readByte(EE_BYTE_CHECKBYTE) != EE_CHECKBYTE_VALUE) DefaultSettings(); frequency = EEPROM.readUInt(EE_UINT16_FREQUENCY_FM); frequency_OIRT = EEPROM.readUInt(EE_UINT16_FREQUENCY_OIRT); @@ -563,6 +557,7 @@ void setup() { TouchCalData[2] = EEPROM.readUInt(EE_UINT16_CALTOUCH3); TouchCalData[3] = EEPROM.readUInt(EE_UINT16_CALTOUCH4); TouchCalData[4] = EEPROM.readUInt(EE_UINT16_CALTOUCH5); + invertdisplay = EEPROM.readByte(EE_BYTE_INVERTDISPLAY); if (spispeed == SPI_SPEED_DEFAULT) { tft.setSPISpeed(SPI_FREQUENCY / 1000000); @@ -654,18 +649,14 @@ void setup() { pinMode(ROTARY_PIN_A, INPUT); pinMode(ROTARY_PIN_B, INPUT); pinMode (STANDBYLED, OUTPUT); - digitalWrite(STANDBYLED, HIGH); pinMode(TOUCHIRQ, INPUT); + pinMode(EXT_IRQ, INPUT_PULLUP); + digitalWrite(STANDBYLED, HIGH); attachInterrupt(digitalPinToInterrupt(TOUCHIRQ), Touch_IRQ_Handler, CHANGE); attachInterrupt(digitalPinToInterrupt(ROTARY_PIN_A), read_encoder, CHANGE); attachInterrupt(digitalPinToInterrupt(ROTARY_PIN_B), read_encoder, CHANGE); -#ifdef DEEPELEC_DP_66X - tft.invertDisplay(1); - pinMode(EXT_IRQ, INPUT_PULLUP); -#endif - tft.setSwapBytes(true); tft.fillScreen(BackgroundColor); @@ -711,8 +702,6 @@ void setup() { displayflip = 1; #ifdef ARS tft.setRotation(2); -#elif defined(DEEPELEC_DP_66X) - tft.setRotation(3); #else tft.setRotation(1); #endif @@ -720,8 +709,6 @@ void setup() { displayflip = 0; #ifdef ARS tft.setRotation(0); -#elif defined(DEEPELEC_DP_66X) - tft.setRotation(1); #else tft.setRotation(3); #endif @@ -760,7 +747,7 @@ void setup() { if (digitalRead(BWBUTTON) == LOW && digitalRead(ROTARY_BUTTON) == LOW && digitalRead(MODEBUTTON) == HIGH && digitalRead(BANDBUTTON) == HIGH) { analogWrite(CONTRASTPIN, map(ContrastSet, 0, 100, 15, 255)); - DefaultSettings(hardwaremodel); + DefaultSettings(); tftPrint(0, myLanguage[language][66], 155, 70, ActiveColor, ActiveColorSmooth, 28); tftPrint(0, myLanguage[language][2], 155, 130, ActiveColor, ActiveColorSmooth, 28); while (digitalRead(ROTARY_BUTTON) == LOW && digitalRead(BWBUTTON) == LOW) delay(50); @@ -780,6 +767,18 @@ void setup() { EEPROM.commit(); } + if (digitalRead(BWBUTTON) == LOW && digitalRead(ROTARY_BUTTON) == HIGH && digitalRead(MODEBUTTON) == HIGH && digitalRead(BANDBUTTON) == LOW) { + analogWrite(CONTRASTPIN, map(ContrastSet, 0, 100, 15, 255)); + tftPrint(0, myLanguage[language][284], 155, 70, ActiveColor, ActiveColorSmooth, 28); + tftPrint(0, myLanguage[language][2], 155, 130, ActiveColor, ActiveColorSmooth, 28); + invertdisplay = !invertdisplay; + tft.invertDisplay(!invertdisplay); + while (digitalRead(BWBUTTON) == LOW && digitalRead(BANDBUTTON) == LOW) delay(50); + EEPROM.writeByte(EE_BYTE_INVERTDISPLAY, invertdisplay); + EEPROM.commit(); + } + + tft.invertDisplay(!invertdisplay); tft.setTouch(TouchCalData); tft.fillScreen(BackgroundColor); tftPrint(0, myLanguage[language][8], 160, 3, PrimaryColor, PrimaryColorSmooth, 28); @@ -836,19 +835,11 @@ void setup() { } tftPrint(0, "Patch: v" + String(TEF), 160, 202, ActiveColor, ActiveColorSmooth, 28); -#ifdef DEEPELEC_DP_66X - bool extIO_dect = false; - // Device address 0x20 - // Set PORT0/PORT1 as input Wire.beginTransmission(0x20); Wire.write(0x06); Wire.write(0xFF); Wire.write(0xFF); - if (Wire.endTransmission() == 0) { - extIO_dect = true; - tftPrint(-1, "HW:DP-666", 240, 152, PrimaryColor, PrimaryColorSmooth, 16); - } -#endif + Wire.endTransmission(); if (analogRead(BATTERY_PIN) < 200) batterydetect = false; @@ -1329,7 +1320,6 @@ void loop() { } } -#ifdef DEEPELEC_DP_66X if (digitalRead(EXT_IRQ) == LOW) { int num; num = GetNum(); @@ -1341,7 +1331,6 @@ void loop() { } } } -#endif if (screensaverset) { if (screensaver_IRQ) @@ -4348,9 +4337,9 @@ void MuteScreen(bool setting) { } } -void DefaultSettings(byte userhardwaremodel) { +void DefaultSettings() { EEPROM.writeByte(EE_BYTE_CHECKBYTE, EE_CHECKBYTE_VALUE); - if (userhardwaremodel == BASE_ILI9341) EEPROM.writeUInt(EE_UINT16_FREQUENCY_FM, 10000); else EEPROM.writeUInt(EE_UINT16_FREQUENCY_FM, 8900); + EEPROM.writeUInt(EE_UINT16_FREQUENCY_FM, 10000); EEPROM.writeUInt(EE_UINT16_FREQUENCY_OIRT, FREQ_FM_OIRT_START); EEPROM.writeByte(EE_BYTE_VOLSET, 0); EEPROM.writeUInt(EE_UINT16_CONVERTERSET, 0); @@ -4358,7 +4347,7 @@ void DefaultSettings(byte userhardwaremodel) { EEPROM.writeUInt(EE_UINT16_FMHIGHEDGESET, 1080); EEPROM.writeByte(EE_BYTE_CONTRASTSET, 50); EEPROM.writeByte(EE_BYTE_STEREOLEVEL, 0); - if (userhardwaremodel == BASE_ILI9341) EEPROM.writeByte(EE_BYTE_BANDFM, FM_BAND_ALL); else EEPROM.writeByte(EE_BYTE_BANDFM, FM_BAND_FM); + EEPROM.writeByte(EE_BYTE_BANDFM, FM_BAND_ALL); EEPROM.writeByte(EE_BYTE_BANDAM, AM_BAND_ALL); EEPROM.writeByte(EE_BYTE_HIGHCUTLEVEL, 70); EEPROM.writeByte(EE_BYTE_HIGHCUTOFFSET, 0); @@ -4371,12 +4360,6 @@ void DefaultSettings(byte userhardwaremodel) { EEPROM.writeByte(EE_BYTE_LANGUAGE, 0); EEPROM.writeByte(EE_BYTE_SHOWRDSERRORS, 1); EEPROM.writeByte(EE_BYTE_TEF, 0); - if (userhardwaremodel == BASE_ILI9341) EEPROM.writeByte(EE_BYTE_DISPLAYFLIP, 0); else EEPROM.writeByte(EE_BYTE_DISPLAYFLIP, 1); -#ifdef DEEPELEC_DP_66X - EEPROM.writeByte(EE_BYTE_ROTARYMODE, 1); -#else - EEPROM.writeByte(EE_BYTE_ROTARYMODE, 0); -#endif EEPROM.writeByte(EE_BYTE_STEPSIZE, 0); EEPROM.writeByte(EE_BYTE_TUNEMODE, 0); EEPROM.writeByte(EE_BYTE_OPTENC, 0); @@ -4393,24 +4376,23 @@ void DefaultSettings(byte userhardwaremodel) { EEPROM.writeByte(EE_BYTE_SHOWSWMIBAND, 1); EEPROM.writeByte(EE_BYTE_RDS_FILTER, 1); EEPROM.writeByte(EE_BYTE_RDS_PIERRORS, 0); - if (userhardwaremodel == BASE_ILI9341) EEPROM.writeUInt(EE_UINT16_FREQUENCY_LW, 180); else EEPROM.writeUInt(EE_UINT16_FREQUENCY_LW, 164); - if (userhardwaremodel == BASE_ILI9341) EEPROM.writeUInt(EE_UINT16_FREQUENCY_MW, 540); else EEPROM.writeUInt(EE_UINT16_FREQUENCY_MW, 639); - if (userhardwaremodel == BASE_ILI9341) EEPROM.writeUInt(EE_UINT16_FREQUENCY_SW, 1800); else EEPROM.writeUInt(EE_UINT16_FREQUENCY_SW, 5000); + EEPROM.writeUInt(EE_UINT16_FREQUENCY_LW, 180); + EEPROM.writeUInt(EE_UINT16_FREQUENCY_MW, 540); + EEPROM.writeUInt(EE_UINT16_FREQUENCY_SW, 1800); #ifdef HAS_AIR_BAND EEPROM.writeUInt(EE_UINT16_FREQUENCY_AIR, 135350); #endif EEPROM.writeString(EE_STRING_XDRGTK_KEY, "password"); EEPROM.writeString(EE_STRING_RABBITEARSUSER, ""); EEPROM.writeString(EE_STRING_RABBITEARSPASSWORD, ""); - if (userhardwaremodel == BASE_ILI9341) EEPROM.writeByte(EE_BYTE_USESQUELCH, 1); else EEPROM.writeByte(EE_BYTE_USESQUELCH, 0); + EEPROM.writeByte(EE_BYTE_USESQUELCH, 1); EEPROM.writeByte(EE_BYTE_SHOWMODULATION, 1); EEPROM.writeByte(EE_BYTE_AM_NB, 0); EEPROM.writeByte(EE_BYTE_FM_NB, 0); EEPROM.writeByte(EE_BYTE_AUDIOMODE, 0); - if (userhardwaremodel == BASE_ILI9341) EEPROM.writeByte(EE_BYTE_TOUCH_ROTATING, 0); else EEPROM.writeByte(EE_BYTE_TOUCH_ROTATING, 1); + EEPROM.writeByte(EE_BYTE_TOUCH_ROTATING, 0); EEPROM.writeUInt(EE_UINT16_LOWEDGEOIRTSET, 0); EEPROM.writeUInt(EE_UINT16_HIGHEDGEOIRTSET, 0); - EEPROM.writeByte(EE_BYTE_HARDWARE_MODEL, userhardwaremodel); EEPROM.writeByte(EE_BYTE_POWEROPTIONS, 1); EEPROM.writeByte(EE_BYTE_CURRENTTHEME, 0); EEPROM.writeByte(EE_BYTE_FMDEFAULTSTEPSIZE, 1); @@ -4467,6 +4449,18 @@ void DefaultSettings(byte userhardwaremodel) { EEPROM.writeUInt(EE_UINT16_CALTOUCH4, 3450); EEPROM.writeUInt(EE_UINT16_CALTOUCH5, 3); +#ifdef DEEPELEC_DP_66X + EEPROM.writeByte(EE_BYTE_ROTARYMODE, 1); + EEPROM.writeByte(EE_BYTE_INVERTDISPLAY, 0); + EEPROM.writeByte(EE_BYTE_DISPLAYFLIP, 0); + EEPROM.writeByte(EE_BYTE_HARDWARE_MODEL, PORTABLE_TOUCH_ILI9341); +#else + EEPROM.writeByte(EE_BYTE_ROTARYMODE, 0); + EEPROM.writeByte(EE_BYTE_INVERTDISPLAY, 1); + EEPROM.writeByte(EE_BYTE_DISPLAYFLIP, 1); + EEPROM.writeByte(EE_BYTE_HARDWARE_MODEL, BASE_ILI9341); +#endif + for (int i = 0; i < EE_PRESETS_CNT; i++) { EEPROM.writeByte(i + EE_PRESETS_BAND_START, BAND_FM); EEPROM.writeUInt((i * 4) + EE_PRESETS_FREQUENCY_START, EE_PRESETS_FREQUENCY); @@ -5051,7 +5045,6 @@ void Touch_IRQ_Handler() { touch_detect = true; } -#ifdef DEEPELEC_DP_66X byte numval[16] = { 2, 3, 127, 5, 6, 0, 9, 13, 8, 7, 4, 1, 0, 0, 0, 0 }; @@ -5188,4 +5181,3 @@ void NumpadProcess(int num) { } } } -#endif diff --git a/src/config.h b/src/config.h index 567ee66..48f485b 100644 --- a/src/config.h +++ b/src/config.h @@ -5,6 +5,6 @@ // #define HAS_AIR_BAND // uncomment to enable Air Band(Make sure you have Air Band extend board) // #define CHINA_PORTABLE // uncomment for China Portable build (Simplified Chinese) -// #define DEEPELEC_DP_66X // uncomment for DEEPELEC Portable DP-66X build (Simplified Chinese) + #define DEEPELEC_DP_66X // uncomment for DEEPELEC Portable DP-66X build (Simplified Chinese) #endif diff --git a/src/constants.h b/src/constants.h index 1bc4190..14a4090 100644 --- a/src/constants.h +++ b/src/constants.h @@ -213,9 +213,9 @@ #define EE_CHECKBYTE_VALUE 10 // 0 ~ 255,add new entry, change for new value #define EE_PRESETS_FREQUENCY 0 // Default value when memory channel should be skipped! #ifdef HAS_AIR_BAND -#define EE_TOTAL_CNT 2279 // Total occupied eeprom bytes +#define EE_TOTAL_CNT 2280 // Total occupied eeprom bytes #else -#define EE_TOTAL_CNT 2274 // Total occupied eeprom bytes +#define EE_TOTAL_CNT 2275 // Total occupied eeprom bytes #endif #define EE_PRESETS_BAND_START 0 // 99 * 1 byte @@ -332,9 +332,10 @@ #define EE_UINT16_CALTOUCH3 2262 #define EE_UINT16_CALTOUCH4 2266 #define EE_UINT16_CALTOUCH5 2270 +#define EE_BYTE_INVERTDISPLAY 2274 #ifdef HAS_AIR_BAND -#define EE_BYTE_AIRSTEPSIZE 2274 -#define EE_UINT16_FREQUENCY_AIR 2275 +#define EE_BYTE_AIRSTEPSIZE 2275 +#define EE_UINT16_FREQUENCY_AIR 2276 #endif // End of EEPROM index defines diff --git a/src/language.h b/src/language.h index 0fd20af..4ee1045 100644 --- a/src/language.h +++ b/src/language.h @@ -5,7 +5,7 @@ // [number of languages][number of texts] -static const char* const myLanguage[18][284] PROGMEM = { +static const char* const myLanguage[18][285] PROGMEM = { { "English", // English "Rotary direction changed", // 1 "Please release button", // 2 @@ -289,7 +289,8 @@ static const char* const myLanguage[18][284] PROGMEM = { "Full", // 280 "Wait time on\nsignal only", // 281 "Press highlighted corner", // 282 - "To calibrate touchscreen" // 283 + "To calibrate touchscreen", // 283 + "Screen inversion toggles" // 284 }, { "Nederlands", // Dutch @@ -575,7 +576,8 @@ static const char* const myLanguage[18][284] PROGMEM = { "Volledig", // 280 "Wachttijd alleen\nbij signaal", // 281 "Druk op aangegeven hoeken", // 282 - "om scherm te calibreren" // 283 + "om scherm te calibreren", // 283 + "Scherm inversie gewijzigd" // 284 }, { "Polski", // Polish @@ -861,7 +863,8 @@ static const char* const myLanguage[18][284] PROGMEM = { "Pełne", // 280 "Wait time on\nsignal only", // 281 "Press highlighted corner", // 282 - "To calibrate touchscreen" // 283 + "To calibrate touchscreen", // 283 + "Screen inversion toggles" // 284 }, { "Hrvatski", // Croatian @@ -1147,7 +1150,8 @@ static const char* const myLanguage[18][284] PROGMEM = { "Full", // 280 "Wait time on\nsignal only", // 281 "Press highlighted corner", // 282 - "To calibrate touchscreen" // 283 + "To calibrate touchscreen", // 283 + "Screen inversion toggles" // 284 }, { "Ελληνικά", // Greek @@ -1433,7 +1437,8 @@ static const char* const myLanguage[18][284] PROGMEM = { "Πλήρης", // 280 "Αναμονή μόνο σε\nυπάρξη σήματος", // 281 "Press highlighted corner", // 282 - "To calibrate touchscreen" // 283 + "To calibrate touchscreen", // 283 + "Screen inversion toggles" // 284 }, { "Română", // Romanian @@ -1719,7 +1724,8 @@ static const char* const myLanguage[18][284] PROGMEM = { "Full", // 280 "Wait time on\nsignal only", // 281 "Press highlighted corner", // 282 - "To calibrate touchscreen" // 283 + "To calibrate touchscreen", // 283 + "Screen inversion toggles" // 284 }, { "Deutsch", // German @@ -2005,7 +2011,8 @@ static const char* const myLanguage[18][284] PROGMEM = { "Voll", // 280 "Wartezeit nur wenn\nSignal vorhanden", // 281 "Press highlighted corner", // 282 - "To calibrate touchscreen" // 283 + "To calibrate touchscreen", // 283 + "Screen inversion toggles" // 284 }, { "Český", // Czech @@ -2291,7 +2298,8 @@ static const char* const myLanguage[18][284] PROGMEM = { "Full", // 280 "Wait time on\nsignal only", // 281 "Press highlighted corner", // 282 - "To calibrate touchscreen" // 283 + "To calibrate touchscreen", // 283 + "Screen inversion toggles" // 284 }, { "Magyar", // Hungarian @@ -2577,7 +2585,8 @@ static const char* const myLanguage[18][284] PROGMEM = { "Full", // 280 "Wait time on\nsignal only", // 281 "Press highlighted corner", // 282 - "To calibrate touchscreen" // 283 + "To calibrate touchscreen", // 283 + "Screen inversion toggles" // 284 }, { "Français", // French @@ -2863,7 +2872,8 @@ static const char* const myLanguage[18][284] PROGMEM = { "Complet", // 280 "Attendre que lorsque\nle signal existe", // 281 "Press highlighted corner", // 282 - "To calibrate touchscreen" // 283 + "To calibrate touchscreen", // 283 + "Screen inversion toggles" // 284 }, @@ -3150,7 +3160,8 @@ static const char* const myLanguage[18][284] PROGMEM = { "Full", // 280 "Wait time on\nsignal only", // 281 "Press highlighted corner", // 282 - "To calibrate touchscreen" // 283 + "To calibrate touchscreen", // 283 + "Screen inversion toggles" // 284 }, { "Русский", // Russian @@ -3436,7 +3447,8 @@ static const char* const myLanguage[18][284] PROGMEM = { "Full", // 280 "Wait time on\nsignal only", // 281 "Press highlighted corner", // 282 - "To calibrate touchscreen" // 283 + "To calibrate touchscreen", // 283 + "Screen inversion toggles" // 284 }, { "Українська", // Ukranian @@ -3722,7 +3734,8 @@ static const char* const myLanguage[18][284] PROGMEM = { "Full", // 280 "Wait time on\nsignal only", // 281 "Press highlighted corner", // 282 - "To calibrate touchscreen" // 283 + "To calibrate touchscreen", // 283 + "Screen inversion toggles" // 284 }, { "Italiano", // Italian @@ -4008,7 +4021,8 @@ static const char* const myLanguage[18][284] PROGMEM = { "Piene", // 280 "Wait time on\nsignal only", // 281 "Press highlighted corner", // 282 - "To calibrate touchscreen" // 283 + "To calibrate touchscreen", // 283 + "Screen inversion toggles" // 284 }, { "Simplified Chinese", // Simplified Chinese @@ -4294,7 +4308,8 @@ static const char* const myLanguage[18][284] PROGMEM = { "Full", // 280 "Wait time on\nsignal only", // 281 "Press highlighted corner", // 282 - "To calibrate touchscreen" // 283 + "To calibrate touchscreen", // 283 + "Screen inversion toggles" // 284 }, { "Norsk", // Norwegian @@ -4580,7 +4595,8 @@ static const char* const myLanguage[18][284] PROGMEM = { "Full", // 280 "Wait time on\nsignal only", // 281 "Press highlighted corner", // 282 - "To calibrate touchscreen" // 283 + "To calibrate touchscreen", // 283 + "Screen inversion toggles" // 284 }, { "Español", // Spanish @@ -4866,7 +4882,8 @@ static const char* const myLanguage[18][284] PROGMEM = { "Completo", // 280 "Tiempo de espera\ncuando la señal", // 281 "Press highlighted corner", // 282 - "To calibrate touchscreen" // 283 + "To calibrate touchscreen", // 283 + "Screen inversion toggles" // 284 }, @@ -5153,7 +5170,8 @@ static const char* const myLanguage[18][284] PROGMEM = { "Completo", // 280 "Espera tempo apenas\nquando sinal", // 281 "Press highlighted corner", // 282 - "To calibrate touchscreen" // 283 + "To calibrate touchscreen", // 283 + "Screen inversion toggles" // 284 } }; #endif \ No newline at end of file