Added PI and PS to memory channels

This commit is contained in:
Sjef Verhoeven PE5PVB
2024-04-06 18:42:53 +02:00
parent 7a12c1ffa4
commit 1b7ba7dd9c
4 changed files with 177 additions and 83 deletions
+87 -30
View File
@@ -76,8 +76,8 @@ bool haseonold;
bool hasrtplusold; bool hasrtplusold;
bool hastmcold; bool hastmcold;
bool LowLevelInit; bool LowLevelInit;
//bool memoryms[EE_PRESETS_CNT];
bool memorystore; bool memorystore;
bool memtune;
bool menu; bool menu;
bool menuopen; bool menuopen;
bool mwstepsize; bool mwstepsize;
@@ -161,8 +161,6 @@ byte iMSEQ;
byte iMSset; byte iMSset;
byte language; byte language;
byte licold; byte licold;
//byte memoryband[EE_PRESETS_CNT];
//byte memorybw[EE_PRESETS_CNT];
byte memorypos; byte memorypos;
byte memoryposold; byte memoryposold;
byte memoryposstatus; byte memoryposstatus;
@@ -338,7 +336,6 @@ unsigned int LWLowEdgeSet;
unsigned int mappedfreqold[20]; unsigned int mappedfreqold[20];
unsigned int mappedfreqold2[20]; unsigned int mappedfreqold2[20];
unsigned int mappedfreqold3[20]; unsigned int mappedfreqold3[20];
//unsigned int memory[EE_PRESETS_CNT];
unsigned int MWHighEdgeSet; unsigned int MWHighEdgeSet;
unsigned int MWLowEdgeSet; unsigned int MWLowEdgeSet;
unsigned int scanner_end; unsigned int scanner_end;
@@ -492,10 +489,19 @@ void setup() {
LowEdgeOIRTSet = LowEdgeOIRTSet; LowEdgeOIRTSet = LowEdgeOIRTSet;
HighEdgeOIRTSet = FREQ_FM_OIRT_END; HighEdgeOIRTSet = FREQ_FM_OIRT_END;
for (int i = 0; i < EE_PRESETS_CNT; i++) presets[i].memoryband = EEPROM.readByte(i + EE_PRESETS_BAND_START); for (int i = 0; i < EE_PRESETS_CNT; i++) presets[i].band = EEPROM.readByte(i + EE_PRESETS_BAND_START);
for (int i = 0; i < EE_PRESETS_CNT; i++) presets[i].frequency = EEPROM.readUInt((i * 4) + EE_PRESETS_START); for (int i = 0; i < EE_PRESETS_CNT; i++) presets[i].frequency = EEPROM.readUInt((i * 4) + EE_PRESETS_FREQUENCY_START);
for (int i = 0; i < EE_PRESETS_CNT; i++) presets[i].memorybw = EEPROM.readByte(i + EE_PRESET_BW_START); for (int i = 0; i < EE_PRESETS_CNT; i++) presets[i].bw = EEPROM.readByte(i + EE_PRESET_BW_START);
for (int i = 0; i < EE_PRESETS_CNT; i++) presets[i].memoryms = EEPROM.readByte(i + EE_PRESET_MS_START); for (int i = 0; i < EE_PRESETS_CNT; i++) presets[i].ms = EEPROM.readByte(i + EE_PRESET_MS_START);
for (int i = 0; i < EE_PRESETS_CNT; i++) {
for (int y = 0; y < 9; y++) {
presets[i].RDSPS[y] = EEPROM.readByte((i * 9) + y + EE_PRESETS_RDSPS_START);
}
for (int y = 0; y < 5; y++) {
presets[i].RDSPI[y] = EEPROM.readByte((i * 5) + y + EE_PRESETS_RDSPI_START);
}
}
btStop(); btStop();
@@ -756,6 +762,7 @@ void setup() {
} }
SelectBand(); SelectBand();
if (tunemode == TUNE_MEM) DoMemoryPosTune();
setupmode = false; setupmode = false;
if (edgebeep) radio.tone(50, -5, 2000); if (edgebeep) radio.tone(50, -5, 2000);
@@ -1343,7 +1350,7 @@ void ToggleBand(byte nowBand) {
void BANDBUTTONPress() { void BANDBUTTONPress() {
if (memorystore) { if (memorystore) {
EEPROM.writeUInt((memorypos * 4) + EE_PRESETS_START, EE_PRESETS_FREQUENCY); EEPROM.writeUInt((memorypos * 4) + EE_PRESETS_FREQUENCY_START, EE_PRESETS_FREQUENCY);
EEPROM.commit(); EEPROM.commit();
presets[memorypos].frequency = EE_PRESETS_FREQUENCY; presets[memorypos].frequency = EE_PRESETS_FREQUENCY;
memorystore = false; memorystore = false;
@@ -2221,20 +2228,39 @@ void ButtonPress() {
EEPROM.writeByte(memorypos + EE_PRESET_BW_START, BWset); EEPROM.writeByte(memorypos + EE_PRESET_BW_START, BWset);
EEPROM.writeByte(memorypos + EE_PRESET_MS_START, StereoToggle); EEPROM.writeByte(memorypos + EE_PRESET_MS_START, StereoToggle);
if (band == BAND_FM) { if (band == BAND_FM) {
EEPROM.writeUInt((memorypos * 4) + EE_PRESETS_START, frequency); EEPROM.writeUInt((memorypos * 4) + EE_PRESETS_FREQUENCY_START, frequency);
} else if (band == BAND_OIRT) { } else if (band == BAND_OIRT) {
EEPROM.writeUInt((memorypos * 4) + EE_PRESETS_START, frequency_OIRT); EEPROM.writeUInt((memorypos * 4) + EE_PRESETS_FREQUENCY_START, frequency_OIRT);
} else if (band == BAND_LW) { } else if (band == BAND_LW) {
EEPROM.writeUInt((memorypos * 4) + EE_PRESETS_START, frequency_LW); EEPROM.writeUInt((memorypos * 4) + EE_PRESETS_FREQUENCY_START, frequency_LW);
} else if (band == BAND_MW) { } else if (band == BAND_MW) {
EEPROM.writeUInt((memorypos * 4) + EE_PRESETS_START, frequency_MW); EEPROM.writeUInt((memorypos * 4) + EE_PRESETS_FREQUENCY_START, frequency_MW);
} else { } else {
EEPROM.writeUInt((memorypos * 4) + EE_PRESETS_START, frequency_SW); EEPROM.writeUInt((memorypos * 4) + EE_PRESETS_FREQUENCY_START, frequency_SW);
} }
presets[memorypos].band = band;
presets[memorypos].bw = BWset;
presets[memorypos].ms = StereoToggle;
String stationName = radio.rds.stationName;
char stationNameCharArray[10];
char picodeArray[7];
stationName.toCharArray(stationNameCharArray, sizeof(stationNameCharArray));
memcpy(picodeArray, radio.rds.picode, sizeof(picodeArray));
for (int y = 0; y < 9; y++) {
presets[memorypos].RDSPS[y] = (y < strlen(stationNameCharArray)) ? stationNameCharArray[y] : '\0';
EEPROM.writeByte((memorypos * 9) + y + EE_PRESETS_RDSPS_START, presets[memorypos].RDSPS[y]);
}
for (int y = 0; y < 5; y++) {
presets[memorypos].RDSPI[y] = (y < sizeof(picodeArray)) ? picodeArray[y] : '\0';
EEPROM.writeByte((memorypos * 5) + y + EE_PRESETS_RDSPI_START, presets[memorypos].RDSPI[y]);
}
EEPROM.commit(); EEPROM.commit();
presets[memorypos].memoryband = band;
presets[memorypos].memorybw = BWset;
presets[memorypos].memoryms = StereoToggle;
if (band == BAND_FM) { if (band == BAND_FM) {
presets[memorypos].frequency = frequency; presets[memorypos].frequency = frequency;
} else if (band == BAND_OIRT) { } else if (band == BAND_OIRT) {
@@ -2381,6 +2407,7 @@ void KeyUp() {
EEPROM.writeByte(EE_BYTE_MEMORYPOS, memorypos); EEPROM.writeByte(EE_BYTE_MEMORYPOS, memorypos);
EEPROM.commit(); EEPROM.commit();
break; break;
case TUNE_MI_BAND: case TUNE_MI_BAND:
if (showSWMIBand) { if (showSWMIBand) {
if (displayflip) { if (displayflip) {
@@ -2395,7 +2422,8 @@ void KeyUp() {
if (band == BAND_FM) DataPrint("M0\nT" + String(frequency * 10) + "\n"); else if (band == BAND_OIRT) DataPrint("M0\nT" + String(frequency_OIRT * 10) + "\n"); else DataPrint("M1\nT" + String(frequency_AM) + "\n"); if (band == BAND_FM) DataPrint("M0\nT" + String(frequency * 10) + "\n"); else if (band == BAND_OIRT) DataPrint("M0\nT" + String(frequency_OIRT * 10) + "\n"); else DataPrint("M1\nT" + String(frequency_AM) + "\n");
} }
if (!memorystore) { if (!memorystore) {
radio.clearRDS(fullsearchrds); if (!memtune) radio.clearRDS(fullsearchrds);
memtune = false;
ShowFreq(0); ShowFreq(0);
store = true; store = true;
} }
@@ -2456,7 +2484,8 @@ void KeyDown() {
if (band == BAND_FM) DataPrint("M0\nT" + String(frequency * 10) + "\n"); else if (band == BAND_OIRT) DataPrint("M0\nT" + String(frequency_OIRT * 10) + "\n"); else DataPrint("M1\nT" + String(frequency_AM) + "\n"); if (band == BAND_FM) DataPrint("M0\nT" + String(frequency * 10) + "\n"); else if (band == BAND_OIRT) DataPrint("M0\nT" + String(frequency_OIRT * 10) + "\n"); else DataPrint("M1\nT" + String(frequency_AM) + "\n");
} }
if (!memorystore) { if (!memorystore) {
radio.clearRDS(fullsearchrds); if (!memtune) radio.clearRDS(fullsearchrds);
memtune = false;
ShowFreq(0); ShowFreq(0);
store = true; store = true;
} }
@@ -2467,7 +2496,7 @@ void KeyDown() {
} }
bool IsStationEmpty() { bool IsStationEmpty() {
if (presets[memorypos].memoryband == BAND_FM && presets[memorypos].frequency == EE_PRESETS_FREQUENCY) { if (presets[memorypos].band == BAND_FM && presets[memorypos].frequency == EE_PRESETS_FREQUENCY) {
return true; return true;
} }
return false; return false;
@@ -2517,11 +2546,11 @@ void DoMemoryPosTune() {
memoryposstatus = MEM_NORMAL; memoryposstatus = MEM_NORMAL;
} }
if (band != presets[memorypos].memoryband) { if (band != presets[memorypos].band) {
band = presets[memorypos].memoryband; band = presets[memorypos].band;
SelectBand(); SelectBand();
} else { } else {
band = presets[memorypos].memoryband; band = presets[memorypos].band;
} }
if (band == BAND_FM) { if (band == BAND_FM) {
@@ -2543,7 +2572,7 @@ void DoMemoryPosTune() {
ShowFreq(0); ShowFreq(0);
if (band == BAND_FM || band == BAND_OIRT) { if (band == BAND_FM || band == BAND_OIRT) {
StereoToggle = presets[memorypos].memoryms; StereoToggle = presets[memorypos].ms;
if (!StereoToggle) { if (!StereoToggle) {
Stereostatusold = false; Stereostatusold = false;
if (CurrentSkin == 1 && !advancedRDS && !afscreen) { if (CurrentSkin == 1 && !advancedRDS && !afscreen) {
@@ -2571,10 +2600,26 @@ void DoMemoryPosTune() {
} }
} }
BWset = presets[memorypos].memorybw; String stationText = "";
if (presets[memorypos].RDSPS[0] != '\0') {
for (int i = 0; i < 9; i++) stationText += presets[memorypos].RDSPS[i];
}
if (presets[memorypos].RDSPI[0] != '\0') {
for (int i = 0; i < 5; i++) {
radio.rds.picode[i] = presets[memorypos].RDSPI[i];
}
radio.rds.picode[6] = '\0';
} else {
radio.rds.picode[0] = '\0';
}
radio.rds.stationName = stationText;
BWset = presets[memorypos].bw;
doBW(); doBW();
BWtune = true; BWtune = true;
memtune = true;
} }
void ShowFreq(int mode) { void ShowFreq(int mode) {
@@ -4053,10 +4098,6 @@ void DefaultSettings(byte userhardwaremodel) {
EEPROM.writeByte(EE_BYTE_SHOWSWMIBAND, 1); EEPROM.writeByte(EE_BYTE_SHOWSWMIBAND, 1);
EEPROM.writeByte(EE_BYTE_RDS_FILTER, 0); EEPROM.writeByte(EE_BYTE_RDS_FILTER, 0);
EEPROM.writeByte(EE_BYTE_RDS_PIERRORS, 0); EEPROM.writeByte(EE_BYTE_RDS_PIERRORS, 0);
for (int i = 0; i < EE_PRESETS_CNT; i++) EEPROM.writeByte(i + EE_PRESETS_BAND_START, BAND_FM);
for (int i = 0; i < EE_PRESETS_CNT; i++) EEPROM.writeUInt((i * 4) + EE_PRESETS_START, EE_PRESETS_FREQUENCY);
for (int i = 0; i < EE_PRESETS_CNT; i++) EEPROM.writeByte(i + EE_PRESET_BW_START, 0);
for (int i = 0; i < EE_PRESETS_CNT; i++) EEPROM.writeByte(i + EE_PRESET_MS_START, 1);
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_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_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); if (userhardwaremodel == BASE_ILI9341) EEPROM.writeUInt(EE_UINT16_FREQUENCY_SW, 1800); else EEPROM.writeUInt(EE_UINT16_FREQUENCY_SW, 5000);
@@ -4100,6 +4141,22 @@ void DefaultSettings(byte userhardwaremodel) {
EEPROM.writeByte(EE_BYTE_FMAGC, 92); EEPROM.writeByte(EE_BYTE_FMAGC, 92);
EEPROM.writeByte(EE_BYTE_AMAGC, 100); EEPROM.writeByte(EE_BYTE_AMAGC, 100);
EEPROM.writeByte(EE_BYTE_FMSI, 1); EEPROM.writeByte(EE_BYTE_FMSI, 1);
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);
EEPROM.writeByte(i + EE_PRESET_BW_START, 0);
EEPROM.writeByte(i + EE_PRESET_MS_START, 1);
for (int y = 0; y < 9; y++) {
EEPROM.writeByte((i * 9) + y + EE_PRESETS_RDSPS_START, '\0');
}
for (int y = 0; y < 5; y++) {
EEPROM.writeByte((i * 5) + y + EE_PRESETS_RDSPI_START, '\0');
}
}
EEPROM.commit(); EEPROM.commit();
} }
Binary file not shown.
+43 -8
View File
@@ -176,11 +176,15 @@ void Communication() {
Serial.print(x + 1); Serial.print(x + 1);
Serial.print(","); Serial.print(",");
Serial.print(presets[x].frequency); Serial.print(presets[x].frequency);
if (presets[x].memoryband == BAND_FM || presets[x].memoryband == BAND_OIRT) Serial.print("0"); if (presets[x].band == BAND_FM || presets[x].band == BAND_OIRT) Serial.print("0");
Serial.print(","); Serial.print(",");
Serial.print(presets[x].memorybw); Serial.print(presets[x].bw);
Serial.print(","); Serial.print(",");
Serial.print(presets[x].memoryms); Serial.print(presets[x].ms);
Serial.print(",");
Serial.print(String(presets[x].RDSPI).substring(0, 4));
Serial.print(",");
Serial.print(String(presets[x].RDSPS).substring(0, 8));
Serial.print("\n"); Serial.print("\n");
} }
} else if (data_str.startsWith("S")) { } else if (data_str.startsWith("S")) {
@@ -207,8 +211,22 @@ void Communication() {
if (commaPos != -1) { if (commaPos != -1) {
membw = data_str.substring(0, commaPos).toInt(); membw = data_str.substring(0, commaPos).toInt();
data_str.remove(0, commaPos + 1); data_str.remove(0, commaPos + 1);
commaPos = data_str.indexOf(',');
if (commaPos != -1) {
memms = data_str.substring(0, commaPos).toInt();
data_str.remove(0, commaPos + 1);
commaPos = data_str.indexOf(',');
if (commaPos != -1) {
String rdsPiStr = data_str.substring(0, commaPos);
char rdsPi[5];
rdsPiStr.toCharArray(rdsPi, sizeof(rdsPi));
data_str.remove(0, commaPos + 1);
commaPos = data_str.indexOf(',');
String rdsPs = data_str;
memms = data_str.toInt();
if (memfreq >= FREQ_LW_LOW_EDGE_MIN && memfreq <= FREQ_LW_HIGH_EDGE_MAX) { if (memfreq >= FREQ_LW_LOW_EDGE_MIN && memfreq <= FREQ_LW_HIGH_EDGE_MAX) {
memband = BAND_LW; memband = BAND_LW;
@@ -243,15 +261,30 @@ void Communication() {
if (error == 0) { if (error == 0) {
error |= (1 << 7); error |= (1 << 7);
memorypos = mempos; memorypos = mempos;
presets[mempos].memoryband = memband; presets[mempos].band = memband;
presets[mempos].frequency = memfreq; presets[mempos].frequency = memfreq;
presets[mempos].memorybw = membw; presets[mempos].bw = membw;
presets[mempos].memoryms = memms; presets[mempos].ms = memms;
EEPROM.writeByte(mempos + EE_PRESETS_BAND_START, memband); EEPROM.writeByte(mempos + EE_PRESETS_BAND_START, memband);
EEPROM.writeByte(mempos + EE_PRESET_BW_START, membw); EEPROM.writeByte(mempos + EE_PRESET_BW_START, membw);
EEPROM.writeByte(mempos + EE_PRESET_MS_START, memms); EEPROM.writeByte(mempos + EE_PRESET_MS_START, memms);
EEPROM.writeUInt((mempos * 4) + EE_PRESETS_START, memfreq); EEPROM.writeUInt((mempos * 4) + EE_PRESETS_FREQUENCY_START, memfreq);
for (int i = 0; i < 5; i++) {
presets[mempos].RDSPI[i] = rdsPi[i];
EEPROM.writeByte((mempos * 5) + i + EE_PRESETS_RDSPI_START, rdsPi[i]);
}
for (int i = 0; i < 9; i++) {
if (i < rdsPs.length()) {
presets[mempos].RDSPS[i] = rdsPs.charAt(i);
} else {
presets[mempos].RDSPS[i] = '\0';
}
EEPROM.writeByte((mempos * 9) + i + EE_PRESETS_RDSPS_START, presets[mempos].RDSPS[i]);
}
EEPROM.commit(); EEPROM.commit();
} }
Serial.print("S:" + String(error, DEC) + "\n"); Serial.print("S:" + String(error, DEC) + "\n");
@@ -260,6 +293,8 @@ void Communication() {
} }
} }
} }
}
}
if (RDSSPYUSB && Serial.available()) { if (RDSSPYUSB && Serial.available()) {
String data_str = Serial.readStringUntil('\n'); String data_str = Serial.readStringUntil('\n');
+7 -5
View File
@@ -198,7 +198,7 @@
#define EE_PRESETS_CNT 99 #define EE_PRESETS_CNT 99
#define EE_CHECKBYTE_VALUE 5 // 0 ~ 255,add new entry, change for new value #define EE_CHECKBYTE_VALUE 5 // 0 ~ 255,add new entry, change for new value
#define EE_TOTAL_CNT 827 #define EE_TOTAL_CNT 2213
#define EE_UINT16_FREQUENCY_FM 0 #define EE_UINT16_FREQUENCY_FM 0
#define EE_BYTE_VOLSET 4 #define EE_BYTE_VOLSET 4
#define EE_BYTE_STEREO 5 #define EE_BYTE_STEREO 5
@@ -285,7 +285,9 @@
#define EE_PRESETS_BAND_START 130 #define EE_PRESETS_BAND_START 130
#define EE_PRESET_BW_START 230 #define EE_PRESET_BW_START 230
#define EE_PRESET_MS_START 330 #define EE_PRESET_MS_START 330
#define EE_PRESETS_START 430 #define EE_PRESETS_FREQUENCY_START 430
#define EE_PRESETS_RDSPI_START 826
#define EE_PRESETS_RDSPS_START 1321
#define EE_PRESETS_FREQUENCY 0 #define EE_PRESETS_FREQUENCY 0
// End of EEPROM index defines // End of EEPROM index defines
@@ -297,9 +299,9 @@ static const char* const Skin[] = {"Essential", "NightSky"};
// Memory channel database // Memory channel database
typedef struct { typedef struct {
byte memorybw; byte bw;
byte memoryband; byte band;
bool memoryms; bool ms;
unsigned int frequency; unsigned int frequency;
char RDSPI[5]; char RDSPI[5];
char RDSPS[9]; char RDSPS[9];