From 33176220f6a13bab49ccf1a993914e9500b49367 Mon Sep 17 00:00:00 2001 From: Daniel <71837281+darmiel@users.noreply.github.com> Date: Thu, 25 Aug 2022 01:24:11 +0200 Subject: [PATCH 1/2] feat[freq-analzer]: added feedback levels 0, 1, 2 0 - no feedback 1 - vibro only 2 - vibro and beep switch the modes with the "UP" key --- .../subghz/views/subghz_frequency_analyzer.c | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/applications/subghz/views/subghz_frequency_analyzer.c b/applications/subghz/views/subghz_frequency_analyzer.c index 14942fc753c..510d6ac6d03 100644 --- a/applications/subghz/views/subghz_frequency_analyzer.c +++ b/applications/subghz/views/subghz_frequency_analyzer.c @@ -40,6 +40,7 @@ struct SubGhzFrequencyAnalyzer { SubGhzFrequencyAnalyzerCallback callback; void* context; bool locked; + uint8_t feedback_level; // 0 - no feedback, 1 - vibro only, 2 - vibro and sound float rssi_last; uint32_t frequency_last; uint32_t frequency_last_vis; @@ -174,9 +175,19 @@ bool subghz_frequency_analyzer_input(InputEvent* event, void* context) { need_redraw = true; } + if(event->type == InputTypePress && event->key == InputKeyUp) { + if(instance->feedback_level == 0) { + instance->feedback_level = 2; + } else { + instance->feedback_level--; + } + FURI_LOG_D(TAG, "feedback_level = %d", instance->feedback_level); + need_redraw = true; + } + if(need_redraw) { SubGhzFrequencyAnalyzer* instance = context; - with_view_model( + instance->view with_view_model( instance->view, (SubGhzFrequencyAnalyzerModel * model) { model->rssi_last = instance->rssi_last; model->frequency_last = instance->frequency_last; @@ -218,7 +229,18 @@ void subghz_frequency_analyzer_pair_callback(void* context, uint32_t frequency, // Triggered! instance->rssi_last = rssi; notification_message(instance->notifications, &sequence_hw_blink_stop); - notification_message(instance->notifications, &sequence_success); + + switch(instance->feedback_level) { + case 1: // 1 - only vibro + notification_message(instance->notifications, &sequence_single_vibro); + break; + case 2: // 2 - vibro and beep + notification_message(instance->notifications, &sequence_success); + break; + default: // 0 - no feedback + break; + } + FURI_LOG_D(TAG, "triggered"); } // Update values @@ -294,6 +316,8 @@ SubGhzFrequencyAnalyzer* subghz_frequency_analyzer_alloc() { SubGhzFrequencyAnalyzer* instance = malloc(sizeof(SubGhzFrequencyAnalyzer)); furi_assert(instance); + instance->feedback_level = 2; + // View allocation and configuration instance->view = view_alloc(); view_allocate_model( From e828d15fe3fd13b98400990de337f8bc195e776a Mon Sep 17 00:00:00 2001 From: Daniel <71837281+darmiel@users.noreply.github.com> Date: Thu, 25 Aug 2022 08:57:31 +0200 Subject: [PATCH 2/2] feat[freq-analzer]: added ui for feedbacl level --- .../subghz/views/subghz_frequency_analyzer.c | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/applications/subghz/views/subghz_frequency_analyzer.c b/applications/subghz/views/subghz_frequency_analyzer.c index 510d6ac6d03..5be00888fe9 100644 --- a/applications/subghz/views/subghz_frequency_analyzer.c +++ b/applications/subghz/views/subghz_frequency_analyzer.c @@ -53,6 +53,7 @@ typedef struct { float rssi; float rssi_last; float trigger; + uint8_t feedback_level; } SubGhzFrequencyAnalyzerModel; void subghz_frequency_analyzer_set_callback( @@ -142,6 +143,21 @@ void subghz_frequency_analyzer_draw(Canvas* canvas, SubGhzFrequencyAnalyzerModel } canvas_draw_str(canvas, 9, 42, buffer); + switch(model->feedback_level) { + case 2: + canvas_draw_icon(canvas, 128 - 8 - 1, 1, &I_Volup_8x6); + break; + case 1: + canvas_draw_icon(canvas, 128 - 8 - 1, 1, &I_Voldwn_6x6); + break; + case 0: + canvas_draw_icon(canvas, 128 - 8 - 1, 1, &I_Voldwn_6x6); + canvas_set_color(canvas, ColorWhite); + canvas_draw_box(canvas, 128 - 2 - 1 - 2, 1, 2, 6); + canvas_set_color(canvas, ColorBlack); + break; + } + // Buttons hint elements_button_left(canvas, "T-"); elements_button_right(canvas, "T+"); @@ -175,7 +191,7 @@ bool subghz_frequency_analyzer_input(InputEvent* event, void* context) { need_redraw = true; } - if(event->type == InputTypePress && event->key == InputKeyUp) { + if(event->type == InputTypePress && event->key == InputKeyDown) { if(instance->feedback_level == 0) { instance->feedback_level = 2; } else { @@ -187,12 +203,13 @@ bool subghz_frequency_analyzer_input(InputEvent* event, void* context) { if(need_redraw) { SubGhzFrequencyAnalyzer* instance = context; - instance->view with_view_model( + with_view_model( instance->view, (SubGhzFrequencyAnalyzerModel * model) { model->rssi_last = instance->rssi_last; model->frequency_last = instance->frequency_last; model->trigger = subghz_frequency_analyzer_worker_get_trigger_level(instance->worker); + model->feedback_level = instance->feedback_level; return true; }); } @@ -258,6 +275,7 @@ void subghz_frequency_analyzer_pair_callback(void* context, uint32_t frequency, model->frequency = frequency; model->frequency_last = instance->frequency_last_vis; model->trigger = subghz_frequency_analyzer_worker_get_trigger_level(instance->worker); + model->feedback_level = instance->feedback_level; return true; }); }