From 000bc845a811ae1242697dc62f175c9b6c79c30e Mon Sep 17 00:00:00 2001
From: MX <10697207+xMasterX@users.noreply.github.com>
Date: Wed, 5 Jul 2023 17:59:09 +0300
Subject: [PATCH] Multiple Fixes
by hedger
---
applications/external/bomberduck/bomberduck.c | 1 -
.../flappy_bird/assets/bird/frame_rate | 1 -
.../assets/{bird/frame_01.png => bird_01.png} | Bin
.../assets/{bird/frame_02.png => bird_02.png} | Bin
.../assets/{bird/frame_03.png => bird_03.png} | Bin
.../external/flappy_bird/flappy_bird.c | 27 +++++---
.../external/heap_defence_game/heap_defence.c | 1 -
.../external/minesweeper/minesweeper.c | 1 -
.../external/swd_probe/swd_probe_app.c | 65 ++++++++++--------
9 files changed, 53 insertions(+), 43 deletions(-)
delete mode 100644 applications/external/flappy_bird/assets/bird/frame_rate
rename applications/external/flappy_bird/assets/{bird/frame_01.png => bird_01.png} (100%)
rename applications/external/flappy_bird/assets/{bird/frame_02.png => bird_02.png} (100%)
rename applications/external/flappy_bird/assets/{bird/frame_03.png => bird_03.png} (100%)
diff --git a/applications/external/bomberduck/bomberduck.c b/applications/external/bomberduck/bomberduck.c
index 79471c99e..3e9d52f56 100644
--- a/applications/external/bomberduck/bomberduck.c
+++ b/applications/external/bomberduck/bomberduck.c
@@ -5,7 +5,6 @@
#include
#include
#include
-#include
#include "bomberduck_icons.h"
#include
diff --git a/applications/external/flappy_bird/assets/bird/frame_rate b/applications/external/flappy_bird/assets/bird/frame_rate
deleted file mode 100644
index e440e5c84..000000000
--- a/applications/external/flappy_bird/assets/bird/frame_rate
+++ /dev/null
@@ -1 +0,0 @@
-3
\ No newline at end of file
diff --git a/applications/external/flappy_bird/assets/bird/frame_01.png b/applications/external/flappy_bird/assets/bird_01.png
similarity index 100%
rename from applications/external/flappy_bird/assets/bird/frame_01.png
rename to applications/external/flappy_bird/assets/bird_01.png
diff --git a/applications/external/flappy_bird/assets/bird/frame_02.png b/applications/external/flappy_bird/assets/bird_02.png
similarity index 100%
rename from applications/external/flappy_bird/assets/bird/frame_02.png
rename to applications/external/flappy_bird/assets/bird_02.png
diff --git a/applications/external/flappy_bird/assets/bird/frame_03.png b/applications/external/flappy_bird/assets/bird_03.png
similarity index 100%
rename from applications/external/flappy_bird/assets/bird/frame_03.png
rename to applications/external/flappy_bird/assets/bird_03.png
diff --git a/applications/external/flappy_bird/flappy_bird.c b/applications/external/flappy_bird/flappy_bird.c
index 2a50868f2..7ec152b99 100644
--- a/applications/external/flappy_bird/flappy_bird.c
+++ b/applications/external/flappy_bird/flappy_bird.c
@@ -3,7 +3,6 @@
#include
#include
#include
-#include
#include
#include
@@ -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];
diff --git a/applications/external/heap_defence_game/heap_defence.c b/applications/external/heap_defence_game/heap_defence.c
index 3c8483c75..111c22dce 100644
--- a/applications/external/heap_defence_game/heap_defence.c
+++ b/applications/external/heap_defence_game/heap_defence.c
@@ -14,7 +14,6 @@
#include
#include
#include
-#include
#include
#define Y_FIELD_SIZE 6
diff --git a/applications/external/minesweeper/minesweeper.c b/applications/external/minesweeper/minesweeper.c
index c169b075e..4e92fba33 100644
--- a/applications/external/minesweeper/minesweeper.c
+++ b/applications/external/minesweeper/minesweeper.c
@@ -6,7 +6,6 @@
#include
#include
-#include
#include
diff --git a/applications/external/swd_probe/swd_probe_app.c b/applications/external/swd_probe/swd_probe_app.c
index 27ef03f5d..63f219508 100644
--- a/applications/external/swd_probe/swd_probe_app.c
+++ b/applications/external/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
+
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;
- }
+ 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;
+ }
- swd_script_seek_newline(ctx);
+ swd_script_seek_newline(ctx);
+ /* append extension */
+ furi_string_cat_str(filepath, ".swd");
- /* append extension */
- if(strlen(filename) + 5 >= sizeof(filename)) {
- swd_script_log(ctx, FuriLogLevelError, "name too long");
- return false;
- }
+ bool ret = swd_execute_script(ctx->app, furi_string_get_cstr(filepath));
- strcat(filename, ".swd");
+ if(!ret) {
+ swd_script_log(
+ ctx, FuriLogLevelError, "failed to exec '%s'", furi_string_get_cstr(filepath));
+ break;
+ }
- bool ret = swd_execute_script(ctx->app, filename);
+ success = true;
+ } while(false);
+ furi_string_free(filepath);
- if(!ret) {
- swd_script_log(ctx, FuriLogLevelError, "failed to exec '%s'", filename);
- return false;
- }
-
- return true;
+ return success;
}
static bool swd_scriptfunc_status(ScriptContext* ctx) {