Merge pull request #444 from ohmytime/Empty_Station_Optimization

Empty station optimization
This commit is contained in:
ohmytime
2023-11-23 17:24:26 +08:00
committed by GitHub
3 changed files with 55 additions and 7 deletions
+47 -3
View File
@@ -160,6 +160,7 @@ byte memoryband[EE_PRESETS_CNT];
byte memorybw[EE_PRESETS_CNT]; byte memorybw[EE_PRESETS_CNT];
byte memorypos; byte memorypos;
byte memoryposold; byte memoryposold;
byte memoryposstatus;
byte menupage; byte menupage;
byte MSold; byte MSold;
byte optenc; byte optenc;
@@ -502,6 +503,8 @@ void setup() {
break; break;
} }
if (IsStationEmpty()) memoryposstatus = MEM_DARK; else memoryposstatus = MEM_NORMAL;
tft.init(); tft.init();
doTheme(); doTheme();
if (displayflip == 0) { if (displayflip == 0) {
@@ -2073,6 +2076,10 @@ void ButtonPress() {
if (tunemode == TUNE_MEM) { if (tunemode == TUNE_MEM) {
if (!memorystore) { if (!memorystore) {
memorystore = true; memorystore = true;
if (!IsStationEmpty()) memoryposstatus = MEM_EXIST;
else memoryposstatus = MEM_NORMAL;
ShowMemoryPos();
ShowTuneMode(); ShowTuneMode();
} else { } else {
memorystore = false; memorystore = false;
@@ -2106,6 +2113,10 @@ void ButtonPress() {
memory[memorypos] = frequency_SW; memory[memorypos] = frequency_SW;
} }
ShowTuneMode(); ShowTuneMode();
if (memoryposstatus == MEM_DARK || memoryposstatus == MEM_EXIST) {
memoryposstatus = MEM_NORMAL;
ShowMemoryPos();
}
} }
} else { } else {
seek = false; seek = false;
@@ -2209,8 +2220,13 @@ void KeyUp() {
case TUNE_MEM: case TUNE_MEM:
memorypos++; memorypos++;
if (memorypos > EE_PRESETS_CNT - 1) memorypos = 0; if (memorypos > EE_PRESETS_CNT - 1) memorypos = 0;
if (!memorystore) {
DoMemoryPosTune();
} else {
if (!IsStationEmpty()) memoryposstatus = MEM_EXIST;
else memoryposstatus = MEM_NORMAL;
}
ShowMemoryPos(); ShowMemoryPos();
if (!memorystore) DoMemoryPosTune();
EEPROM.writeByte(EE_BYTE_MEMORYPOS, memorypos); EEPROM.writeByte(EE_BYTE_MEMORYPOS, memorypos);
EEPROM.commit(); EEPROM.commit();
break; break;
@@ -2256,8 +2272,13 @@ void KeyDown() {
case TUNE_MEM: case TUNE_MEM:
memorypos--; memorypos--;
if (memorypos > EE_PRESETS_CNT - 1) memorypos = EE_PRESETS_CNT - 1; if (memorypos > EE_PRESETS_CNT - 1) memorypos = EE_PRESETS_CNT - 1;
if (!memorystore) {
DoMemoryPosTune();
} else {
if (!IsStationEmpty()) memoryposstatus = MEM_EXIST;
else memoryposstatus = MEM_NORMAL;
}
ShowMemoryPos(); ShowMemoryPos();
if (!memorystore) DoMemoryPosTune();
EEPROM.writeByte(EE_BYTE_MEMORYPOS, memorypos); EEPROM.writeByte(EE_BYTE_MEMORYPOS, memorypos);
EEPROM.commit(); EEPROM.commit();
break; break;
@@ -2285,9 +2306,24 @@ void KeyDown() {
} }
} }
bool IsStationEmpty() {
if (memoryband[memorypos] == BAND_FM && memory[memorypos] == EE_PRESETS_FREQUENCY) {
return true;
}
return false;
}
void ShowMemoryPos() { void ShowMemoryPos() {
if (tunemode == TUNE_MEM) { if (tunemode == TUNE_MEM) {
if (advancedRDS) tftReplace(-1, String(memoryposold + 1), String(memorypos + 1), 215, 36, SecondaryColor, SecondaryColorSmooth, 16); else tftReplace(-1, String(memoryposold + 1), String(memorypos + 1), 50, 32, PrimaryColor, PrimaryColorSmooth, 16); int memposcolor;
log_e("memoryposstatus %d:",memoryposstatus);
switch (memoryposstatus) {
// case MEM_DARK: memposcolor = GreyoutColor; break;
case MEM_DARK: memposcolor = InsignificantColor; break;
case MEM_NORMAL: memposcolor = PrimaryColor; break;
case MEM_EXIST: memposcolor = SignificantColor; break;
}
if (advancedRDS) tftReplace(-1, String(memoryposold + 1), String(memorypos + 1), 215, 36, SecondaryColor, SecondaryColorSmooth, 16); else tftReplace(-1, String(memoryposold + 1), String(memorypos + 1), 50, 32, memposcolor, PrimaryColorSmooth, 16);
memoryposold = memorypos; memoryposold = memorypos;
} else { } else {
if (advancedRDS) tftPrint(-1, String(memorypos + 1), 215, 36, BackgroundColor, BackgroundColor, 16); else tftPrint(-1, String(memorypos + 1), 50, 32, BackgroundColor, BackgroundColor, 16); if (advancedRDS) tftPrint(-1, String(memorypos + 1), 215, 36, BackgroundColor, BackgroundColor, 16); else tftPrint(-1, String(memorypos + 1), 50, 32, BackgroundColor, BackgroundColor, 16);
@@ -2295,6 +2331,14 @@ void ShowMemoryPos() {
} }
void DoMemoryPosTune() { void DoMemoryPosTune() {
// Process empty stations
if (IsStationEmpty()) {
memoryposstatus = MEM_DARK;
return;
} else {
memoryposstatus = MEM_NORMAL;
}
if (band != memoryband[memorypos]) { if (band != memoryband[memorypos]) {
band = memoryband[memorypos]; band = memoryband[memorypos];
SelectBand(); SelectBand();
+4
View File
@@ -243,6 +243,10 @@ enum SPI_SPEED_ENUM {
SPI_SPEED_COUNT SPI_SPEED_COUNT
}; };
enum RADIO_MEM_POS_STATUS {
MEM_DARK, MEM_NORMAL, MEM_EXIST
};
static const uint8_t TEFLogo[] PROGMEM = { static const uint8_t TEFLogo[] PROGMEM = {
0xff, 0xff, 0xf8, 0x7f, 0xfe, 0x07, 0xff, 0xe0, 0xff, 0xff, 0xf8, 0xff, 0xff, 0x1f, 0xff, 0xe0, 0xff, 0xff, 0xf8, 0x7f, 0xfe, 0x07, 0xff, 0xe0, 0xff, 0xff, 0xf8, 0xff, 0xff, 0x1f, 0xff, 0xe0,
0xff, 0xff, 0xf9, 0xff, 0xff, 0x1f, 0xff, 0xe0, 0xff, 0xff, 0xfb, 0xff, 0xfe, 0x3f, 0xff, 0xe0, 0xff, 0xff, 0xf9, 0xff, 0xff, 0x1f, 0xff, 0xe0, 0xff, 0xff, 0xfb, 0xff, 0xfe, 0x3f, 0xff, 0xe0,
+3 -3
View File
@@ -73,7 +73,7 @@ void doTheme() { // Use this to put your own colors in: http://www.barth-dev.de
BackgroundColor = TFT_BLACK; BackgroundColor = TFT_BLACK;
ActiveColor = TFT_WHITE; ActiveColor = TFT_WHITE;
ActiveColorSmooth = 0x18E3; ActiveColorSmooth = 0x18E3;
SignificantColor = TFT_RED; SignificantColor = TFT_GREEN;
SignificantColorSmooth = 0x2000; SignificantColorSmooth = 0x2000;
InsignificantColor = TFT_GREEN; InsignificantColor = TFT_GREEN;
InsignificantColorSmooth = 0x00C0; InsignificantColorSmooth = 0x00C0;
@@ -153,7 +153,7 @@ void doTheme() { // Use this to put your own colors in: http://www.barth-dev.de
ActiveColorSmooth = 0x18E3; ActiveColorSmooth = 0x18E3;
SignificantColor = TFT_RED; SignificantColor = TFT_RED;
SignificantColorSmooth = 0x2000; SignificantColorSmooth = 0x2000;
InsignificantColor = TFT_GREEN; InsignificantColor = 0xAA1C;
InsignificantColorSmooth = 0x00C0; InsignificantColorSmooth = 0x00C0;
StereoColor = TFT_GREEN; StereoColor = TFT_GREEN;
StereoColorSmooth = 0x0200; StereoColorSmooth = 0x0200;
@@ -203,7 +203,7 @@ void doTheme() { // Use this to put your own colors in: http://www.barth-dev.de
BackgroundColor = 0xDFFC; BackgroundColor = 0xDFFC;
ActiveColor = TFT_BLACK; ActiveColor = TFT_BLACK;
ActiveColorSmooth = 0xDFFC; ActiveColorSmooth = 0xDFFC;
SignificantColor = TFT_BLACK; SignificantColor = TFT_RED;
SignificantColorSmooth = 0xDFFC; SignificantColorSmooth = 0xDFFC;
InsignificantColor = TFT_GREEN; InsignificantColor = TFT_GREEN;
InsignificantColorSmooth = 0x0140; InsignificantColorSmooth = 0x0140;