This commit is contained in:
gid9798 2023-05-26 17:32:52 +03:00
parent 1bd7d25973
commit 14a12b02ef
7 changed files with 3 additions and 268 deletions

View File

@ -2,7 +2,6 @@
typedef enum {
//SubmenuIndex
SubmenuIndexSubRemOpenMapFile,
SubmenuIndexSubRemRemoteView,
SubmenuIndexSubRemAbout,

View File

@ -1,3 +1,2 @@
ADD_SCENE(subrem, start, Start)
ADD_SCENE(subrem, openmapfile, OpenMapFile)
ADD_SCENE(subrem, remote, Remote)
ADD_SCENE(subrem, openmapfile, OpenMapFile)

View File

@ -19,7 +19,6 @@ void subrem_scene_openmapfile_on_enter(void* context) {
#endif
}
if(load_state == SubRemLoadMapStateOK || load_state == SubRemLoadMapStateNotAllOK) {
scene_manager_next_scene(app->scene_manager, SubRemSceneRemote);
} else {
// TODO: Map Preset Reset
if(!scene_manager_search_and_switch_to_previous_scene(

View File

@ -1,130 +0,0 @@
#include "../subghz_remote_app_i.h"
#include "../views/remote.h"
#include <lib/subghz/protocols/raw.h>
#define TAG "SubRemScenRemote"
void subrem_scene_remote_callback(SubRemCustomEvent event, void* context) {
furi_assert(context);
SubGhzRemoteApp* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, event);
}
void subrem_scene_remote_raw_callback_end_tx(void* context) {
furi_assert(context);
SubGhzRemoteApp* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, SubRemCustomEventViewRemoteForcedStop);
}
static uint8_t subrem_scene_remote_event_to_index(SubRemCustomEvent event_id) {
uint8_t ret = 0;
if(event_id == SubRemCustomEventViewRemoteStartUP) {
ret = SubRemSubKeyNameUp;
} else if(event_id == SubRemCustomEventViewRemoteStartDOWN) {
ret = SubRemSubKeyNameDown;
} else if(event_id == SubRemCustomEventViewRemoteStartLEFT) {
ret = SubRemSubKeyNameLeft;
} else if(event_id == SubRemCustomEventViewRemoteStartRIGHT) {
ret = SubRemSubKeyNameRight;
} else if(event_id == SubRemCustomEventViewRemoteStartOK) {
ret = SubRemSubKeyNameOk;
}
return ret;
}
static bool subrem_scene_remote_update_data_show(void* context) {
SubGhzRemoteApp* app = context;
bool ret = false;
subrem_view_remote_add_data_to_show(
app->subrem_remote_view,
furi_string_get_cstr(app->subs_preset[0]->label),
furi_string_get_cstr(app->subs_preset[1]->label),
furi_string_get_cstr(app->subs_preset[2]->label),
furi_string_get_cstr(app->subs_preset[3]->label),
furi_string_get_cstr(app->subs_preset[4]->label));
return ret;
}
void subrem_scene_remote_on_enter(void* context) {
SubGhzRemoteApp* app = context;
subrem_scene_remote_update_data_show(app);
subrem_view_remote_set_callback(app->subrem_remote_view, subrem_scene_remote_callback, app);
view_dispatcher_switch_to_view(app->view_dispatcher, SubRemViewIDRemote);
}
bool subrem_scene_remote_on_event(void* context, SceneManagerEvent event) {
SubGhzRemoteApp* app = context;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubRemCustomEventViewRemoteBack) {
if(!scene_manager_search_and_switch_to_previous_scene(
app->scene_manager, SubRemSceneOpenMapFile)) {
if(!scene_manager_search_and_switch_to_previous_scene(
app->scene_manager, SubRemSceneStart)) {
scene_manager_stop(app->scene_manager);
view_dispatcher_stop(app->view_dispatcher);
}
}
return true;
} else if(
event.event == SubRemCustomEventViewRemoteStartUP ||
event.event == SubRemCustomEventViewRemoteStartDOWN ||
event.event == SubRemCustomEventViewRemoteStartLEFT ||
event.event == SubRemCustomEventViewRemoteStartRIGHT ||
event.event == SubRemCustomEventViewRemoteStartOK) {
// Start sending sub
subrem_tx_stop_sub(app, true);
app->chusen_sub = subrem_scene_remote_event_to_index(event.event);
subrem_view_remote_set_state(app->subrem_remote_view, SubRemViewRemoteStateLoading);
if(subrem_tx_start_sub(
app,
app->subs_preset[app->chusen_sub],
subrem_scene_remote_raw_callback_end_tx)) {
subrem_view_remote_set_presed_btn(app->subrem_remote_view, app->chusen_sub);
subrem_view_remote_set_state(
app->subrem_remote_view, SubRemViewRemoteStateSending);
notification_message(app->notifications, &sequence_blink_start_magenta);
} else {
subrem_view_remote_set_state(app->subrem_remote_view, SubRemViewRemoteStateIdle);
notification_message(app->notifications, &sequence_blink_stop);
}
return true;
} else if(event.event == SubRemCustomEventViewRemoteForcedStop) {
subrem_tx_stop_sub(app, true);
subrem_view_remote_set_presed_btn(app->subrem_remote_view, 0);
subrem_view_remote_set_state(app->subrem_remote_view, SubRemViewRemoteStateIdle);
notification_message(app->notifications, &sequence_blink_stop);
return true;
} else if(event.event == SubRemCustomEventViewRemoteStop) {
if(subrem_tx_stop_sub(app, false)) {
subrem_view_remote_set_presed_btn(app->subrem_remote_view, 0);
subrem_view_remote_set_state(app->subrem_remote_view, SubRemViewRemoteStateIdle);
notification_message(app->notifications, &sequence_blink_stop);
}
return true;
}
}
// } else if(event.type == SceneManagerEventTypeTick) {
// }
return false;
}
void subrem_scene_remote_on_exit(void* context) {
SubGhzRemoteApp* app = context;
subrem_tx_stop_sub(app, true);
subrem_view_remote_set_presed_btn(app->subrem_remote_view, 0);
subrem_view_remote_set_state(app->subrem_remote_view, SubRemViewRemoteStateIdle);
notification_message(app->notifications, &sequence_blink_stop);
}

