unleashed-firmware/applications/main/subghz_remote/scenes/subrem_scene_remote.c

119 lines
4.6 KiB
C
Raw Normal View History

2023-05-18 10:48:25 +00:00
#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;
}
void subrem_scene_remote_on_enter(void* context) {
SubGhzRemoteApp* app = context;
2023-05-30 13:51:07 +00:00
subrem_view_remote_update_data_labels(app->subrem_remote_view, app->map_preset->subs_preset);
2023-07-14 11:16:37 +00:00
subrem_view_remote_set_radio(
app->subrem_remote_view,
2023-07-14 11:28:46 +00:00
subghz_txrx_radio_device_get(app->txrx) != SubGhzRadioDeviceTypeInternal);
2023-05-18 10:48:25 +00:00
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) {
2023-05-30 14:41:49 +00:00
if(!scene_manager_previous_scene(app->scene_manager)) {
scene_manager_stop(app->scene_manager);
view_dispatcher_stop(app->view_dispatcher);
2023-05-18 10:48:25 +00:00
}
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);
2023-05-21 20:34:42 +00:00
uint8_t chusen_sub = subrem_scene_remote_event_to_index(event.event);
app->chusen_sub = chusen_sub;
subrem_view_remote_set_state(
app->subrem_remote_view, SubRemViewRemoteStateLoading, chusen_sub);
if(subrem_tx_start_sub(app, app->map_preset->subs_preset[chusen_sub])) {
if(app->map_preset->subs_preset[chusen_sub]->type == SubGhzProtocolTypeRAW) {
subghz_txrx_set_raw_file_encoder_worker_callback_end(
app->txrx, subrem_scene_remote_raw_callback_end_tx, app);
}
2023-05-18 10:48:25 +00:00
subrem_view_remote_set_state(
2023-05-21 20:34:42 +00:00
app->subrem_remote_view, SubRemViewRemoteStateSending, chusen_sub);
2023-05-18 10:48:25 +00:00
notification_message(app->notifications, &sequence_blink_start_magenta);
} else {
2023-05-21 20:34:42 +00:00
subrem_view_remote_set_state(
app->subrem_remote_view, SubRemViewRemoteStateIdle, 0);
2023-06-21 08:24:16 +00:00
notification_message(app->notifications, &sequence_blink_red_100);
2023-05-18 10:48:25 +00:00
}
return true;
} else if(event.event == SubRemCustomEventViewRemoteForcedStop) {
subrem_tx_stop_sub(app, true);
2023-05-21 20:34:42 +00:00
subrem_view_remote_set_state(app->subrem_remote_view, SubRemViewRemoteStateIdle, 0);
2023-05-18 10:48:25 +00:00
notification_message(app->notifications, &sequence_blink_stop);
return true;
} else if(event.event == SubRemCustomEventViewRemoteStop) {
if(subrem_tx_stop_sub(app, false)) {
2023-05-21 20:34:42 +00:00
subrem_view_remote_set_state(
app->subrem_remote_view, SubRemViewRemoteStateIdle, 0);
2023-05-18 10:48:25 +00:00
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);
2023-05-21 20:34:42 +00:00
subrem_view_remote_set_state(app->subrem_remote_view, SubRemViewRemoteStateIdle, 0);
2023-05-18 10:48:25 +00:00
notification_message(app->notifications, &sequence_blink_stop);
}