Skip to content

Commit

Permalink
Added infinite scan option, and turns on 5V for some modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
htotoo committed Aug 29, 2023
1 parent 0d29f84 commit 5b74ae2
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 11 deletions.
Binary file modified NRF24ChannelScanner/.flipcorg/gallery/screen1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified NRF24ChannelScanner/.flipcorg/gallery/screen_open.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion NRF24ChannelScanner/application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
11 changes: 11 additions & 0 deletions NRF24ChannelScanner/lib/nrf24/nrf24.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
#include <stdint.h>
#include <furi_hal_spi.h>

//uncomment for Xtreme FW
//#include <xtreme.h>
//uncomment for RogueMaster
//#include <cfw.h>

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -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 */

Expand Down
45 changes: 36 additions & 9 deletions NRF24ChannelScanner/nrf24channelscanner.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <furi.h>
#include <furi_hal_power.h>
#include <gui/gui.h>
#include <input/input.h>
#include <gui/elements.h>
Expand All @@ -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

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}

Expand All @@ -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();
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ After the scanning finished, you can hit left or right keys, to find what freque

## Screenshot

<img src="https://raw.githubusercontent.com/htotoo/NRF24ChannelScanner/main/screen1.png">
<img src="https://raw.githubusercontent.com/htotoo/NRF24ChannelScanner/main/NRF24ChannelScanner/.flipcorg/gallery/screen1.png">

## 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.
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v1.3: added infinite scan and auto turn on 5V for some modules.

0 comments on commit 5b74ae2

Please sign in to comment.