From 4546bf6f6d1e75f458bb5ced139ba466fb95a9c4 Mon Sep 17 00:00:00 2001 From: Pirata Date: Fri, 2 Aug 2024 11:40:35 -0300 Subject: [PATCH 1/3] Mic Fix, and Porting preparation BLE Scan fix for StickCP1.1 is on the way --- custom_4Mb_full.csv | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 custom_4Mb_full.csv diff --git a/custom_4Mb_full.csv b/custom_4Mb_full.csv new file mode 100644 index 00000000..88cb9246 --- /dev/null +++ b/custom_4Mb_full.csv @@ -0,0 +1,4 @@ +# Name, Type, SubType, Offset, Size, Flags +nvs, data, nvs, 0x9000, 0x6000, +app0, app, ota_0, 0x10000, 0x260000, +spiffs, data, spiffs, 0x270000,0x190000, \ No newline at end of file From 04bad3ad899cbfae4c1899cc2c96e7fed59d0c5b Mon Sep 17 00:00:00 2001 From: Pirata Date: Fri, 2 Aug 2024 11:41:29 -0300 Subject: [PATCH 2/3] Mic Fix and port prep --- .vscode/settings.json | 6 +- platformio.ini | 135 +++++++++++++----- src/core/display.cpp | 28 ++-- src/core/main_menu.cpp | 17 ++- src/core/mykeyboard.cpp | 208 +--------------------------- src/core/serialcmds.cpp | 14 +- src/core/settings.cpp | 12 +- src/main.cpp | 28 ++-- src/modules/ble/ble_common.cpp | 3 +- src/modules/others/bad_usb.cpp | 2 +- src/modules/others/bad_usb.h | 2 +- src/modules/others/led.cpp | 2 +- src/modules/others/led_control.h | 2 +- src/modules/others/mic.cpp | 57 +++----- src/modules/others/mic.h | 2 +- src/modules/others/tururururu.cpp | 4 - src/modules/others/webInterface.cpp | 14 +- src/modules/wifi/dpwo.cpp | 35 ++++- src/modules/wifi/evil_portal.cpp | 7 +- src/modules/wifi/scan_hosts.cpp | 2 +- 20 files changed, 218 insertions(+), 362 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index cedeea77..e873977f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -47,6 +47,10 @@ "stdexcept": "cpp", "streambuf": "cpp", "cinttypes": "cpp", - "typeinfo": "cpp" + "typeinfo": "cpp", + "bitset": "cpp", + "complex": "cpp", + "ctime": "cpp", + "regex": "cpp" } } \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 7ee3df59..240bcf24 100644 --- a/platformio.ini +++ b/platformio.ini @@ -38,6 +38,7 @@ lib_deps = FFat ESP8266SAM TinyGPSPlus + tinyu-zhao/FFT@^0.0.1 [env:m5stack-cplus2] platform = espressif32 @@ -56,30 +57,48 @@ build_flags = -DSTICK_C_PLUS2=1 - -DROTATION=3 - + ;Features Enabled + ;-DLITE_VERSION=1 ; limits some features to save space for M5Launcher Compatibility + -DMIC_SPM1423=1 ;Applicable for SPM1423 device + -DPIN_CLK=0 + -DI2S_SCLK_PIN=0 + -DI2S_DATA_PIN=34 + -DPIN_DATA=34 + + ;Have RTC Chip + -DHAS_RTC=1 + + ;Buttons configuration -DHAS_BTN=1 -DSEL_BTN=37 -DUP_BTN=35 -DDW_BTN=39 + -DBTN_ACT=LOW -DBTN_ALIAS='"M5"' - -DHAS_SCREEN=1 - -DWIDTH=240 - -DHEIGHT=135 - -DBACKLIGHT=27 - -DMINBRIGHT=160 - + ;Infrared Led default pin and state -DLED=19 -DLED_ON=HIGH -DLED_OFF=LOW + + ;Battery ADC read pin -DBAT_PIN=38 - + + ;Font sizes, depending on device -DFP=1 -DFM=2 -DFG=3 -DMAX_MENU_SIZE=5 - + + ; Screen Setup + -DHAS_SCREEN=1 + -DROTATION=3 + -DWIDTH=240 + -DHEIGHT=135 + -DBACKLIGHT=27 + -DMINBRIGHT=160 + + ; TFT_eSPI Setup -DUSER_SETUP_LOADED=1 -DST7789_2_DRIVER=1 -DTFT_RGB_ORDER=1 @@ -98,18 +117,17 @@ build_flags = -DSPI_READ_FREQUENCY=20000000 -DSPI_TOUCH_FREQUENCY=2500000 - -DSDCARD_SPI_BUS=HSPI + ;SD Card Setup pins -DSDCARD_CS=14 -DSDCARD_SCK=0 -DSDCARD_MISO=36 -DSDCARD_MOSI=26 + ;Default I2C port -DGROVE_SDA=32 -DGROVE_SCL=33 lib_deps = ${common.lib_deps} - tinyu-zhao/FFT@^0.0.1 -platform_packages = platformio/toolchain-xtensa32@^2.50200.97 [env:m5stack-cplus1_1] platform = espressif32 @@ -119,27 +137,47 @@ board_build.partitions = custom_4Mb.csv build_flags = ${common.build_flags} -DCORE_DEBUG_LEVEL=5 + -DSTICK_C_PLUS=1 - -DROTATION=3 + + ;Features Enabled + -DLITE_VERSION=1 ; limits some features to save space for M5Launcher Compatibility + ;Microphone + -DMIC_SPM1423=1 ;Applicable for SPM1423 device + -DPIN_CLK=0 + -DI2S_SCLK_PIN=0 + -DI2S_DATA_PIN=34 + -DPIN_DATA=34 + + ;Buttons Setup -DHAS_BTN=1 -DSEL_BTN=37 -DUP_BTN=0 -DDW_BTN=39 + -DBTN_ACT=LOW -DBTN_ALIAS='"M5"' - -DWIDTH=240 - -DHEIGHT=135 - -DMAX_MENU_SIZE=5 - -DHAS_SCREEN=1 - + ;Infrared Led default pin and state -DLED=9 -DLED_ON=LOW -DLED_OFF=HIGH - + + ;Battery ADC read pin + -DBAT_PIN=10 + + ;Font sizes, depending on device -DFP=1 -DFM=2 -DFG=3 - + + ; Screen Setup + -DHAS_SCREEN=1 + -DROTATION=3 + -DWIDTH=240 + -DHEIGHT=135 + -DMAX_MENU_SIZE=5 + + ; TFT_eSPI Setup -DUSER_SETUP_LOADED=1 -DST7789_2_DRIVER=1 -DTFT_RGB_ORDER=1 @@ -158,19 +196,17 @@ build_flags = -DSPI_READ_FREQUENCY=20000000 -DSPI_TOUCH_FREQUENCY=2500000 - -DSDCARD_SPI_BUS=HSPI + ;SD Card Setup pins -DSDCARD_CS=14 -DSDCARD_SCK=0 -DSDCARD_MISO=36 -DSDCARD_MOSI=26 - + + ;Default I2C port -DGROVE_SDA=32 -DGROVE_SCL=33 lib_deps = - https://github.com/tanakamasayuki/I2C_AXP192 ${common.lib_deps} - tinyu-zhao/FFT@^0.0.1 -platform_packages = platformio/toolchain-xtensa32@^2.50200.97 [env:m5stack-cardputer] platform = espressif32 @@ -180,15 +216,40 @@ board_build.partitions = custom_8Mb.csv build_flags = ${common.build_flags} -DCORE_DEBUG_LEVEL=5 + -DARDUINO_USB_CDC_ON_BOOT=1 + -DCARDPUTER=1 - - -DROTATION=1 - - -DHAS_BTN=1 + + ;Features Enabled + ;-DLITE_VERSION=1 ; limits some features to save space for M5Launcher Compatibility + ;Microphone + -DMIC_SPM1423=1 ; uncomment to enable Applicable for SPM1423 device + -DPIN_CLK=43 + -DI2S_SCLK_PIN=43 + -DI2S_DATA_PIN=46 + -DPIN_DATA=46 + + ;RGB LED runned by xylopyrographer/LiteLED@^1.2.0 library + -DHAS_RGB_LED=1 + -DRGB_LED=21 + + ;Speaker to run music, compatible with NS4168 + -DHAS_NS4168_SPKR=1 ; uncomment to enable + -DBCLK=41 + -DWCLK=43 + -DDOUT=42 + + ;Can run USB as HID + -DUSB_as_HID=1 + + ;Buttons configuration + -DHAS_BTN=0 -DBTN_ALIAS='"Ok"' -DBTN_PIN=0 + -DBTN_ACT=LOw -DHAS_SCREEN=1 + -DROTATION=1 -DWIDTH=240 -DHEIGHT=135 -DBACKLIGHT=38 @@ -198,13 +259,13 @@ build_flags = -DFP=1 -DFM=2 -DFG=3 - - -DBAT_PIN=10 - -DRGB_LED=21 + + ;Infrared Led default pin and state -DLED=44 -DLED_ON=HIGH -DLED_OFF=LOW + ; TFT_eSPI Setup -DUSER_SETUP_LOADED=1 -DUSE_HSPI_PORT=1 -DST7789_2_DRIVER=1 @@ -224,18 +285,16 @@ build_flags = -DSPI_READ_FREQUENCY=20000000 -DSPI_TOUCH_FREQUENCY=2500000 - -DSDCARD_SPI_BUS=FSPI + ;SD Card Setup pins -DSDCARD_CS=12 -DSDCARD_SCK=40 -DSDCARD_MISO=39 -DSDCARD_MOSI=14 - + + ;Default I2C port -DGROVE_SDA=2 -DGROVE_SCL=1 - -DARDUINO_USB_CDC_ON_BOOT=1 lib_deps = ${common.lib_deps} xylopyrographer/LiteLED@^1.2.0 - tinyu-zhao/FFT@^0.0.1 -platform_packages = platformio/toolchain-xtensa32@^2.50200.97 diff --git a/src/core/display.cpp b/src/core/display.cpp index f15aa3da..eb54cc9e 100644 --- a/src/core/display.cpp +++ b/src/core/display.cpp @@ -81,11 +81,15 @@ void loopOptions(const std::vector> if(submenu) drawSubmenu(index, options, subText); else drawOptions(index, options, FGCOLOR, BGCOLOR); if(bright){ - #if !defined(STICK_C_PLUS) + #if defined(STICK_C_PLUS2) || defined(CARDPUTER) int bl = MINBRIGHT + round(((255 - MINBRIGHT) * (4 - index) * 0.25)); // 4 is the number of options analogWrite(BACKLIGHT, bl); - #else + #elif defined(STICK_C_PLUS) axp192.ScreenBreath(100*(4 - index) * 0.25); // 4 is the number of options + #elif defined(NEW_DEVICE) + + #else + #endif } redraw=false; @@ -127,7 +131,6 @@ void loopOptions(const std::vector> ** Dependencia: prog_handler =>> 0 - Flash, 1 - LittleFS ***************************************************************************************/ void progressHandler(int progress, size_t total) { -#ifndef STICK_C int barWidth = map(progress, 0, total, 0, 200); if(barWidth <3) { tft.fillRect(6, 27, WIDTH-12, HEIGHT-33, BGCOLOR); @@ -135,18 +138,6 @@ void progressHandler(int progress, size_t total) { displayRedStripe("Running, Wait", TFT_WHITE, FGCOLOR); } tft.fillRect(20, HEIGHT - 45, barWidth, 13, FGCOLOR); -#else - - int barWidth = map(progress, 0, total, 0, 100); - if(barWidth <2) { - tft.fillRect(6, 6, WIDTH-12, HEIGHT-12, BGCOLOR); - tft.drawRect(28, HEIGHT - 47, 104, 17, FGCOLOR); - displayRedStripe("Wait",TFT_WHITE,FGCOLOR); - } - tft.fillRect(30, HEIGHT - 45, barWidth, 13, FGCOLOR); - -#endif - } /*************************************************************************************** @@ -283,7 +274,7 @@ int getBattery() { float b = axp192.GetBatVoltage(); percent = ((b - 3.0) / 1.2) * 100; - #else + #elif defined(CARDPUTER) || defined(STICK_C_PLUS2) #if defined(CARDPUTER) uint8_t _batAdcCh = ADC1_GPIO10_CHANNEL; @@ -306,6 +297,11 @@ int getBattery() { float mv = volt * 2; percent = (mv - 3300) * 100 / (float)(4150 - 3350); + //#elif defined(NEW_DEVICE) + + #else + percent = 0; + #endif return (percent < 0) ? 0 : (percent >= 100) ? 100 diff --git a/src/core/main_menu.cpp b/src/core/main_menu.cpp index af5487c2..0c0f8a7a 100644 --- a/src/core/main_menu.cpp +++ b/src/core/main_menu.cpp @@ -24,8 +24,10 @@ #include "modules/wifi/wifi_atks.h" #include "modules/wifi/wardriving.h" -#ifdef CARDPUTER +#ifdef USB_as_HID #include "modules/others/bad_usb.h" +#endif +#ifdef HAS_RGB_LED #include "modules/others/led_control.h" #endif @@ -47,7 +49,7 @@ void wifiOptions() { } options.push_back({"Wifi Atks", [=]() { wifi_atk_menu(); }}); options.push_back({"Wardriving", [=]() { wardriving_setup(); }}); -#ifndef STICK_C_PLUS +#ifndef LITE_VERSION options.push_back({"TelNET", [=]() { telnet_setup(); }}); options.push_back({"SSH", [=]() { ssh_setup(); }}); #endif @@ -55,7 +57,7 @@ void wifiOptions() { options.push_back({"DPWO", [=]() { dpwo_setup(); }}); options.push_back({"Evil Portal", [=]() { startEvilPortal(); }}); options.push_back({"Scan Hosts", [=]() { local_scan_setup(); }}); -#ifndef STICK_C_PLUS +#ifndef LITE_VERSION options.push_back({"Wireguard", [=]() { wg_setup(); }}); #endif options.push_back({"Main Menu", [=]() { backToMenu(); }}); @@ -92,7 +94,6 @@ void bleOptions() { void rfOptions(){ options = { {"Scan/copy", [=]() { RCSwitch_Read_Raw(); }}, - //{"Replay", [=]() { displayRedStripe("Replay"); }}, {"Custom SubGhz", [=]() { otherRFcodes(); }}, {"Spectrum", [=]() { rf_spectrum(); }}, //@IncursioHack {"Jammer Itmt", [=]() { rf_jammerIntermittent(); }}, //@IncursioHack @@ -141,15 +142,19 @@ void irOptions(){ **********************************************************************/ void otherOptions(){ options = { + #ifdef MIC_SPM1423 {"Mic Spectrum", [=]() { mic_test(); }}, + #endif {"QRCodes", [=]() { qrcode_menu(); }}, {"SD Card", [=]() { loopSD(SD); }}, {"LittleFS", [=]() { loopSD(LittleFS); }}, {"WebUI", [=]() { loopOptionsWebUi(); }}, {"Megalodon", [=]() { shark_setup(); }}, - #ifdef CARDPUTER + #ifdef USB_as_HID {"BadUSB", [=]() { usb_setup(); }}, {"USB Keyboard",[=]() { usb_keyboard(); }}, + #endif + #ifdef HAS_RGB_LED {"LED Control", [=]() { ledrgb_setup(); }}, //IncursioHack {"LED FLash", [=]() { ledrgb_flash(); }}, // IncursioHack #endif @@ -174,10 +179,8 @@ void configOptions(){ {"UI Color", [=]() { setUIColor(); saveConfigs();}}, {"Ir TX Pin", [=]() { gsetIrTxPin(true); saveConfigs();}}, {"Ir RX Pin", [=]() { gsetIrRxPin(true); saveConfigs();}}, - #ifndef CARDPUTER {"RF TX Pin", [=]() { gsetRfTxPin(true); saveConfigs();}}, {"RF RX Pin", [=]() { gsetRfRxPin(true); saveConfigs();}}, - #endif {"Sleep", [=]() { setSleepMode(); }}, {"Restart", [=]() { ESP.restart(); }}, {"Main Menu", [=]() { backToMenu(); }}, diff --git a/src/core/mykeyboard.cpp b/src/core/mykeyboard.cpp index 4db45f6e..f9c4a84b 100644 --- a/src/core/mykeyboard.cpp +++ b/src/core/mykeyboard.cpp @@ -53,6 +53,8 @@ bool checkSelPress(){ #if defined (CARDPUTER) Keyboard.update(); if(Keyboard.isKeyPressed(KEY_ENTER) || digitalRead(0)==LOW) + #elif defined(NEW_DEVICE) + #else if(digitalRead(SEL_BTN)==LOW) #endif @@ -75,6 +77,10 @@ bool checkEscPress(){ #elif defined (CARDPUTER) Keyboard.update(); if(Keyboard.isKeyPressed('`')) + #elif defined(NEW_DEVICE) + + #else + if(digitalRead(UP_BTN)==LOW) #endif { if(wakeUpScreen()){ @@ -113,7 +119,6 @@ void checkShortcutPress(){ #endif } -#ifndef STICK_C /* Starts keyboard to type data */ String keyboard(String mytext, int maxSize, String msg) { @@ -401,207 +406,6 @@ String keyboard(String mytext, int maxSize, String msg) { return mytext; } -#else - -/* Starts keyboard to type data */ -String keyboard(String mytext, int maxSize, String msg) { - - resetTftDisplay(); - bool caps=false; - int x=0; - int y=-1; - char keys[4][12][2] = { //4 lines, with 12 characteres, low and high caps - { - { '1', '!' },//1 - { '2', '@' },//2 - { '3', '#' },//3 - { '4', '$' },//4 - { '5', '%' },//5 - { '6', '^' },//6 - { '7', '&' },//7 - { '8', '*' },//8 - { '9', '(' },//9 - { '0', ')' },//10 - { '-', '_' },//11 - { '=', '+' } //12 - }, - { - { 'q', 'Q' },//1 - { 'w', 'W' },//2 - { 'e', 'E' },//3 - { 'r', 'R' },//4 - { 't', 'T' },//5 - { 'y', 'Y' },//6 - { 'u', 'U' },//7 - { 'i', 'I' },//8 - { 'o', 'O' },//9 - { 'p', 'P' },//10 - { '[', '{' },//11 - { ']', '}' } //12 - }, - { - { 'a', 'A' },//1 - { 's', 'S' },//2 - { 'd', 'D' },//3 - { 'f', 'F' },//4 - { 'g', 'G' },//5 - { 'h', 'H' },//6 - { 'j', 'J' },//7 - { 'k', 'K' },//8 - { 'l', 'L' },//9 - { ';', ':' },//10 - { '"', '\'' },//11 - { '|', '\\' } //12 - }, - { - { '\\', '|' },//1 - { 'z', 'Z' },//2 - { 'x', 'X' },//3 - { 'c', 'C' },//4 - { 'v', 'V' },//5 - { 'b', 'B' },//6 - { 'n', 'N' },//7 - { 'm', 'M' },//8 - { ',', '<' },//9 - { '.', '>' },//10 - { '?', '/' },//11 - { '/', '/' } //12 - } - }; - - int i=0; - int j=0; - delay(200); - bool redraw = true; - while(1) { - if(redraw) { - tft.setCursor(0,0); - tft.fillScreen(BGCOLOR); - tft.setTextColor(TFT_WHITE, BGCOLOR); - tft.setTextSize(FM); - - //Draw the rectangles - tft.drawRect(7,2,20,10,TFT_WHITE); // Ok Rectangle - tft.drawRect(27,2,25,10,TFT_WHITE); // CAP Rectangle - tft.drawRect(52,2,25,10,TFT_WHITE); // DEL Rectangle - tft.drawRect(77,2,50,10,TFT_WHITE); // SPACE Rectangle - tft.drawRect(3,22,WIDTH-3,11,FGCOLOR); // mystring Rectangle - - - if(x==0 && y==-1) { tft.setTextColor(BGCOLOR, TFT_WHITE); tft.fillRect(7,2,20,10,TFT_WHITE); } - else tft.setTextColor(TFT_WHITE, BGCOLOR); - tft.drawString("OK", 10, 4); - - - if(x==1 && y==-1) { tft.setTextColor(BGCOLOR, TFT_WHITE); tft.fillRect(27,2,25,10,TFT_WHITE); } - else if(caps) { tft.fillRect(55,2,50,20,TFT_DARKGREY); tft.setTextColor(TFT_WHITE, TFT_DARKGREY); } - else tft.setTextColor(TFT_WHITE, BGCOLOR); - tft.drawString("CAP", 30, 4); - - - if(x==2 && y==-1) { tft.setTextColor(BGCOLOR, TFT_WHITE); tft.fillRect(52,2,25,10,TFT_WHITE); } - else tft.setTextColor(TFT_WHITE, BGCOLOR); - tft.drawString("DEL", 55, 4); - - if(x>2 && y==-1) { tft.setTextColor(BGCOLOR, TFT_WHITE); tft.fillRect(77,2,50,10,TFT_WHITE); } - else tft.setTextColor(TFT_WHITE, BGCOLOR); - tft.drawString("SPACE", 80, 4); - - tft.setTextSize(FP); - tft.setTextColor(TFT_WHITE); - tft.drawString(msg.substring(0,38), 3, 14); - - tft.setTextSize(FM); - - - tft.setTextColor(TFT_WHITE, 0x5AAB); - if(mytext.length()>19) { - tft.setTextSize(FP); - if(mytext.length()>38) { - tft.drawString(mytext.substring(0,38), 5, 24); - tft.drawString(mytext.substring(38,mytext.length()), 5, 32); - } - else { - tft.drawString(mytext, 5, 24); - } - } else { - tft.drawString(mytext, 5, 24); - } - - - tft.setTextColor(TFT_WHITE, BGCOLOR); - tft.setTextSize(FM); - - - for(i=0;i<4;i++) { - for(j=0;j<12;j++) { - /* If selected, change font color and draw Rectangle*/ - if(x==j && y==i) { tft.setTextColor(BGCOLOR, TFT_WHITE); tft.fillRect(j*11+15,i*9+34,10,10,TFT_WHITE);} - - /* Print the letters */ - if(!caps) tft.drawChar(keys[i][j][0], (j*11+18), (i*9+36)); - else tft.drawChar(keys[i][j][1], (j*11+18), (i*9+36)); - - /* Return colors to normal to print the other letters */ - if(x==j && y==i) { tft.setTextColor(TFT_WHITE, BGCOLOR); } - } - } - redraw = false; - } - - - /* When Select a key in keyboard */ - - if(checkSelPress()) { - int z=0; - if(caps) z=1; - else z=0; - if(x==0 && y==-1) break; - else if(x==1 && y==-1) caps=!caps; - else if(x==2 && y==-1 && mytext.length() > 0) mytext.remove(mytext.length()-1); - else if(x>2 && y==-1 && mytext.length()-1 && mytext.length()3) x=0; - if(x>11) x=0; - else if (x<0) x=11; - redraw = true; - } - /* UP Btn to move in Y axis (Downwards) */ - if(checkPrevPress()) { - delay(200); - - if(checkPrevPress()) { y--; delay(250); }// Long press - else y++; // short press - - if(y>3) { y=-1; } - else if(y<-1) y=3; - redraw = true; - } - - - } - - //Resets screen when finished writing - tft.fillRect(0,0,tft.width(),tft.height(),BGCOLOR); - resetTftDisplay(); - - return mytext; -} - - -#endif //If not STICK_C - void checkReboot() { int countDown; #if defined(STICK_C_PLUS2) diff --git a/src/core/serialcmds.cpp b/src/core/serialcmds.cpp index acb154c0..9404407d 100644 --- a/src/core/serialcmds.cpp +++ b/src/core/serialcmds.cpp @@ -202,21 +202,10 @@ void handleSerialCommands() { } } // endof rf - #if defined(CARDPUTER) //M5StickCs doesn't have speakers.. they have buzzers on pin 02 that only beeps in different frequencies + #if defined(HAS_NS4168_SPKR) //M5StickCs doesn't have speakers.. they have buzzers on pin 02 that only beeps in different frequencies if(cmd_str.startsWith("music_player " ) || cmd_str.startsWith("tts" ) || cmd_str.startsWith("say" ) ) { // TODO: move in audio.cpp module AudioOutputI2S *audioout = new AudioOutputI2S(); // https://github.com/earlephilhower/ESP8266Audio/blob/master/src/AudioOutputI2S.cpp#L32 - #ifdef CARDPUTER - #define BCLK 41 - #define WCLK 43 - #define DOUT 42 - // TODO: other pinouts - #elif define(CORE2) // Core uses buzzer and CoreS3 uses I2C communication (SDA-12, SCL-11 addr 0x36) - #define BCLK 12 - #define WCLK 0 - #define DOUT 2 - #endif - audioout->SetPinout(BCLK, WCLK, DOUT); // bclk, wclk, dout AudioGenerator* generator = NULL; AudioFileSource* source = NULL; @@ -343,6 +332,7 @@ void handleSerialCommands() { axp192.PowerOff(); #elif defined(STICK_C_PLUS2) digitalWrite(4,LOW); + #elif defined(NEW_DEVICE) #else //ESP.deepSleep(0); esp_deep_sleep_start(); // only wake up via hardware reset diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 3bed2779..d9a3db1c 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -243,7 +243,7 @@ NTPClient timeClient(ntpUDP, ntpServer, selectedTimezone, daylightOffset_sec); void setClock() { bool auto_mode=true; - #if defined(STICK_C_PLUS) || defined(STICK_C_PLUS2) + #if defined(HAS_RTC) RTC_TimeTypeDef TimeStruct; cplus_RTC _rtc; _rtc.GetBm8563Time(); @@ -286,7 +286,7 @@ void setClock() { timeClient.begin(); timeClient.update(); localTime = myTZ.toLocal(timeClient.getEpochTime()); - #if !defined(STICK_C_PLUS) && !defined(STICK_C_PLUS2) + #if !defined(HAS_RTC) rtc.setTime(timeClient.getEpochTime()); #endif @@ -387,7 +387,7 @@ void setClock() { loopOptions(options); delay(200); - #if defined(STICK_C_PLUS) || defined(STICK_C_PLUS2) + #if defined(HAS_RTC) TimeStruct.Hours = hr+am; TimeStruct.Minutes = mn; TimeStruct.Seconds = 0; @@ -404,7 +404,7 @@ void setClock() { void runClockLoop() { int tmp=0; - #if defined(STICK_C_PLUS) || defined(STICK_C_PLUS2) + #if defined(HAS_RTC) RTC_TimeTypeDef _time; cplus_RTC _rtc; _rtc.GetBm8563Time(); @@ -417,7 +417,7 @@ void runClockLoop() { for (;;){ if(millis()-tmp>1000) { - #if !defined(STICK_C_PLUS) && !defined(STICK_C_PLUS2) + #if !defined(HAS_RTC) updateTimeStr(rtc.getTimeStruct()); #endif Serial.print("Current time: "); @@ -426,7 +426,7 @@ void runClockLoop() { tft.drawRect(10, 10, tft.width()-16,118, FGCOLOR); tft.setCursor(27, tft.height()/3+5); tft.setTextSize(4); - #if defined(STICK_C_PLUS) || defined(STICK_C_PLUS2) + #if defined(HAS_RTC) _rtc.GetBm8563Time(); _rtc.GetTime(&_time); tft.printf("%02d:%02d:%02d", _time.Hours, _time.Minutes, _time.Seconds); diff --git a/src/main.cpp b/src/main.cpp index e572335c..80ed7a4e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,7 +29,7 @@ bool dimmer = false; char timeStr[10]; time_t localTime; struct tm* timeInfo; -#if defined(STICK_C_PLUS) || defined(STICK_C_PLUS2) +#if defined(HAS_RTC) cplus_RTC _rtc; bool clock_set = true; #else @@ -72,19 +72,23 @@ TFT_eSprite draw = TFT_eSprite(&tft); void setup_gpio() { #if defined(STICK_C_PLUS2) pinMode(UP_BTN, INPUT); // Sets the power btn as an INPUT + pinMode(SEL_BTN, INPUT); + pinMode(DW_BTN, INPUT); + pinMode(4, OUTPUT); // Keeps the Stick alive after take off the USB cable + digitalWrite(4,HIGH); // Keeps the Stick alive after take off the USB cable #elif defined(STICK_C_PLUS) + pinMode(SEL_BTN, INPUT); + pinMode(DW_BTN, INPUT); axp192.begin(); // Start the energy management of AXP192 - #endif - - #ifndef CARDPUTER - pinMode(SEL_BTN, INPUT); - pinMode(DW_BTN, INPUT); - pinMode(4, OUTPUT); // Keeps the Stick alive after take off the USB cable - digitalWrite(4,HIGH); // Keeps the Stick alive after take off the USB cable + #elif defined(CARDPUTER) + Keyboard.begin(); + pinMode(0, INPUT); + pinMode(10, INPUT); // Pin that reads the + #elif defined(NEW_DEVICE) #else - Keyboard.begin(); - pinMode(0, INPUT); - pinMode(10, INPUT); // Pin that reads the + pinMode(UP_BTN, INPUT); // Sets the power btn as an INPUT + pinMode(SEL_BTN, INPUT); + pinMode(DW_BTN, INPUT); #endif #if defined(BACKLIGHT) @@ -301,7 +305,7 @@ void loop() { } if (clock_set) { - #if defined(STICK_C_PLUS) || defined(STICK_C_PLUS2) + #if defined(HAS_RTC) _rtc.GetTime(&_time); setTftDisplay(12, 12, FGCOLOR, 1, BGCOLOR); snprintf(timeStr, sizeof(timeStr), "%02d:%02d", _time.Hours, _time.Minutes); diff --git a/src/modules/ble/ble_common.cpp b/src/modules/ble/ble_common.cpp index 793e683e..14682f03 100644 --- a/src/modules/ble/ble_common.cpp +++ b/src/modules/ble/ble_common.cpp @@ -858,8 +858,7 @@ class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks { if(bt_title.isEmpty()) bt_title = bt_address; if(bt_name.isEmpty()) bt_name=""; // If BT name is empty, set NONAME - options.push_back({bt_title.c_str(), [=]() { ble_info(bt_name, bt_address, bt_signal); }}); - + if(ESP.getFreeHeap()>4096) options.push_back({bt_title.c_str(), [=]() { ble_info(bt_name, bt_address, bt_signal); }}); } }; diff --git a/src/modules/others/bad_usb.cpp b/src/modules/others/bad_usb.cpp index 582b5956..9b3f99ed 100644 --- a/src/modules/others/bad_usb.cpp +++ b/src/modules/others/bad_usb.cpp @@ -1,4 +1,4 @@ -#ifdef CARDPUTER +#ifdef USB_as_HID #include "core/globals.h" #include "core/sd_functions.h" #include "core/main_menu.h" diff --git a/src/modules/others/bad_usb.h b/src/modules/others/bad_usb.h index 28931cb9..296a51f9 100644 --- a/src/modules/others/bad_usb.h +++ b/src/modules/others/bad_usb.h @@ -1,4 +1,4 @@ -#ifdef CARDPUTER +#ifdef USB_as_HID #include #include diff --git a/src/modules/others/led.cpp b/src/modules/others/led.cpp index 0760f1d8..2c8db175 100644 --- a/src/modules/others/led.cpp +++ b/src/modules/others/led.cpp @@ -1,4 +1,4 @@ -#ifdef CARDPUTER +#ifdef HAS_RGB_LED // By @IncursioHack - github.com/IncursioHack #include #include "core/display.h" diff --git a/src/modules/others/led_control.h b/src/modules/others/led_control.h index 75244596..98d285a3 100644 --- a/src/modules/others/led_control.h +++ b/src/modules/others/led_control.h @@ -1,4 +1,4 @@ -#ifdef CARDPUTER +#ifdef HAS_RGB_LED // By IncursioHack @github.com/IncursioHack #include #include diff --git a/src/modules/others/mic.cpp b/src/modules/others/mic.cpp index de6c59a4..79e809bb 100644 --- a/src/modules/others/mic.cpp +++ b/src/modules/others/mic.cpp @@ -13,23 +13,6 @@ * */ -#if defined(STICK_C_PLUS) || defined(STICK_C_PLUS2) || defined(CORE2) - #define PIN_CLK 0 - #define I2S_SCLK_PIN 0 - #define I2S_DATA_PIN 34 - #define PIN_DATA 34 -#elif defined (CARDPUTER) - #define PIN_CLK 43 - #define I2S_SCLK_PIN 43 - #define I2S_DATA_PIN 46 - #define PIN_DATA 46 -#else // to avoid fail when porting to other devices - #define PIN_CLK -1 - #define I2S_SCLK_PIN -1 - #define I2S_DATA_PIN -1 - #define PIN_DATA -1 -#endif - extern const unsigned char ImageData[768]; static SemaphoreHandle_t xSemaphore = NULL; @@ -125,7 +108,7 @@ int rgb(unsigned char r, unsigned char g, unsigned char b) { return result; } -void mic_test_one_task() +void mic_test_one_task(int s_width, int s_height) { tft.fillScreen(TFT_BLACK); @@ -142,8 +125,6 @@ void mic_test_one_task() uint16_t count_x = 0, count_y = 0; uint16_t colorPos; - TFT_eSprite spr_main = TFT_eSprite(&tft); - // Delay due to M5 select press to open mic spectrum delay(300); @@ -169,15 +150,15 @@ void mic_test_one_task() real_fft_plan->output[2 * count_n] + real_fft_plan->output[2 * count_n + 1] * real_fft_plan->output[2 * count_n + 1]); - if ((count_n - 1) < 128) { + if ((count_n - 1) < s_height) { data = (data > 2000) ? 2000 : data; ydata = map(data, 0, 2000, 0, 255); - _new_fft_dis_buff[posData][128 - count_n] = ydata; + _new_fft_dis_buff[posData][s_height - count_n] = ydata; } } posData++; - if (posData >= 241) { + if (posData >= (s_width+1)) { posData = 0; } fft_destroy(real_fft_plan); @@ -186,18 +167,18 @@ void mic_test_one_task() } // Display - for (count_y = 0; count_y < 128; count_y++) + for (count_y = 0; count_y < s_height; count_y++) { - for (count_x = 0; count_x < 240; count_x++) + for (count_x = 0; count_x < s_width; count_x++) { - if ((count_x + (posData % 240)) > 240) + if ((count_x + (posData % s_width)) > s_width) { colorPos = - _new_fft_dis_buff[count_x + (posData % 240) - 240][count_y]; + _new_fft_dis_buff[count_x + (posData % s_width) - s_width][count_y]; } else { - colorPos = _new_fft_dis_buff[count_x + (posData % 240)][count_y]; + colorPos = _new_fft_dis_buff[count_x + (posData % s_width)][count_y]; } tft.drawPixel(count_x, count_y + 4, rgb(ImageData[colorPos * 3 + 0], @@ -205,7 +186,6 @@ void mic_test_one_task() ImageData[colorPos * 3 + 2])); } } - spr_main.pushSprite(0,0); wakeUpScreen(); } } @@ -269,7 +249,9 @@ void mic_test() // Malloc way _new_i2s_readraw_buff = NULL; - _new_i2s_readraw_buff = (int8_t *)malloc(2048 * sizeof(int8_t)); + if(psramFound()) _new_i2s_readraw_buff = (int8_t *)ps_malloc(2048 * sizeof(int8_t)); + else _new_i2s_readraw_buff = (int8_t *)malloc(2048 * sizeof(int8_t)); + if (_new_i2s_readraw_buff == NULL) { printf("Buffer readraw alloc failed\n"); @@ -279,8 +261,11 @@ void mic_test() // [241][128] int a = 241; int b = 128; + int s_width=0; + int s_height=0; _new_fft_dis_buff = NULL; - _new_fft_dis_buff = (uint8_t **)malloc(a * sizeof(uint8_t *)); + if(psramFound()) _new_fft_dis_buff = (uint8_t **)ps_malloc(a * sizeof(uint8_t *)); + else _new_fft_dis_buff = (uint8_t **)malloc(a * sizeof(uint8_t *)); if (_new_fft_dis_buff == NULL) { @@ -291,13 +276,17 @@ void mic_test() for (int i = 0; i < a; i++) { _new_fft_dis_buff[i] = NULL; - _new_fft_dis_buff[i] = (uint8_t *)malloc(b * sizeof(uint8_t)); + if(psramFound()) _new_fft_dis_buff[i] = (uint8_t *)ps_malloc(b * sizeof(uint8_t)); + else _new_fft_dis_buff[i] = (uint8_t *)malloc(b * sizeof(uint8_t)); if (_new_fft_dis_buff[i] == NULL) { printf("Buffer fftdis:%d alloc failed\n", i); - return; + break;; } + s_width=i; } + s_height=b; + // Memset if (is_first_time) @@ -311,7 +300,7 @@ void mic_test() } } - mic_test_one_task(); + mic_test_one_task(s_width, s_height); //new_mic_test(); // Free way diff --git a/src/modules/others/mic.h b/src/modules/others/mic.h index d986c2d8..d7980c4b 100644 --- a/src/modules/others/mic.h +++ b/src/modules/others/mic.h @@ -17,7 +17,7 @@ /* Mic */ void mic_init(); void mic_test(); -void mic_test_one_task(); +void mic_test_one_task(int s_width, int s_height); void DisplayMicro(); diff --git a/src/modules/others/tururururu.cpp b/src/modules/others/tururururu.cpp index a111c502..d1ba322d 100644 --- a/src/modules/others/tururururu.cpp +++ b/src/modules/others/tururururu.cpp @@ -65,11 +65,7 @@ void drawFish(Fish &f) { // Função para mover o tubarão void moveShark() { - #if defined(STICK_C_PLUS) || defined(STICK_C_PLUS2) // checkEscPress is the same of checkPrevPress in these devices - if (checkSelPress()) - #else if (checkPrevPress()) - #endif { sharkY -= 2; // Move para cima } diff --git a/src/modules/others/webInterface.cpp b/src/modules/others/webInterface.cpp index 36c6586c..e0f124dd 100644 --- a/src/modules/others/webInterface.cpp +++ b/src/modules/others/webInterface.cpp @@ -429,11 +429,9 @@ void startWebUi(bool mode_ap) { // configure web server Serial.println("Configuring Webserver ..."); -#ifdef STICK_C_PLUS2 - server=(WebServer*)ps_malloc(sizeof(WebServer)); -#else - server=(WebServer*)malloc(sizeof(WebServer)); -#endif + if(psramFound()) server=(WebServer*)ps_malloc(sizeof(WebServer)); + else server=(WebServer*)malloc(sizeof(WebServer)); + new (server) WebServer(config.webserverporthttp); configureWebServer(); @@ -447,13 +445,9 @@ void startWebUi(bool mode_ap) { else txt = WiFi.softAPIP().toString(); tft.setTextColor(FGCOLOR); -#ifndef STICK_C tft.drawCentreString("http://bruce.local", tft.width()/2,25,1); setTftDisplay(7,47); -#else - tft.drawCentreString("http://bruce.local", tft.width()/2,17,1); - setTftDisplay(7,26); -#endif + tft.setTextSize(FM); tft.print("IP: "); tft.println(txt); tft.setCursor(7,tft.getCursorY()); diff --git a/src/modules/wifi/dpwo.cpp b/src/modules/wifi/dpwo.cpp index 8faa39d4..29f451b1 100644 --- a/src/modules/wifi/dpwo.cpp +++ b/src/modules/wifi/dpwo.cpp @@ -11,6 +11,7 @@ #define SD_CREDS_PATH "/dpwo_creds.txt" #include "core/globals.h" +#include "core/sd_functions.h" #include "dpwo.h" int ap_scanned = 0; @@ -50,10 +51,20 @@ void net_ap(int i) { } Serial.println("\nWiFi Connected"); WiFi.disconnect(); - #if defined(SDCARD) - appendToFile(SD, SD_CREDS_PATH, String(WiFi.SSID(i) + ":" + bssid_ready).c_str()); + + FS *Fs; + File file; + if(setupSdCard()) Fs = &SD; + else { + if(checkLittleFsSize()) Fs = &LittleFS; + else goto PrintOnly; + } + file = (*Fs).open(SD_CREDS_PATH,FILE_APPEND,true); + file.println(String(WiFi.SSID(i) + ":" + bssid_ready).c_str()); Serial.println("\nWrote creds to SD"); - #endif + file.close(); + + PrintOnly: tft.setTextSize(1); tft.setTextColor(FGCOLOR-0x2000); tft.println(String(WiFi.SSID(i) + ":" + bssid_ready).c_str()); @@ -77,10 +88,20 @@ void claro_ap(int i) { } Serial.println("\nWiFi Connected"); WiFi.disconnect(); - #if defined(SDCARD) - appendToFile(SD, SD_CREDS_PATH, String(WiFi.SSID(i) + ":" + bssid_ready).c_str()); - Serial.println("\nWrote creds to SD"); - #endif + + FS *Fs; + File file; + if(setupSdCard()) Fs = &SD; + else { + if(checkLittleFsSize()) Fs = &LittleFS; + else goto PrintOnly; + } + file = (*Fs).open(SD_CREDS_PATH,FILE_APPEND,true); + file.println(String(WiFi.SSID(i) + ":" + bssid_ready).c_str()); + Serial.println("\nWrote creds to SD"); + file.close(); + + PrintOnly: tft.setTextSize(1); tft.setTextColor(FGCOLOR-0x2000); tft.println(String(WiFi.SSID(i) + ":" + bssid_ready).c_str()); diff --git a/src/modules/wifi/evil_portal.cpp b/src/modules/wifi/evil_portal.cpp index e7793466..fc1914a4 100644 --- a/src/modules/wifi/evil_portal.cpp +++ b/src/modules/wifi/evil_portal.cpp @@ -88,11 +88,8 @@ void startEvilPortal(String tssid, uint8_t channel, bool deauth) { tmp=millis(); while(millis() - tmp < 3000) yield(); - #ifdef STICK_C_PLUS2 - ep=(WebServer*)ps_malloc(sizeof(WebServer)); - #else - ep=(WebServer*)malloc(sizeof(WebServer)); - #endif + if(psramFound()) ep=(WebServer*)ps_malloc(sizeof(WebServer)); + else ep=(WebServer*)malloc(sizeof(WebServer)); new (ep) WebServer(80); ep->on("/", [](){ diff --git a/src/modules/wifi/scan_hosts.cpp b/src/modules/wifi/scan_hosts.cpp index eb72350e..119b80a6 100644 --- a/src/modules/wifi/scan_hosts.cpp +++ b/src/modules/wifi/scan_hosts.cpp @@ -145,7 +145,7 @@ void afterScanOptions(IPAddress ip) { std::vector>> option; option = { {"Scan Ports", [=](){ scanPorts(ip); }}, - #ifndef STICK_C_PLUS + #ifndef LITE_VERSION {"SSH Connect", [=](){ ssh_setup(ip.toString()); }}, #endif }; From 5948c651d3dff8e555be1b155ab8432dac687ba3 Mon Sep 17 00:00:00 2001 From: Pirata <104320209+bmorcelli@users.noreply.github.com> Date: Fri, 2 Aug 2024 18:06:33 +0000 Subject: [PATCH 3/3] Try to fix BLE restarts from BLE Scan Organized the files to help on porting process to other devices --- custom_4Mb_full.csv | 4 +- platformio.ini | 118 +++++++++++++++++++++++++++++++-- src/core/display.cpp | 2 +- src/core/mykeyboard.cpp | 4 +- src/core/sd_functions.cpp | 17 +++-- src/core/serialcmds.cpp | 2 +- src/modules/ble/ble_common.cpp | 4 ++ 7 files changed, 135 insertions(+), 16 deletions(-) diff --git a/custom_4Mb_full.csv b/custom_4Mb_full.csv index 88cb9246..89ae3751 100644 --- a/custom_4Mb_full.csv +++ b/custom_4Mb_full.csv @@ -1,4 +1,4 @@ # Name, Type, SubType, Offset, Size, Flags nvs, data, nvs, 0x9000, 0x6000, -app0, app, ota_0, 0x10000, 0x260000, -spiffs, data, spiffs, 0x270000,0x190000, \ No newline at end of file +app0, app, ota_0, 0x10000, 0x2F0000, +spiffs, data, spiffs, 0x300000,0x400000, \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 240bcf24..8a29b93c 100644 --- a/platformio.ini +++ b/platformio.ini @@ -208,6 +208,7 @@ build_flags = lib_deps = ${common.lib_deps} + [env:m5stack-cardputer] platform = espressif32 board = m5stack-stamps3 @@ -247,7 +248,18 @@ build_flags = -DBTN_ALIAS='"Ok"' -DBTN_PIN=0 -DBTN_ACT=LOw - + + ;Font sizes, depending on device + -DFP=1 + -DFM=2 + -DFG=3 + + ;Infrared Led default pin and state + -DLED=44 + -DLED_ON=HIGH + -DLED_OFF=LOW + + ; Screen Setup -DHAS_SCREEN=1 -DROTATION=1 -DWIDTH=240 @@ -255,16 +267,112 @@ build_flags = -DBACKLIGHT=38 -DMINBRIGHT=160 -DMAX_MENU_SIZE=5 + + ; TFT_eSPI Setup + -DUSER_SETUP_LOADED=1 + -DUSE_HSPI_PORT=1 + -DST7789_2_DRIVER=1 + -DTFT_RGB_ORDER=1 + -DTFT_WIDTH=135 + -DTFT_HEIGHT=240 + -DTFT_BACKLIGHT_ON=1 + -DTFT_BL=38 + -DTFT_RST=33 + -DTFT_DC=34 + -DTFT_MOSI=35 + -DTFT_SCLK=36 + -DTFT_CS=37 + -DTOUCH_CS=-1 + -DSMOOTH_FONT=1 + -DSPI_FREQUENCY=20000000 + -DSPI_READ_FREQUENCY=20000000 + -DSPI_TOUCH_FREQUENCY=2500000 - -DFP=1 - -DFM=2 - -DFG=3 + ;SD Card Setup pins + -DSDCARD_CS=12 + -DSDCARD_SCK=40 + -DSDCARD_MISO=39 + -DSDCARD_MOSI=14 + + ;Default I2C port + -DGROVE_SDA=2 + -DGROVE_SCL=1 + +lib_deps = + ${common.lib_deps} + xylopyrographer/LiteLED@^1.2.0 + + +#New device model +[env:NewDeviceModel] +platform = espressif32 +board = m5stack-stamps3 +framework = arduino +board_build.partitions = custom_8Mb.csv +build_flags = + ${common.build_flags} + -DCORE_DEBUG_LEVEL=5 + -DARDUINO_USB_CDC_ON_BOOT=1 + + -DNEW_DEVICE=1 ; key for new device, + ; mykeyboard.cpp: need map buttons an/or touchscreen and battery status value, + ; settings.cpp: need map brighness control + ; main.cpp: need set startup + ; serialcmds.cpp: need set power off command + + ;Features Enabled + ;-DLITE_VERSION=1 ; limits some features to save space for M5Launcher Compatibility + ;Microphone + ;-DMIC_SPM1423=1 ; uncomment to enable Applicable for SPM1423 device + -DPIN_CLK=43 + -DI2S_SCLK_PIN=43 + -DI2S_DATA_PIN=46 + -DPIN_DATA=46 + + ;RGB LED runned by xylopyrographer/LiteLED@^1.2.0 library + ;-DHAS_RGB_LED=1 ; uncomment to enable + -DRGB_LED=21 + + ;Have RTC Chip + ;-DHAS_RTC=1 + + ;Speaker to run music, compatible with NS4168 + ;-DHAS_NS4168_SPKR=1 ; uncomment to enable + -DBCLK=41 + -DWCLK=43 + -DDOUT=42 + + ;Can run USB as HID + ;-DUSB_as_HID=1 ; uncomment to enable + + ;Battery ADC read pin + ;-DBAT_PIN=10 + + ;Buttons configuration + -DHAS_BTN=0 + -DBTN_ALIAS='"Ok"' + -DBTN_PIN=0 + -DBTN_ACT=LOw ;Infrared Led default pin and state -DLED=44 -DLED_ON=HIGH -DLED_OFF=LOW + + ;Font sizes, depending on device + -DFP=1 + -DFM=2 + -DFG=3 + ; Screen Setup + -DHAS_SCREEN=1 + -DROTATION=1 + -DWIDTH=240 + -DHEIGHT=135 + -DBACKLIGHT=38 + -DMINBRIGHT=160 + -DMAX_MENU_SIZE=5 ;HEIGHT/25 + ; TFT_eSPI Setup -DUSER_SETUP_LOADED=1 -DUSE_HSPI_PORT=1 @@ -297,4 +405,4 @@ build_flags = lib_deps = ${common.lib_deps} - xylopyrographer/LiteLED@^1.2.0 + xylopyrographer/LiteLED@^1.2.0 \ No newline at end of file diff --git a/src/core/display.cpp b/src/core/display.cpp index eb54cc9e..b3f96d1f 100644 --- a/src/core/display.cpp +++ b/src/core/display.cpp @@ -86,7 +86,7 @@ void loopOptions(const std::vector> analogWrite(BACKLIGHT, bl); #elif defined(STICK_C_PLUS) axp192.ScreenBreath(100*(4 - index) * 0.25); // 4 is the number of options - #elif defined(NEW_DEVICE) + //#elif defined(NEW_DEVICE) #else diff --git a/src/core/mykeyboard.cpp b/src/core/mykeyboard.cpp index f9c4a84b..561e49c8 100644 --- a/src/core/mykeyboard.cpp +++ b/src/core/mykeyboard.cpp @@ -53,7 +53,7 @@ bool checkSelPress(){ #if defined (CARDPUTER) Keyboard.update(); if(Keyboard.isKeyPressed(KEY_ENTER) || digitalRead(0)==LOW) - #elif defined(NEW_DEVICE) + //#elif defined(NEW_DEVICE) #else if(digitalRead(SEL_BTN)==LOW) @@ -77,7 +77,7 @@ bool checkEscPress(){ #elif defined (CARDPUTER) Keyboard.update(); if(Keyboard.isKeyPressed('`')) - #elif defined(NEW_DEVICE) + //#elif defined(NEW_DEVICE) #else if(digitalRead(UP_BTN)==LOW) diff --git a/src/core/sd_functions.cpp b/src/core/sd_functions.cpp index 92c4a0f3..6c9d35f8 100644 --- a/src/core/sd_functions.cpp +++ b/src/core/sd_functions.cpp @@ -121,24 +121,31 @@ bool copyToFs(FS from, FS to, String path) { uint8_t buffer[bufferSize]; bool result; - if (!SD.begin()) { result = false; displayError("Error 1"); } - if(!LittleFS.begin()) { result = false; displayError("Error 2"); } + if (!SD.begin()) { result = false; Serial.println("Error 1"); } + if(!LittleFS.begin()) { result = false; Serial.println("Error 2"); } File source = from.open(path, FILE_READ); if (!source) { - displayError("Error 3"); + Serial.println("Error 3"); result = false; } path = path.substring(path.lastIndexOf('/')); if(!path.startsWith("/")) path = "/" + path; File dest = to.open(path, FILE_WRITE); if (!dest) { - displayError("Error 4"); + Serial.println("Error 4"); result = false; } size_t bytesRead; int tot=source.size(); int prog=0; + + if(&to==&LittleFS && (LittleFS.totalBytes() - LittleFS.usedBytes()) < tot) { + Serial.println("Not enaugh space on LittleFS for this file"); + displayError("Not enaugh space"); + delay(3000); + return false; + } //tft.drawRect(5,HEIGHT-12, (WIDTH-10), 9, FGCOLOR); while ((bytesRead = source.read(buffer, bufferSize)) > 0) { if (dest.write(buffer, bytesRead) != bytesRead) { @@ -146,7 +153,7 @@ bool copyToFs(FS from, FS to, String path) { source.close(); dest.close(); result = false; - displayError("Error 5"); + Serial.println("Error 5"); } else { prog+=bytesRead; float rad = 360*prog/tot; diff --git a/src/core/serialcmds.cpp b/src/core/serialcmds.cpp index 9404407d..3fc47da8 100644 --- a/src/core/serialcmds.cpp +++ b/src/core/serialcmds.cpp @@ -332,7 +332,7 @@ void handleSerialCommands() { axp192.PowerOff(); #elif defined(STICK_C_PLUS2) digitalWrite(4,LOW); - #elif defined(NEW_DEVICE) + //#elif defined(NEW_DEVICE) #else //ESP.deepSleep(0); esp_deep_sleep_start(); // only wake up via hardware reset diff --git a/src/modules/ble/ble_common.cpp b/src/modules/ble/ble_common.cpp index 14682f03..1fc3f9c2 100644 --- a/src/modules/ble/ble_common.cpp +++ b/src/modules/ble/ble_common.cpp @@ -859,6 +859,10 @@ class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks { if(bt_name.isEmpty()) bt_name=""; // If BT name is empty, set NONAME if(ESP.getFreeHeap()>4096) options.push_back({bt_title.c_str(), [=]() { ble_info(bt_name, bt_address, bt_signal); }}); + else { + Serial.println("Memory low, stopping BLE scan..."); + pBLEScan->stop(); + } } };