Skip to content

Commit

Permalink
Merge pull request #252 from rennancockles/dev
Browse files Browse the repository at this point in the history
R3ck changes
  • Loading branch information
pr3y authored Sep 10, 2024
2 parents d6a53e3 + 50ac97a commit d65127e
Show file tree
Hide file tree
Showing 24 changed files with 204 additions and 5,542 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
.vscode/launch.json
.vscode/ipch
Bruce3_*.bin
bruce.conf
_*.sh
tmp
2 changes: 2 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ lib_deps =
LibSSH-ESP32
PCA9554
https://github.com/bmorcelli/ESPping/
https://github.com/rennancockles/PN532
https://github.com/rennancockles/MFRC522-I2C
NTPClient
Timezone
ESP32Time
Expand Down
1 change: 1 addition & 0 deletions src/core/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ extern bool isScreenOff;
extern bool dimmer;
extern int dimmerSet;
extern int devMode;
extern int soundEnabled;

void readFGCOLORFromEEPROM();

Expand Down
1 change: 1 addition & 0 deletions src/core/menu_items/ConfigMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ void ConfigMenu::optionsMenu() {
{"Dim Time", [=]() { setDimmerTimeMenu(); saveConfigs();}},
{"Orientation", [=]() { gsetRotation(true); saveConfigs();}},
{"UI Color", [=]() { setUIColor(); saveConfigs();}},
{"Sound On/Off", [=]() { setSoundConfig(); saveConfigs();}},
{"Clock", [=]() { setClock(); }},
{"Sleep", [=]() { setSleepMode(); }},
{"Restart", [=]() { ESP.restart(); }},
Expand Down
47 changes: 28 additions & 19 deletions src/core/sd_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ String readSmallFile(FS &fs, String filepath) {
Serial.println("File is too big");
return "";
}

fileContent = file.readString();

file.close();
Expand Down Expand Up @@ -375,18 +375,18 @@ String crc32File(FS &fs, String filepath) {
String readDecryptedFile(FS &fs, String filepath) {
String cyphertext = readSmallFile(fs, filepath);
if(cyphertext.length() == 0) return "";

if(cachedPassword.length()==0) {
cachedPassword = keyboard("", 32, "password");
if(cachedPassword.length()==0) return ""; // cancelled
}

//Serial.println(cyphertext);
//Serial.println(cachedPassword);

// else try to decrypt
String plaintext = decryptString(cyphertext, cachedPassword);

// check if really plaintext
if(!isValidAscii(plaintext)) {
// invalidate cached password -> will ask again on the next try
Expand All @@ -395,7 +395,7 @@ String readDecryptedFile(FS &fs, String filepath) {
//Serial.println(plaintext);
return "";
}

// else
return plaintext;
}
Expand Down Expand Up @@ -648,30 +648,39 @@ String loopSD(FS &fs, bool filePicker, String allowed_ext) {
delay(200);
txSubFile(&fs, filepath);
}});
if(filepath.endsWith(".csv")) options.insert(options.begin(), {"Wigle Upload", [&]() {
if(filepath.endsWith(".csv")) {
options.insert(options.begin(), {"Wigle Upload", [&]() {
delay(200);
Wigle wigle;
wigle.upload(&fs, filepath);
}});
if(filepath.endsWith(".bjs") || filepath.endsWith(".js")) options.insert(options.begin(), {"JS Script Run", [&]() {
options.insert(options.begin(), {"Wigle Up All", [&]() {
delay(200);
Wigle wigle;
wigle.upload_all(&fs, Folder);
}});
}
if(filepath.endsWith(".bjs") || filepath.endsWith(".js")) {
options.insert(options.begin(), {"JS Script Run", [&]() {
delay(200);
run_bjs_script_headless(fs, filepath);
}});
}
#if defined(USB_as_HID)
if(filepath.endsWith(".txt")) {
options.push_back({"BadUSB Run", [&]() {
Kb.begin(); USB.begin();
options.push_back({"BadUSB Run", [&]() {
Kb.begin(); USB.begin();
key_input(fs, filepath);
// TODO: reinit serial port
}});
options.push_back({"USB HID Type", [&]() {
options.push_back({"USB HID Type", [&]() {
String t = readSmallFile(fs, filepath);
displayInfo("Typing");
key_input_from_string(t);
}});
}
if(filepath.endsWith(".enc")) { // encrypted files
options.insert(options.begin(), {"Decrypt+Type", [&]() {
options.insert(options.begin(), {"Decrypt+Type", [&]() {
String plaintext = readDecryptedFile(fs, filepath);
if(plaintext.length()==0) // file is too big or cannot read, or cancelled
// else
Expand Down Expand Up @@ -703,16 +712,16 @@ String loopSD(FS &fs, bool filePicker, String allowed_ext) {
size_t filesize = getFileSize(fs, filepath);
//Serial.println(filesize);
if(filesize < SAFE_STACK_BUFFER_SIZE && filesize>0) {
options.push_back({"QR code", [&]() {
options.push_back({"QR code", [&]() {
delay(200);
qrcode_display(readSmallFile(fs, filepath));
}});
options.push_back({"CRC32", [&]() {
options.push_back({"CRC32", [&]() {
delay(200);
displaySuccess(crc32File(fs, filepath));
while(!checkAnyKeyPress()) delay(100);
}});
options.push_back({"MD5", [&]() {
options.push_back({"MD5", [&]() {
delay(200);
displaySuccess(md5File(fs, filepath));
while(!checkAnyKeyPress()) delay(100);
Expand Down Expand Up @@ -741,7 +750,7 @@ String loopSD(FS &fs, bool filePicker, String allowed_ext) {

#ifdef CARDPUTER
if(checkEscPress()) break; // quit

/* TODO: go back 1 level instead of quitting
if(Keyboard.isKeyPressed(KEY_BACKSPACE)) {
// go back 1 level
Expand All @@ -751,7 +760,7 @@ String loopSD(FS &fs, bool filePicker, String allowed_ext) {
redraw=true;
continue;
}*/

const short PAGE_JUMP_SIZE = 5;
if(checkNextPagePress()) {
index += PAGE_JUMP_SIZE;
Expand All @@ -765,9 +774,9 @@ String loopSD(FS &fs, bool filePicker, String allowed_ext) {
redraw = true;
continue;
}

// check letter shortcuts

char pressed_letter = checkLetterShortcutPress();
if(pressed_letter>0) {
//Serial.println(pressed_letter);
Expand Down
24 changes: 22 additions & 2 deletions src/core/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,24 @@ void setUIColor(){
EEPROM.end();
}

/*********************************************************************
** Function: setSoundConfig
** Enable or disable sound
**********************************************************************/
void setSoundConfig() {
int result = 0;

options = {
{"Sound off", [&]() { result = 0; }, soundEnabled == 0},
{"Sound on", [&]() { result = 1; }, soundEnabled == 1},
};
delay(200);
loopOptions(options, soundEnabled);
delay(200);

soundEnabled=result;
}

/*********************************************************************
** Function: setRFModuleMenu
** Handles Menu to set the RF module in use
Expand Down Expand Up @@ -739,9 +757,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,\"RfidModule\":"+String(RfidModule)+",\"wifi\":[{\"ssid\":\"myNetSSID\",\"pwd\":\"myNetPassword\"}],\"wigleBasicToken\":\"\",\"devMode\":0}]");
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,\"RfidModule\":"+String(RfidModule)+",\"wifi\":[{\"ssid\":\"myNetSSID\",\"pwd\":\"myNetPassword\"}],\"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,\"RfidModule\":"+String(RfidModule)+",\"wifi\":[{\"ssid\":\"myNetSSID\",\"pwd\":\"myNetPassword\"}],\"wigleBasicToken\":\"\",\"devMode\":0}]");
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,\"RfidModule\":"+String(RfidModule)+",\"wifi\":[{\"ssid\":\"myNetSSID\",\"pwd\":\"myNetPassword\"}],\"wigleBasicToken\":\"\",\"devMode\":0,\"soundEnabled\":1}]");
#endif
}
file.close();
Expand Down Expand Up @@ -782,6 +800,7 @@ void getConfigs() {
if(setting.containsKey("wigleBasicToken")) { wigleBasicToken = setting["wigleBasicToken"].as<String>(); } else { count++; log_i("Fail"); }

if(setting.containsKey("devMode")) { devMode = setting["devMode"].as<int>(); } else { count++; log_i("Fail"); }
if(setting.containsKey("soundEnabled")) { soundEnabled = setting["soundEnabled"].as<int>(); } else { count++; log_i("Fail"); }

log_i("Brightness: %d", bright);
setBrightness(bright);
Expand Down Expand Up @@ -856,6 +875,7 @@ void saveConfigs() {
}
setting["wigleBasicToken"] = wigleBasicToken;
setting["devMode"] = devMode;
setting["soundEnabled"] = soundEnabled;
// Open file for writing
File file = fs->open(CONFIG_FILE, FILE_WRITE);
if (!file) {
Expand Down
2 changes: 2 additions & 0 deletions src/core/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ void getConfigs();
void saveConfigs();

void runClockLoop();

void setSoundConfig();
5 changes: 4 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ int dimmerSet;
int bright=100;
int tmz=3;
int devMode=0;
int soundEnabled=1;
bool interpreter_start = false;
bool sdcardMounted = false;
bool gpsConnected = false;
Expand Down Expand Up @@ -126,7 +127,7 @@ void setup_gpio() {
#if defined(BACKLIGHT)
pinMode(BACKLIGHT, OUTPUT);
#endif
//if(RfModule==1)
//if(RfModule==1)
initCC1101once(&sdcardSPI); // Sets GPIO in the CC1101 lib
}

Expand Down Expand Up @@ -335,6 +336,8 @@ void setup() {

boot_screen();
setupSdCard();
getConfigs();

startup_sound();

#if ! defined(HAS_SCREEN)
Expand Down
Loading

0 comments on commit d65127e

Please sign in to comment.