mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-11 06:09:08 -07:00
Merge branch 'dev' of https://github.com/Flipper-XFW/Xtreme-Firmware into xfw-dev
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
#define RX_BUF_SIZE 1024
|
||||
|
||||
static const int gps_baudrates[5] = {9600, 19200, 38400, 57600, 115200};
|
||||
static int current_gps_baudrate = 3;
|
||||
static int current_gps_baudrate = 0;
|
||||
|
||||
typedef struct {
|
||||
bool valid;
|
||||
|
||||
@@ -3,10 +3,12 @@ App(
|
||||
name="[NRF24] Channel Scanner",
|
||||
apptype=FlipperAppType.EXTERNAL,
|
||||
entry_point="nrf24channelscanner_main",
|
||||
fap_author="HTotoo",
|
||||
fap_weburl="https://github.com/htotoo/NRF24ChannelScanner",
|
||||
stack_size=2 * 1024,
|
||||
requires=["gui"],
|
||||
fap_category="GPIO",
|
||||
fap_version=(1, 1),
|
||||
fap_version=(1, 3),
|
||||
fap_icon_assets="images",
|
||||
fap_icon="fapicon.png",
|
||||
fap_description="Scans 2.4Ghz frequency for usage data.",
|
||||
|
||||
@@ -17,10 +17,12 @@ 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
|
||||
|
||||
static int delayPerChan = 5; //can set via up / down.
|
||||
static int delayPerChan = 150; //can set via up / down.
|
||||
|
||||
bool showFreq = true;
|
||||
|
||||
@@ -64,38 +66,31 @@ 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;
|
||||
char strfreq[10] = {32};
|
||||
itoa(freq, strfreq, 10);
|
||||
strfreq[4] = ' ';
|
||||
strfreq[5] = 'M';
|
||||
strfreq[6] = 'H';
|
||||
strfreq[7] = 'Z';
|
||||
strfreq[8] = 0;
|
||||
char strfreq[10] = {0};
|
||||
snprintf(strfreq, sizeof(strfreq), "%d MHZ", freq);
|
||||
canvas_draw_str(canvas, 40, 8, strfreq);
|
||||
} else {
|
||||
//show delay
|
||||
int dly = delayPerChan;
|
||||
char strdel[10] = {32};
|
||||
itoa(dly, strdel, 10);
|
||||
if(dly < 10) strdel[1] = ' ';
|
||||
if(dly < 100) strdel[2] = ' ';
|
||||
if(dly < 1000) strdel[3] = ' ';
|
||||
strdel[4] = ' ';
|
||||
strdel[5] = 'm';
|
||||
strdel[6] = 's';
|
||||
strdel[7] = 0;
|
||||
char strdel[10] = {0};
|
||||
snprintf(strdel, sizeof(strdel), "%d us", dly);
|
||||
canvas_draw_str(canvas, 40, 8, strdel);
|
||||
}
|
||||
}
|
||||
@@ -125,7 +120,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,13 +129,20 @@ static int32_t scanner(void* context) {
|
||||
nrf24_set_rx_mode(nrf24_HANDLE, true);
|
||||
for(uint8_t ii = 0; ii < 3; ++ii) {
|
||||
nrf24_flush_rx(nrf24_HANDLE);
|
||||
furi_delay_ms(delayPerChan);
|
||||
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;
|
||||
@@ -156,10 +158,9 @@ void ChangeFreq(int delta) {
|
||||
|
||||
void ChangeDelay(int delta) {
|
||||
delayPerChan += delta;
|
||||
if(delayPerChan > 100) delayPerChan = 100;
|
||||
if(delayPerChan < 1) delayPerChan = 1;
|
||||
if(delayPerChan == 11) delayPerChan = 10; //to get it rounded :)
|
||||
if(delayPerChan == 6) delayPerChan = 5; //to get it rounded :)
|
||||
if(delayPerChan > 4000) delayPerChan = 4000;
|
||||
if(delayPerChan < 120) delayPerChan = 120;
|
||||
if(delayPerChan == 170) delayPerChan = 150; //rounding for the next
|
||||
showFreq = false;
|
||||
}
|
||||
|
||||
@@ -170,6 +171,7 @@ 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();
|
||||
@@ -201,7 +203,9 @@ int32_t nrf24channelscanner_main(void* p) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
if(event.input.type == InputTypeShort && event.input.key == InputKeyOk) {
|
||||
//isInfiniteScan
|
||||
if((event.input.type == InputTypeShort || event.input.type == InputTypeLong) &&
|
||||
event.input.key == InputKeyOk) {
|
||||
if(isScanning) {
|
||||
notification_message(notification, &sequence_blink_yellow_100);
|
||||
stopNrfScan = true;
|
||||
@@ -215,6 +219,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);
|
||||
@@ -227,10 +232,10 @@ int32_t nrf24channelscanner_main(void* p) {
|
||||
}
|
||||
//change the delay
|
||||
if(event.input.type == InputTypeShort && event.input.key == InputKeyUp) {
|
||||
ChangeDelay(5);
|
||||
ChangeDelay(50);
|
||||
}
|
||||
if(event.input.type == InputTypeShort && event.input.key == InputKeyDown) {
|
||||
ChangeDelay(-5);
|
||||
ChangeDelay(-50);
|
||||
}
|
||||
|
||||
if(!isScanning) {
|
||||
@@ -255,10 +260,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;
|
||||
}
|
||||
Reference in New Issue
Block a user