upython.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. static void write_to_log_output(const char* data, size_t size) {
  10. furi_log_tx((const uint8_t*)data, size);
  11. }
  12. void upython_reset_file_path() {
  13. furi_string_set(file_path, APP_ASSETS_PATH("upython"));
  14. }
  15. int32_t upython(void* args) {
  16. upython_cli_register(args);
  17. do {
  18. switch(action) {
  19. case ActionNone:
  20. action = upython_splash_screen();
  21. break;
  22. case ActionOpen:
  23. if(upython_select_python_file(file_path)) {
  24. stdout_callback = write_to_log_output;
  25. action = ActionExec;
  26. } else {
  27. upython_reset_file_path();
  28. action = ActionNone;
  29. }
  30. break;
  31. case ActionRepl:
  32. break;
  33. case ActionExec:
  34. furi_thread_set_stdout_callback(stdout_callback);
  35. upython_file_execute(file_path);
  36. upython_reset_file_path();
  37. action = ActionNone;
  38. furi_thread_set_stdout_callback(stdout_callback = NULL);
  39. break;
  40. case ActionExit:
  41. action = upython_confirm_exit_action() ? ActionTerm : ActionNone;
  42. break;
  43. case ActionTerm:
  44. break;
  45. }
  46. furi_delay_ms(1);
  47. } while(action != ActionTerm);
  48. upython_cli_unregister(args);
  49. return 0;
  50. }