From ab669b26dab688067682e77e0c3789955783790d Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Tue, 25 Apr 2023 01:42:20 +0300 Subject: [PATCH] Fix very old and funny subghz bugs Fixed Frequency Ananyzer issues Fixed read mode issues Fixed re-inits in HAL --- applications/main/subghz/helpers/subghz_custom_event.h | 3 +++ .../main/subghz/scenes/subghz_scene_frequency_analyzer.c | 5 +++-- applications/main/subghz/subghz_history.c | 5 +++++ applications/main/subghz/views/subghz_frequency_analyzer.c | 4 ++-- firmware/targets/f7/furi_hal/furi_hal_subghz.c | 5 +++++ 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/applications/main/subghz/helpers/subghz_custom_event.h b/applications/main/subghz/helpers/subghz_custom_event.h index 9d2be7ee5..ad49bf09b 100644 --- a/applications/main/subghz/helpers/subghz_custom_event.h +++ b/applications/main/subghz/helpers/subghz_custom_event.h @@ -103,5 +103,8 @@ typedef enum { SubGhzCustomEventViewTransmitterSendStop, SubGhzCustomEventViewTransmitterError, + SubGhzCustomEventViewFreqAnalOkShort, + SubGhzCustomEventViewFreqAnalOkLong, + SubGhzCustomEventByteInputDone, } SubGhzCustomEvent; diff --git a/applications/main/subghz/scenes/subghz_scene_frequency_analyzer.c b/applications/main/subghz/scenes/subghz_scene_frequency_analyzer.c index bed044244..b1071d836 100644 --- a/applications/main/subghz/scenes/subghz_scene_frequency_analyzer.c +++ b/applications/main/subghz/scenes/subghz_scene_frequency_analyzer.c @@ -54,7 +54,7 @@ bool subghz_scene_frequency_analyzer_on_event(void* context, SceneManagerEvent e } else if(event.event == SubGhzCustomEventSceneAnalyzerUnlock) { notification_message(subghz->notifications, &sequence_reset_rgb); return true; - } else if(event.event == SubGhzCustomEventViewReceiverOK) { + } else if(event.event == SubGhzCustomEventViewFreqAnalOkShort) { notification_message(subghz->notifications, &sequence_saved); uint32_t frequency = subghz_frequency_analyzer_get_frequency_to_save(subghz->subghz_frequency_analyzer); @@ -64,11 +64,12 @@ bool subghz_scene_frequency_analyzer_on_event(void* context, SceneManagerEvent e } return true; - } else if(event.event == SubGhzCustomEventViewReceiverUnlock) { + } else if(event.event == SubGhzCustomEventViewFreqAnalOkLong) { // Don't need to save, we already saved on short event #ifdef FURI_DEBUG FURI_LOG_W(TAG, "Goto next scene!"); #endif + //scene_manager_set_scene_state(subghz->scene_manager, SubGhzSceneStart, 10); scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiver); return true; } diff --git a/applications/main/subghz/subghz_history.c b/applications/main/subghz/subghz_history.c index 51d5ada7d..3c018ec8b 100644 --- a/applications/main/subghz/subghz_history.c +++ b/applications/main/subghz/subghz_history.c @@ -125,6 +125,11 @@ uint8_t subghz_history_get_type_protocol(SubGhzHistory* instance, uint16_t idx) const char* subghz_history_get_protocol_name(SubGhzHistory* instance, uint16_t idx) { furi_assert(instance); SubGhzHistoryItem* item = SubGhzHistoryItemArray_get(instance->history->data, idx); + if(!item || !item->flipper_string) { + FURI_LOG_E(TAG, "Missing Item"); + furi_string_reset(instance->tmp_string); + return furi_string_get_cstr(instance->tmp_string); + } flipper_format_rewind(item->flipper_string); if(!flipper_format_read_string(item->flipper_string, "Protocol", instance->tmp_string)) { FURI_LOG_E(TAG, "Missing Protocol"); diff --git a/applications/main/subghz/views/subghz_frequency_analyzer.c b/applications/main/subghz/views/subghz_frequency_analyzer.c index 3b8c37d73..23c05e4c5 100644 --- a/applications/main/subghz/views/subghz_frequency_analyzer.c +++ b/applications/main/subghz/views/subghz_frequency_analyzer.c @@ -372,7 +372,7 @@ bool subghz_frequency_analyzer_input(InputEvent* event, void* context) { #endif if(updated) { - instance->callback(SubGhzCustomEventViewReceiverOK, instance->context); + instance->callback(SubGhzCustomEventViewFreqAnalOkShort, instance->context); } // First device receive short, then when user release button we get long @@ -385,7 +385,7 @@ bool subghz_frequency_analyzer_input(InputEvent* event, void* context) { subghz_frequency_analyzer_worker_stop(instance->worker); } - instance->callback(SubGhzCustomEventViewReceiverUnlock, instance->context); + instance->callback(SubGhzCustomEventViewFreqAnalOkLong, instance->context); } } diff --git a/firmware/targets/f7/furi_hal/furi_hal_subghz.c b/firmware/targets/f7/furi_hal/furi_hal_subghz.c index 952e840fe..6a566d471 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_subghz.c +++ b/firmware/targets/f7/furi_hal/furi_hal_subghz.c @@ -48,6 +48,11 @@ void furi_hal_subghz_select_radio_type(SubGhzRadioType state) { } bool furi_hal_subghz_init_radio_type(SubGhzRadioType state) { + if(state == SubGhzRadioInternal && furi_hal_subghz.cc1101_g0_pin == &gpio_cc1101_g0) { + return true; + } else if(state == SubGhzRadioExternal && furi_hal_subghz.cc1101_g0_pin == &gpio_cc1101_g0_ext) { + return true; + } furi_hal_spi_bus_handle_deinit(furi_hal_subghz.spi_bus_handle); if(state == SubGhzRadioInternal) {