diff --git a/NRF24ChannelScanner/.flipcorg/gallery/screen1.png b/NRF24ChannelScanner/.flipcorg/gallery/screen1.png index 13ce887..b2b064e 100644 Binary files a/NRF24ChannelScanner/.flipcorg/gallery/screen1.png and b/NRF24ChannelScanner/.flipcorg/gallery/screen1.png differ diff --git a/NRF24ChannelScanner/.flipcorg/gallery/screen_open.png b/NRF24ChannelScanner/.flipcorg/gallery/screen_open.png index 13e8021..8167d1f 100644 Binary files a/NRF24ChannelScanner/.flipcorg/gallery/screen_open.png and b/NRF24ChannelScanner/.flipcorg/gallery/screen_open.png differ diff --git a/NRF24ChannelScanner/application.fam b/NRF24ChannelScanner/application.fam index 7573e43..b485523 100644 --- a/NRF24ChannelScanner/application.fam +++ b/NRF24ChannelScanner/application.fam @@ -8,7 +8,7 @@ App( stack_size=2 * 1024, requires=["gui"], fap_category="GPIO", - fap_version=(1, 2), + fap_version=(1, 3), fap_icon_assets="images", fap_icon="fapicon.png", fap_description="Scans 2.4Ghz frequency for usage data.", diff --git a/NRF24ChannelScanner/lib/nrf24/nrf24.h b/NRF24ChannelScanner/lib/nrf24/nrf24.h index dc4bb8a..6146acd 100644 --- a/NRF24ChannelScanner/lib/nrf24/nrf24.h +++ b/NRF24ChannelScanner/lib/nrf24/nrf24.h @@ -3,6 +3,11 @@ #include #include +//uncomment for Xtreme FW +//#include +//uncomment for RogueMaster +//#include + #ifdef __cplusplus extern "C" { #endif @@ -41,7 +46,13 @@ extern "C" { #define nrf24_TIMEOUT 500 #define nrf24_CE_PIN &gpio_ext_pb2 + +//for ofw #define nrf24_HANDLE &furi_hal_spi_bus_handle_external +//for Xtreme +//#define nrf24_HANDLE (XTREME_SETTINGS()->spi_nrf24_handle == SpiDefault ? &furi_hal_spi_bus_handle_external : &furi_hal_spi_bus_handle_external_extra) +//for RogueMaster +//#define nrf24_HANDLE (CFW_SETTINGS()->spi_nrf24_handle == SpiDefault ? &furi_hal_spi_bus_handle_external : &furi_hal_spi_bus_handle_external_extra) /* Low level API */ diff --git a/NRF24ChannelScanner/nrf24channelscanner.c b/NRF24ChannelScanner/nrf24channelscanner.c index 4a9339d..f57cd36 100644 --- a/NRF24ChannelScanner/nrf24channelscanner.c +++ b/NRF24ChannelScanner/nrf24channelscanner.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -15,6 +16,8 @@ bool szuz = true; //to show welcome screen static bool isScanning = false; //to track the progress static bool stopNrfScan = false; //to exit thread +static bool isInfiniteScan = false; //to prevent stop scan when OK long pressed + static bool threadStoppedsoFree = false; //indicate if I can free the thread from ram. static uint8_t currCh = 0; //for the progress bar or the channel selector @@ -62,15 +65,20 @@ static void draw_callback(Canvas* canvas, void* ctx) { //draw hello mesage if(szuz) { canvas_set_font(canvas, FontSecondary); - canvas_draw_str(canvas, 1, 22, "Up / Down to change channel time."); - canvas_draw_str(canvas, 1, 36, "Left / Right to select channel,"); - canvas_draw_str(canvas, 1, 48, "to get it's frequency"); + canvas_draw_str(canvas, 1, 22, "OK: scan / stop. Long: infinite."); + canvas_draw_str(canvas, 1, 33, "Up / Down to change channel time."); + canvas_draw_str(canvas, 1, 44, "Left / Right to select channel"); + canvas_draw_str(canvas, 1, 56, " to get it's frequency"); } //draw freq ir the progress canvas_set_font(canvas, FontSecondary); if(isScanning) { - canvas_draw_str(canvas, 37, 8, "scanning"); + if(isInfiniteScan) + canvas_draw_str(canvas, 37, 8, "scanning..."); + else + canvas_draw_str(canvas, 37, 8, "scanning"); + } else { if(showFreq) { int freq = 2400 + currCh; @@ -123,7 +131,7 @@ static int32_t scanner(void* context) { nrf24_set_rx_mode(nrf24_HANDLE, false); nrf24_write_reg(nrf24_HANDLE, REG_EN_AA, 0x0); nrf24_write_reg(nrf24_HANDLE, REG_RF_SETUP, 0x0f); - for(uint8_t j = 0; j < 15;) { //scan until stopped! + while(true) { //scan until stopped somehow if(stopNrfScan) break; for(uint8_t i = 0; i < num_channels; i++) { if(stopNrfScan) break; @@ -134,12 +142,18 @@ static int32_t scanner(void* context) { nrf24_flush_rx(nrf24_HANDLE); furi_delay_us(delayPerChan); tmp = nrf24_get_rdp(nrf24_HANDLE); - if(tmp > 0) nrf24values[i]++; - if(nrf24values[i] > 50) j = 254; //stop, bc maxed + if(tmp > 0 && nrf24values[i] < 65) { + nrf24values[i]++; //don't overrun it + } + if(nrf24values[i] > 50 && !isInfiniteScan) { + stopNrfScan = true; //stop, bc maxed, but only when not infinite + } } } furi_delay_ms(1); + //for screen refresh. } + //cleanup nrf24_set_idle(nrf24_HANDLE); isScanning = false; threadStoppedsoFree = true; @@ -157,7 +171,7 @@ void ChangeDelay(int delta) { delayPerChan += delta; if(delayPerChan > 4000) delayPerChan = 4000; if(delayPerChan < 120) delayPerChan = 120; - + if(delayPerChan == 170) delayPerChan = 150; //rounding for the next showFreq = false; } @@ -168,6 +182,13 @@ int32_t nrf24channelscanner_main(void* p) { Event event; FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(Event)); + //turn on 5v for some modules + uint8_t attempts = 0; + while(!furi_hal_power_is_otg_enabled() && attempts++ < 5) { + furi_hal_power_enable_otg(); + furi_delay_ms(10); + } + nrf24_init(); ViewPort* view_port = view_port_alloc(); @@ -193,7 +214,8 @@ int32_t nrf24channelscanner_main(void* p) { } break; } - if(event.input.type == InputTypeShort && event.input.key == InputKeyOk) { + if((event.input.type == InputTypeShort || event.input.type == InputTypeLong) && + event.input.key == InputKeyOk) { if(isScanning) { notification_message(notification, &sequence_blink_yellow_100); stopNrfScan = true; @@ -207,6 +229,7 @@ int32_t nrf24channelscanner_main(void* p) { threadStoppedsoFree = false; ifNotFoundNrf = false; notification_message(notification, &sequence_blink_green_100); + isInfiniteScan = (event.input.type == InputTypeLong); thread = furi_thread_alloc(); furi_thread_set_name(thread, "nrfscannerth"); furi_thread_set_stack_size(thread, 1024); @@ -247,5 +270,9 @@ int32_t nrf24channelscanner_main(void* p) { gui_remove_view_port(gui, view_port); view_port_free(view_port); furi_record_close(RECORD_GUI); + //turn off 5v + if(furi_hal_power_is_otg_enabled()) { + furi_hal_power_disable_otg(); + } return 0; } \ No newline at end of file diff --git a/README.md b/README.md index 629975e..6914f86 100644 --- a/README.md +++ b/README.md @@ -13,12 +13,14 @@ After the scanning finished, you can hit left or right keys, to find what freque ## Screenshot - + ## Buttons OK short: start / stop the scan. +OK long: start an infinite scan, that scans until stopped. + BACK long: exit the app. LEFT / RIGHT: when not scanning select the channel to see it's frequency. Short press steps 1, long 10. diff --git a/changelog.md b/changelog.md new file mode 100644 index 0000000..2f5e2a8 --- /dev/null +++ b/changelog.md @@ -0,0 +1 @@ +v1.3: added infinite scan and auto turn on 5V for some modules. \ No newline at end of file