Przeglądaj źródła

Squashed 'brainfuck/' changes from 4893b8fe9..01e522052

01e522052 fix catalog versions
e83b8a420 Screenshots
0ff718cf2 categories part 1
2d50ea717 Fixes for various apps. swd_probe: untested
9cbeade37 more manifestos, xbox controller and videopoker ufbt fixes
6a9bd52d0 ufbt Fixes part 1
c587d8c50 API 31 / unzip sources
REVERT: 4893b8fe9 Bug fixes
REVERT: 0e3f06e9c Update README.md
REVERT: 9e390b76f Update README.md
REVERT: 698c25df1 Update README.md
REVERT: 43bfbb62a misc changes and bugfixes
REVERT: f5681d5ef Merge branch 'main' of https://github.com/nymda/FlipperZeroBrainfuck
REVERT: 1681cba48 Threading and LED
REVERT: b1229d88c Update README.md
REVERT: b6f04cfaf Merge branch 'main' of https://github.com/nymda/FlipperZeroBrainfuck
REVERT: d50e9d772 Added about button
REVERT: 96ddbd590 Update README.md
REVERT: a94ab94a9 care
REVERT: bc79a5bf5 properly implemented inputs
REVERT: 9f859f275 stuff, cant remember
REVERT: 988db2cfe Merge branch 'main' of https://github.com/nymda/FlipperZeroBrainfuck
REVERT: ad60592fe Update bf_dev_env.c
REVERT: ed4b4526f Update README.md
REVERT: 04c08dac5 Create README.md
REVERT: da81e3702 UI redesign WIP, running page
REVERT: e6dab695c Update README.md
REVERT: 8b087a68c removed deprecated files
REVERT: 0d8ed608a Add files via upload
REVERT: f8fd32a82 Create README.md
REVERT: 31706b28d Add files via upload

git-subtree-dir: brainfuck
git-subtree-split: 01e522052e01fe37821756b8c6bbaba1f960bf63
Willy-JL 2 lat temu
rodzic
commit
f5e0ab06d2

+ 0 - 9
README.md

