Просмотр исходного кода

Fixes for various apps. swd_probe: untested

hedger 2 лет назад
Родитель
Сommit
f8a572bf59

+ 0 - 1
apps_source_code/FlipBIP/helpers/flipbip_file.c

@@ -1,6 +1,5 @@
 #include "flipbip_file.h"
 #include <storage/storage.h>
-#include <applications.h>
 #include <loader/loader.h>
 #include "../helpers/flipbip_string.h"
 // From: lib/crypto

+ 0 - 1
apps_source_code/bc_scanner_emulator/views/bc_scanner_view.c

@@ -1,7 +1,6 @@
 #include "bc_scanner_view.h"
 #include "../bc_scanner_app_i.h"
 #include <gui/elements.h>
-#include <assets_icons.h>
 
 #define MAX_NAME_LEN 64
 #define TAG "BcScanner"

+ 9 - 3
apps_source_code/brainfuck/views/bf_dev_env.c

@@ -20,6 +20,12 @@ typedef struct {
     int right;
 } 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);
 static bool bf_dev_process_left(BFDevEnv* devEnv);
@@ -63,7 +69,7 @@ static void bf_dev_draw_button(Canvas* canvas, int x, int y, bool selected, cons
     if(selected) {
         canvas_draw_rbox(canvas, x, y, BT_X, BT_Y, 3);
         canvas_invert_color(canvas);
-        canvas_set_font(canvas, FontBatteryPercent);
+        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);
@@ -73,7 +79,7 @@ static void bf_dev_draw_button(Canvas* canvas, int x, int y, bool selected, cons
         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_set_font(canvas, FONT_NAME);
         canvas_draw_str_aligned(
             canvas, x + (BT_X / 2), y + (BT_Y / 2) - 1, AlignCenter, AlignCenter, lbl);
     }
@@ -131,7 +137,7 @@ 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) {

+ 12 - 10
apps_source_code/flipper_passgen/passgen.c

@@ -5,14 +5,14 @@
 #include <notification/notification_messages.h>
 #include <stdlib.h>
 #include <passgen_icons.h>
+#include <core/string.h>
 
 #define PASSGEN_MAX_LENGTH 16
-#define PASSGEN_CHARACTERS_LENGTH (26 * 4)
 
 #define PASSGEN_DIGITS "0123456789"
 #define PASSGEN_LETTERS_LOW "abcdefghijklmnopqrstuvwxyz"
 #define PASSGEN_LETTERS_UP "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
-#define PASSGEN_SPECIAL "!#$%^&*.-_"
+#define PASSGEN_SPECIAL "!#$%%^&*.-_"
 
 typedef enum PassGen_Alphabet {
     Digits = 1,
@@ -45,7 +45,8 @@ typedef struct {
     FuriMutex** mutex;
     NotificationApp* notify;
     char password[PASSGEN_MAX_LENGTH + 1];
-    char alphabet[PASSGEN_CHARACTERS_LENGTH + 1];
+    // char alphabet[PASSGEN_CHARACTERS_LENGTH + 1];
+    FuriString* alphabet;
     int length;
     int level;
 } PassGen;
@@ -57,6 +58,7 @@ void state_free(PassGen* app) {
     furi_message_queue_free(app->input_queue);
     furi_mutex_free(app->mutex);
     furi_record_close(RECORD_NOTIFICATION);
+    furi_string_free(app->alphabet);
     free(app);
 }
 
@@ -98,17 +100,17 @@ static void render_callback(Canvas* canvas, void* ctx) {
 
 void build_alphabet(PassGen* app) {
     PassGen_Alphabet mode = AlphabetLevels[app->level];
-    app->alphabet[0] = '\0';
-    if((mode & Digits) != 0) strcat(app->alphabet, PASSGEN_DIGITS);
-    if((mode & Lowercase) != 0) strcat(app->alphabet, PASSGEN_LETTERS_LOW);
-    if((mode & Uppercase) != 0) strcat(app->alphabet, PASSGEN_LETTERS_UP);
-    if((mode & Special) != 0) strcat(app->alphabet, PASSGEN_SPECIAL);
+    if((mode & Digits) != 0) furi_string_cat(app->alphabet, PASSGEN_DIGITS);
+    if((mode & Lowercase) != 0) furi_string_cat(app->alphabet, PASSGEN_LETTERS_LOW);
+    if((mode & Uppercase) != 0) furi_string_cat(app->alphabet, PASSGEN_LETTERS_UP);
+    if((mode & Special) != 0) furi_string_cat(app->alphabet, PASSGEN_SPECIAL);
 }
 
 PassGen* state_init() {
     PassGen* app = malloc(sizeof(PassGen));
     app->length = 8;
     app->level = 2;
+    app->alphabet = furi_string_alloc();
     build_alphabet(app);
     app->input_queue = furi_message_queue_alloc(8, sizeof(InputEvent));
     app->view_port = view_port_alloc();
@@ -124,10 +126,10 @@ PassGen* state_init() {
 }
 
 void generate(PassGen* app) {
-    int hi = strlen(app->alphabet);
+    int hi = furi_string_size(app->alphabet);
     for(int i = 0; i < app->length; i++) {
         int x = rand() % hi;
-        app->password[i] = app->alphabet[x];
+        app->password[i] = furi_string_get_char(app->alphabet, x);
     }
     app->password[app->length] = '\0';
 }

+ 4 - 5
apps_source_code/flipperzero-text2sam/stm32_sam.cpp

@@ -5400,15 +5400,14 @@ void STM32SAM::sam(
         }
     }
 
+    if(i < 256) {
+        input[i] = phonetic ? '\x9b' : '[';
+    }
+
     if(!phonetic) {
-        strncat(input, "[", 256);
         if(!TextToPhonemes((unsigned char*)input)) {
-            // PrintUsage();
             return;
         }
-
-    } else {
-        strncat(input, "\x9b", 256);
     }
 
     SetInput(input);

+ 1 - 2
apps_source_code/flipperzero_gpioreader/application.fam

@@ -3,11 +3,10 @@ App(
     name="[GPIO] Input Reader 2",
     apptype=FlipperAppType.EXTERNAL,
     entry_point="gpio_app",
-    cdefines=["APP_GPIOREADER"],
     requires=["gui"],
     stack_size=1 * 1024,
     order=50,
-    fap_libs=["assets"],
     fap_category="GPIO_Extra",
     fap_icon="icon.png",
+    fap_icon_assets="icons",
 )

+ 1 - 1
apps_source_code/flipperzero_gpioreader/gpio_app_i.h

@@ -16,7 +16,7 @@
 #include "views/gpio_test.h"
 #include "views/gpio_reader.h"
 #include "views/gpio_usb_uart.h"
-#include <assets_icons.h>
+#include <gpioreader2_icons.h>
 
 struct GpioApp {
     Gui* gui;

BIN
apps_source_code/flipperzero_gpioreader/icons/ActiveConnection_50x64.png


BIN
apps_source_code/flipperzero_gpioreader/icons/ArrowUpEmpty_14x15.png


BIN
apps_source_code/flipperzero_gpioreader/icons/ArrowUpFilled_14x15.png


+ 0 - 1
main_apps_sources/bomberduck/bomberduck.c

@@ -5,7 +5,6 @@
 #include <input/input.h>
 #include <notification/notification.h>
 #include <notification/notification_messages.h>
-#include <gui/canvas_i.h>
 #include "bomberduck_icons.h"
 #include <dolphin/dolphin.h>
 

+ 0 - 1
main_apps_sources/flappy_bird/assets/bird/frame_rate

@@ -1 +0,0 @@
-3

+ 0 - 0
main_apps_sources/flappy_bird/assets/bird/frame_01.png → main_apps_sources/flappy_bird/assets/bird_01.png


+ 0 - 0
main_apps_sources/flappy_bird/assets/bird/frame_02.png → main_apps_sources/flappy_bird/assets/bird_02.png


+ 0 - 0
main_apps_sources/flappy_bird/assets/bird/frame_03.png → main_apps_sources/flappy_bird/assets/bird_03.png


+ 18 - 9
main_apps_sources/flappy_bird/flappy_bird.c

@@ -3,7 +3,6 @@
 #include <flappy_bird_icons.h>
 #include <furi.h>
 #include <gui/gui.h>
-#include <gui/icon_animation_i.h>
 #include <input/input.h>
 #include <dolphin/dolphin.h>
 
@@ -30,6 +29,19 @@ typedef enum {
     EventTypeKey,
 } EventType;
 
+typedef enum {
+    BirdState0 = 0,
+    BirdState1,
+    BirdState2,
+    BirdStateMAX
+} BirdState;
+
+const Icon* bird_states[BirdStateMAX] = {
+    &I_bird_01,
+    &I_bird_02,
+    &I_bird_03,
+};
+
 typedef struct {
     int x;
     int y;
@@ -38,7 +50,6 @@ typedef struct {
 typedef struct {
     float gravity;
     POINT point;
-    IconAnimation* sprite;
 } BIRD;
 
 typedef struct {
@@ -93,7 +104,6 @@ static void flappy_game_state_init(GameState* const game_state) {
     bird.gravity = 0.0f;
     bird.point.x = 15;
     bird.point.y = 32;
-    bird.sprite = icon_animation_alloc(&A_bird);
 
     game_state->debug = DEBUG;
     game_state->bird = bird;
@@ -106,7 +116,6 @@ static void flappy_game_state_init(GameState* const game_state) {
 }
 
 static void flappy_game_state_free(GameState* const game_state) {
-    icon_animation_free(game_state->bird.sprite);
     free(game_state);
 }
 
@@ -224,14 +233,14 @@ static void flappy_game_render_callback(Canvas* const canvas, void* ctx) {
         }
 
         // Switch animation
-        game_state->bird.sprite->frame = 1;
+        BirdState bird_state = BirdState1;
         if(game_state->bird.gravity < -0.5)
-            game_state->bird.sprite->frame = 0;
+            bird_state = BirdState0;
         else if(game_state->bird.gravity > 0.5)
-            game_state->bird.sprite->frame = 2;
+            bird_state = BirdState2;
 
-        canvas_draw_icon_animation(
-            canvas, game_state->bird.point.x, game_state->bird.point.y, game_state->bird.sprite);
+        canvas_draw_icon(
+            canvas, game_state->bird.point.x, game_state->bird.point.y, bird_states[bird_state]);
 
         canvas_set_font(canvas, FontSecondary);
         char buffer[12];

+ 0 - 1
main_apps_sources/heap_defence_game/heap_defence.c

@@ -14,7 +14,6 @@
 #include <input/input.h>
 #include <notification/notification.h>
 #include <notification/notification_messages.h>
-#include <gui/canvas_i.h>
 #include <dolphin/dolphin.h>
 
 #define Y_FIELD_SIZE 6

+ 0 - 1
main_apps_sources/minesweeper/minesweeper.c

@@ -6,7 +6,6 @@
 
 #include <notification/notification_messages.h>
 #include <dialogs/dialogs.h>
-#include <m-string.h>
 
 #include <dolphin/dolphin.h>
 

+ 35 - 30
main_apps_sources/swd_probe/swd_probe_app.c

@@ -679,7 +679,7 @@ static bool swd_apscan_test(AppFSM* const ctx, uint32_t ap) {
 static void swd_script_log(ScriptContext* ctx, FuriLogLevel level, const char* format, ...) {
     bool commandline = false;
     ScriptContext* cur = ctx;
-    char buffer[256];
+    FuriString* buffer = furi_string_alloc();
     va_list argp;
     va_start(argp, format);
 
@@ -704,17 +704,19 @@ static void swd_script_log(ScriptContext* ctx, FuriLogLevel level, const char* f
             break;
         }
 
-        strcpy(buffer, prefix);
-        size_t pos = strlen(buffer);
-        vsnprintf(&buffer[pos], sizeof(buffer) - pos - 2, format, argp);
-        strcat(buffer, "\n");
-        if(!usb_uart_tx_data(ctx->app->uart, (uint8_t*)buffer, strlen(buffer))) {
+        furi_string_cat_str(buffer, prefix);
+        furi_string_cat_printf(buffer, format, argp);
+        furi_string_cat_str(buffer, "\n");
+
+        if(!usb_uart_tx_data(
+               ctx->app->uart, (uint8_t*)furi_string_get_cstr(buffer), furi_string_size(buffer))) {
             DBGS("Sending via USB failed");
         }
     } else {
-        LOG(buffer);
+        LOG(furi_string_get_cstr(buffer));
     }
     va_end(argp);
+    furi_string_free(buffer);
 }
 
 /* read characters until newline was read */
@@ -939,41 +941,44 @@ static bool swd_scriptfunc_goto(ScriptContext* ctx) {
     return true;
 }
 
+#include <toolbox/path.h>
+
 static bool swd_scriptfunc_call(ScriptContext* ctx) {
     DBGS("call");
 
     swd_script_skip_whitespace(ctx);
 
     /* fetch previous file directory */
-    char filename[MAX_FILE_LENGTH];
-    strncpy(filename, ctx->filename, sizeof(filename));
-    char* path = strrchr(filename, '/');
-    path[1] = '\000';
+    FuriString* filepath = furi_string_alloc();
+    path_extract_dirname(ctx->filename, filepath);
+    // strncpy(filename, ctx->filename, sizeof(filename));
 
-    /* append filename */
-    if(!swd_script_get_string(ctx, &path[1], sizeof(filename) - strlen(path))) {
-        swd_script_log(ctx, FuriLogLevelError, "failed to parse filename");
-        return false;
-    }
-
-    swd_script_seek_newline(ctx);
+    char filename[MAX_FILE_LENGTH] = {};
+    bool success = false;
+    do {
+        /* append filename */
+        if(!swd_script_get_string(ctx, filename, sizeof(filename))) {
+            swd_script_log(ctx, FuriLogLevelError, "failed to parse filename");
+            break;
+        }
 
-    /* append extension */
-    if(strlen(filename) + 5 >= sizeof(filename)) {
-        swd_script_log(ctx, FuriLogLevelError, "name too long");
-        return false;
-    }
+        swd_script_seek_newline(ctx);
+        /* append extension */
+        furi_string_cat_str(filepath, ".swd");
 
-    strcat(filename, ".swd");
+        bool ret = swd_execute_script(ctx->app, furi_string_get_cstr(filepath));
 
-    bool ret = swd_execute_script(ctx->app, filename);
+        if(!ret) {
+            swd_script_log(
+                ctx, FuriLogLevelError, "failed to exec '%s'", furi_string_get_cstr(filepath));
+            break;
+        }
 
-    if(!ret) {
-        swd_script_log(ctx, FuriLogLevelError, "failed to exec '%s'", filename);
-        return false;
-    }
+        success = true;
+    } while(false);
+    furi_string_free(filepath);
 
-    return true;
+    return success;
 }
 
 static bool swd_scriptfunc_status(ScriptContext* ctx) {