upython_cli.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include <storage/storage.h>
  2. #include "upython.h"
  3. void mp_flipper_cli(Cli* cli, FuriString* args, void* ctx) {
  4. UNUSED(ctx);
  5. if(action != ActionNone) {
  6. printf("%s is busy!\n", TAG);
  7. return;
  8. }
  9. if(furi_string_empty(args)) {
  10. action = ActionRepl;
  11. mp_flipper_repl_execute(cli);
  12. action = ActionNone;
  13. } else {
  14. furi_string_set(file_path, args);
  15. action = ActionExec;
  16. }
  17. }
  18. void mp_flipper_cli_register(void* args) {
  19. if(args != NULL) {
  20. file_path = furi_string_alloc_set_str(args);
  21. action = ActionExec;
  22. return;
  23. } else {
  24. file_path = furi_string_alloc_set_str(APP_ASSETS_PATH("upython"));
  25. action = ActionNone;
  26. }
  27. Cli* cli = furi_record_open(RECORD_CLI);
  28. cli_add_command(cli, CLI, CliCommandFlagParallelSafe, mp_flipper_cli, NULL);
  29. furi_record_close(RECORD_CLI);
  30. }
  31. void mp_flipper_cli_unregister(void* args) {
  32. furi_string_free(file_path);
  33. if(args != NULL) {
  34. return;
  35. }
  36. Cli* cli = furi_record_open(RECORD_CLI);
  37. cli_delete_command(cli, CLI);
  38. furi_record_close(RECORD_CLI);
  39. }