Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Long press OK button in SubGHz Frequency analyzer switch to Read menu #79

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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