scene_ir_select.c (1994B)
1 #include <string.h> 2 3 #include "../helpers/ir_helper.h" 4 #include "../timed_remote.h" 5 #include "timed_remote_scene.h" 6 7 static IrSignalList *signals; 8 9 static void 10 pick_signal(void *context, uint32_t index) 11 { 12 TimedRemoteApp *app; 13 14 app = context; 15 if (signals == NULL || index >= signals->count) 16 return; 17 18 if (app->ir != NULL) 19 infrared_signal_free(app->ir); 20 21 app->ir = infrared_signal_alloc(); 22 if (app->ir == NULL) 23 return; 24 25 infrared_signal_set_signal(app->ir, signals->items[index].signal); 26 strncpy( 27 app->sig, 28 furi_string_get_cstr(signals->items[index].name), 29 sizeof(app->sig) - 1); 30 app->sig[sizeof(app->sig) - 1] = '\0'; 31 view_dispatcher_send_custom_event(app->vd, EVENT_SIGNAL_SELECTED); 32 } 33 34 void 35 scene_select_enter(void *context) 36 { 37 TimedRemoteApp *app; 38 size_t i; 39 40 app = context; 41 submenu_reset(app->submenu); 42 submenu_set_header(app->submenu, "Select Signal"); 43 44 signals = ir_list_alloc(); 45 if (signals == NULL) { 46 submenu_add_item(app->submenu, "(Out of memory)", 0, NULL, NULL); 47 } else if (ir_load(app->file, signals)) { 48 if (signals->count == 0) { 49 submenu_add_item( 50 app->submenu, "(No signals in file)", 0, NULL, NULL); 51 } else { 52 for (i = 0; i < signals->count; i++) { 53 submenu_add_item( 54 app->submenu, 55 furi_string_get_cstr(signals->items[i].name), 56 i, 57 pick_signal, 58 app); 59 } 60 } 61 } else { 62 submenu_add_item(app->submenu, "(Error reading file)", 0, NULL, NULL); 63 } 64 65 view_dispatcher_switch_to_view(app->vd, VIEW_MENU); 66 } 67 68 bool 69 scene_select_event(void *context, SceneManagerEvent event) 70 { 71 TimedRemoteApp *app; 72 73 app = context; 74 if (event.type != SceneManagerEventTypeCustom) 75 return false; 76 if (event.event != EVENT_SIGNAL_SELECTED) 77 return false; 78 79 scene_manager_next_scene(app->sm, SCENE_CONFIG); 80 return true; 81 } 82 83 void 84 scene_select_exit(void *context) 85 { 86 TimedRemoteApp *app; 87 88 app = context; 89 submenu_reset(app->submenu); 90 if (signals == NULL) 91 return; 92 93 ir_list_free(signals); 94 signals = NULL; 95 }