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_browse.c (1683B)


      1 #include <stdio.h>
      2 
      3 #include "../helpers/ir_helper.h"
      4 #include "../timed_remote.h"
      5 #include "timed_remote_scene.h"
      6 
      7 #define IR_DIRECTORY "/ext/infrared"
      8 
      9 static FuriString **files;
     10 static size_t nfiles;
     11 
     12 static void
     13 pick_file(void *context, uint32_t index)
     14 {
     15 	TimedRemoteApp *app;
     16 
     17 	app = context;
     18 	if (index >= nfiles)
     19 		return;
     20 
     21 	snprintf(
     22 	    app->file,
     23 	    sizeof(app->file),
     24 	    "%s/%s",
     25 	    IR_DIRECTORY,
     26 	    furi_string_get_cstr(files[index]));
     27 	view_dispatcher_send_custom_event(app->vd, EVENT_FILE_SELECTED);
     28 }
     29 
     30 void
     31 scene_browse_enter(void *context)
     32 {
     33 	TimedRemoteApp *app;
     34 	size_t i;
     35 
     36 	app = context;
     37 	submenu_reset(app->submenu);
     38 	submenu_set_header(app->submenu, "Select IR File");
     39 
     40 	if (ir_files(IR_DIRECTORY, &files, &nfiles)) {
     41 		if (nfiles == 0) {
     42 			submenu_add_item(
     43 			    app->submenu, "(No IR files found)", 0, NULL, NULL);
     44 		} else {
     45 			for (i = 0; i < nfiles; i++) {
     46 				submenu_add_item(
     47 				    app->submenu,
     48 				    furi_string_get_cstr(files[i]),
     49 				    i,
     50 				    pick_file,
     51 				    app);
     52 			}
     53 		}
     54 	} else {
     55 		submenu_add_item(
     56 		    app->submenu, "(Error reading directory)", 0, NULL, NULL);
     57 	}
     58 
     59 	view_dispatcher_switch_to_view(app->vd, VIEW_MENU);
     60 }
     61 
     62 bool
     63 scene_browse_event(void *context, SceneManagerEvent event)
     64 {
     65 	TimedRemoteApp *app;
     66 
     67 	app = context;
     68 	if (event.type != SceneManagerEventTypeCustom)
     69 		return false;
     70 	if (event.event != EVENT_FILE_SELECTED)
     71 		return false;
     72 
     73 	scene_manager_next_scene(app->sm, SCENE_SELECT);
     74 	return true;
     75 }
     76 
     77 void
     78 scene_browse_exit(void *context)
     79 {
     80 	TimedRemoteApp *app;
     81 
     82 	app = context;
     83 	submenu_reset(app->submenu);
     84 	if (files == NULL)
     85 		return;
     86 
     87 	ir_files_free(files, nfiles);
     88 	files = NULL;
     89 	nfiles = 0;
     90 }