timed-remote

Flipper Zero app for sending delayed IR commands
git clone git://src.adamsgaard.dk/timed-remote # fast
git clone https://src.adamsgaard.dk/timed-remote.git # slow
Log | Files | Refs | README | LICENSE Back to index

scene_ir_select.c (2520B)


      1 #include "../helpers/ir_helper.h"
      2 #include "../timed_remote.h"
      3 #include "timed_remote_scene.h"
      4 
      5 static IrSignalList *signal_list = NULL;
      6 
      7 static void ir_select_callback(void *context, uint32_t index) {
      8   TimedRemoteApp *app = context;
      9   if (signal_list && index < signal_list->count) {
     10     /* Free any previous signal */
     11     if (app->ir_signal) {
     12       infrared_signal_free(app->ir_signal);
     13     }
     14     /* Copy the selected signal */
     15     app->ir_signal = infrared_signal_alloc();
     16     infrared_signal_set_signal(app->ir_signal,
     17                                signal_list->items[index].signal);
     18 
     19     /* Copy signal name */
     20     strncpy(app->signal_name,
     21             furi_string_get_cstr(signal_list->items[index].name),
     22             sizeof(app->signal_name) - 1);
     23     app->signal_name[sizeof(app->signal_name) - 1] = '\0';
     24 
     25     view_dispatcher_send_custom_event(app->view_dispatcher,
     26                                       TimedRemoteEventSignalSelected);
     27   }
     28 }
     29 
     30 void timed_remote_scene_ir_select_on_enter(void *context) {
     31   TimedRemoteApp *app = context;
     32 
     33   submenu_reset(app->submenu);
     34   submenu_set_header(app->submenu, "Select Signal");
     35 
     36   /* Load signals from selected file */
     37   signal_list = ir_signal_list_alloc();
     38   if (ir_helper_load_file(app->selected_file_path, signal_list)) {
     39     if (signal_list->count == 0) {
     40       submenu_add_item(app->submenu, "(No signals in file)", 0, NULL, NULL);
     41     } else {
     42       for (size_t i = 0; i < signal_list->count; i++) {
     43         submenu_add_item(app->submenu,
     44                          furi_string_get_cstr(signal_list->items[i].name), i,
     45                          ir_select_callback, app);
     46       }
     47     }
     48   } else {
     49     submenu_add_item(app->submenu, "(Error reading file)", 0, NULL, NULL);
     50   }
     51 
     52   view_dispatcher_switch_to_view(app->view_dispatcher, TimedRemoteViewSubmenu);
     53 }
     54 
     55 bool timed_remote_scene_ir_select_on_event(void *context,
     56                                            SceneManagerEvent event) {
     57   TimedRemoteApp *app = context;
     58   bool consumed = false;
     59 
     60   if (event.type == SceneManagerEventTypeCustom) {
     61     if (event.event == TimedRemoteEventSignalSelected) {
     62       scene_manager_next_scene(app->scene_manager,
     63                                TimedRemoteSceneTimerConfig);
     64       consumed = true;
     65     }
     66   }
     67 
     68   return consumed;
     69 }
     70 
     71 void timed_remote_scene_ir_select_on_exit(void *context) {
     72   TimedRemoteApp *app = context;
     73   submenu_reset(app->submenu);
     74 
     75   /* Free signal list */
     76   if (signal_list) {
     77     ir_signal_list_free(signal_list);
     78     signal_list = NULL;
     79   }
     80 }