upython.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include <furi.h>
  2. #include <storage/storage.h>
  3. #include <mp_flipper_runtime.h>
  4. #include <mp_flipper_compiler.h>
  5. #include "upython.h"
  6. volatile Action action = ActionNone;
  7. FuriString* file_path = NULL;
  8. volatile FuriThreadStdoutWriteCallback stdout_callback = NULL;
  9. void upython_reset_file_path() {
  10. furi_string_set(file_path, APP_ASSETS_PATH("upython"));
  11. }
  12. int32_t upython(void* args) {
  13. upython_cli_register(args);
  14. do {
  15. switch(action) {
  16. case ActionNone:
  17. action = upython_splash_screen();
  18. break;
  19. case ActionOpen:
  20. if(upython_select_python_file(file_path)) {
  21. action = ActionExec;
  22. } else {
  23. upython_reset_file_path();
  24. action = ActionNone;
  25. }
  26. break;
  27. case ActionRepl:
  28. break;
  29. case ActionExec:
  30. furi_thread_set_stdout_callback(stdout_callback);
  31. upython_file_execute(file_path);
  32. upython_reset_file_path();
  33. action = ActionNone;
  34. furi_thread_set_stdout_callback(stdout_callback = NULL);
  35. break;
  36. case ActionExit:
  37. action = upython_confirm_exit_action() ? ActionTerm : ActionNone;
  38. break;
  39. case ActionTerm:
  40. break;
  41. }
  42. furi_delay_ms(1);
  43. } while(action != ActionTerm);
  44. upython_cli_unregister(args);
  45. return 0;
  46. }