Selaa lähdekoodia

send print output to log buffer

Oliver Fabel 1 vuosi sitten
vanhempi
commit
afe5d04711
2 muutettua tiedostoa jossa 8 lisäystä ja 1 poistoa
  1. 3 1
      CHANGELOG.md
  2. 5 0
      upython.c

+ 3 - 1
CHANGELOG.md

@@ -16,7 +16,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
   * Log levels according to the Flipper Zero API: trace, debug, info, warn, error.
   * Only the root logger is supported, so no `getLogger` function.
   * Logs directly to the log output, so no output in the REPL.
-* Send output from `print` to `stdout` if script is started by `py` command from the CLI.
+* Redirect output of `print` statements:
+  * To `stdout` when a script is invoked by `py` command from the CLI.
+  * To the log buffer, if a script is invoked from the UI.
 * UART support for the `flipperzero` module.
 
 ### Changed

+ 5 - 0
upython.c

@@ -10,6 +10,10 @@ volatile Action action = ActionNone;
 FuriString* file_path = NULL;
 volatile FuriThreadStdoutWriteCallback stdout_callback = NULL;
 
+static void write_to_log_output(const char* data, size_t size) {
+    furi_log_tx((const uint8_t*)data, size);
+}
+
 void upython_reset_file_path() {
     furi_string_set(file_path, APP_ASSETS_PATH("upython"));
 }
@@ -25,6 +29,7 @@ int32_t upython(void* args) {
             break;
         case ActionOpen:
             if(upython_select_python_file(file_path)) {
+                stdout_callback = write_to_log_output;
                 action = ActionExec;
             } else {
                 upython_reset_file_path();