From 9f7453668861915481ffc10fff8f68109a1e2418 Mon Sep 17 00:00:00 2001 From: Pirata Date: Sun, 18 Aug 2024 17:30:29 -0300 Subject: [PATCH 1/5] CC1101 for Cardputer and BLE Spam fix CC1101 was finally ported to Cardputer using a SD Card Sniffer BLE Spam fixed, changing the original lib to NimBLE, but Core2 and Core devices are not compiling due to IRAM overflow. It will be solved when change the port from M5Unified to Core2 and M5Stack (Core) libraries, that are lighter than M5Unified/M5GFX. --- custom_4Mb_full.csv | 2 +- platformio.ini | 19 ++--- src/core/display.cpp | 8 --- src/core/display.h | 4 +- src/core/globals.h | 4 +- src/core/main_menu.cpp | 8 ++- src/core/sd_functions.cpp | 4 +- src/core/sd_functions.h | 2 +- src/core/settings.cpp | 5 +- src/main.cpp | 31 +++++---- src/modules/ble/ble_common.cpp | 56 +++++++-------- src/modules/ble/ble_common.h | 18 +++-- src/modules/ble/ble_spam.cpp | 13 ++-- src/modules/ble/ble_spam.h | 3 +- src/modules/rf/rf.cpp | 124 ++++++++++++++++++--------------- src/modules/rf/rf.h | 2 +- 16 files changed, 160 insertions(+), 143 deletions(-) diff --git a/custom_4Mb_full.csv b/custom_4Mb_full.csv index 89ae3751..509db9d6 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, 0x2F0000, -spiffs, data, spiffs, 0x300000,0x400000, \ No newline at end of file +spiffs, data, spiffs, 0x300000,0x100000, \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 4658c219..52cb85dc 100644 --- a/platformio.ini +++ b/platformio.ini @@ -31,6 +31,8 @@ build_flags = -DLH=8 -DLW=6 -DCONFIG_FILE='"/config.conf"' + -w + lib_deps = WireGuard-ESP32 IRremoteESP8266 @@ -49,7 +51,8 @@ lib_deps = TinyGPSPlus tinyu-zhao/FFT@^0.0.1 ;lsatan/SmartRC-CC1101-Driver-Lib@^2.5.7 - https://github.com/bmorcelli/SmartRC-CC1101-Driver-Lib + SmartRC-CC1101-Driver-Lib=https://github.com/bmorcelli/SmartRC-CC1101-Driver-Lib/archive/refs/heads/Bruce.zip + h2zero/NimBLE-Arduino@^1.4.0 [env:m5stack-cplus2] platform = espressif32 @@ -62,9 +65,9 @@ board_upload.maximum_size = 8388608 build_flags = ${common.build_flags} -DCORE_DEBUG_LEVEL=5 - -DBOARD_HAS_PSRAM - -mfix-esp32-psram-cache-issue - -mfix-esp32-psram-cache-strategy=memw + ;-DBOARD_HAS_PSRAM + ;-mfix-esp32-psram-cache-issue + ;-mfix-esp32-psram-cache-strategy=memw -DSTICK_C_PLUS2=1 @@ -318,7 +321,7 @@ build_flags = -DRF_TX_PINS='{ {"M5 RF433T", GROVE_SDA}, {"Groove W", GROVE_SCL}, {"GROVE Y", GROVE_SDA}}' -DRF_RX_PINS='{ {"M5 RF433R", GROVE_SCL}, {"Groove W", GROVE_SCL}, {"GROVE Y", GROVE_SDA}}' ; connection pins using microSD sniffer module https://www.sparkfun.com/products/9419 https://docs.m5stack.com/en/core/Cardputer - ;-DUSE_CC1101_VIA_SPI + -DUSE_CC1101_VIA_SPI -DCC1101_GDO0_PIN=GROVE_SDA -DCC1101_SS_PIN=GROVE_SCL ; chip select -DCC1101_MOSI_PIN=14 @@ -382,7 +385,7 @@ build_flags = -DCORE_DEBUG_LEVEL=5 -DM5STACK=1 ;key for new device, - ;mykeyboard.cpp: need map buttons an/or touchscreen, + -DCORE=1 ;mykeyboard.cpp: need map buttons an/or touchscreen, ;display.cpp: need map battery status value, ;settings.cpp: need map brighness control ;main.cpp: need set startup @@ -499,7 +502,7 @@ build_flags = -DCORE_DEBUG_LEVEL=5 -DM5STACK=1 ;key for new device, - ;mykeyboard.cpp: need map buttons an/or touchscreen, + -DCORE=1 ;mykeyboard.cpp: need map buttons an/or touchscreen, ;display.cpp: need map battery status value, ;settings.cpp: need map brighness control ;main.cpp: need set startup @@ -613,7 +616,7 @@ build_flags = -DCORE_DEBUG_LEVEL=5 -DM5STACK=1 ;key for new device, - ;mykeyboard.cpp: need map buttons an/or touchscreen, + -DCORE=1 ;mykeyboard.cpp: need map buttons an/or touchscreen, ;display.cpp: need map battery status value, ;settings.cpp: need map brighness control ;main.cpp: need set startup diff --git a/src/core/display.cpp b/src/core/display.cpp index 9ac8b54d..fc1a2410 100644 --- a/src/core/display.cpp +++ b/src/core/display.cpp @@ -61,14 +61,6 @@ void setTftDisplay(int x, int y, uint16_t fc, int size, uint16_t bg) { tft.setTextColor(fc,bg); } -/*************************************************************************************** -** Function name: BootScreen -** Description: Start Display functions and display bootscreen -***************************************************************************************/ -void initDisplay(int i) { - tft.drawXBitmap(1,1,bits, bits_width, bits_height,TFT_BLACK,FGCOLOR+i); -} - /*************************************************************************************** ** Function name: displayRedStripe ** Description: Display Red Stripe with information diff --git a/src/core/display.h b/src/core/display.h index 6dc1417e..4bb4e3fe 100644 --- a/src/core/display.h +++ b/src/core/display.h @@ -7,8 +7,6 @@ #define PADX 10 -void initDisplay(int i = 0); // Início da função e mostra bootscreen - //Funções para economizar linhas nas outras funções void resetTftDisplay(int x = 0, int y = 0, uint16_t fc = FGCOLOR, int size = FM, uint16_t bg = BGCOLOR, uint16_t screen = BGCOLOR); void setTftDisplay(int x = 0, int y = 0, uint16_t fc = tft.textcolor, int size = tft.textsize, uint16_t bg = tft.textbgcolor); @@ -94,6 +92,7 @@ void TouchFooter(uint16_t color = FGCOLOR); void MegaFooter(uint16_t color = FGCOLOR); +#if !defined(LITE_VERSION) #define bruce_small_width 60 #define bruce_small_height 34 PROGMEM const unsigned char bruce_small_bits[] = { @@ -461,3 +460,4 @@ PROGMEM const unsigned char bits[] = { #endif +#endif \ No newline at end of file diff --git a/src/core/globals.h b/src/core/globals.h index 6e896048..2fd686c9 100644 --- a/src/core/globals.h +++ b/src/core/globals.h @@ -9,7 +9,7 @@ extern char16_t FGCOLOR; #include #include #include -//#include +#include #include #include #include @@ -54,7 +54,7 @@ extern char16_t FGCOLOR; #endif extern char timeStr[10]; - +extern SPIClass sdcardSPI; extern bool clock_set; extern time_t localTime; extern struct tm* timeInfo; diff --git a/src/core/main_menu.cpp b/src/core/main_menu.cpp index cabddaf1..7b41f106 100644 --- a/src/core/main_menu.cpp +++ b/src/core/main_menu.cpp @@ -74,14 +74,20 @@ void wifiOptions() { **********************************************************************/ void bleOptions() { options = { +#if !defined(CORE) + #if !defined(LITE_VERSION) {"BLE Beacon", [=]() { ble_test(); }}, {"BLE Scan", [=]() { ble_scan(); }}, + #endif {"AppleJuice", [=]() { aj_adv(0); }}, {"SwiftPair", [=]() { aj_adv(1); }}, {"Samsung Spam", [=]() { aj_adv(2); }}, {"SourApple", [=]() { aj_adv(3); }}, {"Android Spam", [=]() { aj_adv(4); }}, {"BT Maelstrom", [=]() { aj_adv(5); }}, +#else + {"In Development", [=]() { backToMenu(); }}, +#endif {"Main Menu", [=]() { backToMenu(); }}, }; delay(200); @@ -300,7 +306,7 @@ void drawMainMenu(int index) { tft.setTextSize(FM); tft.fillRect(10,30+80+(HEIGHT-134)/2, WIDTH-20,LH*FM, BGCOLOR); - tft.drawCentreString(texts[index],WIDTH/2, 30+80+(HEIGHT-134)/2, SMOOTH_FONT); + tft.drawCentreString(texts[index],WIDTH/2, 30+80+(HEIGHT-134)/2, 1); tft.setTextSize(FG); tft.drawChar('<',10,HEIGHT/2+10); tft.drawChar('>',WIDTH-(LW*FG+10),HEIGHT/2+10); diff --git a/src/core/sd_functions.cpp b/src/core/sd_functions.cpp index 3cb0fa63..c87919ae 100644 --- a/src/core/sd_functions.cpp +++ b/src/core/sd_functions.cpp @@ -15,7 +15,7 @@ struct FilePage { }; -SPIClass sdcardSPI; +//SPIClass sdcardSPI; String fileToCopy; String fileList[MAXFILES][3]; FilePage filePages[100]; // Maximum of 100 pages @@ -134,7 +134,7 @@ bool renameFile(FS fs, String path, String filename) { ***************************************************************************************/ bool copyToFs(FS from, FS to, String path) { // Tamanho do buffer para leitura/escrita - const size_t bufferSize = 2048*2; // Ajuste conforme necessário para otimizar a performance + const size_t bufferSize = 1024; // Ajuste conforme necessário para otimizar a performance uint8_t buffer[bufferSize]; bool result; diff --git a/src/core/sd_functions.h b/src/core/sd_functions.h index 695e8eb8..14bd0e85 100644 --- a/src/core/sd_functions.h +++ b/src/core/sd_functions.h @@ -5,7 +5,7 @@ -extern SPIClass sdcardSPI; +//extern SPIClass sdcardSPI; bool setupSdCard(); diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 5a9c243e..87e00c28 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -742,7 +742,7 @@ void getConfigs() { log_i("Brightness: %d", bright); setBrightness(bright); - if(dimmerSet<10) dimmerSet=10; + if(dimmerSet<0) dimmerSet=10; file.close(); if(count>0) saveConfigs(); @@ -762,7 +762,8 @@ void getConfigs() { //If something changed, saves the changes on EEPROM. if(count>0) { if(!EEPROM.commit()) log_i("fail to write EEPROM"); // Store data to EEPROM - } else log_i("Wrote new conf to EEPROM"); + else log_i("Wrote new conf to EEPROM"); + } EEPROM.end(); log_i("Using config.conf setup file"); } else { diff --git a/src/main.cpp b/src/main.cpp index dd57a96b..ac8d8c8a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,6 +7,8 @@ #include #include "esp32-hal-psram.h" + +SPIClass sdcardSPI; // Public Globals Variables unsigned long previousMillis = millis(); int prog_handler; // 0 - Flash, 1 - LittleFS, 3 - Download @@ -113,7 +115,7 @@ void setup_gpio() { #if defined(BACKLIGHT) pinMode(BACKLIGHT, OUTPUT); #endif - initCC1101once(); // Sets GPIO in the CC1101 lib + initCC1101once(&sdcardSPI); // Sets GPIO in the CC1101 lib } @@ -151,6 +153,7 @@ void boot_screen() { int i = millis(); char16_t bgcolor = BGCOLOR; while(millis()2000) && (millis()-i)<2200) tft.fillRect(0,45,WIDTH,HEIGHT-45,BGCOLOR); if((millis()-i>2200) && (millis()-i)<2700) tft.drawRect(2*WIDTH/3,HEIGHT/2,2,2,FGCOLOR); if((millis()-i>2700) && (millis()-i)<2900) tft.fillRect(0,45,WIDTH,HEIGHT-45,BGCOLOR); @@ -163,7 +166,7 @@ void boot_screen() { if((millis()-i>3400) && (millis()-i)<3600) tft.fillRect(0,0,WIDTH,HEIGHT,BGCOLOR); if((millis()-i>3600)) tft.drawXBitmap((WIDTH-238)/2,(HEIGHT-133)/2,bits, bits_width, bits_height,TFT_BLACK,FGCOLOR); #endif - + #endif if(checkAnyKeyPress()) // If any key or M5 key is pressed, it'll jump the boot screen { tft.fillScreen(TFT_BLACK); @@ -172,17 +175,19 @@ void boot_screen() { } } -#if defined(BUZZ_PIN) - // Bip M5 just because it can. Does not bip if splashscreen is bypassed - _tone(5000, 50); - delay(200); - _tone(5000, 50); -/* 2fix: menu infinite loop */ -#elif defined(HAS_NS4168_SPKR) - // play a boot sound - if(SD.exists("/boot.wav")) playAudioFile(&SD, "/boot.wav"); - else if(LittleFS.exists("/boot.wav")) playAudioFile(&LittleFS, "/boot.wav"); - setup_gpio(); // temp fix for menu inf. loop +#if !defined(LITE_VERSION) + #if defined(BUZZ_PIN) + // Bip M5 just because it can. Does not bip if splashscreen is bypassed + _tone(5000, 50); + delay(200); + _tone(5000, 50); + /* 2fix: menu infinite loop */ + #elif defined(HAS_NS4168_SPKR) + // play a boot sound + if(SD.exists("/boot.wav")) playAudioFile(&SD, "/boot.wav"); + else if(LittleFS.exists("/boot.wav")) playAudioFile(&LittleFS, "/boot.wav"); + setup_gpio(); // temp fix for menu inf. loop + #endif #endif } diff --git a/src/modules/ble/ble_common.cpp b/src/modules/ble/ble_common.cpp index a7295ecb..346c8d99 100644 --- a/src/modules/ble/ble_common.cpp +++ b/src/modules/ble/ble_common.cpp @@ -31,14 +31,12 @@ class MyServerCallbacks : public BLEServerCallbacks } }; -// data = new uint8_t[128]; - class MyCallbacks : public BLECharacteristicCallbacks { - uint8_t *data = new uint8_t[128]; - void onWrite(BLECharacteristic *pCharacteristic) + NimBLEAttValue data; + void onWrite(NimBLECharacteristic *pCharacteristic) { - data = pCharacteristic->getData(); + data = pCharacteristic->getValue(); } }; @@ -67,17 +65,17 @@ void ble_info(String name, String address, String signal) } } -class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks { - void onResult(BLEAdvertisedDevice advertisedDevice) { +class AdvertisedDeviceCallbacks : public NimBLEAdvertisedDeviceCallbacks { + void onResult(NimBLEAdvertisedDevice* advertisedDevice) { String bt_title; String bt_name; String bt_address; String bt_signal; - bt_name = advertisedDevice.getName().c_str(); - bt_title = advertisedDevice.getName().c_str(); - bt_address = advertisedDevice.getAddress().toString().c_str(); - bt_signal = String(advertisedDevice.getRSSI()); + bt_name = advertisedDevice->getName().c_str(); + bt_title = advertisedDevice->getName().c_str(); + bt_address = advertisedDevice->getAddress().toString().c_str(); + bt_signal = String(advertisedDevice->getRSSI()); //Serial.println("\n\nAddress - " + bt_address + "Name-"+ bt_name +"\n\n"); if(bt_title.isEmpty()) bt_title = bt_address; if(bt_name.isEmpty()) bt_name=""; @@ -94,7 +92,7 @@ void ble_scan_setup() { BLEDevice::init(""); pBLEScan = BLEDevice::getScan(); - pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks()); + pBLEScan->setAdvertisedDeviceCallbacks(new AdvertisedDeviceCallbacks()); // Active scan uses more power, but get results faster pBLEScan->setActiveScan(true); pBLEScan->setInterval(SCAN_INT); @@ -137,11 +135,11 @@ bool initBLEServer() pServer->setCallbacks(new MyServerCallbacks()); pService = pServer->createService(SERVICE_UUID); pTxCharacteristic = pService->createCharacteristic( - CHARACTERISTIC_RX_UUID, BLECharacteristic::PROPERTY_NOTIFY); + CHARACTERISTIC_RX_UUID, NIMBLE_PROPERTY::NOTIFY); - pTxCharacteristic->addDescriptor(new BLE2902()); + pTxCharacteristic->addDescriptor(new NimBLE2904()); BLECharacteristic *pRxCharacteristic = pService->createCharacteristic( - CHARACTERISTIC_TX_UUID, BLECharacteristic::PROPERTY_WRITE); + CHARACTERISTIC_TX_UUID, NIMBLE_PROPERTY::WRITE); pRxCharacteristic->setCallbacks(new MyCallbacks()); return true; @@ -150,6 +148,9 @@ bool initBLEServer() void disPlayBLESend() { uint8_t senddata[2] = {0}; + tft.fillScreen(TFT_BLACK); + drawMainBorder(); // Moved up to avoid drawing screen issues + tft.setTextSize(1); pService->start(); pServer->getAdvertising()->start(); @@ -157,10 +158,7 @@ void disPlayBLESend() uint64_t chipid = ESP.getEfuseMac(); String blename = "Bruce-" + String((uint8_t)(chipid >> 32), HEX); - tft.setTextSize(1); - tft.fillRect(0, 0, 240, 135, TFT_BLACK); BLEConnected=true; - drawMainBorder(); bool wasConnected = false; bool first_run = true; @@ -170,31 +168,31 @@ void disPlayBLESend() { if (!wasConnected) { tft.fillRect(10, 26, WIDTH-20, HEIGHT-36, TFT_BLACK); - drawBLE_beacon(180, 40, TFT_BLUE); - tft.setTextColor(tft.color565(180, 180, 180)); - tft.setTextSize(3); + drawBLE_beacon(180, 28, TFT_BLUE); + tft.setTextColor(FGCOLOR, BGCOLOR); + tft.setTextSize(FM); tft.setCursor(12, 50); // tft.printf("BLE connect!\n"); tft.printf("BLE Send\n"); - tft.setTextSize(5); + tft.setTextSize(FM); } - tft.fillRect(10, 100, WIDTH-20, 50, TFT_BLACK); - tft.setCursor(12, 105); + tft.fillRect(10, 100, WIDTH-20, 28, TFT_BLACK); + tft.setCursor(12, 100); if (senddata[0] % 4 == 0) { - tft.printf("0x%02X> ", senddata[0]); + tft.printf("0x%02X> ", senddata[0]); } else if (senddata[0] % 4 == 1) { - tft.printf("0x%02X>>", senddata[0]); + tft.printf("0x%02X>> ", senddata[0]); } else if (senddata[0] % 4 == 2) { - tft.printf("0x%02X >>", senddata[0]); + tft.printf("0x%02X >> ", senddata[0]); } else if (senddata[0] % 4 == 3) { - tft.printf("0x%02X >", senddata[0]); + tft.printf("0x%02X > ", senddata[0]); } senddata[1]++; @@ -230,7 +228,7 @@ void disPlayBLESend() } tft.setTextColor(TFT_WHITE); - pService->stop(); + pService->~NimBLEService(); pServer->getAdvertising()->stop(); BLEConnected=false; } diff --git a/src/modules/ble/ble_common.h b/src/modules/ble/ble_common.h index cddb8b50..d484a52b 100644 --- a/src/modules/ble/ble_common.h +++ b/src/modules/ble/ble_common.h @@ -1,18 +1,16 @@ -#include -#include -#include -#include -#include -#include -#include +//#include +#include +#include +#include + +#include +#include +#include #include "core/globals.h" #include "core/display.h" -extern const unsigned char icon_ble[4608]; -extern const unsigned char icon_ble_disconnect[4608]; - void ble_test(); void ble_scan(); void DisPlayBLESend(); diff --git a/src/modules/ble/ble_spam.cpp b/src/modules/ble/ble_spam.cpp index 08789852..88481915 100644 --- a/src/modules/ble/ble_spam.cpp +++ b/src/modules/ble/ble_spam.cpp @@ -456,7 +456,6 @@ BLEAdvertisementData GetUniversalAdvertisementData(EBLEPayloadType Type) { return AdvData; } //// https://github.com/Spooks4576 - void executeSpam(EBLEPayloadType type) { uint8_t macAddr[6]; if(type != Apple) { @@ -465,17 +464,21 @@ void executeSpam(EBLEPayloadType type) { } BLEDevice::init(""); delay(10); - BLEServer *pServer = BLEDevice::createServer(); + //BLEServer *pServer = BLEDevice::createServer(); //esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_ADV, ESP_PWR_LVL_P9); - pAdvertising = pServer->getAdvertising(); + pAdvertising = BLEDevice::getAdvertising(); + //pAdvertising = pServer->getAdvertising(); delay(40); //BLEAdvertisementData advertisementData = getSwiftAdvertisementData(); BLEAdvertisementData advertisementData = GetUniversalAdvertisementData(type); + BLEAdvertisementData oScanResponseData = BLEAdvertisementData(); pAdvertising->setAdvertisementData(advertisementData); + pAdvertising->setScanResponseData(oScanResponseData); + //pAdvertising->setAdvertisementType(ADV_TYPE_IND); pAdvertising->start(); - delay(10); - if(type == Apple) delay(10); + if(type == Apple) delay(20); + else delay(100); pAdvertising->stop(); delay(10); diff --git a/src/modules/ble/ble_spam.h b/src/modules/ble/ble_spam.h index 1c33f648..e9a9f8ec 100644 --- a/src/modules/ble/ble_spam.h +++ b/src/modules/ble/ble_spam.h @@ -1,4 +1,5 @@ -#include +#include +#include void aj_adv(int ble_choice); diff --git a/src/modules/rf/rf.cpp b/src/modules/rf/rf.cpp index 960e30af..93659850 100644 --- a/src/modules/rf/rf.cpp +++ b/src/modules/rf/rf.cpp @@ -365,12 +365,12 @@ static char * dec2binWzerofill(unsigned long Dec, unsigned int bitLength) { return bin; } -void initCC1101once() { +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); + ELECHOUSE_cc1101.setSpiPin(CC1101_SCK_PIN, CC1101_MISO_PIN, CC1101_MOSI_PIN, CC1101_SS_PIN, SSPI); #ifdef CC1101_GDO2_PIN ELECHOUSE_cc1101.setGDO(CC1101_GDO0_PIN, CC1101_GDO2_PIN); //Set Gdo0 (tx) and Gdo2 (rx) for serial transmission function. #else @@ -407,39 +407,45 @@ void deinitRfModule() { bool initRfModule(String mode, float frequency) { + initCC1101once(&sdcardSPI); // use default frequency if no one is passed if(!frequency) frequency = RfFreq; if(RfModule == 1) { // CC1101 in use - #ifdef USE_CC1101_VIA_SPI + #ifdef USE_CC1101_VIA_SPI ELECHOUSE_cc1101.Init(); - if (ELECHOUSE_cc1101.getCC1101()){ // Check the CC1101 Spi connection. Serial.println("cc1101 Connection OK"); } else { Serial.println("cc1101 Connection Error"); - return false; + //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 ELECHOUSE_cc1101.setMHZ(frequency); + Serial.println("cc1101 setMHZ(frequency);"); /* MEMO: cannot change other params after this is executed */ if(mode=="tx") { pinMode(CC1101_GDO0_PIN, OUTPUT); ELECHOUSE_cc1101.setPA(12); // set TxPower. The following settings are possible depending + Serial.println("cc1101 setPA();"); ELECHOUSE_cc1101.SetTx(); + Serial.println("cc1101 SetTx();"); } else if(mode=="rx") { pinMode(CC1101_GDO0_PIN, INPUT); ELECHOUSE_cc1101.SetRx(); + Serial.println("cc1101 SetRx();"); + tft.println("Ready, waiting"); } // else if mode is unspecified wont start TX/RX mode here -> done by the caller @@ -494,6 +500,7 @@ bool RCSwitch_Read_Raw(float frequency) { rcswitch.enableReceive(CC1101_GDO2_PIN); #else rcswitch.enableReceive(CC1101_GDO0_PIN); + Serial.println("CC1101 enableReceive()"); #endif #else return false; @@ -501,14 +508,13 @@ bool RCSwitch_Read_Raw(float frequency) { } else { rcswitch.enableReceive(RfRx); } - while(!checkEscPress()) { if(rcswitch.available()) { + Serial.println("Available"); long value = rcswitch.getReceivedValue(); - //Serial.println("Available"); + Serial.println("getReceivedValue()"); if(value) { - //Serial.println("has value"); - + Serial.println("has value"); unsigned int* raw = rcswitch.getReceivedRawdata(); received.frequency=long(frequency*1000000); received.key=rcswitch.getReceivedValue(); @@ -517,18 +523,21 @@ bool RCSwitch_Read_Raw(float frequency) { received.te=rcswitch.getReceivedDelay(); received.Bit=rcswitch.getReceivedBitlength(); received.filepath="Last copied"; - + Serial.println(received.te*2); + received.data=""; for(int i=0; i0) received.data+=" "; received.data+=raw[i]; } - //Serial.println(received.protocol); - //Serial.println(received.data); + 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? + drawMainBorder(); tft.setCursor(10, 28); tft.setTextSize(FP); - decimalToHexString(received.key,hexString); // need to remove the extra padding 0s? tft.println("Key: " + String(hexString)); tft.setCursor(10, tft.getCursorY()); tft.println("Binary: " + String(b)); @@ -542,9 +551,11 @@ bool RCSwitch_Read_Raw(float frequency) { tft.println("Press " + String(BTN_ALIAS) + "for options."); } rcswitch.resetAvailable(); + //Serial.println("resetAvailable"); previousMillis = millis(); } - if(received.key>0) { + if(received.key>0 && checkSelPress()) { + //Serial.println("received.key>0"); String subfile_out = "Filetype: Bruce SubGhz RAW File\nVersion 1\n"; subfile_out += "Frequency: " + String(int(frequency*1000000)) + "\n"; if(received.preset=="1") received.preset="FuriHalSubGhzPresetOok270Async"; @@ -562,52 +573,51 @@ bool RCSwitch_Read_Raw(float frequency) { return true; #endif - if(checkSelPress()) { - int chosen=0; - options = { - {"Replay signal", [&]() { chosen=1; } }, - {"Save signal", [&]() { chosen=2; } }, - }; - delay(200); - loopOptions(options); - if(chosen==1) { - rcswitch.disableReceive(); - sendRfCommand(received); - addToRecentCodes(received); - displayRedStripe("Waiting Signal",TFT_WHITE, FGCOLOR); - goto RestartRec; + int chosen=0; + options = { + {"Replay signal", [&]() { chosen=1; } }, + {"Save signal", [&]() { chosen=2; } }, + }; + delay(200); + loopOptions(options); + if(chosen==1) { + rcswitch.disableReceive(); + sendRfCommand(received); + addToRecentCodes(received); + displayRedStripe("Waiting Signal",TFT_WHITE, FGCOLOR); + goto RestartRec; + } + else if (chosen==2) { + int i=0; + File file; + String FS=""; + if(SD.begin()) { + if (!SD.exists("/BruceRF")) SD.mkdir("/BruceRF"); + 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()) { + if(!checkLittleFsSize()) goto Exit; + 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"; } - else if (chosen==2) { - int i=0; - File file; - String FS=""; - if(SD.begin()) { - if (!SD.exists("/BruceRF")) SD.mkdir("/BruceRF"); - 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()) { - if(!checkLittleFsSize()) goto Exit; - 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"); - } else { - Serial.println("Fail saving data to LittleFS"); - displayError("Error saving file"); - } - file.close(); - delay(2000); - drawMainBorder(); - tft.setCursor(10, 28); - tft.setTextSize(FP); - tft.println("Waiting for signal."); + if(file) { + file.println(subfile_out); + displaySuccess(FS + "/bruce_" + String(i) + ".sub"); + } else { + Serial.println("Fail saving data to LittleFS"); + displayError("Error saving file"); } + file.close(); + delay(2000); + drawMainBorder(); + tft.setCursor(10, 28); + tft.setTextSize(FP); + tft.println("Waiting for signal."); } + } } Exit: diff --git a/src/modules/rf/rf.h b/src/modules/rf/rf.h index 951b18a2..52c58245 100644 --- a/src/modules/rf/rf.h +++ b/src/modules/rf/rf.h @@ -23,5 +23,5 @@ void RCSwitch_send(uint64_t data, unsigned int bits, int pulse=0, int protocol=1 void addToRecentCodes(struct RfCodes rfcode); void sendRfCommand(struct RfCodes rfcode); bool initRfModule(String mode="", float frequency=0); -void initCC1101once(); +void initCC1101once(SPIClass* SSPI); void deinitRfModule(); \ No newline at end of file From 5524a7e8c20cf61eb7aab8f226c21b0cbfd7cf2b Mon Sep 17 00:00:00 2001 From: Pirata <104320209+bmorcelli@users.noreply.github.com> Date: Mon, 19 Aug 2024 06:57:51 -0300 Subject: [PATCH 2/5] Atualizar o ble_spam.h --- src/modules/ble/ble_spam.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/ble/ble_spam.h b/src/modules/ble/ble_spam.h index e9a9f8ec..76124f67 100644 --- a/src/modules/ble/ble_spam.h +++ b/src/modules/ble/ble_spam.h @@ -1,5 +1,5 @@ -#include -#include +#include +#include void aj_adv(int ble_choice); From 86deda2c6e127c36c13c483f79efcf9425956cbe Mon Sep 17 00:00:00 2001 From: Pirata <104320209+bmorcelli@users.noreply.github.com> Date: Mon, 19 Aug 2024 06:58:27 -0300 Subject: [PATCH 3/5] Atualizar o ble_common.h --- src/modules/ble/ble_common.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/modules/ble/ble_common.h b/src/modules/ble/ble_common.h index d484a52b..76c5d295 100644 --- a/src/modules/ble/ble_common.h +++ b/src/modules/ble/ble_common.h @@ -1,12 +1,12 @@ //#include -#include -#include -#include +#include +#include +#include -#include -#include -#include +#include +#include +#include #include "core/globals.h" #include "core/display.h" From 07df392ea70ee0cc80a8fd5f89260639b3306211 Mon Sep 17 00:00:00 2001 From: Pirata <104320209+bmorcelli@users.noreply.github.com> Date: Mon, 19 Aug 2024 06:58:40 -0300 Subject: [PATCH 4/5] Atualizar o ble_common.h --- src/modules/ble/ble_common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/ble/ble_common.h b/src/modules/ble/ble_common.h index 76c5d295..faa4faf9 100644 --- a/src/modules/ble/ble_common.h +++ b/src/modules/ble/ble_common.h @@ -6,7 +6,7 @@ #include #include -#include +#include #include "core/globals.h" #include "core/display.h" From 006f12ee44e8dcc9f6a01cbc5e17537ec7081e15 Mon Sep 17 00:00:00 2001 From: Pirata Date: Mon, 19 Aug 2024 18:52:02 -0300 Subject: [PATCH 5/5] . --- src/core/sd_functions.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/sd_functions.cpp b/src/core/sd_functions.cpp index c87919ae..db85fe63 100644 --- a/src/core/sd_functions.cpp +++ b/src/core/sd_functions.cpp @@ -209,7 +209,7 @@ bool copyFile(FS fs, String path) { ***************************************************************************************/ bool pasteFile(FS fs, String path) { // Tamanho do buffer para leitura/escrita - const size_t bufferSize = 2048*2; // Ajuste conforme necessário para otimizar a performance + const size_t bufferSize = 1024; // Ajuste conforme necessário para otimizar a performance uint8_t buffer[bufferSize]; // Abrir o arquivo original