-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
372 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: "lirc_converter: Build and lint" | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
paths: | ||
- ".github/workflows/build_lirc_converter.yaml" | ||
- "tools/apps/lirc_converter/**" | ||
pull_request: | ||
branches: [ master ] | ||
paths: | ||
- ".github/workflows/build_lirc_converter.yaml" | ||
- "tools/apps/lirc_converter/**" | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
strategy: | ||
matrix: | ||
sdk-version: ["release", "dev", "rc"] | ||
runs-on: ubuntu-latest | ||
name: 'ufbt: Build for ${{ matrix.sdk-version }} Branch' | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Build with ufbt | ||
uses: flipperdevices/[email protected] | ||
id: build-app | ||
with: | ||
sdk-channel: ${{ matrix.sdk-version }} | ||
app-dir: tools/apps/lirc_converter | ||
- name: Upload app artifacts | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: "lirc_converter-${{ matrix.sdk-version }}-${{ steps.build-app.outputs.suffix }}" | ||
path: ${{ steps.build-app.outputs.fap-artifacts }} | ||
- name: Lint sources | ||
uses: flipperdevices/[email protected] | ||
with: | ||
skip-setup: true | ||
task: lint | ||
app-dir: tools/apps/lirc_converter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
dist/* | ||
.vscode | ||
.clang-format | ||
.editorconfig | ||
.env | ||
.ufbt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
App( | ||
appid="lirc_converter", | ||
name="LIRC Converter", | ||
apptype=FlipperAppType.EXTERNAL, | ||
entry_point="lirc_converter_app", | ||
requires=[ | ||
"gui", | ||
"dialogs", | ||
], | ||
stack_size=10 * 1024, | ||
fap_icon_assets="icons", | ||
fap_category="Tools", | ||
fap_author="@prplecake" | ||
) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#include "lirc_converter.h" | ||
|
||
static bool lirc_converter_custom_event_callback(void* context, uint32_t event) { | ||
furi_assert(context); | ||
LIRCConverter* app = context; | ||
return scene_manager_handle_custom_event(app->scene_manager, event); | ||
} | ||
|
||
static bool lirc_converter_back_event_callback(void* context) { | ||
furi_assert(context); | ||
LIRCConverter* app = context; | ||
return scene_manager_handle_back_event(app->scene_manager); | ||
} | ||
|
||
LIRCConverter* lirc_converter_alloc() { | ||
LIRCConverter* app = malloc(sizeof(LIRCConverter)); | ||
app->gui = furi_record_open(RECORD_GUI); | ||
|
||
// Scene additions | ||
app->view_dispatcher = view_dispatcher_alloc(); | ||
view_dispatcher_enable_queue(app->view_dispatcher); | ||
|
||
app->scene_manager = scene_manager_alloc(&lirc_converter_scene_handlers, app); | ||
view_dispatcher_set_event_callback_context(app->view_dispatcher, app); | ||
view_dispatcher_set_navigation_event_callback( | ||
app->view_dispatcher, lirc_converter_back_event_callback); | ||
view_dispatcher_set_custom_event_callback( | ||
app->view_dispatcher, lirc_converter_custom_event_callback); | ||
|
||
view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen); | ||
|
||
app->widget = widget_alloc(); | ||
view_dispatcher_add_view( | ||
app->view_dispatcher, LIRCConverterViewIdWidget, widget_get_view(app->widget)); | ||
|
||
app->input_file_path = furi_string_alloc(); | ||
app->output_file_path = furi_string_alloc(); | ||
|
||
return app; | ||
} | ||
|
||
void lirc_converter_app_free(LIRCConverter* app) { | ||
furi_assert(app); | ||
|
||
// Scene manager | ||
scene_manager_free(app->scene_manager); | ||
|
||
// View dispatcher | ||
view_dispatcher_remove_view(app->view_dispatcher, LIRCConverterViewIdWidget); | ||
widget_free(app->widget); | ||
|
||
view_dispatcher_free(app->view_dispatcher); | ||
|
||
furi_string_free(app->input_file_path); | ||
furi_string_free(app->output_file_path); | ||
|
||
furi_record_close(RECORD_GUI); | ||
free(app); | ||
} | ||
|
||
extern int32_t lirc_converter_app(void* p) { | ||
LIRCConverter* app = lirc_converter_alloc(); | ||
|
||
do { | ||
if(p && strlen(p)) { | ||
furi_string_set(app->input_file_path, (const char*)p); | ||
} else { | ||
furi_string_set(app->input_file_path, LIRC_CONVERTER_APP_PATH_FOLDER); | ||
|
||
DialogsFileBrowserOptions browser_options; | ||
dialog_file_browser_set_basic_options( | ||
&browser_options, LIRC_CONVERTER_APP_EXTENSION, &I_text_10px); | ||
browser_options.hide_ext = false; | ||
|
||
DialogsApp* dialogs = furi_record_open(RECORD_DIALOGS); | ||
bool res = dialog_file_browser_show( | ||
dialogs, app->input_file_path, app->input_file_path, &browser_options); | ||
|
||
furi_record_close(RECORD_DIALOGS); | ||
if(!res) { | ||
break; | ||
} | ||
} | ||
|
||
scene_manager_next_scene(app->scene_manager, LIRCConverterSceneConvert); | ||
view_dispatcher_run(app->view_dispatcher); | ||
} while(false); | ||
|
||
lirc_converter_app_free(app); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
#include <dialogs/dialogs.h> | ||
#include <gui/gui.h> | ||
#include <gui/modules/widget.h> | ||
#include <gui/scene_manager.h> | ||
#include <gui/view_dispatcher.h> | ||
#include <bit_lib/bit_lib.h> | ||
#include "lirc_converter_icons.h" | ||
#include "scenes/lirc_converter_scene.h" | ||
|
||
#include <storage/storage.h> | ||
|
||
#define TAG "LIRC Converter" | ||
|
||
#define LIRC_CONVERTER_APP_PATH_FOLDER STORAGE_EXT_PATH_PREFIX | ||
#define LIRC_CONVERTER_APP_EXTENSION "*" | ||
|
||
typedef struct { | ||
Gui* gui; | ||
SceneManager* scene_manager; | ||
ViewDispatcher* view_dispatcher; | ||
Widget* widget; | ||
|
||
FuriString* input_file_path; | ||
FuriString* output_file_path; | ||
} LIRCConverter; | ||
|
||
typedef enum { | ||
LIRCConverterViewIdWidget, | ||
} LircConverterViewId; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include "lirc_converter_scene.h" | ||
|
||
// Generate scene on_enter handlers array | ||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter, | ||
void (*const lirc_converter_scene_on_enter_handlers[])(void*) = { | ||
#include "lirc_converter_scene_config.h" | ||
}; | ||
#undef ADD_SCENE | ||
|
||
// Generate scene on_event handlers array | ||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event, | ||
bool (*const lirc_converter_scene_on_event_handlers[])(void* context, SceneManagerEvent event) = { | ||
#include "lirc_converter_scene_config.h" | ||
}; | ||
#undef ADD_SCENE | ||
|
||
// Generate scene on_exit handlers array | ||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_exit, | ||
void (*const lirc_converter_scene_on_exit_handlers[])(void* context) = { | ||
#include "lirc_converter_scene_config.h" | ||
}; | ||
#undef ADD_SCENE | ||
|
||
// Initialize scene handlers configuration strucure | ||
const SceneManagerHandlers lirc_converter_scene_handlers = { | ||
.on_enter_handlers = lirc_converter_scene_on_enter_handlers, | ||
.on_event_handlers = lirc_converter_scene_on_event_handlers, | ||
.on_exit_handlers = lirc_converter_scene_on_exit_handlers, | ||
.scene_num = LIRCConverterSceneNum, | ||
}; | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
|
||
#include <gui/scene_manager.h> | ||
|
||
// Generate scene id and total number | ||
#define ADD_SCENE(prefix, name, id) LIRCConverterScene##id, | ||
typedef enum { | ||
#include "lirc_converter_scene_config.h" | ||
LIRCConverterSceneNum, | ||
} LIRCConverterSceneId; | ||
#undef ADD_SCENE | ||
|
||
extern const SceneManagerHandlers lirc_converter_scene_handlers; | ||
|
||
// Generate scene on_enter handlers declaration | ||
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*); | ||
#include "lirc_converter_scene_config.h" | ||
#undef ADD_SCENE | ||
|
||
// Generate scene on_event handlers declaration | ||
#define ADD_SCENE(prefix, name, id) \ | ||
bool prefix##_scene_##name##_on_event(void* context, SceneManagerEvent event); | ||
#include "lirc_converter_scene_config.h" | ||
#undef ADD_SCENE | ||
|
||
// Generate scene on_exit handlers declaration | ||
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_exit(void* context); | ||
#include "lirc_converter_scene_config.h" | ||
#undef ADD_SCENE | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ADD_SCENE(lirc_converter, convert, Convert) | ||
128 changes: 128 additions & 0 deletions
128
tools/apps/lirc_converter/scenes/lirc_converter_scene_convert.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
#include "../lirc_converter.h" | ||
|
||
#define CONVERT_MAX_FILE_SIZE 8000 | ||
|
||
void lirc_converter_scene_convert_widget_callback( | ||
GuiButtonType result, | ||
InputType type, | ||
void* context) { | ||
furi_assert(context); | ||
LIRCConverter* app = (LIRCConverter*)context; | ||
if(type == InputTypeShort) { | ||
view_dispatcher_send_custom_event(app->view_dispatcher, result); | ||
} | ||
} | ||
|
||
void lirc_converter_scene_convert_on_enter(void* context) { | ||
furi_assert(context); | ||
LIRCConverter* app = context; | ||
|
||
// Load the file | ||
FuriString* buffer; | ||
buffer = furi_string_alloc(); | ||
|
||
Storage* storage = furi_record_open(RECORD_STORAGE); | ||
File* file = storage_file_alloc(storage); | ||
|
||
FileInfo fileinfo; | ||
FS_Error error = | ||
storage_common_stat(storage, furi_string_get_cstr(app->input_file_path), &fileinfo); | ||
if(error == FSE_OK) { | ||
if((fileinfo.size < CONVERT_MAX_FILE_SIZE) && (fileinfo.size > 2)) { | ||
bool ok = storage_file_open( | ||
file, furi_string_get_cstr(app->input_file_path), FSAM_READ, FSOM_OPEN_EXISTING); | ||
if(ok) { | ||
FURI_LOG_D(TAG, "File opened successfully"); | ||
|
||
FuriString* temp_str = furi_string_alloc(); | ||
furi_string_printf( | ||
temp_str, | ||
"\e#Converting...\e#\nFile: %s\nSize: %llu bytes", | ||
furi_string_get_cstr(app->input_file_path), | ||
fileinfo.size); | ||
widget_add_text_box_element( | ||
app->widget, | ||
0, | ||
0, | ||
128, | ||
64, | ||
AlignLeft, | ||
AlignTop, | ||
furi_string_get_cstr(temp_str), | ||
false); | ||
} else { | ||
widget_add_text_box_element( | ||
app->widget, | ||
0, | ||
0, | ||
128, | ||
64, | ||
AlignLeft, | ||
AlignCenter, | ||
"\e#Error:\nStorage file read error\e#", | ||
false); | ||
} | ||
storage_file_close(file); | ||
} else if(fileinfo.size < 2) { | ||
widget_add_text_box_element( | ||
app->widget, | ||
0, | ||
0, | ||
128, | ||
64, | ||
AlignLeft, | ||
AlignCenter, | ||
"\e#Error:\nFile is too small\e#", | ||
false); | ||
} else { | ||
widget_add_text_box_element( | ||
app->widget, | ||
0, | ||
0, | ||
128, | ||
64, | ||
AlignLeft, | ||
AlignCenter, | ||
"\e#Error:\nFile is too large\e#", | ||
false); | ||
} | ||
} else { | ||
widget_add_text_box_element( | ||
app->widget, | ||
0, | ||
0, | ||
128, | ||
64, | ||
AlignLeft, | ||
AlignCenter, | ||
"\e#Error:\nFile system error\e#", | ||
false); | ||
} | ||
|
||
furi_string_free(buffer); | ||
|
||
storage_file_free(file); | ||
furi_record_close(RECORD_STORAGE); | ||
|
||
view_dispatcher_switch_to_view(app->view_dispatcher, LIRCConverterViewIdWidget); | ||
} | ||
|
||
bool lirc_converter_scene_convert_on_event(void* context, SceneManagerEvent event) { | ||
furi_assert(context); | ||
LIRCConverter* app = (LIRCConverter*)context; | ||
|
||
switch(event.type) { | ||
case SceneManagerEventTypeCustom: | ||
scene_manager_previous_scene(app->scene_manager); | ||
return true; | ||
default: | ||
return false; | ||
} | ||
} | ||
|
||
void lirc_converter_scene_convert_on_exit(void* context) { | ||
furi_assert(context); | ||
LIRCConverter* app = (LIRCConverter*)context; | ||
|
||
widget_reset(app->widget); | ||
} | ||