|
@@ -9,14 +9,12 @@
|
|
|
#define PYTHON_SETTINGS_VERSION 0x01
|
|
#define PYTHON_SETTINGS_VERSION 0x01
|
|
|
#define PYTHON_SETTINGS_PATH INT_PATH(".python.settings")
|
|
#define PYTHON_SETTINGS_PATH INT_PATH(".python.settings")
|
|
|
|
|
|
|
|
-int32_t py_app(void *arg)
|
|
|
|
|
-{
|
|
|
|
|
- if (arg == NULL || strlen(arg) == 0)
|
|
|
|
|
- {
|
|
|
|
|
|
|
+int32_t py_app(void* arg) {
|
|
|
|
|
+ if(arg == NULL || strlen(arg) == 0) {
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- FuriString *file_path = furi_string_alloc_printf("%s", (const char *)arg);
|
|
|
|
|
|
|
+ FuriString* file_path = furi_string_alloc_printf("%s", (const char*)arg);
|
|
|
|
|
|
|
|
py_app_file_execute(file_path);
|
|
py_app_file_execute(file_path);
|
|
|
|
|
|
|
@@ -25,21 +23,19 @@ int32_t py_app(void *arg)
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void py_app_file_execute(FuriString *file)
|
|
|
|
|
-{
|
|
|
|
|
|
|
+void py_app_file_execute(FuriString* file) {
|
|
|
size_t stack;
|
|
size_t stack;
|
|
|
|
|
|
|
|
- PyApp *app = py_app_alloc();
|
|
|
|
|
- const char *path = furi_string_get_cstr(file);
|
|
|
|
|
- FuriString *file_path = furi_string_alloc_printf("%s", path);
|
|
|
|
|
|
|
+ PyApp* app = py_app_alloc();
|
|
|
|
|
+ const char* path = furi_string_get_cstr(file);
|
|
|
|
|
+ FuriString* file_path = furi_string_alloc_printf("%s", path);
|
|
|
|
|
|
|
|
- do
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ do {
|
|
|
FURI_LOG_I(TAG, "executing script %s", path);
|
|
FURI_LOG_I(TAG, "executing script %s", path);
|
|
|
|
|
|
|
|
const size_t heap_size = memmgr_get_free_heap() * app->heap_size;
|
|
const size_t heap_size = memmgr_get_free_heap() * app->heap_size;
|
|
|
const size_t stack_size = app->stack_size;
|
|
const size_t stack_size = app->stack_size;
|
|
|
- uint8_t *heap = malloc(heap_size * sizeof(uint8_t));
|
|
|
|
|
|
|
+ uint8_t* heap = malloc(heap_size * sizeof(uint8_t));
|
|
|
|
|
|
|
|
FURI_LOG_D(TAG, "allocated memory is %zu bytes", heap_size);
|
|
FURI_LOG_D(TAG, "allocated memory is %zu bytes", heap_size);
|
|
|
FURI_LOG_D(TAG, "stack size is %zu bytes", stack_size);
|
|
FURI_LOG_D(TAG, "stack size is %zu bytes", stack_size);
|
|
@@ -56,58 +52,49 @@ void py_app_file_execute(FuriString *file)
|
|
|
|
|
|
|
|
mp_flipper_init(heap, heap_size, stack_size, &stack);
|
|
mp_flipper_init(heap, heap_size, stack_size, &stack);
|
|
|
|
|
|
|
|
- if (is_py_file)
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ if(is_py_file) {
|
|
|
mp_flipper_exec_py_file(path);
|
|
mp_flipper_exec_py_file(path);
|
|
|
- }
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ } else {
|
|
|
mp_flipper_exec_mpy_file(path);
|
|
mp_flipper_exec_mpy_file(path);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
mp_flipper_deinit();
|
|
mp_flipper_deinit();
|
|
|
|
|
|
|
|
free(heap);
|
|
free(heap);
|
|
|
- } while (false);
|
|
|
|
|
|
|
+ } while(false);
|
|
|
|
|
|
|
|
furi_string_free(file_path);
|
|
furi_string_free(file_path);
|
|
|
|
|
|
|
|
py_app_free(app);
|
|
py_app_free(app);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-PyApp *py_app_load_settings()
|
|
|
|
|
-{
|
|
|
|
|
- File *file = storage_file_alloc(furi_record_open(RECORD_STORAGE));
|
|
|
|
|
|
|
+PyApp* py_app_load_settings() {
|
|
|
|
|
+ File* file = storage_file_alloc(furi_record_open(RECORD_STORAGE));
|
|
|
|
|
|
|
|
- PyApp *settings = malloc(sizeof(PyApp));
|
|
|
|
|
|
|
+ PyApp* settings = malloc(sizeof(PyApp));
|
|
|
|
|
|
|
|
const size_t settings_size = sizeof(PyApp);
|
|
const size_t settings_size = sizeof(PyApp);
|
|
|
|
|
|
|
|
FURI_LOG_I(TAG, "loading settings from \"%s\"", PYTHON_SETTINGS_PATH);
|
|
FURI_LOG_I(TAG, "loading settings from \"%s\"", PYTHON_SETTINGS_PATH);
|
|
|
bool fs_result = storage_file_open(file, PYTHON_SETTINGS_PATH, FSAM_READ, FSOM_OPEN_EXISTING);
|
|
bool fs_result = storage_file_open(file, PYTHON_SETTINGS_PATH, FSAM_READ, FSOM_OPEN_EXISTING);
|
|
|
|
|
|
|
|
- if (fs_result)
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ if(fs_result) {
|
|
|
size_t bytes_count = storage_file_read(file, settings, settings_size);
|
|
size_t bytes_count = storage_file_read(file, settings, settings_size);
|
|
|
|
|
|
|
|
fs_result = bytes_count == settings_size;
|
|
fs_result = bytes_count == settings_size;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (fs_result)
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ if(fs_result) {
|
|
|
FURI_LOG_I(TAG, "load success");
|
|
FURI_LOG_I(TAG, "load success");
|
|
|
- }
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ } else {
|
|
|
FURI_LOG_E(TAG, "load failed, %s", storage_file_get_error_desc(file));
|
|
FURI_LOG_E(TAG, "load failed, %s", storage_file_get_error_desc(file));
|
|
|
|
|
|
|
|
- settings->heap_size = 0.3;
|
|
|
|
|
|
|
+ settings->heap_size = 0.1;
|
|
|
settings->stack_size = 1024;
|
|
settings->stack_size = 1024;
|
|
|
settings->version = PYTHON_SETTINGS_VERSION;
|
|
settings->version = PYTHON_SETTINGS_VERSION;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (fs_result && settings->version != PYTHON_SETTINGS_VERSION)
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ if(fs_result && settings->version != PYTHON_SETTINGS_VERSION) {
|
|
|
FURI_LOG_E(TAG, "version(%d != %d) mismatch", settings->version, PYTHON_SETTINGS_VERSION);
|
|
FURI_LOG_E(TAG, "version(%d != %d) mismatch", settings->version, PYTHON_SETTINGS_VERSION);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -119,9 +106,8 @@ PyApp *py_app_load_settings()
|
|
|
return settings;
|
|
return settings;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-void py_app_save_settings(PyApp *settings)
|
|
|
|
|
-{
|
|
|
|
|
- File *file = storage_file_alloc(furi_record_open(RECORD_STORAGE));
|
|
|
|
|
|
|
+void py_app_save_settings(PyApp* settings) {
|
|
|
|
|
+ File* file = storage_file_alloc(furi_record_open(RECORD_STORAGE));
|
|
|
|
|
|
|
|
const size_t settings_size = sizeof(PyApp);
|
|
const size_t settings_size = sizeof(PyApp);
|
|
|
|
|
|
|
@@ -129,19 +115,15 @@ void py_app_save_settings(PyApp *settings)
|
|
|
|
|
|
|
|
bool fs_result = storage_file_open(file, PYTHON_SETTINGS_PATH, FSAM_WRITE, FSOM_CREATE_ALWAYS);
|
|
bool fs_result = storage_file_open(file, PYTHON_SETTINGS_PATH, FSAM_WRITE, FSOM_CREATE_ALWAYS);
|
|
|
|
|
|
|
|
- if (fs_result)
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ if(fs_result) {
|
|
|
size_t bytes_count = storage_file_write(file, settings, settings_size);
|
|
size_t bytes_count = storage_file_write(file, settings, settings_size);
|
|
|
|
|
|
|
|
fs_result = bytes_count == settings_size;
|
|
fs_result = bytes_count == settings_size;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (fs_result)
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ if(fs_result) {
|
|
|
FURI_LOG_I(TAG, "save success");
|
|
FURI_LOG_I(TAG, "save success");
|
|
|
- }
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ } else {
|
|
|
FURI_LOG_E(TAG, "save failed, %s", storage_file_get_error_desc(file));
|
|
FURI_LOG_E(TAG, "save failed, %s", storage_file_get_error_desc(file));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -151,12 +133,10 @@ void py_app_save_settings(PyApp *settings)
|
|
|
furi_record_close(RECORD_STORAGE);
|
|
furi_record_close(RECORD_STORAGE);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-PyApp *py_app_alloc()
|
|
|
|
|
-{
|
|
|
|
|
|
|
+PyApp* py_app_alloc() {
|
|
|
return py_app_load_settings();
|
|
return py_app_load_settings();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void py_app_free(PyApp *app)
|
|
|
|
|
-{
|
|
|
|
|
|
|
+void py_app_free(PyApp* app) {
|
|
|
free(app);
|
|
free(app);
|
|
|
}
|
|
}
|