From 3f660592893bb8ec97729c756801ceb0e9a8e52e Mon Sep 17 00:00:00 2001 From: Pirata Date: Thu, 3 Oct 2024 15:24:53 -0300 Subject: [PATCH] NRF24 last build Changed from RPD watching (too noisy, not reliable) to data availability on channel. Added disclaimer message on Information --- src/core/menu_items/NRF24.cpp | 4 ++- src/modules/NRF24/nrf_common.cpp | 22 +++++++++++++ src/modules/NRF24/nrf_common.h | 4 ++- src/modules/NRF24/nrf_spectrum.cpp | 51 +++++++----------------------- 4 files changed, 40 insertions(+), 41 deletions(-) diff --git a/src/core/menu_items/NRF24.cpp b/src/core/menu_items/NRF24.cpp index 142f67652..fcd8aca4f 100644 --- a/src/core/menu_items/NRF24.cpp +++ b/src/core/menu_items/NRF24.cpp @@ -1,11 +1,12 @@ #include "NRF24.h" #include "core/display.h" +#include "modules/NRF24/nrf_common.h" #include "modules/NRF24/nrf_jammer.h" #include "modules/NRF24/nrf_spectrum.h" void NRF24Menu::optionsMenu() { options.clear(); - options.push_back({"Jammer 2.4G", [=]() { nrf_jammer(); }}); + options.push_back({"Information", [=]() { nrf_info(); }}); #if defined(STICK_C_PLUS) || defined(STICK_C_PLUS2) options.push_back({"Spectrum", [=]() { nrf_spectrum(&CC_NRF_SPI); }}); #elif defined(CARDPUTER) || defined(ESP32S3DEVKITC1) @@ -13,6 +14,7 @@ void NRF24Menu::optionsMenu() { #else options.push_back({"Spectrum", [=]() { nrf_spectrum(&SPI); }}); #endif + options.push_back({"Jammer 2.4G", [=]() { nrf_jammer(); }}); options.push_back({"Main Menu", [=]() { backToMenu(); }}); delay(200); diff --git a/src/modules/NRF24/nrf_common.cpp b/src/modules/NRF24/nrf_common.cpp index 3ef092334..9dd225759 100644 --- a/src/modules/NRF24/nrf_common.cpp +++ b/src/modules/NRF24/nrf_common.cpp @@ -1,9 +1,31 @@ #include "nrf_common.h" +#include "../../core/mykeyboard.h" RF24 NRFradio(NRF24_CE_PIN, NRF24_SS_PIN); +void nrf_info() { + tft.fillScreen(BGCOLOR); + tft.setTextSize(FM); + tft.setTextColor(TFT_RED, BGCOLOR); + tft.drawCentreString("_Disclaimer_",WIDTH/2,10,1); + tft.setTextColor(TFT_WHITE, BGCOLOR); + tft.setTextSize(FP); + tft.setCursor(15,33); + tft.println("These functions were made to be used in a controlled environment for STUDY only."); + tft.println("\nDO NOT use these functions to harm people or companies, you can go to jail!"); + tft.setTextColor(FGCOLOR, BGCOLOR); + tft.println("\nThis device is VERY sensible to noise, so long wires or passing near VCC line can make things go wrong."); + delay(1000); + while(!checkAnyKeyPress()); +} + bool nrf_start() { #if defined(USE_NRF24_VIA_SPI) + pinMode(NRF24_SS_PIN, OUTPUT); + digitalWrite(NRF24_SS_PIN, HIGH); + pinMode(NRF24_CE_PIN, OUTPUT); + digitalWrite(NRF24_CE_PIN, LOW); + #if defined(STICK_C_PLUS) || defined(STICK_C_PLUS2) CC_NRF_SPI.begin(NRF24_SCK_PIN,NRF24_MISO_PIN,NRF24_MOSI_PIN,NRF24_SS_PIN); #elif defined(CARDPUTER) || defined(ESP32S3DEVKITC1) diff --git a/src/modules/NRF24/nrf_common.h b/src/modules/NRF24/nrf_common.h index 80d4d6e65..b734505ba 100644 --- a/src/modules/NRF24/nrf_common.h +++ b/src/modules/NRF24/nrf_common.h @@ -11,4 +11,6 @@ extern RF24 NRFradio; -bool nrf_start(); \ No newline at end of file +bool nrf_start(); + +void nrf_info(); \ No newline at end of file diff --git a/src/modules/NRF24/nrf_spectrum.cpp b/src/modules/NRF24/nrf_spectrum.cpp index 8c860f8b5..63c37f21b 100644 --- a/src/modules/NRF24/nrf_spectrum.cpp +++ b/src/modules/NRF24/nrf_spectrum.cpp @@ -4,12 +4,6 @@ #include "../../core/mykeyboard.h" -// nRF24L01P Registers -#define _NRF24_CONFIG 0x00 -#define _NRF24_EN_AA 0x01 -#define _NRF24_RF_CH 0x05 -#define _NRF24_RF_SETUP 0x06 -#define _NRF24_RPD 0x09 #define CHANNELS 80 #define RGB565(r, g, b) ((((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3))) uint8_t channel[CHANNELS]; @@ -30,51 +24,29 @@ inline void setRegister(SPIClass &SSPI, byte r, byte v) { digitalWrite(NRF24_SS_PIN, HIGH); } -inline void powerUp(SPIClass &SSPI) { - byte v = getRegister(SSPI,_NRF24_CONFIG) | 0x02; - delayMicroseconds(20); - setRegister(SSPI,_NRF24_CONFIG, v); - delayMicroseconds(130); -} - inline void powerDown(SPIClass &SSPI) { - byte v = getRegister(SSPI,_NRF24_CONFIG) & ~0x02; - delayMicroseconds(20); - setRegister(SSPI,_NRF24_CONFIG, v); -} - -inline void enable_nrf() { - digitalWrite(NRF24_CE_PIN, HIGH); -} - -inline void disable_nrf() { - digitalWrite(NRF24_CE_PIN, LOW); -} - -inline void setRX(SPIClass &SSPI) { - byte v = getRegister(SSPI,_NRF24_CONFIG) | 0x01; - delayMicroseconds(20); - setRegister(SSPI,_NRF24_CONFIG, v); - enable_nrf(); - delayMicroseconds(100); + setRegister(SSPI,0x00, getRegister(SSPI,0x00) & ~0x02); } // Scanning Channels #define _BW WIDTH/CHANNELS String scanChannels(SPIClass* SSPI, bool web) { String result="{"; - disable_nrf(); + digitalWrite(NRF24_CE_PIN, LOW); for (int i = 0; i < CHANNELS; i++) { - setRegister(*SSPI,_NRF24_RF_CH,i); //(126 * i) / CHANNELS); - setRX(*SSPI); - delayMicroseconds(80); - disable_nrf(); - int rpd = getRegister(*SSPI,_NRF24_RPD) * 200; + NRFradio.setChannel(i); + NRFradio.startListening(); + delayMicroseconds(128); + NRFradio.stopListening(); + int rpd=0; + if(NRFradio.testCarrier()) rpd=200; channel[i] = (channel[i] * 3 + rpd) / 4; + int level = (channel[i] > 125) ? 125 : channel[i]; // Clamp values tft.drawFastVLine(i*_BW, 0, 125, (i % 8) ? TFT_BLACK : RGB565(25, 25, 25)); tft.drawFastVLine(i*_BW, HEIGHT-(10+level), level, (i % 2 == 0) ? FGCOLOR : TFT_DARKGREY); // Use green for even indices + tft.drawFastVLine(i*_BW, 0, HEIGHT-(9+level), (i % 8) ? TFT_BLACK : RGB565(25, 25, 25)); tft.drawFastVLine(i*_BW, 0, rpd ? 2 : 0, TFT_DARKGREY); if(web) { if(i>0) result+=","; @@ -92,6 +64,7 @@ void nrf_spectrum(SPIClass* SSPI) { tft.drawString("2.40Ghz",0,HEIGHT-LH); tft.drawCentreString("2.44Ghz", WIDTH/2,HEIGHT-LH,1); tft.drawRightString("2.48Ghz",WIDTH,HEIGHT-LH,1); + memset(channel,0,CHANNELS); if(nrf_start()) { NRFradio.setAutoAck(false); @@ -103,7 +76,7 @@ void nrf_spectrum(SPIClass* SSPI) { } NRFradio.setDataRate(RF24_1MBPS); - while(!checkNextPress()) { + while(!checkEscPress()) { scanChannels(SSPI); } NRFradio.stopListening();