Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 into mntm-dev
  • Loading branch information
Willy-JL committed Mar 15, 2024
2 parents 29aa61a + 17dd089 commit 0f821fa
Show file tree
Hide file tree
Showing 22 changed files with 218 additions and 69 deletions.
12 changes: 8 additions & 4 deletions applications/main/infrared/infrared_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ static InfraredApp* infrared_alloc() {
view_dispatcher_add_view(
view_dispatcher, InfraredViewMove, infrared_move_view_get_view(infrared->move_view));

infrared->loading = loading_alloc();
view_dispatcher_add_view(
view_dispatcher, InfraredViewLoading, loading_get_view(infrared->loading));

if(app_state->is_debug_enabled) {
infrared->debug_view = infrared_debug_view_alloc();
view_dispatcher_add_view(
Expand All @@ -204,7 +208,6 @@ static InfraredApp* infrared_alloc() {
}

infrared->button_panel = button_panel_alloc();
infrared->loading = loading_alloc();
infrared->progress = infrared_progress_view_alloc();

infrared->last_settings = infrared_last_settings_alloc();
Expand Down Expand Up @@ -253,13 +256,15 @@ static void infrared_free(InfraredApp* infrared) {
view_dispatcher_remove_view(view_dispatcher, InfraredViewMove);
infrared_move_view_free(infrared->move_view);

view_dispatcher_remove_view(view_dispatcher, InfraredViewLoading);
loading_free(infrared->loading);

if(app_state->is_debug_enabled) {
view_dispatcher_remove_view(view_dispatcher, InfraredViewDebugView);
infrared_debug_view_free(infrared->debug_view);
}

button_panel_free(infrared->button_panel);
loading_free(infrared->loading);
infrared_progress_view_free(infrared->progress);

view_dispatcher_free(view_dispatcher);
Expand Down Expand Up @@ -401,14 +406,13 @@ void infrared_tx_stop(InfraredApp* infrared) {
}

void infrared_blocking_task_start(InfraredApp* infrared, FuriThreadCallback callback) {
view_stack_add_view(infrared->view_stack, loading_get_view(infrared->loading));
view_dispatcher_switch_to_view(infrared->view_dispatcher, InfraredViewLoading);
furi_thread_set_callback(infrared->task_thread, callback);
furi_thread_start(infrared->task_thread);
}

bool infrared_blocking_task_finalize(InfraredApp* infrared) {
furi_thread_join(infrared->task_thread);
view_stack_remove_view(infrared->view_stack, loading_get_view(infrared->loading));
return furi_thread_get_return_code(infrared->task_thread);
}

Expand Down
12 changes: 7 additions & 5 deletions applications/main/infrared/infrared_app_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ typedef enum {
InfraredViewDebugView,
InfraredViewMove,
InfraredViewVariableItemList,
InfraredViewLoading,
} InfraredView;

/**
Expand Down Expand Up @@ -218,19 +219,20 @@ void infrared_tx_stop(InfraredApp* infrared);
/**
* @brief Start a blocking task in a separate thread.
*
* If a ViewStack is currently on screen, a busy "Hourglass" animation
* will be shown and no input will be accepted until completion.
* Before starting a blocking task, the current view will be replaced
* with a busy animation. All subsequent user input will be ignored.
*
* @param[in,out] infrared pointer to the application instance.
* @param[in] callback pointer to the function to be run in the thread.
*/
void infrared_blocking_task_start(InfraredApp* infrared, FuriThreadCallback callback);

/**
* @brief Wait for a blocking task to finish and receive the result.
* @brief Wait for a blocking task to finish and get the result.
*
* Upon the completion of a blocking task, the busy animation will be hidden
* and input will be accepted again.
* The busy animation shown during the infrared_blocking_task_start() call
* will NOT be hidden and WILL remain on screen. If another view is needed
* (e.g. to display the results), the caller code MUST set it explicitly.
*
* @param[in,out] infrared pointer to the application instance.
* @return true if the blocking task finished successfully, false otherwise.
Expand Down
50 changes: 43 additions & 7 deletions applications/main/infrared/infrared_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
#include "infrared_signal.h"
#include "infrared_brute_force.h"

#define INFRARED_CLI_BUF_SIZE 10
#define INFRARED_ASSETS_FOLDER "infrared/assets"
#define INFRARED_CLI_BUF_SIZE (10U)
#define INFRARED_CLI_FILE_NAME_SIZE (256U)
#define INFRARED_FILE_EXTENSION ".ir"
#define INFRARED_ASSETS_FOLDER EXT_PATH("infrared/assets")
#define INFRARED_BRUTE_FORCE_DUMMY_INDEX 0

DICT_DEF2(dict_signals, FuriString*, FURI_STRING_OPLIST, int, M_DEFAULT_OPLIST)
Expand Down Expand Up @@ -66,6 +68,37 @@ static void signal_received_callback(void* context, InfraredWorkerSignal* receiv
}
}

static void infrared_cli_print_universal_remotes(void) {
Storage* storage = furi_record_open(RECORD_STORAGE);
File* dir = storage_file_alloc(storage);

do {
if(!storage_dir_open(dir, INFRARED_ASSETS_FOLDER)) break;

FileInfo file_info;
char file_name[INFRARED_CLI_FILE_NAME_SIZE];

while(storage_dir_read(dir, &file_info, file_name, sizeof(file_name))) {
if(file_info.flags & FSF_DIRECTORY) {
continue;
}

char* file_ext = strstr(file_name, INFRARED_FILE_EXTENSION);
if((file_ext == NULL) || (strcmp(file_ext, INFRARED_FILE_EXTENSION) != 0)) {
continue;
}

*file_ext = '\0';
printf("%s ", file_name);
}

printf("\r\n");
} while(false);

storage_file_free(dir);
furi_record_close(RECORD_STORAGE);
}

static void infrared_cli_print_usage(void) {
printf("Usage:\r\n");
printf("\tir rx [raw]\r\n");
Expand All @@ -85,8 +118,9 @@ static void infrared_cli_print_usage(void) {
printf("\tir decode <input_file> [<output_file>]\r\n");
printf("\tir universal <remote_name> <signal_name>\r\n");
printf("\tir universal list <remote_name>\r\n");
// TODO FL-3496: Do not hardcode universal remote names
printf("\tAvailable universal remotes: tv audio ac projector\r\n");
printf("\tAvailable universal remotes: ");

infrared_cli_print_universal_remotes();
}

static void infrared_cli_start_ir_rx(Cli* cli, FuriString* args) {
Expand Down Expand Up @@ -211,7 +245,6 @@ static bool infrared_cli_decode_raw_signal(

size_t i;
for(i = 0; i < raw_signal->timings_size; ++i) {
// TODO FL-3523: Any infrared_check_decoder_ready() magic?
const InfraredMessage* message = infrared_decode(decoder, level, raw_signal->timings[i]);

if(message) {
Expand Down Expand Up @@ -365,7 +398,10 @@ static void infrared_cli_list_remote_signals(FuriString* remote_name) {
Storage* storage = furi_record_open(RECORD_STORAGE);
FlipperFormat* ff = flipper_format_buffered_file_alloc(storage);
FuriString* remote_path = furi_string_alloc_printf(
"%s/%s.ir", EXT_PATH(INFRARED_ASSETS_FOLDER), furi_string_get_cstr(remote_name));
"%s/%s%s",
INFRARED_ASSETS_FOLDER,
furi_string_get_cstr(remote_name),
INFRARED_FILE_EXTENSION);

do {
if(!flipper_format_buffered_file_open_existing(ff, furi_string_get_cstr(remote_path))) {
Expand Down Expand Up @@ -413,7 +449,7 @@ static void
infrared_cli_brute_force_signals(Cli* cli, FuriString* remote_name, FuriString* signal_name) {
InfraredBruteForce* brute_force = infrared_brute_force_alloc();
FuriString* remote_path = furi_string_alloc_printf(
"%s/%s.ir", EXT_PATH(INFRARED_ASSETS_FOLDER), furi_string_get_cstr(remote_name));
"%s/%s.ir", INFRARED_ASSETS_FOLDER, furi_string_get_cstr(remote_name));

infrared_brute_force_set_db_filename(brute_force, furi_string_get_cstr(remote_path));
infrared_brute_force_add_record(
Expand Down
38 changes: 38 additions & 0 deletions applications/main/infrared/resources/infrared/assets/ac.ir
Original file line number Diff line number Diff line change
Expand Up @@ -983,3 +983,41 @@ type: raw
frequency: 38000
duty_cycle: 0.330000
data: 301 132136 5036 2167 337 1766 361 689 358 692 366 684 363 1770 357 692 366 684 363 718 329 690 357 1776 361 687 360 1773 364 1767 360 689 358 1775 362 1769 357 1774 363 1768 359 1773 364 684 363 718 329 1773 364 684 363 718 329 691 356 694 364 716 331 719 328 1775 362 1769 358 1774 363 1768 359 1772 365 714 333 1770 357 1774 363 716 331 719 328 722 336 715 332 718 329 721 326 724 334 716 331 719 328 722 336 715 332 718 329 1773 364 1767 360 1772 354 1777 360 719 328 721 326 725 333 717 330 29455 5036 2139 354 1777 360 688 359 691 367 714 333 1770 356 692 366 684 363 687 360 690 357 1776 361 688 359 1773 364 1768 359 689 358 1775 362 1769 357 1774 363 1768 359 1773 364 684 363 687 360 1773 364 685 362 688 359 691 356 694 364 686 361 689 358 692 366 685 362 688 359 691 356 1777 360 1771 355 693 365 685 362 1771 355 693 365 1768 359 1773 364 1767 360 689 358 692 366 685 362 1771 355 1775 362 687 360 690 357 1775 362 687 360 690 357 693 365 716 331 689 358 1774 363 686 361 689 358 692 366 685 362 688 359 691 356 694 364 686 361 689 358 692 366 685 362 688 359 691 356 694 364 686 361 689 358 692 366 685 362 1771 355 693 365 1768 358 1773 364 684 363 687 360 690 357 693 365 1768 359 690 357 1776 361 688 359 691 356 694 364 686 361 689 358 692 366 685 362 1770 356 693 365 685 362 688 359 691 356 1777 360 1771 355 693 365 686 361 689 358 692 366 685 362 1770 356
#
# Model: Fujitsu ASYG24KMTB
#
name: Dh
type: raw
frequency: 38000
duty_cycle: 0.330000
data: 3302 1639 405 423 407 420 410 1234 405 421 409 1210 440 387 432 420 410 417 413 1231 408 1238 412 388 431 422 408 392 438 1233 406 1238 412 389 430 396 434 419 411 390 440 413 406 394 436 391 439 388 431 421 409 417 413 414 405 421 409 392 438 1233 406 421 409 417 413 414 405 395 435 418 412 388 432 421 409 1236 414 387 432 420 410 390 440 388 431 1213 437 1208 431 1239 411 1234 405 1213 437 1208 431 1214 436 1235 415 386 433 420 410 1234 405 422 408 418 412 389 431 396 434 1211 439 388 432 422 408 418 412 1233 406 1238 412 415 404 422 408 1237 413 388 432 422 408 1236 414 1205 434 1210 440 1205 434 392 438 390 440 1231 408 392 438 415 404 396 434 392 438 415 404 422 408 419 411 416 414 412 407 394 436 417 413 414 405 421 409 417 413 1232 407 419 411 390 440 1204 435 418 412 415 415 412 407 419 411 1208 431 421 409 418 412 388 432 421 409 392 438 415 404 395 435 1211 439 388 432 1213 437 416 414 386 433 1212 438 415 404 396 434 392 438 416 414 413 406 420 410 417 413 1231 409 418 412 389 430 1240 410 391 439 1205 434 420 410 390 440 387 432 420 410 417 413
#
name: Cool_hi
type: raw
frequency: 38000
duty_cycle: 0.330000
data: 3293 1649 405 396 434 419 411 1207 432 395 435 1236 414 413 406 394 436 417 413 1232 407 1212 438 415 404 396 434 419 411 1234 405 1239 411 417 413 414 405 421 409 419 411 389 430 423 407 393 437 416 414 387 432 394 436 417 413 388 431 421 409 1236 414 387 432 421 409 418 412 414 405 422 408 418 412 415 404 1240 410 391 439 414 405 421 409 419 411 1234 405 1239 411 1208 431 1239 411 1235 404 1214 436 1210 440 1205 434 419 411 416 414 1204 435 418 412 415 404 396 434 393 437 1235 404 396 434 420 410 416 414 1231 408 1210 440 387 432 421 409 1235 415 414 405 395 435 418 412 1232 407 420 410 1208 431 422 408 1237 413 415 404 396 434 419 411 416 414 413 406 420 410 417 413 414 405 421 409 418 412 415 404 422 408 419 411 416 414 413 406 1238 412 415 404 422 408 1237 413 414 405 421 409 418 412 416 414 1231 408 418 412 415 404 422 408 419 411 416 414 413 406 420 410 1235 404 423 407 420 410 1234 405 422 408 1210 440 414 405 421 409 392 438 415 404 422 408 420 410 417 413 1231 408 419 411 416 414 413 406 1237 413 415 404 1239 411 417 413 1232 407 420 410 417 413
#
name: Cool_lo
type: raw
frequency: 38000
duty_cycle: 0.330000
data: 3302 1614 440 414 405 421 409 1235 414 413 406 1238 411 415 404 422 408 419 411 1234 405 1240 409 418 412 415 404 422 408 1237 412 1232 407 420 410 417 413 414 405 422 408 419 411 416 414 413 406 420 410 417 413 414 405 421 409 418 412 415 404 1239 410 418 412 415 404 422 408 419 411 416 414 413 406 420 410 1234 405 422 408 419 411 416 414 414 405 1239 411 1207 432 1239 410 1235 414 1230 409 1236 413 1232 407 1237 412 415 415 412 407 1237 412 414 405 422 408 419 411 416 414 1231 408 419 411 416 414 413 406 1238 411 1206 433 421 409 418 412 1206 433 421 409 418 412 1206 433 1238 412 1207 432 1213 436 390 440 1232 407 420 410 417 413 414 405 421 409 418 412 415 404 422 408 419 411 416 414 413 406 421 409 418 412 415 404 422 408 419 411 1233 406 421 409 418 412 1232 407 420 410 418 412 389 430 422 408 1210 440 414 405 395 435 418 412 415 404 423 407 420 410 416 414 414 405 422 408 418 412 415 404 1240 409 1235 414 413 406 420 410 417 413 414 405 422 408 419 411 416 414 1231 408 418 412 415 404 1240 409 1209 440 387 432 1212 437 1234 405 1214 435 1209 440 1204 435
#
name: Heat_hi
type: raw
frequency: 38000
duty_cycle: 0.330000
data: 3301 1615 439 415 404 422 408 1210 439 414 405 1239 410 416 414 414 405 395 435 1209 440 1205 434 419 411 417 413 414 405 1212 437 1207 432 422 408 419 411 416 414 414 405 421 409 418 412 415 404 422 408 393 437 416 414 413 406 420 410 417 413 1205 434 420 410 417 413 414 405 421 409 418 412 415 404 422 408 1210 439 414 405 422 408 419 411 417 413 1205 434 1236 413 1206 433 1211 438 1207 432 1212 437 1209 440 1204 435 418 412 415 415 1204 435 418 412 415 404 422 408 419 411 1208 441 412 407 420 410 417 413 1205 434 1237 412 414 405 422 408 1210 439 415 404 396 434 419 411 1207 432 1213 436 417 413 1205 434 420 410 417 413 1231 408 419 411 416 414 413 406 421 409 418 412 414 405 422 408 419 411 415 404 424 406 421 409 418 412 415 404 1239 410 417 413 414 405 1239 410 416 414 413 406 422 408 419 411 1233 406 421 409 418 412 415 404 423 407 419 411 416 414 413 406 1238 411 416 414 413 406 421 409 1235 414 1230 409 418 412 415 415 412 407 420 410 417 413 414 405 422 408 1236 413 413 406 421 409 1235 414 1204 435 1210 439 1206 433 1212 437 1207 432 395 435 1236 413
#
name: Heat_lo
type: raw
frequency: 38000
duty_cycle: 0.330000
data: 3295 1646 408 420 410 390 440 1205 434 393 437 1234 405 421 409 419 411 415 415 1230 409 1210 440 414 405 421 409 418 412 1233 406 1212 437 416 414 413 406 394 436 418 412 415 404 422 408 393 437 416 414 413 406 420 410 417 413 414 405 421 409 1236 413 414 405 421 409 418 412 415 404 423 407 419 411 416 414 1231 408 418 412 415 415 412 407 421 409 1235 414 1204 435 1209 441 1205 434 1210 440 1205 434 1212 437 1207 432 395 435 419 411 1233 406 421 409 418 412 415 404 422 408 1238 411 415 404 396 434 419 411 1234 405 1239 410 417 413 414 405 1213 436 417 413 414 405 1213 436 1235 404 1214 435 1209 441 413 406 421 409 418 412 1206 433 394 436 418 412 388 431 422 408 419 411 415 415 386 433 420 410 418 412 414 405 422 408 419 411 389 430 1241 408 418 412 415 404 1240 409 417 413 414 405 395 435 419 411 1233 406 395 435 418 412 415 404 422 408 419 411 416 414 413 406 421 409 1236 413 413 406 394 436 1235 414 1230 409 418 412 415 404 422 408 420 410 417 413 414 405 421 409 1236 413 413 406 420 410 417 413 1232 407 1237 412 416 414 1230 409 1236 413 1205 434 1210 439
#
name: Off
type: raw
frequency: 38000
duty_cycle: 0.330000
data: 3302 1640 404 423 407 420 410 1212 437 390 440 1234 405 395 435 392 438 415 415 1207 432 1242 407 420 410 391 439 414 405 1243 406 1241 408 392 438 415 415 386 433 393 437 390 440 414 405 396 434 419 411 389 441 412 407 420 410 390 440 387 432 1242 407 393 437 390 440 414 405 395 435 392 438 389 430 396 434 1240 409 417 413 414 405 395 435 419 411 1237 412 389 430 396 434 393 437 416 414 387 432 394 436 1212 437 389 441 1234 405 1217 432 1241 408 1213 436 1212 437 1210 439
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ void infrared_scene_universal_common_on_enter(void* context) {
InfraredApp* infrared = context;
view_set_orientation(view_stack_get_view(infrared->view_stack), ViewOrientationVertical);
view_stack_add_view(infrared->view_stack, button_panel_get_view(infrared->button_panel));
view_dispatcher_switch_to_view(infrared->view_dispatcher, InfraredViewStack);

// Load universal remote data in background
infrared_blocking_task_start(infrared, infrared_scene_universal_common_task_callback);
Expand Down Expand Up @@ -98,6 +97,8 @@ bool infrared_scene_universal_common_on_event(void* context, SceneManagerEvent e

if(!task_success) {
scene_manager_next_scene(infrared->scene_manager, InfraredSceneErrorDatabases);
} else {
view_dispatcher_switch_to_view(infrared->view_dispatcher, InfraredViewStack);
}
}
consumed = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,7 @@ void infrared_scene_edit_delete_on_enter(void* context) {
dialog_ex_set_result_callback(dialog_ex, infrared_scene_edit_delete_dialog_result_callback);
dialog_ex_set_context(dialog_ex, context);

view_set_orientation(view_stack_get_view(infrared->view_stack), ViewOrientationHorizontal);
view_stack_add_view(infrared->view_stack, dialog_ex_get_view(infrared->dialog_ex));

view_dispatcher_switch_to_view(infrared->view_dispatcher, InfraredViewStack);
view_dispatcher_switch_to_view(infrared->view_dispatcher, InfraredViewDialogEx);
}

bool infrared_scene_edit_delete_on_event(void* context, SceneManagerEvent event) {
Expand Down Expand Up @@ -136,5 +133,5 @@ bool infrared_scene_edit_delete_on_event(void* context, SceneManagerEvent event)

void infrared_scene_edit_delete_on_exit(void* context) {
InfraredApp* infrared = context;
view_stack_remove_view(infrared->view_stack, dialog_ex_get_view(infrared->dialog_ex));
dialog_ex_reset(infrared->dialog_ex);
}
8 changes: 3 additions & 5 deletions applications/main/infrared/scenes/infrared_scene_edit_move.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ void infrared_scene_edit_move_on_enter(void* context) {
infrared_move_view_set_callback(
infrared->move_view, infrared_scene_edit_move_button_callback, infrared);

view_set_orientation(view_stack_get_view(infrared->view_stack), ViewOrientationHorizontal);
view_stack_add_view(infrared->view_stack, infrared_move_view_get_view(infrared->move_view));

view_dispatcher_switch_to_view(infrared->view_dispatcher, InfraredViewStack);
view_dispatcher_switch_to_view(infrared->view_dispatcher, InfraredViewMove);
}

bool infrared_scene_edit_move_on_event(void* context, SceneManagerEvent event) {
Expand All @@ -62,6 +59,8 @@ bool infrared_scene_edit_move_on_event(void* context, SceneManagerEvent event) {
infrared_show_error_message(infrared, "Failed to move\n\"%s\"", signal_name);
scene_manager_search_and_switch_to_previous_scene(
infrared->scene_manager, InfraredSceneRemoteList);
} else {
view_dispatcher_switch_to_view(infrared->view_dispatcher, InfraredViewMove);
}
}
consumed = true;
Expand All @@ -72,6 +71,5 @@ bool infrared_scene_edit_move_on_event(void* context, SceneManagerEvent event) {

void infrared_scene_edit_move_on_exit(void* context) {
InfraredApp* infrared = context;
view_stack_remove_view(infrared->view_stack, infrared_move_view_get_view(infrared->move_view));
infrared_move_view_reset(infrared->move_view);
}
15 changes: 5 additions & 10 deletions applications/main/infrared/scenes/infrared_scene_edit_rename.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,7 @@ void infrared_scene_edit_rename_on_enter(void* context) {
enter_name_length,
false);

view_set_orientation(view_stack_get_view(infrared->view_stack), ViewOrientationHorizontal);
view_stack_add_view(infrared->view_stack, text_input_get_view(infrared->text_input));

view_dispatcher_switch_to_view(infrared->view_dispatcher, InfraredViewStack);
view_dispatcher_switch_to_view(infrared->view_dispatcher, InfraredViewTextInput);
}

bool infrared_scene_edit_rename_on_event(void* context, SceneManagerEvent event) {
Expand Down Expand Up @@ -117,12 +114,10 @@ void infrared_scene_edit_rename_on_exit(void* context) {
InfraredApp* infrared = context;
TextInput* text_input = infrared->text_input;

view_stack_remove_view(infrared->view_stack, text_input_get_view(text_input));

void* validator_context = text_input_get_validator_callback_context(text_input);
text_input_set_validator(text_input, NULL, NULL);

ValidatorIsFile* validator_context = text_input_get_validator_callback_context(text_input);
if(validator_context) {
validator_is_file_free((ValidatorIsFile*)validator_context);
validator_is_file_free(validator_context);
}

text_input_reset(text_input);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ static void infrared_scene_remote_list_select_and_load(InfraredApp* infrared) {
infrared->dialogs, infrared->file_path, infrared->file_path, &browser_options);

if(file_selected) {
view_set_orientation(view_stack_get_view(infrared->view_stack), ViewOrientationVertical);
view_dispatcher_switch_to_view(infrared->view_dispatcher, InfraredViewStack);

// Load the remote in a separate thread
infrared_blocking_task_start(infrared, infrared_scene_remote_list_task_callback);

Expand Down
Loading

0 comments on commit 0f821fa

Please sign in to comment.