diff --git a/.gitignore b/.gitignore index 36ae1e1a..d8d13775 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ Bruce3_*.bin bruce.conf _*.sh tmp +ISSUES.md diff --git a/src/core/eeprom.cpp b/src/core/eeprom.cpp new file mode 100644 index 00000000..6dfd5e0d --- /dev/null +++ b/src/core/eeprom.cpp @@ -0,0 +1,171 @@ +#include "eeprom.h" +#include "core/globals.h" +#include "core/settings.h" + + +/********************************************************************* +** Function: load_eeprom +** Load EEPROM data +*********************************************************************/ +void load_eeprom() { + EEPROM.begin(EEPROMSIZE); // open eeprom + + rotation = EEPROM.read(EEPROM_ROT); + dimmerSet = EEPROM.read(EEPROM_DIMMER); + bright = EEPROM.read(EEPROM_BRIGHT); + IrTx = EEPROM.read(EEPROM_IR_TX); + IrRx = EEPROM.read(EEPROM_IR_RX); + RfTx = EEPROM.read(EEPROM_RF_TX); + RfRx = EEPROM.read(EEPROM_RF_RX); + tmz = EEPROM.read(EEPROM_TMZ); + FGCOLOR = EEPROM.read(EEPROM_FGCOLOR0) << 8 | EEPROM.read(EEPROM_FGCOLOR1); + RfModule = EEPROM.read(EEPROM_RF_MODULE); + RfidModule = EEPROM.read(EEPROM_RFID_MODULE); + + log_i("\ + \n*-*EEPROM Settings*-* \ + \n- rotation =%03d, \ + \n- dimmerSet =%03d, \ + \n- Brightness=%03d, \ + \n- IR Tx Pin =%03d, \ + \n- IR Rx Pin =%03d, \ + \n- RF Tx Pin =%03d, \ + \n- RF Rx Pin =%03d, \ + \n- Time Zone =%03d, \ + \n- FGColor =0x%04X \ + \n- RfModule =%03d, \ + \n- RfidModule=%03d, \ + \n*-*-*-*-*-*-*-*-*-*-*", + rotation, dimmerSet, bright,IrTx, IrRx, RfTx, RfRx, tmz, FGCOLOR, RfModule, RfidModule + ); + + if ( + rotation > 3 + || dimmerSet > 60 + || bright > 100 + || IrTx > 100 + || IrRx > 100 + || RfRx > 100 + || RfTx > 100 + || tmz > 24 + ) { + rotation = ROTATION; + dimmerSet = 10; + bright = 100; + IrTx = LED; + IrRx = GROVE_SCL; + RfTx = GROVE_SDA; + RfRx = GROVE_SCL; + FGCOLOR = 0xA80F; + tmz = 0; + RfModule = M5_RF_MODULE; + RfidModule = M5_RFID2_MODULE; + + EEPROM.write(EEPROM_ROT, rotation); + EEPROM.write(EEPROM_DIMMER, dimmerSet); + EEPROM.write(EEPROM_BRIGHT, bright); + EEPROM.write(EEPROM_IR_TX, IrTx); + EEPROM.write(EEPROM_IR_RX, IrRx); + EEPROM.write(EEPROM_RF_TX, RfTx); + EEPROM.write(EEPROM_RF_RX, RfRx); + EEPROM.write(EEPROM_TMZ, tmz); + EEPROM.write(EEPROM_FGCOLOR0, int((FGCOLOR >> 8) & 0x00FF)); + EEPROM.write(EEPROM_FGCOLOR1, int(FGCOLOR & 0x00FF)); + EEPROM.write(EEPROM_RF_MODULE, RfModule); + EEPROM.write(EEPROM_RFID_MODULE, RfidModule); + EEPROM.writeString(20,""); + + EEPROM.commit(); // Store data to EEPROM + log_w("One of the eeprom values is invalid"); + } + + EEPROM.end(); + + setBrightness(bright, false); +} + + +/********************************************************************* +** Function: write_eeprom +** write EEPROM data +*********************************************************************/ +void write_eeprom(int address, uint8_t val) { + Serial.printf("Writing EEPROM address %d value %d\n", address, val); + EEPROM.begin(EEPROMSIZE); // open eeprom + EEPROM.write(address, val); //set the byte + EEPROM.commit(); // Store data to EEPROM + EEPROM.end(); // Free EEPROM memory + Serial.println("Write EEPROM success"); +} + + +/********************************************************************* +** Function: write_eeprom_string +** write EEPROM string data +*********************************************************************/ +void write_eeprom_string(int address, String val) { + Serial.printf("Writing EEPROM address %d value %d\n", address, val); + EEPROM.begin(EEPROMSIZE); // open eeprom + EEPROM.writeString(address, val); //set the byte + EEPROM.commit(); // Store data to EEPROM + EEPROM.end(); // Free EEPROM memory + Serial.println("Write EEPROM success"); +} + + +/********************************************************************* +** Function: read_eeprom +** read EEPROM data +*********************************************************************/ +uint8_t read_eeprom(int address) { + Serial.printf("Reading EEPROM address %d\n", address); + EEPROM.begin(EEPROMSIZE); // open eeprom + uint8_t value = EEPROM.read(address); //set the byte + EEPROM.end(); // Free EEPROM memory + Serial.printf("EEPROM value = %d\n", value); + return value; +} + + +/********************************************************************* +** Function: read_eeprom_string +** read EEPROM string data +*********************************************************************/ +String read_eeprom_string(int address) { + Serial.printf("Reading EEPROM address %d\n", address); + EEPROM.begin(EEPROMSIZE); // open eeprom + String value = EEPROM.readString(address); //set the byte + EEPROM.end(); // Free EEPROM memory + Serial.println("EEPROM value = "+value); + return value; +} + + +void sync_eeprom_values(void) { + int count = 0; + + EEPROM.begin(EEPROMSIZE); // open eeprom + + if(EEPROM.read(EEPROM_ROT) != rotation) { EEPROM.write(EEPROM_ROT, rotation); count++; } + if(EEPROM.read(EEPROM_DIMMER) != dimmerSet) { EEPROM.write(EEPROM_DIMMER, dimmerSet); count++; } + if(EEPROM.read(EEPROM_BRIGHT) != bright) { EEPROM.write(EEPROM_BRIGHT, bright); count++; } + + if(EEPROM.read(EEPROM_IR_TX) != IrTx) { EEPROM.write(EEPROM_IR_TX, IrTx); count++; } + if(EEPROM.read(EEPROM_IR_RX) != IrRx) { EEPROM.write(EEPROM_IR_RX, IrRx); count++; } + if(EEPROM.read(EEPROM_RF_TX) != RfTx) { EEPROM.write(EEPROM_RF_TX, RfTx); count++; } + if(EEPROM.read(EEPROM_RF_RX) != RfRx) { EEPROM.write(EEPROM_RF_RX, RfRx); count++; } + if(EEPROM.read(EEPROM_TMZ) != tmz) { EEPROM.write(EEPROM_TMZ, tmz); count++; } + if(EEPROM.read(EEPROM_FGCOLOR0) !=(int((FGCOLOR >> 8) & 0x00FF))) {EEPROM.write(EEPROM_FGCOLOR0, int((FGCOLOR >> 8) & 0x00FF)); count++; } + if(EEPROM.read(EEPROM_FGCOLOR1) != int(FGCOLOR & 0x00FF)) { EEPROM.write(EEPROM_FGCOLOR1, int(FGCOLOR & 0x00FF)); count++; } + if(EEPROM.read(EEPROM_RF_MODULE) != RfModule) { EEPROM.write(EEPROM_RF_MODULE, RfModule); count++; } + if(EEPROM.read(EEPROM_RFID_MODULE) != RfidModule) { EEPROM.write(EEPROM_RFID_MODULE, RfidModule); count++; } + // TODO: add RfFreq + + //If something changed, saves the changes on EEPROM. + if(count > 0) { + if(!EEPROM.commit()) log_i("fail to write EEPROM"); // Store data to EEPROM + else log_i("Wrote new conf to EEPROM"); + } + + EEPROM.end(); +} diff --git a/src/core/eeprom.h b/src/core/eeprom.h new file mode 100644 index 00000000..e326e2e9 --- /dev/null +++ b/src/core/eeprom.h @@ -0,0 +1,58 @@ +#ifndef __BRUCE_EEPROM_H__ +#define __BRUCE_EEPROM_H__ + +#include +#include + + +/* +EEPROM ADDRESSES MAP + +0 Rotation 16 32 Pass 48 Pass 64 Pass 80 Pass 96 112 +1 Dim(N/L) 17 33 Pass 49 Pass 65 Pass 81 Pass 97 113 +2 Bright 18 34 Pass 50 Pass 66 Pass 82 Pass 98 114 +3 - 19 35 Pass 51 Pass 67 Pass 83 Pass 99 115 +4 - 20 Pass 36 Pass 52 Pass 68 Pass 84 Pass 100 116 +5 - 21 Pass 37 Pass 53 Pass 69 Pass 85 101 117 +6 IrTX 22 Pass 38 Pass 54 Pass 70 Pass 86 102 118 (L-odd) +7 IrRx 23 Pass 39 Pass 55 Pass 71 Pass 87 103 119 (L-odd) +8 RfTX 24 Pass 40 Pass 56 Pass 72 Pass 88 104 120 (L-even) +9 RfRx 25 Pass 41 Pass 57 Pass 73 Pass 89 105 121 (L-even) +10 TimeZone 26 Pass 42 Pass 58 Pass 74 Pass 90 106 122 (L-BGCOLOR) +11 FGCOLOR 27 Pass 43 Pass 59 Pass 75 Pass 91 107 123 (L-BGCOLOR) +12 FGCOLOR 28 Pass 44 Pass 60 Pass 76 Pass 92 108 124 (L-FGCOLOR) +13 RfModule 29 Pass 45 Pass 61 Pass 77 Pass 93 109 125 (L-FGCOLOR) +14 RfidModule 30 Pass 46 Pass 62 Pass 78 Pass 94 110 126 (L-AskSpiffs) +15 31 Pass 47 Pass 63 Pass 79 Pass 95 111 127 (L-OnlyBins) + +From 1 to 5: Nemo shared addresses +(L -*) stands for Launcher addresses +*/ + + +#define EEPROM_ROT (0) +#define EEPROM_DIMMER (1) +#define EEPROM_BRIGHT (2) +#define EEPROM_IR_TX (6) +#define EEPROM_IR_RX (7) +#define EEPROM_RF_TX (8) +#define EEPROM_RF_RX (9) +#define EEPROM_TMZ (10) +#define EEPROM_FGCOLOR0 (11) +#define EEPROM_FGCOLOR1 (12) +#define EEPROM_RF_MODULE (13) +#define EEPROM_RFID_MODULE (14) +#define EEPROM_PWD (20) + + +void load_eeprom(void); + +void write_eeprom(int address, uint8_t val); +void write_eeprom_string(int address, String val); + +uint8_t read_eeprom(int address); +String read_eeprom_string(int address); + +void sync_eeprom_values(void); + +#endif \ No newline at end of file diff --git a/src/core/globals.cpp b/src/core/globals.cpp index 38796c12..262c3621 100644 --- a/src/core/globals.cpp +++ b/src/core/globals.cpp @@ -17,49 +17,7 @@ while(1) { loopOptions(options); ... } - -/********************************************************************* -** Function: readFGColorFromEEPROM -** reads the foreground color from EEPROM -** if the value is not set, it will use the default value -**********************************************************************/ -void readFGCOLORFromEEPROM() { - int colorEEPROM; - - EEPROM.begin(EEPROMSIZE); - EEPROM.get(5, colorEEPROM); - - switch(colorEEPROM){ - case 0: - FGCOLOR = TFT_PURPLE+0x3000; - break; - case 1: - FGCOLOR = TFT_WHITE; - break; - case 2: - FGCOLOR = TFT_RED; - break; - case 3: - FGCOLOR = TFT_DARKGREEN; - break; - case 4: - FGCOLOR = TFT_BLUE; - break; - case 5: - FGCOLOR = TFT_YELLOW; - break; - case 7: - FGCOLOR = TFT_ORANGE; - break; - default: - FGCOLOR = TFT_PURPLE+0x3000; - EEPROM.put(5, 0); - EEPROM.commit(); - break; - - } - EEPROM.end(); // Free EEPROM memory -} +*/ void backToMenu() { diff --git a/src/core/globals.h b/src/core/globals.h index 4960650c..9187902b 100644 --- a/src/core/globals.h +++ b/src/core/globals.h @@ -14,7 +14,6 @@ extern char16_t FGCOLOR; #include #include #include -#include #include #if defined (STICK_C_PLUS) || defined (STICK_C) @@ -136,8 +135,6 @@ extern int dimmerSet; extern int devMode; extern int soundEnabled; -void readFGCOLORFromEEPROM(); - void backToMenu(); void updateTimeStr(struct tm timeInfo); @@ -157,5 +154,10 @@ enum RFIDModules { PN532_SPI_MODULE = 2, }; +enum RFModules { + M5_RF_MODULE = 0, + CC1101_SPI_MODULE = 1, +}; + void setup_gpio(); diff --git a/src/core/serialcmds.cpp b/src/core/serialcmds.cpp index 477b13a1..7963577c 100644 --- a/src/core/serialcmds.cpp +++ b/src/core/serialcmds.cpp @@ -92,7 +92,7 @@ String readSmallFileFromSerialAlt() { #include void serialcmds_loop(void* pvParameters) { - Serial.begin (115200); + Serial.begin (115200); while (1) { handleSerialCommands(); //delay (500); // wait for half a second @@ -102,7 +102,7 @@ void serialcmds_loop(void* pvParameters) { void startSerialCommandsHandlerTask() { TaskHandle_t serialcmdsTaskHandle; - + xTaskCreatePinnedToCore ( serialcmds_loop, // Function to implement the task "serialcmds", // Name of the task (any string) @@ -149,7 +149,7 @@ void SerialPrintHexString(uint64_t val) { void handleSerialCommands() { // read and process a single command - + String cmd_str; if (Serial.available() >= 1) { @@ -158,18 +158,18 @@ void handleSerialCommands() { // try again on next iteration return; } - + bool r = processSerialCommand(cmd_str); if(r) setup_gpio(); // temp fix for menu inf. loop else Serial.println("failed: " + cmd_str); - + returnToMenu = true; // forced menu redrawn } bool processSerialCommand(String cmd_str) { // return true on success, false on error // TODO: rewrite using https://github.com/SpacehuhnTech/SimpleCLI (auto-generated help and args checking) - + cmd_str.trim(); if(cmd_str == "" || cmd_str.startsWith("#") || cmd_str.startsWith(";") || cmd_str.startsWith("/")) { @@ -201,7 +201,7 @@ bool processSerialCommand(String cmd_str) { // switch on cmd_str if(cmd_str.startsWith("ir") ) { - + if(cmd_str.startsWith("ir rx")) { IrRead* i = NULL; // avoid calling the constructor here if(cmd_str == "ir rx") i = new IrRead(true); // true -> headless mode @@ -214,7 +214,7 @@ bool processSerialCommand(String cmd_str) { delete i; return true; } - + if(cmd_str.startsWith("ir tx")) { // make sure it is initted gsetIrTxPin(false); @@ -226,7 +226,7 @@ bool processSerialCommand(String cmd_str) { // e.g. ir tx NEC 04000000 08000000 } //TODO: if(cmd_str.startsWith("ir tx raw ")){ - + if(cmd_str.startsWith("ir tx nec ")){ String address = cmd_str.substring(10, 10+8); String command = cmd_str.substring(19, 19+8); @@ -248,7 +248,7 @@ bool processSerialCommand(String cmd_str) { //if(cmd_str.startsWith("ir tx sirc")){ //if(cmd_str.startsWith("ir tx samsung")){ //if(cmd_str.startsWith("ir tx raw")){ - + if(cmd_str.startsWith("ir tx_from_file ")){ // example: ir tx_from_file LG_AKB72915206_power.ir String filepath = cmd_str.substring(strlen("ir tx_from_file ")); @@ -260,7 +260,7 @@ bool processSerialCommand(String cmd_str) { // else file not found return false; } - + if(cmd_str.startsWith("ir tx_from_buffer")){ if(!(setupPsramFs())) return false; String txt = readSmallFileFromSerial(); @@ -273,7 +273,7 @@ bool processSerialCommand(String cmd_str) { PSRamFS.remove(tmpfilepath); // TODO: keep cached? return r; } - + if(cmd_str.startsWith("irsend")) { // tasmota json command https://tasmota.github.io/docs/Tasmota-IR/#sending-ir-commands // e.g. IRSend {"Protocol":"NEC","Bits":32,"Data":"0x20DF10EF"} @@ -331,8 +331,8 @@ bool processSerialCommand(String cmd_str) { } // end of ir commands if(cmd_str.startsWith("rf") || cmd_str.startsWith("subghz" )) { - - if(cmd_str.startsWith("subghz rx")) { + + if(cmd_str.startsWith("subghz rx")) { /* const char* args = cmd_str.c_str() + strlen("subghz rx"); float frequency=RfFreq; // global default @@ -376,7 +376,7 @@ bool processSerialCommand(String cmd_str) { if(!f) return false; f.write((const uint8_t*) txt.c_str(), txt.length()); f.close(); - //if(PSRamFS.exists(filepath)) + //if(PSRamFS.exists(filepath)) bool r = txSubFile(&PSRamFS, tmpfilepath); PSRamFS.remove(tmpfilepath); // TODO: keep cached? return r; @@ -400,7 +400,7 @@ bool processSerialCommand(String cmd_str) { deinitRfModule(); return true; } - + if(cmd_str.startsWith("rfsend")) { // tasmota json command https://tasmota.github.io/docs/RF-Protocol/ // e.g. RfSend {"Data":"0x447503","Bits":24,"Protocol":1,"Pulse":174,"Repeat":10} // on @@ -439,7 +439,7 @@ bool processSerialCommand(String cmd_str) { //Serial.println(dataStr); //SerialPrintHexString(data); //Serial.println(bits); - + if(!initRfModule("tx")) return false; RCSwitch_send(data, bits, pulse, protocol, repeat); @@ -448,7 +448,7 @@ bool processSerialCommand(String cmd_str) { return true; } } // endof rf - + #if defined(USB_as_HID) // badusb available if(cmd_str.startsWith("badusb run_from_file ")) { @@ -466,8 +466,8 @@ bool processSerialCommand(String cmd_str) { key_input(*fs, filepath); //TODO: need to reinit serial when finished //Kb.end(); - //USB.~ESPUSB(); // Explicit call to destructor - //Serial.begin(115200); + //USB.~ESPUSB(); // Explicit call to destructor + //Serial.begin(115200); return true; } if(cmd_str == "badusb run_from_buffer") { @@ -485,7 +485,7 @@ bool processSerialCommand(String cmd_str) { return true; } #endif - + #if defined(HAS_NS4168_SPKR) || defined(BUZZ_PIN) if(cmd_str.startsWith("tone") || cmd_str.startsWith("beep")) { // || cmd_str.startsWith("music_player beep" ) const char* args = cmd_str.c_str() + 4; @@ -500,7 +500,7 @@ bool processSerialCommand(String cmd_str) { return true; } #endif - + #if defined(HAS_NS4168_SPKR) //M5StickCs doesn't have speakers.. they have buzzers on pin 02 that only beeps in different frequencies if(cmd_str.startsWith("music_player " ) ) { // || cmd_str.startsWith("play " ) String song = cmd_str.substring(13); @@ -508,7 +508,7 @@ bool processSerialCommand(String cmd_str) { // RTTTL player // music_player mario:d=4,o=5,b=100:16e6,16e6,32p,8e6,16c6,8e6,8g6,8p,8g,8p,8c6,16p,8g,16p,8e,16p,8a,8b,16a#,8a,16g.,16e6,16g6,8a6,16f6,8g6,8e6,16c6,16d6,8b,16p,8c6,16p,8g,16p,8e,16p,8a,8b,16a#,8a,16g.,16e6,16g6,8a6,16f6,8g6,8e6,16c6,16d6,8b,8p,16g6,16f#6,16f6,16d#6,16p,16e6,16p,16g#,16a,16c6,16p,16a,16c6,16d6,8p,16g6,16f#6,16f6,16d#6,16p,16e6,16p,16c7,16p,16c7,16c7,p,16g6,16f#6,16f6,16d#6,16p,16e6,16p,16g#,16a,16c6,16p,16a,16c6,16d6,8p,16d#6,8p,16d6,8p,16c6 return playAudioRTTTLString(song); - + } else if(song.indexOf(".") != -1) { // try to open "song" as a file // e.g. music_player boot.wav @@ -609,7 +609,7 @@ bool processSerialCommand(String cmd_str) { return true; } -/* +/* // WIP https://github.com/pr3y/Bruce/issues/162#issuecomment-2308788115 if(cmd_str.startsWith("serial2 write")) { @@ -619,7 +619,7 @@ bool processSerialCommand(String cmd_str) { Serial2.flush(); return true; } - + if(cmd_str.startsWith("serial2 read")) { setupBruceDaughterboard(); String curr_line = ""; @@ -715,7 +715,7 @@ bool processSerialCommand(String cmd_str) { getConfigs(); // recreate config file if it does not exists return true; } - + if(cmd_str.startsWith("settings")) { JsonObject setting = settings[0]; String args = cmd_str.substring(strlen("settings ")); @@ -755,19 +755,23 @@ bool processSerialCommand(String cmd_str) { if(setting_name=="tmz") IrRx = setting_value.toInt(); if(setting_name=="wui_usr") wui_usr = setting_value; if(setting_name=="wui_pwd") wui_pwd = setting_value; + if(setting_name=="RfidModule") RfidModule = setting_value.toInt(); + if(setting_name=="devMode") devMode = setting_value.toInt(); + if(setting_name=="soundEnabled") soundEnabled = setting_value.toInt(); + if(setting_name=="wigleBasicToken") wigleBasicToken = setting_value; saveConfigs(); serializeJsonPretty(settings, Serial); Serial.println(""); return true; } - + if(cmd_str == "info device" || cmd_str == "!") { Serial.print("Bruce v"); Serial.println(BRUCE_VERSION); Serial.println(GIT_COMMIT_HASH); Serial.printf("SDK: %s\n", ESP.getSdkVersion()); // TODO: read mac addresses https://lastminuteengineers.com/esp32-mac-address-tutorial/ - + // https://github.com/espressif/arduino-esp32/blob/master/libraries/ESP32/examples/ChipID/GetChipID/GetChipID.ino //Serial.printf("Chip is %s (revision v%d)\n", ESP.getChipModel(), ESP.getChipRevision()); //Serial.printf("Detected flash size: %d\n", ESP.getFlashChipSize()); @@ -776,7 +780,7 @@ bool processSerialCommand(String cmd_str) { // Features: WiFi, BLE, Embedded Flash 8MB (GD) // Crystal is 40MHz // MAC: 24:58:7c:5b:24:5c - + if (wifiConnected) { Serial.println("wifi: connected"); Serial.println("ip: " + wifiIP); // read global var @@ -785,7 +789,7 @@ bool processSerialCommand(String cmd_str) { } return true; } - + if(cmd_str == "free") { // report free memory Serial.print("Total heap: "); @@ -800,7 +804,7 @@ bool processSerialCommand(String cmd_str) { } return true; } - + if(cmd_str == "i2c") { // scan for connected i2c modules // derived from https://learn.adafruit.com/scanning-i2c-addresses/arduino @@ -841,9 +845,9 @@ bool processSerialCommand(String cmd_str) { return true; } } - + // "storage" cmd to manage files https://docs.flipper.net/development/cli/#Xgais - + if(cmd_str.startsWith("storage read ") || cmd_str.startsWith("storage md5 ") || cmd_str.startsWith("storage crc32 ")) { //String filepath = cmd_str.substring(strlen("storage read ")); String filepath = cmd_str.substring(cmd_str.indexOf(" ", strlen("storage md5"))); @@ -884,13 +888,13 @@ bool processSerialCommand(String cmd_str) { //Serial.println(filepath); //Serial.println(file.size()); //Serial.println(file.getLastWrite()); - + //ALT.: use directly https://github.com/espressif/arduino-esp32/blob/66c9c0b1a6a36b85d27cdac0fb52098368de1a09/libraries/FS/src/vfs_api.cpp#L348#L348 // missing in Core2? https://github.com/pr3y/Bruce/actions/runs/10469748217/job/28993441958?pr=196 /* #if !defined(M5STACK) - if(SD.exists(filepath)) filepath = "/sd" + filepath; - else if(LittleFS.exists(filepath)) filepath = "/littlefs" + filepath; + if(SD.exists(filepath)) filepath = "/sd" + filepath; + else if(LittleFS.exists(filepath)) filepath = "/littlefs" + filepath; else return false; // not found struct stat st; memset(&st, 0, sizeof(struct stat)); @@ -900,7 +904,7 @@ bool processSerialCommand(String cmd_str) { Serial.print("File: "); Serial.print(filepath); Serial.println(""); - + Serial.print("Size: "); //Serial.print(st.st_size); Serial.print(file.size()); @@ -911,12 +915,12 @@ bool processSerialCommand(String cmd_str) { else Serial.print("regular file"); Serial.println(""); - + Serial.print("Modify: "); //Serial.print(st.st_mtime); // TODO: parse to localtime Serial.print(file.getLastWrite()); // TODO: parse to localtime Serial.println(""); - + //Serial.println(st.st_mode); //Serial.println(st.st_dev); //Serial.println(st.st_ctime); @@ -990,7 +994,7 @@ bool processSerialCommand(String cmd_str) { Serial.println("file written: " + filepath); return true; } - + if(cmd_str.startsWith("storage rename ")) { // storage rename HelloWorld.txt HelloWorld2.txt String args = cmd_str.substring(strlen("storage rename ")); @@ -1043,7 +1047,7 @@ bool processSerialCommand(String cmd_str) { PSRamFS.remove(tmpfilepath); return r; } - + if(cmd_str.startsWith("js ")) { String filepath = cmd_str.substring(strlen("js ")); filepath.trim(); @@ -1063,7 +1067,7 @@ bool processSerialCommand(String cmd_str) { // else return true; } - + if(cmd_str.startsWith("crypto ")) { // crypto decrypt_from_file passwords/test.txt.enc 123 // crypto encrypt_to_file passwords/test.txt.enc 123 @@ -1082,7 +1086,7 @@ bool processSerialCommand(String cmd_str) { cachedPassword = password; // avoid interactive prompt //Serial.println(filepath); //Serial.println(password); - + if(cmd_str.startsWith("crypto decrypt_from_file")) { FS* fs = NULL; if(SD.exists(filepath)) fs = &SD; @@ -1108,7 +1112,7 @@ bool processSerialCommand(String cmd_str) { return true; } } - + if(cmd_str == "uptime") { // https://github.com/espressif/arduino-esp32/blob/66c9c0b1a6a36b85d27cdac0fb52098368de1a09/libraries/WebServer/examples/AdvancedWebServer/AdvancedWebServer.ino#L64 int sec = millis() / 1000; @@ -1120,7 +1124,7 @@ bool processSerialCommand(String cmd_str) { Serial.println(temp); return true; } - + if(cmd_str == "date") { if (clock_set) { Serial.print("Current time: "); @@ -1144,14 +1148,14 @@ bool processSerialCommand(String cmd_str) { return false; } } - + /* WIP if(cmd_str.startsWith("rtl433")) { // https://github.com/pr3y/Bruce/issues/192 rtl433_setup(); return rtl433_loop(10000*3); } - + if(cmd_str.startsWith("mass_storage")) { // WIP https://github.com/pr3y/Bruce/issues/210 // https://github.com/espressif/arduino-esp32/blob/master/libraries/SD_MMC/examples/SD2USBMSC/SD2USBMSC.ino @@ -1163,9 +1167,9 @@ bool processSerialCommand(String cmd_str) { while(loop_rx); return true; }*/ - + // TODO: help - + // TODO: more commands https://docs.flipper.net/development/cli#0Z9fs Serial.println("unsupported serial command: " + cmd_str); diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 700985c8..f0431191 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -5,40 +5,13 @@ #include "mykeyboard.h" #include "sd_functions.h" #include "powerSave.h" -#include +#include "eeprom.h" #include "modules/rf/rf.h" // for initRfModule #ifdef USE_CC1101_VIA_SPI #include #endif -/* -EEPROM ADDRESSES MAP - - -0 Rotation 16 32 Pass 48 Pass 64 Pass 80 Pass 96 112 -1 Dim(N/L) 17 33 Pass 49 Pass 65 Pass 81 Pass 97 113 -2 Bright 18 34 Pass 50 Pass 66 Pass 82 Pass 98 114 -3 - 19 35 Pass 51 Pass 67 Pass 83 Pass 99 115 -4 - 20 Pass 36 Pass 52 Pass 68 Pass 84 Pass 100 116 -5 - 21 Pass 37 Pass 53 Pass 69 Pass 85 101 117 -6 IrTX 22 Pass 38 Pass 54 Pass 70 Pass 86 102 118 (L-odd) -7 IrRx 23 Pass 39 Pass 55 Pass 71 Pass 87 103 119 (L-odd) -8 RfTX 24 Pass 40 Pass 56 Pass 72 Pass 88 104 120 (L-even) -9 RfRx 25 Pass 41 Pass 57 Pass 73 Pass 89 105 121 (L-even) -10 TimeZone 26 Pass 42 Pass 58 Pass 74 Pass 90 106 122 (L-BGCOLOR) -11 FGCOLOR 27 Pass 43 Pass 59 Pass 75 Pass 91 107 123 (L-BGCOLOR) -12 FGCOLOR 28 Pass 44 Pass 60 Pass 76 Pass 92 108 124 (L-FGCOLOR) -13 RfModule 29 Pass 45 Pass 61 Pass 77 Pass 93 109 125 (L-FGCOLOR) -14 RfidModule 30 Pass 46 Pass 62 Pass 78 Pass 94 110 126 (L-AskSpiffs) -15 31 Pass 47 Pass 63 Pass 79 Pass 95 111 127 (L-OnlyBins) - -From 1 to 5: Nemo shared addresses -(L -*) stands for Launcher addresses - - - -*/ /********************************************************************* ** Function: setBrightness @@ -67,10 +40,7 @@ void setBrightness(int brightval, bool save) { if(save){ bright=brightval; - EEPROM.begin(EEPROMSIZE); // open eeprom - EEPROM.write(2, brightval); //set the byte - EEPROM.commit(); // Store data to EEPROM - EEPROM.end(); // Free EEPROM memory + write_eeprom(EEPROM_BRIGHT, brightval); } } @@ -79,9 +49,7 @@ void setBrightness(int brightval, bool save) { ** save brightness value into EEPROM **********************************************************************/ void getBrightness() { - EEPROM.begin(EEPROMSIZE); - bright = EEPROM.read(2); - EEPROM.end(); // Free EEPROM memory + bright = read_eeprom(EEPROM_BRIGHT); if(bright>100) { bright = 100; #if defined(STICK_C_PLUS2) || defined(CARDPUTER) @@ -120,8 +88,7 @@ void getBrightness() { ** get orientation from EEPROM **********************************************************************/ int gsetRotation(bool set){ - EEPROM.begin(EEPROMSIZE); - int getRot = EEPROM.read(0); + int getRot = read_eeprom(EEPROM_ROT); int result = ROTATION; if(getRot==1 && set) result = 3; @@ -135,10 +102,8 @@ int gsetRotation(bool set){ if(set) { rotation = result; tft.setRotation(result); - EEPROM.write(0, result); // Left rotation - EEPROM.commit(); + write_eeprom(EEPROM_ROT, result); } - EEPROM.end(); // Free EEPROM memory returnToMenu=true; return result; } @@ -151,10 +116,7 @@ void setDimmerTime(int dimmerTime) { if(dimmerTime>60 || dimmerTime<0) dimmerTime = 0; dimmerSet=dimmerTime; - EEPROM.begin(EEPROMSIZE); // open eeprom - EEPROM.write(1, dimmerSet); //set the byte - EEPROM.commit(); // Store data to EEPROM - EEPROM.end(); // Free EEPROM memory + write_eeprom(EEPROM_DIMMER, dimmerSet); } /********************************************************************* @@ -162,9 +124,7 @@ void setDimmerTime(int dimmerTime) { ** Get dimmerSet value from EEPROM **********************************************************************/ void getDimmerSet() { - EEPROM.begin(EEPROMSIZE); - dimmerSet = EEPROM.read(1); - EEPROM.end(); // Free EEPROM memory + dimmerSet = read_eeprom(EEPROM_DIMMER); if(dimmerSet>60 || dimmerSet<0) setDimmerTime(0); } @@ -242,37 +202,33 @@ void setDimmerTimeMenu() { ** Set and store main UI color **********************************************************************/ void setUIColor(){ - EEPROM.begin(EEPROMSIZE); int idx=0; - if(FGCOLOR==0xA80F) idx=0; - else if(FGCOLOR==TFT_WHITE) idx=1; - else if(FGCOLOR==TFT_RED) idx=2; - else if(FGCOLOR==TFT_DARKGREEN) idx=3; - else if(FGCOLOR==TFT_BLUE) idx=4; - else if(FGCOLOR==TFT_YELLOW) idx=5; - else if(FGCOLOR==TFT_MAGENTA) idx=6; - else if(FGCOLOR==TFT_ORANGE) idx=7; - - options = { - {"Default", [&]() { FGCOLOR=0xA80F; }, FGCOLOR==0xA80F ? true:false}, - {"White", [&]() { FGCOLOR=TFT_WHITE; }, FGCOLOR==TFT_WHITE ? true:false}, - {"Red", [&]() { FGCOLOR=TFT_RED; }, FGCOLOR==TFT_RED ? true:false}, - {"Green", [&]() { FGCOLOR=TFT_DARKGREEN; }, FGCOLOR==TFT_DARKGREEN ? true:false}, - {"Blue", [&]() { FGCOLOR=TFT_BLUE; }, FGCOLOR==TFT_BLUE ? true:false}, - {"Yellow", [&]() { FGCOLOR=TFT_YELLOW; }, FGCOLOR==TFT_YELLOW ? true:false}, - {"Magenta", [&]() { FGCOLOR=TFT_MAGENTA; }, FGCOLOR==TFT_MAGENTA ? true:false}, - {"Orange", [&]() { FGCOLOR=TFT_ORANGE; }, FGCOLOR==TFT_ORANGE ? true:false}, - {"Main Menu", [=]() { backToMenu(); }}, - }; - delay(200); - loopOptions(options, idx); - tft.setTextColor(TFT_BLACK, FGCOLOR); + if(FGCOLOR==0xA80F) idx=0; + else if(FGCOLOR==TFT_WHITE) idx=1; + else if(FGCOLOR==TFT_RED) idx=2; + else if(FGCOLOR==TFT_DARKGREEN) idx=3; + else if(FGCOLOR==TFT_BLUE) idx=4; + else if(FGCOLOR==TFT_YELLOW) idx=5; + else if(FGCOLOR==TFT_MAGENTA) idx=6; + else if(FGCOLOR==TFT_ORANGE) idx=7; - EEPROM.begin(EEPROMSIZE); - EEPROM.write(11, int((FGCOLOR >> 8) & 0x00FF)); - EEPROM.write(12, int(FGCOLOR & 0x00FF)); - EEPROM.commit(); - EEPROM.end(); + options = { + {"Default", [&]() { FGCOLOR=0xA80F; }, FGCOLOR==0xA80F ? true:false}, + {"White", [&]() { FGCOLOR=TFT_WHITE; }, FGCOLOR==TFT_WHITE ? true:false}, + {"Red", [&]() { FGCOLOR=TFT_RED; }, FGCOLOR==TFT_RED ? true:false}, + {"Green", [&]() { FGCOLOR=TFT_DARKGREEN; }, FGCOLOR==TFT_DARKGREEN ? true:false}, + {"Blue", [&]() { FGCOLOR=TFT_BLUE; }, FGCOLOR==TFT_BLUE ? true:false}, + {"Yellow", [&]() { FGCOLOR=TFT_YELLOW; }, FGCOLOR==TFT_YELLOW ? true:false}, + {"Magenta", [&]() { FGCOLOR=TFT_MAGENTA; }, FGCOLOR==TFT_MAGENTA ? true:false}, + {"Orange", [&]() { FGCOLOR=TFT_ORANGE; }, FGCOLOR==TFT_ORANGE ? true:false}, + {"Main Menu", [=]() { backToMenu(); }}, + }; + delay(200); + loopOptions(options, idx); + tft.setTextColor(TFT_BLACK, FGCOLOR); + + write_eeprom(EEPROM_FGCOLOR0, int((FGCOLOR >> 8) & 0x00FF)); + write_eeprom(EEPROM_FGCOLOR1, int(FGCOLOR & 0x00FF)); } /********************************************************************* @@ -318,15 +274,12 @@ void setRFModuleMenu() { delay(200); loopOptions(options, idx); // 2fix: idx highlight not working? delay(200); - EEPROM.begin(EEPROMSIZE); // open eeprom if(result == 1) { #ifdef USE_CC1101_VIA_SPI ELECHOUSE_cc1101.Init(); if (ELECHOUSE_cc1101.getCC1101()){ RfModule=1; - EEPROM.write(13, RfModule); //set the byte - EEPROM.commit(); // Store data to EEPROM - EEPROM.end(); // Free EEPROM memory + write_eeprom(EEPROM_RF_MODULE, RfModule); return; } #endif @@ -336,9 +289,7 @@ void setRFModuleMenu() { } // fallback to "M5 RF433T/R" on errors RfModule=0; - EEPROM.write(13, RfModule); //set the byte - EEPROM.commit(); // Store data to EEPROM - EEPROM.end(); // Free EEPROM memory + write_eeprom(EEPROM_RF_MODULE, RfModule); } /********************************************************************* @@ -380,10 +331,7 @@ void setRFIDModuleMenu() { delay(200); RfidModule=result; - EEPROM.begin(EEPROMSIZE); // open eeprom - EEPROM.write(14, RfidModule); //set the byte - EEPROM.commit(); // Store data to EEPROM - EEPROM.end(); // Free EEPROM memory + write_eeprom(EEPROM_RFID_MODULE, RfidModule); } @@ -439,10 +387,7 @@ void setClock() { if (!returnToMenu) { delay(200); loopOptions(options); - EEPROM.begin(EEPROMSIZE); // open eeprom - EEPROM.write(10, tmz); // set the byte - EEPROM.commit(); // Store data to EEPROM - EEPROM.end(); // Free EEPROM memory + write_eeprom(EEPROM_TMZ, tmz); delay(200); timeClient.begin(); @@ -614,8 +559,8 @@ void runClockLoop() { ** get or set IR Pin from EEPROM **********************************************************************/ int gsetIrTxPin(bool set){ - EEPROM.begin(EEPROMSIZE); - int result = EEPROM.read(6); + int result = read_eeprom(EEPROM_IR_TX); + if(result>50) IrTx = LED; if(set) { options.clear(); @@ -636,10 +581,9 @@ int gsetIrTxPin(bool set){ loopOptions(options, idx); delay(200); Serial.println("Saved pin: " + String(IrTx)); - EEPROM.write(6, IrTx); - EEPROM.commit(); + write_eeprom(EEPROM_IR_TX, IrTx); } - EEPROM.end(); + returnToMenu=true; return IrTx; } @@ -649,8 +593,8 @@ int gsetIrTxPin(bool set){ ** get or set IR Rx Pin from EEPROM **********************************************************************/ int gsetIrRxPin(bool set){ - EEPROM.begin(EEPROMSIZE); - int result = EEPROM.read(7); + int result = read_eeprom(EEPROM_IR_RX); + if(result>45) IrRx = GROVE_SCL; if(set) { options.clear(); @@ -670,10 +614,9 @@ int gsetIrRxPin(bool set){ delay(200); loopOptions(options); delay(200); - EEPROM.write(7, IrRx); - EEPROM.commit(); + write_eeprom(EEPROM_IR_RX, IrRx); } - EEPROM.end(); + returnToMenu=true; return IrRx; } @@ -683,8 +626,8 @@ int gsetIrRxPin(bool set){ ** get or set RF Tx Pin from EEPROM **********************************************************************/ int gsetRfTxPin(bool set){ - EEPROM.begin(EEPROMSIZE); - int result = EEPROM.read(8); + int result = read_eeprom(EEPROM_RF_TX); + if(result>45) RfTx = GROVE_SDA; if(set) { options.clear(); @@ -704,10 +647,9 @@ int gsetRfTxPin(bool set){ delay(200); loopOptions(options); delay(200); - EEPROM.write(8, RfTx); - EEPROM.commit(); + write_eeprom(EEPROM_RF_TX, RfTx); } - EEPROM.end(); + returnToMenu=true; return RfTx; } @@ -716,8 +658,8 @@ int gsetRfTxPin(bool set){ ** get or set FR Rx Pin from EEPROM **********************************************************************/ int gsetRfRxPin(bool set){ - EEPROM.begin(EEPROMSIZE); - int result = EEPROM.read(9); + int result = read_eeprom(EEPROM_RF_RX); + if(result>36) RfRx = GROVE_SCL; if(set) { options.clear(); @@ -737,16 +679,14 @@ int gsetRfRxPin(bool set){ delay(200); loopOptions(options); delay(200); - EEPROM.write(9, RfRx); // Left rotation - EEPROM.commit(); + write_eeprom(EEPROM_RF_RX, RfRx); } - EEPROM.end(); + returnToMenu=true; return RfRx; } void getConfigs() { - bool EEPROMSave=false; int count=0; FS* fs = &LittleFS; if(setupSdCard()) fs = &SD; @@ -808,26 +748,7 @@ void getConfigs() { file.close(); if(count>0) saveConfigs(); - count=0; - EEPROM.begin(EEPROMSIZE); // open eeprom - if(EEPROM.read(0)!= rotation) { EEPROM.write(0, rotation); count++; } - if(EEPROM.read(1)!= dimmerSet) { EEPROM.write(1, dimmerSet); count++; } - if(EEPROM.read(2)!= bright) { EEPROM.write(2, bright); count++; } - if(EEPROM.read(6)!= IrTx) { EEPROM.write(6, IrTx); count++; } - if(EEPROM.read(7)!= IrRx) { EEPROM.write(7, IrRx); count++; } - if(EEPROM.read(8)!= RfTx) { EEPROM.write(8, RfTx); count++; } - if(EEPROM.read(9)!= RfRx) { EEPROM.write(9, RfRx); count++; } - // TODO: add RfModule,RfFreq - if(EEPROM.read(10)!= tmz) { EEPROM.write(10, tmz); count++; } - if(EEPROM.read(11)!=(int((FGCOLOR >> 8) & 0x00FF))) {EEPROM.write(11, int((FGCOLOR >> 8) & 0x00FF)); count++; } - if(EEPROM.read(12)!= int(FGCOLOR & 0x00FF)) { EEPROM.write(12, int(FGCOLOR & 0x00FF)); count++; } - if(EEPROM.read(14)!= RfidModule) { EEPROM.write(14, RfidModule); count++; } - //If something changed, saves the changes on EEPROM. - if(count>0) { - if(!EEPROM.commit()) log_i("fail to write EEPROM"); // Store data to EEPROM - else log_i("Wrote new conf to EEPROM"); - } - EEPROM.end(); + sync_eeprom_values(); log_i("Using config.conf setup file"); } else { goto Default; diff --git a/src/core/settings.h b/src/core/settings.h index 41fd98ce..5ae1d4d9 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -1,4 +1,3 @@ -#include #include diff --git a/src/core/wifi_common.cpp b/src/core/wifi_common.cpp index 6d58d1f2..0af9af7f 100644 --- a/src/core/wifi_common.cpp +++ b/src/core/wifi_common.cpp @@ -3,6 +3,7 @@ #include "mykeyboard.h" // usinf keyboard when calling rename #include "display.h" // using displayRedStripe and loop options #include "settings.h" +#include "eeprom.h" #include "powerSave.h" /*************************************************************************************** @@ -12,10 +13,8 @@ bool wifiConnect(String ssid, int encryptation, bool isAP) { if(!isAP) { int tmz; - EEPROM.begin(EEPROMSIZE); - tmz = EEPROM.read(10); // read timezone - pwd = EEPROM.readString(20); //password - EEPROM.end(); + tmz = read_eeprom(EEPROM_TMZ); // read timezone + pwd = read_eeprom_string(EEPROM_PWD); //password if(tmz>8) tmz=0; bool found = false; bool wrongPass = false; @@ -34,7 +33,7 @@ bool wifiConnect(String ssid, int encryptation, bool isAP) { break; } } - + Retry: if (!found || wrongPass) { @@ -44,12 +43,9 @@ bool wifiConnect(String ssid, int encryptation, bool isAP) { pwd = "mobile-ap"; else if (encryptation > 0) pwd = keyboard(pwd, 63, "Network Password:"); - EEPROM.begin(EEPROMSIZE); - if (pwd != EEPROM.readString(20)) { - EEPROM.writeString(20, pwd); - EEPROM.commit(); // Store data to EEPROM + if (pwd != read_eeprom_string(EEPROM_PWD)) { + write_eeprom_string(EEPROM_PWD, pwd); } - EEPROM.end(); // Free EEPROM memory if (!found) { // Cria um novo objeto JSON para adicionar ao array "wifi" JsonObject newWifi = WifiList.add(); @@ -123,9 +119,9 @@ bool wifiConnect(String ssid, int encryptation, bool isAP) { else { wifiDisconnect(); return false; - } - - } + } + + } } else { //Running in Access point mode IPAddress AP_GATEWAY(172, 0, 0, 1); diff --git a/src/core/wifi_common.h b/src/core/wifi_common.h index b2be71f5..0e575566 100644 --- a/src/core/wifi_common.h +++ b/src/core/wifi_common.h @@ -1,6 +1,5 @@ #include "display.h" #include -#include #include #include diff --git a/src/main.cpp b/src/main.cpp index 06ff79de..5d781b36 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,6 @@ #include "core/globals.h" #include "core/main_menu.h" -#include #include #include #include @@ -91,6 +90,7 @@ uint8_t buff[1024] = {0}; #include "core/sd_functions.h" #include "core/settings.h" #include "core/serialcmds.h" +#include "core/eeprom.h" #include "modules/others/audio.h" // for playAudioFile #include "modules/rf/rf.h" // for initCC1101once #include "modules/bjs_interpreter/interpreter.h" // for JavaScript interpreter @@ -201,75 +201,6 @@ void boot_screen() { tft.fillScreen(TFT_BLACK); } - -/********************************************************************* -** Function: load_eeprom -** Load EEPROM data -*********************************************************************/ -void load_eeprom() { - EEPROM.begin(EEPROMSIZE); // open eeprom - - rotation = EEPROM.read(0); - dimmerSet = EEPROM.read(1); - bright = EEPROM.read(2); - IrTx = EEPROM.read(6); - IrRx = EEPROM.read(7); - RfTx = EEPROM.read(8); - RfRx = EEPROM.read(9); - tmz = EEPROM.read(10); - FGCOLOR = EEPROM.read(11) << 8 | EEPROM.read(12); - RfModule = EEPROM.read(13); - RfidModule = EEPROM.read(14); - - log_i("\ - \n*-*EEPROM Settings*-* \ - \n- rotation =%03d, \ - \n- dimmerSet =%03d, \ - \n- Brightness=%03d, \ - \n- IR Tx Pin =%03d, \ - \n- IR Rx Pin =%03d, \ - \n- RF Tx Pin =%03d, \ - \n- RF Rx Pin =%03d, \ - \n- Time Zone =%03d, \ - \n- FGColor =0x%04X \ - \n- RfModule =%03d, \ - \n- RfidModule=%03d, \ - \n*-*-*-*-*-*-*-*-*-*-*", rotation, dimmerSet, bright,IrTx, IrRx, RfTx, RfRx, tmz, FGCOLOR, RfModule, RfidModule); - if (rotation>3 || dimmerSet>60 || bright>100 || IrTx>100 || IrRx>100 || RfRx>100 || RfTx>100 || tmz>24) { - rotation = ROTATION; - dimmerSet=10; - bright=100; - IrTx=LED; - IrRx=GROVE_SCL; - RfTx=GROVE_SDA; - RfRx=GROVE_SCL; - FGCOLOR=0xA80F; - tmz=0; - RfModule=0; - RfidModule=M5_RFID2_MODULE; - - EEPROM.write(0, rotation); - EEPROM.write(1, dimmerSet); - EEPROM.write(2, bright); - EEPROM.write(6, IrTx); - EEPROM.write(7, IrRx); - EEPROM.write(8, RfTx); - EEPROM.write(9, RfRx); - EEPROM.write(10, tmz); - EEPROM.write(11, int((FGCOLOR >> 8) & 0x00FF)); - EEPROM.write(12, int(FGCOLOR & 0x00FF)); - EEPROM.write(13, RfModule); - EEPROM.write(14, RfidModule); - EEPROM.writeString(20,""); - - EEPROM.commit(); // Store data to EEPROM - EEPROM.end(); - log_w("One of the eeprom values is invalid"); - } - setBrightness(bright,false); - EEPROM.end(); -} - /********************************************************************* ** Function: init_clock ** Clock initialisation for propper display in menu