From fbb62242f5baca36a4a04e8083e73c350ab0b0eb Mon Sep 17 00:00:00 2001 From: Rennan Cockles Date: Sun, 3 Nov 2024 17:09:24 -0300 Subject: [PATCH 01/13] new config class --- src/core/config.cpp | 132 ++++++++++++++++++++++++++++++++++++++++++++ src/core/config.h | 55 ++++++++++++++++++ 2 files changed, 187 insertions(+) create mode 100644 src/core/config.cpp create mode 100644 src/core/config.h diff --git a/src/core/config.cpp b/src/core/config.cpp new file mode 100644 index 00000000..4b49d8bb --- /dev/null +++ b/src/core/config.cpp @@ -0,0 +1,132 @@ +#include "config.h" +#include "sd_functions.h" + + +void BruceConfig::fromFile() { + FS *fs; + if(!getFsStorage(fs)) return; + + if(!fs->exists(filepath)) return saveFile(); + + File file; + file = fs->open(filepath, FILE_READ); + if (!file) { + log_e("Config file not found. Using default values"); + return; + } + + // Deserialize the JSON document + JsonDocument jsonDoc; + if (deserializeJson(jsonDoc, file)) { + log_e("Failed to read config file, using default configuration"); + return; + } + file.close(); + + JsonObject setting = jsonDoc.as(); + int count = 0; + + if(!setting["rot"].isNull()) { rotation = setting["rot"].as(); } else { count++; log_e("Fail"); } + if(!setting["dimmerSet"].isNull()) { dimmerSet = setting["dimmerSet"].as(); } else { count++; log_e("Fail"); } + if(!setting["bright"].isNull()) { bright = setting["bright"].as(); } else { count++; log_e("Fail"); } + if(!setting["tmz"].isNull()) { tmz = setting["tmz"].as(); } else { count++; log_e("Fail"); } + if(!setting["wuiUsr"].isNull()) { wuiUsr = setting["wuiUsr"].as(); } else { count++; log_e("Fail"); } + if(!setting["wuiPwd"].isNull()) { wuiPwd = setting["wuiPwd"].as(); } else { count++; log_e("Fail"); } + + if(!setting["priColor"].isNull()) { priColor = setting["priColor"].as(); } else { count++; log_e("Fail"); } + if(!setting["secColor"].isNull()) { secColor = setting["secColor"].as(); } else { count++; log_e("Fail"); } + if(!setting["bgColor"].isNull()) { bgColor = setting["bgColor"].as(); } else { count++; log_e("Fail"); } + + if(!setting["irTx"].isNull()) { irTx = setting["irTx"].as(); } else { count++; log_e("Fail"); } + if(!setting["irRx"].isNull()) { irRx = setting["irRx"].as(); } else { count++; log_e("Fail"); } + if(!setting["rfTx"].isNull()) { rfTx = setting["rfTx"].as(); } else { count++; log_e("Fail"); } + if(!setting["rfRx"].isNull()) { rfRx = setting["rfRx"].as(); } else { count++; log_e("Fail"); } + if(!setting["rfModule"].isNull()) { rfModule = setting["rfModule"].as(); } else { count++; log_e("Fail"); } + if(!setting["rfFreq"].isNull()) { rfFreq = setting["rfFreq"].as(); } else { count++; log_e("Fail"); } + if(!setting["rfFxdFreq"].isNull()) { rfFxdFreq = setting["rfFxdFreq"].as(); } else { count++; log_e("Fail"); } + if(!setting["rfScanRange"].isNull()) { rfScanRange = setting["rfScanRange"].as(); } else { count++; log_e("Fail"); } + if(!setting["rfidModule"].isNull()) { rfidModule = setting["rfidModule"].as(); } else { count++; log_e("Fail"); } + + if(!setting["wigleBasicToken"].isNull()) { wigleBasicToken = setting["wigleBasicToken"].as(); } else { count++; log_e("Fail"); } + if(!setting["devMode"].isNull()) { devMode = setting["devMode"].as(); } else { count++; log_e("Fail"); } + if(!setting["soundEnabled"].isNull()) { soundEnabled = setting["soundEnabled"].as(); } else { count++; log_e("Fail"); } + + // if(!setting.containsKey("wifi")) { count++; log_e("Fail"); } + + // if(setting.containsKey("wifi_ap")) { + // JsonObject wifiAp = setting["wifi_ap"].as(); + // if (wifiAp.containsKey("ssid")) { ap_ssid = wifiAp["ssid"].as(); } else { count++; log_e("Fail"); } + // if (wifiAp.containsKey("pwd")) { ap_pwd = wifiAp["pwd"].as(); } else { count++; log_e("Fail"); } + // } else { + // count++; log_e("Fail"); + // } + + if(dimmerSet < 0) dimmerSet = 10; + // log_i("Brightness: %d", bright); + // setBrightness(bright); + if(count>0) saveFile(); + // sync_eeprom_values(); + + log_i("Using config from file"); +} + + +void BruceConfig::saveFile() { + FS *fs; + if(!getFsStorage(fs)) return; + + JsonDocument jsonDoc; + JsonObject setting = jsonDoc.to(); + + setting["rot"] = rotation; + setting["dimmerSet"] = dimmerSet; + setting["bright"] = bright; + setting["tmz"] = tmz; + setting["wuiUsr"] = wuiUsr; + setting["wuiPwd"] = wuiPwd; + setting["priColor"] = priColor; + setting["secColor"] = secColor; + setting["bgColor"] = bgColor; + setting["irTx"] = irTx; + setting["irRx"] = irRx; + setting["rfTx"] = rfTx; + setting["rfRx"] = rfRx; + setting["rfModule"] = rfModule; + setting["rfFreq"] = rfFreq; + setting["rfFxdFreq"] = rfFxdFreq; + setting["rfScanRange"] = rfScanRange; + setting["rfidModule"] = rfidModule; + setting["wigleBasicToken"] = wigleBasicToken; + setting["devMode"] = devMode; + setting["soundEnabled"] = soundEnabled; + + // if(!setting.containsKey("wifi")) { + // JsonArray WifiList = setting["wifi"].to(); + // if(WifiList.size()<1) { + // JsonObject WifiObj = WifiList.add(); + // WifiObj["ssid"] = "myNetSSID"; + // WifiObj["pwd"] = "myNetPassword"; + // } + // } + // if(!setting.containsKey("wifi_ap")) { + // JsonObject WifiAp = setting["wifi_ap"].to(); + // WifiAp["ssid"] = ap_ssid; + // WifiAp["pwd"] = ap_pwd; + // } + + // Open file for writing + File file = fs->open(filepath, FILE_WRITE); + if (!file) { + log_e("Failed to open config file"); + file.close(); + return; + }; + + // Serialize JSON to file + serializeJsonPretty(jsonDoc, Serial); + if (serializeJsonPretty(jsonDoc, file) < 5) log_e("Failed to write config file"); + else log_i("config file written successfully"); + + // Close the file + file.close(); +} diff --git a/src/core/config.h b/src/core/config.h new file mode 100644 index 00000000..e3cdaed5 --- /dev/null +++ b/src/core/config.h @@ -0,0 +1,55 @@ +#ifndef __BRUCE_CONFIG_H__ +#define __BRUCE_CONFIG_H__ + +#include "core/globals.h" +// #include + + +class BruceConfig { +public: + int rotation = ROTATION > 1 ? 3 : 1; + int dimmerSet = 10; + int bright = 100; + int tmz = 3; + String wuiUsr = "admin"; + String wuiPwd = "bruce"; + + // Theme colors in RGB565 format + uint16_t priColor = 0xA80F; + uint16_t secColor = 0xFA99; // 0x0566; + uint16_t bgColor = 0x0; + + int irTx = LED; + int irRx = GROVE_SCL; + int rfTx = GROVE_SDA; + int rfRx = GROVE_SCL; + int rfModule = M5_RF_MODULE; + float rfFreq = 433.92; + int rfFxdFreq = 1; + int rfScanRange = 3; + int rfidModule = M5_RFID2_MODULE; + + String wigleBasicToken = ""; + int devMode = 0; + int soundEnabled = 1; + // wifi = [{"ssid":"myNetSSID","pwd":"myNetPassword"}]; + // wifi_ap = {"ssid":"BruceNet","pwd":"brucenet"}; + + + ///////////////////////////////////////////////////////////////////////////////////// + // Constructor + ///////////////////////////////////////////////////////////////////////////////////// + BruceConfig() {}; + // ~BruceConfig(); + + ///////////////////////////////////////////////////////////////////////////////////// + // Operations + ///////////////////////////////////////////////////////////////////////////////////// + void saveFile(); + void fromFile(); + +private: + const char *filepath = "/bruceNew.conf"; +}; + +#endif From 1504c1f656f63d925ff6643eb62e5ac2a1e635f9 Mon Sep 17 00:00:00 2001 From: Rennan Cockles Date: Sun, 3 Nov 2024 17:12:05 -0300 Subject: [PATCH 02/13] use rotation from config class --- src/core/eeprom.cpp | 12 +- src/core/globals.h | 5 +- src/core/mykeyboard.cpp | 50 ++++----- src/core/serialcmds.cpp | 28 ++--- src/core/settings.cpp | 10 +- src/main.cpp | 11 +- src/modules/bjs_interpreter/interpreter.cpp | 116 ++++++++++---------- 7 files changed, 117 insertions(+), 115 deletions(-) diff --git a/src/core/eeprom.cpp b/src/core/eeprom.cpp index 03d42100..f37bc325 100644 --- a/src/core/eeprom.cpp +++ b/src/core/eeprom.cpp @@ -10,7 +10,7 @@ void load_eeprom() { EEPROM.begin(EEPROMSIZE); // open eeprom - rotation = EEPROM.read(EEPROM_ROT); + bruceConfig.rotation = EEPROM.read(EEPROM_ROT); dimmerSet = EEPROM.read(EEPROM_DIMMER); bright = EEPROM.read(EEPROM_BRIGHT); IrTx = EEPROM.read(EEPROM_IR_TX); @@ -36,11 +36,11 @@ void load_eeprom() { \n- RfModule =%03d, \ \n- RfidModule=%03d, \ \n*-*-*-*-*-*-*-*-*-*-*", - rotation, dimmerSet, bright,IrTx, IrRx, RfTx, RfRx, tmz, FGCOLOR, RfModule, RfidModule + bruceConfig.rotation, dimmerSet, bright,IrTx, IrRx, RfTx, RfRx, tmz, FGCOLOR, RfModule, RfidModule ); if ( - rotation > 3 + bruceConfig.rotation > 3 || dimmerSet > 60 || bright > 100 || IrTx > 100 @@ -49,7 +49,7 @@ void load_eeprom() { || RfTx > 100 || tmz > 24 ) { - rotation = ROTATION; + bruceConfig.rotation = ROTATION; dimmerSet = 10; bright = 100; IrTx = LED; @@ -61,7 +61,7 @@ void load_eeprom() { RfModule = M5_RF_MODULE; RfidModule = M5_RFID2_MODULE; - EEPROM.write(EEPROM_ROT, rotation); + EEPROM.write(EEPROM_ROT, bruceConfig.rotation); EEPROM.write(EEPROM_DIMMER, dimmerSet); EEPROM.write(EEPROM_BRIGHT, bright); EEPROM.write(EEPROM_IR_TX, IrTx); @@ -146,7 +146,7 @@ void sync_eeprom_values(void) { EEPROM.begin(EEPROMSIZE); // open eeprom - if(EEPROM.read(EEPROM_ROT) != rotation) { EEPROM.write(EEPROM_ROT, rotation); count++; } + if(EEPROM.read(EEPROM_ROT) != bruceConfig.rotation) { EEPROM.write(EEPROM_ROT, bruceConfig.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++; } diff --git a/src/core/globals.h b/src/core/globals.h index 4ed19164..6a7f6eb9 100644 --- a/src/core/globals.h +++ b/src/core/globals.h @@ -17,6 +17,7 @@ extern char16_t FGCOLOR; #include #include #include +#include "config.h" #if defined (STICK_C_PLUS) || defined (STICK_C) #include @@ -62,6 +63,8 @@ extern char16_t FGCOLOR; extern bool interpreter_start; +extern BruceConfig bruceConfig; + extern char timeStr[10]; extern SPIClass sdcardSPI; #if defined(STICK_C_PLUS) || defined(STICK_C_PLUS2) @@ -109,8 +112,6 @@ extern String ap_pwd; extern String fileToCopy; -extern int rotation; - extern uint8_t buff[1024]; extern const int bufSize; diff --git a/src/core/mykeyboard.cpp b/src/core/mykeyboard.cpp index 9d1f80b3..8fc05168 100644 --- a/src/core/mykeyboard.cpp +++ b/src/core/mykeyboard.cpp @@ -63,9 +63,9 @@ bool menuPress(int bot) { M5.update(); auto t = M5.Touch.getDetail(); if (t.isPressed() || t.isHolding()) { - //if(rotation==3) t.x = WIDTH-t.x; - //else if (rotation==1) t.y = (HEIGHT+20)-t.y; - if(t.y>(HEIGHT) && (t.x>terco*bot && t.x(HEIGHT) && (t.x>terco*bot && t.x(HEIGHT) && ((t.x>terco*bot && t.x(HEIGHT) && ((t.x>terco*bot && t.xvaluestring); cJSON_Delete(root); - + /*if(protocolStr == "nec"){ // sendNEC(uint64_t data, uint16_t nbits, uint16_t repeat) irsend.sendNEC(data, bits, 10); return true; } */ - + return sendDecodedCommand(protocolStr, dataStr, String(bits)); } @@ -339,7 +339,7 @@ bool processSerialCommand(String cmd_str) { 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 @@ -407,7 +407,7 @@ bool processSerialCommand(String cmd_str) { deinitRfModule(); return true; } - + if(cmd_str.startsWith("subghz scan")) { // subghz scan 433 434 String args = cmd_str.substring(cmd_str.indexOf(" ", strlen("subghz rx"))); @@ -417,13 +417,13 @@ bool processSerialCommand(String cmd_str) { sscanf(args.c_str(), " %f %f", &start_frequency, &stop_frequency); if(!start_frequency || !stop_frequency) return false; // invalid args // passed as a long int (e.g. 433920000) - start_frequency /= 1000000; - stop_frequency /= 1000000; + start_frequency /= 1000000; + stop_frequency /= 1000000; } else return false; // missing args rf_scan(start_frequency, stop_frequency, 10*1000); // 10s timeout 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 @@ -768,7 +768,7 @@ bool processSerialCommand(String cmd_str) { // TODO: check if valid values if(setting_name=="bright") bright = setting_value.toInt(); if(setting_name=="dimmerSet") dimmerSet = setting_value.toInt(); - if(setting_name=="rot") rotation = setting_value.toInt(); + if(setting_name=="rot") bruceConfig.rotation = setting_value.toInt(); if(setting_name=="Bruce_FGCOLOR") FGCOLOR = setting_value.toInt(); if(setting_name=="IrTx") IrTx = setting_value.toInt(); if(setting_name=="IrRx") IrRx = setting_value.toInt(); @@ -1113,7 +1113,7 @@ bool processSerialCommand(String cmd_str) { //Serial.println(filepath); //Serial.println(password); - + if(cmd_str.startsWith("crypto decrypt_from_file") || cmd_str.startsWith("crypto type_from_file")) { FS* fs = NULL; if(SD.exists(filepath)) fs = &SD; @@ -1182,17 +1182,17 @@ bool processSerialCommand(String cmd_str) { return false; } } - + if(cmd_str == "wifi off") { wifiDisconnect(); return true; } - + /* WIP if(cmd_str.startsWith("wifi scan") || cmd_str.startsWith("scanap") { } - + if(cmd_str.startsWith("bt scan")) { } diff --git a/src/core/settings.cpp b/src/core/settings.cpp index dd36e65d..0599f6a2 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -137,7 +137,7 @@ int gsetRotation(bool set){ } if(set) { - rotation = result; + bruceConfig.rotation = result; tft.setRotation(result); write_eeprom(EEPROM_ROT, result); } @@ -433,7 +433,7 @@ void setClock() { timeClient.begin(); timeClient.update(); localTime = myTZ.toLocal(timeClient.getEpochTime()); - + #if defined(HAS_RTC) struct tm *timeinfo = localtime(&localTime); TimeStruct.Hours = timeinfo->tm_hour; @@ -459,7 +459,7 @@ void setClock() { delay(200); options = { }; for(int i=0; i<60;i++) options.push_back({String(String(i<10?"0":"") + String(i)).c_str(), [&]() { delay(1); }}); - + delay(200); mn=loopOptions(options,false,true,"Set Minute"); delay(200); @@ -700,7 +700,7 @@ void getConfigs() { setting = settings[0]; if(setting.containsKey("bright")) { bright = setting["bright"].as(); } else { count++; log_i("Fail"); } if(setting.containsKey("dimmerSet")) { dimmerSet = setting["dimmerSet"].as(); } else { count++; log_i("Fail"); } - if(setting.containsKey("rot")) { rotation = setting["rot"].as(); } else { count++; log_i("Fail"); } + if(setting.containsKey("rot")) { bruceConfig.rotation = setting["rot"].as(); } else { count++; log_i("Fail"); } if(setting.containsKey("Bruce_FGCOLOR")) { FGCOLOR = setting["Bruce_FGCOLOR"].as(); } else { count++; log_i("Fail"); } if(setting.containsKey("wui_usr")) { wui_usr = setting["wui_usr"].as(); } else { count++; log_i("Fail"); } if(setting.containsKey("wui_pwd")) { wui_pwd = setting["wui_pwd"].as(); } else { count++; log_i("Fail"); } @@ -763,7 +763,7 @@ void saveConfigs() { JsonObject setting = settings[0]; setting["bright"] = bright; setting["dimmerSet"] = dimmerSet; - setting["rot"] = rotation; + setting["rot"] = bruceConfig.rotation; setting["Bruce_FGCOLOR"] = FGCOLOR; setting["wui_usr"] = wui_usr; setting["wui_pwd"] = wui_pwd; diff --git a/src/main.cpp b/src/main.cpp index 6e8d911f..13546a70 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,6 +8,7 @@ #include "esp32-hal-psram.h" +BruceConfig bruceConfig; MainMenu mainMenu; SPIClass sdcardSPI; @@ -17,7 +18,6 @@ SPIClass CC_NRF_SPI; // Public Globals Variables unsigned long previousMillis = millis(); int prog_handler; // 0 - Flash, 1 - LittleFS, 3 - Download -int rotation; int IrTx; int IrRx; int RfTx; @@ -167,8 +167,8 @@ void begin_tft(){ M5.begin(); #endif - rotation = gsetRotation(); - tft.setRotation(rotation); + bruceConfig.rotation = gsetRotation(); + tft.setRotation(bruceConfig.rotation); resetTftDisplay(); } @@ -199,13 +199,13 @@ void boot_screen() { // Start image loop while(millis()2000) && (millis()-i)<2200){ + if((millis()-i>2000) && (millis()-i)<2200){ tft.fillRect(0,45,WIDTH,HEIGHT-45,BGCOLOR); if(showJpeg(SD,"/boot.jpg") && (millis()-i>2000) && (millis()-i<2200)) { boot_img=true; Serial.println("Image from SD"); } else if (showJpeg(LittleFS,"/boot.jpg") && (millis()-i>2000) && (millis()-i<2100)) { boot_img=true; Serial.println("Image from LittleFS"); } else if (showGIF(SD,"/boot.gif") && (millis()-i>2000) && (millis()-i<2200)) { boot_img=true; Serial.println("Image from SD"); } else if (showGIF(LittleFS,"/boot.gif") && (millis()-i>2000) && (millis()-i<2100)) { boot_img=true; Serial.println("Image from LittleFS"); } - } + } if(!boot_img && (millis()-i>2200) && (millis()-i)<2700) tft.drawRect(2*WIDTH/3,HEIGHT/2,2,2,FGCOLOR); if(!boot_img && (millis()-i>2700) && (millis()-i)<2900) tft.fillRect(0,45,WIDTH,HEIGHT-45,BGCOLOR); #if defined(M5STACK) @@ -301,6 +301,7 @@ void setup() { setupSdCard(); boot_screen(); getConfigs(); + bruceConfig.fromFile(); startup_sound(); diff --git a/src/modules/bjs_interpreter/interpreter.cpp b/src/modules/bjs_interpreter/interpreter.cpp index 8339b9da..754bc579 100644 --- a/src/modules/bjs_interpreter/interpreter.cpp +++ b/src/modules/bjs_interpreter/interpreter.cpp @@ -44,7 +44,7 @@ static duk_ret_t native_delay(duk_context *ctx) { return 0; } -// Hardware GPIO interactions +// Hardware GPIO interactions static duk_ret_t native_digitalWrite(duk_context *ctx) { digitalWrite(duk_to_int(ctx, 0), duk_to_boolean(ctx, 1)); return 0; @@ -108,11 +108,11 @@ static duk_ret_t native_wifiConnect(duk_context *ctx) { String ssid = duk_to_string(ctx, 0); int timeout_in_seconds = 10; if(duk_is_number(ctx, 1)) timeout_in_seconds = duk_to_int(ctx, 1); - + bool r = false; - + Serial.println("Connecting to: " + ssid); - + if(duk_is_string(ctx, 2)) { String pwd = duk_to_string(ctx, 2); WiFi.begin(ssid, pwd); @@ -129,12 +129,12 @@ static duk_ret_t native_wifiConnect(duk_context *ctx) { break; } } while (WiFi.status() != WL_CONNECTED); - + if(WiFi.status() == WL_CONNECTED) { r = true; wifiIP = WiFi.localIP().toString(); // update global var } - + duk_push_boolean(ctx, r); return 1; } @@ -190,7 +190,7 @@ static duk_ret_t native_get(duk_context *ctx) { for (duk_uint_t i = 0; i < len; i++) { // Get each element in the array duk_get_prop_index(ctx, 1, i); - + // Ensure it's a string if (!duk_is_string(ctx, -1)) { duk_pop(ctx); @@ -202,7 +202,7 @@ static duk_ret_t native_get(duk_context *ctx) { duk_pop(ctx); i++; duk_get_prop_index(ctx, 1, i); - + // Ensure it's a string if (!duk_is_string(ctx, -1)) { duk_pop(ctx); @@ -215,10 +215,10 @@ static duk_ret_t native_get(duk_context *ctx) { http.addHeader(headerKey, headerValue); } } - + // Send HTTP GET request int httpResponseCode = http.GET(); - + if (httpResponseCode>0) { String payload = http.getString(); @@ -303,7 +303,7 @@ static duk_ret_t native_fillScreen(duk_context *ctx) { tft.fillScreen(duk_to_int(ctx, 0)); return 0; } - + static duk_ret_t native_width(duk_context *ctx) { int width = tft.width(); duk_push_int(ctx, width); @@ -439,7 +439,7 @@ static duk_ret_t native_serialCmd(duk_context *ctx) { duk_push_boolean(ctx, r); return 1; } - + static duk_ret_t native_playAudioFile(duk_context *ctx) { // usage: playAudioFile(filename : string); // returns: bool==true on success, false on any error @@ -495,7 +495,7 @@ static duk_ret_t native_badusbSetup(duk_context *ctx) { Kb.begin(); //cc.begin(); USB.begin(); - duk_push_boolean(ctx, true); + duk_push_boolean(ctx, true); #else duk_push_boolean(ctx, false); #endif @@ -509,9 +509,9 @@ static duk_ret_t native_badusbQuit(duk_context *ctx) { #if defined(USB_as_HID) Kb.end(); //cc.begin(); - USB.~ESPUSB(); // Explicit call to destructor + USB.~ESPUSB(); // Explicit call to destructor Serial.begin(115200); // need to reinit serial when finished - duk_push_boolean(ctx, true); + duk_push_boolean(ctx, true); #else duk_push_boolean(ctx, false); #endif @@ -547,7 +547,7 @@ static duk_ret_t native_badusbPress(duk_context *ctx) { } static duk_ret_t native_badusbHold(duk_context *ctx) { - // usage: badusbHold(keycode : number); + // usage: badusbHold(keycode : number); #if defined(USB_as_HID) Kb.press(duk_to_int(ctx, 0)); #endif @@ -555,7 +555,7 @@ static duk_ret_t native_badusbHold(duk_context *ctx) { } static duk_ret_t native_badusbRelease(duk_context *ctx) { - // usage: badusbHold(keycode : number); + // usage: badusbHold(keycode : number); #if defined(USB_as_HID) Kb.release(duk_to_int(ctx, 0)); #endif @@ -597,8 +597,8 @@ static duk_ret_t native_badusbPressSpecial(duk_context *ctx) { // IR functions static duk_ret_t native_irRead(duk_context *ctx) { - // usage: irRead(); - // usage: irRead(timeout_in_seconds : number); + // usage: irRead(); + // usage: irRead(timeout_in_seconds : number); // returns a string of the generated ir file, empty string on timeout or other errors IrRead i = IrRead(true); // true == headless mode String r = ""; @@ -611,8 +611,8 @@ static duk_ret_t native_irRead(duk_context *ctx) { } static duk_ret_t native_irReadRaw(duk_context *ctx) { - // usage: irReadRaw(); - // usage: irRead(timeout_in_seconds : number); + // usage: irReadRaw(); + // usage: irRead(timeout_in_seconds : number); // returns a string of the generated ir file, empty string on timeout or other errors IrRead i = IrRead(true, true); // true == headless mode, true==raw mode String r = ""; @@ -627,14 +627,14 @@ static duk_ret_t native_irReadRaw(duk_context *ctx) { // Subghz functions static duk_ret_t native_subghzRead(duk_context *ctx) { - // usage: subghzRead(); - // usage: subghzRead(timeout_in_seconds : number); + // usage: subghzRead(); + // usage: subghzRead(timeout_in_seconds : number); // returns a string of the generated sub file, empty string on timeout or other errors (decoding failed) String r = ""; if(duk_is_number(ctx, 0)) r = RCSwitch_Read(RfFreq, duk_to_int(ctx, 0)); // custom timeout else - r = RCSwitch_Read(RfFreq, 10); + r = RCSwitch_Read(RfFreq, 10); duk_push_string(ctx, r.c_str()); return 1; } @@ -644,14 +644,14 @@ static duk_ret_t native_subghzReadRaw(duk_context *ctx) { if(duk_is_number(ctx, 0)) r = RCSwitch_Read(RfFreq, duk_to_int(ctx, 0), true); // custom timeout else - r = RCSwitch_Read(RfFreq, 10, true); + r = RCSwitch_Read(RfFreq, 10, true); duk_push_string(ctx, r.c_str()); return 1; } static duk_ret_t native_subghzSetFrequency(duk_context *ctx) { - // usage: subghzSetFrequency(freq_as_float); + // usage: subghzSetFrequency(freq_as_float); if(duk_is_number(ctx, 0)) RfFreq = duk_to_number(ctx, 0); // float global var return 0; @@ -695,16 +695,16 @@ static duk_ret_t native_dialogChoice(duk_context *ctx) { // usage: dialogChoice(choices : string[]) // returns: string (val1, 2, ...), or empty string if cancelled const char* r = ""; - + if (duk_is_array(ctx, 0)) { options = {}; - + // Get the length of the array duk_uint_t len = duk_get_length(ctx, 0); for (duk_uint_t i = 0; i < len; i++) { // Get each element in the array duk_get_prop_index(ctx, 0, i); - + // Ensure it's a string if (!duk_is_string(ctx, -1)) { duk_pop(ctx); @@ -716,7 +716,7 @@ static duk_ret_t native_dialogChoice(duk_context *ctx) { duk_pop(ctx); i++; duk_get_prop_index(ctx, 0, i); - + // Ensure it's a string if (!duk_is_string(ctx, -1)) { duk_pop(ctx); @@ -726,21 +726,21 @@ static duk_ret_t native_dialogChoice(duk_context *ctx) { // Get the string const char *choiceValue = duk_get_string(ctx, -1); duk_pop(ctx); - + // add to the choices list options.push_back({choiceKey, [choiceValue, &r]() { r = choiceValue; }}); } // end for - + options.push_back({"Cancel", [&]() { r = ""; }}); - + delay(200); loopOptions(options); } - + duk_push_string(ctx, r); return 1; } - + static duk_ret_t native_dialogViewFile(duk_context *ctx) { // usage: dialogViewFile(path : string) // returns: nothing @@ -775,8 +775,8 @@ static duk_ret_t native_keyboard(duk_context *ctx) { duk_push_string(ctx, r.c_str()); return 1; } - - + + // Storage functions static duk_ret_t native_storageRead(duk_context *ctx) { @@ -812,17 +812,17 @@ static duk_ret_t native_storageWrite(duk_context *ctx) { f.write((const uint8_t*) data.c_str(), data.length()); f.close(); r = true; // success - } + } } duk_push_boolean(ctx, r); return 1; } - + // Read script file String readScriptFile(FS fs, String filename) { String fileError = "drawString('No boot.js file.', 4, 4);"; - + File file = fs.open(filename); if (!file) { return fileError; @@ -847,7 +847,7 @@ bool interpreter() { #endif * */ tft.fillRect(0,0,WIDTH,HEIGHT,TFT_BLACK); - tft.setRotation(rotation); + tft.setRotation(bruceConfig.rotation); tft.setTextSize(FM); tft.setTextColor(TFT_WHITE); // Create context. @@ -882,12 +882,12 @@ bool interpreter() { duk_push_c_function(ctx, native_wifiConnectDialog, 0); duk_put_global_string(ctx, "wifiConnectDialog"); duk_push_c_function(ctx, native_wifiDisconnect, 0); - duk_put_global_string(ctx, "wifiDisconnect"); + duk_put_global_string(ctx, "wifiDisconnect"); duk_push_c_function(ctx, native_wifiScan, 0); - duk_put_global_string(ctx, "wifiScan"); + duk_put_global_string(ctx, "wifiScan"); duk_push_c_function(ctx, native_get, 2); - duk_put_global_string(ctx, "httpGet"); - // TODO: get mac addresses + duk_put_global_string(ctx, "httpGet"); + // TODO: get mac addresses // Graphics duk_push_c_function(ctx, native_color, 3); @@ -912,7 +912,7 @@ bool interpreter() { duk_push_c_function(ctx, native_drawJpg, 4); //drawJpg(fs,filepath,x,y) duk_put_global_string(ctx, "drawJpg"); //drawJpg("SD","/boot.jpg",10,10); - + duk_push_c_function(ctx, native_width, 0); duk_put_global_string(ctx, "width"); @@ -927,11 +927,11 @@ bool interpreter() { duk_push_c_function(ctx, native_getSelPress, 0); // checkSelPress duk_put_global_string(ctx, "getSelPress"); duk_push_c_function(ctx, native_getNextPress, 0); // checkNextPress - duk_put_global_string(ctx, "getNextPress"); + duk_put_global_string(ctx, "getNextPress"); duk_push_c_function(ctx, native_getAnyPress, 0); - duk_put_global_string(ctx, "getAnyPress"); - - // Serial + wrappers + duk_put_global_string(ctx, "getAnyPress"); + + // Serial + wrappers duk_push_c_function(ctx, native_serialReadln, 0); duk_put_global_string(ctx, "serialReadln"); duk_push_c_function(ctx, native_serialCmd, 1); @@ -946,7 +946,7 @@ bool interpreter() { duk_put_global_string(ctx, "subghzTransmitFile"); duk_push_c_function(ctx, native_badusbRunFile, 1); duk_put_global_string(ctx, "badusbRunFile"); - + // badusb functions duk_push_c_function(ctx, native_badusbSetup, 0); duk_put_global_string(ctx, "badusbSetup"); @@ -966,14 +966,14 @@ bool interpreter() { duk_put_global_string(ctx, "badusbPressRaw"); //duk_push_c_function(ctx, native_badusbPressSpecial, 1); //duk_put_global_string(ctx, "badusbPressSpecial"); - + // IR functions duk_push_c_function(ctx, native_irRead, 0); duk_put_global_string(ctx, "irRead"); duk_push_c_function(ctx, native_irReadRaw, 0); duk_put_global_string(ctx, "irReadRaw"); //TODO: irTransmit(string) - + // subghz functions duk_push_c_function(ctx, native_subghzRead, 0); duk_put_global_string(ctx, "subghzRead"); @@ -983,7 +983,7 @@ bool interpreter() { duk_put_global_string(ctx, "subghzSetFrequency"); //duk_put_global_string(ctx, "subghzSetIdle"); // TODO: subghzTransmit(string) - + // Dialog functions duk_push_c_function(ctx, native_dialogMessage, 1); duk_put_global_string(ctx, "dialogMessage"); @@ -998,20 +998,20 @@ bool interpreter() { duk_put_global_string(ctx, "dialogViewFile"); duk_push_c_function(ctx, native_keyboard, 3); duk_put_global_string(ctx, "keyboard"); - + // Storage functions duk_push_c_function(ctx, native_storageRead, 1); duk_put_global_string(ctx, "storageRead"); duk_push_c_function(ctx, native_storageWrite, 2); duk_put_global_string(ctx, "storageWrite"); // TODO: wrap more serial storage cmd: mkdir, remove, ... - + // TODO: match flipper syntax https://github.com/jamisonderek/flipper-zero-tutorials/wiki/JavaScript // https://github.com/jamisonderek/flipper-zero-tutorials/wiki/JavaScript // MEMO: API https://duktape.org/api.html https://github.com/joeqread/arduino-duktape/blob/main/src/duktape.h bool r; - + duk_push_string(ctx, script.c_str()); if (duk_peval(ctx) != 0) { printf("eval failed: %s\n", duk_safe_to_string(ctx, -1)); @@ -1048,7 +1048,7 @@ void run_bjs_script() { returnToMenu=true; interpreter_start=true; - + // To stop the script, press Prev and Next together for a few seconds } From 31e849003fca087688bca6b177af59939f5aa1d1 Mon Sep 17 00:00:00 2001 From: Rennan Cockles Date: Sun, 3 Nov 2024 18:51:27 -0300 Subject: [PATCH 03/13] change config values tu use config class --- src/core/eeprom.cpp | 108 ++++--- src/core/eeprom.h | 10 +- src/core/globals.h | 27 -- src/core/menu_items/ConfigMenu.cpp | 2 +- src/core/menu_items/IRMenu.cpp | 2 +- src/core/menu_items/RFIDMenu.cpp | 6 +- src/core/menu_items/RFMenu.cpp | 4 +- src/core/powerSave.cpp | 8 +- src/core/serialcmds.cpp | 38 +-- src/core/settings.cpp | 282 ++++++++--------- src/core/wifi_common.cpp | 3 +- src/main.cpp | 18 -- src/modules/bjs_interpreter/interpreter.cpp | 10 +- src/modules/ir/TV-B-Gone.cpp | 104 +++---- src/modules/ir/ir_read.cpp | 54 ++-- src/modules/ir/ir_read.h | 6 +- src/modules/others/audio.cpp | 10 +- src/modules/others/webInterface.cpp | 10 +- src/modules/rf/rf.cpp | 324 ++++++++++---------- src/modules/rfid/tag_o_matic.cpp | 2 +- src/modules/wifi/wigle.cpp | 4 +- 21 files changed, 498 insertions(+), 534 deletions(-) diff --git a/src/core/eeprom.cpp b/src/core/eeprom.cpp index f37bc325..ac5a75c6 100644 --- a/src/core/eeprom.cpp +++ b/src/core/eeprom.cpp @@ -11,16 +11,16 @@ void load_eeprom() { EEPROM.begin(EEPROMSIZE); // open eeprom bruceConfig.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); + bruceConfig.dimmerSet = EEPROM.read(EEPROM_DIMMER); + bruceConfig.bright = EEPROM.read(EEPROM_BRIGHT); + bruceConfig.irTx = EEPROM.read(EEPROM_IR_TX); + bruceConfig.irRx = EEPROM.read(EEPROM_IR_RX); + bruceConfig.rfTx = EEPROM.read(EEPROM_RF_TX); + bruceConfig.rfRx = EEPROM.read(EEPROM_RF_RX); + bruceConfig.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); + bruceConfig.rfModule = EEPROM.read(EEPROM_RF_MODULE); + bruceConfig.rfidModule = EEPROM.read(EEPROM_RFID_MODULE); log_i("\ \n*-*EEPROM Settings*-* \ @@ -33,46 +33,56 @@ void load_eeprom() { \n- RF Rx Pin =%03d, \ \n- Time Zone =%03d, \ \n- FGColor =0x%04X \ - \n- RfModule =%03d, \ - \n- RfidModule=%03d, \ + \n- rfModule =%03d, \ + \n- rfidModule=%03d, \ \n*-*-*-*-*-*-*-*-*-*-*", - bruceConfig.rotation, dimmerSet, bright,IrTx, IrRx, RfTx, RfRx, tmz, FGCOLOR, RfModule, RfidModule + bruceConfig.rotation, + bruceConfig.dimmerSet, + bruceConfig.bright, + bruceConfig.irTx, + bruceConfig.irRx, + bruceConfig.rfTx, + bruceConfig.rfRx, + bruceConfig.tmz, + FGCOLOR, + bruceConfig.rfModule, + bruceConfig.rfidModule ); if ( bruceConfig.rotation > 3 - || dimmerSet > 60 - || bright > 100 - || IrTx > 100 - || IrRx > 100 - || RfRx > 100 - || RfTx > 100 - || tmz > 24 + || bruceConfig.dimmerSet > 60 + || bruceConfig.bright > 100 + || bruceConfig.irTx > 100 + || bruceConfig.irRx > 100 + || bruceConfig.rfRx > 100 + || bruceConfig.rfTx > 100 + || bruceConfig.tmz > 24 ) { bruceConfig.rotation = ROTATION; - dimmerSet = 10; - bright = 100; - IrTx = LED; - IrRx = GROVE_SCL; - RfTx = GROVE_SDA; - RfRx = GROVE_SCL; + bruceConfig.dimmerSet = 10; + bruceConfig.bright = 100; + bruceConfig.irTx = LED; + bruceConfig.irRx = GROVE_SCL; + bruceConfig.rfTx = GROVE_SDA; + bruceConfig.rfRx = GROVE_SCL; FGCOLOR = DEFAULTFGCOLOR; - tmz = 0; - RfModule = M5_RF_MODULE; - RfidModule = M5_RFID2_MODULE; + bruceConfig.tmz = 0; + bruceConfig.rfModule = M5_RF_MODULE; + bruceConfig.rfidModule = M5_RFID2_MODULE; EEPROM.write(EEPROM_ROT, bruceConfig.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_DIMMER, bruceConfig.dimmerSet); + EEPROM.write(EEPROM_BRIGHT, bruceConfig.bright); + EEPROM.write(EEPROM_IR_TX, bruceConfig.irTx); + EEPROM.write(EEPROM_IR_RX, bruceConfig.irRx); + EEPROM.write(EEPROM_RF_TX, bruceConfig.rfTx); + EEPROM.write(EEPROM_RF_RX, bruceConfig.rfRx); + EEPROM.write(EEPROM_TMZ, bruceConfig.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.write(EEPROM_RF_MODULE, bruceConfig.rfModule); + EEPROM.write(EEPROM_RFID_MODULE, bruceConfig.rfidModule); EEPROM.writeString(20,""); EEPROM.commit(); // Store data to EEPROM @@ -81,7 +91,7 @@ void load_eeprom() { EEPROM.end(); - setBrightness(bright, false); + setBrightness(bruceConfig.bright, false); } @@ -147,19 +157,19 @@ void sync_eeprom_values(void) { EEPROM.begin(EEPROMSIZE); // open eeprom if(EEPROM.read(EEPROM_ROT) != bruceConfig.rotation) { EEPROM.write(EEPROM_ROT, bruceConfig.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_DIMMER) != bruceConfig.dimmerSet) { EEPROM.write(EEPROM_DIMMER, bruceConfig.dimmerSet); count++; } + if(EEPROM.read(EEPROM_BRIGHT) != bruceConfig.bright) { EEPROM.write(EEPROM_BRIGHT, bruceConfig.bright); count++; } + + if(EEPROM.read(EEPROM_IR_TX) != bruceConfig.irTx) { EEPROM.write(EEPROM_IR_TX, bruceConfig.irTx); count++; } + if(EEPROM.read(EEPROM_IR_RX) != bruceConfig.irRx) { EEPROM.write(EEPROM_IR_RX, bruceConfig.irRx); count++; } + if(EEPROM.read(EEPROM_RF_TX) != bruceConfig.rfTx) { EEPROM.write(EEPROM_RF_TX, bruceConfig.rfTx); count++; } + if(EEPROM.read(EEPROM_RF_RX) != bruceConfig.rfRx) { EEPROM.write(EEPROM_RF_RX, bruceConfig.rfRx); count++; } + if(EEPROM.read(EEPROM_TMZ) != bruceConfig.tmz) { EEPROM.write(EEPROM_TMZ, bruceConfig.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(EEPROM.read(EEPROM_RF_MODULE) != bruceConfig.rfModule) { EEPROM.write(EEPROM_RF_MODULE, bruceConfig.rfModule); count++; } + if(EEPROM.read(EEPROM_RFID_MODULE) != bruceConfig.rfidModule) { EEPROM.write(EEPROM_RFID_MODULE, bruceConfig.rfidModule); count++; } + // TODO: add rfFreq //If something changed, saves the changes on EEPROM. if(count > 0) { diff --git a/src/core/eeprom.h b/src/core/eeprom.h index e326e2e9..498ba061 100644 --- a/src/core/eeprom.h +++ b/src/core/eeprom.h @@ -14,15 +14,15 @@ EEPROM ADDRESSES MAP 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) +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) +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) +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 diff --git a/src/core/globals.h b/src/core/globals.h index 6a7f6eb9..00e5a7b3 100644 --- a/src/core/globals.h +++ b/src/core/globals.h @@ -118,35 +118,13 @@ extern const int bufSize; extern bool returnToMenu; // variable to check and break loops to return to main menu -extern int IrTx; - -extern int IrRx; - -extern int RfTx; - -extern int RfRx; - -extern int RfModule; - -extern float RfFreq; - -extern int RfFxdFreq; - -extern int RfScanRange; - -extern int RfidModule; - extern String cachedPassword; -extern String wigleBasicToken; // Screen sleep control variables extern unsigned long previousMillis; extern bool isSleeping; extern bool isScreenOff; extern bool dimmer; -extern int dimmerSet; -extern int devMode; -extern int soundEnabled; void backToMenu(); @@ -154,12 +132,7 @@ void updateTimeStr(struct tm timeInfo); extern JsonDocument settings; extern unsigned long dimmerTemp; -extern int dimmerSet; -extern int bright; extern bool dimmer; -extern String wui_usr; -extern String wui_pwd; -extern int tmz; enum RFIDModules { M5_RFID2_MODULE = 0, diff --git a/src/core/menu_items/ConfigMenu.cpp b/src/core/menu_items/ConfigMenu.cpp index 4136c39a..36d80eaa 100644 --- a/src/core/menu_items/ConfigMenu.cpp +++ b/src/core/menu_items/ConfigMenu.cpp @@ -20,7 +20,7 @@ void ConfigMenu::optionsMenu() { {"Restart", [=]() { ESP.restart(); }}, }; - if (devMode) options.push_back({"Dev Mode", [=]() { devMenu(); }}); + if (bruceConfig.devMode) options.push_back({"Dev Mode", [=]() { devMenu(); }}); options.push_back({"Main Menu", [=]() { backToMenu(); }}); delay(200); diff --git a/src/core/menu_items/IRMenu.cpp b/src/core/menu_items/IRMenu.cpp index c8a9a568..f58da322 100644 --- a/src/core/menu_items/IRMenu.cpp +++ b/src/core/menu_items/IRMenu.cpp @@ -15,7 +15,7 @@ void IRMenu::optionsMenu() { delay(200); String txt = "Infrared"; - txt+=" Tx: " + String(IrTx) + " Rx: " + String(IrRx); + txt+=" Tx: " + String(bruceConfig.irTx) + " Rx: " + String(bruceConfig.irRx); loopOptions(options,false,true,txt); } diff --git a/src/core/menu_items/RFIDMenu.cpp b/src/core/menu_items/RFIDMenu.cpp index 7ade13ed..a147cfe9 100644 --- a/src/core/menu_items/RFIDMenu.cpp +++ b/src/core/menu_items/RFIDMenu.cpp @@ -23,9 +23,9 @@ void RFIDMenu::optionsMenu() { delay(200); String txt = "RFID"; - if(RfidModule==M5_RFID2_MODULE) txt+=" (RFID2)"; - else if(RfidModule==PN532_I2C_MODULE) txt+=" (PN532-I2C)"; - else if(RfidModule==PN532_SPI_MODULE) txt+=" (PN532-SPI)"; + if(bruceConfig.rfidModule==M5_RFID2_MODULE) txt+=" (RFID2)"; + else if(bruceConfig.rfidModule==PN532_I2C_MODULE) txt+=" (PN532-I2C)"; + else if(bruceConfig.rfidModule==PN532_SPI_MODULE) txt+=" (PN532-SPI)"; loopOptions(options,false,true,txt); } diff --git a/src/core/menu_items/RFMenu.cpp b/src/core/menu_items/RFMenu.cpp index 7d068c8d..9d7fea3c 100644 --- a/src/core/menu_items/RFMenu.cpp +++ b/src/core/menu_items/RFMenu.cpp @@ -16,8 +16,8 @@ void RFMenu::optionsMenu() { delay(200); String txt = "Radio Frequency"; - if(RfModule==CC1101_SPI_MODULE) txt+=" (CC1101)"; // Indicates if CC1101 is connected - else txt+=" Tx: " + String(RfTx) + " Rx: " + String(RfRx); + if(bruceConfig.rfModule==CC1101_SPI_MODULE) txt+=" (CC1101)"; // Indicates if CC1101 is connected + else txt+=" Tx: " + String(bruceConfig.rfTx) + " Rx: " + String(bruceConfig.rfRx); loopOptions(options,false,true,txt); } diff --git a/src/core/powerSave.cpp b/src/core/powerSave.cpp index a0e8ce8e..03401936 100644 --- a/src/core/powerSave.cpp +++ b/src/core/powerSave.cpp @@ -20,17 +20,17 @@ bool wakeUpScreen(){ getBrightness(); delay(200); return true; - } + } return false; } /* Check if it's time to put the device to sleep */ void checkPowerSaveTime(){ - if(dimmerSet!=0){ - if((millis() - previousMillis) >= (dimmerSet * 1000) && dimmer == false && isSleeping == false){ + if(bruceConfig.dimmerSet!=0){ + if((millis() - previousMillis) >= (bruceConfig.dimmerSet * 1000) && dimmer == false && isSleeping == false){ dimmer = true; setBrightness(5, false); - }else if((millis() - previousMillis) >= ((dimmerSet * 1000) + 5000) && isScreenOff == false && isSleeping == false){ + }else if((millis() - previousMillis) >= ((bruceConfig.dimmerSet * 1000) + 5000) && isScreenOff == false && isSleeping == false){ isScreenOff = true; turnOffDisplay(); } diff --git a/src/core/serialcmds.cpp b/src/core/serialcmds.cpp index 5df4572c..f0f1cd54 100644 --- a/src/core/serialcmds.cpp +++ b/src/core/serialcmds.cpp @@ -224,7 +224,7 @@ bool processSerialCommand(String cmd_str) { if(cmd_str.startsWith("ir tx")) { // make sure it is initted gsetIrTxPin(false); - //if(IrTx==0) IrTx = LED; // quickfix init issue? CARDPUTER is 44 + //if(bruceConfig.irTx==0) bruceConfig.irTx = LED; // quickfix init issue? CARDPUTER is 44 // ir tx
// : NEC, NECext, NEC42, NEC42ext, Samsung32, RC6, RC5, RC5X, SIRC, SIRC15, SIRC20, Kaseikyo, RCA @@ -332,7 +332,7 @@ bool processSerialCommand(String cmd_str) { } // turn off the led - digitalWrite(IrTx, LED_OFF); + digitalWrite(bruceConfig.irTx, LED_OFF); //backToMenu(); return false; } // end of ir commands @@ -342,11 +342,11 @@ bool processSerialCommand(String cmd_str) { if(cmd_str.startsWith("subghz rx")) { /* const char* args = cmd_str.c_str() + strlen("subghz rx"); - float frequency=RfFreq; // global default + float frequency=bruceConfig.rfFreq; // global default if(strlen(args)>1) sscanf(args, " %f", &frequency); * */ String args = cmd_str.substring(cmd_str.indexOf(" ", strlen("subghz rx"))); - float frequency=RfFreq; // global default + float frequency=bruceConfig.rfFreq; // global default if(args.length()>1) { sscanf(args.c_str(), " %f", &frequency); frequency /= 1000000; // passed as a long int (e.g. 433920000) @@ -766,23 +766,23 @@ bool processSerialCommand(String cmd_str) { } // else change the passed settings // TODO: check if valid values - if(setting_name=="bright") bright = setting_value.toInt(); - if(setting_name=="dimmerSet") dimmerSet = setting_value.toInt(); + if(setting_name=="bright") bruceConfig.bright = setting_value.toInt(); + if(setting_name=="dimmerSet") bruceConfig.dimmerSet = setting_value.toInt(); if(setting_name=="rot") bruceConfig.rotation = setting_value.toInt(); if(setting_name=="Bruce_FGCOLOR") FGCOLOR = setting_value.toInt(); - if(setting_name=="IrTx") IrTx = setting_value.toInt(); - if(setting_name=="IrRx") IrRx = setting_value.toInt(); - if(setting_name=="RfTx") RfTx = setting_value.toInt(); - if(setting_name=="RfRx") RfRx = setting_value.toInt(); - if(setting_name=="RfModule" && setting_value.toInt() <=1) RfModule = setting_value.toInt(); - if(setting_name=="RfFreq" && setting_value.toFloat()) RfFreq = setting_value.toFloat(); - 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; + if(setting_name=="irTx") bruceConfig.irTx = setting_value.toInt(); + if(setting_name=="irRx") bruceConfig.irRx = setting_value.toInt(); + if(setting_name=="rfTx") bruceConfig.rfTx = setting_value.toInt(); + if(setting_name=="RrfRx") bruceConfig.rfRx = setting_value.toInt(); + if(setting_name=="rfModule" && setting_value.toInt() <=1) bruceConfig.rfModule = setting_value.toInt(); + if(setting_name=="rfFreq" && setting_value.toFloat()) bruceConfig.rfFreq = setting_value.toFloat(); + if(setting_name=="tmz") bruceConfig.tmz = setting_value.toInt(); + if(setting_name=="wuiUsr") bruceConfig.wuiUsr = setting_value; + if(setting_name=="wuiPwd") bruceConfig.wuiPwd = setting_value; + if(setting_name=="rfidModule") bruceConfig.rfidModule = setting_value.toInt(); + if(setting_name=="devMode") bruceConfig.devMode = setting_value.toInt(); + if(setting_name=="soundEnabled") bruceConfig.soundEnabled = setting_value.toInt(); + if(setting_name=="wigleBasicToken") bruceConfig.wigleBasicToken = setting_value; saveConfigs(); serializeJsonPretty(settings, Serial); Serial.println(""); diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 0599f6a2..776d33bf 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -18,7 +18,7 @@ ** save brightness value into EEPROM **********************************************************************/ void setBrightness(int brightval, bool save) { - if(bright>100) bright=100; + if(bruceConfig.bright>100) bruceConfig.bright=100; #if defined(STICK_C_PLUS2) || defined(CARDPUTER) if(brightval == 0){ @@ -52,7 +52,7 @@ void setBrightness(int brightval, bool save) { #endif if(save){ - bright=brightval; + bruceConfig.bright=brightval; write_eeprom(EEPROM_BRIGHT, brightval); } } @@ -62,29 +62,29 @@ void setBrightness(int brightval, bool save) { ** save brightness value into EEPROM **********************************************************************/ void getBrightness() { - bright = read_eeprom(EEPROM_BRIGHT); - if(bright>100) { - bright = 100; + bruceConfig.bright = read_eeprom(EEPROM_BRIGHT); + if(bruceConfig.bright>100) { + bruceConfig.bright = 100; #if defined(STICK_C_PLUS2) || defined(CARDPUTER) - int bl = MINBRIGHT + round(((255 - MINBRIGHT) * bright/100 )); + int bl = MINBRIGHT + round(((255 - MINBRIGHT) * bruceConfig.bright/100 )); analogWrite(BACKLIGHT, bl); #elif defined(STICK_C_PLUS) - axp192.ScreenBreath(bright); + axp192.ScreenBreath(bruceConfig.bright); #elif defined(CORE2) - M5.Axp.ScreenBreath(bright); + M5.Axp.ScreenBreath(bruceConfig.bright); #elif defined(CORE) - uint8_t _tmp = (255*bright)/100; + uint8_t _tmp = (255*bruceConfig.bright)/100; M5.Lcd.setBrightness(_tmp); #elif defined(M5STACK) - M5.Display.setBrightness(bright); + M5.Display.setBrightness(bruceConfig.bright); #elif defined(CYD) int dutyCycle; - if (bright==100) dutyCycle=255; - else if (bright==75) dutyCycle=130; - else if (bright==50) dutyCycle=70; - else if (bright==25) dutyCycle=20; - else if (bright==0) dutyCycle=5; - else dutyCycle = ((bright*255)/100); + if (bruceConfig.bright==100) dutyCycle=255; + else if (bruceConfig.bright==75) dutyCycle=130; + else if (bruceConfig.bright==50) dutyCycle=70; + else if (bruceConfig.bright==25) dutyCycle=20; + else if (bruceConfig.bright==0) dutyCycle=5; + else dutyCycle = ((bruceConfig.bright*255)/100); log_i("dutyCycle for bright 0-255: %d",dutyCycle); ledcWrite(TFT_BRIGHT_CHANNEL,dutyCycle); // Channel 0 #else @@ -94,25 +94,25 @@ void getBrightness() { } #if defined(STICK_C_PLUS2) || defined(CARDPUTER) - int bl = MINBRIGHT + round(((255 - MINBRIGHT) * bright/100 )); + int bl = MINBRIGHT + round(((255 - MINBRIGHT) * bruceConfig.bright/100 )); analogWrite(BACKLIGHT, bl); #elif defined(STICK_C_PLUS) - axp192.ScreenBreath(bright); + axp192.ScreenBreath(bruceConfig.bright); #elif defined(CORE2) - M5.Axp.ScreenBreath(bright); + M5.Axp.ScreenBreath(bruceConfig.bright); #elif defined(CORE) - uint8_t _tmp = (255*bright)/100; + uint8_t _tmp = (255*bruceConfig.bright)/100; M5.Lcd.setBrightness(_tmp); #elif defined(M5STACK) - M5.Display.setBrightness(bright); + M5.Display.setBrightness(bruceConfig.bright); #elif defined(CYD) int dutyCycle; - if (bright==100) dutyCycle=255; - else if (bright==75) dutyCycle=130; - else if (bright==50) dutyCycle=70; - else if (bright==25) dutyCycle=20; - else if (bright==0) dutyCycle=5; - else dutyCycle = ((bright*255)/100); + if (bruceConfig.bright==100) dutyCycle=255; + else if (bruceConfig.bright==75) dutyCycle=130; + else if (bruceConfig.bright==50) dutyCycle=70; + else if (bruceConfig.bright==25) dutyCycle=20; + else if (bruceConfig.bright==0) dutyCycle=5; + else dutyCycle = ((bruceConfig.bright*255)/100); log_i("dutyCycle for bright 0-255: %d",dutyCycle); ledcWrite(TFT_BRIGHT_CHANNEL,dutyCycle); // Channel 0 #else @@ -152,8 +152,8 @@ int gsetRotation(bool set){ void setDimmerTime(int dimmerTime) { if(dimmerTime>60 || dimmerTime<0) dimmerTime = 0; - dimmerSet=dimmerTime; - write_eeprom(EEPROM_DIMMER, dimmerSet); + bruceConfig.dimmerSet=dimmerTime; + write_eeprom(EEPROM_DIMMER, bruceConfig.dimmerSet); } /********************************************************************* @@ -161,8 +161,8 @@ void setDimmerTime(int dimmerTime) { ** Get dimmerSet value from EEPROM **********************************************************************/ void getDimmerSet() { - dimmerSet = read_eeprom(EEPROM_DIMMER); - if(dimmerSet>60 || dimmerSet<0) setDimmerTime(0); + bruceConfig.dimmerSet = read_eeprom(EEPROM_DIMMER); + if(bruceConfig.dimmerSet>60 || bruceConfig.dimmerSet<0) setDimmerTime(0); } /********************************************************************* @@ -171,18 +171,18 @@ void getDimmerSet() { **********************************************************************/ void setBrightnessMenu() { int idx=0; - if(bright==100) idx=0; - else if(bright==75) idx=1; - else if(bright==50) idx=2; - else if(bright==25) idx=3; - else if(bright== 1) idx=4; + if(bruceConfig.bright==100) idx=0; + else if(bruceConfig.bright==75) idx=1; + else if(bruceConfig.bright==50) idx=2; + else if(bruceConfig.bright==25) idx=3; + else if(bruceConfig.bright== 1) idx=4; options = { - {"100%", [=]() { setBrightness(100); }, bright == 100 }, - {"75 %", [=]() { setBrightness(75); }, bright == 75 }, - {"50 %", [=]() { setBrightness(50); }, bright == 50 }, - {"25 %", [=]() { setBrightness(25); }, bright == 25 }, - {" 1 %", [=]() { setBrightness(1); }, bright == 1 }, + {"100%", [=]() { setBrightness(100); }, bruceConfig.bright == 100 }, + {"75 %", [=]() { setBrightness(75); }, bruceConfig.bright == 75 }, + {"50 %", [=]() { setBrightness(50); }, bruceConfig.bright == 50 }, + {"25 %", [=]() { setBrightness(25); }, bruceConfig.bright == 25 }, + {" 1 %", [=]() { setBrightness(1); }, bruceConfig.bright == 1 }, {"Main Menu", [=]() { backToMenu(); }}, }; delay(200); @@ -217,17 +217,17 @@ void setSleepMode() { **********************************************************************/ void setDimmerTimeMenu() { int idx=0; - if(dimmerSet==60) idx=0; - else if(dimmerSet==20) idx=1; - else if(dimmerSet==30) idx=2; - else if(dimmerSet==60) idx=3; - else if(dimmerSet== 0) idx=4; + if(bruceConfig.dimmerSet==10) idx=0; + else if(bruceConfig.dimmerSet==20) idx=1; + else if(bruceConfig.dimmerSet==30) idx=2; + else if(bruceConfig.dimmerSet==60) idx=3; + else if(bruceConfig.dimmerSet== 0) idx=4; options = { - {"10s", [=]() { setDimmerTime(10); }, dimmerSet == 10 ? true:false}, - {"20s", [=]() { setDimmerTime(20); }, dimmerSet == 20 ? true:false}, - {"30s", [=]() { setDimmerTime(30); }, dimmerSet == 30 ? true:false}, - {"60s", [=]() { setDimmerTime(60); }, dimmerSet == 60 ? true:false}, - {"Disabled", [=]() { setDimmerTime(0); }, dimmerSet == 0 ? true:false}, + {"10s", [=]() { setDimmerTime(10); }, bruceConfig.dimmerSet == 10 }, + {"20s", [=]() { setDimmerTime(20); }, bruceConfig.dimmerSet == 20 }, + {"30s", [=]() { setDimmerTime(30); }, bruceConfig.dimmerSet == 30 }, + {"60s", [=]() { setDimmerTime(60); }, bruceConfig.dimmerSet == 60 }, + {"Disabled", [=]() { setDimmerTime(0); }, bruceConfig.dimmerSet == 0 }, }; delay(200); loopOptions(options,idx); @@ -279,14 +279,14 @@ void setSoundConfig() { int result = 0; options = { - {"Sound off", [&]() { result = 0; }, soundEnabled == 0}, - {"Sound on", [&]() { result = 1; }, soundEnabled == 1}, + {"Sound off", [&]() { result = 0; }, bruceConfig.soundEnabled == 0}, + {"Sound on", [&]() { result = 1; }, bruceConfig.soundEnabled == 1}, }; delay(200); - loopOptions(options, soundEnabled); + loopOptions(options, bruceConfig.soundEnabled); delay(200); - soundEnabled=result; + bruceConfig.soundEnabled = result; } /********************************************************************* @@ -297,8 +297,8 @@ void setRFModuleMenu() { // TODO: save the setting in the EEPROM too? int result = 0; int idx=0; - if(RfModule==0) idx=0; - else if(RfModule==1) idx=1; + if(bruceConfig.rfModule==M5_RF_MODULE) idx=0; + else if(bruceConfig.rfModule==CC1101_SPI_MODULE) idx=1; options = { {"M5 RF433T/R", [&]() { result = 0; }}, @@ -318,8 +318,8 @@ void setRFModuleMenu() { #ifdef USE_CC1101_VIA_SPI ELECHOUSE_cc1101.Init(); if (ELECHOUSE_cc1101.getCC1101()){ - RfModule=1; - write_eeprom(EEPROM_RF_MODULE, RfModule); + bruceConfig.rfModule=CC1101_SPI_MODULE; + write_eeprom(EEPROM_RF_MODULE, bruceConfig.rfModule); return; } #endif @@ -328,8 +328,8 @@ void setRFModuleMenu() { while(!checkAnyKeyPress()); } // fallback to "M5 RF433T/R" on errors - RfModule=0; - write_eeprom(EEPROM_RF_MODULE, RfModule); + bruceConfig.rfModule=0; + write_eeprom(EEPROM_RF_MODULE, bruceConfig.rfModule); } /********************************************************************* @@ -339,18 +339,18 @@ void setRFModuleMenu() { void setRFFreqMenu() { // TODO: save the setting in the EEPROM too? float result = 433.92; - String freq_str = keyboard(String(RfFreq), 10, "Default frequency:"); + String freq_str = keyboard(String(bruceConfig.rfFreq), 10, "Default frequency:"); if(freq_str.length()>1) { result = freq_str.toFloat(); // returns 0 if not valid if(result>=300 && result<=928) { // TODO: check valid freq according to current module? - RfFreq=result; + bruceConfig.rfFreq=result; return; } } // else displayError("Invalid frequency"); - RfFreq=433.92; // reset to default + bruceConfig.rfFreq=433.92; // reset to default delay(1000); } @@ -362,16 +362,16 @@ void setRFIDModuleMenu() { int result = 0; options = { - {"M5 RFID2", [&]() { result = M5_RFID2_MODULE; }, RfidModule == M5_RFID2_MODULE}, - {"PN532 on I2C", [&]() { result = PN532_I2C_MODULE; }, RfidModule == PN532_I2C_MODULE}, - {"PN532 on SPI", [&]() { result = PN532_SPI_MODULE; }, RfidModule == PN532_SPI_MODULE}, + {"M5 RFID2", [&]() { result = M5_RFID2_MODULE; }, bruceConfig.rfidModule == M5_RFID2_MODULE}, + {"PN532 on I2C", [&]() { result = PN532_I2C_MODULE; }, bruceConfig.rfidModule == PN532_I2C_MODULE}, + {"PN532 on SPI", [&]() { result = PN532_SPI_MODULE; }, bruceConfig.rfidModule == PN532_SPI_MODULE}, }; delay(200); - loopOptions(options, RfidModule); + loopOptions(options, bruceConfig.rfidModule); delay(200); - RfidModule=result; - write_eeprom(EEPROM_RFID_MODULE, RfidModule); + bruceConfig.rfidModule = result; + write_eeprom(EEPROM_RFID_MODULE, bruceConfig.rfidModule); } @@ -413,21 +413,21 @@ void setClock() { if(!wifiConnected) wifiConnectMenu(); if(!returnToMenu) { options = { - {"Brasilia", [&]() { timeClient.setTimeOffset(-3 * 3600); tmz=0; }, tmz==0 ? true:false}, - {"Pernambuco",[&]() { timeClient.setTimeOffset(-2 * 3600); tmz=1; }, tmz==1 ? true:false}, - {"New York", [&]() { timeClient.setTimeOffset(-4 * 3600); tmz=2; }, tmz==2 ? true:false}, - {"Lisbon", [&]() { timeClient.setTimeOffset(1 * 3600); tmz=3; }, tmz==3 ? true:false}, - {"Hong Kong", [&]() { timeClient.setTimeOffset(8 * 3600); tmz=4; }, tmz==4 ? true:false}, - {"Sydney", [&]() { timeClient.setTimeOffset(10 * 3600); tmz=5; }, tmz==5 ? true:false}, - {"Tokyo", [&]() { timeClient.setTimeOffset(9 * 3600); tmz=6; }, tmz==6 ? true:false}, - {"Moscow", [&]() { timeClient.setTimeOffset(3 * 3600); tmz=7; }, tmz==7 ? true:false}, - {"Amsterdam", [&]() { timeClient.setTimeOffset(2 * 3600); tmz=8; }, tmz==8 ? true:false}, + {"Brasilia", [&]() { timeClient.setTimeOffset(-3 * 3600); bruceConfig.tmz=0; }, bruceConfig.tmz==0 }, + {"Pernambuco",[&]() { timeClient.setTimeOffset(-2 * 3600); bruceConfig.tmz=1; }, bruceConfig.tmz==1 }, + {"New York", [&]() { timeClient.setTimeOffset(-4 * 3600); bruceConfig.tmz=2; }, bruceConfig.tmz==2 }, + {"Lisbon", [&]() { timeClient.setTimeOffset(1 * 3600); bruceConfig.tmz=3; }, bruceConfig.tmz==3 }, + {"Hong Kong", [&]() { timeClient.setTimeOffset(8 * 3600); bruceConfig.tmz=4; }, bruceConfig.tmz==4 }, + {"Sydney", [&]() { timeClient.setTimeOffset(10 * 3600); bruceConfig.tmz=5; }, bruceConfig.tmz==5 }, + {"Tokyo", [&]() { timeClient.setTimeOffset(9 * 3600); bruceConfig.tmz=6; }, bruceConfig.tmz==6 }, + {"Moscow", [&]() { timeClient.setTimeOffset(3 * 3600); bruceConfig.tmz=7; }, bruceConfig.tmz==7 }, + {"Amsterdam", [&]() { timeClient.setTimeOffset(2 * 3600); bruceConfig.tmz=8; }, bruceConfig.tmz==8 }, {"Main Menu", [=]() { backToMenu(); }}, }; if (!returnToMenu) { delay(200); loopOptions(options); - write_eeprom(EEPROM_TMZ, tmz); + write_eeprom(EEPROM_TMZ, bruceConfig.tmz); delay(200); timeClient.begin(); @@ -540,7 +540,7 @@ void runClockLoop() { int gsetIrTxPin(bool set){ int result = read_eeprom(EEPROM_IR_TX); - if(result>50) IrTx = LED; + if(result>50) bruceConfig.irTx = LED; if(set) { options.clear(); std::vector> pins; @@ -548,23 +548,23 @@ int gsetIrTxPin(bool set){ int idx=100; int j=0; for (auto pin : pins) { - if(pin.second==IrTx && idx==100) idx=j; + if(pin.second==bruceConfig.irTx && idx==100) idx=j; j++; #ifdef ALLOW_ALL_GPIO_FOR_IR_RF int i=pin.second; if(i!=TFT_CS && i!=TFT_RST && i!=TFT_SCLK && i!=TFT_MOSI && i!=TFT_BL && i!=TOUCH_CS && i!=SDCARD_CS && i!=SDCARD_MOSI && i!=SDCARD_MISO) #endif - options.push_back({pin.first, [=]() { IrTx=pin.second; }, pin.second==IrTx ? true:false}); + options.push_back({pin.first, [=]() { bruceConfig.irTx=pin.second; }, pin.second==bruceConfig.irTx }); } delay(200); loopOptions(options, idx); delay(200); - Serial.println("Saved pin: " + String(IrTx)); - write_eeprom(EEPROM_IR_TX, IrTx); + Serial.println("Saved pin: " + String(bruceConfig.irTx)); + write_eeprom(EEPROM_IR_TX, bruceConfig.irTx); } returnToMenu=true; - return IrTx; + return bruceConfig.irTx; } /********************************************************************* @@ -574,7 +574,7 @@ int gsetIrTxPin(bool set){ int gsetIrRxPin(bool set){ int result = read_eeprom(EEPROM_IR_RX); - if(result>45) IrRx = GROVE_SCL; + if(result>45) bruceConfig.irRx = GROVE_SCL; if(set) { options.clear(); std::vector> pins; @@ -582,22 +582,22 @@ int gsetIrRxPin(bool set){ int idx=-1; int j=0; for (auto pin : pins) { - if(pin.second==IrRx && idx<0) idx=j; + if(pin.second==bruceConfig.irRx && idx<0) idx=j; j++; #ifdef ALLOW_ALL_GPIO_FOR_IR_RF int i=pin.second; if(i!=TFT_CS && i!=TFT_RST && i!=TFT_SCLK && i!=TFT_MOSI && i!=TFT_BL && i!=TOUCH_CS && i!=SDCARD_CS && i!=SDCARD_MOSI && i!=SDCARD_MISO) #endif - options.push_back({pin.first, [=]() {IrRx=pin.second;}, pin.second==IrRx ? true:false}); + options.push_back({pin.first, [=]() {bruceConfig.irRx=pin.second;}, pin.second==bruceConfig.irRx }); } delay(200); loopOptions(options); delay(200); - write_eeprom(EEPROM_IR_RX, IrRx); + write_eeprom(EEPROM_IR_RX, bruceConfig.irRx); } returnToMenu=true; - return IrRx; + return bruceConfig.irRx; } /********************************************************************* @@ -607,7 +607,7 @@ int gsetIrRxPin(bool set){ int gsetRfTxPin(bool set){ int result = read_eeprom(EEPROM_RF_TX); - if(result>45) RfTx = GROVE_SDA; + if(result>45) bruceConfig.rfTx = GROVE_SDA; if(set) { options.clear(); std::vector> pins; @@ -615,22 +615,22 @@ int gsetRfTxPin(bool set){ int idx=-1; int j=0; for (auto pin : pins) { - if(pin.second==RfTx && idx<0) idx=j; + if(pin.second==bruceConfig.rfTx && idx<0) idx=j; j++; #ifdef ALLOW_ALL_GPIO_FOR_IR_RF int i=pin.second; if(i!=TFT_CS && i!=TFT_RST && i!=TFT_SCLK && i!=TFT_MOSI && i!=TFT_BL && i!=TOUCH_CS && i!=SDCARD_CS && i!=SDCARD_MOSI && i!=SDCARD_MISO) #endif - options.push_back({pin.first, [=]() {RfTx=pin.second;}, pin.second==RfTx ? true:false}); + options.push_back({pin.first, [=]() {bruceConfig.rfTx=pin.second;}, pin.second==bruceConfig.rfTx }); } delay(200); loopOptions(options); delay(200); - write_eeprom(EEPROM_RF_TX, RfTx); + write_eeprom(EEPROM_RF_TX, bruceConfig.rfTx); } returnToMenu=true; - return RfTx; + return bruceConfig.rfTx; } /********************************************************************* ** Function: gsetRfRxPin @@ -639,7 +639,7 @@ int gsetRfTxPin(bool set){ int gsetRfRxPin(bool set){ int result = read_eeprom(EEPROM_RF_RX); - if(result>36) RfRx = GROVE_SCL; + if(result>36) bruceConfig.rfRx = GROVE_SCL; if(set) { options.clear(); std::vector> pins; @@ -647,22 +647,22 @@ int gsetRfRxPin(bool set){ int idx=-1; int j=0; for (auto pin : pins) { - if(pin.second==RfRx && idx<0) idx=j; + if(pin.second==bruceConfig.rfRx && idx<0) idx=j; j++; #ifdef ALLOW_ALL_GPIO_FOR_IR_RF int i=pin.second; if(i!=TFT_CS && i!=TFT_RST && i!=TFT_SCLK && i!=TFT_MOSI && i!=TFT_BL && i!=TOUCH_CS && i!=SDCARD_CS && i!=SDCARD_MOSI && i!=SDCARD_MISO) #endif - options.push_back({pin.first, [=]() {RfRx=pin.second;}, pin.second==RfRx ? true:false}); + options.push_back({pin.first, [=]() {bruceConfig.rfRx=pin.second;}, pin.second==bruceConfig.rfRx }); } delay(200); loopOptions(options); delay(200); - write_eeprom(EEPROM_RF_RX, RfRx); + write_eeprom(EEPROM_RF_RX, bruceConfig.rfRx); } returnToMenu=true; - return RfRx; + return bruceConfig.rfRx; } void getConfigs() { @@ -676,9 +676,9 @@ void getConfigs() { if(file) { // init with default settings #if ROTATION > 1 - file.print("[{\"rot\":3,\"dimmerSet\":10,\"bright\":100,\"wui_usr\":\"admin\",\"wui_pwd\":\"bruce\",\"Bruce_FGCOLOR\":43023,\"IrTx\":" + String(LED) + ",\"IrRx\":" + String(GROVE_SCL) + ",\"RfTx\":" + String(GROVE_SDA) + ",\"RfRx\":" + String(GROVE_SCL) + ",\"tmz\":3,\"RfModule\":0,\"RfFreq\":433.92,\"RfFxdFreq\":1,\"RfScanRange\":3,\"RfidModule\":" + String(RfidModule) + ",\"wifi\":[{\"ssid\":\"myNetSSID\",\"pwd\":\"myNetPassword\"}],\"wifi_ap\":{\"ssid\":\"BruceNet\",\"pwd\":\"brucenet\"},\"wigleBasicToken\":\"\",\"devMode\":0,\"soundEnabled\":1}]"); + file.print("[{\"rot\":3,\"dimmerSet\":10,\"bright\":100,\"wuiUsr\":\"admin\",\"wuiPwd\":\"bruce\",\"Bruce_FGCOLOR\":43023,\"irTx\":" + String(LED) + ",\"irRx\":" + String(GROVE_SCL) + ",\"rfTx\":" + String(GROVE_SDA) + ",\"rfRx\":" + String(GROVE_SCL) + ",\"tmz\":3,\"rfModule\":0,\"rfFreq\":433.92,\"rfFxdFreq\":1,\"rfScanRange\":3,\"rfidModule\":" + String(bruceConfig.rfidModule) + ",\"wifi\":[{\"ssid\":\"myNetSSID\",\"pwd\":\"myNetPassword\"}],\"wifi_ap\":{\"ssid\":\"BruceNet\",\"pwd\":\"brucenet\"},\"wigleBasicToken\":\"\",\"devMode\":0,\"soundEnabled\":1}]"); #else - file.print("[{\"rot\":1,\"dimmerSet\":10,\"bright\":100,\"wui_usr\":\"admin\",\"wui_pwd\":\"bruce\",\"Bruce_FGCOLOR\":43023,\"IrTx\":" + String(LED) + ",\"IrRx\":" + String(GROVE_SCL) + ",\"RfTx\":" + String(GROVE_SDA) + ",\"RfRx\":" + String(GROVE_SCL) + ",\"tmz\":3,\"RfModule\":0,\"RfFreq\":433.92,\"RfFxdFreq\":1,\"RfScanRange\":3,\"RfidModule\":" + String(RfidModule) + ",\"wifi\":[{\"ssid\":\"myNetSSID\",\"pwd\":\"myNetPassword\"}],\"wigleBasicToken\":\"\",\"devMode\":0,\"soundEnabled\":1}]"); + file.print("[{\"rot\":1,\"dimmerSet\":10,\"bright\":100,\"wuiUsr\":\"admin\",\"wuiPwd\":\"bruce\",\"Bruce_FGCOLOR\":43023,\"irTx\":" + String(LED) + ",\"irRx\":" + String(GROVE_SCL) + ",\"rfTx\":" + String(GROVE_SDA) + ",\"rfRx\":" + String(GROVE_SCL) + ",\"tmz\":3,\"rfModule\":0,\"rfFreq\":433.92,\"rfFxdFreq\":1,\"rfScanRange\":3,\"rfidModule\":" + String(bruceConfig.rfidModule) + ",\"wifi\":[{\"ssid\":\"myNetSSID\",\"pwd\":\"myNetPassword\"}],\"wigleBasicToken\":\"\",\"devMode\":0,\"soundEnabled\":1}]"); #endif } file.close(); @@ -698,23 +698,23 @@ void getConfigs() { } else log_i("getConfigs: deserialized correctly"); setting = settings[0]; - if(setting.containsKey("bright")) { bright = setting["bright"].as(); } else { count++; log_i("Fail"); } - if(setting.containsKey("dimmerSet")) { dimmerSet = setting["dimmerSet"].as(); } else { count++; log_i("Fail"); } + if(setting.containsKey("bright")) { bruceConfig.bright = setting["bright"].as(); } else { count++; log_i("Fail"); } + if(setting.containsKey("dimmerSet")) { bruceConfig.dimmerSet = setting["dimmerSet"].as(); } else { count++; log_i("Fail"); } if(setting.containsKey("rot")) { bruceConfig.rotation = setting["rot"].as(); } else { count++; log_i("Fail"); } if(setting.containsKey("Bruce_FGCOLOR")) { FGCOLOR = setting["Bruce_FGCOLOR"].as(); } else { count++; log_i("Fail"); } - if(setting.containsKey("wui_usr")) { wui_usr = setting["wui_usr"].as(); } else { count++; log_i("Fail"); } - if(setting.containsKey("wui_pwd")) { wui_pwd = setting["wui_pwd"].as(); } else { count++; log_i("Fail"); } - - if(setting.containsKey("IrTx")) { IrTx = setting["IrTx"].as(); } else { count++; log_i("Fail"); } - if(setting.containsKey("IrRx")) { IrRx = setting["IrRx"].as(); } else { count++; log_i("Fail"); } - if(setting.containsKey("RfTx")) { RfTx = setting["RfTx"].as(); } else { count++; log_i("Fail"); } - if(setting.containsKey("RfRx")) { RfRx = setting["RfRx"].as(); } else { count++; log_i("Fail"); } - if(setting.containsKey("tmz")) { tmz = setting["tmz"].as(); } else { count++; log_i("Fail"); } - if(setting.containsKey("RfModule")) { RfModule = setting["RfModule"].as(); } else { count++; log_i("Fail"); } - if(setting.containsKey("RfFreq")) { RfFreq = setting["RfFreq"].as(); } else { count++; log_i("Fail"); } - if(setting.containsKey("RfFxdFreq")) { RfFxdFreq = setting["RfFxdFreq"].as(); } else { count++; log_i("Fail"); } - if(setting.containsKey("RfScanRange")) { RfScanRange = setting["RfScanRange"].as(); } else { count++; log_i("Fail"); } - if(setting.containsKey("RfidModule")) { RfidModule = setting["RfidModule"].as(); } else { count++; log_i("Fail"); } + if(setting.containsKey("wuiUsr")) { bruceConfig.wuiUsr = setting["wuiUsr"].as(); } else { count++; log_i("Fail"); } + if(setting.containsKey("wuiPwd")) { bruceConfig.wuiPwd = setting["wuiPwd"].as(); } else { count++; log_i("Fail"); } + + if(setting.containsKey("irTx")) { bruceConfig.irTx = setting["irTx"].as(); } else { count++; log_i("Fail"); } + if(setting.containsKey("irRx")) { bruceConfig.irRx = setting["irRx"].as(); } else { count++; log_i("Fail"); } + if(setting.containsKey("rfTx")) { bruceConfig.rfTx = setting["rfTx"].as(); } else { count++; log_i("Fail"); } + if(setting.containsKey("rfRx")) { bruceConfig.rfRx = setting["rfRx"].as(); } else { count++; log_i("Fail"); } + if(setting.containsKey("tmz")) { bruceConfig.tmz = setting["tmz"].as(); } else { count++; log_i("Fail"); } + if(setting.containsKey("rfModule")) { bruceConfig.rfModule = setting["rfModule"].as(); } else { count++; log_i("Fail"); } + if(setting.containsKey("rfFreq")) { bruceConfig.rfFreq = setting["rfFreq"].as(); } else { count++; log_i("Fail"); } + if(setting.containsKey("rfFxdFreq")) { bruceConfig.rfFxdFreq = setting["rfFxdFreq"].as(); } else { count++; log_i("Fail"); } + if(setting.containsKey("rfScanRange")) { bruceConfig.rfScanRange = setting["rfScanRange"].as(); } else { count++; log_i("Fail"); } + if(setting.containsKey("rfidModule")) { bruceConfig.rfidModule = setting["rfidModule"].as(); } else { count++; log_i("Fail"); } if(!setting.containsKey("wifi")) { count++; log_i("Fail"); } @@ -726,14 +726,14 @@ void getConfigs() { count++; log_i("Fail"); } - if(setting.containsKey("wigleBasicToken")) { wigleBasicToken = setting["wigleBasicToken"].as(); } else { count++; log_i("Fail"); } + if(setting.containsKey("wigleBasicToken")) { bruceConfig.wigleBasicToken = setting["wigleBasicToken"].as(); } else { count++; log_i("Fail"); } - if(setting.containsKey("devMode")) { devMode = setting["devMode"].as(); } else { count++; log_i("Fail"); } - if(setting.containsKey("soundEnabled")) { soundEnabled = setting["soundEnabled"].as(); } else { count++; log_i("Fail"); } + if(setting.containsKey("devMode")) { bruceConfig.devMode = setting["devMode"].as(); } else { count++; log_i("Fail"); } + if(setting.containsKey("soundEnabled")) { bruceConfig.soundEnabled = setting["soundEnabled"].as(); } else { count++; log_i("Fail"); } - log_i("Brightness: %d", bright); - setBrightness(bright); - if(dimmerSet<0) dimmerSet=10; + log_i("Brightness: %d", bruceConfig.bright); + setBrightness(bruceConfig.bright); + if(bruceConfig.dimmerSet<0) bruceConfig.dimmerSet=10; file.close(); if(count>0) saveConfigs(); @@ -761,22 +761,22 @@ void saveConfigs() { if(setupSdCard()) fs = &SD; // prefer SD card if available JsonObject setting = settings[0]; - setting["bright"] = bright; - setting["dimmerSet"] = dimmerSet; + setting["bright"] = bruceConfig.bright; + setting["dimmerSet"] = bruceConfig.dimmerSet; setting["rot"] = bruceConfig.rotation; setting["Bruce_FGCOLOR"] = FGCOLOR; - setting["wui_usr"] = wui_usr; - setting["wui_pwd"] = wui_pwd; - setting["IrTx"] = IrTx; - setting["IrRx"] = IrRx; - setting["RfTx"] = RfTx; - setting["RfRx"] = RfRx; - setting["RfModule"] = RfModule; - setting["RfFreq"] = RfFreq; - setting["RfFxdFreq"] = RfFxdFreq; - setting["RfScanRange"] = RfScanRange; - setting["RfidModule"] = RfidModule; - setting["tmz"] = tmz; + setting["wuiUsr"] = bruceConfig.wuiUsr; + setting["wuiPwd"] = bruceConfig.wuiPwd; + setting["irTx"] = bruceConfig.irTx; + setting["irRx"] = bruceConfig.irRx; + setting["rfTx"] = bruceConfig.rfTx; + setting["rfRx"] = bruceConfig.rfRx; + setting["rfModule"] = bruceConfig.rfModule; + setting["rfFreq"] = bruceConfig.rfFreq; + setting["rfFxdFreq"] = bruceConfig.rfFxdFreq; + setting["rfScanRange"] = bruceConfig.rfScanRange; + setting["rfidModule"] = bruceConfig.rfidModule; + setting["tmz"] = bruceConfig.tmz; if(!setting.containsKey("wifi")) { JsonArray WifiList = setting["wifi"].to(); if(WifiList.size()<1) { @@ -790,9 +790,9 @@ void saveConfigs() { WifiAp["ssid"] = ap_ssid; WifiAp["pwd"] = ap_pwd; } - setting["wigleBasicToken"] = wigleBasicToken; - setting["devMode"] = devMode; - setting["soundEnabled"] = soundEnabled; + setting["wigleBasicToken"] = bruceConfig.wigleBasicToken; + setting["devMode"] = bruceConfig.devMode; + setting["soundEnabled"] = bruceConfig.soundEnabled; // Open file for writing File file = fs->open(CONFIG_FILE, FILE_WRITE); if (!file) { diff --git a/src/core/wifi_common.cpp b/src/core/wifi_common.cpp index b372b0ab..2ea20c8c 100644 --- a/src/core/wifi_common.cpp +++ b/src/core/wifi_common.cpp @@ -12,8 +12,7 @@ ***************************************************************************************/ bool wifiConnect(String ssid, int encryptation, bool isAP) { if(!isAP) { - int tmz; - tmz = read_eeprom(EEPROM_TMZ); // read timezone + int tmz = bruceConfig.tmz; pwd = read_eeprom_string(EEPROM_PWD); //password if(tmz>8) tmz=0; bool found = false; diff --git a/src/main.cpp b/src/main.cpp index 13546a70..74e9dc2f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,22 +18,7 @@ SPIClass CC_NRF_SPI; // Public Globals Variables unsigned long previousMillis = millis(); int prog_handler; // 0 - Flash, 1 - LittleFS, 3 - Download -int IrTx; -int IrRx; -int RfTx; -int RfRx; -int RfModule=0; // 0 - single-pinned, 1 - CC1101+SPI -float RfFreq=433.92; -int RfFxdFreq = 1; -int RfScanRange = 3; -int RfidModule=M5_RFID2_MODULE; String cachedPassword=""; -String wigleBasicToken=""; -int dimmerSet; -int bright=100; -int tmz=0; -int devMode=0; -int soundEnabled=1; bool interpreter_start = false; bool sdcardMounted = false; bool gpsConnected = false; @@ -57,8 +42,6 @@ struct tm* timeInfo; #endif JsonDocument settings; -String wui_usr="admin"; -String wui_pwd="bruce"; String ssid; String pwd; String ap_ssid="BruceNet"; @@ -145,7 +128,6 @@ void setup_gpio() { #if defined(BACKLIGHT) pinMode(BACKLIGHT, OUTPUT); #endif - //if(RfModule==1) initCC1101once(&sdcardSPI); // Sets GPIO in the CC1101 lib } diff --git a/src/modules/bjs_interpreter/interpreter.cpp b/src/modules/bjs_interpreter/interpreter.cpp index 754bc579..ef42cfa3 100644 --- a/src/modules/bjs_interpreter/interpreter.cpp +++ b/src/modules/bjs_interpreter/interpreter.cpp @@ -632,9 +632,9 @@ static duk_ret_t native_subghzRead(duk_context *ctx) { // returns a string of the generated sub file, empty string on timeout or other errors (decoding failed) String r = ""; if(duk_is_number(ctx, 0)) - r = RCSwitch_Read(RfFreq, duk_to_int(ctx, 0)); // custom timeout + r = RCSwitch_Read(bruceConfig.rfFreq, duk_to_int(ctx, 0)); // custom timeout else - r = RCSwitch_Read(RfFreq, 10); + r = RCSwitch_Read(bruceConfig.rfFreq, 10); duk_push_string(ctx, r.c_str()); return 1; } @@ -642,9 +642,9 @@ static duk_ret_t native_subghzRead(duk_context *ctx) { static duk_ret_t native_subghzReadRaw(duk_context *ctx) { String r = ""; if(duk_is_number(ctx, 0)) - r = RCSwitch_Read(RfFreq, duk_to_int(ctx, 0), true); // custom timeout + r = RCSwitch_Read(bruceConfig.rfFreq, duk_to_int(ctx, 0), true); // custom timeout else - r = RCSwitch_Read(RfFreq, 10, true); + r = RCSwitch_Read(bruceConfig.rfFreq, 10, true); duk_push_string(ctx, r.c_str()); return 1; } @@ -653,7 +653,7 @@ static duk_ret_t native_subghzReadRaw(duk_context *ctx) { static duk_ret_t native_subghzSetFrequency(duk_context *ctx) { // usage: subghzSetFrequency(freq_as_float); if(duk_is_number(ctx, 0)) - RfFreq = duk_to_number(ctx, 0); // float global var + bruceConfig.rfFreq = duk_to_number(ctx, 0); // float global var return 0; } diff --git a/src/modules/ir/TV-B-Gone.cpp b/src/modules/ir/TV-B-Gone.cpp index 720ee916..3585c4a7 100644 --- a/src/modules/ir/TV-B-Gone.cpp +++ b/src/modules/ir/TV-B-Gone.cpp @@ -114,7 +114,7 @@ void checkIrTxPin(){ const std::vector> pins = IR_TX_PINS; int count=0; for (auto pin : pins) { - if(pin.second==IrTx) count++; + if(pin.second==bruceConfig.irTx) count++; } if(count>0) return; else gsetIrTxPin(true); @@ -123,9 +123,9 @@ void checkIrTxPin(){ void StartTvBGone() { Serial.begin(115200); checkIrTxPin(); - IRsend irsend(IrTx); // Set the GPIO to be used to sending the message. + IRsend irsend(bruceConfig.irTx); // Set the GPIO to be used to sending the message. irsend.begin(); - pinMode(IrTx, OUTPUT); + pinMode(bruceConfig.irTx, OUTPUT); // determine region options = { @@ -202,7 +202,7 @@ void StartTvBGone() { } //turnoff LED - digitalWrite(IrTx,LED_OFF); + digitalWrite(bruceConfig.irTx,LED_OFF); } } //end of sendAllCodes @@ -259,7 +259,7 @@ struct Codes selectRecentIrMenu() { // else options.push_back({ recent_ircodes[i].filepath.c_str(), [i, &selected_code](){ selected_code = recent_ircodes[i]; }}); } - options.push_back({ "Main Menu" , [&](){ exit=true; }}); + options.push_back({ "Main Menu" , [&](){ exit=true; }}); delay(200); loopOptions(options); return(selected_code); @@ -271,11 +271,11 @@ bool txIrFile(FS *fs, String filepath) { int total_codes = 0; String line; - + File databaseFile = fs->open(filepath, FILE_READ); - pinMode(IrTx, OUTPUT); - //digitalWrite(IrTx, LED_ON); + pinMode(bruceConfig.irTx, OUTPUT); + //digitalWrite(bruceConfig.irTx, LED_ON); if (!databaseFile) { Serial.println("Failed to open database file."); @@ -284,7 +284,7 @@ bool txIrFile(FS *fs, String filepath) { return false; } Serial.println("Opened database file."); - + bool endingEarly; int codes_sent=0; uint16_t frequency = 0; @@ -294,9 +294,9 @@ bool txIrFile(FS *fs, String filepath) { String command = ""; String value = ""; String bits = "32"; - + databaseFile.seek(0); // comes back to first position - + // count the number of codes to replay while (databaseFile.available()) { line = databaseFile.readStringUntil('\n'); @@ -418,7 +418,7 @@ bool txIrFile(FS *fs, String filepath) { Serial.println("EXTRA finished"); resetCodesArray(); - digitalWrite(IrTx, LED_OFF); + digitalWrite(bruceConfig.irTx, LED_OFF); return true; } @@ -431,19 +431,19 @@ void otherIRcodes() { File databaseFile; FS *fs = NULL; struct Codes selected_code; - + returnToMenu = true; // make sure menu is redrawn when quitting in any point - + options = { {"Recent", [&]() { selected_code = selectRecentIrMenu(); }}, {"LittleFS", [&]() { fs=&LittleFS; }}, }; - if(setupSdCard()) options.push_back({"SD Card", [&]() { fs=&SD; }}); + if(setupSdCard()) options.push_back({"SD Card", [&]() { fs=&SD; }}); delay(200); loopOptions(options); delay(200); - + if(fs == NULL) { // recent menu was selected if(selected_code.filepath!="") { // a code was selected, switch on code type if(selected_code.type=="raw") sendRawCommand(selected_code.frequency, selected_code.data); @@ -457,12 +457,12 @@ void otherIRcodes() { return; // no need to proceed, go back } - + // select a file to tx filepath = loopSD(*fs, true, "IR"); if(filepath=="") return; // cancelled // else - + // select mode bool mode_cmd=true; options = { @@ -478,9 +478,9 @@ void otherIRcodes() { txIrFile(fs, filepath); return; } - + // else continue and try to parse the file - + databaseFile = fs->open(filepath, FILE_READ); drawMainBorder(); @@ -491,11 +491,11 @@ void otherIRcodes() { return; } Serial.println("Opened database file."); - - pinMode(IrTx, OUTPUT); - //digitalWrite(IrTx, LED_ON); - // Mode to choose and send command by command limitted to 50 commands + pinMode(bruceConfig.irTx, OUTPUT); + //digitalWrite(bruceConfig.irTx, LED_ON); + + // Mode to choose and send command by command limitted to 50 commands String line; String txt; while (databaseFile.available() && total_codes<50) { @@ -526,7 +526,7 @@ void otherIRcodes() { options.push_back({ "Main Menu" , [&](){ exit=true; }}); databaseFile.close(); - digitalWrite(IrTx, LED_OFF); + digitalWrite(bruceConfig.irTx, LED_OFF); int idx=0; while (1) { delay(200); @@ -539,7 +539,7 @@ void otherIRcodes() { //IR commands void sendNECCommand(String address, String command) { - IRsend irsend(IrTx); // Set the GPIO to be used to sending the message. + IRsend irsend(bruceConfig.irTx); // Set the GPIO to be used to sending the message. irsend.begin(); displayRedStripe("Sending..",TFT_WHITE,FGCOLOR); uint8_t first_zero_byte_pos = address.indexOf("00", 2); @@ -551,12 +551,12 @@ void sendNECCommand(String address, String command) { uint64_t data = irsend.encodeNEC(addressValue, commandValue); irsend.sendNEC(data, 32, 10); Serial.println("Sent NEC Command"); - digitalWrite(IrTx, LED_OFF); + digitalWrite(bruceConfig.irTx, LED_OFF); } void sendRC5Command(String address, String command) { - IRsend irsend(IrTx,true); // Set the GPIO to be used to sending the message. + IRsend irsend(bruceConfig.irTx,true); // Set the GPIO to be used to sending the message. irsend.begin(); displayRedStripe("Sending..",TFT_WHITE,FGCOLOR); uint8_t addressValue = strtoul(address.substring(0,2).c_str(), nullptr, 16); @@ -564,11 +564,11 @@ void sendRC5Command(String address, String command) { uint16_t data = irsend.encodeRC5(addressValue, commandValue); irsend.sendRC5(data, 13, 10); Serial.println("Sent RC5 command"); - digitalWrite(IrTx, LED_OFF); + digitalWrite(bruceConfig.irTx, LED_OFF); } void sendRC6Command(String address, String command) { - IRsend irsend(IrTx,true); // Set the GPIO to be used to sending the message. + IRsend irsend(bruceConfig.irTx,true); // Set the GPIO to be used to sending the message. irsend.begin(); displayRedStripe("Sending..",TFT_WHITE,FGCOLOR); uint32_t addressValue = strtoul(address.c_str(), nullptr, 16); @@ -576,26 +576,26 @@ void sendRC6Command(String address, String command) { uint64_t data = irsend.encodeRC6(addressValue, commandValue); irsend.sendRC6(data,20, 10); Serial.println("Sent RC5 command"); - digitalWrite(IrTx, LED_OFF); + digitalWrite(bruceConfig.irTx, LED_OFF); } void sendSamsungCommand(String address, String command) { - IRsend irsend(IrTx); // Set the GPIO to be used to sending the message. + IRsend irsend(bruceConfig.irTx); // Set the GPIO to be used to sending the message. irsend.begin(); displayRedStripe("Sending..",TFT_WHITE,FGCOLOR); //uint64_t data = ((uint64_t)strtoul(address.c_str(), nullptr, 16) << 32) | strtoul(command.c_str(), nullptr, 16); uint32_t addressValue = strtoul(address.c_str(), nullptr, 16); - uint32_t commandValue = strtoul(command.c_str(), nullptr, 16); + uint32_t commandValue = strtoul(command.c_str(), nullptr, 16); uint64_t data = irsend.encodeSAMSUNG(addressValue, commandValue); irsend.sendSAMSUNG(data, 32, 10); //delay(20); //irsend.sendSamsung36(data, 36, 10); Serial.println("Sent Samsung Command"); - digitalWrite(IrTx, LED_OFF); + digitalWrite(bruceConfig.irTx, LED_OFF); } void sendSonyCommand(String address, String command) { - IRsend irsend(IrTx); // Set the GPIO to be used to sending the message. + IRsend irsend(bruceConfig.irTx); // Set the GPIO to be used to sending the message. irsend.begin(); displayRedStripe("Sending..",TFT_WHITE,FGCOLOR); uint16_t commandValue = strtoul(command.substring(0,2).c_str(), nullptr, 16); @@ -607,11 +607,11 @@ void sendSonyCommand(String address, String command) { uint32_t data = irsend.encodeSony(nbits,commandValue,addressValue); irsend.sendSony(data,20,10); Serial.println("Sent Sony Command"); - digitalWrite(IrTx, LED_OFF); + digitalWrite(bruceConfig.irTx, LED_OFF); } void sendPanasonicCommand(String address, String command) { - IRsend irsend(IrTx); // Set the GPIO to be used to sending the message. + IRsend irsend(bruceConfig.irTx); // Set the GPIO to be used to sending the message. irsend.begin(); displayRedStripe("Sending..",TFT_WHITE,FGCOLOR); uint8_t first_zero_byte_pos = address.indexOf("00", 2); @@ -622,14 +622,14 @@ void sendPanasonicCommand(String address, String command) { // "D3 C4 00 00" -> "C4 D3 00 00" // "02 00 40 64" -> "64 40 00 02" uint16_t addressValue = strtoul(address.c_str(), nullptr, 16); - uint32_t commandValue = strtoul(command.c_str(), nullptr, 16); + uint32_t commandValue = strtoul(command.c_str(), nullptr, 16); Serial.println(addressValue); Serial.println(commandValue); irsend.sendPanasonic(addressValue, commandValue, 48, 10); // sendPanasonic(const uint16_t address, const uint32_t data, const uint16_t nbits = kPanasonicBits, const uint16_t repeat = kNoRepeat); delay(20); Serial.println("Sent Panasonic Command"); - digitalWrite(IrTx, LED_OFF); + digitalWrite(bruceConfig.irTx, LED_OFF); } bool sendDecodedCommand(String protocol, String value, String bits) { @@ -639,15 +639,15 @@ bool sendDecodedCommand(String protocol, String value, String bits) { if(type == decode_type_t::UNKNOWN) return false; uint16_t nbit_int = bits.toInt(); - IRsend irsend(IrTx); // Set the GPIO to be used to sending the message. + IRsend irsend(bruceConfig.irTx); // Set the GPIO to be used to sending the message. irsend.begin(); - bool success = false; + bool success = false; displayRedStripe("Sending..",TFT_WHITE,FGCOLOR); - + if(hasACState(type)) { // need to send the state (still passed from value) - uint8_t state[nbit_int / 8] = {0}; - uint16_t state_pos = 0; + uint8_t state[nbit_int / 8] = {0}; + uint16_t state_pos = 0; for (uint16_t i = 0; i < value.length(); i += 3) { // parse value -> state uint8_t highNibble = hexCharToDecimal(value[i]); @@ -657,23 +657,23 @@ bool sendDecodedCommand(String protocol, String value, String bits) { } //success = irsend.send(type, state, nbit_int / 8); success = irsend.send(type, state, state_pos); // safer - + } else { - + value.replace(" ", ""); - uint64_t value_int = strtoull(value.c_str(), nullptr, 16); - + uint64_t value_int = strtoull(value.c_str(), nullptr, 16); + success = irsend.send(type, value_int, nbit_int); // bool send(const decode_type_t type, const uint64_t data, const uint16_t nbits, const uint16_t repeat = kNoRepeat); } - + delay(20); Serial.println("Sent Decoded Command"); - digitalWrite(IrTx, LED_OFF); + digitalWrite(bruceConfig.irTx, LED_OFF); return success; } void sendRawCommand(uint16_t frequency, String rawData) { - IRsend irsend(IrTx); // Set the GPIO to be used to sending the message. + IRsend irsend(bruceConfig.irTx); // Set the GPIO to be used to sending the message. irsend.begin(); displayRedStripe("Sending..",TFT_WHITE,FGCOLOR); uint16_t dataBuffer[SAFE_STACK_BUFFER_SIZE/2]; // MEMO: stack overflow with full buffer size @@ -699,5 +699,5 @@ void sendRawCommand(uint16_t frequency, String rawData) { irsend.sendRaw(dataBuffer, count, frequency); Serial.println("Sent Raw command"); - digitalWrite(IrTx, LED_OFF); + digitalWrite(bruceConfig.irTx, LED_OFF); } diff --git a/src/modules/ir/ir_read.cpp b/src/modules/ir/ir_read.cpp index 3eae9d0f..155c3c28 100644 --- a/src/modules/ir/ir_read.cpp +++ b/src/modules/ir/ir_read.cpp @@ -53,15 +53,15 @@ IrRead::IrRead(bool headless_mode, bool raw_mode) { void IrRead::setup() { irrecv.enableIRIn(); - //Checks if IrRx pin is properly set + //Checks if irRx pin is properly set const std::vector> pins = IR_RX_PINS; int count=0; for (auto pin : pins) { - if(pin.second==IrRx) count++; + if(pin.second==bruceConfig.irRx) count++; } - if(count==0) gsetIrRxPin(true); // Open dialog to choose IrRx pin - - pinMode(IrRx, INPUT); + if(count==0) gsetIrRxPin(true); // Open dialog to choose irRx pin + + pinMode(bruceConfig.irRx, INPUT); if(headless) return; // else begin(); @@ -128,7 +128,7 @@ void IrRead::read_signal() { if (_read_signal || !irrecv.decode(&results)) return; _read_signal = true; - + // switch to raw mode if decoding failed if(results.decode_type == decode_type_t::UNKNOWN ) { displayWarning("signal decoding failed, switching to RAW mode", true); @@ -138,11 +138,11 @@ void IrRead::read_signal() { } display_banner(); - + // dump signal details padprint("HEX: 0x"); tft.println(results.value, HEX); - + display_btn_options(); delay(500); @@ -181,17 +181,17 @@ String IrRead::parse_state_signal() { return r; } -String IrRead::parse_raw_signal() { +String IrRead::parse_raw_signal() { // https://github.com/crankyoldgit/IRremoteESP8266/blob/master/examples/SmartIRRepeater/SmartIRRepeater.ino rawcode = resultToRawArray(&results); raw_data_len = getCorrectedRawLength(&results); - + String signal_code = ""; for (uint16_t i = 0; i < raw_data_len; i++) { signal_code += String(rawcode[i]) + " "; } - + delete[] rawcode; rawcode = nullptr; signal_code.trim(); @@ -202,7 +202,7 @@ String IrRead::parse_raw_signal() { void IrRead::append_to_file_str(String btn_name) { strDeviceContent += "name: " + btn_name + "\n"; - + if(raw) { strDeviceContent += "type: raw\n"; strDeviceContent += "frequency: " + String(IR_FREQUENCY) + "\n"; @@ -257,7 +257,7 @@ void IrRead::append_to_file_str(String btn_name) { case decode_type_t::UNKNOWN: { Serial.print("unknown protocol, try raw mode"); - return; + return; } default: { @@ -268,13 +268,13 @@ void IrRead::append_to_file_str(String btn_name) { strDeviceContent += "address: " + uint32ToString(results.address) + "\n"; strDeviceContent += "command: " + uint32ToString(results.command) + "\n"; - + // extra fields not supported on flipper strDeviceContent += "bits: " + String(results.bits) + "\n"; - if(hasACState(results.decode_type)) + if(hasACState(results.decode_type)) strDeviceContent += "state: " + parse_state_signal() + "\n"; else if(results.bits>32) - strDeviceContent += "value: " + uint32ToString(results.value) + " " + uint32ToString(results.value>> 32) + "\n"; // MEMO: from uint64_t + strDeviceContent += "value: " + uint32ToString(results.value) + " " + uint32ToString(results.value>> 32) + "\n"; // MEMO: from uint64_t else strDeviceContent += "value: " + uint32ToStringInverted(results.value) + "\n"; @@ -289,11 +289,11 @@ void IrRead::append_to_file_str(String btn_name) { serialPrintUint64(results.command, HEX); Serial.print("resultToHexidecimal: "); Serial.println(resultToHexidecimal(&results)); - Serial.println(results.value); + Serial.println(results.value); String value = uint32ToString(results.value ) + " " + uint32ToString(results.value>> 32); value.replace(" ", ""); - uint64_t value_int = strtoull(value.c_str(), nullptr, 16); - Serial.println(value_int); + uint64_t value_int = strtoull(value.c_str(), nullptr, 16); + Serial.println(value_int); */ } strDeviceContent += "#\n"; @@ -305,7 +305,7 @@ void IrRead::save_device() { String filename = keyboard("MyDevice", 30, "File name:"); display_banner(); - + FS* fs = nullptr; bool sdCardAvaible = setupSdCard(); @@ -340,8 +340,8 @@ void IrRead::save_device() { } -String IrRead::loop_headless(int max_loops) { - +String IrRead::loop_headless(int max_loops) { + while (!irrecv.decode(&results)) { // MEMO: default timeout is 15ms max_loops -= 1; if(max_loops <= 0) { @@ -351,15 +351,15 @@ String IrRead::loop_headless(int max_loops) { delay(1000); //delay(50); } - + irrecv.disableIRIn(); - + if(!raw && results.decode_type == decode_type_t::UNKNOWN ) { Serial.println("# decoding failed, try raw mode"); return ""; } - + if(results.overflow) displayWarning("buffer overflow, data may be truncated", true); // TODO: check results.repeat @@ -367,11 +367,11 @@ String IrRead::loop_headless(int max_loops) { r += "Version: 1\n"; r += "#\n"; r += "#\n"; - + strDeviceContent = ""; append_to_file_str("Unknown"); // writes on strDeviceContent r += strDeviceContent; - + return r; } diff --git a/src/modules/ir/ir_read.h b/src/modules/ir/ir_read.h index 3f637f95..00180f86 100644 --- a/src/modules/ir/ir_read.h +++ b/src/modules/ir/ir_read.h @@ -12,8 +12,8 @@ class IrRead { public: - //IRrecv irrecv = IRrecv(IrRx); - IRrecv irrecv = IRrecv(IrRx, SAFE_STACK_BUFFER_SIZE/2, 50); + //IRrecv irrecv = IRrecv(bruceConfig.irRx); + IRrecv irrecv = IRrecv(bruceConfig.irRx, SAFE_STACK_BUFFER_SIZE/2, 50); ///////////////////////////////////////////////////////////////////////////////////// @@ -26,7 +26,7 @@ class IrRead { /////////////////////////////////////////////////////////////////////////////////// void setup(); void loop(); - + String loop_headless(int max_loops); private: diff --git a/src/modules/others/audio.cpp b/src/modules/others/audio.cpp index 42a96f1a..25a6a5c8 100644 --- a/src/modules/others/audio.cpp +++ b/src/modules/others/audio.cpp @@ -11,7 +11,7 @@ #if defined(HAS_NS4168_SPKR) bool playAudioFile(FS* fs, String filepath) { - if (!soundEnabled) return false; + if (!bruceConfig.soundEnabled) return false; AudioFileSource* source = new AudioFileSourceFS(*fs, filepath.c_str()); if(!source) return false; @@ -68,7 +68,7 @@ bool playAudioFile(FS* fs, String filepath) { } bool playAudioRTTTLString(String song) { - if (!soundEnabled) return false; + if (!bruceConfig.soundEnabled) return false; // derived from https://github.com/earlephilhower/ESP8266Audio/blob/master/examples/PlayRTTTLToI2SDAC/PlayRTTTLToI2SDAC.ino @@ -103,7 +103,7 @@ bool playAudioRTTTLString(String song) { } bool tts(String text){ - if (!soundEnabled) return false; + if (!bruceConfig.soundEnabled) return false; text.trim(); if(text=="") return false; @@ -129,7 +129,7 @@ bool isAudioFile(String filepath) { void playTone(unsigned int frequency, unsigned long duration, short waveType) { - if (!soundEnabled) return; + if (!bruceConfig.soundEnabled) return; // derived from https://github.com/earlephilhower/ESP8266Audio/blob/master/examples/PlayWAVFromFunction/PlayWAVFromFunction.ino @@ -191,7 +191,7 @@ void playTone(unsigned int frequency, unsigned long duration, short waveType) void _tone(unsigned int frequency, unsigned long duration) { - if (!soundEnabled) return; + if (!bruceConfig.soundEnabled) return; #if defined(BUZZ_PIN) tone(BUZZ_PIN, frequency, duration); diff --git a/src/modules/others/webInterface.cpp b/src/modules/others/webInterface.cpp index 460e24cc..7395a2af 100644 --- a/src/modules/others/webInterface.cpp +++ b/src/modules/others/webInterface.cpp @@ -178,7 +178,7 @@ String processor(const String& var) { **********************************************************************/ bool checkUserWebAuth() { bool isAuthenticated = false; - if (server->authenticate(wui_usr.c_str(), wui_pwd.c_str())) { + if (server->authenticate(bruceConfig.wuiUsr.c_str(), bruceConfig.wuiPwd.c_str())) { isAuthenticated = true; } return isAuthenticated; @@ -254,9 +254,9 @@ void drawWebUiScreen(bool mode_ap) { tft.setTextSize(FM); tft.print("IP: "); tft.println(txt); tft.setCursor(7,tft.getCursorY()); - tft.println("Usr: " + String(wui_usr)); + tft.println("Usr: " + String(bruceConfig.wuiUsr)); tft.setCursor(7,tft.getCursorY()); - tft.println("Pwd: " + String(wui_pwd)); + tft.println("Pwd: " + String(bruceConfig.wuiPwd)); tft.setCursor(7,tft.getCursorY()); tft.setTextColor(TFT_RED); tft.setTextSize(FP); @@ -478,8 +478,8 @@ server->on("/script.js", HTTP_GET, []() { if (server->hasArg("usr") && server->hasArg("pwd")) { const char *usr = server->arg("usr").c_str(); const char *pwd = server->arg("pwd").c_str(); - wui_usr= usr; - wui_pwd = pwd; + bruceConfig.wuiUsr = usr; + bruceConfig.wuiPwd = pwd; saveConfigs(); server->send(200, "text/plain", "User: " + String(usr) + " configured with password: " + String(pwd)); } diff --git a/src/modules/rf/rf.cpp b/src/modules/rf/rf.cpp index 5600fd09..64dfac2b 100644 --- a/src/modules/rf/rf.cpp +++ b/src/modules/rf/rf.cpp @@ -55,9 +55,9 @@ void initRMT() { rmt_config_t rxconfig; rxconfig.rmt_mode = RMT_MODE_RX; rxconfig.channel = RMT_RX_CHANNEL; - rxconfig.gpio_num = gpio_num_t(RfRx); + rxconfig.gpio_num = gpio_num_t(bruceConfig.rfRx); #ifdef USE_CC1101_VIA_SPI - if(RfModule==1) + if(bruceConfig.rfModule==CC1101_SPI_MODULE) rxconfig.gpio_num = gpio_num_t(CC1101_GDO0_PIN); #endif rxconfig.clk_div = RMT_CLK_DIV; // RMT_DEFAULT_CLK_DIV=32 @@ -81,7 +81,7 @@ void rf_spectrum() { //@IncursioHack - https://github.com/IncursioHack ----thank tft.setTextSize(1); tft.println(""); tft.println(" RF - Spectrum"); - if(!initRfModule("rx", RfFreq)) return; + if(!initRfModule("rx", bruceConfig.rfFreq)) return; initRMT(); RingbufHandle_t rb = nullptr; @@ -119,16 +119,16 @@ void rf_spectrum() { //@IncursioHack - https://github.com/IncursioHack ----thank void rf_jammerFull() { //@IncursioHack - https://github.com/IncursioHack - thanks @EversonPereira - rfcardputer // init rf module - int nTransmitterPin = RfTx; + int nTransmitterPin = bruceConfig.rfTx; if(!initRfModule("tx")) return; - if(RfModule == 1) { // CC1101 in use + if(bruceConfig.rfModule == CC1101_SPI_MODULE) { // CC1101 in use #ifdef USE_CC1101_VIA_SPI nTransmitterPin = CC1101_GDO0_PIN; #else return; #endif } - + tft.fillScreen(TFT_BLACK); drawMainBorder(); tft.setCursor(10,30); @@ -153,9 +153,9 @@ void rf_jammerFull() { //@IncursioHack - https://github.com/IncursioHack - than void rf_jammerIntermittent() { //@IncursioHack - https://github.com/IncursioHack - thanks @EversonPereira - rfcardputer - int nTransmitterPin = RfTx; + int nTransmitterPin = bruceConfig.rfTx; if(!initRfModule("tx")) return; - if(RfModule == 1) { // CC1101 in use + if(bruceConfig.rfModule == CC1101_SPI_MODULE) { // CC1101 in use #ifdef USE_CC1101_VIA_SPI nTransmitterPin = CC1101_GDO0_PIN; #else @@ -202,34 +202,34 @@ void rf_jammerIntermittent() { //@IncursioHack - https://github.com/IncursioHack String rf_scan(float start_freq, float stop_freq, int max_loops) { // derived from https://github.com/mcore1976/cc1101-tool/blob/main/cc1101-tool-esp32.ino#L480 - - if(RfModule != 1) { + + if(bruceConfig.rfModule != CC1101_SPI_MODULE) { displayError("rf scanning is available with CC1101 only", true); return ""; // only CC1101 is supported for this } if(!initRfModule("rx", start_freq)) return ""; ELECHOUSE_cc1101.setRxBW(58); - + float settingf1 = start_freq; float settingf2 = stop_freq; float freq; long compare_freq; float mark_freq; int rssi; - int mark_rssi=-100; + int mark_rssi=-100; String out=""; - + while(max_loops || !checkEscPress()) { delay(1); max_loops -= 1; - + ELECHOUSE_cc1101.setMHZ(freq); rssi = ELECHOUSE_cc1101.getRssi(); if (rssi>-75) { if (rssi > mark_rssi) { - mark_rssi = rssi; + mark_rssi = rssi; mark_freq = freq; }; }; @@ -263,20 +263,20 @@ String rf_scan(float start_freq, float stop_freq, int max_loops) mark_rssi=-100; }; }; - }; // end of IF freq>stop frequency - }; // End of While - + }; // end of IF freq>stop frequency + }; // End of While + deinitRfModule(); return out; } - + void RCSwitch_send(uint64_t data, unsigned int bits, int pulse, int protocol, int repeat) { // derived from https://github.com/LSatan/SmartRC-CC1101-Driver-Lib/blob/master/examples/Rc-Switch%20examples%20cc1101/SendDemo_cc1101/SendDemo_cc1101.ino - + RCSwitch mySwitch = RCSwitch(); - - if(RfModule==1) { + + if(bruceConfig.rfModule==CC1101_SPI_MODULE) { #ifdef USE_CC1101_VIA_SPI mySwitch.enableTransmit(CC1101_GDO0_PIN); #else @@ -284,9 +284,9 @@ void RCSwitch_send(uint64_t data, unsigned int bits, int pulse, int protocol, in return; // not enabled for this board #endif } else { - mySwitch.enableTransmit(RfTx); + mySwitch.enableTransmit(bruceConfig.rfTx); } - + mySwitch.setProtocol(protocol); // override if (pulse) { mySwitch.setPulseLength(pulse); } mySwitch.setRepeatTransmit(repeat); @@ -301,7 +301,7 @@ void RCSwitch_send(uint64_t data, unsigned int bits, int pulse, int protocol, in */ mySwitch.disableTransmit(); - + deinitRfModule(); } @@ -425,7 +425,7 @@ static char * dec2binWzerofill(unsigned long Dec, unsigned int bitLength) { void initCC1101once(SPIClass* SSPI) { // the init (); command may only be executed once in the entire program sequence. Otherwise problems can arise. https://github.com/LSatan/SmartRC-CC1101-Driver-Lib/issues/65 - + #ifdef USE_CC1101_VIA_SPI // derived from https://github.com/LSatan/SmartRC-CC1101-Driver-Lib/blob/master/examples/Rc-Switch%20examples%20cc1101/ReceiveDemo_Advanced_cc1101/ReceiveDemo_Advanced_cc1101.ino ELECHOUSE_cc1101.setSpiPin(CC1101_SCK_PIN, CC1101_MISO_PIN, CC1101_MOSI_PIN, CC1101_SS_PIN, SSPI); @@ -443,7 +443,7 @@ void initCC1101once(SPIClass* SSPI) { return; } ELECHOUSE_cc1101.Init(); - */ + */ #else Serial.println("Error: USE_CC1101_VIA_SPI not defined for this board"); @@ -453,14 +453,14 @@ void initCC1101once(SPIClass* SSPI) { } void deinitRfModule() { - if(RfModule==1) + if(bruceConfig.rfModule==CC1101_SPI_MODULE) #ifdef USE_CC1101_VIA_SPI ELECHOUSE_cc1101.setSidle(); #else return; #endif else - digitalWrite(RfTx, LED_OFF); + digitalWrite(bruceConfig.rfTx, LED_OFF); } @@ -469,15 +469,15 @@ bool initRfModule(String mode, float frequency) { initCC1101once(&CC_NRF_SPI); #elif defined(CARDPUTER) || defined(ESP32S3DEVKITC1) initCC1101once(&sdcardSPI); - #else + #else initCC1101once(&SPI); #endif - + // use default frequency if no one is passed - if(!frequency) frequency = RfFreq; - - if(RfModule == 1) { // CC1101 in use - #ifdef USE_CC1101_VIA_SPI + if(!frequency) frequency = bruceConfig.rfFreq; + + if(bruceConfig.rfModule == CC1101_SPI_MODULE) { // CC1101 in use + #ifdef USE_CC1101_VIA_SPI ELECHOUSE_cc1101.Init(); if (ELECHOUSE_cc1101.getCC1101()){ // Check the CC1101 Spi connection. Serial.println("cc1101 Connection OK"); @@ -485,19 +485,19 @@ bool initRfModule(String mode, float frequency) { Serial.println("cc1101 Connection Error"); //return false; } - + // make sure it is in idle state when changing frequency and other parameters // "If any frequency programming register is altered when the frequency synthesizer is running, the synthesizer may give an undesired response. Hence, the frequency programming should only be updated when the radio is in the IDLE state." https://github.com/LSatan/SmartRC-CC1101-Driver-Lib/issues/65 ELECHOUSE_cc1101.setSidle(); Serial.println("cc1101 setSidle();"); - + if(!(frequency>=300 && frequency<=928)) // TODO: check all supported subranges: 300-348 MHZ, 387-464MHZ and 779-928MHZ. return false; - // else + // else ELECHOUSE_cc1101.setMHZ(frequency); Serial.println("cc1101 setMHZ(frequency);"); ELECHOUSE_cc1101.setRxBW(812.50); // reset to default - + /* MEMO: cannot change other params after this is executed */ if(mode=="tx") { pinMode(CC1101_GDO0_PIN, OUTPUT); @@ -517,25 +517,25 @@ bool initRfModule(String mode, float frequency) { // TODO: PCA9554-based implmentation return false; #endif - + } else { // single-pinned module - if(frequency!=RfFreq) { + if(frequency!=bruceConfig.rfFreq) { Serial.println("unsupported frequency"); return false; } - + if(mode=="tx") { gsetRfTxPin(false); - //if(RfTx==0) RfTx=GROVE_SDA; // quick fix - pinMode(RfTx, OUTPUT); - digitalWrite(RfTx, LED_OFF); + //if(bruceConfig.rfTx==0) bruceConfig.rfTx=GROVE_SDA; // quick fix + pinMode(bruceConfig.rfTx, OUTPUT); + digitalWrite(bruceConfig.rfTx, LED_OFF); } else if(mode=="rx") { // Rx Mode gsetRfRxPin(false); - //if(RfRx==0) RfRx=GROVE_SCL; // quick fix - pinMode(RfRx, INPUT); + //if(bruceConfig.rfRx==0) bruceConfig.rfRx=GROVE_SCL; // quick fix + pinMode(bruceConfig.rfRx, INPUT); } } // no error @@ -546,10 +546,10 @@ String RCSwitch_Read(float frequency, int max_loops, bool raw) { RCSwitch rcswitch = RCSwitch(); RfCodes received; - if(!frequency) frequency = RfFreq; // default from settings + if(!frequency) frequency = bruceConfig.rfFreq; // default from settings char hexString[64]; - + RestartRec: drawMainBorder(); tft.setCursor(10, 28); @@ -558,8 +558,8 @@ String RCSwitch_Read(float frequency, int max_loops, bool raw) { // init receive if(!initRfModule("rx", frequency)) return ""; - if(RfModule == 1) { // CC1101 in use - #ifdef USE_CC1101_VIA_SPI + if(bruceConfig.rfModule == CC1101_SPI_MODULE) { // CC1101 in use + #ifdef USE_CC1101_VIA_SPI #ifdef CC1101_GDO2_PIN rcswitch.enableReceive(CC1101_GDO2_PIN); #else @@ -570,7 +570,7 @@ String RCSwitch_Read(float frequency, int max_loops, bool raw) { return ""; #endif } else { - rcswitch.enableReceive(RfRx); + rcswitch.enableReceive(bruceConfig.rfRx); } while(!checkEscPress()) { if(rcswitch.available()) { @@ -600,10 +600,10 @@ String RCSwitch_Read(float frequency, int max_loops, bool raw) { } //Serial.println(received.protocol); //Serial.println(received.data); - + const char* b = dec2binWzerofill(received.key, received.Bit); - decimalToHexString(received.key,hexString); // need to remove the extra padding 0s? - + decimalToHexString(received.key,hexString); // need to remove the extra padding 0s? + drawMainBorder(); tft.setCursor(10, 28); tft.setTextSize(FP); @@ -651,7 +651,7 @@ String RCSwitch_Read(float frequency, int max_loops, bool raw) { // headless mode return subfile_out; #endif - + if(checkSelPress()) { int chosen=0; options = { @@ -691,9 +691,9 @@ String RCSwitch_Read(float frequency, int max_loops, bool raw) { } Exit: delay(1); - + deinitRfModule(); - + return ""; } @@ -737,7 +737,7 @@ bool RCSwitch_SaveSignal(float frequency, RfCodes codes, bool raw, char* key) while (SD.exists("/BruceRF/bruce_" + String(i) + ".sub")) { i++; } - + file = SD.open("/BruceRF/bruce_"+ String(i) +".sub", FILE_WRITE); FS="SD"; } else if (LittleFS.begin()) { @@ -747,15 +747,15 @@ bool RCSwitch_SaveSignal(float frequency, RfCodes codes, bool raw, char* key) if (!LittleFS.exists("/BruceRF")) { LittleFS.mkdir("/BruceRF"); } - + while(LittleFS.exists("/BruceRF/bruce_" + String(i) + ".sub")) { i++; } - + file = LittleFS.open("/BruceRF/bruce_" + String(i) +".sub", FILE_WRITE); FS = "LittleFS"; } - + if (file) { file.println(subfile_out); displaySuccess(FS + "/bruce_" + String(i) + ".sub"); @@ -770,15 +770,15 @@ bool RCSwitch_SaveSignal(float frequency, RfCodes codes, bool raw, char* key) // ported from https://github.com/sui77/rc-switch/blob/3a536a172ab752f3c7a58d831c5075ca24fd920b/RCSwitch.cpp void RCSwitch_RAW_Bit_send(RfCodes data) { - int nTransmitterPin = RfTx; - if(RfModule==1) { + int nTransmitterPin = bruceConfig.rfTx; + if(bruceConfig.rfModule==CC1101_SPI_MODULE) { #ifdef USE_CC1101_VIA_SPI nTransmitterPin = CC1101_GDO0_PIN; #else return; #endif } - + if (data.data == "") return; bool currentlogiclevel = false; @@ -813,15 +813,15 @@ void RCSwitch_RAW_Bit_send(RfCodes data) { void RCSwitch_RAW_send(int * ptrtransmittimings) { - int nTransmitterPin = RfTx; - if(RfModule==1) { + int nTransmitterPin = bruceConfig.rfTx; + if(bruceConfig.rfModule==CC1101_SPI_MODULE) { #ifdef USE_CC1101_VIA_SPI nTransmitterPin = CC1101_GDO0_PIN; #else return; #endif } - + if (!ptrtransmittimings) return; @@ -925,16 +925,16 @@ void sendRfCommand(struct RfCodes rfcode) { Serial.println(preset); return; } - + // init transmitter if(!initRfModule("", frequency/1000000.0)) return; - if(RfModule == 1) { // CC1101 in use + if(bruceConfig.rfModule == CC1101_SPI_MODULE) { // CC1101 in use #ifdef USE_CC1101_VIA_SPI // derived from https://github.com/LSatan/SmartRC-CC1101-Driver-Lib/blob/master/examples/Rc-Switch%20examples%20cc1101/SendDemo_cc1101/SendDemo_cc1101.ino ELECHOUSE_cc1101.setModulation(modulation); if(deviation) ELECHOUSE_cc1101.setDeviation(deviation); if(rxBW) ELECHOUSE_cc1101.setRxBW(rxBW); // Set the Receive Bandwidth in kHz. Value from 58.03 to 812.50. Default is 812.50 kHz. - if(dataRate) ELECHOUSE_cc1101.setDRate(dataRate); + if(dataRate) ELECHOUSE_cc1101.setDRate(dataRate); pinMode(CC1101_GDO0_PIN, OUTPUT); ELECHOUSE_cc1101.setPA(12); // set TxPower. The following settings are possible depending on the frequency band. (-30 -20 -15 -10 -6 0 5 7 10 11 12) Default is max! ELECHOUSE_cc1101.SetTx(); @@ -951,7 +951,7 @@ void sendRfCommand(struct RfCodes rfcode) { } initRfModule("tx", frequency/1000000.0); } - + if(protocol == "RAW") { // count the number of elements of RAW_Data int buff_size=0; @@ -1013,7 +1013,7 @@ void sendRfCommand(struct RfCodes rfcode) { return; } - //digitalWrite(RfTx, LED_OFF); + //digitalWrite(bruceConfig.rfTx, LED_OFF); deinitRfModule(); } @@ -1048,9 +1048,9 @@ void otherRFcodes() { FS *fs = NULL; String filepath = ""; struct RfCodes selected_code; - + returnToMenu=true; // make sure menu is redrawn when quitting in any point - + options = { {"Recent", [&]() { selected_code = selectRecentRfMenu(); }}, {"LittleFS", [&]() { fs=&LittleFS; }}, @@ -1060,13 +1060,13 @@ void otherRFcodes() { delay(200); loopOptions(options); delay(200); - + if(fs == NULL) { // recent menu was selected if(selected_code.filepath!="") sendRfCommand(selected_code); // a code was selected return; // no need to proceed, go back } - + while (1) { delay(200); filepath = loopSD(*fs, true, "SUB"); @@ -1076,14 +1076,14 @@ void otherRFcodes() { delay(200); } } - - + + bool txSubFile(FS *fs, String filepath) { struct RfCodes selected_code; File databaseFile; - + if(!fs) return false; - + databaseFile = fs->open(filepath, FILE_READ); drawMainBorder(); @@ -1117,7 +1117,7 @@ bool txSubFile(FS *fs, String filepath) { addToRecentCodes(selected_code); sendRfCommand(selected_code); - //digitalWrite(RfTx, LED_OFF); + //digitalWrite(bruceConfig.rfTx, LED_OFF); deinitRfModule(); return true; } @@ -1154,11 +1154,11 @@ void rf_scan_copy() { if (!initRfModule("rx")) { return; } - + RfCodes received; RCSwitch rcswitch = RCSwitch(); - - if (RfModule == 1) { + + if (bruceConfig.rfModule == CC1101_SPI_MODULE) { #ifdef USE_CC1101_VIA_SPI #ifdef CC1101_GDO2_PIN rcswitch.enableReceive(CC1101_GDO2_PIN); @@ -1170,26 +1170,26 @@ void rf_scan_copy() { return; #endif } else { - rcswitch.enableReceive(RfRx); + rcswitch.enableReceive(bruceConfig.rfRx); } - - if (RfScanRange < 0 || RfScanRange > 3) { - RfScanRange = 3; + + if (bruceConfig.rfScanRange < 0 || bruceConfig.rfScanRange > 3) { + bruceConfig.rfScanRange = 3; } - - if (RfModule != 1) { - RfFxdFreq = 1; + + if (bruceConfig.rfModule != CC1101_SPI_MODULE) { + bruceConfig.rfFxdFreq = 1; } - + const char* sz_range[] = {"300-348 MHz", "387-464 MHz", "779-928 MHz", "All ranges" }; - + int range_limits[][2] = { { 0, 23 }, // 300-348 MHz { 24, 47 }, // 387-464 MHz { 48, 56 }, // 779-928 MHz { 0, sizeof(subghz_frequency_list) / sizeof(subghz_frequency_list[0]) - 1} // All ranges }; - + uint8_t _try = 0; RestartScan: drawMainBorder(); @@ -1197,61 +1197,61 @@ void rf_scan_copy() { tft.setTextSize(FP); tft.println("Waiting for signal."); tft.setCursor(10, tft.getCursorY()); - if (RfFxdFreq) { + if (bruceConfig.rfFxdFreq) { if (_try >= _MAX_TRIES) { tft.setTextColor(getColorVariation(FGCOLOR), BGCOLOR); } - - tft.println("Freq: " + String(RfFreq) + " MHz"); - + + tft.println("Freq: " + String(bruceConfig.rfFreq) + " MHz"); + if (_try >= _MAX_TRIES) { tft.setTextColor(FGCOLOR, BGCOLOR); } } else { - tft.println("Range: " + String(sz_range[RfScanRange])); + tft.println("Range: " + String(sz_range[bruceConfig.rfScanRange])); } - + tft.setCursor(10, tft.getCursorY()+LH*2); tft.println("Press [NEXT] for range."); - + char hexString[64]; - int signals = 0, idx = range_limits[RfScanRange][0]; - + int signals = 0, idx = range_limits[bruceConfig.rfScanRange][0]; + float found_freq = 0.f, frequency = 0.f; - - if (RfFxdFreq) { - frequency = RfFreq; + + if (bruceConfig.rfFxdFreq) { + frequency = bruceConfig.rfFreq; #if defined(USE_CC1101_VIA_SPI) - if(RfModule) ELECHOUSE_cc1101.setMHZ(frequency); + if(bruceConfig.rfModule == CC1101_SPI_MODULE) ELECHOUSE_cc1101.setMHZ(frequency); #endif delay(50); } - + int rssi, rssiThreshold = -60; FreqFound _freqs[_MAX_TRIES]; // get the best RSSI out of 3 tries - + for (;;) { FastScan: - if (idx < range_limits[RfScanRange][0] || idx > range_limits[RfScanRange][1]) { - idx = range_limits[RfScanRange][0]; + if (idx < range_limits[bruceConfig.rfScanRange][0] || idx > range_limits[bruceConfig.rfScanRange][1]) { + idx = range_limits[bruceConfig.rfScanRange][0]; } - + if (checkEscPress()) { break; } - - if (!RfFxdFreq) { // Try FastScan + + if (!bruceConfig.rfFxdFreq) { // Try FastScan #if defined(USE_CC1101_VIA_SPI) frequency = subghz_frequency_list[idx]; - + ELECHOUSE_cc1101.setMHZ(frequency); delay(5); rssi = ELECHOUSE_cc1101.getRssi(); if (checkSelPress()) { Serial.println("Frequency: " + String(frequency) + " - rssi: " + String(rssi)); } - + if (rssi > rssiThreshold) { _freqs[_try].freq = frequency; _freqs[_try].rssi = rssi; @@ -1263,10 +1263,10 @@ void rf_scan_copy() { max_index = i; } } - - RfFreq = _freqs[max_index].freq; + + bruceConfig.rfFreq = _freqs[max_index].freq; frequency = _freqs[max_index].freq; - RfFxdFreq = true; + bruceConfig.rfFxdFreq = true; Serial.println("Frequency Found: " + String(frequency)); goto RestartScan; } @@ -1279,26 +1279,26 @@ void rf_scan_copy() { if (checkNextPress()) { goto Menu; } - + goto FastScan; } #else displayWarning("Freq Scan not available", true); - RfFxdFreq=1; - RfFreq=433.92; + bruceConfig.rfFxdFreq=1; + bruceConfig.rfFreq=433.92; saveConfigs(); #endif } - - //frequency = RfFxdFreq ? RfFreq : subghz_frequency_list[idx]; - + + //frequency = bruceConfig.rfFxdFreq ? bruceConfig.rfFreq : subghz_frequency_list[idx]; + if (rcswitch.available()) { unsigned long value = rcswitch.getReceivedValue(); if (value) { found_freq = frequency; - + ++signals; - + unsigned int* raw = rcswitch.getReceivedRawdata(); received.frequency = long(frequency*1000000); received.key = value; @@ -1312,13 +1312,13 @@ void rf_scan_copy() { //if(received.preset.invertedSignal) sign = -1; for (int i = 0; i < received.Bit * 2; i++) { if (i > 0) received.data += " "; - + if (i % 2 == 0) sign = +1; else sign = -1; - + received.data += String(sign * (int)raw[i]); } - + const char* b = dec2binWzerofill(received.key, received.Bit); decimalToHexString(received.key,hexString); drawMainBorder(); @@ -1326,7 +1326,7 @@ void rf_scan_copy() { tft.setTextSize(FP); tft.println("Key: " + String(hexString)); tft.setCursor(10, tft.getCursorY()); - if (RfModule == 1) { + if (bruceConfig.rfModule == CC1101_SPI_MODULE) { tft.println("Rssi: " + String(ELECHOUSE_cc1101.getRssi())); tft.setCursor(10, tft.getCursorY()); } @@ -1344,21 +1344,21 @@ void rf_scan_copy() { tft.setCursor(10, tft.getCursorY()+LH*2); tft.println("Press [NEXT] for options."); } - + rcswitch.resetAvailable(); } - + if (checkNextPress()) { Menu: int option = 0; - - if (RfModule == 1) { + + if (bruceConfig.rfModule == CC1101_SPI_MODULE) { if (found_freq) { options = { { "Range", [&]() { option = 1; } }, { "Signal", [&]() { option = 2; } }, }; - + delay(200); loopOptions(options); } @@ -1369,28 +1369,28 @@ void rf_scan_copy() { else if (found_freq) { option = 2; } - + if (option == 1) { options = { - { String("Fxd [" + String(RfFreq) + "]").c_str(), [&]() { RfFxdFreq = 1; } }, - { sz_range[0], [&]() { RfScanRange = 0; RfFxdFreq = 0; } }, - { sz_range[1], [&]() { RfScanRange = 1; RfFxdFreq = 0; } }, - { sz_range[2], [&]() { RfScanRange = 2; RfFxdFreq = 0; } }, - { sz_range[3], [&]() { RfScanRange = 3; RfFxdFreq = 0; } }, + { String("Fxd [" + String(bruceConfig.rfFreq) + "]").c_str(), [&]() { bruceConfig.rfFxdFreq = 1; } }, + { sz_range[0], [&]() { bruceConfig.rfScanRange = 0; bruceConfig.rfFxdFreq = 0; } }, + { sz_range[1], [&]() { bruceConfig.rfScanRange = 1; bruceConfig.rfFxdFreq = 0; } }, + { sz_range[2], [&]() { bruceConfig.rfScanRange = 2; bruceConfig.rfFxdFreq = 0; } }, + { sz_range[3], [&]() { bruceConfig.rfScanRange = 3; bruceConfig.rfFxdFreq = 0; } }, }; - + delay(200); loopOptions(options); - - if (RfFxdFreq) { - displayRedStripe("Scan freq set to " + String(RfFreq), TFT_WHITE, FGCOLOR); + + if (bruceConfig.rfFxdFreq) { + displayRedStripe("Scan freq set to " + String(bruceConfig.rfFreq), TFT_WHITE, FGCOLOR); } else { - displayRedStripe("Range set to " + String(sz_range[RfScanRange]), TFT_WHITE, FGCOLOR); + displayRedStripe("Range set to " + String(sz_range[bruceConfig.rfScanRange]), TFT_WHITE, FGCOLOR); } - + saveConfigs(); - + delay(1500); goto RestartScan; } @@ -1401,24 +1401,24 @@ void rf_scan_copy() { { "Replay signal", [&]() { option = 2; } }, { "Save signal", [&]() { option = 3; } }, }; - - if (RfFxdFreq) { + + if (bruceConfig.rfFxdFreq) { options.erase(options.begin()); } - + delay(200); loopOptions(options); - + if (option == 2) { rcswitch.disableReceive(); sendRfCommand(received); addToRecentCodes(received); - + if (!initRfModule("rx")) { return; } - - if (RfModule == 1) { + + if (bruceConfig.rfModule == CC1101_SPI_MODULE) { #ifdef USE_CC1101_VIA_SPI #ifdef CC1101_GDO2_PIN rcswitch.enableReceive(CC1101_GDO2_PIN); @@ -1431,9 +1431,9 @@ void rf_scan_copy() { #endif } else { - rcswitch.enableReceive(RfRx); + rcswitch.enableReceive(bruceConfig.rfRx); } - + delay(1500); goto RestartScan; } @@ -1441,16 +1441,16 @@ void rf_scan_copy() { RCSwitch_SaveSignal(found_freq, received, false, hexString); } else if (option == 1) { - RfFreq = found_freq; + bruceConfig.rfFreq = found_freq; saveConfigs(); displayRedStripe("Set to " + String(found_freq) + " MHz", TFT_WHITE, FGCOLOR); delay(1500); } } } - + ++idx; } - + deinitRfModule(); } diff --git a/src/modules/rfid/tag_o_matic.cpp b/src/modules/rfid/tag_o_matic.cpp index b7cd3f50..ad51fd05 100644 --- a/src/modules/rfid/tag_o_matic.cpp +++ b/src/modules/rfid/tag_o_matic.cpp @@ -40,7 +40,7 @@ TagOMatic::~TagOMatic() { } void TagOMatic::set_rfid_module() { - switch (RfidModule) { + switch (bruceConfig.rfidModule) { case PN532_I2C_MODULE: _rfid = new PN532(); break; diff --git a/src/modules/wifi/wigle.cpp b/src/modules/wifi/wigle.cpp index c6e51002..65b49c1f 100644 --- a/src/modules/wifi/wigle.cpp +++ b/src/modules/wifi/wigle.cpp @@ -20,13 +20,13 @@ Wigle::Wigle() {} Wigle::~Wigle() {} bool Wigle::_check_token() { - if (wigleBasicToken == "") { + if (bruceConfig.wigleBasicToken == "") { displayError("Wigle token not found"); delay(1000); return false; } - auth_header = "Basic " + wigleBasicToken; + auth_header = "Basic " + bruceConfig.wigleBasicToken; if(!wifiConnected) wifiConnectMenu(false); From 33155cc4ad6d23135995e1b13d49e6e529145f8f Mon Sep 17 00:00:00 2001 From: Rennan Cockles Date: Sun, 3 Nov 2024 22:10:10 -0300 Subject: [PATCH 04/13] change theme colors to use config class --- html/AsyncWebServer/evil_portal.cpp | 30 +++--- html/AsyncWebServer/webInterface.cpp | 24 ++--- html/WebServer/evil_portal.cpp | 18 ++-- html/WebServer/webInterface.cpp | 22 ++-- src/core/config.cpp | 1 + src/core/config.h | 22 +++- src/core/display.cpp | 144 +++++++++++++------------- src/core/display.h | 6 +- src/core/eeprom.cpp | 13 ++- src/core/globals.h | 15 --- src/core/main_menu.cpp | 4 +- src/core/menu_items/BleMenu.cpp | 22 ++-- src/core/menu_items/ClockMenu.cpp | 14 +-- src/core/menu_items/ConfigMenu.cpp | 6 +- src/core/menu_items/ConnectMenu.cpp | 16 +-- src/core/menu_items/FMMenu.cpp | 24 ++--- src/core/menu_items/IRMenu.cpp | 14 +-- src/core/menu_items/NRF24.cpp | 34 +++--- src/core/menu_items/OthersMenu.cpp | 12 +-- src/core/menu_items/RFIDMenu.cpp | 14 +-- src/core/menu_items/RFMenu.cpp | 18 ++-- src/core/menu_items/ScriptsMenu.cpp | 18 ++-- src/core/menu_items/WifiMenu.cpp | 8 +- src/core/mykeyboard.cpp | 56 +++++----- src/core/scrollableTextArea.cpp | 30 +++--- src/core/sd_functions.cpp | 32 +++--- src/core/serialcmds.cpp | 4 +- src/core/settings.cpp | 58 +++++------ src/core/wg.cpp | 22 ++-- src/core/wifi_common.cpp | 2 +- src/main.cpp | 32 +++--- src/modules/NRF24/nrf_common.cpp | 20 ++-- src/modules/NRF24/nrf_spectrum.cpp | 4 +- src/modules/ble/bad_ble.cpp | 38 +++---- src/modules/ble/ble_common.cpp | 6 +- src/modules/ble/ble_spam.cpp | 18 ++-- src/modules/fm/fm.cpp | 20 ++-- src/modules/ir/TV-B-Gone.cpp | 28 +++-- src/modules/ir/ir_read.cpp | 2 +- src/modules/others/bad_usb.cpp | 44 ++++---- src/modules/others/openhaystack.cpp | 22 ++-- src/modules/others/qrcode_menu.cpp | 2 +- src/modules/others/tururururu.cpp | 14 +-- src/modules/others/webInterface.cpp | 8 +- src/modules/pwnagotchi/pwnagotchi.cpp | 6 +- src/modules/pwnagotchi/spam.cpp | 22 ++-- src/modules/pwnagotchi/ui.cpp | 26 ++--- src/modules/rf/rf.cpp | 14 +-- src/modules/rfid/rfid125.cpp | 2 +- src/modules/wifi/ap_info.cpp | 14 +-- src/modules/wifi/clients.cpp | 54 +++++----- src/modules/wifi/dpwo.cpp | 14 +-- src/modules/wifi/evil_portal.cpp | 6 +- src/modules/wifi/scan_hosts.cpp | 10 +- src/modules/wifi/sniffer.cpp | 44 ++++---- src/modules/wifi/wardriving.cpp | 2 +- src/modules/wifi/wifi_atks.cpp | 20 ++-- 57 files changed, 596 insertions(+), 599 deletions(-) diff --git a/html/AsyncWebServer/evil_portal.cpp b/html/AsyncWebServer/evil_portal.cpp index 9f721dc0..06b003f0 100644 --- a/html/AsyncWebServer/evil_portal.cpp +++ b/html/AsyncWebServer/evil_portal.cpp @@ -55,10 +55,10 @@ class CaptiveRequestHandler : public AsyncWebHandler { saveToCSV("/Bruce_creds.csv", csvLine); capturedCredentialsHtml = html_temp + capturedCredentialsHtml; totalCapturedCredentials++; - request->send(200, "text/html", getHtmlContents("Por favor, aguarde alguns minutos. Em breve você poderá acessar a internet.")); - } + request->send(200, "text/html", getHtmlContents("Por favor, aguarde alguns minutos. Em breve você poderá acessar a internet.")); + } else { - request->redirect("/"); + request->redirect("/"); } } }; @@ -74,12 +74,12 @@ void startEvilPortal(String tssid, uint8_t channel, bool deauth) { }; delay(200); loopOptions(options); - + while(checkNextPress()){ yield(); } // debounce delay(200); // tssid="" means that are opening a virgin Evil Portal - if (tssid=="") { - AP_name = keyboard("Free Wifi", 30, "Evil Portal SSID:"); + if (tssid=="") { + AP_name = keyboard("Free Wifi", 30, "Evil Portal SSID:"); } else { // tssid != "" means that is was cloned and can deploy Deauth //memcpy(ap_record.bssid, bssid, 6); @@ -90,13 +90,13 @@ void startEvilPortal(String tssid, uint8_t channel, bool deauth) { wifiConnected=true; drawMainBorder(); - displayRedStripe("Starting..",TFT_WHITE,FGCOLOR); + displayRedStripe("Starting..",TFT_WHITE,bruceConfig.priColor); IPAddress AP_GATEWAY(172, 0, 0, 1); WiFi.mode(WIFI_MODE_AP); WiFi.softAPConfig(AP_GATEWAY, AP_GATEWAY, IPAddress(255, 255, 255, 0)); WiFi.softAP(AP_name,emptyString,channel); - + tmp=millis(); while(millis() - tmp < 3000) yield(); dnsServer.start(53, "*", WiFi.softAPIP()); @@ -125,7 +125,7 @@ void startEvilPortal(String tssid, uint8_t channel, bool deauth) { previousTotalCapturedCredentials=-1; // redesenha a tela }); - ep->on("/clear", HTTP_GET, [](AsyncWebServerRequest * request) { + ep->on("/clear", HTTP_GET, [](AsyncWebServerRequest * request) { request->send(200, "text/html", clear_GET()); }); @@ -148,8 +148,8 @@ void startEvilPortal(String tssid, uint8_t channel, bool deauth) { new (ep) AsyncWebServer(80); ep->begin(); - tft.fillRect(6, 27, WIDTH-12, HEIGHT-33, BGCOLOR); - + tft.fillRect(6, 27, WIDTH-12, HEIGHT-33, bruceConfig.bgColor); + bool hold_deauth = false; tmp=millis(); // one deauth frame each 30ms at least redraw=true; @@ -160,7 +160,7 @@ void startEvilPortal(String tssid, uint8_t channel, bool deauth) { tft.setTextColor(TFT_RED); tft.drawCentreString("Evil Portal",WIDTH/2, 29, SMOOTH_FONT); tft.setCursor(7,49); - tft.setTextColor(FGCOLOR); + tft.setTextColor(bruceConfig.priColor); tft.println("AP: " + AP_name); tft.setCursor(7,tft.getCursorY()); tft.println("->" + WiFi.softAPIP().toString() + "/creds"); @@ -177,7 +177,7 @@ void startEvilPortal(String tssid, uint8_t channel, bool deauth) { if (deauth){ if (hold_deauth) { tft.setTextSize(FP); - tft.setTextColor(FGCOLOR); + tft.setTextColor(bruceConfig.priColor); tft.drawRightString("Deauth OFF", WIDTH-7,HEIGHT-14,SMOOTH_FONT); } else { tft.setTextSize(FP); @@ -190,7 +190,7 @@ void startEvilPortal(String tssid, uint8_t channel, bool deauth) { redraw=false; } - if(!hold_deauth && (millis()-tmp) >5) { + if(!hold_deauth && (millis()-tmp) >5) { wsl_bypasser_send_raw_frame(deauth_frame, 26); // sends deauth frames if needed. tmp=millis(); } @@ -232,7 +232,7 @@ void saveToCSV(const String &filename, const String &csvLine) { } String getHtmlContents(String body) { - PROGMEM String html = + PROGMEM String html = "" "" "" diff --git a/html/AsyncWebServer/webInterface.cpp b/html/AsyncWebServer/webInterface.cpp index f05614bc..37a7ae4d 100644 --- a/html/AsyncWebServer/webInterface.cpp +++ b/html/AsyncWebServer/webInterface.cpp @@ -21,7 +21,7 @@ bool update; size_t file_size; // WiFi as a Client -String default_httpuser = "admin"; +String default_httpuser = "admin"; String default_httppassword = "bruce"; const int default_webserverporthttp = 80; @@ -44,13 +44,13 @@ String uploadFolder=""; **********************************************************************/ void webUIMyNet() { if (WiFi.status() != WL_CONNECTED) { - if(wifiConnectMenu()) startWebUi(false); + if(wifiConnectMenu()) startWebUi(false); else { displayError("Wifi Offline"); } } else { //If it is already connected, just start the network - startWebUi(false); + startWebUi(false); } sprite.createSprite(WIDTH-20,HEIGHT-20); // On fail installing will run the following line @@ -165,7 +165,7 @@ String processor(const String& var) { else if (var == "FREESD") return humanReadableSize(SD.totalBytes() - SD.usedBytes()); else if (var == "USEDSD") return humanReadableSize(SD.usedBytes()); else if (var == "TOTALSD") return humanReadableSize(SD.totalBytes()); - else return "Attribute not configured"; + else return "Attribute not configured"; } @@ -188,7 +188,7 @@ bool checkUserWebAuth(AsyncWebServerRequest * request) { **********************************************************************/ void handleUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) { // make sure authenticated before allowing upload - Serial.println("Folder: " + uploadFolder); + Serial.println("Folder: " + uploadFolder); if (uploadFolder=="/") uploadFolder = ""; if (checkUserWebAuth(request)) { @@ -229,7 +229,7 @@ void notFound(AsyncWebServerRequest *request) { void configureWebServer() { MDNS.begin(host); - + // if url isn't found server->onNotFound([](AsyncWebServerRequest * request) { request->redirect("/"); @@ -249,7 +249,7 @@ void configureWebServer() { }); server->on("/rename", HTTP_POST, [](AsyncWebServerRequest * request) { - if (request->hasParam("fileName", true) && request->hasParam("filePath", true)) { + if (request->hasParam("fileName", true) && request->hasParam("filePath", true)) { String fileName = request->getParam("fileName", true)->value().c_str(); String filePath = request->getParam("filePath", true)->value().c_str(); String filePath2 = filePath.substring(0,filePath.lastIndexOf('/')+1) + fileName; @@ -317,7 +317,7 @@ void configureWebServer() { } else if (strcmp(fileAction, "delete") == 0) { if(deleteFromSd(fileName)) { request->send(200, "text/plain", "Deleted : " + String(fileName)); } else { request->send(200, "text/plain", "FAIL delating: " + String(fileName));} - + } else if (strcmp(fileAction, "create") == 0) { if(SD.mkdir(fileName)) { } else { request->send(200, "text/plain", "FAIL creating folder: " + String(fileName));} @@ -340,7 +340,7 @@ void configureWebServer() { const char *ssid = request->getParam("usr")->value().c_str(); const char *pwd = request->getParam("pwd")->value().c_str(); SD.remove(fileconf); - File file = SD.open(fileconf, FILE_WRITE); + File file = SD.open(fileconf, FILE_WRITE); file.print(String(ssid) + ";" + String(pwd) + ";\n"); config.httpuser = ssid; config.httppassword = pwd; @@ -395,7 +395,7 @@ file_size = 0; // Choose wifi access mode wifiConnectMenu(mode_ap); } - + // configure web server Serial.println("Configuring Webserver ..."); #if defined(CARDPUTER) || defined(STICK_C_PLUS2) @@ -413,8 +413,8 @@ file_size = 0; String txt; if(!mode_ap) txt = WiFi.localIP().toString(); else txt = WiFi.softAPIP().toString(); - tft.setTextColor(FGCOLOR); - + tft.setTextColor(bruceConfig.priColor); + #ifndef STICK_C tft.drawCentreString("http://bruce.local", WIDTH/2,25,1); setTftDisplay(7,47); diff --git a/html/WebServer/evil_portal.cpp b/html/WebServer/evil_portal.cpp index 10957a2e..d988bd6e 100644 --- a/html/WebServer/evil_portal.cpp +++ b/html/WebServer/evil_portal.cpp @@ -40,7 +40,7 @@ void handleCreds() { saveToCSV("/Bruce_creds.csv", csvLine); capturedCredentialsHtml = html_temp + capturedCredentialsHtml; totalCapturedCredentials++; - ep->send(200, "text/html", getHtmlContents("Por favor, aguarde alguns minutos. Em breve você poderá acessar a internet.")); + ep->send(200, "text/html", getHtmlContents("Por favor, aguarde alguns minutos. Em breve você poderá acessar a internet.")); } void startEvilPortal(String tssid, uint8_t channel, bool deauth) { @@ -58,8 +58,8 @@ void startEvilPortal(String tssid, uint8_t channel, bool deauth) { while(checkNextPress()){ yield(); } // debounce // tssid="" means that are opening a virgin Evil Portal - if (tssid=="") { - AP_name = keyboard("Free Wifi", 30, "Evil Portal SSID:"); + if (tssid=="") { + AP_name = keyboard("Free Wifi", 30, "Evil Portal SSID:"); } else { // tssid != "" means that is was cloned and can deploy Deauth //memcpy(ap_record.bssid, bssid, 6); @@ -109,19 +109,19 @@ void startEvilPortal(String tssid, uint8_t channel, bool deauth) { }); ep->begin(); - + bool hold_deauth = false; int tmp=millis(); // one deauth frame each 30ms at least redraw=true; while(1) { if(redraw) { drawMainBorder(); - + tft.setTextSize(FM); tft.setTextColor(TFT_RED); tft.drawCentreString("Evil Portal",WIDTH/2, 29, SMOOTH_FONT); tft.setCursor(8,46); - tft.setTextColor(FGCOLOR); + tft.setTextColor(bruceConfig.priColor); tft.println("AP: " + AP_name); tft.setCursor(8,tft.getCursorY()); tft.println("->" + WiFi.softAPIP().toString() + "/creds"); @@ -138,7 +138,7 @@ void startEvilPortal(String tssid, uint8_t channel, bool deauth) { if (deauth){ if (hold_deauth) { tft.setTextSize(FP); - tft.setTextColor(FGCOLOR); + tft.setTextColor(bruceConfig.priColor); tft.drawRightString("Deauth OFF", WIDTH-6,HEIGHT-8,SMOOTH_FONT); } else { tft.setTextSize(FP); @@ -150,7 +150,7 @@ void startEvilPortal(String tssid, uint8_t channel, bool deauth) { redraw=false; } - if(!hold_deauth && (millis()-tmp) >5) { + if(!hold_deauth && (millis()-tmp) >5) { wsl_bypasser_send_raw_frame(deauth_frame, 26); // sends deauth frames if needed. tmp=millis(); } @@ -192,7 +192,7 @@ void saveToCSV(const String &filename, const String &csvLine) { } String getHtmlContents(String body) { - PROGMEM String html = + PROGMEM String html = "" "" "" diff --git a/html/WebServer/webInterface.cpp b/html/WebServer/webInterface.cpp index 3b4def72..45f735b6 100644 --- a/html/WebServer/webInterface.cpp +++ b/html/WebServer/webInterface.cpp @@ -14,7 +14,7 @@ struct Config { File uploadFile; // WiFi as a Client -String default_httpuser = "admin"; +String default_httpuser = "admin"; String default_httppassword = "bruce"; const int default_webserverporthttp = 80; @@ -36,13 +36,13 @@ String uploadFolder=""; **********************************************************************/ void webUIMyNet() { if (WiFi.status() != WL_CONNECTED) { - if(wifiConnectMenu()) startWebUi(false); + if(wifiConnectMenu()) startWebUi(false); else { displayError("Wifi Offline"); } } else { //If it is already connected, just start the network - startWebUi(false); + startWebUi(false); } // On fail installing will run the following line } @@ -158,7 +158,7 @@ String processor(const String& var) { processedHtml.replace("%FREESD%", humanReadableSize(SD.totalBytes() - SD.usedBytes())); processedHtml.replace("%USEDSD%", humanReadableSize(SD.usedBytes())); processedHtml.replace("%TOTALSD%", humanReadableSize(SD.totalBytes())); - + return processedHtml; } @@ -256,13 +256,13 @@ void configureWebServer() { // Route to rename a file server->on("/rename", HTTP_POST, []() { - if (server->hasArg("fileName") && server->hasArg("filePath")) { + if (server->hasArg("fileName") && server->hasArg("filePath")) { String fileName = server->arg("fileName").c_str(); String filePath = server->arg("filePath").c_str(); String filePath2 = filePath.substring(0,filePath.lastIndexOf('/')+1) + fileName; if(!SD.begin()) { server->send(200, "text/plain", "Fail starting SD Card."); - } + } else { // Rename the file of folder if (SD.rename(filePath, filePath2)) { @@ -311,7 +311,7 @@ void configureWebServer() { server->send(200, "text/plain", "Created new folder: " + String(fileName)); } else { server->send(200, "text/plain", "FAIL creating folder: " + String(fileName)); - } + } } else server->send(400, "text/plain", "ERROR: file does not exist"); } else { @@ -407,7 +407,7 @@ void startWebUi(bool mode_ap) { // Choose wifi access mode wifiConnectMenu(mode_ap); } - + // configure web server Serial.println("Configuring Webserver ..."); server = (WebServer*)malloc(sizeof(WebServer)); @@ -415,15 +415,15 @@ void startWebUi(bool mode_ap) { configureWebServer(); - tft.fillScreen(BGCOLOR); + tft.fillScreen(bruceConfig.bgColor); tft.drawRoundRect(5,5,WIDTH-10,HEIGHT-10,5,ALCOLOR); setTftDisplay(0,0,ALCOLOR,FM); tft.drawCentreString("BRUCE WebUI",WIDTH/2,7,1); String txt; if(!mode_ap) txt = WiFi.localIP().toString(); else txt = WiFi.softAPIP().toString(); - tft.setTextColor(FGCOLOR); - + tft.setTextColor(bruceConfig.priColor); + #ifndef STICK_C tft.drawCentreString("http://bruce.local", WIDTH/2,25,1); setTftDisplay(7,47); diff --git a/src/core/config.cpp b/src/core/config.cpp index 4b49d8bb..2238a11c 100644 --- a/src/core/config.cpp +++ b/src/core/config.cpp @@ -1,5 +1,6 @@ #include "config.h" #include "sd_functions.h" +#include void BruceConfig::fromFile() { diff --git a/src/core/config.h b/src/core/config.h index e3cdaed5..1ea91328 100644 --- a/src/core/config.h +++ b/src/core/config.h @@ -1,8 +1,21 @@ #ifndef __BRUCE_CONFIG_H__ #define __BRUCE_CONFIG_H__ -#include "core/globals.h" -// #include +// #include "globals.h" +#include + +#define DEFAULT_PRICOLOR 0xA80F + +enum RFIDModules { + M5_RFID2_MODULE = 0, + PN532_I2C_MODULE = 1, + PN532_SPI_MODULE = 2, +}; + +enum RFModules { + M5_RF_MODULE = 0, + CC1101_SPI_MODULE = 1, +}; class BruceConfig { @@ -16,8 +29,9 @@ class BruceConfig { // Theme colors in RGB565 format uint16_t priColor = 0xA80F; - uint16_t secColor = 0xFA99; // 0x0566; - uint16_t bgColor = 0x0; + uint16_t secColor = 0x880F; + // uint16_t secColor = 0xFA99; // 0x0566; + uint16_t bgColor = 0x0; // Black int irTx = LED; int irRx = GROVE_SCL; diff --git a/src/core/display.cpp b/src/core/display.cpp index 760ef1b1..23abf87c 100644 --- a/src/core/display.cpp +++ b/src/core/display.cpp @@ -256,12 +256,12 @@ int loopOptions(std::vector