View File

@ -13,12 +13,6 @@ void subrem_scene_start_on_enter(void* context) {
SubGhzRemoteApp* app = context;
Submenu* submenu = app->submenu;
submenu_add_item(
submenu,
"Open Map File",
SubmenuIndexSubRemOpenMapFile,
subrem_scene_start_submenu_callback,
app);
#if FURI_DEBUG
submenu_add_item(
submenu,
@ -37,7 +31,7 @@ void subrem_scene_start_on_enter(void* context) {
// TODO: set scene state in subrem alloc
// submenu_set_selected_item(
// submenu, scene_manager_get_scene_state(app->scene_manager, SubRemSceneStart));
submenu_set_selected_item(submenu, SubmenuIndexSubRemOpenMapFile);
submenu_set_selected_item(submenu, 0);
view_dispatcher_switch_to_view(app->view_dispatcher, SubRemViewSubmenu);
}
@ -47,22 +41,12 @@ bool subrem_scene_start_on_event(void* context, SceneManagerEvent event) {
SubGhzRemoteApp* app = context;
bool consumed = false;
UNUSED(app);
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubmenuIndexSubRemOpenMapFile) {
scene_manager_next_scene(app->scene_manager, SubRemSceneOpenMapFile);
consumed = true;
}
// } else if(event.event == SubmenuIndexSubRemAbout) {
// scene_manager_next_scene(app->scene_manager, SubRemSceneAbout);
// consumed = true;
// }
#if FURI_DEBUG
else if(event.event == SubmenuIndexSubRemRemoteView) {
scene_manager_next_scene(app->scene_manager, SubRemSceneRemote);
consumed = true;
}
#endif
}
return consumed;

View File

@ -163,115 +163,6 @@ bool subrem_save_protocol_to_file(FlipperFormat* flipper_format, const char* dev
return saved;
}
bool subrem_tx_start_sub(
SubGhzRemoteApp* app,
SubRemSubFilePreset* sub_preset,
SubGhzProtocolEncoderRAWCallbackEnd callback) {
furi_assert(app);
furi_assert(sub_preset);
bool ret = false;
subrem_tx_stop_sub(app, true);
if(sub_preset->type == SubGhzProtocolTypeUnknown) {
return false;
}
FURI_LOG_I(TAG, "Send %s", furi_string_get_cstr(sub_preset->label));
// subghz_custom_btn_set(SUBGHZ_CUSTOM_BTN_OK);
// keeloq_reset_original_btn();
// subghz_custom_btns_reset();
do {
flipper_format_rewind(sub_preset->fff_data); //
app->transmitter = subghz_transmitter_alloc_init(
app->environment, furi_string_get_cstr(sub_preset->protocaol_name));
if(app->transmitter) {
if(subghz_transmitter_deserialize(app->transmitter, sub_preset->fff_data) !=
SubGhzProtocolStatusOk) {
FURI_LOG_E(TAG, "Deserialize error!");
break;
}
furi_hal_subghz_reset();
furi_hal_subghz_idle();
furi_hal_subghz_load_custom_preset(sub_preset->freq_preset.data);
furi_hal_gpio_init(
furi_hal_subghz.cc1101_g0_pin, GpioModeInput, GpioPullNo, GpioSpeedLow);
furi_hal_subghz_idle();
furi_hal_subghz_set_frequency_and_path(sub_preset->freq_preset.frequency);
furi_hal_gpio_write(furi_hal_subghz.cc1101_g0_pin, false);
furi_hal_gpio_init(
furi_hal_subghz.cc1101_g0_pin, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
if(!furi_hal_subghz_tx()) {
FURI_LOG_E(TAG, "Sending not allowed");
break;
}
if(sub_preset->type == SubGhzProtocolTypeRAW) {
subghz_protocol_raw_file_encoder_worker_set_callback_end(
(SubGhzProtocolEncoderRAW*)subghz_transmitter_get_protocol_instance(
app->transmitter),
callback,
app);
}
furi_hal_subghz_start_async_tx(subghz_transmitter_yield, app->transmitter);
ret = true;
}
} while(false);
app->tx_running = ret;
return ret;
}
static void subghz_tx_stop(SubGhzRemoteApp* app) {
furi_assert(app);
//Stop TX
furi_hal_subghz_stop_async_tx();
subghz_transmitter_stop(app->transmitter);
subghz_transmitter_free(app->transmitter);
furi_hal_subghz_idle();
}
bool subrem_tx_stop_sub(SubGhzRemoteApp* app, bool forced) {
furi_assert(app);
SubRemSubFilePreset* sub_preset = app->subs_preset[app->chusen_sub];
if(forced || (sub_preset->type != SubGhzProtocolTypeRAW)) {
// SubRemSubKeyTypeRawKey)) {
if(app->tx_running) {
subghz_tx_stop(app);
if(sub_preset->type == SubGhzProtocolTypeDynamic) {
subrem_save_protocol_to_file(
sub_preset->fff_data, furi_string_get_cstr(sub_preset->file_path));
// keeloq_reset_mfname();
// keeloq_reset_kl_type();
// keeloq_reset_original_btn();
// subghz_custom_btns_reset();
// star_line_reset_mfname();
// star_line_reset_kl_type();
}
app->tx_running = false;
return true;
}
}
return false;
}
static SubRemLoadMapState
subrem_map_preset_check(SubGhzRemoteApp* app, FlipperFormat* fff_data_file) {
furi_assert(app);

View File

@ -76,10 +76,3 @@ typedef struct {
} SubGhzRemoteApp;
SubRemLoadMapState subrem_load_from_file(SubGhzRemoteApp* app);
bool subrem_tx_start_sub(
SubGhzRemoteApp* app,
SubRemSubFilePreset* sub_preset,
SubGhzProtocolEncoderRAWCallbackEnd callback);
bool subrem_tx_stop_sub(SubGhzRemoteApp* app, bool forced);