Skip to content

Commit

Permalink
Merge pull request #79 from derskythe/subghz-freq-analyzer-long-press
Browse files Browse the repository at this point in the history
Long press OK button in SubGHz Frequency analyzer switch to Read menu
  • Loading branch information
xMasterX authored Sep 29, 2022
2 parents 1fb1a68 + f543753 commit 4d8f294
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 21 deletions.
28 changes: 19 additions & 9 deletions applications/main/subghz/scenes/subghz_scene_frequency_analyzer.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "../subghz_i.h"
#include <dolphin/dolphin.h>

#define TAG "SubGhzSceneFrequencyAnalyzer"

void subghz_scene_frequency_analyzer_callback(SubGhzCustomEvent event, void* context) {
furi_assert(context);
SubGhz* subghz = context;
Expand All @@ -17,16 +19,24 @@ void subghz_scene_frequency_analyzer_on_enter(void* context) {

bool subghz_scene_frequency_analyzer_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = context;
if(event.type == SceneManagerEventTypeCustom &&
event.event == SubGhzCustomEventViewReceiverOK) {
uint32_t frequency =
subghz_frequency_analyzer_get_frequency_to_save(subghz->subghz_frequency_analyzer);
if(frequency > 0) {
subghz->last_settings->frequency = frequency;
subghz_last_settings_save(subghz->last_settings);
}
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubGhzCustomEventViewReceiverOK) {
uint32_t frequency =
subghz_frequency_analyzer_get_frequency_to_save(subghz->subghz_frequency_analyzer);
if(frequency > 0) {
subghz->last_settings->frequency = frequency;
subghz_last_settings_save(subghz->last_settings);
}

return true;
return true;
} else if(event.event == SubGhzCustomEventViewReceiverUnlock) {
// Don't need to save, we already saved on short event
#if FURI_DEBUG
FURI_LOG_W(TAG, "Goto next scene!");
#endif
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiver);
return true;
}
}
return false;
}
Expand Down
50 changes: 38 additions & 12 deletions applications/main/subghz/views/subghz_frequency_analyzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ static const NotificationSequence sequence_saved = {
&message_vibro_off,
NULL,
};
static const NotificationSequence sequence_not_saved = {
&message_blink_stop,
&message_green_255,
&message_blue_255,
&message_red_255,
NULL,
};
//static const NotificationSequence sequence_not_saved = {
// &message_blink_stop,
// &message_green_255,
// &message_blue_255,
// &message_red_255,
// NULL,
//};

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

if(event->type == InputTypeShort && event->key == InputKeyOk) {
if(event->key == InputKeyOk) {
bool updated = false;
with_view_model(
instance->view, (SubGhzFrequencyAnalyzerModel * model) {
uint32_t prev_freq_to_save = model->frequency_to_save;
Expand All @@ -282,14 +283,39 @@ bool subghz_frequency_analyzer_input(InputEvent* event, void* context) {
#endif
model->frequency_to_save = frequency_candidate;
notification_message(instance->notifications, &sequence_saved);
instance->callback(SubGhzCustomEventViewReceiverOK, instance->context);
notification_message(instance->notifications, &sequence_hw_blink);
} else {
notification_message(instance->notifications, &sequence_not_saved);
notification_message(instance->notifications, &sequence_hw_blink);
updated = true;
}
return true;
});

#if FURI_DEBUG
FURI_LOG_I(
TAG,
"updated: %d, long: %d, type: %d",
updated,
(event->type == InputTypeLong),
event->type);
#endif

if(updated) {
instance->callback(SubGhzCustomEventViewReceiverOK, instance->context);
}

// First device receive short, then when user release button we get long
if(event->type == InputTypeLong) {
#if FURI_DEBUG
FURI_LOG_I(TAG, "Longpress!");
#endif
// Stop blinking
notification_message(instance->notifications, &sequence_hw_blink_stop);

// Stop worker
if(subghz_frequency_analyzer_worker_is_running(instance->worker)) {
subghz_frequency_analyzer_worker_stop(instance->worker);
}
instance->callback(SubGhzCustomEventViewReceiverUnlock, instance->context);
}
}

if(need_redraw) {
Expand Down

0 comments on commit 4d8f294

Please sign in to comment.