diff --git a/include/nonvolatile.h b/include/nonvolatile.h index 3b3d0e3..c0a60cf 100644 --- a/include/nonvolatile.h +++ b/include/nonvolatile.h @@ -5,7 +5,7 @@ #define EE_PRESETS_CNT 99 // When set > 99 change the complete EEPROM adressing! #define EE_CHECKBYTE_VALUE 20 // 0 ~ 255,add new entry, change for new value #define EE_PRESETS_FREQUENCY 0 // Default value when memory channel should be skipped! -#define EE_TOTAL_CNT 2287 // Total occupied eeprom bytes, we can take 20K +#define EE_TOTAL_CNT 2288 // Total occupied eeprom bytes, we can take 20K #define EE_PRESETS_BAND_START 0 // 99 * 1 byte #define EE_PRESET_BW_START 99 // 99 * 1 byte @@ -127,6 +127,7 @@ #define EE_BYTE_CLOCKAMPM 2278 #define EE_UINT16_LOGCOUNTER 2279 #define EE_UINT16_PICTLOCK 2283 +#define EE_BYTE_CONTROLMODE 2285 // End of EEPROM index defines void StoreFrequency(); diff --git a/src/comms.cpp b/src/comms.cpp index 09d5cde..20bb944 100644 --- a/src/comms.cpp +++ b/src/comms.cpp @@ -997,10 +997,8 @@ void total_pc_control() { } break; case 6: { // Change baud if(len < 5) break; - uint32_t clock = ((uint32_t)data[1] << 24) | - ((uint32_t)data[2] << 16) | - ((uint32_t)data[3] << 8) | - ((uint32_t)data[4]); + uint32_t clock = ((uint32_t)data[1] << 24) | ((uint32_t)data[2] << 16) | + ((uint32_t)data[3] << 8) | ((uint32_t)data[4]); Serial.write(1); Serial.write(6); Serial.flush(); @@ -1020,10 +1018,14 @@ void total_pc_control() { Serial.write(8); for(uint16_t i = 0; i < data[3]; i++) Serial.write(EEPROM.read(address + i)); } break; + case 0xfe: { // Get EEPROM address for starting control mode on boot + Serial.write(2); + Serial.write((uint8_t)(EE_BYTE_CONTROLMODE >> 8)); + Serial.write(EE_BYTE_CONTROLMODE & 0xff); + } break; case 0xff: { // Another wake command Serial.write(1); Serial.write(0xff); - Serial.flush(true); } break; default: break; diff --git a/src/main.cpp b/src/main.cpp index e176aad..8d6b6a6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -198,6 +198,10 @@ void setup() { loadData(); + pinMode(MODEBUTTON, INPUT); + if(i2c_pc_control && digitalRead(MODEBUTTON) == HIGH) return; + else i2c_pc_control = false; + if (spispeed == 0) setAutoSpeedSPI(); else tft.setSPISpeed(spispeed); @@ -265,7 +269,6 @@ void setup() { tft.invertDisplay(!invertdisplay); pinMode(BANDBUTTON, INPUT); - pinMode(MODEBUTTON, INPUT); pinMode(BWBUTTON, INPUT); pinMode(ROTARY_BUTTON, INPUT); pinMode(ROTARY_PIN_A, INPUT); @@ -1075,6 +1078,10 @@ void loop() { if(i2c_pc_control) { total_pc_control(); if(i2c_pc_control) return; + if(EEPROM.readByte(EE_BYTE_CONTROLMODE)) { + saveData(); + esp_restart(); + } } handleWiFi(); diff --git a/src/nonvolatile.cpp b/src/nonvolatile.cpp index 32c09a7..eb081b6 100644 --- a/src/nonvolatile.cpp +++ b/src/nonvolatile.cpp @@ -125,6 +125,7 @@ void saveData() { EEPROM.writeByte(EE_BYTE_AUTODST, autoDST); EEPROM.writeByte(EE_BYTE_CLOCKAMPM, clockampm); EEPROM.writeUInt(EE_UINT16_PICTLOCK, radio.rds.PICTlock); + EEPROM.writeByte(EE_BYTE_CONTROLMODE, 0); // Always 0 EEPROM.commit(); } @@ -239,6 +240,7 @@ void loadData() { clockampm = EEPROM.readByte(EE_BYTE_CLOCKAMPM); logcounter = EEPROM.readUInt(EE_UINT16_LOGCOUNTER); radio.rds.PICTlock = EEPROM.readUInt(EE_UINT16_PICTLOCK); + i2c_pc_control = i2c_pc_control_init = EEPROM.readByte(EE_BYTE_CONTROLMODE); } void DefaultSettings() { @@ -345,6 +347,7 @@ void DefaultSettings() { EEPROM.writeByte(EE_BYTE_AUTODST, 1); EEPROM.writeByte(EE_BYTE_CLOCKAMPM, 0); EEPROM.writeUInt(EE_UINT16_PICTLOCK, 0); + EEPROM.writeByte(EE_BYTE_CONTROLMODE, 0); EEPROM.writeByte(EE_BYTE_SPISPEED, 0);