Skip to content

Commit 4d8f294

Browse files
authored
Merge pull request #79 from derskythe/subghz-freq-analyzer-long-press
Long press OK button in SubGHz Frequency analyzer switch to Read menu
2 parents 1fb1a68 + f543753 commit 4d8f294

File tree

2 files changed

+57
-21
lines changed

2 files changed

+57
-21
lines changed

applications/main/subghz/scenes/subghz_scene_frequency_analyzer.c

+19-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "../subghz_i.h"
22
#include <dolphin/dolphin.h>
33

4+
#define TAG "SubGhzSceneFrequencyAnalyzer"
5+
46
void subghz_scene_frequency_analyzer_callback(SubGhzCustomEvent event, void* context) {
57
furi_assert(context);
68
SubGhz* subghz = context;
@@ -17,16 +19,24 @@ void subghz_scene_frequency_analyzer_on_enter(void* context) {
1719

1820
bool subghz_scene_frequency_analyzer_on_event(void* context, SceneManagerEvent event) {
1921
SubGhz* subghz = context;
20-
if(event.type == SceneManagerEventTypeCustom &&
21-
event.event == SubGhzCustomEventViewReceiverOK) {
22-
uint32_t frequency =
23-
subghz_frequency_analyzer_get_frequency_to_save(subghz->subghz_frequency_analyzer);
24-
if(frequency > 0) {
25-
subghz->last_settings->frequency = frequency;
26-
subghz_last_settings_save(subghz->last_settings);
27-
}
22+
if(event.type == SceneManagerEventTypeCustom) {
23+
if(event.event == SubGhzCustomEventViewReceiverOK) {
24+
uint32_t frequency =
25+
subghz_frequency_analyzer_get_frequency_to_save(subghz->subghz_frequency_analyzer);
26+
if(frequency > 0) {
27+
subghz->last_settings->frequency = frequency;
28+
subghz_last_settings_save(subghz->last_settings);
29+
}
2830

29-
return true;
31+
return true;
32+
} else if(event.event == SubGhzCustomEventViewReceiverUnlock) {
33+
// Don't need to save, we already saved on short event
34+
#if FURI_DEBUG
35+
FURI_LOG_W(TAG, "Goto next scene!");
36+
#endif
37+
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiver);
38+
return true;
39+
}
3040
}
3141
return false;
3242
}

applications/main/subghz/views/subghz_frequency_analyzer.c

+38-12
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ static const NotificationSequence sequence_saved = {
4040
&message_vibro_off,
4141
NULL,
4242
};
43-
static const NotificationSequence sequence_not_saved = {
44-
&message_blink_stop,
45-
&message_green_255,
46-
&message_blue_255,
47-
&message_red_255,
48-
NULL,
49-
};
43+
//static const NotificationSequence sequence_not_saved = {
44+
// &message_blink_stop,
45+
// &message_green_255,
46+
// &message_blue_255,
47+
// &message_red_255,
48+
// NULL,
49+
//};
5050

5151
static const uint32_t subghz_frequency_list[] = {
5252
300000000, 302757000, 303875000, 304250000, 307000000, 307500000, 307800000,
@@ -255,7 +255,8 @@ bool subghz_frequency_analyzer_input(InputEvent* event, void* context) {
255255
need_redraw = true;
256256
}
257257

258-
if(event->type == InputTypeShort && event->key == InputKeyOk) {
258+
if(event->key == InputKeyOk) {
259+
bool updated = false;
259260
with_view_model(
260261
instance->view, (SubGhzFrequencyAnalyzerModel * model) {
261262
uint32_t prev_freq_to_save = model->frequency_to_save;
@@ -282,14 +283,39 @@ bool subghz_frequency_analyzer_input(InputEvent* event, void* context) {
282283
#endif
283284
model->frequency_to_save = frequency_candidate;
284285
notification_message(instance->notifications, &sequence_saved);
285-
instance->callback(SubGhzCustomEventViewReceiverOK, instance->context);
286-
notification_message(instance->notifications, &sequence_hw_blink);
287-
} else {
288-
notification_message(instance->notifications, &sequence_not_saved);
289286
notification_message(instance->notifications, &sequence_hw_blink);
287+
updated = true;
290288
}
291289
return true;
292290
});
291+
292+
#if FURI_DEBUG
293+
FURI_LOG_I(
294+
TAG,
295+
"updated: %d, long: %d, type: %d",
296+
updated,
297+
(event->type == InputTypeLong),
298+
event->type);
299+
#endif
300+
301+
if(updated) {
302+
instance->callback(SubGhzCustomEventViewReceiverOK, instance->context);
303+
}
304+
305+
// First device receive short, then when user release button we get long
306+
if(event->type == InputTypeLong) {
307+
#if FURI_DEBUG
308+
FURI_LOG_I(TAG, "Longpress!");
309+
#endif
310+
// Stop blinking
311+
notification_message(instance->notifications, &sequence_hw_blink_stop);
312+
313+
// Stop worker
314+
if(subghz_frequency_analyzer_worker_is_running(instance->worker)) {
315+
subghz_frequency_analyzer_worker_stop(instance->worker);
316+
}
317+
instance->callback(SubGhzCustomEventViewReceiverUnlock, instance->context);
318+
}
293319
}
294320

295321
if(need_redraw) {

0 commit comments

Comments
 (0)