From 5b74ae2bee0bfa39cb642cb902199742e2df517b Mon Sep 17 00:00:00 2001 From: HTotoo Date: Tue, 29 Aug 2023 11:48:27 +0200 Subject: [PATCH] Added infinite scan option, and turns on 5V for some modules. --- .../.flipcorg/gallery/screen1.png | Bin 1453 -> 1560 bytes .../.flipcorg/gallery/screen_open.png | Bin 2131 -> 2381 bytes NRF24ChannelScanner/application.fam | 2 +- NRF24ChannelScanner/lib/nrf24/nrf24.h | 11 +++++ NRF24ChannelScanner/nrf24channelscanner.c | 45 ++++++++++++++---- README.md | 4 +- changelog.md | 1 + 7 files changed, 52 insertions(+), 11 deletions(-) create mode 100644 changelog.md diff --git a/NRF24ChannelScanner/.flipcorg/gallery/screen1.png b/NRF24ChannelScanner/.flipcorg/gallery/screen1.png index 13ce887bf8d5df8a0daa76179042554c19297574..b2b064ed7f7484914dcf0e8d9b0fa929a38e48c4 100644 GIT binary patch literal 1560 zcmeAS@N?(olHy`uVBq!ia0y~yU;;8388|?c*QZDWAjMhW5n0T@z;^_M8K-LVNi#68 zp7L~Y45^s&_HJO%94`ikiy1p*u0L0bng4p@r-|}vVw@r-26u}8#eI^QsCe(yyM>iM z|JD5eYQJ7S{{P?lXF8R&4Z6$rFaC2b^4-@r%nT1?m>2|985jcdi|aRDpL1*4^~g=% z687cqy!gEMZS~&kAA5f6bc_EVeeUX=*K5AM`Cqo}&zo?Iw!P>6Ps+~x_Uqx!&%KTOuA95@<>o)y>-WB#FU`o{!pYz;g@M6EH;UQfQrzd4%FnJm+gEmEqip7p zzmnCmhvQ!RyRTzkW12MgLDuyf9O2dV>-YRi*H>VWeR?&+hY}VB1uq7MMRL~|roE9h{8hQCdaZfR z&zQGYzZKt4Iyvt_vD=wOxu5^^D(6~9RJ@{0#rhzS|_8mu#z*L_|O&^MinAA0Jxv0KE(KH9qPM>yd)X zf9w1HL_N5VQ_CIp1DQ7R66aD8{!Zm>xO?L>`@C*JNc2IYf3Q$jZr@}-P+a}@ht+QZ zIiLRLzd!#yqTKk}7)Lz8VgM1o_`)7ZuFCp1L&ECo{p&aLGtQetWLWHNs4%!24sjEs z8JgK&6uLL49081l-=RYpLDBhH!`|!l$hqLy)&q+kM;;Xbz WWO z?={Obz5UzW`*ZoD@3vRlUz>A3?EK`3i?4}<@10)%==I{;hD;0{LJSQWj0_#KqL?d| zt$lX+`;1`e*z*45-K!VN>Ay?w|GL)n{OZ+f{@>*00EXNOpz0Nu*D~t7-77xf=cDQk zat9>kUa$QoSoJJDvWJ0T5etKY7m!+ZjbYx->t~Ih7n~Kp-~W~2+KxwY4y)_lscmOE z@RS4M&Du!j88hu`OWwV_Sh;%bHR)@6)_>!veqnsxk|DzC)tm$U|Lz#u*!Lm~joWtX zdDRo1&oK;tPI5r(0a}-p#mms}8_6e74?!qk3k z>Lzzb@P_mJHuDAXC_*w|Z-a$tHOs*|q-eu%9X^*2Yq@)Ub`0y@e*N7a|Nq~g3i}Tp z4em(M5Xqd-wX<#qQmWC&X0XZGDQEC&S1FT)Jt8#$#or`t@ne|Njx$!yGa5YE`==nE z$RvlF4$lD#fNeJEho2w+-ROQu6v>T9F%3*ny!Px5{vKuco`y)MsA+qug?z(#6O^3w zDlD79xcF~+1b@Xd!TXJg8r y)!lwoSNEm7{>!fPZO4nh^7L!IIf%#(uhc(rIxFqG>9GTpH$7ebT-G@yGywn`47~OL diff --git a/NRF24ChannelScanner/.flipcorg/gallery/screen_open.png b/NRF24ChannelScanner/.flipcorg/gallery/screen_open.png index 13e8021ecd73e50c98146e15f0cc2ef92ac0134c..8167d1f6640a596bb16fcb2b9a4bb3769fb93a6c 100644 GIT binary patch literal 2381 zcma)74Nwzj8s2~&pw*~!ydnt9-SxPWX;E`1;V;zFB53*1L?jTRqNEA(V^cswei%z_ zi?r%+HjgEFk%xWJzU zzfbR&I=`crZ?#W09tuyEwD2OSXeqI!v(@=F+s@Jj?0sDs2zVyeOO~OFImevF3)`tgJr* z1#z$bt_pN%?BmgB2R;&rGrF2|*yr?aUh45cTMIS(1hy;m9@%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QU5Oz!QVHtt<``5C5dml7Hf5_BzOpp_G_@jCa?qM3N2%+b<N(ap0gl(!swSoo{J)L(K4y}mgY3qFa;N8V~X>!G_eFjSp3aMON^q!7_H#lG~ zPbKSNjIvk~JHr%d3n2$1UN7M+i57vej8&bAXSv<+sCS9LIwMv&TB#!+9icY1C3W^y zFiJJyVr1iIk90Asc~Se2wAwkL6ZWzc8)HdCT2`uRX2FVxgBs3lrGXW}6;CH*8!`i(wmWA zmUo-xfp{cS>_-9^iEbmby>&~2u4gz}{`ZG$#w;$6GAvRjc70ldRT*$J&A^&MU`tTaFChrQbJ z)~g;?aZ*t8o%!@ZdzC*W$G7-OLN`w$zx&gBBgS)*USFs#oLG*yCLG$IL8QoMc)?7) zMVP(V-FlYv2m9sUSOHijBGmL3S^iUqUB_SH-3AFy^eX;lh%Kl@bus69s*Yi(maxpy zOj_oEf0yQ3L37WNzsa{pQl`eEQTBmWz0B6q?OLQFU@DZ5q@m`9-kK+sx^3#_h&a*o z`iKjOgS8hQNn{bbpJ&gnx>jKIGiwDFqz$*+xT>KwSuYuCLrkZC+Z5OJA;_OO>dx88 zKrDRHVIH=WA+~KAa$HKZgiJ3w)1Em`NQtVpwJnXv=2cP)dKvqJ>QwiHw%YH#fX~`d zK~m+DzH8np?1vZzj+>3yc260osA=`As`kXv&I#C^kCCe(q_nA{{X8$hHG9KX{kfPN zlpcep!*KOgVtTY)g&xgV}`^TT4)!lV<@tBQLqX!BW=-)=Y$#W$f#wX`r_ zrgp`XknC-~!fcx^Fq&|%*Cf?`!Y#Uilaxm6jTX5tK;QHx(cDbxT`JXx2os z!zTY)YHY7OKjEc l=MQI8vwxhR|ASrIILfh0fuhxuA?L7PA4XeKwQASV-vK{YVN(DA 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