mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-14 16:08:35 -07:00
[FL-1913, FL-1963] SubGhz: save raw signal, add came atomo decoder (#783)
* File_Worker: getting the name of a new file with an index * SubGhz: add decoder RAW protocol * SubGhz: add view Save RAW * SubGhz: refactoring subghz custom event * SubGhz: fix syntax * SubGhz: fix error build * SubGhz: test build * SubGhz: refactoring subghz, add rename, delete, start and emulate RAW signal * SubGhz: fix triangle glitch in save raw view * SubGhz: fix receiver config scene * SubGhz: fix transfer after returning from save scene * Canvas: add font rotation * SubGhz: raw protocol encoder * SubGhz: fix error completion of transfer raw encoder * SubGhz: increased the speed of reading RAW data from a flash drive, displaying the name of the saved file in the Save RAW scene * Canvas: fix font rotation * SubGhz: fix navigation save RAW scene * SubGhz: add decode came atomo * Git: renormalize * Cleanup sources and enums * Gui: add font direction to canvas reset, canvas init sequence cleanup. * SubGhz: reorder menu. * Gui: correct canvas_set_font_direction signature Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
28
applications/subghz/helpers/subghz_custom_event.h
Normal file
28
applications/subghz/helpers/subghz_custom_event.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
typedef enum {
|
||||
SubghzCustomEventSceneDeleteSuccess = 100,
|
||||
SubghzCustomEventSceneDelete,
|
||||
SubghzCustomEventSceneReceiverInfoTxStart,
|
||||
SubghzCustomEventSceneReceiverInfoTxStop,
|
||||
SubghzCustomEventSceneReceiverInfoSave,
|
||||
SubghzCustomEventSceneSaveName,
|
||||
SubghzCustomEventSceneSaveSuccess,
|
||||
SubghzCustomEventSceneShowError,
|
||||
SubghzCustomEventSceneShowOnlyRX,
|
||||
|
||||
SubghzCustomEventViewReceverOK,
|
||||
SubghzCustomEventViewReceverConfig,
|
||||
SubghzCustomEventViewReceverBack,
|
||||
|
||||
SubghzCustomEventViewSaveRAWBack,
|
||||
SubghzCustomEventViewSaveRAWIDLE,
|
||||
SubghzCustomEventViewSaveRAWREC,
|
||||
SubghzCustomEventViewSaveRAWConfig,
|
||||
SubghzCustomEventViewSaveRAWMore,
|
||||
|
||||
SubghzCustomEventViewTransmitterBack,
|
||||
SubghzCustomEventViewTransmitterSendStart,
|
||||
SubghzCustomEventViewTransmitterSendStop,
|
||||
SubghzCustomEventViewTransmitterError,
|
||||
} SubghzCustomEvent;
|
||||
@@ -16,4 +16,5 @@ ADD_SCENE(subghz, test_static, TestStatic)
|
||||
ADD_SCENE(subghz, test_carrier, TestCarrier)
|
||||
ADD_SCENE(subghz, test_packet, TestPacket)
|
||||
ADD_SCENE(subghz, set_type, SetType)
|
||||
ADD_SCENE(subghz, frequency_analyzer, FrequencyAnalyzer)
|
||||
ADD_SCENE(subghz, frequency_analyzer, FrequencyAnalyzer)
|
||||
ADD_SCENE(subghz, save_raw, SaveRAW)
|
||||
@@ -1,15 +1,11 @@
|
||||
#include "../subghz_i.h"
|
||||
|
||||
typedef enum {
|
||||
SubGhzSceneDeleteInfoCustomEventDelete,
|
||||
} SubGhzSceneDeleteInfoCustomEvent;
|
||||
#include "../helpers/subghz_custom_event.h"
|
||||
|
||||
void subghz_scene_delete_callback(GuiButtonType result, InputType type, void* context) {
|
||||
furi_assert(context);
|
||||
SubGhz* subghz = context;
|
||||
if((result == GuiButtonTypeRight) && (type == InputTypeShort)) {
|
||||
view_dispatcher_send_custom_event(
|
||||
subghz->view_dispatcher, SubGhzSceneDeleteInfoCustomEventDelete);
|
||||
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubghzCustomEventSceneDelete);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +49,7 @@ void subghz_scene_delete_on_enter(void* context) {
|
||||
bool subghz_scene_delete_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhz* subghz = context;
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SubGhzSceneDeleteInfoCustomEventDelete) {
|
||||
if(event.event == SubghzCustomEventSceneDelete) {
|
||||
memcpy(subghz->file_name_tmp, subghz->file_name, strlen(subghz->file_name));
|
||||
if(subghz_delete_file(subghz)) {
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneDeleteSuccess);
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include "../subghz_i.h"
|
||||
|
||||
#define SCENE_DELETE_SUCCESS_CUSTOM_EVENT (0UL)
|
||||
#include "../helpers/subghz_custom_event.h"
|
||||
|
||||
void subghz_scene_delete_success_popup_callback(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
view_dispatcher_send_custom_event(subghz->view_dispatcher, SCENE_DELETE_SUCCESS_CUSTOM_EVENT);
|
||||
view_dispatcher_send_custom_event(
|
||||
subghz->view_dispatcher, SubghzCustomEventSceneDeleteSuccess);
|
||||
}
|
||||
|
||||
void subghz_scene_delete_success_on_enter(void* context) {
|
||||
@@ -25,7 +25,7 @@ bool subghz_scene_delete_success_on_event(void* context, SceneManagerEvent event
|
||||
SubGhz* subghz = context;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SCENE_DELETE_SUCCESS_CUSTOM_EVENT) {
|
||||
if(event.event == SubghzCustomEventSceneDeleteSuccess) {
|
||||
return scene_manager_search_and_switch_to_previous_scene(
|
||||
subghz->scene_manager, SubGhzSceneStart);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "../subghz_i.h"
|
||||
#include "../views/subghz_frequency_analyzer.h"
|
||||
|
||||
void subghz_scene_frequency_analyzer_callback(SubghzFrequencyAnalyzerEvent event, void* context) {
|
||||
void subghz_scene_frequency_analyzer_callback(SubghzCustomEvent event, void* context) {
|
||||
furi_assert(context);
|
||||
SubGhz* subghz = context;
|
||||
view_dispatcher_send_custom_event(subghz->view_dispatcher, event);
|
||||
@@ -15,13 +15,7 @@ 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) {
|
||||
if(event.event == SubghzFrequencyAnalyzerEventOnlyRx) {
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowOnlyRx);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
//SubGhz* subghz = context;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ static void subghz_scene_receiver_update_statusbar(void* context) {
|
||||
string_clear(history_stat_str);
|
||||
}
|
||||
|
||||
void subghz_scene_receiver_callback(SubghzReceverEvent event, void* context) {
|
||||
void subghz_scene_receiver_callback(SubghzCustomEvent event, void* context) {
|
||||
furi_assert(context);
|
||||
SubGhz* subghz = context;
|
||||
view_dispatcher_send_custom_event(subghz->view_dispatcher, event);
|
||||
@@ -102,8 +102,9 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) {
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
switch(event.event) {
|
||||
case SubghzReceverEventBack:
|
||||
case SubghzCustomEventViewReceverBack:
|
||||
// Stop CC1101 Rx
|
||||
subghz->state_notifications = NOTIFICATION_IDLE_STATE;
|
||||
if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
|
||||
subghz_rx_end(subghz);
|
||||
subghz_sleep(subghz);
|
||||
@@ -118,12 +119,12 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) {
|
||||
subghz->scene_manager, SubGhzSceneStart);
|
||||
return true;
|
||||
break;
|
||||
case SubghzReceverEventOK:
|
||||
case SubghzCustomEventViewReceverOK:
|
||||
subghz->txrx->idx_menu_chosen = subghz_receiver_get_idx_menu(subghz->subghz_receiver);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiverInfo);
|
||||
return true;
|
||||
break;
|
||||
case SubghzReceverEventConfig:
|
||||
case SubghzCustomEventViewReceverConfig:
|
||||
subghz->state_notifications = NOTIFICATION_IDLE_STATE;
|
||||
subghz->txrx->idx_menu_chosen = subghz_receiver_get_idx_menu(subghz->subghz_receiver);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiverConfig);
|
||||
|
||||
@@ -66,6 +66,8 @@ static void subghz_scene_receiver_config_set_frequency(VariableItem* item) {
|
||||
if(subghz->txrx->hopper_state == SubGhzHopperStateOFF) {
|
||||
variable_item_set_current_value_text(item, subghz_frequencies_text[index]);
|
||||
subghz->txrx->frequency = subghz_frequencies[index];
|
||||
} else {
|
||||
variable_item_set_current_value_index(item, subghz_frequencies_433_92);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,22 +90,24 @@ static void subghz_scene_receiver_config_set_hopping_runing(VariableItem* item)
|
||||
subghz->scene_manager, SubGhzSceneReceiverConfig),
|
||||
subghz_frequencies_text[subghz_frequencies_433_92]);
|
||||
subghz->txrx->frequency = subghz_frequencies[subghz_frequencies_433_92];
|
||||
variable_item_set_current_value_index(
|
||||
(VariableItem*)scene_manager_get_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneReceiverConfig),
|
||||
subghz_frequencies_433_92);
|
||||
} else {
|
||||
variable_item_set_current_value_text(
|
||||
(VariableItem*)scene_manager_get_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneReceiverConfig),
|
||||
" -----");
|
||||
variable_item_set_current_value_index(
|
||||
(VariableItem*)scene_manager_get_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneReceiverConfig),
|
||||
subghz_frequencies_433_92);
|
||||
}
|
||||
|
||||
subghz->txrx->hopper_state = hopping_value[index];
|
||||
}
|
||||
|
||||
void subghz_scene_receiver_config_callback(SubghzReceverEvent event, void* context) {
|
||||
furi_assert(context);
|
||||
SubGhz* subghz = context;
|
||||
view_dispatcher_send_custom_event(subghz->view_dispatcher, event);
|
||||
}
|
||||
|
||||
void subghz_scene_receiver_config_on_enter(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
VariableItem* item;
|
||||
@@ -122,16 +126,18 @@ void subghz_scene_receiver_config_on_enter(void* context) {
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, subghz_frequencies_text[value_index]);
|
||||
|
||||
item = variable_item_list_add(
|
||||
subghz->variable_item_list,
|
||||
"Hopping:",
|
||||
HOPPING_COUNT,
|
||||
subghz_scene_receiver_config_set_hopping_runing,
|
||||
subghz);
|
||||
value_index = subghz_scene_receiver_config_hopper_value_index(
|
||||
subghz->txrx->hopper_state, hopping_value, HOPPING_COUNT, subghz);
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, hopping_text[value_index]);
|
||||
if(!scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneSaveRAW)) {
|
||||
item = variable_item_list_add(
|
||||
subghz->variable_item_list,
|
||||
"Hopping:",
|
||||
HOPPING_COUNT,
|
||||
subghz_scene_receiver_config_set_hopping_runing,
|
||||
subghz);
|
||||
value_index = subghz_scene_receiver_config_hopper_value_index(
|
||||
subghz->txrx->hopper_state, hopping_value, HOPPING_COUNT, subghz);
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, hopping_text[value_index]);
|
||||
}
|
||||
|
||||
item = variable_item_list_add(
|
||||
subghz->variable_item_list,
|
||||
@@ -155,4 +161,5 @@ bool subghz_scene_receiver_config_on_event(void* context, SceneManagerEvent even
|
||||
void subghz_scene_receiver_config_on_exit(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
variable_item_list_clean(subghz->variable_item_list);
|
||||
scene_manager_set_scene_state(subghz->scene_manager, SubGhzSceneSaveRAW, 0);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
#include "../subghz_i.h"
|
||||
|
||||
typedef enum {
|
||||
SubGhzSceneReceiverInfoCustomEventTxStart,
|
||||
SubGhzSceneReceiverInfoCustomEventTxStop,
|
||||
SubGhzSceneReceiverInfoCustomEventSave,
|
||||
} SubGhzSceneReceiverInfoCustomEvent;
|
||||
#include "../helpers/subghz_custom_event.h"
|
||||
|
||||
void subghz_scene_receiver_info_callback(GuiButtonType result, InputType type, void* context) {
|
||||
furi_assert(context);
|
||||
@@ -12,13 +7,13 @@ void subghz_scene_receiver_info_callback(GuiButtonType result, InputType type, v
|
||||
|
||||
if((result == GuiButtonTypeCenter) && (type == InputTypePress)) {
|
||||
view_dispatcher_send_custom_event(
|
||||
subghz->view_dispatcher, SubGhzSceneReceiverInfoCustomEventTxStart);
|
||||
subghz->view_dispatcher, SubghzCustomEventSceneReceiverInfoTxStart);
|
||||
} else if((result == GuiButtonTypeCenter) && (type == InputTypeRelease)) {
|
||||
view_dispatcher_send_custom_event(
|
||||
subghz->view_dispatcher, SubGhzSceneReceiverInfoCustomEventTxStop);
|
||||
subghz->view_dispatcher, SubghzCustomEventSceneReceiverInfoTxStop);
|
||||
} else if((result == GuiButtonTypeRight) && (type == InputTypeShort)) {
|
||||
view_dispatcher_send_custom_event(
|
||||
subghz->view_dispatcher, SubGhzSceneReceiverInfoCustomEventSave);
|
||||
subghz->view_dispatcher, SubghzCustomEventSceneReceiverInfoSave);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +96,7 @@ void subghz_scene_receiver_info_on_enter(void* context) {
|
||||
bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhz* subghz = context;
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SubGhzSceneReceiverInfoCustomEventTxStart) {
|
||||
if(event.event == SubghzCustomEventSceneReceiverInfoTxStart) {
|
||||
//CC1101 Stop RX -> Start TX
|
||||
if(subghz->txrx->hopper_state != SubGhzHopperStateOFF) {
|
||||
subghz->txrx->hopper_state = SubGhzHopperStatePause;
|
||||
@@ -112,7 +107,8 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event)
|
||||
if(!subghz_scene_receiver_info_update_parser(subghz)) {
|
||||
return false;
|
||||
}
|
||||
if(subghz->txrx->txrx_state == SubGhzTxRxStateIdle) {
|
||||
if(subghz->txrx->txrx_state == SubGhzTxRxStateIdle ||
|
||||
subghz->txrx->txrx_state == SubGhzTxRxStateSleep) {
|
||||
if(!subghz_tx_start(subghz)) {
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowOnlyRx);
|
||||
} else {
|
||||
@@ -120,7 +116,7 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event)
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else if(event.event == SubGhzSceneReceiverInfoCustomEventTxStop) {
|
||||
} else if(event.event == SubghzCustomEventSceneReceiverInfoTxStop) {
|
||||
//CC1101 Stop Tx -> Start RX
|
||||
subghz->state_notifications = NOTIFICATION_IDLE_STATE;
|
||||
if(subghz->txrx->txrx_state == SubGhzTxRxStateTx) {
|
||||
@@ -135,7 +131,7 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event)
|
||||
}
|
||||
subghz->state_notifications = NOTIFICATION_RX_STATE;
|
||||
return true;
|
||||
} else if(event.event == SubGhzSceneReceiverInfoCustomEventSave) {
|
||||
} else if(event.event == SubghzCustomEventSceneReceiverInfoSave) {
|
||||
//CC1101 Stop RX -> Save
|
||||
subghz->state_notifications = NOTIFICATION_IDLE_STATE;
|
||||
if(subghz->txrx->hopper_state != SubGhzHopperStateOFF) {
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
#include "../subghz_i.h"
|
||||
#include <lib/toolbox/random_name.h>
|
||||
#include "file-worker.h"
|
||||
|
||||
#define SCENE_SAVE_NAME_CUSTOM_EVENT (0UL)
|
||||
#include "../helpers/subghz_custom_event.h"
|
||||
|
||||
void subghz_scene_save_name_text_input_callback(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
view_dispatcher_send_custom_event(subghz->view_dispatcher, SCENE_SAVE_NAME_CUSTOM_EVENT);
|
||||
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubghzCustomEventSceneSaveName);
|
||||
}
|
||||
|
||||
void subghz_scene_save_name_on_enter(void* context) {
|
||||
@@ -38,12 +37,14 @@ bool subghz_scene_save_name_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhz* subghz = context;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SCENE_SAVE_NAME_CUSTOM_EVENT) {
|
||||
if(strcmp(subghz->file_name, "") &&
|
||||
subghz_save_protocol_to_file(subghz, subghz->file_name)) {
|
||||
if(event.event == SubghzCustomEventSceneSaveName) {
|
||||
if(strcmp(subghz->file_name, "")) {
|
||||
if(strcmp(subghz->file_name_tmp, "")) {
|
||||
subghz_delete_file(subghz);
|
||||
subghz_rename_file(subghz);
|
||||
} else {
|
||||
subghz_save_protocol_to_file(subghz, subghz->file_name);
|
||||
}
|
||||
|
||||
subghz_file_name_clear(subghz);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaveSuccess);
|
||||
return true;
|
||||
|
||||
169
applications/subghz/scenes/subghz_scene_save_raw.c
Normal file
169
applications/subghz/scenes/subghz_scene_save_raw.c
Normal file
@@ -0,0 +1,169 @@
|
||||
#include "../subghz_i.h"
|
||||
#include "../views/subghz_save_raw.h"
|
||||
#include <lib/subghz/protocols/subghz_protocol_raw.h>
|
||||
#include <lib/subghz/subghz_parser.h>
|
||||
|
||||
static void subghz_scene_save_raw_update_statusbar(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhz* subghz = context;
|
||||
char frequency_str[20];
|
||||
char preset_str[10];
|
||||
|
||||
snprintf(
|
||||
frequency_str,
|
||||
sizeof(frequency_str),
|
||||
"%03ld.%02ld",
|
||||
subghz->txrx->frequency / 1000000 % 1000,
|
||||
subghz->txrx->frequency / 10000 % 100);
|
||||
if(subghz->txrx->preset == FuriHalSubGhzPresetOok650Async ||
|
||||
subghz->txrx->preset == FuriHalSubGhzPresetOok270Async) {
|
||||
snprintf(preset_str, sizeof(preset_str), "AM");
|
||||
} else if(
|
||||
subghz->txrx->preset == FuriHalSubGhzPreset2FSKDev238Async ||
|
||||
subghz->txrx->preset == FuriHalSubGhzPreset2FSKDev476Async) {
|
||||
snprintf(preset_str, sizeof(preset_str), "FM");
|
||||
} else {
|
||||
furi_crash(NULL);
|
||||
}
|
||||
subghz_save_raw_add_data_statusbar(subghz->subghz_save_raw, frequency_str, preset_str);
|
||||
}
|
||||
|
||||
void subghz_scene_save_raw_callback(SubghzCustomEvent event, void* context) {
|
||||
furi_assert(context);
|
||||
SubGhz* subghz = context;
|
||||
view_dispatcher_send_custom_event(subghz->view_dispatcher, event);
|
||||
}
|
||||
|
||||
void subghz_scene_save_raw_on_enter(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
subghz_scene_save_raw_update_statusbar(subghz);
|
||||
subghz_save_raw_set_callback(subghz->subghz_save_raw, subghz_scene_save_raw_callback, subghz);
|
||||
|
||||
subghz->txrx->protocol_result = subghz_parser_get_by_name(subghz->txrx->parser, "RAW");
|
||||
furi_assert(subghz->txrx->protocol_result);
|
||||
|
||||
subghz_worker_set_pair_callback(
|
||||
subghz->txrx->worker, (SubGhzWorkerPairCallback)subghz_parser_raw_parse);
|
||||
|
||||
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewSaveRAW);
|
||||
}
|
||||
|
||||
bool subghz_scene_save_raw_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhz* subghz = context;
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
switch(event.event) {
|
||||
case SubghzCustomEventViewSaveRAWBack:
|
||||
if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
|
||||
subghz_rx_end(subghz);
|
||||
subghz_sleep(subghz);
|
||||
};
|
||||
subghz->txrx->frequency = subghz_frequencies[subghz_frequencies_433_92];
|
||||
subghz->txrx->preset = FuriHalSubGhzPresetOok650Async;
|
||||
subghz_protocol_save_raw_to_file_stop(
|
||||
(SubGhzProtocolRAW*)subghz->txrx->protocol_result);
|
||||
scene_manager_search_and_switch_to_previous_scene(
|
||||
subghz->scene_manager, SubGhzSceneStart);
|
||||
subghz->state_notifications = NOTIFICATION_IDLE_STATE;
|
||||
return true;
|
||||
break;
|
||||
case SubghzCustomEventViewSaveRAWConfig:
|
||||
scene_manager_set_scene_state(subghz->scene_manager, SubGhzSceneSaveRAW, 1);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiverConfig);
|
||||
return true;
|
||||
break;
|
||||
case SubghzCustomEventViewSaveRAWIDLE:
|
||||
if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
|
||||
subghz_rx_end(subghz);
|
||||
subghz_sleep(subghz);
|
||||
};
|
||||
subghz_protocol_save_raw_to_file_stop(
|
||||
(SubGhzProtocolRAW*)subghz->txrx->protocol_result);
|
||||
subghz->state_notifications = NOTIFICATION_IDLE_STATE;
|
||||
//send the name of the saved file to the account
|
||||
subghz_save_raw_set_file_name(
|
||||
subghz->subghz_save_raw,
|
||||
subghz_protocol_get_last_file_name(
|
||||
(SubGhzProtocolRAW*)subghz->txrx->protocol_result));
|
||||
return true;
|
||||
break;
|
||||
case SubghzCustomEventViewSaveRAWREC:
|
||||
if(subghz_protocol_save_raw_to_file_init(
|
||||
(SubGhzProtocolRAW*)subghz->txrx->protocol_result,
|
||||
"Raw",
|
||||
subghz->txrx->frequency,
|
||||
subghz->txrx->preset)) {
|
||||
if((subghz->txrx->txrx_state == SubGhzTxRxStateIdle) ||
|
||||
(subghz->txrx->txrx_state == SubGhzTxRxStateSleep)) {
|
||||
subghz_begin(subghz, subghz->txrx->preset);
|
||||
subghz_rx(subghz, subghz->txrx->frequency);
|
||||
}
|
||||
subghz->state_notifications = NOTIFICATION_RX_STATE;
|
||||
} else {
|
||||
string_set(subghz->error_str, "No SD card");
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError);
|
||||
}
|
||||
return true;
|
||||
break;
|
||||
case SubghzCustomEventViewSaveRAWMore:
|
||||
if(strcmp(
|
||||
subghz_protocol_get_last_file_name(
|
||||
(SubGhzProtocolRAW*)subghz->txrx->protocol_result),
|
||||
"")) {
|
||||
strlcpy(
|
||||
subghz->file_name,
|
||||
subghz_protocol_get_last_file_name(
|
||||
(SubGhzProtocolRAW*)subghz->txrx->protocol_result),
|
||||
strlen(subghz_protocol_get_last_file_name(
|
||||
(SubGhzProtocolRAW*)subghz->txrx->protocol_result)) +
|
||||
1);
|
||||
//set the path to read the file
|
||||
string_t temp_str;
|
||||
string_init_printf(
|
||||
temp_str,
|
||||
"%s/%s%s",
|
||||
SUBGHZ_APP_PATH_FOLDER,
|
||||
subghz->file_name,
|
||||
SUBGHZ_APP_EXTENSION);
|
||||
subghz_protocol_set_last_file_name(
|
||||
(SubGhzProtocolRAW*)subghz->txrx->protocol_result, string_get_cstr(temp_str));
|
||||
string_clear(temp_str);
|
||||
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSavedMenu);
|
||||
}
|
||||
return true;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else if(event.type == SceneManagerEventTypeTick) {
|
||||
switch(subghz->state_notifications) {
|
||||
case NOTIFICATION_RX_STATE:
|
||||
notification_message(subghz->notifications, &sequence_blink_blue_10);
|
||||
subghz_save_raw_update_sample_write(
|
||||
subghz->subghz_save_raw,
|
||||
subghz_save_protocol_raw_get_sample_write(
|
||||
(SubGhzProtocolRAW*)subghz->txrx->protocol_result));
|
||||
subghz_save_raw_add_data_rssi(subghz->subghz_save_raw, furi_hal_subghz_get_rssi());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void subghz_scene_save_raw_on_exit(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
|
||||
//Stop CC1101
|
||||
if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
|
||||
subghz_rx_end(subghz);
|
||||
subghz_sleep(subghz);
|
||||
};
|
||||
subghz->state_notifications = NOTIFICATION_IDLE_STATE;
|
||||
|
||||
//Сallback restoration
|
||||
subghz_worker_set_pair_callback(
|
||||
subghz->txrx->worker, (SubGhzWorkerPairCallback)subghz_parser_parse);
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
#include "../subghz_i.h"
|
||||
|
||||
#define SCENE_SAVE_SUCCESS_CUSTOM_EVENT (0UL)
|
||||
#include "../helpers/subghz_custom_event.h"
|
||||
|
||||
void subghz_scene_save_success_popup_callback(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
view_dispatcher_send_custom_event(subghz->view_dispatcher, SCENE_SAVE_SUCCESS_CUSTOM_EVENT);
|
||||
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubghzCustomEventSceneSaveSuccess);
|
||||
}
|
||||
|
||||
void subghz_scene_save_success_on_enter(void* context) {
|
||||
@@ -24,7 +23,7 @@ void subghz_scene_save_success_on_enter(void* context) {
|
||||
bool subghz_scene_save_success_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhz* subghz = context;
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SCENE_SAVE_SUCCESS_CUSTOM_EVENT) {
|
||||
if(event.event == SubghzCustomEventSceneSaveSuccess) {
|
||||
if(!scene_manager_search_and_switch_to_previous_scene(
|
||||
subghz->scene_manager, SubGhzSceneReceiver)) {
|
||||
scene_manager_search_and_switch_to_previous_scene(
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
#include "../subghz_i.h"
|
||||
|
||||
#define SCENE_NO_MAN_CUSTOM_EVENT (11UL)
|
||||
#include "../helpers/subghz_custom_event.h"
|
||||
|
||||
void subghz_scene_show_error_popup_callback(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
view_dispatcher_send_custom_event(subghz->view_dispatcher, SCENE_NO_MAN_CUSTOM_EVENT);
|
||||
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubghzCustomEventSceneShowError);
|
||||
}
|
||||
|
||||
void subghz_scene_show_error_on_enter(void* context) {
|
||||
@@ -24,7 +23,7 @@ void subghz_scene_show_error_on_enter(void* context) {
|
||||
bool subghz_scene_show_error_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhz* subghz = context;
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SCENE_NO_MAN_CUSTOM_EVENT) {
|
||||
if(event.event == SubghzCustomEventSceneShowError) {
|
||||
scene_manager_search_and_switch_to_previous_scene(
|
||||
subghz->scene_manager, SubGhzSceneStart);
|
||||
return true;
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
#include "../subghz_i.h"
|
||||
|
||||
#define SCENE_NO_MAN_CUSTOM_EVENT (11UL)
|
||||
#include "../helpers/subghz_custom_event.h"
|
||||
|
||||
void subghz_scene_show_only_rx_popup_callback(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
view_dispatcher_send_custom_event(subghz->view_dispatcher, SCENE_NO_MAN_CUSTOM_EVENT);
|
||||
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubghzCustomEventSceneShowOnlyRX);
|
||||
}
|
||||
|
||||
void subghz_scene_show_only_rx_on_enter(void* context) {
|
||||
@@ -30,7 +29,7 @@ void subghz_scene_show_only_rx_on_enter(void* context) {
|
||||
const bool subghz_scene_show_only_rx_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhz* subghz = context;
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SCENE_NO_MAN_CUSTOM_EVENT) {
|
||||
if(event.event == SubghzCustomEventSceneShowOnlyRX) {
|
||||
scene_manager_previous_scene(subghz->scene_manager);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
#include "../subghz_i.h"
|
||||
|
||||
enum SubmenuIndex {
|
||||
SubmenuIndexRead,
|
||||
SubmenuIndexRead = 10,
|
||||
SubmenuIndexSaved,
|
||||
SubmenuIndexTest,
|
||||
SubmenuIndexAddManualy,
|
||||
SubmenuIndexFrequencyAnalyzer,
|
||||
SubmenuIndexSaveRAW,
|
||||
};
|
||||
|
||||
void subghz_scene_start_submenu_callback(void* context, uint32_t index) {
|
||||
@@ -20,6 +21,12 @@ void subghz_scene_start_on_enter(void* context) {
|
||||
}
|
||||
submenu_add_item(
|
||||
subghz->submenu, "Read", SubmenuIndexRead, subghz_scene_start_submenu_callback, subghz);
|
||||
submenu_add_item(
|
||||
subghz->submenu,
|
||||
"Read Raw",
|
||||
SubmenuIndexSaveRAW,
|
||||
subghz_scene_start_submenu_callback,
|
||||
subghz);
|
||||
submenu_add_item(
|
||||
subghz->submenu, "Saved", SubmenuIndexSaved, subghz_scene_start_submenu_callback, subghz);
|
||||
submenu_add_item(
|
||||
@@ -47,7 +54,12 @@ bool subghz_scene_start_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhz* subghz = context;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SubmenuIndexRead) {
|
||||
if(event.event == SubmenuIndexSaveRAW) {
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneStart, SubmenuIndexSaveRAW);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaveRAW);
|
||||
return true;
|
||||
} else if(event.event == SubmenuIndexRead) {
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneStart, SubmenuIndexRead);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiver);
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
#include "../views/subghz_transmitter.h"
|
||||
#include <lib/subghz/protocols/subghz_protocol_keeloq.h>
|
||||
|
||||
void subghz_scene_transmitter_callback(SubghzTransmitterEvent event, void* context) {
|
||||
void subghz_scene_transmitter_callback(SubghzCustomEvent event, void* context) {
|
||||
furi_assert(context);
|
||||
SubGhz* subghz = context;
|
||||
view_dispatcher_send_custom_event(subghz->view_dispatcher, event);
|
||||
}
|
||||
|
||||
static void subghz_scene_transmitter_update_data_show(void* context) {
|
||||
bool subghz_scene_transmitter_update_data_show(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
|
||||
if(subghz->txrx->protocol_result && subghz->txrx->protocol_result->get_upload_protocol) {
|
||||
@@ -51,17 +51,22 @@ static void subghz_scene_transmitter_update_data_show(void* context) {
|
||||
preset_str,
|
||||
show_button);
|
||||
string_clear(key_str);
|
||||
} else {
|
||||
string_set(subghz->error_str, "Protocol not found");
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError);
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void subghz_scene_transmitter_on_enter(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
if(!subghz_scene_transmitter_update_data_show(subghz)) {
|
||||
view_dispatcher_send_custom_event(
|
||||
subghz->view_dispatcher, SubghzCustomEventViewTransmitterError);
|
||||
}
|
||||
|
||||
subghz_transmitter_set_callback(
|
||||
subghz->subghz_transmitter, subghz_scene_transmitter_callback, subghz);
|
||||
subghz_scene_transmitter_update_data_show(subghz);
|
||||
|
||||
subghz->state_notifications = NOTIFICATION_IDLE_STATE;
|
||||
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewTransmitter);
|
||||
}
|
||||
@@ -69,7 +74,7 @@ void subghz_scene_transmitter_on_enter(void* context) {
|
||||
bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhz* subghz = context;
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SubghzTransmitterEventSendStart) {
|
||||
if(event.event == SubghzCustomEventViewTransmitterSendStart) {
|
||||
subghz->state_notifications = NOTIFICATION_IDLE_STATE;
|
||||
if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
|
||||
subghz_rx_end(subghz);
|
||||
@@ -84,18 +89,21 @@ bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent event) {
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else if(event.event == SubghzTransmitterEventSendStop) {
|
||||
} else if(event.event == SubghzCustomEventViewTransmitterSendStop) {
|
||||
subghz->state_notifications = NOTIFICATION_IDLE_STATE;
|
||||
if(subghz->txrx->txrx_state == SubGhzTxRxStateTx) {
|
||||
subghz_tx_stop(subghz);
|
||||
subghz_sleep(subghz);
|
||||
}
|
||||
return true;
|
||||
} else if(event.event == SubghzTransmitterEventBack) {
|
||||
} else if(event.event == SubghzCustomEventViewTransmitterBack) {
|
||||
subghz->state_notifications = NOTIFICATION_IDLE_STATE;
|
||||
scene_manager_search_and_switch_to_previous_scene(
|
||||
subghz->scene_manager, SubGhzSceneStart);
|
||||
return true;
|
||||
} else if(event.event == SubghzCustomEventViewTransmitterError) {
|
||||
string_set(subghz->error_str, "Protocol not found");
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError);
|
||||
}
|
||||
} else if(event.type == SceneManagerEventTypeTick) {
|
||||
if(subghz->state_notifications == NOTIFICATION_TX_STATE) {
|
||||
|
||||
@@ -140,6 +140,13 @@ SubGhz* subghz_alloc() {
|
||||
SubGhzViewFrequencyAnalyzer,
|
||||
subghz_frequency_analyzer_get_view(subghz->subghz_frequency_analyzer));
|
||||
|
||||
// Save RAW
|
||||
subghz->subghz_save_raw = subghz_save_raw_alloc();
|
||||
view_dispatcher_add_view(
|
||||
subghz->view_dispatcher,
|
||||
SubGhzViewSaveRAW,
|
||||
subghz_save_raw_get_view(subghz->subghz_save_raw));
|
||||
|
||||
// Carrier Test Module
|
||||
subghz->subghz_test_carrier = subghz_test_carrier_alloc();
|
||||
view_dispatcher_add_view(
|
||||
@@ -181,6 +188,7 @@ SubGhz* subghz_alloc() {
|
||||
|
||||
subghz_parser_load_keeloq_file(subghz->txrx->parser, "/ext/subghz/keeloq_mfcodes");
|
||||
subghz_parser_load_nice_flor_s_file(subghz->txrx->parser, "/ext/subghz/nice_floor_s_rx");
|
||||
subghz_parser_load_came_atomo_file(subghz->txrx->parser, "/ext/subghz/came_atomo");
|
||||
|
||||
//subghz_parser_enable_dump_text(subghz->protocol, subghz_text_callback, subghz);
|
||||
|
||||
@@ -226,6 +234,10 @@ void subghz_free(SubGhz* subghz) {
|
||||
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewFrequencyAnalyzer);
|
||||
subghz_frequency_analyzer_free(subghz->subghz_frequency_analyzer);
|
||||
|
||||
// Save RAW
|
||||
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewSaveRAW);
|
||||
subghz_save_raw_free(subghz->subghz_save_raw);
|
||||
|
||||
// Submenu
|
||||
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewMenu);
|
||||
submenu_free(subghz->submenu);
|
||||
|
||||
@@ -191,7 +191,7 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path) {
|
||||
break;
|
||||
}
|
||||
if(!subghz->txrx->protocol_result->to_load_protocol_from_file(
|
||||
file_worker, subghz->txrx->protocol_result)) {
|
||||
file_worker, subghz->txrx->protocol_result, string_get_cstr(path))) {
|
||||
break;
|
||||
}
|
||||
loaded = true;
|
||||
@@ -334,8 +334,10 @@ bool subghz_load_protocol_from_file(SubGhz* subghz) {
|
||||
if(subghz->txrx->protocol_result == NULL) {
|
||||
break;
|
||||
}
|
||||
if(!subghz->txrx->protocol_result->to_load_protocol_from_file(
|
||||
file_worker, subghz->txrx->protocol_result)) {
|
||||
|
||||
if(subghz->txrx->protocol_result->to_load_protocol_from_file == NULL ||
|
||||
!subghz->txrx->protocol_result->to_load_protocol_from_file(
|
||||
file_worker, subghz->txrx->protocol_result, string_get_cstr(protocol_file_name))) {
|
||||
break;
|
||||
}
|
||||
res = true;
|
||||
@@ -354,6 +356,28 @@ bool subghz_load_protocol_from_file(SubGhz* subghz) {
|
||||
return res;
|
||||
}
|
||||
|
||||
bool subghz_rename_file(SubGhz* subghz) {
|
||||
furi_assert(subghz);
|
||||
bool ret = false;
|
||||
string_t old_path;
|
||||
string_t new_path;
|
||||
|
||||
FileWorker* file_worker = file_worker_alloc(false);
|
||||
|
||||
string_init_printf(
|
||||
old_path, "%s/%s%s", SUBGHZ_APP_PATH_FOLDER, subghz->file_name_tmp, SUBGHZ_APP_EXTENSION);
|
||||
|
||||
string_init_printf(
|
||||
new_path, "%s/%s%s", SUBGHZ_APP_PATH_FOLDER, subghz->file_name, SUBGHZ_APP_EXTENSION);
|
||||
|
||||
ret = file_worker_rename(file_worker, string_get_cstr(old_path), string_get_cstr(new_path));
|
||||
string_clear(old_path);
|
||||
string_clear(new_path);
|
||||
file_worker_close(file_worker);
|
||||
file_worker_free(file_worker);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool subghz_delete_file(SubGhz* subghz) {
|
||||
furi_assert(subghz);
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "views/subghz_receiver.h"
|
||||
#include "views/subghz_transmitter.h"
|
||||
#include "views/subghz_frequency_analyzer.h"
|
||||
#include "views/subghz_save_raw.h"
|
||||
|
||||
#include "views/subghz_test_static.h"
|
||||
#include "views/subghz_test_carrier.h"
|
||||
@@ -64,6 +65,7 @@ struct SubGhzTxRx {
|
||||
SubGhzWorker* worker;
|
||||
SubGhzParser* parser;
|
||||
SubGhzProtocolCommon* protocol_result;
|
||||
//SubGhzProtocolCommon* protocol_save_raw;
|
||||
SubGhzProtocolCommonEncoder* encoder;
|
||||
uint32_t frequency;
|
||||
FuriHalSubGhzPreset preset;
|
||||
@@ -100,6 +102,7 @@ struct SubGhz {
|
||||
VariableItemList* variable_item_list;
|
||||
|
||||
SubghzFrequencyAnalyzer* subghz_frequency_analyzer;
|
||||
SubghzSaveRAW* subghz_save_raw;
|
||||
SubghzTestStatic* subghz_test_static;
|
||||
SubghzTestCarrier* subghz_test_carrier;
|
||||
SubghzTestPacket* subghz_test_packet;
|
||||
@@ -116,6 +119,7 @@ typedef enum {
|
||||
SubGhzViewTransmitter,
|
||||
SubGhzViewVariableItemList,
|
||||
SubGhzViewFrequencyAnalyzer,
|
||||
SubGhzViewSaveRAW,
|
||||
SubGhzViewStatic,
|
||||
SubGhzViewTestCarrier,
|
||||
SubGhzViewTestPacket,
|
||||
@@ -130,6 +134,7 @@ void subghz_tx_stop(SubGhz* subghz);
|
||||
bool subghz_key_load(SubGhz* subghz, const char* file_path);
|
||||
bool subghz_save_protocol_to_file(SubGhz* subghz, const char* dev_name);
|
||||
bool subghz_load_protocol_from_file(SubGhz* subghz);
|
||||
bool subghz_rename_file(SubGhz* subghz);
|
||||
bool subghz_delete_file(SubGhz* subghz);
|
||||
void subghz_file_name_clear(SubGhz* subghz);
|
||||
uint32_t subghz_random_serial(void);
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/view.h>
|
||||
|
||||
typedef enum {
|
||||
SubghzFrequencyAnalyzerEventOnlyRx,
|
||||
} SubghzFrequencyAnalyzerEvent;
|
||||
#include "../helpers/subghz_custom_event.h"
|
||||
|
||||
typedef struct SubghzFrequencyAnalyzer SubghzFrequencyAnalyzer;
|
||||
|
||||
typedef void (*SubghzFrequencyAnalyzerCallback)(SubghzFrequencyAnalyzerEvent event, void* context);
|
||||
typedef void (*SubghzFrequencyAnalyzerCallback)(SubghzCustomEvent event, void* context);
|
||||
|
||||
void subghz_frequency_analyzer_set_callback(
|
||||
SubghzFrequencyAnalyzer* subghz_frequency_analyzer,
|
||||
|
||||
@@ -181,7 +181,7 @@ bool subghz_receiver_input(InputEvent* event, void* context) {
|
||||
SubghzReceiver* subghz_receiver = context;
|
||||
|
||||
if(event->key == InputKeyBack && event->type == InputTypeShort) {
|
||||
subghz_receiver->callback(SubghzReceverEventBack, subghz_receiver->context);
|
||||
subghz_receiver->callback(SubghzCustomEventViewReceverBack, subghz_receiver->context);
|
||||
} else if(
|
||||
event->key == InputKeyUp &&
|
||||
(event->type == InputTypeShort || event->type == InputTypeRepeat)) {
|
||||
@@ -199,12 +199,13 @@ bool subghz_receiver_input(InputEvent* event, void* context) {
|
||||
return true;
|
||||
});
|
||||
} else if(event->key == InputKeyLeft && event->type == InputTypeShort) {
|
||||
subghz_receiver->callback(SubghzReceverEventConfig, subghz_receiver->context);
|
||||
subghz_receiver->callback(SubghzCustomEventViewReceverConfig, subghz_receiver->context);
|
||||
} else if(event->key == InputKeyOk && event->type == InputTypeShort) {
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubghzReceiverModel * model) {
|
||||
if(model->history_item != 0) {
|
||||
subghz_receiver->callback(SubghzReceverEventOK, subghz_receiver->context);
|
||||
subghz_receiver->callback(
|
||||
SubghzCustomEventViewReceverOK, subghz_receiver->context);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
@@ -1,16 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/view.h>
|
||||
|
||||
typedef enum {
|
||||
SubghzReceverEventOK,
|
||||
SubghzReceverEventConfig,
|
||||
SubghzReceverEventBack,
|
||||
} SubghzReceverEvent;
|
||||
#include "../helpers/subghz_custom_event.h"
|
||||
|
||||
typedef struct SubghzReceiver SubghzReceiver;
|
||||
|
||||
typedef void (*SubghzReceiverCallback)(SubghzReceverEvent event, void* context);
|
||||
typedef void (*SubghzReceiverCallback)(SubghzCustomEvent event, void* context);
|
||||
|
||||
void subghz_receiver_set_callback(
|
||||
SubghzReceiver* subghz_receiver,
|
||||
|
||||
313
applications/subghz/views/subghz_save_raw.c
Normal file
313
applications/subghz/views/subghz_save_raw.c
Normal file
@@ -0,0 +1,313 @@
|
||||
#include "subghz_save_raw.h"
|
||||
#include "../subghz_i.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <furi.h>
|
||||
#include <furi-hal.h>
|
||||
#include <input/input.h>
|
||||
#include <gui/elements.h>
|
||||
#include <lib/subghz/protocols/subghz_protocol_princeton.h>
|
||||
|
||||
#include <assets_icons.h>
|
||||
#define SUBGHZ_SAVE_RAW_RSSI_HISTORY_SIZE 100
|
||||
|
||||
typedef enum {
|
||||
SubghzSaveRAWStatusStart,
|
||||
SubghzSaveRAWStatusIDLE,
|
||||
SubghzSaveRAWStatusREC,
|
||||
SubghzSaveRAWStatusShowName,
|
||||
} SubghzSaveRAWStatus;
|
||||
|
||||
struct SubghzSaveRAW {
|
||||
View* view;
|
||||
osTimerId timer;
|
||||
SubghzSaveRAWCallback callback;
|
||||
void* context;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
string_t frequency_str;
|
||||
string_t preset_str;
|
||||
string_t sample_write;
|
||||
string_t file_name;
|
||||
uint8_t* rssi_history;
|
||||
bool rssi_history_end;
|
||||
uint8_t ind_write;
|
||||
SubghzSaveRAWStatus satus;
|
||||
} SubghzSaveRAWModel;
|
||||
|
||||
void subghz_save_raw_set_callback(
|
||||
SubghzSaveRAW* subghz_save_raw,
|
||||
SubghzSaveRAWCallback callback,
|
||||
void* context) {
|
||||
furi_assert(subghz_save_raw);
|
||||
furi_assert(callback);
|
||||
subghz_save_raw->callback = callback;
|
||||
subghz_save_raw->context = context;
|
||||
}
|
||||
|
||||
void subghz_save_raw_add_data_statusbar(
|
||||
SubghzSaveRAW* instance,
|
||||
const char* frequency_str,
|
||||
const char* preset_str) {
|
||||
furi_assert(instance);
|
||||
with_view_model(
|
||||
instance->view, (SubghzSaveRAWModel * model) {
|
||||
string_set(model->frequency_str, frequency_str);
|
||||
string_set(model->preset_str, preset_str);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
void subghz_save_raw_set_file_name(SubghzSaveRAW* instance, const char* file_name) {
|
||||
furi_assert(instance);
|
||||
with_view_model(
|
||||
instance->view, (SubghzSaveRAWModel * model) {
|
||||
string_set(model->file_name, file_name);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
static void subghz_save_raw_timer_callback(void* context) {
|
||||
furi_assert(context);
|
||||
SubghzSaveRAW* instance = context;
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubghzSaveRAWModel * model) {
|
||||
model->satus = SubghzSaveRAWStatusIDLE;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
void subghz_save_raw_add_data_rssi(SubghzSaveRAW* instance, float rssi) {
|
||||
furi_assert(instance);
|
||||
uint8_t u_rssi = 0;
|
||||
|
||||
if(rssi < -90) {
|
||||
u_rssi = 0;
|
||||
} else {
|
||||
u_rssi = (uint8_t)((rssi + 90) / 2.7);
|
||||
}
|
||||
//if(u_rssi > 34) u_rssi = 34;
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubghzSaveRAWModel * model) {
|
||||
model->rssi_history[model->ind_write++] = u_rssi;
|
||||
if(model->ind_write > SUBGHZ_SAVE_RAW_RSSI_HISTORY_SIZE) {
|
||||
model->rssi_history_end = true;
|
||||
model->ind_write = 0;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
void subghz_save_raw_update_sample_write(SubghzSaveRAW* instance, size_t sample) {
|
||||
furi_assert(instance);
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubghzSaveRAWModel * model) {
|
||||
string_printf(model->sample_write, "%d spl.", sample);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
void subghz_save_raw_draw_rssi(Canvas* canvas, SubghzSaveRAWModel* model) {
|
||||
int ind = 0;
|
||||
int base = 0;
|
||||
if(model->rssi_history_end == false) {
|
||||
for(int i = model->ind_write; i >= 0; i--) {
|
||||
canvas_draw_line(canvas, i, 47, i, 47 - model->rssi_history[i]);
|
||||
}
|
||||
if(model->ind_write > 3) {
|
||||
canvas_draw_line(canvas, model->ind_write, 47, model->ind_write, 13);
|
||||
canvas_draw_line(canvas, model->ind_write - 2, 12, model->ind_write + 2, 12);
|
||||
canvas_draw_line(canvas, model->ind_write - 1, 13, model->ind_write + 1, 13);
|
||||
}
|
||||
} else {
|
||||
base = SUBGHZ_SAVE_RAW_RSSI_HISTORY_SIZE - model->ind_write;
|
||||
for(int i = SUBGHZ_SAVE_RAW_RSSI_HISTORY_SIZE; i >= 0; i--) {
|
||||
ind = i - base;
|
||||
if(ind < 0) ind += SUBGHZ_SAVE_RAW_RSSI_HISTORY_SIZE;
|
||||
canvas_draw_line(canvas, i, 47, i, 47 - model->rssi_history[ind]);
|
||||
}
|
||||
canvas_draw_line(
|
||||
canvas, SUBGHZ_SAVE_RAW_RSSI_HISTORY_SIZE, 47, SUBGHZ_SAVE_RAW_RSSI_HISTORY_SIZE, 13);
|
||||
canvas_draw_line(
|
||||
canvas,
|
||||
SUBGHZ_SAVE_RAW_RSSI_HISTORY_SIZE - 2,
|
||||
12,
|
||||
SUBGHZ_SAVE_RAW_RSSI_HISTORY_SIZE + 2,
|
||||
12);
|
||||
canvas_draw_line(
|
||||
canvas,
|
||||
SUBGHZ_SAVE_RAW_RSSI_HISTORY_SIZE - 1,
|
||||
13,
|
||||
SUBGHZ_SAVE_RAW_RSSI_HISTORY_SIZE + 1,
|
||||
13);
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_save_raw_draw(Canvas* canvas, SubghzSaveRAWModel* model) {
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
if(model->satus != SubghzSaveRAWStatusShowName) {
|
||||
canvas_draw_str(canvas, 5, 8, string_get_cstr(model->frequency_str));
|
||||
canvas_draw_str(canvas, 40, 8, string_get_cstr(model->preset_str));
|
||||
canvas_draw_str_aligned(
|
||||
canvas, 126, 0, AlignRight, AlignTop, string_get_cstr(model->sample_write));
|
||||
} else {
|
||||
canvas_draw_str_aligned(
|
||||
canvas, 61, 1, AlignRight, AlignTop, string_get_cstr(model->file_name));
|
||||
canvas_draw_str(canvas, 65, 8, "Saved!");
|
||||
}
|
||||
|
||||
canvas_draw_line(canvas, 0, 14, 115, 14);
|
||||
subghz_save_raw_draw_rssi(canvas, model);
|
||||
canvas_draw_line(canvas, 0, 48, 115, 48);
|
||||
canvas_draw_line(canvas, 115, 14, 115, 48);
|
||||
|
||||
if(model->satus == SubghzSaveRAWStatusIDLE) {
|
||||
elements_button_left(canvas, "Config");
|
||||
elements_button_center(canvas, "REC");
|
||||
elements_button_right(canvas, "More");
|
||||
} else if(model->satus == SubghzSaveRAWStatusStart) {
|
||||
elements_button_left(canvas, "Config");
|
||||
elements_button_center(canvas, "REC");
|
||||
} else {
|
||||
elements_button_center(canvas, "Stop");
|
||||
}
|
||||
|
||||
canvas_set_font_direction(canvas, 3);
|
||||
canvas_draw_str(canvas, 126, 40, "RSSI");
|
||||
canvas_set_font_direction(canvas, 0);
|
||||
}
|
||||
|
||||
bool subghz_save_raw_input(InputEvent* event, void* context) {
|
||||
furi_assert(context);
|
||||
SubghzSaveRAW* instance = context;
|
||||
|
||||
if(event->key == InputKeyBack && event->type == InputTypeShort) {
|
||||
instance->callback(SubghzCustomEventViewSaveRAWBack, instance->context);
|
||||
} else if(event->key == InputKeyLeft && event->type == InputTypeShort) {
|
||||
with_view_model(
|
||||
instance->view, (SubghzSaveRAWModel * model) {
|
||||
if(model->satus == SubghzSaveRAWStatusIDLE ||
|
||||
model->satus == SubghzSaveRAWStatusStart) {
|
||||
instance->callback(SubghzCustomEventViewSaveRAWConfig, instance->context);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
} else if(event->key == InputKeyRight && event->type == InputTypeShort) {
|
||||
with_view_model(
|
||||
instance->view, (SubghzSaveRAWModel * model) {
|
||||
if(model->satus == SubghzSaveRAWStatusIDLE) {
|
||||
instance->callback(SubghzCustomEventViewSaveRAWMore, instance->context);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
} else if(event->key == InputKeyOk && event->type == InputTypeShort) {
|
||||
with_view_model(
|
||||
instance->view, (SubghzSaveRAWModel * model) {
|
||||
if(model->satus == SubghzSaveRAWStatusIDLE ||
|
||||
model->satus == SubghzSaveRAWStatusStart) {
|
||||
instance->callback(SubghzCustomEventViewSaveRAWREC, instance->context);
|
||||
model->satus = SubghzSaveRAWStatusREC;
|
||||
model->ind_write = 0;
|
||||
model->rssi_history_end = false;
|
||||
} else {
|
||||
instance->callback(SubghzCustomEventViewSaveRAWIDLE, instance->context);
|
||||
model->satus = SubghzSaveRAWStatusShowName;
|
||||
osTimerStart(instance->timer, 1024);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
if(event->key == InputKeyBack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void subghz_save_raw_enter(void* context) {
|
||||
furi_assert(context);
|
||||
SubghzSaveRAW* instance = context;
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubghzSaveRAWModel * model) {
|
||||
model->satus = SubghzSaveRAWStatusStart;
|
||||
model->rssi_history = furi_alloc(SUBGHZ_SAVE_RAW_RSSI_HISTORY_SIZE * sizeof(uint8_t));
|
||||
model->rssi_history_end = false;
|
||||
model->ind_write = 0;
|
||||
string_set(model->sample_write, "0 spl.");
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
void subghz_save_raw_exit(void* context) {
|
||||
furi_assert(context);
|
||||
SubghzSaveRAW* instance = context;
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubghzSaveRAWModel * model) {
|
||||
if(model->satus != SubghzSaveRAWStatusIDLE &&
|
||||
model->satus != SubghzSaveRAWStatusStart) {
|
||||
instance->callback(SubghzCustomEventViewSaveRAWIDLE, instance->context);
|
||||
model->satus = SubghzSaveRAWStatusStart;
|
||||
}
|
||||
string_clean(model->frequency_str);
|
||||
string_clean(model->preset_str);
|
||||
string_clean(model->sample_write);
|
||||
string_clean(model->file_name);
|
||||
free(model->rssi_history);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
SubghzSaveRAW* subghz_save_raw_alloc() {
|
||||
SubghzSaveRAW* instance = furi_alloc(sizeof(SubghzSaveRAW));
|
||||
|
||||
// View allocation and configuration
|
||||
instance->view = view_alloc();
|
||||
view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(SubghzSaveRAWModel));
|
||||
view_set_context(instance->view, instance);
|
||||
view_set_draw_callback(instance->view, (ViewDrawCallback)subghz_save_raw_draw);
|
||||
view_set_input_callback(instance->view, subghz_save_raw_input);
|
||||
view_set_enter_callback(instance->view, subghz_save_raw_enter);
|
||||
view_set_exit_callback(instance->view, subghz_save_raw_exit);
|
||||
|
||||
instance->timer = osTimerNew(subghz_save_raw_timer_callback, osTimerOnce, instance, NULL);
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubghzSaveRAWModel * model) {
|
||||
string_init(model->frequency_str);
|
||||
string_init(model->preset_str);
|
||||
string_init(model->sample_write);
|
||||
string_init(model->file_name);
|
||||
return true;
|
||||
});
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void subghz_save_raw_free(SubghzSaveRAW* instance) {
|
||||
furi_assert(instance);
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubghzSaveRAWModel * model) {
|
||||
string_clear(model->frequency_str);
|
||||
string_clear(model->preset_str);
|
||||
string_clear(model->sample_write);
|
||||
string_clear(model->file_name);
|
||||
return true;
|
||||
});
|
||||
osTimerDelete(instance->timer);
|
||||
view_free(instance->view);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
View* subghz_save_raw_get_view(SubghzSaveRAW* instance) {
|
||||
furi_assert(instance);
|
||||
return instance->view;
|
||||
}
|
||||
30
applications/subghz/views/subghz_save_raw.h
Normal file
30
applications/subghz/views/subghz_save_raw.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/view.h>
|
||||
#include "../helpers/subghz_custom_event.h"
|
||||
|
||||
typedef struct SubghzSaveRAW SubghzSaveRAW;
|
||||
|
||||
typedef void (*SubghzSaveRAWCallback)(SubghzCustomEvent event, void* context);
|
||||
|
||||
void subghz_save_raw_set_callback(
|
||||
SubghzSaveRAW* subghz_save_raw,
|
||||
SubghzSaveRAWCallback callback,
|
||||
void* context);
|
||||
|
||||
SubghzSaveRAW* subghz_save_raw_alloc();
|
||||
|
||||
void subghz_save_raw_free(SubghzSaveRAW* subghz_static);
|
||||
|
||||
void subghz_save_raw_add_data_statusbar(
|
||||
SubghzSaveRAW* instance,
|
||||
const char* frequency_str,
|
||||
const char* preset_str);
|
||||
|
||||
void subghz_save_raw_set_file_name(SubghzSaveRAW* instance, const char* file_name);
|
||||
|
||||
void subghz_save_raw_update_sample_write(SubghzSaveRAW* instance, size_t sample);
|
||||
|
||||
void subghz_save_raw_add_data_rssi(SubghzSaveRAW* instance, float rssi);
|
||||
|
||||
View* subghz_save_raw_get_view(SubghzSaveRAW* subghz_static);
|
||||
@@ -111,10 +111,12 @@ bool subghz_transmitter_input(InputEvent* event, void* context) {
|
||||
});
|
||||
|
||||
if(can_be_sent && event->key == InputKeyOk && event->type == InputTypePress) {
|
||||
subghz_transmitter->callback(SubghzTransmitterEventSendStart, subghz_transmitter->context);
|
||||
subghz_transmitter->callback(
|
||||
SubghzCustomEventViewTransmitterSendStart, subghz_transmitter->context);
|
||||
return true;
|
||||
} else if(can_be_sent && event->key == InputKeyOk && event->type == InputTypeRelease) {
|
||||
subghz_transmitter->callback(SubghzTransmitterEventSendStop, subghz_transmitter->context);
|
||||
subghz_transmitter->callback(
|
||||
SubghzCustomEventViewTransmitterSendStop, subghz_transmitter->context);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/view.h>
|
||||
|
||||
typedef enum {
|
||||
SubghzTransmitterEventSendStart,
|
||||
SubghzTransmitterEventSendStop,
|
||||
SubghzTransmitterEventBack,
|
||||
SubghzTransmitterEventNoMan,
|
||||
} SubghzTransmitterEvent;
|
||||
#include "../helpers/subghz_custom_event.h"
|
||||
|
||||
typedef struct SubghzTransmitter SubghzTransmitter;
|
||||
|
||||
typedef void (*SubghzTransmitterCallback)(SubghzTransmitterEvent event, void* context);
|
||||
typedef void (*SubghzTransmitterCallback)(SubghzCustomEvent event, void* context);
|
||||
|
||||
void subghz_transmitter_set_callback(
|
||||
SubghzTransmitter* subghz_transmitter,
|
||||
|
||||
Reference in New Issue
Block a user