unleashed-firmware/applications/main/subghz/scenes/subghz_scene_receiver.c

290 lines
11 KiB
C
Raw Normal View History

2021-08-12 17:42:56 +03:00
#include "../subghz_i.h"
#include "../views/receiver.h"
#include <dolphin/dolphin.h>
#include <lib/subghz/protocols/bin_raw.h>
2021-08-12 17:42:56 +03:00
2022-09-28 01:01:09 +03:00
#define TAG "SubGhzSceneReceiver"
const NotificationSequence subghz_sequence_rx = {
&message_green_255,
2022-10-02 09:29:16 +03:00
&message_display_backlight_on,
&message_vibro_on,
&message_note_c6,
&message_delay_50,
&message_sound_off,
&message_vibro_off,
&message_delay_50,
NULL,
};
const NotificationSequence subghz_sequence_rx_locked = {
&message_green_255,
&message_display_backlight_on,
&message_vibro_on,
&message_note_c6,
&message_delay_50,
&message_sound_off,
&message_vibro_off,
&message_delay_500,
&message_display_backlight_off,
NULL,
};
static void subghz_scene_receiver_update_statusbar(void* context) {
SubGhz* subghz = context;
2023-05-05 03:51:16 +03:00
FuriString* history_stat_str = furi_string_alloc();
2023-05-09 15:11:54 +03:00
if(!subghz_history_get_text_space_left(subghz->history, history_stat_str)) {
2023-05-05 03:51:16 +03:00
FuriString* frequency_str = furi_string_alloc();
FuriString* modulation_str = furi_string_alloc();
#ifdef SUBGHZ_EXT_PRESET_NAME
2023-05-09 15:11:54 +03:00
if(subghz_history_get_last_index(subghz->history) > 0) {
2023-05-09 21:54:56 +03:00
subghz_txrx_get_frequency_and_modulation(
2023-05-09 19:10:56 +03:00
subghz->txrx, frequency_str, modulation_str, false);
} else {
2023-05-09 13:34:54 +03:00
FuriString* temp_str = furi_string_alloc();
2023-05-09 21:54:56 +03:00
subghz_txrx_get_frequency_and_modulation(subghz->txrx, frequency_str, temp_str, true);
furi_string_printf(
2023-02-02 22:47:50 +03:00
modulation_str,
"%s Mod: %s",
2023-06-18 20:25:40 +03:00
(subghz_txrx_radio_device_get(subghz->txrx) == SubGhzRadioDeviceTypeInternal) ?
"Int" :
"Ext",
2023-05-09 13:34:54 +03:00
furi_string_get_cstr(temp_str));
furi_string_free(temp_str);
}
#else
2023-05-09 21:54:56 +03:00
subghz_txrx_get_frequency_and_modulation(
subghz->txrx, frequency_str, modulation_str, false);
#endif
subghz_view_receiver_add_data_statusbar(
subghz->subghz_receiver,
furi_string_get_cstr(frequency_str),
furi_string_get_cstr(modulation_str),
furi_string_get_cstr(history_stat_str));
furi_string_free(frequency_str);
furi_string_free(modulation_str);
} else {
subghz_view_receiver_add_data_statusbar(
subghz->subghz_receiver, furi_string_get_cstr(history_stat_str), "", "");
subghz->state_notifications = SubGhzNotificationStateIDLE;
}
furi_string_free(history_stat_str);
2023-06-18 20:25:40 +03:00
subghz_view_receiver_set_radio_device_type(
subghz->subghz_receiver, subghz_txrx_radio_device_get(subghz->txrx));
}
void subghz_scene_receiver_callback(SubGhzCustomEvent event, void* context) {
2021-08-12 17:42:56 +03:00
furi_assert(context);
SubGhz* subghz = context;
view_dispatcher_send_custom_event(subghz->view_dispatcher, event);
}
static void subghz_scene_add_to_history_callback(
SubGhzReceiver* receiver,
SubGhzProtocolDecoderBase* decoder_base,
void* context) {
furi_assert(context);
SubGhz* subghz = context;
// The check can be moved to /lib/subghz/receiver.c, but may result in false positives
if((decoder_base->protocol->flag & subghz->ignore_filter) == 0) {
SubGhzHistory* history = subghz->history;
FuriString* item_name = furi_string_alloc();
FuriString* item_time = furi_string_alloc();
uint16_t idx = subghz_history_get_item(history);
SubGhzRadioPreset preset = subghz_txrx_get_preset(subghz->txrx);
if(subghz_history_add_to_history(history, decoder_base, &preset)) {
furi_string_reset(item_name);
furi_string_reset(item_time);
subghz->state_notifications = SubGhzNotificationStateRxDone;
subghz_history_get_text_item_menu(history, item_name, idx);
subghz_history_get_time_item_menu(history, item_time, idx);
subghz_view_receiver_add_item_to_menu(
subghz->subghz_receiver,
furi_string_get_cstr(item_name),
furi_string_get_cstr(item_time),
subghz_history_get_type_protocol(history, idx));
subghz_scene_receiver_update_statusbar(subghz);
if(subghz_history_get_text_space_left(subghz->history, NULL)) {
notification_message(subghz->notifications, &sequence_error);
}
}
subghz_receiver_reset(receiver);
furi_string_free(item_name);
furi_string_free(item_time);
subghz_rx_key_state_set(subghz, SubGhzRxKeyStateAddKey);
} else {
FURI_LOG_I(TAG, "%s protocol ignored", decoder_base->protocol->name);
}
}
void subghz_scene_receiver_on_enter(void* context) {
2021-08-12 17:42:56 +03:00
SubGhz* subghz = context;
2023-05-09 21:20:35 +03:00
SubGhzHistory* history = subghz->history;
2021-08-12 17:42:56 +03:00
2023-05-05 03:51:16 +03:00
FuriString* item_name = furi_string_alloc();
FuriString* item_time = furi_string_alloc();
if(subghz_rx_key_state_get(subghz) == SubGhzRxKeyStateIDLE) {
2023-05-09 19:10:56 +03:00
subghz_txrx_set_preset(subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0);
2023-05-09 21:20:35 +03:00
subghz_history_reset(history);
subghz_rx_key_state_set(subghz, SubGhzRxKeyStateStart);
subghz->idx_menu_chosen = 0;
}
subghz_view_receiver_set_lock(subghz->subghz_receiver, subghz_is_locked(subghz));
2022-08-28 04:46:59 +03:00
subghz_view_receiver_set_mode(subghz->subghz_receiver, SubGhzViewReceiverModeLive);
//Load history to receiver
subghz_view_receiver_exit(subghz->subghz_receiver);
2023-05-09 21:20:35 +03:00
for(uint8_t i = 0; i < subghz_history_get_item(history); i++) {
2023-04-21 03:08:38 +03:00
furi_string_reset(item_name);
furi_string_reset(item_time);
2023-05-09 21:20:35 +03:00
subghz_history_get_text_item_menu(history, item_name, i);
subghz_history_get_time_item_menu(history, item_time, i);
subghz_view_receiver_add_item_to_menu(
subghz->subghz_receiver,
2023-04-21 03:08:38 +03:00
furi_string_get_cstr(item_name),
furi_string_get_cstr(item_time),
2023-05-09 21:20:35 +03:00
subghz_history_get_type_protocol(history, i));
subghz_rx_key_state_set(subghz, SubGhzRxKeyStateAddKey);
}
2023-04-21 03:08:38 +03:00
furi_string_free(item_name);
furi_string_free(item_time);
subghz_scene_receiver_update_statusbar(subghz);
subghz_view_receiver_set_callback(
subghz->subghz_receiver, subghz_scene_receiver_callback, subghz);
2023-05-09 18:24:25 +03:00
subghz_txrx_set_rx_calback(subghz->txrx, subghz_scene_add_to_history_callback, subghz);
2021-08-12 17:42:56 +03:00
if(!subghz_history_get_text_space_left(subghz->history, NULL)) {
subghz->state_notifications = SubGhzNotificationStateRx;
}
2023-05-09 19:10:56 +03:00
subghz_txrx_rx_start(subghz->txrx);
subghz_view_receiver_set_idx_menu(subghz->subghz_receiver, subghz->idx_menu_chosen);
//to use a universal decoder, we are looking for a link to it
2023-05-09 13:34:54 +03:00
furi_check(
subghz_txrx_load_decoder_by_name_protocol(subghz->txrx, SUBGHZ_PROTOCOL_BIN_RAW_NAME));
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdReceiver);
2021-08-12 17:42:56 +03:00
}
bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) {
2021-08-12 17:42:56 +03:00
SubGhz* subghz = context;
bool consumed = false;
2021-08-12 17:42:56 +03:00
if(event.type == SceneManagerEventTypeCustom) {
// Save cursor position before going to any other dialog
subghz->idx_menu_chosen = subghz_view_receiver_get_idx_menu(subghz->subghz_receiver);
Skorp subghz signal archive (#667) * SubGhz: Add millis() furi, add subghz history struct * SubGhz: Fix subghz history * Gubghz: Fix code repeat history, add clean history * SubGhz: reading and adding keys to history * Gui: Renaming Sub 1-Ghz -> SubGhz * Archive: Renaming Sub 1-Ghz -> SubGhz * SubGhz: Add menu history, modified button for sending a signal, changed output of data about accepted protocol * Archive: Fix name subghz * SubGhz: Menu navigation * Assets: Add assets/SubGHz/icon.png * Assets: add new icons for subghz * SubGhz: Fix name Add manually scene * SubGhz: Fix load icon Read scene. rename encoder struct, rename protocol function load from file, add load raw data protocol, add info pleasant signals all protocol * SubGhz: fix memory leak * SubGhz: change of receiving frequency for read scene * SubGhz: Add save/load frequency and preset, add automatic configuration of transmit/receive to the desired frequency and modulation, add button "save" config scene * SubGhz: Fix frequency and preset, fix frequency add manualli scene, fix re-executing the parser * Furi-hal-subghz: add 2-FSK config, fix ook config 650KHz BW Tx filter * Fix formatting and release build * SubGhz: Delete read scene * SubGhz: Fix frequency add manualli scene, refactoring code * SubGhz: 2 profiles for OOK, fix broken build. * SubGhz: Add passing static codes from read scene, add notification read scene, refactoring code * SubGhz: fix assert on worker double stop. Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2021-08-28 16:51:48 +03:00
switch(event.event) {
case SubGhzCustomEventViewReceiverBack:
// Stop CC1101 Rx
subghz->state_notifications = SubGhzNotificationStateIDLE;
subghz_txrx_stop(subghz->txrx);
2023-05-09 19:10:56 +03:00
subghz_txrx_hopper_set_state(subghz->txrx, SubGhzHopperStateOFF);
2023-05-09 18:24:25 +03:00
subghz_txrx_set_rx_calback(subghz->txrx, NULL, subghz);
if(subghz_rx_key_state_get(subghz) == SubGhzRxKeyStateAddKey) {
subghz_rx_key_state_set(subghz, SubGhzRxKeyStateExit);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving);
} else {
subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE);
2023-05-09 19:10:56 +03:00
subghz_txrx_set_preset(
subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0);
scene_manager_search_and_switch_to_previous_scene(
subghz->scene_manager, SubGhzSceneStart);
}
consumed = true;
Skorp subghz signal archive (#667) * SubGhz: Add millis() furi, add subghz history struct * SubGhz: Fix subghz history * Gubghz: Fix code repeat history, add clean history * SubGhz: reading and adding keys to history * Gui: Renaming Sub 1-Ghz -> SubGhz * Archive: Renaming Sub 1-Ghz -> SubGhz * SubGhz: Add menu history, modified button for sending a signal, changed output of data about accepted protocol * Archive: Fix name subghz * SubGhz: Menu navigation * Assets: Add assets/SubGHz/icon.png * Assets: add new icons for subghz * SubGhz: Fix name Add manually scene * SubGhz: Fix load icon Read scene. rename encoder struct, rename protocol function load from file, add load raw data protocol, add info pleasant signals all protocol * SubGhz: fix memory leak * SubGhz: change of receiving frequency for read scene * SubGhz: Add save/load frequency and preset, add automatic configuration of transmit/receive to the desired frequency and modulation, add button "save" config scene * SubGhz: Fix frequency and preset, fix frequency add manualli scene, fix re-executing the parser * Furi-hal-subghz: add 2-FSK config, fix ook config 650KHz BW Tx filter * Fix formatting and release build * SubGhz: Delete read scene * SubGhz: Fix frequency add manualli scene, refactoring code * SubGhz: 2 profiles for OOK, fix broken build. * SubGhz: Add passing static codes from read scene, add notification read scene, refactoring code * SubGhz: fix assert on worker double stop. Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2021-08-28 16:51:48 +03:00
break;
case SubGhzCustomEventViewReceiverOK:
// Show file info, scene: receiver_info
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiverInfo);
dolphin_deed(DolphinDeedSubGhzReceiverInfo);
consumed = true;
Skorp subghz signal archive (#667) * SubGhz: Add millis() furi, add subghz history struct * SubGhz: Fix subghz history * Gubghz: Fix code repeat history, add clean history * SubGhz: reading and adding keys to history * Gui: Renaming Sub 1-Ghz -> SubGhz * Archive: Renaming Sub 1-Ghz -> SubGhz * SubGhz: Add menu history, modified button for sending a signal, changed output of data about accepted protocol * Archive: Fix name subghz * SubGhz: Menu navigation * Assets: Add assets/SubGHz/icon.png * Assets: add new icons for subghz * SubGhz: Fix name Add manually scene * SubGhz: Fix load icon Read scene. rename encoder struct, rename protocol function load from file, add load raw data protocol, add info pleasant signals all protocol * SubGhz: fix memory leak * SubGhz: change of receiving frequency for read scene * SubGhz: Add save/load frequency and preset, add automatic configuration of transmit/receive to the desired frequency and modulation, add button "save" config scene * SubGhz: Fix frequency and preset, fix frequency add manualli scene, fix re-executing the parser * Furi-hal-subghz: add 2-FSK config, fix ook config 650KHz BW Tx filter * Fix formatting and release build * SubGhz: Delete read scene * SubGhz: Fix frequency add manualli scene, refactoring code * SubGhz: 2 profiles for OOK, fix broken build. * SubGhz: Add passing static codes from read scene, add notification read scene, refactoring code * SubGhz: fix assert on worker double stop. Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2021-08-28 16:51:48 +03:00
break;
case SubGhzCustomEventViewReceiverDeleteItem:
subghz->state_notifications = SubGhzNotificationStateRx;
2023-02-26 04:13:28 +03:00
subghz_view_receiver_disable_draw_callback(subghz->subghz_receiver);
2023-05-09 15:11:54 +03:00
subghz_history_delete_item(subghz->history, subghz->idx_menu_chosen);
2023-02-26 04:13:28 +03:00
subghz_view_receiver_delete_element_callback(subghz->subghz_receiver);
subghz_view_receiver_enable_draw_callback(subghz->subghz_receiver);
subghz_scene_receiver_update_statusbar(subghz);
subghz->idx_menu_chosen = subghz_view_receiver_get_idx_menu(subghz->subghz_receiver);
if(subghz_history_get_last_index(subghz->history) == 0) {
subghz_rx_key_state_set(subghz, SubGhzRxKeyStateStart);
}
consumed = true;
break;
case SubGhzCustomEventViewReceiverConfig:
// Actually signals are received but SubGhzNotificationStateRx is not working inside Config Scene
2022-09-28 01:01:09 +03:00
scene_manager_set_scene_state(
subghz->scene_manager, SubGhzViewIdReceiver, SubGhzCustomEventManagerSet);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiverConfig);
consumed = true;
break;
case SubGhzCustomEventViewReceiverOffDisplay:
notification_message(subghz->notifications, &sequence_display_backlight_off);
consumed = true;
break;
case SubGhzCustomEventViewReceiverUnlock:
subghz_unlock(subghz);
consumed = true;
break;
Skorp subghz signal archive (#667) * SubGhz: Add millis() furi, add subghz history struct * SubGhz: Fix subghz history * Gubghz: Fix code repeat history, add clean history * SubGhz: reading and adding keys to history * Gui: Renaming Sub 1-Ghz -> SubGhz * Archive: Renaming Sub 1-Ghz -> SubGhz * SubGhz: Add menu history, modified button for sending a signal, changed output of data about accepted protocol * Archive: Fix name subghz * SubGhz: Menu navigation * Assets: Add assets/SubGHz/icon.png * Assets: add new icons for subghz * SubGhz: Fix name Add manually scene * SubGhz: Fix load icon Read scene. rename encoder struct, rename protocol function load from file, add load raw data protocol, add info pleasant signals all protocol * SubGhz: fix memory leak * SubGhz: change of receiving frequency for read scene * SubGhz: Add save/load frequency and preset, add automatic configuration of transmit/receive to the desired frequency and modulation, add button "save" config scene * SubGhz: Fix frequency and preset, fix frequency add manualli scene, fix re-executing the parser * Furi-hal-subghz: add 2-FSK config, fix ook config 650KHz BW Tx filter * Fix formatting and release build * SubGhz: Delete read scene * SubGhz: Fix frequency add manualli scene, refactoring code * SubGhz: 2 profiles for OOK, fix broken build. * SubGhz: Add passing static codes from read scene, add notification read scene, refactoring code * SubGhz: fix assert on worker double stop. Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2021-08-28 16:51:48 +03:00
default:
break;
}
} else if(event.type == SceneManagerEventTypeTick) {
2023-05-09 19:10:56 +03:00
if(subghz_txrx_hopper_get_state(subghz->txrx) != SubGhzHopperStateOFF) {
subghz_txrx_hopper_update(subghz->txrx);
subghz_scene_receiver_update_statusbar(subghz);
}
2023-06-18 20:25:40 +03:00
SubGhzThresholdRssiData ret_rssi = subghz_threshold_get_rssi_data(
subghz->threshold_rssi, subghz_txrx_radio_device_get_rssi(subghz->txrx));
2023-05-06 02:00:26 +03:00
subghz_receiver_rssi(subghz->subghz_receiver, ret_rssi.rssi);
subghz_protocol_decoder_bin_raw_data_input_rssi(
2023-05-09 13:34:54 +03:00
(SubGhzProtocolDecoderBinRAW*)subghz_txrx_get_decoder(subghz->txrx), ret_rssi.rssi);
Skorp subghz signal archive (#667) * SubGhz: Add millis() furi, add subghz history struct * SubGhz: Fix subghz history * Gubghz: Fix code repeat history, add clean history * SubGhz: reading and adding keys to history * Gui: Renaming Sub 1-Ghz -> SubGhz * Archive: Renaming Sub 1-Ghz -> SubGhz * SubGhz: Add menu history, modified button for sending a signal, changed output of data about accepted protocol * Archive: Fix name subghz * SubGhz: Menu navigation * Assets: Add assets/SubGHz/icon.png * Assets: add new icons for subghz * SubGhz: Fix name Add manually scene * SubGhz: Fix load icon Read scene. rename encoder struct, rename protocol function load from file, add load raw data protocol, add info pleasant signals all protocol * SubGhz: fix memory leak * SubGhz: change of receiving frequency for read scene * SubGhz: Add save/load frequency and preset, add automatic configuration of transmit/receive to the desired frequency and modulation, add button "save" config scene * SubGhz: Fix frequency and preset, fix frequency add manualli scene, fix re-executing the parser * Furi-hal-subghz: add 2-FSK config, fix ook config 650KHz BW Tx filter * Fix formatting and release build * SubGhz: Delete read scene * SubGhz: Fix frequency add manualli scene, refactoring code * SubGhz: 2 profiles for OOK, fix broken build. * SubGhz: Add passing static codes from read scene, add notification read scene, refactoring code * SubGhz: fix assert on worker double stop. Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2021-08-28 16:51:48 +03:00
switch(subghz->state_notifications) {
case SubGhzNotificationStateRx:
notification_message(subghz->notifications, &sequence_blink_cyan_10);
break;
case SubGhzNotificationStateRxDone:
if(!subghz_is_locked(subghz)) {
notification_message(subghz->notifications, &subghz_sequence_rx);
} else {
notification_message(subghz->notifications, &subghz_sequence_rx_locked);
}
subghz->state_notifications = SubGhzNotificationStateRx;
Skorp subghz signal archive (#667) * SubGhz: Add millis() furi, add subghz history struct * SubGhz: Fix subghz history * Gubghz: Fix code repeat history, add clean history * SubGhz: reading and adding keys to history * Gui: Renaming Sub 1-Ghz -> SubGhz * Archive: Renaming Sub 1-Ghz -> SubGhz * SubGhz: Add menu history, modified button for sending a signal, changed output of data about accepted protocol * Archive: Fix name subghz * SubGhz: Menu navigation * Assets: Add assets/SubGHz/icon.png * Assets: add new icons for subghz * SubGhz: Fix name Add manually scene * SubGhz: Fix load icon Read scene. rename encoder struct, rename protocol function load from file, add load raw data protocol, add info pleasant signals all protocol * SubGhz: fix memory leak * SubGhz: change of receiving frequency for read scene * SubGhz: Add save/load frequency and preset, add automatic configuration of transmit/receive to the desired frequency and modulation, add button "save" config scene * SubGhz: Fix frequency and preset, fix frequency add manualli scene, fix re-executing the parser * Furi-hal-subghz: add 2-FSK config, fix ook config 650KHz BW Tx filter * Fix formatting and release build * SubGhz: Delete read scene * SubGhz: Fix frequency add manualli scene, refactoring code * SubGhz: 2 profiles for OOK, fix broken build. * SubGhz: Add passing static codes from read scene, add notification read scene, refactoring code * SubGhz: fix assert on worker double stop. Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2021-08-28 16:51:48 +03:00
break;
default:
break;
2021-08-12 17:42:56 +03:00
}
}
return consumed;
2021-08-12 17:42:56 +03:00
}
void subghz_scene_receiver_on_exit(void* context) {
2022-09-17 20:33:26 +03:00
UNUSED(context);
2021-08-12 17:42:56 +03:00
}