@@ -1,9 +0,0 @@
-# FlipperZeroBrainfuck
-
-Brainfuck interpreter and editor for the F0.  
-Supports text inputs and outputs.  
-Blue LED indicates program is running.  
-
-![Screenshot-20230214-180839](https://user-images.githubusercontent.com/16545187/218821549-c024fee3-ae74-49ce-8e3d-da7aed88e62d.png)
-
-![Screenshot-20230214-180942](https://user-images.githubusercontent.com/16545187/218821617-67a5db12-bbeb-4e78-8d69-01ca6fa65650.png)

+ 5 - 1
application.fam

@@ -1,5 +1,5 @@
 App(
-    appid="Brainfuck",
+    appid="brainfuck",
     name="Brainfuck",
     apptype=FlipperAppType.EXTERNAL,
     entry_point="brainfuck_app",
@@ -11,4 +11,8 @@ App(
     fap_icon="bfico.png",
     fap_category="Tools",
     fap_icon_assets="icons",
+    fap_author="@nymda",
+    fap_weburl="https://github.com/nymda/FlipperZeroBrainfuck",
+    fap_version="1.1",
+    fap_description="Brainfuck language interpreter",
 )

+ 21 - 9
brainfuck.c

@@ -27,36 +27,46 @@ BFApp* brainfuck_alloc() {
     brainfuck->scene_manager = scene_manager_alloc(&brainfuck_scene_handlers, brainfuck);
     view_dispatcher_enable_queue(brainfuck->view_dispatcher);
     view_dispatcher_set_event_callback_context(brainfuck->view_dispatcher, brainfuck);
-    view_dispatcher_set_custom_event_callback(brainfuck->view_dispatcher, brainfuck_custom_event_callback);
-    view_dispatcher_set_navigation_event_callback(brainfuck->view_dispatcher, brainfuck_back_event_callback);
+    view_dispatcher_set_custom_event_callback(
+        brainfuck->view_dispatcher, brainfuck_custom_event_callback);
+    view_dispatcher_set_navigation_event_callback(
+        brainfuck->view_dispatcher, brainfuck_back_event_callback);
 
     // Open GUI record
     brainfuck->gui = furi_record_open(RECORD_GUI);
-    view_dispatcher_attach_to_gui(brainfuck->view_dispatcher, brainfuck->gui, ViewDispatcherTypeFullscreen);
+    view_dispatcher_attach_to_gui(
+        brainfuck->view_dispatcher, brainfuck->gui, ViewDispatcherTypeFullscreen);
 
     // Open Notification record
     brainfuck->notifications = furi_record_open(RECORD_NOTIFICATION);
 
     // Submenu
     brainfuck->submenu = submenu_alloc();
-    view_dispatcher_add_view(brainfuck->view_dispatcher, brainfuckViewMenu, submenu_get_view(brainfuck->submenu));
+    view_dispatcher_add_view(
+        brainfuck->view_dispatcher, brainfuckViewMenu, submenu_get_view(brainfuck->submenu));
 
     // Popup
     brainfuck->popup = popup_alloc();
-    view_dispatcher_add_view(brainfuck->view_dispatcher, brainfuckViewPopup, popup_get_view(brainfuck->popup));
+    view_dispatcher_add_view(
+        brainfuck->view_dispatcher, brainfuckViewPopup, popup_get_view(brainfuck->popup));
 
     // Text Input
     brainfuck->text_input = text_input_alloc();
-    view_dispatcher_add_view(brainfuck->view_dispatcher, brainfuckViewTextInput, text_input_get_view(brainfuck->text_input));
+    view_dispatcher_add_view(
+        brainfuck->view_dispatcher,
+        brainfuckViewTextInput,
+        text_input_get_view(brainfuck->text_input));
 
     // Textbox
     brainfuck->text_box = text_box_alloc();
-    view_dispatcher_add_view(brainfuck->view_dispatcher, brainfuckViewTextBox, text_box_get_view(brainfuck->text_box)); 
+    view_dispatcher_add_view(
+        brainfuck->view_dispatcher, brainfuckViewTextBox, text_box_get_view(brainfuck->text_box));
     brainfuck->text_box_store = furi_string_alloc();
 
     // Dev environment
     brainfuck->BF_dev_env = bf_dev_env_alloc(brainfuck);
-    view_dispatcher_add_view(brainfuck->view_dispatcher, brainfuckViewDev, bf_dev_env_get_view(brainfuck->BF_dev_env));
+    view_dispatcher_add_view(
+        brainfuck->view_dispatcher, brainfuckViewDev, bf_dev_env_get_view(brainfuck->BF_dev_env));
 
     // File path
     brainfuck->BF_file_path = furi_string_alloc();
@@ -122,7 +132,9 @@ void brainfuck_show_loading_popup(void* context, bool show) {
 int32_t brainfuck_app(void* p) {
     UNUSED(p);
     BFApp* brainfuck = brainfuck_alloc();
-    if(!brainfuck){ return 0; }
+    if(!brainfuck) {
+        return 0;
+    }
 
     Storage* storage = furi_record_open(RECORD_STORAGE);
     storage_simply_mkdir(storage, "/ext/brainfuck");

+ 2 - 2
brainfuck.h

@@ -1,3 +1,3 @@
-#pragma once
-
+#pragma once
+
 typedef struct BFApp BFApp;

+ 0 - 2
brainfuck_i.h

@@ -37,7 +37,6 @@ typedef unsigned char byte;
 #include <toolbox/stream/file_stream.h>
 
 #include <notification/notification_messages.h>
-#include <notification/notification_app.h>
 
 #define BF_INST_BUFFER_SIZE 2048
 #define BF_OUTPUT_SIZE 512
@@ -87,4 +86,3 @@ typedef enum {
     brainfuckViewDev,
     brainfuckViewExec,
 } brainfuckView;
-

BIN
img/1.png


BIN
img/2.png


BIN
img/3.png


+ 16 - 17
scenes/brainfuck_scene_dev.c

@@ -1,17 +1,16 @@
-#include "../brainfuck_i.h"
-
-void brainfuck_scene_dev_env_on_enter(void* context) {
-    BFApp* app = context;
-    view_dispatcher_switch_to_view(app->view_dispatcher, brainfuckViewDev);
-}
-
-bool brainfuck_scene_dev_env_on_event(void* context, SceneManagerEvent event) {
-    UNUSED(context);
-    UNUSED(event);
-    return false;
-}
-
-void brainfuck_scene_dev_env_on_exit(void* context) {
-    UNUSED(context);
-}
-
+#include "../brainfuck_i.h"
+
+void brainfuck_scene_dev_env_on_enter(void* context) {
+    BFApp* app = context;
+    view_dispatcher_switch_to_view(app->view_dispatcher, brainfuckViewDev);
+}
+
+bool brainfuck_scene_dev_env_on_event(void* context, SceneManagerEvent event) {
+    UNUSED(context);
+    UNUSED(event);
+    return false;
+}
+
+void brainfuck_scene_dev_env_on_exit(void* context) {
+    UNUSED(context);
+}

+ 16 - 16
scenes/brainfuck_scene_exec.c

@@ -1,16 +1,16 @@
-#include "../brainfuck_i.h"
-
-void brainfuck_scene_exec_env_on_enter(void* context) {
-    BFApp* app = context;
-    view_dispatcher_switch_to_view(app->view_dispatcher, brainfuckViewTextBox);
-}
-
-bool brainfuck_scene_exec_env_on_event(void* context, SceneManagerEvent event) {
-    UNUSED(context);
-    UNUSED(event);
-    return false;
-}
-
-void brainfuck_scene_exec_env_on_exit(void* context) {
-    UNUSED(context);
-}
+#include "../brainfuck_i.h"
+
+void brainfuck_scene_exec_env_on_enter(void* context) {
+    BFApp* app = context;
+    view_dispatcher_switch_to_view(app->view_dispatcher, brainfuckViewTextBox);
+}
+
+bool brainfuck_scene_exec_env_on_event(void* context, SceneManagerEvent event) {
+    UNUSED(context);
+    UNUSED(event);
+    return false;
+}
+
+void brainfuck_scene_exec_env_on_exit(void* context) {
+    UNUSED(context);
+}

+ 50 - 54
scenes/brainfuck_scene_file_create.c

@@ -1,54 +1,50 @@
-#include "../brainfuck_i.h"
-
-void file_name_text_input_callback(void* context) {
-    BFApp* app = context;
-    view_dispatcher_send_custom_event(app->view_dispatcher, brainfuckCustomEventTextInputDone);
-}
-
-char tmpName[64] = {};
-byte empty[1] = {0x00};
-void brainfuck_scene_file_create_on_enter(void* context) {
-    BFApp* app = context;
-    TextInput* text_input = app->text_input;
-
-    text_input_set_header_text(text_input, "New script name");
-    text_input_set_result_callback(
-        text_input,
-        file_name_text_input_callback,
-        app,
-        tmpName,
-        64,
-        true);
-
-    view_dispatcher_switch_to_view(app->view_dispatcher, brainfuckViewTextInput);
-}
-
-bool brainfuck_scene_file_create_on_event(void* context, SceneManagerEvent event) {
-    BFApp* app = context;
-    UNUSED(app);
-    
-    bool consumed = false;
-    if(event.type == SceneManagerEventTypeCustom) {
-        if(event.event == brainfuckCustomEventTextInputDone) {
-            furi_string_cat_printf(app->BF_file_path, "/ext/brainfuck/%s.b", tmpName);
-
-            //remove old file
-            Storage* storage = furi_record_open(RECORD_STORAGE);
-            storage_simply_remove(storage, furi_string_get_cstr(app->BF_file_path));
-
-            //save new file
-            Stream* stream = buffered_file_stream_alloc(storage);
-            buffered_file_stream_open(stream, furi_string_get_cstr(app->BF_file_path), FSAM_WRITE, FSOM_CREATE_ALWAYS);
-            stream_write(stream, (const uint8_t*)empty, 1);
-            buffered_file_stream_close(stream);
-
-            //scene_manager_next_scene(app->scene_manager, brainfuckSceneFileSelect);
-            scene_manager_next_scene(app->scene_manager, brainfuckSceneDevEnv);
-        }
-    }
-    return consumed;
-}
-
-void brainfuck_scene_file_create_on_exit(void* context) {
-    UNUSED(context);
-}
+#include "../brainfuck_i.h"
+
+void file_name_text_input_callback(void* context) {
+    BFApp* app = context;
+    view_dispatcher_send_custom_event(app->view_dispatcher, brainfuckCustomEventTextInputDone);
+}
+
+char tmpName[64] = {};
+byte empty[1] = {0x00};
+void brainfuck_scene_file_create_on_enter(void* context) {
+    BFApp* app = context;
+    TextInput* text_input = app->text_input;
+
+    text_input_set_header_text(text_input, "New script name");
+    text_input_set_result_callback(
+        text_input, file_name_text_input_callback, app, tmpName, 64, true);
+
+    view_dispatcher_switch_to_view(app->view_dispatcher, brainfuckViewTextInput);
+}
+
+bool brainfuck_scene_file_create_on_event(void* context, SceneManagerEvent event) {
+    BFApp* app = context;
+    UNUSED(app);
+
+    bool consumed = false;
+    if(event.type == SceneManagerEventTypeCustom) {
+        if(event.event == brainfuckCustomEventTextInputDone) {
+            furi_string_cat_printf(app->BF_file_path, "/ext/brainfuck/%s.b", tmpName);
+
+            //remove old file
+            Storage* storage = furi_record_open(RECORD_STORAGE);
+            storage_simply_remove(storage, furi_string_get_cstr(app->BF_file_path));
+
+            //save new file
+            Stream* stream = buffered_file_stream_alloc(storage);
+            buffered_file_stream_open(
+                stream, furi_string_get_cstr(app->BF_file_path), FSAM_WRITE, FSOM_CREATE_ALWAYS);
+            stream_write(stream, (const uint8_t*)empty, 1);
+            buffered_file_stream_close(stream);
+
+            //scene_manager_next_scene(app->scene_manager, brainfuckSceneFileSelect);
+            scene_manager_next_scene(app->scene_manager, brainfuckSceneDevEnv);
+        }
+    }
+    return consumed;
+}
+
+void brainfuck_scene_file_create_on_exit(void* context) {
+    UNUSED(context);
+}

+ 2 - 3
scenes/brainfuck_scene_file_select.c

@@ -15,11 +15,10 @@ void brainfuck_scene_file_select_on_enter(void* context) {
 
     bool selected = dialog_file_browser_show(dialogs, path, path, &browser_options);
 
-    if(selected){
+    if(selected) {
         furi_string_set(app->BF_file_path, path);
         scene_manager_next_scene(app->scene_manager, brainfuckSceneDevEnv);
-    }
-    else{
+    } else {
         scene_manager_search_and_switch_to_previous_scene(app->scene_manager, brainfuckSceneStart);
     }
 }

+ 4 - 8
scenes/brainfuck_scene_set_input.c

@@ -11,23 +11,19 @@ void brainfuck_scene_set_input_on_enter(void* context) {
 
     text_input_set_header_text(text_input, "Edit input buffer");
     text_input_set_result_callback(
-        text_input,
-        set_input_text_input_callback,
-        app,
-        app->inputBuffer,
-        64,
-        true);
+        text_input, set_input_text_input_callback, app, app->inputBuffer, 64, true);
 
     view_dispatcher_switch_to_view(app->view_dispatcher, brainfuckViewTextInput);
 }
 
 bool brainfuck_scene_set_input_on_event(void* context, SceneManagerEvent event) {
     BFApp* app = context;
-    
+
     bool consumed = false;
     if(event.type == SceneManagerEventTypeCustom) {
         if(event.event == brainfuckCustomEventTextInputDone) {
-            scene_manager_search_and_switch_to_previous_scene(app->scene_manager, brainfuckSceneDevEnv);
+            scene_manager_search_and_switch_to_previous_scene(
+                app->scene_manager, brainfuckSceneDevEnv);
         }
     }
     return consumed;

+ 11 - 5
scenes/brainfuck_scene_start.c

@@ -13,11 +13,15 @@ void brainfuck_scene_start_on_enter(void* context) {
     BFApp* brainfuck = context;
 
     Submenu* submenu = brainfuck->submenu;
-    submenu_add_item(submenu, "New", SubmenuIndexNew, brainfuck_scene_start_submenu_callback, brainfuck);
-    submenu_add_item(submenu, "Open", SubmenuIndexOpen, brainfuck_scene_start_submenu_callback, brainfuck);
-    submenu_add_item(submenu, "About", SubmenuIndexAbout, brainfuck_scene_start_submenu_callback, brainfuck);
+    submenu_add_item(
+        submenu, "New", SubmenuIndexNew, brainfuck_scene_start_submenu_callback, brainfuck);
+    submenu_add_item(
+        submenu, "Open", SubmenuIndexOpen, brainfuck_scene_start_submenu_callback, brainfuck);
+    submenu_add_item(
+        submenu, "About", SubmenuIndexAbout, brainfuck_scene_start_submenu_callback, brainfuck);
 
-    submenu_set_selected_item(submenu, scene_manager_get_scene_state(brainfuck->scene_manager, brainfuckSceneStart));
+    submenu_set_selected_item(
+        submenu, scene_manager_get_scene_state(brainfuck->scene_manager, brainfuckSceneStart));
     view_dispatcher_switch_to_view(brainfuck->view_dispatcher, brainfuckViewMenu);
 }
 
@@ -33,7 +37,9 @@ bool brainfuck_scene_start_on_event(void* context, SceneManagerEvent event) {
             scene_manager_next_scene(brainfuck->scene_manager, brainfuckSceneFileSelect);
             consumed = true;
         } else if(event.event == SubmenuIndexAbout) {
-            text_box_set_text(brainfuck->text_box, "FlipperBrainfuck\n\nAn F0 brainfuck intepretor\nBy github.com/Nymda");
+            text_box_set_text(
+                brainfuck->text_box,
+                "FlipperBrainfuck\n\nAn F0 brainfuck intepretor\nBy github.com/Nymda");
             scene_manager_next_scene(brainfuck->scene_manager, brainfuckSceneExecEnv);
             consumed = true;
         }

+ 161 - 147
views/bf_dev_env.c

@@ -13,12 +13,18 @@ typedef struct {
     uint32_t col;
 } BFDevEnvModel;
 
-typedef struct{
+typedef struct {
     int up;
     int down;
     int left;
     int right;
-}bMapping;
+} bMapping;
+
+#ifdef FW_ORIGIN_Official
+#define FONT_NAME FontSecondary
+#else
+#define FONT_NAME FontBatteryPercent
+#endif
 
 static bool bf_dev_process_up(BFDevEnv* devEnv);
 static bool bf_dev_process_down(BFDevEnv* devEnv);
@@ -27,7 +33,7 @@ static bool bf_dev_process_right(BFDevEnv* devEnv);
 static bool bf_dev_process_ok(BFDevEnv* devEnv, InputEvent* event);
 
 BFApp* appDev;
-FuriThread* workerThread; 
+FuriThread* workerThread;
 
 char bfChars[9] = {'<', '>', '[', ']', '+', '-', '.', ',', 0x00};
 
@@ -35,57 +41,59 @@ int selectedButton = 0;
 int saveNotifyCountdown = 0;
 int execCountdown = 0;
 
-char dspLine0[25] = { 0x00 };
-char dspLine1[25] = { 0x00 };
-char dspLine2[25] = { 0x00 };
+char dspLine0[25] = {0x00};
+char dspLine1[25] = {0x00};
+char dspLine2[25] = {0x00};
 
 static bMapping buttonMappings[12] = {
-    { 8,  8,  7,  1},  //0
-    { 8,  8,  0,  2},  //1
-    { 9,  9,  1,  3},  //2
-    { 9,  9,  2,  4},  //3
-    {10, 10,  3,  5},  //4
-    {10, 10,  4,  6},  //5
-    {11, 11,  5,  7},  //6
-    {11, 11,  6,  0},  //7
-
-    { 0,  0, 11,  9},  //8 
-    { 3,  3,  8, 10},  //9
-    { 5,  5,  9, 11},  //10
-    { 6,  6, 10,  8}   //11
+    {8, 8, 7, 1}, //0
+    {8, 8, 0, 2}, //1
+    {9, 9, 1, 3}, //2
+    {9, 9, 2, 4}, //3
+    {10, 10, 3, 5}, //4
+    {10, 10, 4, 6}, //5
+    {11, 11, 5, 7}, //6
+    {11, 11, 6, 0}, //7
+
+    {0, 0, 11, 9}, //8
+    {3, 3, 8, 10}, //9
+    {5, 5, 9, 11}, //10
+    {6, 6, 10, 8} //11
 };
 
 #define BT_X 14
 #define BT_Y 14
-static void bf_dev_draw_button(Canvas* canvas, int x, int y, bool selected, const char* lbl){
+static void bf_dev_draw_button(Canvas* canvas, int x, int y, bool selected, const char* lbl) {
     UNUSED(lbl);
 
-    if(selected){
+    if(selected) {
         canvas_draw_rbox(canvas, x, y, BT_X, BT_Y, 3);
         canvas_invert_color(canvas);
-        canvas_set_font(canvas, FontBatteryPercent);
-        canvas_draw_str_aligned(canvas, x + (BT_X/2), y + (BT_Y/2) - 1, AlignCenter, AlignCenter, lbl);
+        canvas_set_font(canvas, FONT_NAME);
+        canvas_draw_str_aligned(
+            canvas, x + (BT_X / 2), y + (BT_Y / 2) - 1, AlignCenter, AlignCenter, lbl);
         canvas_invert_color(canvas);
-    }
-    else{
+    } else {
         canvas_draw_rbox(canvas, x, y, BT_X, BT_Y, 3);
         canvas_invert_color(canvas);
-        canvas_draw_rbox(canvas, x+2, y-1, BT_X - 2, BT_Y - 1, 3);
+        canvas_draw_rbox(canvas, x + 2, y - 1, BT_X - 2, BT_Y - 1, 3);
         canvas_invert_color(canvas);
         canvas_draw_rframe(canvas, x, y, BT_X, BT_Y, 3);
-        canvas_set_font(canvas, FontBatteryPercent);
-        canvas_draw_str_aligned(canvas, x + (BT_X/2), y + (BT_Y/2) - 1, AlignCenter, AlignCenter, lbl);
+        canvas_set_font(canvas, FONT_NAME);
+        canvas_draw_str_aligned(
+            canvas, x + (BT_X / 2), y + (BT_Y / 2) - 1, AlignCenter, AlignCenter, lbl);
     }
 }
 
-void bf_save_changes(){
+void bf_save_changes() {
     //remove old file
     Storage* storage = furi_record_open(RECORD_STORAGE);
     storage_simply_remove(storage, furi_string_get_cstr(appDev->BF_file_path));
 
     //save new file
     Stream* stream = buffered_file_stream_alloc(storage);
-    buffered_file_stream_open(stream, furi_string_get_cstr(appDev->BF_file_path), FSAM_WRITE, FSOM_CREATE_ALWAYS);
+    buffered_file_stream_open(
+        stream, furi_string_get_cstr(appDev->BF_file_path), FSAM_WRITE, FSOM_CREATE_ALWAYS);
     stream_write(stream, (const uint8_t*)appDev->dataBuffer, appDev->dataSize);
     buffered_file_stream_close(stream);
 }
@@ -93,28 +101,35 @@ void bf_save_changes(){
 static void bf_dev_draw_callback(Canvas* canvas, void* _model) {
     UNUSED(_model);
 
-    if(saveNotifyCountdown > 0){
+    if(saveNotifyCountdown > 0) {
         canvas_draw_str_aligned(canvas, 64, 32, AlignCenter, AlignCenter, "SAVED");
         saveNotifyCountdown--;
         return;
     }
 
-    bf_dev_draw_button(canvas, 1,   36, (selectedButton == 0), "+");  //T 0
-    bf_dev_draw_button(canvas, 17,  36, (selectedButton == 1), "-");  //T 1
-    bf_dev_draw_button(canvas, 33,  36, (selectedButton == 2), "<");  //T 2
-    bf_dev_draw_button(canvas, 49,  36, (selectedButton == 3), ">");  //T 3
-    bf_dev_draw_button(canvas, 65,  36, (selectedButton == 4), "[");  //B 0
-    bf_dev_draw_button(canvas, 81,  36, (selectedButton == 5), "]");  //B 1
-    bf_dev_draw_button(canvas, 97,  36, (selectedButton == 6), ".");  //B 2
-    bf_dev_draw_button(canvas, 113, 36, (selectedButton == 7), ",");  //B 3
+    bf_dev_draw_button(canvas, 1, 36, (selectedButton == 0), "+"); //T 0
+    bf_dev_draw_button(canvas, 17, 36, (selectedButton == 1), "-"); //T 1
+    bf_dev_draw_button(canvas, 33, 36, (selectedButton == 2), "<"); //T 2
+    bf_dev_draw_button(canvas, 49, 36, (selectedButton == 3), ">"); //T 3
+    bf_dev_draw_button(canvas, 65, 36, (selectedButton == 4), "["); //B 0
+    bf_dev_draw_button(canvas, 81, 36, (selectedButton == 5), "]"); //B 1
+    bf_dev_draw_button(canvas, 97, 36, (selectedButton == 6), "."); //B 2
+    bf_dev_draw_button(canvas, 113, 36, (selectedButton == 7), ","); //B 3
 
     //backspace, input, run, save
-    canvas_draw_icon(canvas, 1, 52, (selectedButton == 8) ? &I_KeyBackspaceSelected_24x11 : &I_KeyBackspace_24x11);
-    canvas_draw_icon(canvas, 45, 52, (selectedButton == 9) ? &I_KeyInputSelected_30x11 : &I_KeyInput_30x11);
-    canvas_draw_icon(canvas, 77, 52, (selectedButton == 10) ? &I_KeyRunSelected_24x11 : &I_KeyRun_24x11);
-    canvas_draw_icon(canvas, 103, 52, (selectedButton == 11) ? &I_KeySaveSelected_24x11 : &I_KeySave_24x11);
-
-    if(saveNotifyCountdown > 0){
+    canvas_draw_icon(
+        canvas,
+        1,
+        52,
+        (selectedButton == 8) ? &I_KeyBackspaceSelected_24x11 : &I_KeyBackspace_24x11);
+    canvas_draw_icon(
+        canvas, 45, 52, (selectedButton == 9) ? &I_KeyInputSelected_30x11 : &I_KeyInput_30x11);
+    canvas_draw_icon(
+        canvas, 77, 52, (selectedButton == 10) ? &I_KeyRunSelected_24x11 : &I_KeyRun_24x11);
+    canvas_draw_icon(
+        canvas, 103, 52, (selectedButton == 11) ? &I_KeySaveSelected_24x11 : &I_KeySave_24x11);
+
+    if(saveNotifyCountdown > 0) {
         canvas_draw_icon(canvas, 98, 54, &I_ButtonRightSmall_3x5);
         saveNotifyCountdown--;
     }
@@ -122,13 +137,13 @@ static void bf_dev_draw_callback(Canvas* canvas, void* _model) {
     //textbox
     //grossly overcomplicated. not fixing it.
     canvas_draw_rframe(canvas, 1, 1, 126, 33, 2);
-    canvas_set_font(canvas, FontBatteryPercent);
+    canvas_set_font(canvas, FONT_NAME);
 
     int dbOffset = 0;
-    if(appDev->dataSize > 72){
+    if(appDev->dataSize > 72) {
         dbOffset = (appDev->dataSize - 72);
     }
- 
+
     memset(dspLine0, 0x00, 25);
     memset(dspLine1, 0x00, 25);
     memset(dspLine2, 0x00, 25);
@@ -138,28 +153,25 @@ static void bf_dev_draw_callback(Canvas* canvas, void* _model) {
     int tp1 = 0;
     int tp2 = 0;
 
-    for(int p = dbOffset; p < appDev->dataSize; p++){
-        if(tpM < 24 * 1){
+    for(int p = dbOffset; p < appDev->dataSize; p++) {
+        if(tpM < 24 * 1) {
             dspLine0[tp0] = appDev->dataBuffer[p];
             tp0++;
-        }
-        else if(tpM < 24 * 2){
+        } else if(tpM < 24 * 2) {
             dspLine1[tp1] = appDev->dataBuffer[p];
             tp1++;
-        }
-        else if(tpM < 24 * 3){
+        } else if(tpM < 24 * 3) {
             dspLine2[tp2] = appDev->dataBuffer[p];
             tp2++;
         }
         tpM++;
     }
 
-    canvas_draw_str_aligned(canvas, 3,  8, AlignLeft, AlignCenter, dspLine0);
+    canvas_draw_str_aligned(canvas, 3, 8, AlignLeft, AlignCenter, dspLine0);
     canvas_draw_str_aligned(canvas, 3, 17, AlignLeft, AlignCenter, dspLine1);
     canvas_draw_str_aligned(canvas, 3, 26, AlignLeft, AlignCenter, dspLine2);
 }
 
-
 static bool bf_dev_input_callback(InputEvent* event, void* context) {
     furi_assert(context);
     BFDevEnv* devEnv = context;
@@ -210,113 +222,112 @@ static bool bf_dev_process_ok(BFDevEnv* devEnv, InputEvent* event) {
     UNUSED(devEnv);
     UNUSED(event);
 
-    if(event->type != InputTypePress){ return false; }
+    if(event->type != InputTypePress) {
+        return false;
+    }
 
-    switch(selectedButton){
-        case 0:
-        {
-            if(appDev->dataSize < BF_INST_BUFFER_SIZE){ 
-                appDev->dataBuffer[appDev->dataSize] = '+'; 
-                appDev->dataSize++; }
-            break;
+    switch(selectedButton) {
+    case 0: {
+        if(appDev->dataSize < BF_INST_BUFFER_SIZE) {
+            appDev->dataBuffer[appDev->dataSize] = '+';
+            appDev->dataSize++;
         }
+        break;
+    }
 
-        case 1:
-        {
-            if(appDev->dataSize < BF_INST_BUFFER_SIZE){ 
-                appDev->dataBuffer[appDev->dataSize] = '-'; 
-                appDev->dataSize++; }
-            break;
+    case 1: {
+        if(appDev->dataSize < BF_INST_BUFFER_SIZE) {
+            appDev->dataBuffer[appDev->dataSize] = '-';
+            appDev->dataSize++;
         }
+        break;
+    }
 
-        case 2:
-        {
-            if(appDev->dataSize < BF_INST_BUFFER_SIZE){ 
-                appDev->dataBuffer[appDev->dataSize] = '<'; 
-                appDev->dataSize++; }
-            break;
+    case 2: {
+        if(appDev->dataSize < BF_INST_BUFFER_SIZE) {
+            appDev->dataBuffer[appDev->dataSize] = '<';
+            appDev->dataSize++;
         }
+        break;
+    }
 
-        case 3:
-        {
-            if(appDev->dataSize < BF_INST_BUFFER_SIZE){ 
-                appDev->dataBuffer[appDev->dataSize] = '>'; 
-                appDev->dataSize++; }
-            break;
+    case 3: {
+        if(appDev->dataSize < BF_INST_BUFFER_SIZE) {
+            appDev->dataBuffer[appDev->dataSize] = '>';
+            appDev->dataSize++;
         }
+        break;
+    }
 
-        case 4:
-        {
-            if(appDev->dataSize < BF_INST_BUFFER_SIZE){ 
-                appDev->dataBuffer[appDev->dataSize] = '['; 
-                appDev->dataSize++; }
-            break;
+    case 4: {
+        if(appDev->dataSize < BF_INST_BUFFER_SIZE) {
+            appDev->dataBuffer[appDev->dataSize] = '[';
+            appDev->dataSize++;
         }
+        break;
+    }
 
-        case 5:
-        {
-            if(appDev->dataSize < BF_INST_BUFFER_SIZE){ 
-                appDev->dataBuffer[appDev->dataSize] = ']'; 
-                appDev->dataSize++; }
-            break;
+    case 5: {
+        if(appDev->dataSize < BF_INST_BUFFER_SIZE) {
+            appDev->dataBuffer[appDev->dataSize] = ']';
+            appDev->dataSize++;
         }
+        break;
+    }
 
-        case 6:
-        {
-            if(appDev->dataSize < BF_INST_BUFFER_SIZE){ 
-                appDev->dataBuffer[appDev->dataSize] = '.'; 
-                appDev->dataSize++; }
-            break;
+    case 6: {
+        if(appDev->dataSize < BF_INST_BUFFER_SIZE) {
+            appDev->dataBuffer[appDev->dataSize] = '.';
+            appDev->dataSize++;
         }
+        break;
+    }
 
-        case 7:
-        {
-            if(appDev->dataSize < BF_INST_BUFFER_SIZE){ 
-                appDev->dataBuffer[appDev->dataSize] = ','; 
-                appDev->dataSize++; }
-            break;
+    case 7: {
+        if(appDev->dataSize < BF_INST_BUFFER_SIZE) {
+            appDev->dataBuffer[appDev->dataSize] = ',';
+            appDev->dataSize++;
         }
+        break;
+    }
 
-        case 8:
-        {
-            if(appDev->dataSize > 0){
-                appDev->dataSize--; 
-                appDev->dataBuffer[appDev->dataSize] = (uint32_t)0x00;}
-            break;
+    case 8: {
+        if(appDev->dataSize > 0) {
+            appDev->dataSize--;
+            appDev->dataBuffer[appDev->dataSize] = (uint32_t)0x00;
         }
+        break;
+    }
 
-        case 9:
-        {
-            scene_manager_next_scene(appDev->scene_manager, brainfuckSceneSetInput);
-            break;
-        }
+    case 9: {
+        scene_manager_next_scene(appDev->scene_manager, brainfuckSceneSetInput);
+        break;
+    }
 
-        case 10:
-        {
-            if(getStatus() != 0){
-                killThread();
-                furi_thread_join(workerThread);
-            }
+    case 10: {
+        if(getStatus() != 0) {
+            killThread();
+            furi_thread_join(workerThread);
+        }
 
-            bf_save_changes();
+        bf_save_changes();
 
-            initWorker(appDev);
-            text_box_set_focus(appDev->text_box, TextBoxFocusEnd);
-            text_box_set_text(appDev->text_box, workerGetOutput());
+        initWorker(appDev);
+        text_box_set_focus(appDev->text_box, TextBoxFocusEnd);
+        text_box_set_text(appDev->text_box, workerGetOutput());
 
-            workerThread = furi_thread_alloc_ex("Worker", 2048, (void*)beginWorker, NULL);
-            furi_thread_start(workerThread);
+        workerThread = furi_thread_alloc_ex("Worker", 2048, (void*)beginWorker, NULL);
+        furi_thread_start(workerThread);
 
-            scene_manager_next_scene(appDev->scene_manager, brainfuckSceneExecEnv);
-            break;
-        }
+        scene_manager_next_scene(appDev->scene_manager, brainfuckSceneExecEnv);
+        break;
+    }
 
-        case 11:
-        {
-            bf_save_changes();
-            saveNotifyCountdown = 3;
-            break;
-        }
+    case 11: {
+        bf_save_changes();
+        saveNotifyCountdown = 3;
+        break;
+    }
     }
 
     bool consumed = false;
@@ -329,7 +340,7 @@ static void bf_dev_enter_callback(void* context) {
 
     with_view_model(
         devEnv->view,
-        BFDevEnvModel* model,
+        BFDevEnvModel * model,
         {
             model->col = 0;
             model->row = 0;
@@ -340,7 +351,7 @@ static void bf_dev_enter_callback(void* context) {
     selectedButton = 0;
 
     //exit the running thread if required
-    if(getStatus() != 0){
+    if(getStatus() != 0) {
         killThread();
         furi_thread_join(workerThread);
     }
@@ -351,11 +362,12 @@ static void bf_dev_enter_callback(void* context) {
     //open the file
     Storage* storage = furi_record_open(RECORD_STORAGE);
     Stream* stream = buffered_file_stream_alloc(storage);
-    buffered_file_stream_open(stream, furi_string_get_cstr(appDev->BF_file_path), FSAM_READ, FSOM_OPEN_EXISTING);
+    buffered_file_stream_open(
+        stream, furi_string_get_cstr(appDev->BF_file_path), FSAM_READ, FSOM_OPEN_EXISTING);
 
     //read into the buffer
     appDev->dataSize = stream_size(stream);
-    if(appDev->dataSize > 2000){
+    if(appDev->dataSize > 2000) {
         return; //BF file is too large
     }
 
@@ -363,15 +375,17 @@ static void bf_dev_enter_callback(void* context) {
     buffered_file_stream_close(stream);
 
     //replaces any invalid characters with an underscore. strips out newlines, comments, etc
-    for(int i = 0; i < appDev->dataSize; i++){
-        if(!strchr(bfChars, appDev->dataBuffer[i])){
+    for(int i = 0; i < appDev->dataSize; i++) {
+        if(!strchr(bfChars, appDev->dataBuffer[i])) {
             appDev->dataBuffer[i] = '_';
         }
     }
 
     //find the end of the file to begin editing
     int tptr = 0;
-    while(appDev->dataBuffer[tptr] != 0x00){ tptr++; }
+    while(appDev->dataBuffer[tptr] != 0x00) {
+        tptr++;
+    }
     appDev->dataSize = tptr;
 }
 
@@ -384,7 +398,7 @@ BFDevEnv* bf_dev_env_alloc(BFApp* appDev) {
 
     with_view_model(
         devEnv->view,
-        BFDevEnvModel* model,
+        BFDevEnvModel * model,
         {
             model->col = 0;
             model->row = 0;
@@ -399,7 +413,7 @@ BFDevEnv* bf_dev_env_alloc(BFApp* appDev) {
 }
 
 void bf_dev_env_free(BFDevEnv* devEnv) {
-    if(getStatus() != 0){
+    if(getStatus() != 0) {
         killThread();
         furi_thread_join(workerThread);
     }

+ 1 - 4
views/bf_dev_env.h

@@ -12,7 +12,4 @@ void bf_dev_env_free(BFDevEnv* devEnv);
 
 View* bf_dev_env_get_view(BFDevEnv* devEnv);
 
-void bf_dev_env_set_ok(
-    BFDevEnv* devEnv,
-    DevEnvOkCallback callback,
-    void* context);
+void bf_dev_env_set_ok(BFDevEnv* devEnv, DevEnvOkCallback callback, void* context);

+ 290 - 256
worker.c

@@ -1,257 +1,291 @@
-#include "worker.h"
-#include <furi_hal_resources.h>
-#include <furi.h>
-
-bool killswitch = false;
-
-int status = 0; //0: idle, 1: running, 2: failure
-
-char* inst = 0;
-int instCount = 0;
-int instPtr = 0;
-int runOpCount = 0;
-
-char* wOutput = 0;
-int wOutputPtr = 0;
-
-char* wInput = 0;
-int wInputPtr = 0;
-
-uint8_t* bfStack = 0;
-int stackPtr = 0;
-int stackSize = BF_STACK_INITIAL_SIZE;
-int stackSizeReal = 0;
-
-BFApp* wrkrApp = 0;
-
-void killThread(){
-    killswitch = true;
-}
-
-bool validateInstPtr(){
-    if(instPtr > instCount || instPtr < 0){
-        return false;
-    }
-    return true;
-}
-
-bool validateStackPtr(){
-    if(stackPtr > stackSize || stackPtr < 0){
-        return false;
-    }
-    return true;
-}
-
-char* workerGetOutput(){
-    return wOutput;
-}
-
-int getStackSize(){
-    return stackSizeReal;
-}
-
-int getOpCount(){
-    return runOpCount;
-}
-
-int getStatus(){
-    return status;
-}
-
-void initWorker(BFApp* app){
-    wrkrApp = app;
-
-    //rebuild output
-    if(wOutput){ free(wOutput); }
-    wOutput = (char*)malloc(BF_OUTPUT_SIZE);
-    wOutputPtr = 0;
-
-    //rebuild stack
-    if(bfStack){ free(bfStack); }
-    bfStack = (uint8_t*)malloc(BF_STACK_INITIAL_SIZE);
-    memset(bfStack, 0x00, BF_STACK_INITIAL_SIZE);
-    stackSize = BF_STACK_INITIAL_SIZE;
-    stackSizeReal = 0;
-    stackPtr = 0;
-
-    //set instructions
-    inst = wrkrApp->dataBuffer;
-    instCount = wrkrApp->dataSize;
-    instPtr = 0;
-    runOpCount = 0;
-
-    //set input
-    wInput = wrkrApp->inputBuffer;
-    wInputPtr = 0;
-
-    //set status
-    status = 0;
-}
-
-void rShift(){
-    runOpCount++;
-    stackPtr++;
-    if(!validateStackPtr()){ status = 2; return; }
-
-    while(stackPtr > stackSize){
-        stackSize += BF_STACK_STEP_SIZE;
-        void* tmp = realloc(bfStack, stackSize);
-
-        if(!tmp){ 
-            status = 2;
-            return;
-        }
-
-        memset((tmp + stackSize) - BF_STACK_STEP_SIZE, 0x00, BF_STACK_STEP_SIZE);
-        bfStack = (uint8_t*)tmp;
-    };
-    if(stackPtr > stackSizeReal){ 
-        stackSizeReal = stackPtr; 
-    }
-}
-
-void lShift(){
-    runOpCount++;
-    stackPtr--;
-    if(!validateStackPtr()){ status = 2; return; }
-}
-
-void inc(){
-    runOpCount++;
-    if(!validateStackPtr()){ status = 2; return; }
-    bfStack[stackPtr]++;
-}
-
-void dec(){
-    runOpCount++;
-    if(!validateStackPtr()){ status = 2; return; }
-    bfStack[stackPtr]--;
-}
-
-void print(){
-    runOpCount++;
-    wOutput[wOutputPtr] = bfStack[stackPtr];
-    wOutputPtr++;
-    if(wOutputPtr > (BF_OUTPUT_SIZE - 1)){ wOutputPtr = 0;}
-}
-
-void input(){
-    runOpCount++;
-    
-    bfStack[stackPtr] = (uint8_t)wInput[wInputPtr];
-    if(wInput[wInputPtr] == 0x00 || wInputPtr >= 64){
-        wInputPtr = 0;
-    }
-    else{
-        wInputPtr++;
-    }
-}
-
-void loop() {
-    runOpCount++;
-	if (bfStack[stackPtr] == 0) {
-		int loopCount = 1;
-		while (loopCount > 0) {
-			instPtr++;
-            if(!validateInstPtr()){ status = 2; return; }
-			if (inst[instPtr] == '[') { loopCount++; }
-			else if (inst[instPtr] == ']') { loopCount--; }
-		}
-	}
-}
-
-void endLoop() {
-    runOpCount++;
-	if (bfStack[stackPtr] != 0) {
-		int loopCount = 1;
-		while (loopCount > 0) {
-			instPtr--;
-            if(!validateInstPtr()){ status = 2; return; }
-			if (inst[instPtr] == ']') { loopCount++; }
-			else if (inst[instPtr] == '[') { loopCount--; }
-		}
-	}
-}
-
-static const NotificationSequence led_on = {
-    &message_blue_255,
-    &message_do_not_reset,
-    NULL,
-};
-
-static const NotificationSequence led_off = {
-    &message_blue_0,
-    NULL,
-};
-
-void input_kill(void* _ctx) {
-    UNUSED(_ctx);
-    killswitch = true;
-}
-
-void beginWorker(){
-    status = 1;
-
-    //redefined from furi_hal_resources.c
-    const GpioPin gpio_button_back = {.port = GPIOC, .pin = LL_GPIO_PIN_13};
-
-    while (inst[instPtr] != 0x00) {
-
-        if(runOpCount % 500 == 0){ 
-            text_box_set_text(wrkrApp->text_box, workerGetOutput()); 
-            notification_message(wrkrApp->notifications, &led_on);
-        }
-
-        //status 2 indicates failure
-        if(status == 2){ status = 0; break; }
-
-        //read back button directly to avoid weirdness in furi
-        if(killswitch || !furi_hal_gpio_read(&gpio_button_back)) {
-            status = 0; 
-            killswitch = false; 
-            break; 
-        }
-
-        switch (inst[instPtr]) {
-            case '>':
-                rShift();
-                break;
-            case '<':
-                lShift();
-                break;
-
-            case '+':
-                inc();
-                break;
-                
-            case '-':
-                dec();
-                break;
-                
-            case '.':
-                print();
-                break;
-            
-            case ',':
-                input();
-                break;
-                
-            case '[':
-                loop();
-                break;
-                
-            case ']':
-                endLoop();
-                break;
-                
-            default:
-                break;
-        }
-        instPtr++;
-        if(!validateInstPtr()){ status = 0; break; }
-    }
-
-    notification_message(wrkrApp->notifications, &led_off);
-    text_box_set_text(wrkrApp->text_box, workerGetOutput());
-    status = 0;
+#include "worker.h"
+#include <furi_hal_resources.h>
+#include <furi.h>
+
+bool killswitch = false;
+
+int status = 0; //0: idle, 1: running, 2: failure
+
+char* inst = 0;
+int instCount = 0;
+int instPtr = 0;
+int runOpCount = 0;
+
+char* wOutput = 0;
+int wOutputPtr = 0;
+
+char* wInput = 0;
+int wInputPtr = 0;
+
+uint8_t* bfStack = 0;
+int stackPtr = 0;
+int stackSize = BF_STACK_INITIAL_SIZE;
+int stackSizeReal = 0;
+
+BFApp* wrkrApp = 0;
+
+void killThread() {
+    killswitch = true;
+}
+
+bool validateInstPtr() {
+    if(instPtr > instCount || instPtr < 0) {
+        return false;
+    }
+    return true;
+}
+
+bool validateStackPtr() {
+    if(stackPtr > stackSize || stackPtr < 0) {
+        return false;
+    }
+    return true;
+}
+
+char* workerGetOutput() {
+    return wOutput;
+}
+
+int getStackSize() {
+    return stackSizeReal;
+}
+
+int getOpCount() {
+    return runOpCount;
+}
+
+int getStatus() {
+    return status;
+}
+
+void initWorker(BFApp* app) {
+    wrkrApp = app;
+
+    //rebuild output
+    if(wOutput) {
+        free(wOutput);
+    }
+    wOutput = (char*)malloc(BF_OUTPUT_SIZE);
+    wOutputPtr = 0;
+
+    //rebuild stack
+    if(bfStack) {
+        free(bfStack);
+    }
+    bfStack = (uint8_t*)malloc(BF_STACK_INITIAL_SIZE);
+    memset(bfStack, 0x00, BF_STACK_INITIAL_SIZE);
+    stackSize = BF_STACK_INITIAL_SIZE;
+    stackSizeReal = 0;
+    stackPtr = 0;
+
+    //set instructions
+    inst = wrkrApp->dataBuffer;
+    instCount = wrkrApp->dataSize;
+    instPtr = 0;
+    runOpCount = 0;
+
+    //set input
+    wInput = wrkrApp->inputBuffer;
+    wInputPtr = 0;
+
+    //set status
+    status = 0;
+}
+
+void rShift() {
+    runOpCount++;
+    stackPtr++;
+    if(!validateStackPtr()) {
+        status = 2;
+        return;
+    }
+
+    while(stackPtr > stackSize) {
+        stackSize += BF_STACK_STEP_SIZE;
+        void* tmp = realloc(bfStack, stackSize);
+
+        if(!tmp) {
+            status = 2;
+            return;
+        }
+
+        memset((tmp + stackSize) - BF_STACK_STEP_SIZE, 0x00, BF_STACK_STEP_SIZE);
+        bfStack = (uint8_t*)tmp;
+    };
+    if(stackPtr > stackSizeReal) {
+        stackSizeReal = stackPtr;
+    }
+}
+
+void lShift() {
+    runOpCount++;
+    stackPtr--;
+    if(!validateStackPtr()) {
+        status = 2;
+        return;
+    }
+}
+
+void inc() {
+    runOpCount++;
+    if(!validateStackPtr()) {
+        status = 2;
+        return;
+    }
+    bfStack[stackPtr]++;
+}
+
+void dec() {
+    runOpCount++;
+    if(!validateStackPtr()) {
+        status = 2;
+        return;
+    }
+    bfStack[stackPtr]--;
+}
+
+void print() {
+    runOpCount++;
+    wOutput[wOutputPtr] = bfStack[stackPtr];
+    wOutputPtr++;
+    if(wOutputPtr > (BF_OUTPUT_SIZE - 1)) {
+        wOutputPtr = 0;
+    }
+}
+
+void input() {
+    runOpCount++;
+
+    bfStack[stackPtr] = (uint8_t)wInput[wInputPtr];
+    if(wInput[wInputPtr] == 0x00 || wInputPtr >= 64) {
+        wInputPtr = 0;
+    } else {
+        wInputPtr++;
+    }
+}
+
+void loop() {
+    runOpCount++;
+    if(bfStack[stackPtr] == 0) {
+        int loopCount = 1;
+        while(loopCount > 0) {
+            instPtr++;
+            if(!validateInstPtr()) {
+                status = 2;
+                return;
+            }
+            if(inst[instPtr] == '[') {
+                loopCount++;
+            } else if(inst[instPtr] == ']') {
+                loopCount--;
+            }
+        }
+    }
+}
+
+void endLoop() {
+    runOpCount++;
+    if(bfStack[stackPtr] != 0) {
+        int loopCount = 1;
+        while(loopCount > 0) {
+            instPtr--;
+            if(!validateInstPtr()) {
+                status = 2;
+                return;
+            }
+            if(inst[instPtr] == ']') {
+                loopCount++;
+            } else if(inst[instPtr] == '[') {
+                loopCount--;
+            }
+        }
+    }
+}
+
+static const NotificationSequence led_on = {
+    &message_blue_255,
+    &message_do_not_reset,
+    NULL,
+};
+
+static const NotificationSequence led_off = {
+    &message_blue_0,
+    NULL,
+};
+
+void input_kill(void* _ctx) {
+    UNUSED(_ctx);
+    killswitch = true;
+}
+
+void beginWorker() {
+    status = 1;
+
+    //redefined from furi_hal_resources.c
+    const GpioPin gpio_button_back = {.port = GPIOC, .pin = LL_GPIO_PIN_13};
+
+    while(inst[instPtr] != 0x00) {
+        if(runOpCount % 500 == 0) {
+            text_box_set_text(wrkrApp->text_box, workerGetOutput());
+            notification_message(wrkrApp->notifications, &led_on);
+        }
+
+        //status 2 indicates failure
+        if(status == 2) {
+            status = 0;
+            break;
+        }
+
+        //read back button directly to avoid weirdness in furi
+        if(killswitch || !furi_hal_gpio_read(&gpio_button_back)) {
+            status = 0;
+            killswitch = false;
+            break;
+        }
+
+        switch(inst[instPtr]) {
+        case '>':
+            rShift();
+            break;
+        case '<':
+            lShift();
+            break;
+
+        case '+':
+            inc();
+            break;
+
+        case '-':
+            dec();
+            break;
+
+        case '.':
+            print();
+            break;
+
+        case ',':
+            input();
+            break;
+
+        case '[':
+            loop();
+            break;
+
+        case ']':
+            endLoop();
+            break;
+
+        default:
+            break;
+        }
+        instPtr++;
+        if(!validateInstPtr()) {
+            status = 0;
+            break;
+        }
+    }
+
+    notification_message(wrkrApp->notifications, &led_off);
+    text_box_set_text(wrkrApp->text_box, workerGetOutput());
+    status = 0;
 }

+ 8 - 8
worker.h

@@ -1,9 +1,9 @@
-#include "brainfuck_i.h"
-
-void initWorker(BFApp* application);
-char* workerGetOutput();
-int getStackSize();
-int getOpCount();
-int getStatus();
-void beginWorker();
+#include "brainfuck_i.h"
+
+void initWorker(BFApp* application);
+char* workerGetOutput();
+int getStackSize();
+int getOpCount();
+int getStatus();
+void beginWorker();
 void killThread();