Преглед изворни кода

main apps src part1 - with all manifests ready

MX пре 2 година
родитељ
комит
7a0b134a86
100 измењених фајлова са 7996 додато и 0 уклоњено
  1. 14 0
      main_apps_sources/arkanoid/application.fam
  2. BIN
      main_apps_sources/arkanoid/arkanoid_10px.png
  3. 479 0
      main_apps_sources/arkanoid/arkanoid_game.c
  4. 17 0
      main_apps_sources/barcode_generator/application.fam
  5. BIN
      main_apps_sources/barcode_generator/barcode_10px.png
  6. 447 0
      main_apps_sources/barcode_generator/barcode_generator.c
  7. 115 0
      main_apps_sources/barcode_generator/barcode_generator.h
  8. 15 0
      main_apps_sources/blackjack/application.fam
  9. BIN
      main_apps_sources/blackjack/assets/blackjack.png
  10. BIN
      main_apps_sources/blackjack/assets/card_graphics.png
  11. BIN
      main_apps_sources/blackjack/assets/endscreen.png
  12. 633 0
      main_apps_sources/blackjack/blackjack.c
  13. BIN
      main_apps_sources/blackjack/blackjack_10px.png
  14. 353 0
      main_apps_sources/blackjack/common/card.c
  15. 192 0
      main_apps_sources/blackjack/common/card.h
  16. 53 0
      main_apps_sources/blackjack/common/dml.c
  17. 116 0
      main_apps_sources/blackjack/common/dml.h
  18. 103 0
      main_apps_sources/blackjack/common/menu.c
  19. 77 0
      main_apps_sources/blackjack/common/menu.h
  20. 69 0
      main_apps_sources/blackjack/common/queue.c
  21. 70 0
      main_apps_sources/blackjack/common/queue.h
  22. 257 0
      main_apps_sources/blackjack/common/ui.c
  23. 105 0
      main_apps_sources/blackjack/common/ui.h
  24. 77 0
      main_apps_sources/blackjack/defines.h
  25. 186 0
      main_apps_sources/blackjack/ui.c
  26. 18 0
      main_apps_sources/blackjack/ui.h
  27. 123 0
      main_apps_sources/blackjack/util.c
  28. 7 0
      main_apps_sources/blackjack/util.h
  29. 22 0
      main_apps_sources/bomberduck/LICENSE
  30. 2 0
      main_apps_sources/bomberduck/README.md
  31. 17 0
      main_apps_sources/bomberduck/application.fam
  32. BIN
      main_apps_sources/bomberduck/assets/bomb0.png
  33. BIN
      main_apps_sources/bomberduck/assets/bomb1.png
  34. BIN
      main_apps_sources/bomberduck/assets/bomb2.png
  35. BIN
      main_apps_sources/bomberduck/assets/box.png
  36. BIN
      main_apps_sources/bomberduck/assets/end.png
  37. BIN
      main_apps_sources/bomberduck/assets/enemy1.png
  38. BIN
      main_apps_sources/bomberduck/assets/enemyleft.png
  39. BIN
      main_apps_sources/bomberduck/assets/enemyright.png
  40. BIN
      main_apps_sources/bomberduck/assets/explore.png
  41. BIN
      main_apps_sources/bomberduck/assets/playerleft.png
  42. BIN
      main_apps_sources/bomberduck/assets/playerright.png
  43. BIN
      main_apps_sources/bomberduck/assets/unbreakbox.png
  44. BIN
      main_apps_sources/bomberduck/bomb.png
  45. 648 0
      main_apps_sources/bomberduck/bomberduck.c
  46. 674 0
      main_apps_sources/dtmf_dolphin/LICENSE
  47. 18 0
      main_apps_sources/dtmf_dolphin/README.md
  48. 18 0
      main_apps_sources/dtmf_dolphin/application.fam
  49. 89 0
      main_apps_sources/dtmf_dolphin/dtmf_dolphin.c
  50. 270 0
      main_apps_sources/dtmf_dolphin/dtmf_dolphin_audio.c
  51. 54 0
      main_apps_sources/dtmf_dolphin/dtmf_dolphin_audio.h
  52. 220 0
      main_apps_sources/dtmf_dolphin/dtmf_dolphin_data.c
  53. 36 0
      main_apps_sources/dtmf_dolphin/dtmf_dolphin_data.h
  54. 21 0
      main_apps_sources/dtmf_dolphin/dtmf_dolphin_event.h
  55. 52 0
      main_apps_sources/dtmf_dolphin/dtmf_dolphin_hal.c
  56. 33 0
      main_apps_sources/dtmf_dolphin/dtmf_dolphin_hal.h
  57. 42 0
      main_apps_sources/dtmf_dolphin/dtmf_dolphin_i.h
  58. BIN
      main_apps_sources/dtmf_dolphin/phone.png
  59. BIN
      main_apps_sources/dtmf_dolphin/pics/dialer.jpg
  60. 30 0
      main_apps_sources/dtmf_dolphin/scenes/dtmf_dolphin_scene.c
  61. 29 0
      main_apps_sources/dtmf_dolphin/scenes/dtmf_dolphin_scene.h
  62. 2 0
      main_apps_sources/dtmf_dolphin/scenes/dtmf_dolphin_scene_config.h
  63. 49 0
      main_apps_sources/dtmf_dolphin/scenes/dtmf_dolphin_scene_dialer.c
  64. 94 0
      main_apps_sources/dtmf_dolphin/scenes/dtmf_dolphin_scene_start.c
  65. 10 0
      main_apps_sources/dtmf_dolphin/views/dtmf_dolphin_common.h
  66. 350 0
      main_apps_sources/dtmf_dolphin/views/dtmf_dolphin_dialer.c
  67. 18 0
      main_apps_sources/dtmf_dolphin/views/dtmf_dolphin_dialer.h
  68. 7 0
      main_apps_sources/esp8266_deauth/FlipperZeroWiFiDeauthModuleDefines.h
  69. 14 0
      main_apps_sources/esp8266_deauth/application.fam
  70. 543 0
      main_apps_sources/esp8266_deauth/esp8266_deauth.c
  71. BIN
      main_apps_sources/esp8266_deauth/wifi_10px.png
  72. 15 0
      main_apps_sources/flappy_bird/application.fam
  73. BIN
      main_apps_sources/flappy_bird/assets/bird/frame_01.png
  74. BIN
      main_apps_sources/flappy_bird/assets/bird/frame_02.png
  75. BIN
      main_apps_sources/flappy_bird/assets/bird/frame_03.png
  76. 1 0
      main_apps_sources/flappy_bird/assets/bird/frame_rate
  77. BIN
      main_apps_sources/flappy_bird/flappy_10px.png
  78. 374 0
      main_apps_sources/flappy_bird/flappy_bird.c
  79. 44 0
      main_apps_sources/flipper_i2ctools/README.md
  80. 15 0
      main_apps_sources/flipper_i2ctools/application.fam
  81. 35 0
      main_apps_sources/flipper_i2ctools/i2cscanner.c
  82. 23 0
      main_apps_sources/flipper_i2ctools/i2cscanner.h
  83. 29 0
      main_apps_sources/flipper_i2ctools/i2csender.c
  84. 21 0
      main_apps_sources/flipper_i2ctools/i2csender.h
  85. 101 0
      main_apps_sources/flipper_i2ctools/i2csniffer.c
  86. 46 0
      main_apps_sources/flipper_i2ctools/i2csniffer.h
  87. 225 0
      main_apps_sources/flipper_i2ctools/i2ctools.c
  88. BIN
      main_apps_sources/flipper_i2ctools/i2ctools.gif
  89. BIN
      main_apps_sources/flipper_i2ctools/i2ctools.png
  90. 23 0
      main_apps_sources/flipper_i2ctools/i2ctools_i.h
  91. BIN
      main_apps_sources/flipper_i2ctools/images/ButtonDown_7x4.png
  92. BIN
      main_apps_sources/flipper_i2ctools/images/ButtonLeft_4x7.png
  93. BIN
      main_apps_sources/flipper_i2ctools/images/ButtonRight_4x7.png
  94. BIN
      main_apps_sources/flipper_i2ctools/images/ButtonUp_7x4.png
  95. BIN
      main_apps_sources/flipper_i2ctools/images/Ok_btn_9x9.png
  96. BIN
      main_apps_sources/flipper_i2ctools/images/i2ctools_main_76x59.png
  97. 62 0
      main_apps_sources/flipper_i2ctools/views/main_view.c
  98. 38 0
      main_apps_sources/flipper_i2ctools/views/main_view.h
  99. 47 0
      main_apps_sources/flipper_i2ctools/views/scanner_view.c
  100. 9 0
      main_apps_sources/flipper_i2ctools/views/scanner_view.h

+ 14 - 0
main_apps_sources/arkanoid/application.fam

@@ -0,0 +1,14 @@
+App(
+    appid="arkanoid",
+    name="Arkanoid",
+    apptype=FlipperAppType.EXTERNAL,
+    entry_point="arkanoid_game_app",
+    requires=["gui"],
+    stack_size=1 * 1024,
+    order=30,
+    fap_icon="arkanoid_10px.png",
+    fap_category="Games",
+    fap_author="@xMasterX & @gotnull",
+    fap_version="1.0",
+    fap_description="Arkanoid Game",
+)

BIN
main_apps_sources/arkanoid/arkanoid_10px.png


+ 479 - 0
main_apps_sources/arkanoid/arkanoid_game.c

@@ -0,0 +1,479 @@
+#include <furi.h>
+#include <gui/gui.h>
+#include <input/input.h>
+#include <stdlib.h>
+#include <gui/view.h>
+#include <notification/notification.h>
+#include <notification/notification_messages.h>
+#include <dolphin/dolphin.h>
+
+#define TAG "Arkanoid"
+
+#define FLIPPER_LCD_WIDTH 128
+#define FLIPPER_LCD_HEIGHT 64
+#define MAX_SPEED 3
+
+typedef enum { EventTypeTick, EventTypeKey } EventType;
+
+typedef struct {
+    //Brick Bounds used in collision detection
+    int leftBrick;
+    int rightBrick;
+    int topBrick;
+    int bottomBrick;
+    bool isHit[4][13]; //Array of if bricks are hit or not
+} BrickState;
+
+typedef struct {
+    int dx; //Initial movement of ball
+    int dy; //Initial movement of ball
+    int xb; //Balls starting possition
+    int yb; //Balls starting possition
+    bool released; //If the ball has been released by the player
+    //Ball Bounds used in collision detection
+    int leftBall;
+    int rightBall;
+    int topBall;
+    int bottomBall;
+} BallState;
+
+typedef struct {
+    FuriMutex* mutex;
+    BallState ball_state;
+    BrickState brick_state;
+    NotificationApp* notify;
+    unsigned int COLUMNS; //Columns of bricks
+    unsigned int ROWS; //Rows of bricks
+    bool initialDraw; //If the inital draw has happened
+    int xPaddle; //X position of paddle
+    char text[16]; //General string buffer
+    bool bounced; //Used to fix double bounce glitch
+    int lives; //Amount of lives
+    int level; //Current level
+    unsigned int score; //Score for the game
+    unsigned int brickCount; //Amount of bricks hit
+    int tick; //Tick counter
+    bool gameStarted; // Did the game start?
+    int speed; // Ball speed
+} ArkanoidState;
+
+typedef struct {
+    EventType type;
+    InputEvent input;
+} GameEvent;
+
+static const NotificationSequence sequence_short_sound = {
+    &message_note_c5,
+    &message_delay_50,
+    &message_sound_off,
+    NULL,
+};
+
+// generate number in range [min,max)
+int rand_range(int min, int max) {
+    return min + rand() % (max - min);
+}
+
+void move_ball(Canvas* canvas, ArkanoidState* st) {
+    st->tick++;
+
+    int current_speed = abs(st->speed - 1 - MAX_SPEED);
+    if(st->tick % current_speed != 0 && st->tick % (current_speed + 1) != 0) {
+        return;
+    }
+
+    if(st->ball_state.released) {
+        //Move ball
+        if(abs(st->ball_state.dx) == 2) {
+            st->ball_state.xb += st->ball_state.dx / 2;
+            // 2x speed is really 1.5 speed
+            if((st->tick / current_speed) % 2 == 0) st->ball_state.xb += st->ball_state.dx / 2;
+        } else {
+            st->ball_state.xb += st->ball_state.dx;
+        }
+        st->ball_state.yb = st->ball_state.yb + st->ball_state.dy;
+
+        //Set bounds
+        st->ball_state.leftBall = st->ball_state.xb;
+        st->ball_state.rightBall = st->ball_state.xb + 2;
+        st->ball_state.topBall = st->ball_state.yb;
+        st->ball_state.bottomBall = st->ball_state.yb + 2;
+
+        //Bounce off top edge
+        if(st->ball_state.yb <= 0) {
+            st->ball_state.yb = 2;
+            st->ball_state.dy = -st->ball_state.dy;
+        }
+
+        //Lose a life if bottom edge hit
+        if(st->ball_state.yb >= FLIPPER_LCD_HEIGHT) {
+            canvas_draw_frame(canvas, st->xPaddle, FLIPPER_LCD_HEIGHT - 1, 11, 1);
+            st->xPaddle = 54;
+            st->ball_state.yb = 60;
+            st->ball_state.released = false;
+            st->lives--;
+            st->gameStarted = false;
+
+            if(rand_range(0, 2) == 0) {
+                st->ball_state.dx = 1;
+            } else {
+                st->ball_state.dx = -1;
+            }
+        }
+
+        //Bounce off left side
+        if(st->ball_state.xb <= 0) {
+            st->ball_state.xb = 2;
+            st->ball_state.dx = -st->ball_state.dx;
+        }
+
+        //Bounce off right side
+        if(st->ball_state.xb >= FLIPPER_LCD_WIDTH - 2) {
+            st->ball_state.xb = FLIPPER_LCD_WIDTH - 4;
+            st->ball_state.dx = -st->ball_state.dx;
+            // arduboy.tunes.tone(523, 250);
+        }
+
+        //Bounce off paddle
+        if(st->ball_state.xb + 1 >= st->xPaddle && st->ball_state.xb <= st->xPaddle + 12 &&
+           st->ball_state.yb + 2 >= FLIPPER_LCD_HEIGHT - 1 &&
+           st->ball_state.yb <= FLIPPER_LCD_HEIGHT) {
+            st->ball_state.dy = -st->ball_state.dy;
+            st->ball_state.dx =
+                ((st->ball_state.xb - (st->xPaddle + 6)) / 3); //Applies spin on the ball
+            // prevent straight bounce, but not prevent roguuemaster from stealing
+            if(st->ball_state.dx == 0) {
+                st->ball_state.dx = (rand_range(0, 2) == 1) ? 1 : -1;
+            }
+        }
+
+        //Bounce off Bricks
+        for(unsigned int row = 0; row < st->ROWS; row++) {
+            for(unsigned int column = 0; column < st->COLUMNS; column++) {
+                if(!st->brick_state.isHit[row][column]) {
+                    //Sets Brick bounds
+                    st->brick_state.leftBrick = 10 * column;
+                    st->brick_state.rightBrick = 10 * column + 10;
+                    st->brick_state.topBrick = 6 * row + 1;
+                    st->brick_state.bottomBrick = 6 * row + 7;
+
+                    //If A collison has occured
+                    if(st->ball_state.topBall <= st->brick_state.bottomBrick &&
+                       st->ball_state.bottomBall >= st->brick_state.topBrick &&
+                       st->ball_state.leftBall <= st->brick_state.rightBrick &&
+                       st->ball_state.rightBall >= st->brick_state.leftBrick) {
+                        st->score += st->level;
+                        // Blink led when we hit some brick
+                        notification_message(st->notify, &sequence_short_sound);
+                        //notification_message(st->notify, &sequence_blink_white_100);
+
+                        st->brickCount++;
+                        st->brick_state.isHit[row][column] = true;
+                        canvas_draw_frame(canvas, 10 * column, 2 + 6 * row, 8, 4);
+
+                        //Vertical collision
+                        if(st->ball_state.bottomBall > st->brick_state.bottomBrick ||
+                           st->ball_state.topBall < st->brick_state.topBrick) {
+                            //Only bounce once each ball move
+                            if(!st->bounced) {
+                                st->ball_state.dy = -st->ball_state.dy;
+                                st->ball_state.yb += st->ball_state.dy;
+                                st->bounced = true;
+                            }
+                        }
+
+                        //Hoizontal collision
+                        if(st->ball_state.leftBall < st->brick_state.leftBrick ||
+                           st->ball_state.rightBall > st->brick_state.rightBrick) {
+                            //Only bounce once brick each ball move
+                            if(!st->bounced) {
+                                st->ball_state.dx = -st->ball_state.dx;
+                                st->ball_state.xb += st->ball_state.dx;
+                                st->bounced = true;
+                            }
+                        }
+                    }
+                }
+            }
+        }
+
+        //Reset Bounce
+        st->bounced = false;
+    } else {
+        //Ball follows paddle
+        st->ball_state.xb = st->xPaddle + 5;
+    }
+}
+
+void draw_lives(Canvas* canvas, ArkanoidState* arkanoid_state) {
+    if(arkanoid_state->lives == 3) {
+        canvas_draw_dot(canvas, 4, FLIPPER_LCD_HEIGHT - 7);
+        canvas_draw_dot(canvas, 3, FLIPPER_LCD_HEIGHT - 7);
+        canvas_draw_dot(canvas, 4, FLIPPER_LCD_HEIGHT - 8);
+        canvas_draw_dot(canvas, 3, FLIPPER_LCD_HEIGHT - 8);
+
+        canvas_draw_dot(canvas, 4, FLIPPER_LCD_HEIGHT - 11);
+        canvas_draw_dot(canvas, 3, FLIPPER_LCD_HEIGHT - 11);
+        canvas_draw_dot(canvas, 4, FLIPPER_LCD_HEIGHT - 12);
+        canvas_draw_dot(canvas, 3, FLIPPER_LCD_HEIGHT - 12);
+
+        canvas_draw_dot(canvas, 4, FLIPPER_LCD_HEIGHT - 15);
+        canvas_draw_dot(canvas, 3, FLIPPER_LCD_HEIGHT - 15);
+        canvas_draw_dot(canvas, 4, FLIPPER_LCD_HEIGHT - 16);
+        canvas_draw_dot(canvas, 3, FLIPPER_LCD_HEIGHT - 16);
+    } else if(arkanoid_state->lives == 2) {
+        canvas_draw_dot(canvas, 4, FLIPPER_LCD_HEIGHT - 7);
+        canvas_draw_dot(canvas, 3, FLIPPER_LCD_HEIGHT - 7);
+        canvas_draw_dot(canvas, 4, FLIPPER_LCD_HEIGHT - 8);
+        canvas_draw_dot(canvas, 3, FLIPPER_LCD_HEIGHT - 8);
+
+        canvas_draw_dot(canvas, 4, FLIPPER_LCD_HEIGHT - 11);
+        canvas_draw_dot(canvas, 3, FLIPPER_LCD_HEIGHT - 11);
+        canvas_draw_dot(canvas, 4, FLIPPER_LCD_HEIGHT - 12);
+        canvas_draw_dot(canvas, 3, FLIPPER_LCD_HEIGHT - 12);
+    } else {
+        canvas_draw_dot(canvas, 4, FLIPPER_LCD_HEIGHT - 7);
+        canvas_draw_dot(canvas, 3, FLIPPER_LCD_HEIGHT - 7);
+        canvas_draw_dot(canvas, 4, FLIPPER_LCD_HEIGHT - 8);
+        canvas_draw_dot(canvas, 3, FLIPPER_LCD_HEIGHT - 8);
+    }
+}
+
+void draw_score(Canvas* canvas, ArkanoidState* arkanoid_state) {
+    snprintf(arkanoid_state->text, sizeof(arkanoid_state->text), "%u", arkanoid_state->score);
+    canvas_draw_str_aligned(
+        canvas,
+        FLIPPER_LCD_WIDTH - 2,
+        FLIPPER_LCD_HEIGHT - 6,
+        AlignRight,
+        AlignBottom,
+        arkanoid_state->text);
+}
+
+void draw_ball(Canvas* canvas, ArkanoidState* ast) {
+    canvas_draw_dot(canvas, ast->ball_state.xb, ast->ball_state.yb);
+    canvas_draw_dot(canvas, ast->ball_state.xb + 1, ast->ball_state.yb);
+    canvas_draw_dot(canvas, ast->ball_state.xb, ast->ball_state.yb + 1);
+    canvas_draw_dot(canvas, ast->ball_state.xb + 1, ast->ball_state.yb + 1);
+
+    move_ball(canvas, ast);
+}
+
+void draw_paddle(Canvas* canvas, ArkanoidState* arkanoid_state) {
+    canvas_draw_frame(canvas, arkanoid_state->xPaddle, FLIPPER_LCD_HEIGHT - 1, 11, 1);
+}
+
+void reset_level(Canvas* canvas, ArkanoidState* arkanoid_state) {
+    //Undraw paddle
+    canvas_draw_frame(canvas, arkanoid_state->xPaddle, FLIPPER_LCD_HEIGHT - 1, 11, 1);
+
+    //Undraw ball
+    canvas_draw_dot(canvas, arkanoid_state->ball_state.xb, arkanoid_state->ball_state.yb);
+    canvas_draw_dot(canvas, arkanoid_state->ball_state.xb + 1, arkanoid_state->ball_state.yb);
+    canvas_draw_dot(canvas, arkanoid_state->ball_state.xb, arkanoid_state->ball_state.yb + 1);
+    canvas_draw_dot(canvas, arkanoid_state->ball_state.xb + 1, arkanoid_state->ball_state.yb + 1);
+
+    //Alter various variables to reset the game
+    arkanoid_state->xPaddle = 54;
+    arkanoid_state->ball_state.yb = 60;
+    arkanoid_state->brickCount = 0;
+    arkanoid_state->ball_state.released = false;
+    arkanoid_state->gameStarted = false;
+
+    // Reset all brick hit states
+    for(unsigned int row = 0; row < arkanoid_state->ROWS; row++) {
+        for(unsigned int column = 0; column < arkanoid_state->COLUMNS; column++) {
+            arkanoid_state->brick_state.isHit[row][column] = false;
+        }
+    }
+}
+
+static void arkanoid_state_init(ArkanoidState* arkanoid_state) {
+    // Init notification
+    arkanoid_state->notify = furi_record_open(RECORD_NOTIFICATION);
+
+    // Set the initial game state
+    arkanoid_state->COLUMNS = 13;
+    arkanoid_state->ROWS = 4;
+    arkanoid_state->ball_state.dx = -1;
+    arkanoid_state->ball_state.dy = -1;
+    arkanoid_state->speed = 2;
+    arkanoid_state->bounced = false;
+    arkanoid_state->lives = 3;
+    arkanoid_state->level = 1;
+    arkanoid_state->score = 0;
+    arkanoid_state->COLUMNS = 13;
+    arkanoid_state->COLUMNS = 13;
+
+    // Reset initial state
+    arkanoid_state->initialDraw = false;
+    arkanoid_state->gameStarted = false;
+}
+
+static void arkanoid_draw_callback(Canvas* const canvas, void* ctx) {
+    furi_assert(ctx);
+    ArkanoidState* arkanoid_state = ctx;
+    furi_mutex_acquire(arkanoid_state->mutex, FuriWaitForever);
+
+    //Initial level draw
+    if(!arkanoid_state->initialDraw) {
+        arkanoid_state->initialDraw = true;
+
+        // Set default font for text
+        canvas_set_font(canvas, FontSecondary);
+
+        //Draws the new level
+        reset_level(canvas, arkanoid_state);
+    }
+
+    //Draws new bricks and resets their values
+    for(unsigned int row = 0; row < arkanoid_state->ROWS; row++) {
+        for(unsigned int column = 0; column < arkanoid_state->COLUMNS; column++) {
+            if(!arkanoid_state->brick_state.isHit[row][column]) {
+                canvas_draw_frame(canvas, 10 * column, 2 + 6 * row, 8, 4);
+            }
+        }
+    }
+
+    if(arkanoid_state->lives > 0) {
+        draw_paddle(canvas, arkanoid_state);
+        draw_ball(canvas, arkanoid_state);
+        draw_score(canvas, arkanoid_state);
+        draw_lives(canvas, arkanoid_state);
+
+        if(arkanoid_state->brickCount == arkanoid_state->ROWS * arkanoid_state->COLUMNS) {
+            arkanoid_state->level++;
+            reset_level(canvas, arkanoid_state);
+        }
+    } else {
+        reset_level(canvas, arkanoid_state);
+        arkanoid_state->initialDraw = false;
+        arkanoid_state->lives = 3;
+        arkanoid_state->score = 0;
+    }
+
+    furi_mutex_release(arkanoid_state->mutex);
+}
+
+static void arkanoid_input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
+    furi_assert(event_queue);
+
+    GameEvent event = {.type = EventTypeKey, .input = *input_event};
+    furi_message_queue_put(event_queue, &event, FuriWaitForever);
+}
+
+static void arkanoid_update_timer_callback(FuriMessageQueue* event_queue) {
+    furi_assert(event_queue);
+
+    GameEvent event = {.type = EventTypeTick};
+    furi_message_queue_put(event_queue, &event, 0);
+}
+
+int32_t arkanoid_game_app(void* p) {
+    UNUSED(p);
+    int32_t return_code = 0;
+
+    FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(GameEvent));
+
+    ArkanoidState* arkanoid_state = malloc(sizeof(ArkanoidState));
+    arkanoid_state_init(arkanoid_state);
+
+    arkanoid_state->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
+    if(!arkanoid_state->mutex) {
+        FURI_LOG_E(TAG, "Cannot create mutex\r\n");
+        return_code = 255;
+        goto free_and_exit;
+    }
+
+    // Set system callbacks
+    ViewPort* view_port = view_port_alloc();
+    view_port_draw_callback_set(view_port, arkanoid_draw_callback, arkanoid_state);
+    view_port_input_callback_set(view_port, arkanoid_input_callback, event_queue);
+
+    FuriTimer* timer =
+        furi_timer_alloc(arkanoid_update_timer_callback, FuriTimerTypePeriodic, event_queue);
+    furi_timer_start(timer, furi_kernel_get_tick_frequency() / 22);
+
+    // Open GUI and register view_port
+    Gui* gui = furi_record_open(RECORD_GUI);
+    gui_add_view_port(gui, view_port, GuiLayerFullscreen);
+
+    // Call dolphin deed on game start
+    dolphin_deed(DolphinDeedPluginGameStart);
+
+    GameEvent event;
+    for(bool processing = true; processing;) {
+        FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
+        furi_mutex_acquire(arkanoid_state->mutex, FuriWaitForever);
+
+        if(event_status == FuriStatusOk) {
+            // Key events
+            if(event.type == EventTypeKey) {
+                if(event.input.type == InputTypePress || event.input.type == InputTypeLong ||
+                   event.input.type == InputTypeRepeat) {
+                    switch(event.input.key) {
+                    case InputKeyBack:
+                        processing = false;
+                        break;
+                    case InputKeyRight:
+                        if(arkanoid_state->xPaddle < FLIPPER_LCD_WIDTH - 12) {
+                            arkanoid_state->xPaddle += 8;
+                        }
+                        break;
+                    case InputKeyLeft:
+                        if(arkanoid_state->xPaddle > 0) {
+                            arkanoid_state->xPaddle -= 8;
+                        }
+                        break;
+                    case InputKeyUp:
+                        if(arkanoid_state->speed < MAX_SPEED) {
+                            arkanoid_state->speed++;
+                        }
+                        break;
+                    case InputKeyDown:
+                        if(arkanoid_state->speed > 1) {
+                            arkanoid_state->speed--;
+                        }
+                        break;
+                    case InputKeyOk:
+                        if(arkanoid_state->gameStarted == false) {
+                            //Release ball if FIRE pressed
+                            arkanoid_state->ball_state.released = true;
+
+                            //Apply random direction to ball on release
+                            if(rand_range(0, 2) == 0) {
+                                arkanoid_state->ball_state.dx = 1;
+                            } else {
+                                arkanoid_state->ball_state.dx = -1;
+                            }
+
+                            //Makes sure the ball heads upwards
+                            arkanoid_state->ball_state.dy = -1;
+                            //start the game flag
+                            arkanoid_state->gameStarted = true;
+                        }
+                        break;
+                    default:
+                        break;
+                    }
+                }
+            }
+        }
+
+        view_port_update(view_port);
+        furi_mutex_release(arkanoid_state->mutex);
+    }
+    furi_timer_free(timer);
+    view_port_enabled_set(view_port, false);
+    gui_remove_view_port(gui, view_port);
+    furi_record_close(RECORD_GUI);
+    furi_record_close(RECORD_NOTIFICATION);
+    view_port_free(view_port);
+    furi_mutex_free(arkanoid_state->mutex);
+
+free_and_exit:
+    free(arkanoid_state);
+    furi_message_queue_free(event_queue);
+
+    return return_code;
+}

+ 17 - 0
main_apps_sources/barcode_generator/application.fam

@@ -0,0 +1,17 @@
+App(
+    appid="barcode_generator",
+    name="Barcode Generator",
+    apptype=FlipperAppType.EXTERNAL,
+    entry_point="barcode_generator_app",
+    requires=[
+        "gui",
+        "dialogs",
+    ],
+    stack_size=1 * 1024,
+    order=50,
+    fap_icon="barcode_10px.png",
+    fap_category="Misc",
+    fap_author="@xMasterX & @msvsergey & @McAzzaMan",
+    fap_version="1.0",
+    fap_description="App displays Barcode on flipper screen and allows to edit it",
+)

BIN
main_apps_sources/barcode_generator/barcode_10px.png


+ 447 - 0
main_apps_sources/barcode_generator/barcode_generator.c

@@ -0,0 +1,447 @@
+#include "barcode_generator.h"
+
+static BarcodeType* barcodeTypes[NUMBER_OF_BARCODE_TYPES];
+
+void init_types() {
+    BarcodeType* upcA = malloc(sizeof(BarcodeType));
+    upcA->name = "UPC-A";
+    upcA->numberOfDigits = 12;
+    upcA->startPos = 19;
+    upcA->bartype = BarTypeUPCA;
+    barcodeTypes[0] = upcA;
+
+    BarcodeType* ean8 = malloc(sizeof(BarcodeType));
+    ean8->name = "EAN-8";
+    ean8->numberOfDigits = 8;
+    ean8->startPos = 33;
+    ean8->bartype = BarTypeEAN8;
+    barcodeTypes[1] = ean8;
+
+    BarcodeType* ean13 = malloc(sizeof(BarcodeType));
+    ean13->name = "EAN-13";
+    ean13->numberOfDigits = 13;
+    ean13->startPos = 19;
+    ean13->bartype = BarTypeEAN13;
+    barcodeTypes[2] = ean13;
+}
+
+void draw_digit(
+    Canvas* canvas,
+    int digit,
+    BarEncodingType rightHand,
+    int startingPosition,
+    bool drawlines) {
+    char digitStr[2];
+    snprintf(digitStr, 2, "%u", digit);
+    canvas_set_color(canvas, ColorBlack);
+    canvas_draw_str(
+        canvas, startingPosition, BARCODE_Y_START + BARCODE_HEIGHT + BARCODE_TEXT_OFFSET, digitStr);
+
+    if(drawlines) {
+        switch(rightHand) {
+        case BarEncodingTypeLeft:
+        case BarEncodingTypeRight:
+            canvas_set_color(
+                canvas, (rightHand == BarEncodingTypeRight) ? ColorBlack : ColorWhite);
+            //int count = 0;
+            for(int i = 0; i < 4; i++) {
+                canvas_draw_box(
+                    canvas, startingPosition, BARCODE_Y_START, DIGITS[digit][i], BARCODE_HEIGHT);
+                canvas_invert_color(canvas);
+                startingPosition += DIGITS[digit][i];
+            }
+            break;
+        case BarEncodingTypeG:
+            canvas_set_color(canvas, ColorWhite);
+            //int count = 0;
+            for(int i = 3; i >= 0; i--) {
+                canvas_draw_box(
+                    canvas, startingPosition, BARCODE_Y_START, DIGITS[digit][i], BARCODE_HEIGHT);
+                canvas_invert_color(canvas);
+                startingPosition += DIGITS[digit][i];
+            }
+            break;
+        default:
+            break;
+        }
+    }
+}
+
+int get_digit_position(int index, BarcodeType* type) {
+    int pos = 0;
+    switch(type->bartype) {
+    case BarTypeEAN8:
+    case BarTypeUPCA:
+        pos = type->startPos + index * 7;
+        if(index >= type->numberOfDigits / 2) {
+            pos += 5;
+        }
+        break;
+    case BarTypeEAN13:
+        if(index == 0)
+            pos = type->startPos - 10;
+        else {
+            pos = type->startPos + (index - 1) * 7;
+            if((index - 1) >= type->numberOfDigits / 2) {
+                pos += 5;
+            }
+        }
+        break;
+    default:
+        break;
+    }
+    return pos;
+}
+
+int get_menu_text_location(int index) {
+    return 20 + 10 * index;
+}
+
+int get_barcode_max_index(PluginState* plugin_state) {
+    return plugin_state->barcode_state.doParityCalculation ?
+               barcodeTypes[plugin_state->barcode_state.barcodeTypeIndex]->numberOfDigits - 1 :
+               barcodeTypes[plugin_state->barcode_state.barcodeTypeIndex]->numberOfDigits;
+}
+
+int calculate_check_digit(PluginState* plugin_state, BarcodeType* type) {
+    int checkDigit = 0;
+    int checkDigitOdd = 0;
+    int checkDigitEven = 0;
+    //add all odd positions. Confusing because 0index
+    for(int i = 0; i < type->numberOfDigits - 1; i += 2) {
+        checkDigitOdd += plugin_state->barcode_state.barcodeNumeral[i];
+    }
+
+    //add all even positions to above. Confusing because 0index
+    for(int i = 1; i < type->numberOfDigits - 1; i += 2) {
+        checkDigitEven += plugin_state->barcode_state.barcodeNumeral[i];
+    }
+
+    if(type->bartype == BarTypeEAN13) {
+        checkDigit = checkDigitEven * 3 + checkDigitOdd;
+    } else {
+        checkDigit = checkDigitOdd * 3 + checkDigitEven;
+    }
+
+    checkDigit = checkDigit % 10; //mod 10
+
+    //if m = 0 then x12 = 0, otherwise x12 is 10 - m
+    return (10 - checkDigit) % 10;
+}
+
+static void render_callback(Canvas* const canvas, void* ctx) {
+    furi_assert(ctx);
+    PluginState* plugin_state = ctx;
+    furi_mutex_acquire(plugin_state->mutex, FuriWaitForever);
+
+    if(plugin_state->mode == MenuMode) {
+        canvas_set_color(canvas, ColorBlack);
+        canvas_draw_str_aligned(canvas, 64, 6, AlignCenter, AlignCenter, "MENU");
+        canvas_draw_frame(canvas, 50, 0, 29, 11); //box around Menu
+        canvas_draw_str_aligned(
+            canvas, 64, get_menu_text_location(0), AlignCenter, AlignCenter, "View");
+        canvas_draw_str_aligned(
+            canvas, 64, get_menu_text_location(1), AlignCenter, AlignCenter, "Edit");
+        canvas_draw_str_aligned(
+            canvas, 64, get_menu_text_location(2), AlignCenter, AlignCenter, "Parity?");
+
+        canvas_draw_frame(canvas, 83, get_menu_text_location(2) - 3, 6, 6);
+        if(plugin_state->barcode_state.doParityCalculation == true) {
+            canvas_draw_box(canvas, 85, get_menu_text_location(2) - 1, 2, 2);
+        }
+        canvas_draw_str_aligned(
+            canvas,
+            64,
+            get_menu_text_location(3),
+            AlignCenter,
+            AlignCenter,
+            (barcodeTypes[plugin_state->barcode_state.barcodeTypeIndex])->name);
+        canvas_draw_disc(
+            canvas,
+            40,
+            get_menu_text_location(plugin_state->menuIndex) - 1,
+            2); //draw menu cursor
+    } else {
+        BarcodeType* type = barcodeTypes[plugin_state->barcode_state.barcodeTypeIndex];
+
+        //start saftey
+        canvas_set_color(canvas, ColorBlack);
+        canvas_draw_box(canvas, type->startPos - 3, BARCODE_Y_START, 1, BARCODE_HEIGHT + 2);
+        canvas_draw_box(canvas, (type->startPos - 1), BARCODE_Y_START, 1, BARCODE_HEIGHT + 2);
+
+        int startpos = 0;
+        int endpos = type->numberOfDigits;
+        if(type->bartype == BarTypeEAN13) {
+            startpos++;
+            draw_digit(
+                canvas,
+                plugin_state->barcode_state.barcodeNumeral[0],
+                BarEncodingTypeRight,
+                get_digit_position(0, barcodeTypes[plugin_state->barcode_state.barcodeTypeIndex]),
+                false);
+        }
+        if(plugin_state->barcode_state.doParityCalculation) { //calculate the check digit
+            plugin_state->barcode_state.barcodeNumeral[type->numberOfDigits - 1] =
+                calculate_check_digit(plugin_state, type);
+        }
+        for(int index = startpos; index < endpos; index++) {
+            BarEncodingType barEncodingType = BarEncodingTypeLeft;
+            if(type->bartype == BarTypeEAN13) {
+                if(index - 1 >= (type->numberOfDigits - 1) / 2) {
+                    barEncodingType = BarEncodingTypeRight;
+                } else {
+                    barEncodingType =
+                        (FURI_BIT(
+                            EAN13ENCODE[plugin_state->barcode_state.barcodeNumeral[0]],
+                            index - 1)) ?
+                            BarEncodingTypeG :
+                            BarEncodingTypeLeft;
+                }
+            } else {
+                if(index >= type->numberOfDigits / 2) {
+                    barEncodingType = BarEncodingTypeRight;
+                }
+            }
+
+            int digitPosition = get_digit_position(
+                index, barcodeTypes[plugin_state->barcode_state.barcodeTypeIndex]);
+            draw_digit(
+                canvas,
+                plugin_state->barcode_state.barcodeNumeral[index],
+                barEncodingType,
+                digitPosition,
+                true);
+        }
+
+        //central separator
+        canvas_set_color(canvas, ColorBlack);
+        canvas_draw_box(canvas, 62, BARCODE_Y_START, 1, BARCODE_HEIGHT + 2);
+        canvas_draw_box(canvas, 64, BARCODE_Y_START, 1, BARCODE_HEIGHT + 2);
+
+        if(plugin_state->mode == EditMode) {
+            canvas_set_color(canvas, ColorBlack);
+            canvas_draw_box(
+                canvas,
+                get_digit_position(
+                    plugin_state->editingIndex,
+                    barcodeTypes[plugin_state->barcode_state.barcodeTypeIndex]) -
+                    1,
+                63,
+                7,
+                1); //draw editing cursor
+        }
+
+        //end safety
+        int endSafetyPosition = get_digit_position(type->numberOfDigits - 1, type) + 7;
+        canvas_set_color(canvas, ColorBlack);
+        canvas_draw_box(canvas, endSafetyPosition, BARCODE_Y_START, 1, BARCODE_HEIGHT + 2);
+        canvas_draw_box(canvas, (endSafetyPosition + 2), BARCODE_Y_START, 1, BARCODE_HEIGHT + 2);
+    }
+
+    furi_mutex_release(plugin_state->mutex);
+}
+
+static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
+    furi_assert(event_queue);
+
+    PluginEvent event = {.type = EventTypeKey, .input = *input_event};
+    furi_message_queue_put(event_queue, &event, FuriWaitForever);
+}
+
+static void barcode_generator_state_init(PluginState* plugin_state) {
+    plugin_state->editingIndex = 0;
+    plugin_state->mode = ViewMode;
+    plugin_state->menuIndex = MENU_INDEX_VIEW;
+    if(!LOAD_BARCODE_SETTINGS(&plugin_state->barcode_state)) {
+        for(int i = 0; i < BARCODE_MAX_LENS; ++i) {
+            plugin_state->barcode_state.barcodeNumeral[i] = i % 10;
+        }
+        plugin_state->barcode_state.doParityCalculation = true;
+        plugin_state->barcode_state.barcodeTypeIndex = 0;
+    }
+}
+
+static bool handle_key_press_view(InputKey key, PluginState* plugin_state) {
+    switch(key) {
+    case InputKeyOk:
+    case InputKeyBack:
+        plugin_state->mode = MenuMode;
+        break;
+
+    default:
+        break;
+    }
+
+    return true;
+}
+
+static bool handle_key_press_edit(InputKey key, PluginState* plugin_state) {
+    int barcodeMaxIndex = get_barcode_max_index(plugin_state);
+
+    switch(key) {
+    case InputKeyUp:
+        plugin_state->barcode_state.barcodeNumeral[plugin_state->editingIndex] =
+            (plugin_state->barcode_state.barcodeNumeral[plugin_state->editingIndex] + 1) % 10;
+        break;
+
+    case InputKeyDown:
+        plugin_state->barcode_state.barcodeNumeral[plugin_state->editingIndex] =
+            (plugin_state->barcode_state.barcodeNumeral[plugin_state->editingIndex] == 0) ?
+                9 :
+                plugin_state->barcode_state.barcodeNumeral[plugin_state->editingIndex] - 1;
+        break;
+
+    case InputKeyRight:
+        plugin_state->editingIndex = (plugin_state->editingIndex + 1) % barcodeMaxIndex;
+        break;
+
+    case InputKeyLeft:
+        plugin_state->editingIndex = (plugin_state->editingIndex == 0) ?
+                                         barcodeMaxIndex - 1 :
+                                         plugin_state->editingIndex - 1;
+        break;
+
+    case InputKeyOk:
+    case InputKeyBack:
+        plugin_state->mode = MenuMode;
+        break;
+
+    default:
+        break;
+    }
+
+    return true;
+}
+
+static bool handle_key_press_menu(InputKey key, PluginState* plugin_state) {
+    switch(key) {
+    case InputKeyUp:
+        plugin_state->menuIndex = (plugin_state->menuIndex == MENU_INDEX_VIEW) ?
+                                      MENU_INDEX_TYPE :
+                                      plugin_state->menuIndex - 1;
+        break;
+
+    case InputKeyDown:
+        plugin_state->menuIndex = (plugin_state->menuIndex + 1) % 4;
+        break;
+
+    case InputKeyRight:
+        if(plugin_state->menuIndex == MENU_INDEX_TYPE) {
+            plugin_state->barcode_state.barcodeTypeIndex =
+                (plugin_state->barcode_state.barcodeTypeIndex == NUMBER_OF_BARCODE_TYPES - 1) ?
+                    0 :
+                    plugin_state->barcode_state.barcodeTypeIndex + 1;
+        } else if(plugin_state->menuIndex == MENU_INDEX_PARITY) {
+            plugin_state->barcode_state.doParityCalculation =
+                !plugin_state->barcode_state.doParityCalculation;
+        }
+        break;
+    case InputKeyLeft:
+        if(plugin_state->menuIndex == MENU_INDEX_TYPE) {
+            plugin_state->barcode_state.barcodeTypeIndex =
+                (plugin_state->barcode_state.barcodeTypeIndex == 0) ?
+                    NUMBER_OF_BARCODE_TYPES - 1 :
+                    plugin_state->barcode_state.barcodeTypeIndex - 1;
+        } else if(plugin_state->menuIndex == MENU_INDEX_PARITY) {
+            plugin_state->barcode_state.doParityCalculation =
+                !plugin_state->barcode_state.doParityCalculation;
+        }
+        break;
+
+    case InputKeyOk:
+        if(plugin_state->menuIndex == MENU_INDEX_VIEW) {
+            plugin_state->mode = ViewMode;
+        } else if(plugin_state->menuIndex == MENU_INDEX_EDIT) {
+            plugin_state->mode = EditMode;
+        } else if(plugin_state->menuIndex == MENU_INDEX_PARITY) {
+            plugin_state->barcode_state.doParityCalculation =
+                !plugin_state->barcode_state.doParityCalculation;
+        } else if(plugin_state->menuIndex == MENU_INDEX_TYPE) {
+            plugin_state->barcode_state.barcodeTypeIndex =
+                (plugin_state->barcode_state.barcodeTypeIndex == NUMBER_OF_BARCODE_TYPES - 1) ?
+                    0 :
+                    plugin_state->barcode_state.barcodeTypeIndex + 1;
+        }
+        break;
+
+    case InputKeyBack:
+        return false;
+
+    default:
+        break;
+    }
+    int barcodeMaxIndex = get_barcode_max_index(plugin_state);
+    if(plugin_state->editingIndex >= barcodeMaxIndex)
+        plugin_state->editingIndex = barcodeMaxIndex - 1;
+
+    return true;
+}
+
+int32_t barcode_generator_app(void* p) {
+    UNUSED(p);
+
+    init_types();
+
+    FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent));
+
+    PluginState* plugin_state = malloc(sizeof(PluginState));
+    barcode_generator_state_init(plugin_state);
+
+    plugin_state->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
+    if(!plugin_state->mutex) {
+        FURI_LOG_E("barcode_generator", "cannot create mutex\r\n");
+        furi_message_queue_free(event_queue);
+        free(plugin_state);
+        return 255;
+    }
+
+    // Set system callbacks
+    ViewPort* view_port = view_port_alloc();
+    view_port_draw_callback_set(view_port, render_callback, plugin_state);
+    view_port_input_callback_set(view_port, input_callback, event_queue);
+
+    // Open GUI and register view_port
+    Gui* gui = furi_record_open(RECORD_GUI);
+    gui_add_view_port(gui, view_port, GuiLayerFullscreen);
+
+    PluginEvent event;
+    for(bool processing = true; processing;) {
+        FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
+        furi_mutex_acquire(plugin_state->mutex, FuriWaitForever);
+
+        if(event_status == FuriStatusOk) {
+            // press events
+            if(event.type == EventTypeKey &&
+               ((event.input.type == InputTypePress) || (event.input.type == InputTypeRepeat))) {
+                switch(plugin_state->mode) {
+                case ViewMode:
+                    processing = handle_key_press_view(event.input.key, plugin_state);
+                    break;
+                case EditMode:
+                    processing = handle_key_press_edit(event.input.key, plugin_state);
+                    break;
+                case MenuMode:
+                    processing = handle_key_press_menu(event.input.key, plugin_state);
+                    break;
+                default:
+                    break;
+                }
+            }
+        }
+
+        view_port_update(view_port);
+        furi_mutex_release(plugin_state->mutex);
+    }
+
+    view_port_enabled_set(view_port, false);
+    gui_remove_view_port(gui, view_port);
+    furi_record_close(RECORD_GUI);
+    view_port_free(view_port);
+    furi_message_queue_free(event_queue);
+    furi_mutex_free(plugin_state->mutex);
+    // save settings
+    SAVE_BARCODE_SETTINGS(&plugin_state->barcode_state);
+    free(plugin_state);
+
+    return 0;
+}

+ 115 - 0
main_apps_sources/barcode_generator/barcode_generator.h

@@ -0,0 +1,115 @@
+#pragma once
+
+#include <furi.h>
+#include <gui/gui.h>
+#include <input/input.h>
+#include <stdlib.h>
+#include <storage/storage.h>
+#include <toolbox/saved_struct.h>
+
+#define BARCODE_SETTINGS_FILE_NAME "apps/Misc/barcodegen.save"
+
+#define BARCODE_SETTINGS_VER (1)
+#define BARCODE_SETTINGS_PATH EXT_PATH(BARCODE_SETTINGS_FILE_NAME)
+#define BARCODE_SETTINGS_MAGIC (0xC2)
+
+#define SAVE_BARCODE_SETTINGS(x) \
+    saved_struct_save(           \
+        BARCODE_SETTINGS_PATH,   \
+        (x),                     \
+        sizeof(BarcodeState),    \
+        BARCODE_SETTINGS_MAGIC,  \
+        BARCODE_SETTINGS_VER)
+
+#define LOAD_BARCODE_SETTINGS(x) \
+    saved_struct_load(           \
+        BARCODE_SETTINGS_PATH,   \
+        (x),                     \
+        sizeof(BarcodeState),    \
+        BARCODE_SETTINGS_MAGIC,  \
+        BARCODE_SETTINGS_VER)
+
+#define BARCODE_HEIGHT 50
+#define BARCODE_Y_START 3
+#define BARCODE_TEXT_OFFSET 9
+#define BARCODE_MAX_LENS 13
+#define NUMBER_OF_BARCODE_TYPES 3
+#define MENU_INDEX_VIEW 0
+#define MENU_INDEX_EDIT 1
+#define MENU_INDEX_PARITY 2
+#define MENU_INDEX_TYPE 3
+
+typedef enum {
+    EventTypeTick,
+    EventTypeKey,
+} EventType;
+
+typedef struct {
+    EventType type;
+    InputEvent input;
+} PluginEvent;
+
+typedef enum {
+    ViewMode,
+    EditMode,
+    MenuMode,
+} Mode;
+
+typedef enum {
+    BarEncodingTypeLeft,
+    BarEncodingTypeRight,
+    BarEncodingTypeG,
+} BarEncodingType;
+
+typedef enum {
+    BarTypeEAN8,
+    BarTypeUPCA,
+    BarTypeEAN13,
+} BarType;
+
+typedef struct {
+    char* name;
+    int numberOfDigits;
+    int startPos;
+    BarType bartype;
+} BarcodeType;
+
+typedef struct {
+    int barcodeNumeral[BARCODE_MAX_LENS]; //The current barcode number
+    bool doParityCalculation; //Should do parity check?
+    int barcodeTypeIndex;
+} BarcodeState;
+
+typedef struct {
+    FuriMutex* mutex;
+    BarcodeState barcode_state;
+    int editingIndex; //The index of the editing symbol
+    int menuIndex; //The index of the menu cursor
+    Mode mode; //View, edit or menu
+} PluginState;
+
+static const int DIGITS[10][4] = {
+    {3, 2, 1, 1},
+    {2, 2, 2, 1},
+    {2, 1, 2, 2},
+    {1, 4, 1, 1},
+    {1, 1, 3, 2},
+    {1, 2, 3, 1},
+    {1, 1, 1, 4},
+    {1, 3, 1, 2},
+    {1, 2, 1, 3},
+    {3, 1, 1, 2},
+};
+
+static const uint8_t EAN13ENCODE[10] = {
+    0b000000,
+    0b110100,
+    0b101100,
+    0b011100,
+    0b110010,
+    0b100110,
+    0b001110,
+    0b101010,
+    0b011010,
+    0b010110,
+};

+ 15 - 0
main_apps_sources/blackjack/application.fam

@@ -0,0 +1,15 @@
+App(
+    appid="blackjack",
+    name="Blackjack",
+    apptype=FlipperAppType.EXTERNAL,
+    entry_point="blackjack_app",
+    requires=["gui","storage","canvas"],
+    stack_size=2 * 1024,
+    order=30,
+    fap_icon="blackjack_10px.png",
+    fap_category="Games",
+    fap_icon_assets="assets",
+    fap_author="@teeebor",
+    fap_version="1.0",
+    fap_description="Blackjack Game",
+)

BIN
main_apps_sources/blackjack/assets/blackjack.png


BIN
main_apps_sources/blackjack/assets/card_graphics.png


BIN
main_apps_sources/blackjack/assets/endscreen.png


+ 633 - 0
main_apps_sources/blackjack/blackjack.c

@@ -0,0 +1,633 @@
+
+#include <gui/gui.h>
+#include <stdlib.h>
+#include <dolphin/dolphin.h>
+#include <dialogs/dialogs.h>
+#include <gui/canvas_i.h>
+
+#include <math.h>
+#include "util.h"
+#include "defines.h"
+#include "common/card.h"
+#include "common/dml.h"
+#include "common/queue.h"
+#include "util.h"
+#include "ui.h"
+
+#include "blackjack_icons.h"
+
+#define DEALER_MAX 17
+
+void start_round(GameState* game_state);
+
+void init(GameState* game_state);
+
+static void draw_ui(Canvas* const canvas, const GameState* game_state) {
+    draw_money(canvas, game_state->player_score);
+
+    draw_score(canvas, true, hand_count(game_state->player_cards, game_state->player_card_count));
+
+    if(!game_state->queue_state.running && game_state->state == GameStatePlay) {
+        render_menu(game_state->menu, canvas, 2, 47);
+    }
+}
+
+static void render_callback(Canvas* const canvas, void* ctx) {
+    furi_assert(ctx);
+    const GameState* game_state = ctx;
+    furi_mutex_acquire(game_state->mutex, FuriWaitForever);
+
+    canvas_set_color(canvas, ColorBlack);
+    canvas_draw_frame(canvas, 0, 0, 128, 64);
+
+    if(game_state->state == GameStateStart) {
+        canvas_draw_icon(canvas, 0, 0, &I_blackjack);
+    }
+    if(game_state->state == GameStateGameOver) {
+        canvas_draw_icon(canvas, 0, 0, &I_endscreen);
+    }
+
+    if(game_state->state == GameStatePlay || game_state->state == GameStateDealer) {
+        if(game_state->state == GameStatePlay)
+            draw_player_scene(canvas, game_state);
+        else
+            draw_dealer_scene(canvas, game_state);
+        render_queue(&(game_state->queue_state), game_state, canvas);
+        draw_ui(canvas, game_state);
+    } else if(game_state->state == GameStateSettings) {
+        settings_page(canvas, game_state);
+    }
+
+    furi_mutex_release(game_state->mutex);
+}
+
+//region card draw
+Card draw_card(GameState* game_state) {
+    Card c = game_state->deck.cards[game_state->deck.index];
+    game_state->deck.index++;
+    return c;
+}
+
+void drawPlayerCard(void* ctx) {
+    GameState* game_state = ctx;
+    Card c = draw_card(game_state);
+    game_state->player_cards[game_state->player_card_count] = c;
+    game_state->player_card_count++;
+    if(game_state->player_score < game_state->settings.round_price || game_state->doubled) {
+        set_menu_state(game_state->menu, 0, false);
+    }
+}
+
+void drawDealerCard(void* ctx) {
+    GameState* game_state = ctx;
+    Card c = draw_card(game_state);
+    game_state->dealer_cards[game_state->dealer_card_count] = c;
+    game_state->dealer_card_count++;
+}
+//endregion
+
+//region queue callbacks
+void to_lose_state(const void* ctx, Canvas* const canvas) {
+    const GameState* game_state = ctx;
+    if(game_state->settings.message_duration == 0) return;
+    popup_frame(canvas);
+    elements_multiline_text_aligned(canvas, 64, 22, AlignCenter, AlignCenter, "You lost");
+}
+
+void to_bust_state(const void* ctx, Canvas* const canvas) {
+    const GameState* game_state = ctx;
+    if(game_state->settings.message_duration == 0) return;
+    popup_frame(canvas);
+    elements_multiline_text_aligned(canvas, 64, 22, AlignCenter, AlignCenter, "Busted!");
+}
+
+void to_draw_state(const void* ctx, Canvas* const canvas) {
+    const GameState* game_state = ctx;
+    if(game_state->settings.message_duration == 0) return;
+    popup_frame(canvas);
+    elements_multiline_text_aligned(canvas, 64, 22, AlignCenter, AlignCenter, "Draw");
+}
+
+void to_dealer_turn(const void* ctx, Canvas* const canvas) {
+    const GameState* game_state = ctx;
+    if(game_state->settings.message_duration == 0) return;
+    popup_frame(canvas);
+    elements_multiline_text_aligned(canvas, 64, 22, AlignCenter, AlignCenter, "Dealers turn");
+}
+
+void to_win_state(const void* ctx, Canvas* const canvas) {
+    const GameState* game_state = ctx;
+    if(game_state->settings.message_duration == 0) return;
+    popup_frame(canvas);
+    elements_multiline_text_aligned(canvas, 64, 22, AlignCenter, AlignCenter, "You win");
+}
+
+void to_start(const void* ctx, Canvas* const canvas) {
+    const GameState* game_state = ctx;
+    if(game_state->settings.message_duration == 0) return;
+    popup_frame(canvas);
+    elements_multiline_text_aligned(canvas, 64, 22, AlignCenter, AlignCenter, "Round started");
+}
+
+void before_start(void* ctx) {
+    GameState* game_state = ctx;
+    game_state->dealer_card_count = 0;
+    game_state->player_card_count = 0;
+}
+
+void start(void* ctx) {
+    GameState* game_state = ctx;
+    start_round(game_state);
+}
+
+void draw(void* ctx) {
+    GameState* game_state = ctx;
+    game_state->player_score += game_state->bet;
+    game_state->bet = 0;
+    enqueue(
+        &(game_state->queue_state),
+        game_state,
+        start,
+        before_start,
+        to_start,
+        game_state->settings.message_duration);
+}
+
+void game_over(void* ctx) {
+    GameState* game_state = ctx;
+    game_state->state = GameStateGameOver;
+}
+
+void lose(void* ctx) {
+    GameState* game_state = ctx;
+    game_state->state = GameStatePlay;
+    game_state->bet = 0;
+    if(game_state->player_score >= game_state->settings.round_price) {
+        enqueue(
+            &(game_state->queue_state),
+            game_state,
+            start,
+            before_start,
+            to_start,
+            game_state->settings.message_duration);
+    } else {
+        enqueue(&(game_state->queue_state), game_state, game_over, NULL, NULL, 0);
+    }
+}
+
+void win(void* ctx) {
+    GameState* game_state = ctx;
+    game_state->state = GameStatePlay;
+    game_state->player_score += game_state->bet * 2;
+    game_state->bet = 0;
+    enqueue(
+        &(game_state->queue_state),
+        game_state,
+        start,
+        before_start,
+        to_start,
+        game_state->settings.message_duration);
+}
+
+void dealerTurn(void* ctx) {
+    GameState* game_state = ctx;
+    game_state->state = GameStateDealer;
+}
+
+float animationTime(const GameState* game_state) {
+    return (float)(furi_get_tick() - game_state->queue_state.start) /
+           (float)(game_state->settings.animation_duration);
+}
+
+void dealer_card_animation(const void* ctx, Canvas* const canvas) {
+    const GameState* game_state = ctx;
+    float t = animationTime(game_state);
+
+    Card animatingCard = game_state->deck.cards[game_state->deck.index];
+    if(game_state->dealer_card_count > 1) {
+        Vector end = card_pos_at_index(game_state->dealer_card_count);
+        draw_card_animation(animatingCard, (Vector){0, 64}, (Vector){0, 32}, end, t, true, canvas);
+    } else {
+        draw_card_animation(
+            animatingCard,
+            (Vector){32, -CARD_HEIGHT},
+            (Vector){64, 32},
+            (Vector){2, 2},
+            t,
+            false,
+            canvas);
+    }
+}
+
+void dealer_back_card_animation(const void* ctx, Canvas* const canvas) {
+    const GameState* game_state = ctx;
+    float t = animationTime(game_state);
+
+    Vector currentPos =
+        quadratic_2d((Vector){32, -CARD_HEIGHT}, (Vector){64, 32}, (Vector){13, 5}, t);
+    draw_card_back_at(currentPos.x, currentPos.y, canvas);
+}
+
+void player_card_animation(const void* ctx, Canvas* const canvas) {
+    const GameState* game_state = ctx;
+    float t = animationTime(game_state);
+
+    Card animatingCard = game_state->deck.cards[game_state->deck.index];
+    Vector end = card_pos_at_index(game_state->player_card_count);
+
+    draw_card_animation(
+        animatingCard, (Vector){32, -CARD_HEIGHT}, (Vector){0, 32}, end, t, true, canvas);
+}
+//endregion
+
+void player_tick(GameState* game_state) {
+    uint8_t score = hand_count(game_state->player_cards, game_state->player_card_count);
+    if((game_state->doubled && score <= 21) || score == 21) {
+        enqueue(
+            &(game_state->queue_state),
+            game_state,
+            dealerTurn,
+            NULL,
+            to_dealer_turn,
+            game_state->settings.message_duration);
+    } else if(score > 21) {
+        enqueue(
+            &(game_state->queue_state),
+            game_state,
+            lose,
+            NULL,
+            to_bust_state,
+            game_state->settings.message_duration);
+    } else {
+        if(game_state->selectDirection == DirectionUp ||
+           game_state->selectDirection == DirectionDown) {
+            move_menu(game_state->menu, game_state->selectDirection == DirectionUp ? -1 : 1);
+        }
+
+        if(game_state->selectDirection == Select) {
+            activate_menu(game_state->menu, game_state);
+        }
+    }
+}
+
+void dealer_tick(GameState* game_state) {
+    uint8_t dealer_score = hand_count(game_state->dealer_cards, game_state->dealer_card_count);
+    uint8_t player_score = hand_count(game_state->player_cards, game_state->player_card_count);
+
+    if(dealer_score >= DEALER_MAX) {
+        if(dealer_score > 21 || dealer_score < player_score) {
+            dolphin_deed(DolphinDeedPluginGameWin);
+            enqueue(
+                &(game_state->queue_state),
+                game_state,
+                win,
+                NULL,
+                to_win_state,
+                game_state->settings.message_duration);
+        } else if(dealer_score > player_score) {
+            enqueue(
+                &(game_state->queue_state),
+                game_state,
+                lose,
+                NULL,
+                to_lose_state,
+                game_state->settings.message_duration);
+        } else if(dealer_score == player_score) {
+            enqueue(
+                &(game_state->queue_state),
+                game_state,
+                draw,
+                NULL,
+                to_draw_state,
+                game_state->settings.message_duration);
+        }
+    } else {
+        enqueue(
+            &(game_state->queue_state),
+            game_state,
+            drawDealerCard,
+            NULL,
+            dealer_card_animation,
+            game_state->settings.animation_duration);
+    }
+}
+
+void settings_tick(GameState* game_state) {
+    if(game_state->selectDirection == DirectionDown && game_state->selectedMenu < 4) {
+        game_state->selectedMenu++;
+    }
+    if(game_state->selectDirection == DirectionUp && game_state->selectedMenu > 0) {
+        game_state->selectedMenu--;
+    }
+
+    if(game_state->selectDirection == DirectionLeft ||
+       game_state->selectDirection == DirectionRight) {
+        int nextScore = 0;
+        switch(game_state->selectedMenu) {
+        case 0:
+            nextScore = game_state->settings.starting_money;
+            if(game_state->selectDirection == DirectionLeft)
+                nextScore -= 10;
+            else
+                nextScore += 10;
+            if(nextScore >= (int)game_state->settings.round_price && nextScore < 400)
+                game_state->settings.starting_money = nextScore;
+            break;
+        case 1:
+            nextScore = game_state->settings.round_price;
+            if(game_state->selectDirection == DirectionLeft)
+                nextScore -= 10;
+            else
+                nextScore += 10;
+            if(nextScore >= 5 && nextScore <= (int)game_state->settings.starting_money)
+                game_state->settings.round_price = nextScore;
+            break;
+        case 2:
+            nextScore = game_state->settings.animation_duration;
+            if(game_state->selectDirection == DirectionLeft)
+                nextScore -= 100;
+            else
+                nextScore += 100;
+            if(nextScore >= 0 && nextScore < 2000)
+                game_state->settings.animation_duration = nextScore;
+            break;
+        case 3:
+            nextScore = game_state->settings.message_duration;
+            if(game_state->selectDirection == DirectionLeft)
+                nextScore -= 100;
+            else
+                nextScore += 100;
+            if(nextScore >= 0 && nextScore < 2000)
+                game_state->settings.message_duration = nextScore;
+            break;
+        case 4:
+            game_state->settings.sound_effects = !game_state->settings.sound_effects;
+        default:
+            break;
+        }
+    }
+}
+
+void tick(GameState* game_state) {
+    game_state->last_tick = furi_get_tick();
+    bool queue_ran = run_queue(&(game_state->queue_state), game_state);
+
+    switch(game_state->state) {
+    case GameStateGameOver:
+    case GameStateStart:
+        if(game_state->selectDirection == Select)
+            init(game_state);
+        else if(game_state->selectDirection == DirectionRight) {
+            game_state->selectedMenu = 0;
+            game_state->state = GameStateSettings;
+        }
+        break;
+    case GameStatePlay:
+        if(!game_state->started) {
+            game_state->selectedMenu = 0;
+            game_state->started = true;
+            enqueue(
+                &(game_state->queue_state),
+                game_state,
+                drawDealerCard,
+                NULL,
+                dealer_back_card_animation,
+                game_state->settings.animation_duration);
+            enqueue(
+                &(game_state->queue_state),
+                game_state,
+                drawPlayerCard,
+                NULL,
+                player_card_animation,
+                game_state->settings.animation_duration);
+            enqueue(
+                &(game_state->queue_state),
+                game_state,
+                drawDealerCard,
+                NULL,
+                dealer_card_animation,
+                game_state->settings.animation_duration);
+            enqueue(
+                &(game_state->queue_state),
+                game_state,
+                drawPlayerCard,
+                NULL,
+                player_card_animation,
+                game_state->settings.animation_duration);
+        }
+        if(!queue_ran) player_tick(game_state);
+        break;
+    case GameStateDealer:
+        if(!queue_ran) dealer_tick(game_state);
+        break;
+    case GameStateSettings:
+        settings_tick(game_state);
+        break;
+    default:
+        break;
+    }
+
+    game_state->selectDirection = None;
+}
+
+void start_round(GameState* game_state) {
+    game_state->menu->current_menu = 1;
+    game_state->player_card_count = 0;
+    game_state->dealer_card_count = 0;
+    set_menu_state(game_state->menu, 0, true);
+    game_state->menu->enabled = true;
+    game_state->started = false;
+    game_state->doubled = false;
+    game_state->queue_state.running = true;
+    shuffle_deck(&(game_state->deck));
+    game_state->doubled = false;
+    game_state->bet = game_state->settings.round_price;
+    if(game_state->player_score < game_state->settings.round_price) {
+        game_state->state = GameStateGameOver;
+    } else {
+        game_state->player_score -= game_state->settings.round_price;
+    }
+    game_state->state = GameStatePlay;
+}
+
+void init(GameState* game_state) {
+    set_menu_state(game_state->menu, 0, true);
+    game_state->menu->enabled = true;
+    game_state->menu->current_menu = 1;
+    game_state->settings = load_settings();
+    game_state->last_tick = 0;
+    game_state->processing = true;
+    game_state->selectedMenu = 0;
+    game_state->player_score = game_state->settings.starting_money;
+    generate_deck(&(game_state->deck), 6);
+    start_round(game_state);
+}
+
+static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
+    furi_assert(event_queue);
+    AppEvent event = {.type = EventTypeKey, .input = *input_event};
+    furi_message_queue_put(event_queue, &event, FuriWaitForever);
+}
+
+static void update_timer_callback(FuriMessageQueue* event_queue) {
+    furi_assert(event_queue);
+    AppEvent event = {.type = EventTypeTick};
+    furi_message_queue_put(event_queue, &event, 0);
+}
+
+void doubleAction(void* state) {
+    GameState* game_state = state;
+    if(!game_state->doubled && game_state->player_score >= game_state->settings.round_price) {
+        game_state->player_score -= game_state->settings.round_price;
+        game_state->bet += game_state->settings.round_price;
+        game_state->doubled = true;
+        enqueue(
+            &(game_state->queue_state),
+            game_state,
+            drawPlayerCard,
+            NULL,
+            player_card_animation,
+            game_state->settings.animation_duration);
+        game_state->player_cards[game_state->player_card_count] =
+            game_state->deck.cards[game_state->deck.index];
+        uint8_t score = hand_count(game_state->player_cards, game_state->player_card_count + 1);
+        if(score > 21) {
+            enqueue(
+                &(game_state->queue_state),
+                game_state,
+                lose,
+                NULL,
+                to_bust_state,
+                game_state->settings.message_duration);
+        } else {
+            enqueue(
+                &(game_state->queue_state),
+                game_state,
+                dealerTurn,
+                NULL,
+                to_dealer_turn,
+                game_state->settings.message_duration);
+        }
+        set_menu_state(game_state->menu, 0, false);
+    }
+}
+
+void hitAction(void* state) {
+    GameState* game_state = state;
+    enqueue(
+        &(game_state->queue_state),
+        game_state,
+        drawPlayerCard,
+        NULL,
+        player_card_animation,
+        game_state->settings.animation_duration);
+}
+void stayAction(void* state) {
+    GameState* game_state = state;
+    enqueue(
+        &(game_state->queue_state),
+        game_state,
+        dealerTurn,
+        NULL,
+        to_dealer_turn,
+        game_state->settings.message_duration);
+}
+
+int32_t blackjack_app(void* p) {
+    UNUSED(p);
+
+    int32_t return_code = 0;
+
+    FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(AppEvent));
+
+    GameState* game_state = malloc(sizeof(GameState));
+    game_state->menu = malloc(sizeof(Menu));
+    game_state->menu->menu_width = 40;
+    init(game_state);
+    add_menu(game_state->menu, "Double", doubleAction);
+    add_menu(game_state->menu, "Hit", hitAction);
+    add_menu(game_state->menu, "Stay", stayAction);
+    set_card_graphics(&I_card_graphics);
+
+    game_state->state = GameStateStart;
+
+    game_state->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
+    if(!game_state->mutex) {
+        FURI_LOG_E(APP_NAME, "cannot create mutex\r\n");
+        return_code = 255;
+        goto free_and_exit;
+    }
+
+    ViewPort* view_port = view_port_alloc();
+    view_port_draw_callback_set(view_port, render_callback, game_state);
+    view_port_input_callback_set(view_port, input_callback, event_queue);
+
+    FuriTimer* timer = furi_timer_alloc(update_timer_callback, FuriTimerTypePeriodic, event_queue);
+    furi_timer_start(timer, furi_kernel_get_tick_frequency() / 25);
+
+    Gui* gui = furi_record_open(RECORD_GUI);
+    gui_add_view_port(gui, view_port, GuiLayerFullscreen);
+
+    AppEvent event;
+
+    // Call dolphin deed on game start
+    dolphin_deed(DolphinDeedPluginGameStart);
+
+    for(bool processing = true; processing;) {
+        FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
+        furi_mutex_acquire(game_state->mutex, FuriWaitForever);
+        if(event_status == FuriStatusOk) {
+            if(event.type == EventTypeKey) {
+                if(event.input.type == InputTypePress) {
+                    switch(event.input.key) {
+                    case InputKeyUp:
+                        game_state->selectDirection = DirectionUp;
+                        break;
+                    case InputKeyDown:
+                        game_state->selectDirection = DirectionDown;
+                        break;
+                    case InputKeyRight:
+                        game_state->selectDirection = DirectionRight;
+                        break;
+                    case InputKeyLeft:
+                        game_state->selectDirection = DirectionLeft;
+                        break;
+                    case InputKeyBack:
+                        if(game_state->state == GameStateSettings) {
+                            game_state->state = GameStateStart;
+                            save_settings(game_state->settings);
+                        } else
+                            processing = false;
+                        break;
+                    case InputKeyOk:
+                        game_state->selectDirection = Select;
+                        break;
+                    default:
+                        break;
+                    }
+                }
+            } else if(event.type == EventTypeTick) {
+                tick(game_state);
+                processing = game_state->processing;
+            }
+        }
+        view_port_update(view_port);
+        furi_mutex_release(game_state->mutex);
+    }
+
+    furi_timer_free(timer);
+    view_port_enabled_set(view_port, false);
+    gui_remove_view_port(gui, view_port);
+    furi_record_close(RECORD_GUI);
+    view_port_free(view_port);
+    furi_mutex_free(game_state->mutex);
+
+free_and_exit:
+    free(game_state->deck.cards);
+    free_menu(game_state->menu);
+    queue_clear(&(game_state->queue_state));
+    free(game_state);
+    furi_message_queue_free(event_queue);
+
+    return return_code;
+}

BIN
main_apps_sources/blackjack/blackjack_10px.png


+ 353 - 0
main_apps_sources/blackjack/common/card.c

@@ -0,0 +1,353 @@
+#include "card.h"
+#include "dml.h"
+#include "ui.h"
+
+#define CARD_DRAW_X_START 108
+#define CARD_DRAW_Y_START 38
+#define CARD_DRAW_X_SPACE 10
+#define CARD_DRAW_Y_SPACE 8
+#define CARD_DRAW_X_OFFSET 4
+#define CARD_DRAW_FIRST_ROW_LENGTH 7
+
+uint8_t pips[4][3] = {
+    {21, 10, 7}, //spades
+    {7, 10, 7}, //hearts
+    {0, 10, 7}, //diamonds
+    {14, 10, 7}, //clubs
+};
+uint8_t letters[13][3] = {
+    {0, 0, 5},
+    {5, 0, 5},
+    {10, 0, 5},
+    {15, 0, 5},
+    {20, 0, 5},
+    {25, 0, 5},
+    {30, 0, 5},
+    {0, 5, 5},
+    {5, 5, 5},
+    {10, 5, 5},
+    {15, 5, 5},
+    {20, 5, 5},
+    {25, 5, 5},
+};
+
+//region Player card positions
+uint8_t playerCardPositions[22][4] = {
+    //first row
+    {108, 38},
+    {98, 38},
+    {88, 38},
+    {78, 38},
+    {68, 38},
+    {58, 38},
+    {48, 38},
+    {38, 38},
+    //second row
+    {104, 26},
+    {94, 26},
+    {84, 26},
+    {74, 26},
+    {64, 26},
+    {54, 26},
+    {44, 26},
+    //third row
+    {99, 14},
+    {89, 14},
+    {79, 14},
+    {69, 14},
+    {59, 14},
+    {49, 14},
+};
+//endregion
+Icon* card_graphics = NULL;
+
+void set_card_graphics(const Icon* graphics) {
+    card_graphics = (Icon*)graphics;
+}
+
+void draw_card_at_colored(
+    int8_t pos_x,
+    int8_t pos_y,
+    uint8_t pip,
+    uint8_t character,
+    bool inverted,
+    Canvas* const canvas) {
+    DrawMode primary = inverted ? Black : White;
+    DrawMode secondary = inverted ? White : Black;
+    draw_rounded_box(canvas, pos_x, pos_y, CARD_WIDTH, CARD_HEIGHT, primary);
+    draw_rounded_box_frame(canvas, pos_x, pos_y, CARD_WIDTH, CARD_HEIGHT, Black);
+
+    uint8_t* drawInfo = pips[pip];
+    uint8_t px = drawInfo[0], py = drawInfo[1], s = drawInfo[2];
+
+    uint8_t left = pos_x + 2;
+    uint8_t right = (pos_x + CARD_WIDTH - s - 2);
+    uint8_t top = pos_y + 2;
+    uint8_t bottom = (pos_y + CARD_HEIGHT - s - 2);
+
+    draw_icon_clip(canvas, card_graphics, right, top, px, py, s, s, secondary);
+    draw_icon_clip_flipped(canvas, card_graphics, left, bottom, px, py, s, s, secondary);
+
+    drawInfo = letters[character];
+    px = drawInfo[0], py = drawInfo[1], s = drawInfo[2];
+    left = pos_x + 2;
+    right = (pos_x + CARD_WIDTH - s - 2);
+    top = pos_y + 2;
+    bottom = (pos_y + CARD_HEIGHT - s - 2);
+
+    draw_icon_clip(canvas, card_graphics, left, top + 1, px, py, s, s, secondary);
+    draw_icon_clip_flipped(canvas, card_graphics, right, bottom - 1, px, py, s, s, secondary);
+}
+
+void draw_card_at(int8_t pos_x, int8_t pos_y, uint8_t pip, uint8_t character, Canvas* const canvas) {
+    draw_card_at_colored(pos_x, pos_y, pip, character, false, canvas);
+}
+
+void draw_deck(const Card* cards, uint8_t count, Canvas* const canvas) {
+    for(int i = count - 1; i >= 0; i--) {
+        draw_card_at(
+            playerCardPositions[i][0],
+            playerCardPositions[i][1],
+            cards[i].pip,
+            cards[i].character,
+            canvas);
+    }
+}
+
+Vector card_pos_at_index(uint8_t index) {
+    return (Vector){playerCardPositions[index][0], playerCardPositions[index][1]};
+}
+
+void draw_card_back_at(int8_t pos_x, int8_t pos_y, Canvas* const canvas) {
+    draw_rounded_box(canvas, pos_x, pos_y, CARD_WIDTH, CARD_HEIGHT, White);
+    draw_rounded_box_frame(canvas, pos_x, pos_y, CARD_WIDTH, CARD_HEIGHT, Black);
+
+    draw_icon_clip(canvas, card_graphics, pos_x + 1, pos_y + 1, 35, 0, 15, 21, Black);
+}
+
+void generate_deck(Deck* deck_ptr, uint8_t deck_count) {
+    uint16_t counter = 0;
+    if(deck_ptr->cards != NULL) {
+        free(deck_ptr->cards);
+    }
+
+    deck_ptr->deck_count = deck_count;
+    deck_ptr->card_count = deck_count * 52;
+    deck_ptr->cards = malloc(sizeof(Card) * deck_ptr->card_count);
+
+    for(uint8_t deck = 0; deck < deck_count; deck++) {
+        for(uint8_t pip = 0; pip < 4; pip++) {
+            for(uint8_t label = 0; label < 13; label++) {
+                deck_ptr->cards[counter] = (Card){pip, label, false, false};
+                counter++;
+            }
+        }
+    }
+}
+
+void shuffle_deck(Deck* deck_ptr) {
+    srand(DWT->CYCCNT);
+    deck_ptr->index = 0;
+    int max = deck_ptr->deck_count * 52;
+    for(int i = 0; i < max; i++) {
+        int r = i + (rand() % (max - i));
+        Card tmp = deck_ptr->cards[i];
+        deck_ptr->cards[i] = deck_ptr->cards[r];
+        deck_ptr->cards[r] = tmp;
+    }
+}
+
+uint8_t hand_count(const Card* cards, uint8_t count) {
+    uint8_t aceCount = 0;
+    uint8_t score = 0;
+
+    for(uint8_t i = 0; i < count; i++) {
+        if(cards[i].character == 12)
+            aceCount++;
+        else {
+            if(cards[i].character > 8)
+                score += 10;
+            else
+                score += cards[i].character + 2;
+        }
+    }
+
+    for(uint8_t i = 0; i < aceCount; i++) {
+        if((score + 11 + (aceCount - 1)) <= 21)
+            score += 11;
+        else
+            score++;
+    }
+
+    return score;
+}
+
+void draw_card_animation(
+    Card animatingCard,
+    Vector from,
+    Vector control,
+    Vector to,
+    float t,
+    bool extra_margin,
+    Canvas* const canvas) {
+    float time = t;
+    if(extra_margin) {
+        time += 0.2;
+    }
+
+    Vector currentPos = quadratic_2d(from, control, to, time);
+    if(t > 1) {
+        draw_card_at(
+            currentPos.x, currentPos.y, animatingCard.pip, animatingCard.character, canvas);
+    } else {
+        if(t < 0.5)
+            draw_card_back_at(currentPos.x, currentPos.y, canvas);
+        else
+            draw_card_at(
+                currentPos.x, currentPos.y, animatingCard.pip, animatingCard.character, canvas);
+    }
+}
+
+void init_hand(Hand* hand_ptr, uint8_t count) {
+    hand_ptr->cards = malloc(sizeof(Card) * count);
+    hand_ptr->index = 0;
+    hand_ptr->max = count;
+}
+
+void free_hand(Hand* hand_ptr) {
+    FURI_LOG_D("CARD", "Freeing hand");
+    free(hand_ptr->cards);
+}
+
+void add_to_hand(Hand* hand_ptr, Card card) {
+    FURI_LOG_D("CARD", "Adding to hand");
+    if(hand_ptr->index < hand_ptr->max) {
+        hand_ptr->cards[hand_ptr->index] = card;
+        hand_ptr->index++;
+    }
+}
+
+void draw_card_space(int16_t pos_x, int16_t pos_y, bool highlighted, Canvas* const canvas) {
+    if(highlighted) {
+        draw_rounded_box_frame(canvas, pos_x, pos_y, CARD_WIDTH, CARD_HEIGHT, Black);
+        draw_rounded_box_frame(
+            canvas, pos_x + 2, pos_y + 2, CARD_WIDTH - 4, CARD_HEIGHT - 4, White);
+    } else {
+        draw_rounded_box(canvas, pos_x, pos_y, CARD_WIDTH, CARD_HEIGHT, Black);
+        draw_rounded_box_frame(
+            canvas, pos_x + 2, pos_y + 2, CARD_WIDTH - 4, CARD_HEIGHT - 4, White);
+    }
+}
+
+int first_non_flipped_card(Hand hand) {
+    for(int i = 0; i < hand.index; i++) {
+        if(!hand.cards[i].flipped) {
+            return i;
+        }
+    }
+    return hand.index;
+}
+
+void draw_hand_column(
+    Hand hand,
+    int16_t pos_x,
+    int16_t pos_y,
+    int8_t highlight,
+    Canvas* const canvas) {
+    if(hand.index == 0) {
+        draw_card_space(pos_x, pos_y, highlight > 0, canvas);
+        if(highlight == 0)
+            draw_rounded_box(canvas, pos_x, pos_y, CARD_WIDTH, CARD_HEIGHT, Inverse);
+        return;
+    }
+
+    int loopEnd = hand.index;
+    int hStart = max(loopEnd - 4, 0);
+    int pos = 0;
+    int first = first_non_flipped_card(hand);
+    bool wastop = false;
+    if(first >= 0 && first <= hStart && highlight != first) {
+        if(first > 0) {
+            draw_card_back_at(pos_x, pos_y + pos, canvas);
+            pos += 4;
+            hStart++;
+            wastop = true;
+        }
+        draw_card_at_colored(
+            pos_x, pos_y + pos, hand.cards[first].pip, hand.cards[first].character, false, canvas);
+        pos += 8;
+        hStart++;
+    }
+    if(hStart > highlight && highlight >= 0) {
+        if(!wastop && first > 0) {
+            draw_card_back_at(pos_x, pos_y + pos, canvas);
+            pos += 4;
+            hStart++;
+        }
+        draw_card_at_colored(
+            pos_x,
+            pos_y + pos,
+            hand.cards[highlight].pip,
+            hand.cards[highlight].character,
+            true,
+            canvas);
+        pos += 8;
+        hStart++;
+    }
+    for(int i = hStart; i < loopEnd; i++, pos += 4) {
+        if(hand.cards[i].flipped) {
+            draw_card_back_at(pos_x, pos_y + pos, canvas);
+            if(i == highlight)
+                draw_rounded_box(
+                    canvas, pos_x + 1, pos_y + pos + 1, CARD_WIDTH - 2, CARD_HEIGHT - 2, Inverse);
+        } else {
+            draw_card_at_colored(
+                pos_x,
+                pos_y + pos,
+                hand.cards[i].pip,
+                hand.cards[i].character,
+                (i == highlight),
+                canvas);
+            if(i == highlight || i == first) pos += 4;
+        }
+    }
+}
+
+Card remove_from_deck(uint16_t index, Deck* deck) {
+    FURI_LOG_D("CARD", "Removing from deck");
+    Card result = {0, 0, true, false};
+    if(deck->card_count > 0) {
+        deck->card_count--;
+        for(int i = 0, curr_index = 0; i <= deck->card_count; i++) {
+            if(i != index) {
+                deck->cards[curr_index] = deck->cards[i];
+                curr_index++;
+            } else {
+                result = deck->cards[i];
+            }
+        }
+        if(deck->index >= 0) {
+            deck->index--;
+        }
+    }
+    return result;
+}
+
+void extract_hand_region(Hand* hand, Hand* to, uint8_t start_index) {
+    FURI_LOG_D("CARD", "Extracting hand region");
+    if(start_index >= hand->index) return;
+
+    for(uint8_t i = start_index; i < hand->index; i++) {
+        add_to_hand(to, hand->cards[i]);
+    }
+    hand->index = start_index;
+}
+
+void add_hand_region(Hand* to, Hand* from) {
+    FURI_LOG_D("CARD", "Adding hand region");
+    if((to->index + from->index) <= to->max) {
+        for(int i = 0; i < from->index; i++) {
+            add_to_hand(to, from->cards[i]);
+        }
+    }
+}

+ 192 - 0
main_apps_sources/blackjack/common/card.h

@@ -0,0 +1,192 @@
+#pragma once
+
+#include <gui/gui.h>
+#include <math.h>
+#include <stdlib.h>
+#include "dml.h"
+
+#define CARD_HEIGHT 23
+#define CARD_HALF_HEIGHT 11
+#define CARD_WIDTH 17
+#define CARD_HALF_WIDTH 8
+
+//region types
+typedef struct {
+    uint8_t pip; //Pip index 0:spades, 1:hearths, 2:diamonds, 3:clubs
+    uint8_t character; //Card letter [0-12], 0 means 2, 12 is Ace
+    bool disabled;
+    bool flipped;
+} Card;
+
+typedef struct {
+    uint8_t deck_count; //Number of decks used
+    Card* cards; //Cards in the deck
+    int card_count;
+    int index; //Card index (to know where we at in the deck)
+} Deck;
+
+typedef struct {
+    Card* cards; //Cards in the deck
+    uint8_t index; //Current index
+    uint8_t max; //How many cards we want to store
+} Hand;
+//endregion
+
+void set_card_graphics(const Icon* graphics);
+
+/**
+ * Gets card coordinates at the index (range: 0-20).
+ *
+ * @param index Index to check 0-20
+ * @return      Position of the card
+ */
+Vector card_pos_at_index(uint8_t index);
+
+/**
+ * Draws card at a given coordinate (top-left corner)
+ *
+ * @param pos_x         X position
+ * @param pos_y         Y position
+ * @param pip           Pip index 0:spades, 1:hearths, 2:diamonds, 3:clubs
+ * @param character     Letter [0-12] 0 is 2, 12 is A
+ * @param canvas        Pointer to Flipper's canvas object
+ */
+void draw_card_at(int8_t pos_x, int8_t pos_y, uint8_t pip, uint8_t character, Canvas* const canvas);
+
+/**
+ * Draws card at a given coordinate (top-left corner)
+ *
+ * @param pos_x         X position
+ * @param pos_y         Y position
+ * @param pip           Pip index 0:spades, 1:hearths, 2:diamonds, 3:clubs
+ * @param character     Letter [0-12] 0 is 2, 12 is A
+ * @param inverted      Invert colors
+ * @param canvas        Pointer to Flipper's canvas object
+ */
+void draw_card_at_colored(
+    int8_t pos_x,
+    int8_t pos_y,
+    uint8_t pip,
+    uint8_t character,
+    bool inverted,
+    Canvas* const canvas);
+
+/**
+ * Draws 'count' cards at the bottom right corner
+ *
+ * @param cards     List of cards
+ * @param count     Count of cards
+ * @param canvas    Pointer to Flipper's canvas object
+ */
+void draw_deck(const Card* cards, uint8_t count, Canvas* const canvas);
+
+/**
+ * Draws card back at a given coordinate (top-left corner)
+ *
+ * @param pos_x     X coordinate
+ * @param pos_y     Y coordinate
+ * @param canvas    Pointer to Flipper's canvas object
+ */
+void draw_card_back_at(int8_t pos_x, int8_t pos_y, Canvas* const canvas);
+
+/**
+ * Generates the deck
+ *
+ * @param deck_ptr      Pointer to the deck
+ * @param deck_count    Number of decks
+ */
+void generate_deck(Deck* deck_ptr, uint8_t deck_count);
+
+/**
+ * Shuffles the deck
+ *
+ * @param deck_ptr Pointer to the deck
+ */
+void shuffle_deck(Deck* deck_ptr);
+
+/**
+ * Calculates the hand count for blackjack
+ *
+ * @param cards     List of cards
+ * @param count     Count of cards
+ * @return          Hand value
+ */
+uint8_t hand_count(const Card* cards, uint8_t count);
+
+/**
+ * Draws card animation
+ *
+ * @param animatingCard Card to animate
+ * @param from          Starting position
+ * @param control       Quadratic lerp control point
+ * @param to            End point
+ * @param t             Current time (0-1)
+ * @param extra_margin  Use extra margin at the end (arrives 0.2 unit before the end so it can stay there a bit)
+ * @param canvas        Pointer to Flipper's canvas object
+ */
+void draw_card_animation(
+    Card animatingCard,
+    Vector from,
+    Vector control,
+    Vector to,
+    float t,
+    bool extra_margin,
+    Canvas* const canvas);
+
+/**
+ * Init hand pointer
+ * @param hand_ptr   Pointer to hand
+ * @param count      Number of cards we want to store
+ */
+void init_hand(Hand* hand_ptr, uint8_t count);
+
+/**
+ * Free hand resources
+ * @param hand_ptr  Pointer to hand
+ */
+void free_hand(Hand* hand_ptr);
+
+/**
+ * Add card to hand
+ * @param hand_ptr  Pointer to hand
+ * @param card      Card to add
+ */
+void add_to_hand(Hand* hand_ptr, Card card);
+
+/**
+ * Draw card placement position at coordinate
+ * @param pos_x     X coordinate
+ * @param pos_y     Y coordinate
+ * @param highlighted   Apply highlight effect
+ * @param canvas    Canvas object
+ */
+void draw_card_space(int16_t pos_x, int16_t pos_y, bool highlighted, Canvas* const canvas);
+
+/**
+ * Draws a column of card, displaying the last [max_cards] cards on the list
+ * @param hand              Hand object
+ * @param pos_x             X coordinate to draw
+ * @param pos_y             Y coordinate to draw
+ * @param highlight         Index to highlight, negative means no highlight
+ * @param canvas            Canvas object
+ */
+void draw_hand_column(
+    Hand hand,
+    int16_t pos_x,
+    int16_t pos_y,
+    int8_t highlight,
+    Canvas* const canvas);
+
+/**
+ * Removes a card from the deck (Be aware, if you remove the first item, the deck index will be at -1 so you have to handle that)
+ * @param index Index to remove
+ * @param deck  Deck reference
+ * @return      The removed card
+ */
+Card remove_from_deck(uint16_t index, Deck* deck);
+
+int first_non_flipped_card(Hand hand);
+
+void extract_hand_region(Hand* hand, Hand* to, uint8_t start_index);
+
+void add_hand_region(Hand* to, Hand* from);

+ 53 - 0
main_apps_sources/blackjack/common/dml.c

@@ -0,0 +1,53 @@
+#include "dml.h"
+#include <math.h>
+
+float lerp(float v0, float v1, float t) {
+    if(t > 1) return v1;
+    return (1 - t) * v0 + t * v1;
+}
+
+Vector lerp_2d(Vector start, Vector end, float t) {
+    return (Vector){
+        lerp(start.x, end.x, t),
+        lerp(start.y, end.y, t),
+    };
+}
+
+Vector quadratic_2d(Vector start, Vector control, Vector end, float t) {
+    return lerp_2d(lerp_2d(start, control, t), lerp_2d(control, end, t), t);
+}
+
+Vector vector_add(Vector a, Vector b) {
+    return (Vector){a.x + b.x, a.y + b.y};
+}
+
+Vector vector_sub(Vector a, Vector b) {
+    return (Vector){a.x - b.x, a.y - b.y};
+}
+
+Vector vector_mul_components(Vector a, Vector b) {
+    return (Vector){a.x * b.x, a.y * b.y};
+}
+
+Vector vector_div_components(Vector a, Vector b) {
+    return (Vector){a.x / b.x, a.y / b.y};
+}
+
+Vector vector_normalized(Vector a) {
+    float length = vector_magnitude(a);
+    return (Vector){a.x / length, a.y / length};
+}
+
+float vector_magnitude(Vector a) {
+    return sqrt(a.x * a.x + a.y * a.y);
+}
+
+float vector_distance(Vector a, Vector b) {
+    return vector_magnitude(vector_sub(a, b));
+}
+
+float vector_dot(Vector a, Vector b) {
+    Vector _a = vector_normalized(a);
+    Vector _b = vector_normalized(b);
+    return _a.x * _b.x + _a.y * _b.y;
+}

+ 116 - 0
main_apps_sources/blackjack/common/dml.h

@@ -0,0 +1,116 @@
+//
+// Doofy's Math library
+//
+
+#pragma once
+
+typedef struct {
+    float x;
+    float y;
+} Vector;
+
+#define min(a, b) ((a) < (b) ? (a) : (b))
+#define max(a, b) ((a) > (b) ? (a) : (b))
+#define abs(x) ((x) > 0 ? (x) : -(x))
+
+/**
+ * Lerp function
+ *
+ * @param v0    Start value
+ * @param v1    End value
+ * @param t     Time (0-1 range)
+ * @return      Point between v0-v1 at a given time
+ */
+float lerp(float v0, float v1, float t);
+
+/**
+ * 2D lerp function
+ *
+ * @param start Start vector
+ * @param end   End vector
+ * @param t     Time (0-1 range)
+ * @return      2d Vector between start and end at time
+ */
+Vector lerp_2d(Vector start, Vector end, float t);
+
+/**
+ * Quadratic lerp function
+ *
+ * @param start     Start vector
+ * @param control   Control point
+ * @param end       End vector
+ * @param t         Time (0-1 range)
+ * @return          2d Vector at time
+ */
+Vector quadratic_2d(Vector start, Vector control, Vector end, float t);
+
+/**
+ * Add vector components together
+ *
+ * @param a     First vector
+ * @param b     Second vector
+ * @return      Resulting vector
+ */
+Vector vector_add(Vector a, Vector b);
+
+/**
+ * Subtract vector components together
+ *
+ * @param a First vector
+ * @param b Second vector
+ * @return  Resulting vector
+ */
+Vector vector_sub(Vector a, Vector b);
+
+/**
+ * Multiplying vector components together
+ *
+ * @param a First vector
+ * @param b Second vector
+ * @return  Resulting vector
+ */
+Vector vector_mul_components(Vector a, Vector b);
+
+/**
+ * Dividing vector components
+ *
+ * @param a First vector
+ * @param b Second vector
+ * @return  Resulting vector
+ */
+Vector vector_div_components(Vector a, Vector b);
+
+/**
+ * Calculating Vector length
+ *
+ * @param a Direction vector
+ * @return  Length of the vector
+ */
+float vector_magnitude(Vector a);
+
+/**
+ * Get a normalized vector (length of 1)
+ *
+ * @param a Direction vector
+ * @return  Normalized vector
+ */
+Vector vector_normalized(Vector a);
+
+/**
+ * Calculate two vector's distance
+ *
+ * @param a First vector
+ * @param b Second vector
+ * @return  Distance between vectors
+ */
+float vector_distance(Vector a, Vector b);
+
+/**
+ * Calculate the dot product of the vectors.
+ * No need to normalize, it will do it
+ *
+ * @param a First vector
+ * @param b Second vector
+ * @return  value from -1 to 1
+ */
+float vector_dot(Vector a, Vector b);

+ 103 - 0
main_apps_sources/blackjack/common/menu.c

@@ -0,0 +1,103 @@
+#include "menu.h"
+
+void add_menu(Menu* menu, const char* name, void (*callback)(void*)) {
+    MenuItem* items = menu->items;
+
+    menu->items = malloc(sizeof(MenuItem) * (menu->menu_count + 1));
+    for(uint8_t i = 0; i < menu->menu_count; i++) {
+        menu->items[i] = items[i];
+    }
+    free(items);
+
+    menu->items[menu->menu_count] = (MenuItem){name, true, callback};
+    menu->menu_count++;
+}
+
+void free_menu(Menu* menu) {
+    free(menu->items);
+    free(menu);
+}
+
+void set_menu_state(Menu* menu, uint8_t index, bool state) {
+    if(menu->menu_count > index) {
+        menu->items[index].enabled = state;
+    }
+    if(!state && menu->current_menu == index) move_menu(menu, 1);
+}
+
+void move_menu(Menu* menu, int8_t direction) {
+    if(!menu->enabled) return;
+    int max = menu->menu_count;
+    for(int8_t i = 0; i < max; i++) {
+        FURI_LOG_D(
+            "MENU",
+            "Iteration %i, current %i, direction %i, state %i",
+            i,
+            menu->current_menu,
+            direction,
+            menu->items[menu->current_menu].enabled ? 1 : 0);
+        if(direction < 0 && menu->current_menu == 0) {
+            menu->current_menu = menu->menu_count - 1;
+        } else {
+            menu->current_menu = (menu->current_menu + direction) % menu->menu_count;
+        }
+        FURI_LOG_D(
+            "MENU",
+            "After process current %i, direction %i, state %i",
+            menu->current_menu,
+            direction,
+            menu->items[menu->current_menu].enabled ? 1 : 0);
+        if(menu->items[menu->current_menu].enabled) {
+            FURI_LOG_D("MENU", "Next menu %i", menu->current_menu);
+            return;
+        }
+    }
+    FURI_LOG_D("MENU", "Not found, setting false");
+    menu->enabled = false;
+}
+
+void activate_menu(Menu* menu, void* state) {
+    if(!menu->enabled) return;
+    menu->items[menu->current_menu].callback(state);
+}
+
+void render_menu(Menu* menu, Canvas* canvas, uint8_t pos_x, uint8_t pos_y) {
+    if(!menu->enabled) return;
+    canvas_set_color(canvas, ColorWhite);
+    canvas_draw_rbox(canvas, pos_x, pos_y, menu->menu_width + 2, 10, 2);
+
+    uint8_t w = pos_x + menu->menu_width;
+    uint8_t h = pos_y + 10;
+    uint8_t p1x = pos_x + 2;
+    uint8_t p2x = pos_x + menu->menu_width - 2;
+    uint8_t p1y = pos_y + 2;
+    uint8_t p2y = pos_y + 8;
+
+    canvas_set_color(canvas, ColorBlack);
+    canvas_draw_line(canvas, p1x, pos_y, p2x, pos_y);
+    canvas_draw_line(canvas, p1x, h, p2x, h);
+    canvas_draw_line(canvas, pos_x, p1y, pos_x, p2y);
+    canvas_draw_line(canvas, w, p1y, w, p2y);
+    canvas_draw_dot(canvas, pos_x + 1, pos_y + 1);
+    canvas_draw_dot(canvas, w - 1, pos_y + 1);
+    canvas_draw_dot(canvas, w - 1, h - 1);
+    canvas_draw_dot(canvas, pos_x + 1, h - 1);
+
+    //    canvas_draw_rbox(canvas, pos_x, pos_y, menu->menu_width + 2, 10, 2);
+    canvas_set_font(canvas, FontSecondary);
+    canvas_draw_str_aligned(
+        canvas,
+        pos_x + menu->menu_width / 2,
+        pos_y + 6,
+        AlignCenter,
+        AlignCenter,
+        menu->items[menu->current_menu].name);
+    //9*5
+    int center = pos_x + menu->menu_width / 2;
+    for(uint8_t i = 0; i < 4; i++) {
+        for(int8_t j = -i; j <= i; j++) {
+            canvas_draw_dot(canvas, center + j, pos_y - 4 + i);
+            canvas_draw_dot(canvas, center + j, pos_y + 14 - i);
+        }
+    }
+}

+ 77 - 0
main_apps_sources/blackjack/common/menu.h

@@ -0,0 +1,77 @@
+#pragma once
+
+#include <furi.h>
+#include <gui/gui.h>
+
+typedef struct {
+    const char* name; //Name of the menu
+    bool enabled; //Is the menu item enabled (it will not render, you cannot select it)
+
+    void (*callback)(
+        void* state); //Callback for when the activate_menu is called while this menu is selected
+} MenuItem;
+
+typedef struct {
+    MenuItem* items; //list of menu items
+    uint8_t menu_count; //count of menu items (do not change)
+    uint8_t current_menu; //currently selected menu item
+    uint8_t menu_width; //width of the menu
+    bool enabled; //is the menu enabled (it will not render and accept events when disabled)
+} Menu;
+
+/**
+ * Cleans up the pointers used by the menu
+ *
+ * @param menu Pointer of the menu to clean up
+ */
+void free_menu(Menu* menu);
+
+/**
+ * Add a new menu item
+ *
+ * @param menu      Pointer of the menu
+ * @param name      Name of the menu item
+ * @param callback  Callback called on activation
+ */
+void add_menu(Menu* menu, const char* name, void (*callback)(void*));
+
+/**
+ * Setting menu item to be enabled/disabled
+ *
+ * @param menu  Pointer of the menu
+ * @param index Menu index to set
+ * @param state Enabled (true), Disabled(false)
+ */
+void set_menu_state(Menu* menu, uint8_t index, bool state);
+
+/**
+ * Moves selection up or down
+ *
+ * @param menu      Pointer of the menu
+ * @param direction Direction to move -1 down, 1 up
+ */
+void move_menu(Menu* menu, int8_t direction);
+
+/**
+ * Triggers the current menu callback
+ *
+ * @param menu  Pointer of the menu
+ * @param state Usually your application state
+ */
+void activate_menu(Menu* menu, void* state);
+
+/**
+ * Renders the menu at a coordinate (call it in your render function).
+ *
+ * Keep in mind that Flipper has a 128x64 pixel screen resolution and the coordinate
+ * you give is the menu's rectangle top-left corner (arrows not included).
+ * The rectangle height is 10 px, the arrows have a 4 pixel height. Space needed is 18px.
+ * The width of the menu can be configured in the menu object.
+ *
+ *
+ * @param menu      Pointer of the menu
+ * @param canvas    Flippers Canvas pointer
+ * @param pos_x     X position to draw
+ * @param pos_y     Y position to draw
+ */
+void render_menu(Menu* menu, Canvas* canvas, uint8_t pos_x, uint8_t pos_y);

+ 69 - 0
main_apps_sources/blackjack/common/queue.c

@@ -0,0 +1,69 @@
+#include "queue.h"
+
+void render_queue(const QueueState* queue_state, const void* app_state, Canvas* const canvas) {
+    if(queue_state->current != NULL && queue_state->current->render != NULL)
+        ((QueueItem*)queue_state->current)->render(app_state, canvas);
+}
+
+bool run_queue(QueueState* queue_state, void* app_state) {
+    if(queue_state->current != NULL) {
+        queue_state->running = true;
+        if((furi_get_tick() - queue_state->start) >= queue_state->current->duration)
+            dequeue(queue_state, app_state);
+
+        return true;
+    }
+    return false;
+}
+
+void dequeue(QueueState* queue_state, void* app_state) {
+    ((QueueItem*)queue_state->current)->callback(app_state);
+    QueueItem* f = queue_state->current;
+    queue_state->current = f->next;
+    free(f);
+    if(queue_state->current != NULL) {
+        if(queue_state->current->start != NULL) queue_state->current->start(app_state);
+        queue_state->start = furi_get_tick();
+    } else {
+        queue_state->running = false;
+    }
+}
+
+void queue_clear(QueueState* queue_state) {
+    queue_state->running = false;
+    QueueItem* curr = queue_state->current;
+    while(curr != NULL) {
+        QueueItem* f = curr;
+        curr = curr->next;
+        free(f);
+    }
+}
+
+void enqueue(
+    QueueState* queue_state,
+    void* app_state,
+    void (*done)(void* state),
+    void (*start)(void* state),
+    void (*render)(const void* state, Canvas* const canvas),
+    uint32_t duration) {
+    QueueItem* next;
+    if(queue_state->current == NULL) {
+        queue_state->start = furi_get_tick();
+        queue_state->current = malloc(sizeof(QueueItem));
+        next = queue_state->current;
+        if(next->start != NULL) next->start(app_state);
+
+    } else {
+        next = queue_state->current;
+        while(next->next != NULL) {
+            next = (QueueItem*)(next->next);
+        }
+        next->next = malloc(sizeof(QueueItem));
+        next = next->next;
+    }
+    next->callback = done;
+    next->render = render;
+    next->start = start;
+    next->duration = duration;
+    next->next = NULL;
+}

+ 70 - 0
main_apps_sources/blackjack/common/queue.h

@@ -0,0 +1,70 @@
+#pragma once
+
+#include <gui/gui.h>
+#include <furi.h>
+
+typedef struct {
+    void (*callback)(void* state); //Callback for when the item is dequeued
+    void (*render)(
+        const void* state,
+        Canvas* const canvas); //Callback for the rendering loop while this item is running
+    void (*start)(void* state); //Callback when this item is started running
+    void* next; //Pointer to the next item
+    uint32_t duration; //duration of the item
+} QueueItem;
+
+typedef struct {
+    unsigned int start; //current queue item start time
+    QueueItem* current; //current queue item
+    bool running; //is the queue running
+} QueueState;
+
+/**
+ * Enqueue a new item.
+ *
+ * @param queue_state   The queue state pointer
+ * @param app_state     Your app state
+ * @param done          Callback for dequeue event
+ * @param start         Callback for when the item is activated
+ * @param render        Callback to render loop if needed
+ * @param duration      Length of the item
+ */
+void enqueue(
+    QueueState* queue_state,
+    void* app_state,
+    void (*done)(void* state),
+    void (*start)(void* state),
+    void (*render)(const void* state, Canvas* const canvas),
+    uint32_t duration);
+/**
+ * Clears all queue items
+ *
+ * @param queue_state   The queue state pointer
+ */
+void queue_clear(QueueState* queue_state);
+
+/**
+ * Dequeues the active queue item. Usually you don't need to call it directly.
+ *
+ * @param queue_state   The queue state pointer
+ * @param app_state     Your application state
+ */
+void dequeue(QueueState* queue_state, void* app_state);
+
+/**
+ * Runs the queue logic (place it in your tick function)
+ *
+ * @param queue_state   The queue state pointer
+ * @param app_state     Your application state
+ * @return              FALSE when there is nothing to run, TRUE otherwise
+ */
+bool run_queue(QueueState* queue_state, void* app_state);
+
+/**
+ * Calls the currently active queue items render callback (if there is any)
+ *
+ * @param queue_state   The queue state pointer
+ * @param app_state     Your application state
+ * @param canvas        Pointer to Flipper's canvas object
+ */
+void render_queue(const QueueState* queue_state, const void* app_state, Canvas* const canvas);

+ 257 - 0
main_apps_sources/blackjack/common/ui.c

@@ -0,0 +1,257 @@
+#include "ui.h"
+#include <gui/canvas_i.h>
+#include <u8g2_glue.h>
+#include <gui/icon_animation_i.h>
+#include <gui/icon.h>
+#include <gui/icon_i.h>
+#include <furi_hal.h>
+
+TileMap* tileMap;
+uint8_t tileMapCount = 0;
+
+void ui_cleanup() {
+    if(tileMap != NULL) {
+        for(uint8_t i = 0; i < tileMapCount; i++) {
+            if(tileMap[i].data != NULL) free(tileMap[i].data);
+        }
+        free(tileMap);
+    }
+}
+
+void add_new_tilemap(uint8_t* data, unsigned long iconId) {
+    TileMap* old = tileMap;
+    tileMapCount++;
+    tileMap = malloc(sizeof(TileMap) * tileMapCount);
+    if(tileMapCount > 1) {
+        for(uint8_t i = 0; i < tileMapCount; i++) tileMap[i] = old[i];
+    }
+    tileMap[tileMapCount - 1] = (TileMap){data, iconId};
+}
+
+uint8_t* get_tilemap(unsigned long icon_id) {
+    for(uint8_t i = 0; i < tileMapCount; i++) {
+        if(tileMap[i].iconId == icon_id) return tileMap[i].data;
+    }
+
+    return NULL;
+}
+
+uint32_t pixel_index(uint8_t x, uint8_t y) {
+    return y * SCREEN_WIDTH + x;
+}
+
+bool in_screen(int16_t x, int16_t y) {
+    return x >= 0 && x < SCREEN_WIDTH && y >= 0 && y < SCREEN_HEIGHT;
+}
+
+unsigned flipBit(uint8_t x, uint8_t bit) {
+    return x ^ (1 << bit);
+}
+
+unsigned setBit(uint8_t x, uint8_t bit) {
+    return x | (1 << bit);
+}
+
+unsigned unsetBit(uint8_t x, uint8_t bit) {
+    return x & ~(1 << bit);
+}
+
+bool test_pixel(uint8_t* data, uint8_t x, uint8_t y, uint8_t w) {
+    uint8_t current_bit = (y % 8);
+    uint8_t current_row = ((y - current_bit) / 8);
+    uint8_t current_value = data[current_row * w + x];
+    return current_value & (1 << current_bit);
+}
+
+uint8_t* get_buffer(Canvas* const canvas) {
+    return canvas->fb.tile_buf_ptr;
+    //  return canvas_get_buffer(canvas);
+}
+uint8_t* make_buffer() {
+    return malloc(sizeof(uint8_t) * 8 * 128);
+}
+void clone_buffer(uint8_t* canvas, uint8_t* data) {
+    for(int i = 0; i < 1024; i++) {
+        data[i] = canvas[i];
+    }
+}
+
+bool read_pixel(Canvas* const canvas, int16_t x, int16_t y) {
+    if(in_screen(x, y)) {
+        return test_pixel(get_buffer(canvas), x, y, SCREEN_WIDTH);
+    }
+    return false;
+}
+
+void set_pixel(Canvas* const canvas, int16_t x, int16_t y, DrawMode draw_mode) {
+    if(in_screen(x, y)) {
+        uint8_t current_bit = (y % 8);
+        uint8_t current_row = ((y - current_bit) / 8);
+        uint32_t i = pixel_index(x, current_row);
+        uint8_t* buffer = get_buffer(canvas);
+
+        uint8_t current_value = buffer[i];
+        if(draw_mode == Inverse) {
+            buffer[i] = flipBit(current_value, current_bit);
+        } else {
+            if(draw_mode == White) {
+                buffer[i] = unsetBit(current_value, current_bit);
+            } else {
+                buffer[i] = setBit(current_value, current_bit);
+            }
+        }
+    }
+}
+
+void draw_line(
+    Canvas* const canvas,
+    int16_t x1,
+    int16_t y1,
+    int16_t x2,
+    int16_t y2,
+    DrawMode draw_mode) {
+    for(int16_t x = x2; x >= x1; x--) {
+        for(int16_t y = y2; y >= y1; y--) {
+            set_pixel(canvas, x, y, draw_mode);
+        }
+    }
+}
+
+void draw_rounded_box_frame(
+    Canvas* const canvas,
+    int16_t x,
+    int16_t y,
+    uint8_t w,
+    uint8_t h,
+    DrawMode draw_mode) {
+    int16_t xMinCorner = x + 1;
+    int16_t xMax = x + w - 1;
+    int16_t xMaxCorner = x + w - 2;
+    int16_t yMinCorner = y + 1;
+    int16_t yMax = y + h - 1;
+    int16_t yMaxCorner = y + h - 2;
+    draw_line(canvas, xMinCorner, y, xMaxCorner, y, draw_mode);
+    draw_line(canvas, xMinCorner, yMax, xMaxCorner, yMax, draw_mode);
+    draw_line(canvas, x, yMinCorner, x, yMaxCorner, draw_mode);
+    draw_line(canvas, xMax, yMinCorner, xMax, yMaxCorner, draw_mode);
+}
+
+void draw_rounded_box(
+    Canvas* const canvas,
+    int16_t x,
+    int16_t y,
+    uint8_t w,
+    uint8_t h,
+    DrawMode draw_mode) {
+    for(int16_t o = w - 2; o >= 1; o--) {
+        for(int16_t p = h - 2; p >= 1; p--) {
+            set_pixel(canvas, x + o, y + p, draw_mode);
+        }
+    }
+    draw_rounded_box_frame(canvas, x, y, w, h, draw_mode);
+}
+
+void invert_shape(Canvas* const canvas, uint8_t* data, int16_t x, int16_t y, uint8_t w, uint8_t h) {
+    draw_pixels(canvas, data, x, y, w, h, Inverse);
+}
+
+void draw_pixels(
+    Canvas* const canvas,
+    uint8_t* data,
+    int16_t x,
+    int16_t y,
+    uint8_t w,
+    uint8_t h,
+    DrawMode drawMode) {
+    for(int8_t o = 0; o < w; o++) {
+        for(int8_t p = 0; p < h; p++) {
+            if(in_screen(o + x, p + y) && data[p * w + o] == 1)
+                set_pixel(canvas, o + x, p + y, drawMode);
+        }
+    }
+}
+
+void draw_rectangle(
+    Canvas* const canvas,
+    int16_t x,
+    int16_t y,
+    uint8_t w,
+    uint8_t h,
+    DrawMode drawMode) {
+    for(int8_t o = 0; o < w; o++) {
+        for(int8_t p = 0; p < h; p++) {
+            if(in_screen(o + x, p + y)) {
+                set_pixel(canvas, o + x, p + y, drawMode);
+            }
+        }
+    }
+}
+
+void invert_rectangle(Canvas* const canvas, int16_t x, int16_t y, uint8_t w, uint8_t h) {
+    draw_rectangle(canvas, x, y, w, h, Inverse);
+}
+
+uint8_t* image_data(Canvas* const canvas, const Icon* icon) {
+    uint8_t* data = malloc(sizeof(uint8_t) * 8 * 128);
+    uint8_t* screen = canvas->fb.tile_buf_ptr;
+    canvas->fb.tile_buf_ptr = data;
+    canvas_draw_icon(canvas, 0, 0, icon);
+    canvas->fb.tile_buf_ptr = screen;
+    return data;
+}
+
+uint8_t* getOrAddIconData(Canvas* const canvas, const Icon* icon) {
+    uint8_t* icon_data = get_tilemap((unsigned long)icon);
+    if(icon_data == NULL) {
+        icon_data = image_data(canvas, icon);
+        add_new_tilemap(icon_data, (unsigned long)icon);
+    }
+    return icon_data;
+}
+
+void draw_icon_clip(
+    Canvas* const canvas,
+    const Icon* icon,
+    int16_t x,
+    int16_t y,
+    uint8_t left,
+    uint8_t top,
+    uint8_t w,
+    uint8_t h,
+    DrawMode drawMode) {
+    uint8_t* icon_data = getOrAddIconData(canvas, icon);
+
+    for(int i = 0; i < w; i++) {
+        for(int j = 0; j < h; j++) {
+            bool on = test_pixel(icon_data, left + i, top + j, SCREEN_WIDTH);
+            if(drawMode == Filled) {
+                set_pixel(canvas, x + i, y + j, on ? Black : White);
+            } else if(on)
+                set_pixel(canvas, x + i, y + j, drawMode);
+        }
+    }
+}
+
+void draw_icon_clip_flipped(
+    Canvas* const canvas,
+    const Icon* icon,
+    int16_t x,
+    int16_t y,
+    uint8_t left,
+    uint8_t top,
+    uint8_t w,
+    uint8_t h,
+    DrawMode drawMode) {
+    uint8_t* icon_data = getOrAddIconData(canvas, icon);
+
+    for(int i = 0; i < w; i++) {
+        for(int j = 0; j < h; j++) {
+            bool on = test_pixel(icon_data, left + i, top + j, SCREEN_WIDTH);
+
+            if(drawMode == Filled) {
+                set_pixel(canvas, x + w - i - 1, y + h - j - 1, on ? Black : White);
+            } else if(on)
+                set_pixel(canvas, x + w - i - 1, y + h - j - 1, drawMode);
+        }
+    }
+}

+ 105 - 0
main_apps_sources/blackjack/common/ui.h

@@ -0,0 +1,105 @@
+#pragma once
+
+#include <furi.h>
+#include <gui/canvas.h>
+
+#define SCREEN_WIDTH 128
+#define SCREEN_HEIGHT 64
+
+typedef enum {
+    Black,
+    White,
+    Inverse,
+    Filled //Currently only for Icon clip drawing
+} DrawMode;
+
+// size is the screen size
+
+typedef struct {
+    uint8_t* data;
+    unsigned long iconId;
+} TileMap;
+
+bool test_pixel(uint8_t* data, uint8_t x, uint8_t y, uint8_t w);
+
+uint8_t* image_data(Canvas* const canvas, const Icon* icon);
+
+uint32_t pixel_index(uint8_t x, uint8_t y);
+
+void draw_icon_clip(
+    Canvas* const canvas,
+    const Icon* icon,
+    int16_t x,
+    int16_t y,
+    uint8_t left,
+    uint8_t top,
+    uint8_t w,
+    uint8_t h,
+    DrawMode drawMode);
+
+void draw_icon_clip_flipped(
+    Canvas* const canvas,
+    const Icon* icon,
+    int16_t x,
+    int16_t y,
+    uint8_t left,
+    uint8_t top,
+    uint8_t w,
+    uint8_t h,
+    DrawMode drawMode);
+
+void draw_rounded_box(
+    Canvas* const canvas,
+    int16_t x,
+    int16_t y,
+    uint8_t w,
+    uint8_t h,
+    DrawMode drawMode);
+
+void draw_rounded_box_frame(
+    Canvas* const canvas,
+    int16_t x,
+    int16_t y,
+    uint8_t w,
+    uint8_t h,
+    DrawMode drawMode);
+
+void draw_rectangle(
+    Canvas* const canvas,
+    int16_t x,
+    int16_t y,
+    uint8_t w,
+    uint8_t h,
+    DrawMode drawMode);
+
+void invert_rectangle(Canvas* const canvas, int16_t x, int16_t y, uint8_t w, uint8_t h);
+
+void invert_shape(Canvas* const canvas, uint8_t* data, int16_t x, int16_t y, uint8_t w, uint8_t h);
+
+void draw_pixels(
+    Canvas* const canvas,
+    uint8_t* data,
+    int16_t x,
+    int16_t y,
+    uint8_t w,
+    uint8_t h,
+    DrawMode drawMode);
+
+bool read_pixel(Canvas* const canvas, int16_t x, int16_t y);
+
+void set_pixel(Canvas* const canvas, int16_t x, int16_t y, DrawMode draw_mode);
+
+void draw_line(
+    Canvas* const canvas,
+    int16_t x1,
+    int16_t y1,
+    int16_t x2,
+    int16_t y2,
+    DrawMode draw_mode);
+
+bool in_screen(int16_t x, int16_t y);
+
+void ui_cleanup();
+uint8_t* get_buffer(Canvas* const canvas);
+uint8_t* make_buffer();
+void clone_buffer(uint8_t* canvas, uint8_t* data);

+ 77 - 0
main_apps_sources/blackjack/defines.h

@@ -0,0 +1,77 @@
+#pragma once
+
+#include <furi.h>
+#include <input/input.h>
+#include <gui/elements.h>
+#include <flipper_format/flipper_format.h>
+#include <flipper_format/flipper_format_i.h>
+#include "common/card.h"
+#include "common/queue.h"
+#include "common/menu.h"
+
+#define APP_NAME "Blackjack"
+
+#define CONF_ANIMATION_DURATION "AnimationDuration"
+#define CONF_MESSAGE_DURATION "MessageDuration"
+#define CONF_STARTING_MONEY "StartingMoney"
+#define CONF_ROUND_PRICE "RoundPrice"
+#define CONF_SOUND_EFFECTS "SoundEffects"
+
+typedef enum {
+    EventTypeTick,
+    EventTypeKey,
+} EventType;
+
+typedef struct {
+    uint32_t animation_duration;
+    uint32_t message_duration;
+    uint32_t starting_money;
+    uint32_t round_price;
+    bool sound_effects;
+} Settings;
+
+typedef struct {
+    EventType type;
+    InputEvent input;
+} AppEvent;
+
+typedef enum {
+    GameStateGameOver,
+    GameStateStart,
+    GameStatePlay,
+    GameStateSettings,
+    GameStateDealer,
+} PlayState;
+
+typedef enum {
+    DirectionUp,
+    DirectionDown,
+    DirectionRight,
+    DirectionLeft,
+    Select,
+    Back,
+    None
+} Direction;
+
+typedef struct {
+    FuriMutex* mutex;
+    Card player_cards[21];
+    Card dealer_cards[21];
+    uint8_t player_card_count;
+    uint8_t dealer_card_count;
+
+    Direction selectDirection;
+    Settings settings;
+
+    uint32_t player_score;
+    uint32_t bet;
+    uint8_t selectedMenu;
+    bool doubled;
+    bool started;
+    bool processing;
+    Deck deck;
+    PlayState state;
+    QueueState queue_state;
+    Menu* menu;
+    unsigned int last_tick;
+} GameState;

+ 186 - 0
main_apps_sources/blackjack/ui.c

@@ -0,0 +1,186 @@
+#include <math.h>
+#include <notification/notification_messages.h>
+
+#include "ui.h"
+
+#define LINE_HEIGHT 16
+#define ITEM_PADDING 4
+
+const char MoneyMul[4] = {'K', 'B', 'T', 'S'};
+
+void draw_player_scene(Canvas* const canvas, const GameState* game_state) {
+    int max_card = game_state->player_card_count;
+
+    if(max_card > 0) draw_deck((game_state->player_cards), max_card, canvas);
+
+    if(game_state->dealer_card_count > 0) draw_card_back_at(13, 5, canvas);
+
+    max_card = game_state->dealer_card_count;
+    if(max_card > 1) {
+        draw_card_at(
+            2, 2, game_state->dealer_cards[1].pip, game_state->dealer_cards[1].character, canvas);
+    }
+}
+
+void draw_dealer_scene(Canvas* const canvas, const GameState* game_state) {
+    uint8_t max_card = game_state->dealer_card_count;
+    draw_deck((game_state->dealer_cards), max_card, canvas);
+}
+
+void popup_frame(Canvas* const canvas) {
+    canvas_set_color(canvas, ColorWhite);
+    canvas_draw_box(canvas, 32, 15, 66, 13);
+    canvas_set_color(canvas, ColorBlack);
+    canvas_draw_frame(canvas, 32, 15, 66, 13);
+    canvas_set_font(canvas, FontSecondary);
+}
+
+void draw_play_menu(Canvas* const canvas, const GameState* game_state) {
+    const char* menus[3] = {"Double", "Hit", "Stay"};
+    for(uint8_t m = 0; m < 3; m++) {
+        if(m == 0 &&
+           (game_state->doubled || game_state->player_score < game_state->settings.round_price))
+            continue;
+        int y = m * 13 + 25;
+        canvas_set_color(canvas, ColorBlack);
+
+        if(game_state->selectedMenu == m) {
+            canvas_set_color(canvas, ColorBlack);
+            canvas_draw_box(canvas, 1, y, 31, 12);
+        } else {
+            canvas_set_color(canvas, ColorWhite);
+            canvas_draw_box(canvas, 1, y, 31, 12);
+            canvas_set_color(canvas, ColorBlack);
+            canvas_draw_frame(canvas, 1, y, 31, 12);
+        }
+
+        if(game_state->selectedMenu == m)
+            canvas_set_color(canvas, ColorWhite);
+        else
+            canvas_set_color(canvas, ColorBlack);
+        canvas_draw_str_aligned(canvas, 16, y + 6, AlignCenter, AlignCenter, menus[m]);
+    }
+}
+
+void draw_screen(Canvas* const canvas, const bool* points) {
+    for(uint8_t x = 0; x < 128; x++) {
+        for(uint8_t y = 0; y < 64; y++) {
+            if(points[y * 128 + x]) canvas_draw_dot(canvas, x, y);
+        }
+    }
+}
+
+void draw_score(Canvas* const canvas, bool top, uint8_t amount) {
+    char drawChar[20];
+    snprintf(drawChar, sizeof(drawChar), "Player score: %i", amount);
+    if(top)
+        canvas_draw_str_aligned(canvas, 64, 2, AlignCenter, AlignTop, drawChar);
+    else
+        canvas_draw_str_aligned(canvas, 64, 62, AlignCenter, AlignBottom, drawChar);
+}
+
+void draw_money(Canvas* const canvas, uint32_t score) {
+    canvas_set_font(canvas, FontSecondary);
+    char drawChar[11];
+    uint32_t currAmount = score;
+    if(currAmount < 1000) {
+        snprintf(drawChar, sizeof(drawChar), "$%lu", currAmount);
+    } else {
+        char c = 'K';
+        for(uint8_t i = 0; i < 4; i++) {
+            currAmount = currAmount / 1000;
+            if(currAmount < 1000) {
+                c = MoneyMul[i];
+                break;
+            }
+        }
+
+        snprintf(drawChar, sizeof(drawChar), "$%lu %c", currAmount, c);
+    }
+    canvas_draw_str_aligned(canvas, 126, 2, AlignRight, AlignTop, drawChar);
+}
+
+void draw_menu(
+    Canvas* const canvas,
+    const char* text,
+    const char* value,
+    int8_t y,
+    bool left_caret,
+    bool right_caret,
+    bool selected) {
+    UNUSED(selected);
+    if(y < 0 || y >= 64) return;
+
+    if(selected) {
+        canvas_set_color(canvas, ColorBlack);
+        canvas_draw_box(canvas, 0, y, 122, LINE_HEIGHT);
+        canvas_set_color(canvas, ColorWhite);
+    }
+
+    canvas_draw_str_aligned(canvas, 4, y + ITEM_PADDING, AlignLeft, AlignTop, text);
+    if(left_caret) canvas_draw_str_aligned(canvas, 80, y + ITEM_PADDING, AlignLeft, AlignTop, "<");
+    canvas_draw_str_aligned(canvas, 100, y + ITEM_PADDING, AlignCenter, AlignTop, value);
+    if(right_caret)
+        canvas_draw_str_aligned(canvas, 120, y + ITEM_PADDING, AlignRight, AlignTop, ">");
+
+    canvas_set_color(canvas, ColorBlack);
+}
+
+void settings_page(Canvas* const canvas, const GameState* gameState) {
+    char drawChar[10];
+    int startY = 0;
+    if(LINE_HEIGHT * (gameState->selectedMenu + 1) >= 64) {
+        startY -= (LINE_HEIGHT * (gameState->selectedMenu + 1)) - 64;
+    }
+
+    int scrollHeight = round(64 / 6.0) + ITEM_PADDING * 2;
+    int scrollPos = 64 / (6.0 / (gameState->selectedMenu + 1)) - ITEM_PADDING * 2;
+
+    canvas_set_color(canvas, ColorBlack);
+    canvas_draw_box(canvas, 123, scrollPos, 4, scrollHeight);
+    canvas_draw_box(canvas, 125, 0, 1, 64);
+
+    snprintf(drawChar, sizeof(drawChar), "%li", gameState->settings.starting_money);
+    draw_menu(
+        canvas,
+        "Start money",
+        drawChar,
+        0 * LINE_HEIGHT + startY,
+        gameState->settings.starting_money > gameState->settings.round_price,
+        gameState->settings.starting_money < 400,
+        gameState->selectedMenu == 0);
+    snprintf(drawChar, sizeof(drawChar), "%li", gameState->settings.round_price);
+    draw_menu(
+        canvas,
+        "Round price",
+        drawChar,
+        1 * LINE_HEIGHT + startY,
+        gameState->settings.round_price > 10,
+        gameState->settings.round_price < gameState->settings.starting_money,
+        gameState->selectedMenu == 1);
+
+    snprintf(drawChar, sizeof(drawChar), "%li", gameState->settings.animation_duration);
+    draw_menu(
+        canvas,
+        "Anim. length",
+        drawChar,
+        2 * LINE_HEIGHT + startY,
+        gameState->settings.animation_duration > 0,
+        gameState->settings.animation_duration < 2000,
+        gameState->selectedMenu == 2);
+    snprintf(drawChar, sizeof(drawChar), "%li", gameState->settings.message_duration);
+    draw_menu(
+        canvas,
+        "Popup time",
+        drawChar,
+        3 * LINE_HEIGHT + startY,
+        gameState->settings.message_duration > 0,
+        gameState->settings.message_duration < 2000,
+        gameState->selectedMenu == 3);
+    //    draw_menu(canvas, "Sound", gameState->settings.sound_effects ? "Yes" : "No",
+    //              5 * LINE_HEIGHT + startY,
+    //              true,
+    //              true,
+    //              gameState->selectedMenu == 5
+    //    );
+}

+ 18 - 0
main_apps_sources/blackjack/ui.h

@@ -0,0 +1,18 @@
+#pragma once
+
+#include "defines.h"
+#include <gui/gui.h>
+
+void draw_player_scene(Canvas* const canvas, const GameState* game_state);
+
+void draw_dealer_scene(Canvas* const canvas, const GameState* game_state);
+
+void draw_play_menu(Canvas* const canvas, const GameState* game_state);
+
+void draw_score(Canvas* const canvas, bool top, uint8_t amount);
+
+void draw_money(Canvas* const canvas, uint32_t score);
+void settings_page(Canvas* const canvas, const GameState* gameState);
+
+void popup_frame(Canvas* const canvas);
+void draw_screen(Canvas* const canvas, const bool* points);

+ 123 - 0
main_apps_sources/blackjack/util.c

@@ -0,0 +1,123 @@
+#include <storage/storage.h>
+#include "util.h"
+
+const char* CONFIG_FILE_PATH = EXT_PATH(".blackjack.settings");
+
+void save_settings(Settings settings) {
+    Storage* storage = furi_record_open(RECORD_STORAGE);
+    FlipperFormat* file = flipper_format_file_alloc(storage);
+    FURI_LOG_D(APP_NAME, "Saving config");
+    if(flipper_format_file_open_existing(file, CONFIG_FILE_PATH)) {
+        FURI_LOG_D(
+            APP_NAME, "Saving %s: %ld", CONF_ANIMATION_DURATION, settings.animation_duration);
+        flipper_format_update_uint32(
+            file, CONF_ANIMATION_DURATION, &(settings.animation_duration), 1);
+
+        FURI_LOG_D(APP_NAME, "Saving %s: %ld", CONF_MESSAGE_DURATION, settings.message_duration);
+        flipper_format_update_uint32(file, CONF_MESSAGE_DURATION, &(settings.message_duration), 1);
+
+        FURI_LOG_D(APP_NAME, "Saving %s: %ld", CONF_STARTING_MONEY, settings.starting_money);
+        flipper_format_update_uint32(file, CONF_STARTING_MONEY, &(settings.starting_money), 1);
+
+        FURI_LOG_D(APP_NAME, "Saving %s: %ld", CONF_ROUND_PRICE, settings.round_price);
+        flipper_format_update_uint32(file, CONF_ROUND_PRICE, &(settings.round_price), 1);
+
+        FURI_LOG_D(APP_NAME, "Saving %s: %i", CONF_SOUND_EFFECTS, settings.sound_effects ? 1 : 0);
+        flipper_format_update_bool(file, CONF_SOUND_EFFECTS, &(settings.sound_effects), 1);
+        FURI_LOG_D(APP_NAME, "Config saved");
+    } else {
+        FURI_LOG_E(APP_NAME, "Save error");
+    }
+    flipper_format_file_close(file);
+    flipper_format_free(file);
+    furi_record_close(RECORD_STORAGE);
+}
+
+void save_settings_file(FlipperFormat* file, Settings* settings) {
+    flipper_format_write_header_cstr(file, CONFIG_FILE_HEADER, CONFIG_FILE_VERSION);
+    flipper_format_write_comment_cstr(file, "Card animation duration in ms");
+    flipper_format_write_uint32(file, CONF_ANIMATION_DURATION, &(settings->animation_duration), 1);
+    flipper_format_write_comment_cstr(file, "Popup message duration in ms");
+    flipper_format_write_uint32(file, CONF_MESSAGE_DURATION, &(settings->message_duration), 1);
+    flipper_format_write_comment_cstr(file, "Player's starting money");
+    flipper_format_write_uint32(file, CONF_STARTING_MONEY, &(settings->starting_money), 1);
+    flipper_format_write_comment_cstr(file, "Round price");
+    flipper_format_write_uint32(file, CONF_ROUND_PRICE, &(settings->round_price), 1);
+    flipper_format_write_comment_cstr(file, "Enable sound effects");
+    flipper_format_write_bool(file, CONF_SOUND_EFFECTS, &(settings->sound_effects), 1);
+}
+
+Settings load_settings() {
+    Settings settings;
+
+    FURI_LOG_D(APP_NAME, "Loading default settings");
+    settings.animation_duration = 800;
+    settings.message_duration = 1500;
+    settings.starting_money = 200;
+    settings.round_price = 10;
+    settings.sound_effects = true;
+
+    FURI_LOG_D(APP_NAME, "Opening storage");
+    Storage* storage = furi_record_open(RECORD_STORAGE);
+    FURI_LOG_D(APP_NAME, "Allocating file");
+    FlipperFormat* file = flipper_format_file_alloc(storage);
+
+    FURI_LOG_D(APP_NAME, "Allocating string");
+    FuriString* string_value;
+    string_value = furi_string_alloc();
+
+    if(storage_common_stat(storage, CONFIG_FILE_PATH, NULL) != FSE_OK) {
+        FURI_LOG_D(APP_NAME, "Config file %s not found, creating new one...", CONFIG_FILE_PATH);
+        if(!flipper_format_file_open_new(file, CONFIG_FILE_PATH)) {
+            FURI_LOG_E(APP_NAME, "Error creating new file %s", CONFIG_FILE_PATH);
+            flipper_format_file_close(file);
+        } else {
+            save_settings_file(file, &settings);
+        }
+    } else {
+        if(!flipper_format_file_open_existing(file, CONFIG_FILE_PATH)) {
+            FURI_LOG_E(APP_NAME, "Error opening existing file %s", CONFIG_FILE_PATH);
+            flipper_format_file_close(file);
+        } else {
+            uint32_t value;
+            bool valueBool;
+            FURI_LOG_D(APP_NAME, "Checking version");
+            if(!flipper_format_read_header(file, string_value, &value)) {
+                FURI_LOG_E(APP_NAME, "Config file mismatch");
+            } else {
+                FURI_LOG_D(APP_NAME, "Loading %s", CONF_ANIMATION_DURATION);
+                if(flipper_format_read_uint32(file, CONF_ANIMATION_DURATION, &value, 1)) {
+                    settings.animation_duration = value;
+                    FURI_LOG_D(APP_NAME, "Loaded %s: %ld", CONF_ANIMATION_DURATION, value);
+                }
+                FURI_LOG_D(APP_NAME, "Loading %s", CONF_MESSAGE_DURATION);
+                if(flipper_format_read_uint32(file, CONF_MESSAGE_DURATION, &value, 1)) {
+                    settings.message_duration = value;
+                    FURI_LOG_D(APP_NAME, "Loaded %s: %ld", CONF_MESSAGE_DURATION, value);
+                }
+                FURI_LOG_D(APP_NAME, "Loading %s", CONF_STARTING_MONEY);
+                if(flipper_format_read_uint32(file, CONF_STARTING_MONEY, &value, 1)) {
+                    settings.starting_money = value;
+                    FURI_LOG_D(APP_NAME, "Loaded %s: %ld", CONF_STARTING_MONEY, value);
+                }
+                FURI_LOG_D(APP_NAME, "Loading %s", CONF_ROUND_PRICE);
+                if(flipper_format_read_uint32(file, CONF_ROUND_PRICE, &value, 1)) {
+                    settings.round_price = value;
+                    FURI_LOG_D(APP_NAME, "Loaded %s: %ld", CONF_ROUND_PRICE, value);
+                }
+                FURI_LOG_D(APP_NAME, "Loading %s", CONF_SOUND_EFFECTS);
+                if(flipper_format_read_bool(file, CONF_SOUND_EFFECTS, &valueBool, 1)) {
+                    settings.sound_effects = valueBool;
+                    FURI_LOG_D(APP_NAME, "Loaded %s: %i", CONF_ROUND_PRICE, valueBool ? 1 : 0);
+                }
+            }
+            flipper_format_file_close(file);
+        }
+    }
+
+    furi_string_free(string_value);
+    //        flipper_format_file_close(file);
+    flipper_format_free(file);
+    furi_record_close(RECORD_STORAGE);
+    return settings;
+}

+ 7 - 0
main_apps_sources/blackjack/util.h

@@ -0,0 +1,7 @@
+#pragma once
+#include "defines.h"
+#define CONFIG_FILE_HEADER "Blackjack config file"
+#define CONFIG_FILE_VERSION 1
+
+void save_settings(Settings settings);
+Settings load_settings();

+ 22 - 0
main_apps_sources/bomberduck/LICENSE

@@ -0,0 +1,22 @@
+MIT License
+
+Copyright (c) 2023 лень
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+

+ 2 - 0
main_apps_sources/bomberduck/README.md

@@ -0,0 +1,2 @@
+# flipperzero-bomberduck
+Bomberman clone on flipper zero!

+ 17 - 0
main_apps_sources/bomberduck/application.fam

@@ -0,0 +1,17 @@
+App(
+    appid="bomberduck",
+    name="Bomberduck",
+    apptype=FlipperAppType.EXTERNAL,
+    entry_point="bomberduck_app",
+    requires=[
+        "gui",
+    ],
+    stack_size=1 * 1024,
+    order=90,
+	fap_icon="bomb.png",
+    fap_category="Games",
+    fap_icon_assets="assets",
+    fap_author="@leo-need-more-coffee & @xMasterX",
+    fap_version="1.0",
+    fap_description="Bomberduck(Bomberman) Game",
+)

BIN
main_apps_sources/bomberduck/assets/bomb0.png


BIN
main_apps_sources/bomberduck/assets/bomb1.png


BIN
main_apps_sources/bomberduck/assets/bomb2.png


BIN
main_apps_sources/bomberduck/assets/box.png


BIN
main_apps_sources/bomberduck/assets/end.png


BIN
main_apps_sources/bomberduck/assets/enemy1.png


BIN
main_apps_sources/bomberduck/assets/enemyleft.png


BIN
main_apps_sources/bomberduck/assets/enemyright.png


BIN
main_apps_sources/bomberduck/assets/explore.png


BIN
main_apps_sources/bomberduck/assets/playerleft.png


BIN
main_apps_sources/bomberduck/assets/playerright.png


BIN
main_apps_sources/bomberduck/assets/unbreakbox.png


BIN
main_apps_sources/bomberduck/bomb.png


+ 648 - 0
main_apps_sources/bomberduck/bomberduck.c

@@ -0,0 +1,648 @@
+#include <stdio.h>
+#include <furi.h>
+
+#include <gui/gui.h>
+#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>
+
+int max(int a, int b) {
+    return (a > b) ? a : b;
+}
+
+int min(int a, int b) {
+    return (a < b) ? a : b;
+}
+
+#define WorldSizeX 12
+#define WorldSizeY 6
+#define BombRange 1
+
+typedef struct {
+    FuriMutex* mutex;
+} BomberState;
+
+typedef struct {
+    int row;
+    int col;
+} Cell;
+
+typedef struct {
+    Cell cells[WorldSizeY * WorldSizeX];
+    int front;
+    int rear;
+} Queue;
+
+void enqueue(Queue* q, Cell c) {
+    q->cells[q->rear] = c;
+    q->rear++;
+}
+
+Cell dequeue(Queue* q) {
+    Cell c = q->cells[q->front];
+    q->front++;
+
+    return c;
+}
+
+bool is_empty(Queue* q) {
+    return q->front == q->rear;
+}
+
+typedef struct {
+    int x;
+    int y;
+    int planted;
+} Bomb;
+
+typedef struct {
+    int x;
+    int y;
+    bool side;
+} Player;
+
+typedef struct {
+    int x;
+    int y;
+    int last;
+    bool side;
+    int level;
+} Enemy;
+
+typedef struct {
+    int matrix[WorldSizeY][WorldSizeX];
+    Player* player;
+    bool running;
+    int level;
+
+    Enemy enemies[10];
+    int enemies_count;
+
+    Bomb bombs[100];
+    int bombs_count;
+
+    int endx;
+    int endy;
+} World;
+
+Player player = {0, 0, 1};
+World world = {{{0}}, &player, 1, 0, {}, 0, {}, 0, 0, 0};
+bool vibration = false;
+
+void init() {
+    player.x = 1;
+    player.y = 1;
+
+    world.endx = 4 + rand() % 8;
+    world.endy = rand() % 6;
+    for(int i = 0; i < WorldSizeY; i++) {
+        for(int j = 0; j < WorldSizeX; j++) {
+            world.matrix[i][j] = rand() % 3;
+        }
+    }
+    world.running = 1;
+    world.bombs_count = 0;
+    vibration = false;
+    for(int j = max(0, player.y - BombRange); j < min(WorldSizeY, player.y + BombRange + 1); j++) {
+        world.matrix[j][player.x] = 0;
+    }
+
+    for(int j = max(0, player.x - BombRange); j < min(WorldSizeX, player.x + BombRange + 1); j++) {
+        world.matrix[player.y][j] = 0;
+    }
+
+    world.enemies_count = 0;
+    for(int j = 0; j < rand() % 4 + world.level / 5; j++) {
+        Enemy enemy;
+        enemy.x = 4 + rand() % 7;
+        enemy.y = rand() % 6;
+        enemy.last = 0;
+        enemy.side = 1;
+        enemy.level = 0;
+
+        world.enemies[j] = enemy;
+        world.enemies_count++;
+
+        for(int m = max(0, world.enemies[j].y - BombRange);
+            m < min(WorldSizeY, world.enemies[j].y + BombRange + 1);
+            m++) {
+            world.matrix[m][world.enemies[j].x] = 0;
+        }
+
+        for(int m = max(0, world.enemies[j].x - BombRange);
+            m < min(WorldSizeX, world.enemies[j].x + BombRange + 1);
+            m++) {
+            world.matrix[world.enemies[j].y][m] = 0;
+        }
+    }
+    world.matrix[world.endy][world.endx] = 1;
+}
+
+const NotificationSequence end = {
+    &message_vibro_on,
+
+    &message_note_ds4,
+    &message_delay_10,
+    &message_sound_off,
+    &message_delay_10,
+
+    &message_note_ds4,
+    &message_delay_10,
+    &message_sound_off,
+    &message_delay_10,
+
+    &message_note_ds4,
+    &message_delay_10,
+    &message_sound_off,
+    &message_delay_10,
+
+    &message_vibro_off,
+    NULL,
+};
+
+static const NotificationSequence bomb2 = {
+    &message_vibro_on,
+    &message_delay_25,
+    &message_vibro_off,
+    NULL,
+};
+
+static const NotificationSequence bomb_explore = {
+    &message_vibro_on,
+    &message_delay_50,
+    &message_vibro_off,
+    NULL,
+};
+
+static const NotificationSequence vibr1 = {
+    &message_vibro_on,
+    &message_delay_10,
+    &message_vibro_off,
+    &message_delay_10,
+    &message_vibro_on,
+    &message_delay_10,
+    &message_vibro_off,
+    &message_delay_10,
+
+    NULL,
+};
+
+void intToStr(int num, char* str) {
+    int i = 0, sign = 0;
+
+    if(num < 0) {
+        num = -num;
+        sign = 1;
+    }
+
+    do {
+        str[i++] = num % 10 + '0';
+        num /= 10;
+    } while(num > 0);
+
+    if(sign) {
+        str[i++] = '-';
+    }
+
+    str[i] = '\0';
+
+    // Reverse the string
+    int j, len = i;
+    char temp;
+    for(j = 0; j < len / 2; j++) {
+        temp = str[j];
+        str[j] = str[len - j - 1];
+        str[len - j - 1] = temp;
+    }
+}
+
+bool BFS() {
+    // Initialize visited array and queue
+    int visited[WorldSizeY][WorldSizeX] = {0};
+    Queue q = {.front = 0, .rear = 0};
+    // Mark the starting cell as visited and enqueue it
+    visited[world.player->y][world.player->x] = 1;
+    Cell startCell = {.row = world.player->y, .col = world.player->x};
+    enqueue(&q, startCell);
+    // Traverse the field
+    while(!is_empty(&q)) {
+        // Dequeue a cell from the queue
+        Cell currentCell = dequeue(&q);
+        // Check if the current cell is the destination cell
+        if(currentCell.row == world.endy && currentCell.col == world.endx) {
+            return true;
+        }
+        // Check the neighboring cells
+        for(int rowOffset = -1; rowOffset <= 1; rowOffset++) {
+            for(int colOffset = -1; colOffset <= 1; colOffset++) {
+                // Skip diagonals and the current cell
+                if(rowOffset == 0 && colOffset == 0) {
+                    continue;
+                }
+                if(rowOffset != 0 && colOffset != 0) {
+                    continue;
+                }
+                // Calculate the row and column of the neighboring cell
+                int neighborRow = currentCell.row + rowOffset;
+                int neighborCol = currentCell.col + colOffset;
+                // Skip out-of-bounds cells and already visited cells
+                if(neighborRow < 0 || neighborRow >= WorldSizeY || neighborCol < 0 ||
+                   neighborCol >= WorldSizeX) {
+                    continue;
+                }
+                if(visited[neighborRow][neighborCol]) {
+                    continue;
+                }
+                // Mark the neighboring cell as visited and enqueue it
+                if(world.matrix[neighborRow][neighborCol] != 2) {
+                    visited[neighborRow][neighborCol] = 1;
+                    Cell neighborCell = {.row = neighborRow, .col = neighborCol};
+                    enqueue(&q, neighborCell);
+                }
+            }
+        }
+    }
+    return false;
+}
+
+static void draw_callback(Canvas* canvas, void* ctx) {
+    furi_assert(ctx);
+    const BomberState* bomber_state = ctx;
+
+    furi_mutex_acquire(bomber_state->mutex, FuriWaitForever);
+    if(!BFS()) {
+        init();
+    }
+    canvas_clear(canvas);
+
+    canvas_draw_icon(canvas, world.endx * 10 + 4, world.endy * 10 + 2, &I_end);
+
+    if(world.running) {
+        for(size_t i = 0; i < WorldSizeY; i++) {
+            for(size_t j = 0; j < WorldSizeX; j++) {
+                switch(world.matrix[i][j]) {
+                case 0:
+                    break;
+                case 1:
+                    canvas_draw_icon(canvas, j * 10 + 4, i * 10 + 2, &I_box);
+                    break;
+                case 2:
+                    canvas_draw_icon(canvas, j * 10 + 4, i * 10 + 2, &I_unbreakbox);
+                    break;
+                case 3:
+                    canvas_draw_icon(canvas, j * 10 + 4, i * 10 + 2, &I_bomb0);
+                    break;
+                case 4:
+                    canvas_draw_icon(canvas, j * 10 + 4, i * 10 + 2, &I_bomb1);
+                    break;
+                case 5:
+                    canvas_draw_icon(canvas, j * 10 + 4, i * 10 + 2, &I_bomb2);
+                    break;
+                case 6:
+                    canvas_draw_icon(canvas, j * 10 + 4, i * 10 + 2, &I_explore);
+                    world.matrix[i][j] = 0;
+                    break;
+                }
+            }
+        }
+
+        if(world.player->side) {
+            canvas_draw_icon(
+                canvas, world.player->x * 10 + 4, world.player->y * 10 + 2, &I_playerright);
+        } else {
+            canvas_draw_icon(
+                canvas, world.player->x * 10 + 4, world.player->y * 10 + 2, &I_playerleft);
+        }
+
+        for(int i = 0; i < world.enemies_count; i++) {
+            if(world.enemies[i].level > 0) {
+                canvas_draw_icon(
+                    canvas, world.enemies[i].x * 10 + 4, world.enemies[i].y * 10 + 2, &I_enemy1);
+            } else {
+                if(world.enemies[i].side) {
+                    canvas_draw_icon(
+                        canvas,
+                        world.enemies[i].x * 10 + 4,
+                        world.enemies[i].y * 10 + 2,
+                        &I_enemyright);
+                } else {
+                    canvas_draw_icon(
+                        canvas,
+                        world.enemies[i].x * 10 + 4,
+                        world.enemies[i].y * 10 + 2,
+                        &I_enemyleft);
+                }
+            }
+        }
+    } else {
+        canvas_set_font(canvas, FontPrimary);
+        if(world.player->x == world.endx && world.player->y == world.endy) {
+            if(world.level == 20) {
+                canvas_draw_str(canvas, 30, 35, "You win!");
+            } else {
+                canvas_draw_str(canvas, 30, 35, "Next level!");
+                char str[20];
+                intToStr(world.level, str);
+                canvas_draw_str(canvas, 90, 35, str);
+            }
+
+        } else {
+            canvas_draw_str(canvas, 30, 35, "You died :(");
+        }
+    }
+
+    furi_mutex_release(bomber_state->mutex);
+}
+
+static void input_callback(InputEvent* input_event, void* ctx) {
+    // Проверяем, что контекст не нулевой
+    furi_assert(ctx);
+    FuriMessageQueue* event_queue = ctx;
+
+    furi_message_queue_put(event_queue, input_event, FuriWaitForever);
+}
+
+int32_t bomberduck_app(void* p) {
+    UNUSED(p);
+
+    // Текущее событие типа InputEvent
+    InputEvent event;
+    // Очередь событий на 8 элементов размера InputEvent
+    FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(InputEvent));
+
+    BomberState* bomber_state = malloc(sizeof(BomberState));
+
+    bomber_state->mutex = furi_mutex_alloc(FuriMutexTypeNormal); // Alloc Mutex
+    if(!bomber_state->mutex) {
+        FURI_LOG_E("BomberDuck", "cannot create mutex\r\n");
+        furi_message_queue_free(event_queue);
+        free(bomber_state);
+        return 255;
+    }
+
+    dolphin_deed(DolphinDeedPluginGameStart);
+    // Создаем новый view port
+    ViewPort* view_port = view_port_alloc();
+    // Создаем callback отрисовки, без контекста
+    view_port_draw_callback_set(view_port, draw_callback, bomber_state);
+    // Создаем callback нажатий на клавиши, в качестве контекста передаем
+    // нашу очередь сообщений, чтоб запихивать в неё эти события
+    view_port_input_callback_set(view_port, input_callback, event_queue);
+
+    // Создаем GUI приложения
+    Gui* gui = furi_record_open(RECORD_GUI);
+    // Подключаем view port к GUI в полноэкранном режиме
+    gui_add_view_port(gui, view_port, GuiLayerFullscreen);
+    NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
+    notification_message_block(notification, &sequence_display_backlight_enforce_on);
+
+    init();
+
+    // Бесконечный цикл обработки очереди событий
+    while(1) {
+        if(furi_message_queue_get(event_queue, &event, 100) == FuriStatusOk) {
+            furi_mutex_acquire(bomber_state->mutex, FuriWaitForever);
+            // Если нажата кнопка "назад", то выходим из цикла, а следовательно и из приложения
+
+            if(event.type == InputTypePress) {
+                if(event.key == InputKeyOk) {
+                    if(world.running) {
+                        if(world.matrix[world.player->y][world.player->x] == 0 &&
+                           world.bombs_count < 2) {
+                            notification_message(notification, &bomb2);
+                            world.matrix[world.player->y][world.player->x] = 3;
+                            Bomb bomb = {world.player->x, world.player->y, furi_get_tick()};
+                            world.bombs[world.bombs_count] = bomb;
+                            world.bombs_count++;
+                        }
+                    } else {
+                        init();
+                    }
+                }
+                if(world.running) {
+                    if(event.key == InputKeyUp) {
+                        if(world.player->y > 0 &&
+                           world.matrix[world.player->y - 1][world.player->x] == 0)
+                            world.player->y--;
+                    }
+                    if(event.key == InputKeyDown) {
+                        if(world.player->y < WorldSizeY - 1 &&
+                           world.matrix[world.player->y + 1][world.player->x] == 0)
+                            world.player->y++;
+                    }
+                    if(event.key == InputKeyLeft) {
+                        world.player->side = 0;
+                        if(world.player->x > 0 &&
+                           world.matrix[world.player->y][world.player->x - 1] == 0)
+                            world.player->x--;
+                    }
+                    if(event.key == InputKeyRight) {
+                        world.player->side = 1;
+                        if(world.player->x < WorldSizeX - 1 &&
+                           world.matrix[world.player->y][world.player->x + 1] == 0)
+                            world.player->x++;
+                    }
+                }
+            } else if(event.type == InputTypeLong) {
+                if(event.key == InputKeyBack) {
+                    break;
+                }
+            }
+        }
+        if(world.running) {
+            if(world.player->x == world.endx && world.player->y == world.endy) {
+                notification_message(notification, &end);
+                world.running = 0;
+                world.level += 1;
+                if(world.level % 5 == 0) {
+                    dolphin_deed(DolphinDeedPluginGameWin);
+                }
+            }
+            for(int i = 0; i < world.bombs_count; i++) {
+                if(furi_get_tick() - world.bombs[i].planted >
+                   (unsigned long)max((3000 - world.level * 150), 1000)) {
+                    vibration = false;
+                    world.matrix[world.bombs[i].y][world.bombs[i].x] = 6;
+                    notification_message(notification, &bomb_explore);
+
+                    for(int j = max(0, world.bombs[i].y - BombRange);
+                        j < min(WorldSizeY, world.bombs[i].y + BombRange + 1);
+                        j++) {
+                        if(world.matrix[j][world.bombs[i].x] != 2) {
+                            world.matrix[j][world.bombs[i].x] = 6;
+                            if(j == world.player->y && world.bombs[i].x == world.player->x) {
+                                notification_message(notification, &end);
+                                world.running = 0;
+                            }
+                            for(int e = 0; e < world.enemies_count; e++) {
+                                if(j == world.enemies[e].y &&
+                                   world.bombs[i].x == world.enemies[e].x) {
+                                    if(world.enemies[e].level > 0) {
+                                        world.enemies[e].level--;
+                                    } else {
+                                        for(int l = e; l < world.enemies_count - 1; l++) {
+                                            world.enemies[l] = world.enemies[l + 1];
+                                        }
+                                        world.enemies_count--;
+                                    }
+                                }
+                            }
+                        }
+                    }
+
+                    for(int j = max(0, world.bombs[i].x - BombRange);
+                        j < min(WorldSizeX, world.bombs[i].x + BombRange + 1);
+                        j++) {
+                        if(world.matrix[world.bombs[i].y][j] != 2) {
+                            world.matrix[world.bombs[i].y][j] = 6;
+                            if(world.bombs[i].y == world.player->y && j == world.player->x) {
+                                notification_message(notification, &end);
+                                world.running = 0;
+                            }
+                            for(int e = 0; e < world.enemies_count; e++) {
+                                if(world.bombs[i].y == world.enemies[e].y &&
+                                   j == world.enemies[e].x) {
+                                    if(world.enemies[e].level > 0) {
+                                        world.enemies[e].level--;
+                                    } else {
+                                        for(int l = e; l < world.enemies_count - 1; l++) {
+                                            world.enemies[l] = world.enemies[l + 1];
+                                        }
+                                        world.enemies_count--;
+                                    }
+                                }
+                            }
+                        }
+                    }
+
+                    for(int j = i; j < world.bombs_count - 1; j++) {
+                        world.bombs[j] = world.bombs[j + 1];
+                    }
+                    world.bombs_count--;
+                } else if(
+                    furi_get_tick() - world.bombs[i].planted >
+                        (unsigned long)max((3000 - world.level * 150) * 2 / 3, 666) &&
+                    world.matrix[world.bombs[i].y][world.bombs[i].x] != 5) {
+                    world.matrix[world.bombs[i].y][world.bombs[i].x] = 5;
+                    vibration = true;
+
+                } else if(
+                    furi_get_tick() - world.bombs[i].planted >
+                        (unsigned long)max((3000 - world.level * 150) / 3, 333) &&
+                    world.matrix[world.bombs[i].y][world.bombs[i].x] != 4) {
+                    world.matrix[world.bombs[i].y][world.bombs[i].x] = 4;
+                }
+            }
+            for(int e = 0; e < world.enemies_count; e++) {
+                if(world.player->y == world.enemies[e].y &&
+                   world.player->x == world.enemies[e].x) {
+                    notification_message(notification, &end);
+                    world.running = 0;
+                }
+            }
+
+            for(int e = 0; e < world.enemies_count; e++) {
+                if(world.enemies[e].level > 0) {
+                    if(furi_get_tick() - world.enemies[e].last >
+                       (unsigned long)max((2000 - world.level * 100), 1000)) {
+                        world.enemies[e].last = furi_get_tick();
+                        int move = rand() % 4;
+                        switch(move) {
+                        case 0:
+                            if(world.enemies[e].y > 0 &&
+                               world.matrix[world.enemies[e].y - 1][world.enemies[e].x] != 2)
+                                world.enemies[e].y--;
+                            break;
+                        case 1:
+                            if(world.enemies[e].y < WorldSizeY - 1 &&
+                               world.matrix[world.enemies[e].y + 1][world.enemies[e].x] != 2)
+                                world.enemies[e].y++;
+                            break;
+                        case 2:
+                            world.enemies[e].side = 0;
+                            if(world.enemies[e].x > 0 &&
+                               world.matrix[world.enemies[e].y][world.enemies[e].x - 1] != 2)
+                                world.enemies[e].x--;
+                            break;
+                        case 3:
+                            world.enemies[e].side = 1;
+                            if(world.enemies[e].x < WorldSizeX - 1 &&
+                               world.matrix[world.enemies[e].y][world.enemies[e].x + 1] != 2)
+                                world.enemies[e].x++;
+                        default:
+                            break;
+                        }
+                    }
+                } else {
+                    if(furi_get_tick() - world.enemies[e].last >
+                       (unsigned long)max((1000 - world.level * 50), 500)) {
+                        world.enemies[e].last = furi_get_tick();
+                        int move = rand() % 4;
+                        switch(move) {
+                        case 0:
+                            if(world.enemies[e].y > 0 &&
+                               world.matrix[world.enemies[e].y - 1][world.enemies[e].x] == 0)
+                                world.enemies[e].y--;
+                            break;
+                        case 1:
+                            if(world.enemies[e].y < WorldSizeY - 1 &&
+                               world.matrix[world.enemies[e].y + 1][world.enemies[e].x] == 0)
+                                world.enemies[e].y++;
+                            break;
+                        case 2:
+                            world.enemies[e].side = 0;
+                            if(world.enemies[e].x > 0 &&
+                               world.matrix[world.enemies[e].y][world.enemies[e].x - 1] == 0)
+                                world.enemies[e].x--;
+                            break;
+                        case 3:
+                            world.enemies[e].side = 1;
+                            if(world.enemies[e].x < WorldSizeX - 1 &&
+                               world.matrix[world.enemies[e].y][world.enemies[e].x + 1] == 0)
+                                world.enemies[e].x++;
+                        default:
+                            break;
+                        }
+                    }
+                }
+            }
+            for(int e = 0; e < world.enemies_count; e++) {
+                for(int h = e + 1; h < world.enemies_count; h++) {
+                    if(world.enemies[e].y == world.enemies[h].y &&
+                       world.enemies[e].x == world.enemies[h].x) {
+                        world.enemies[h].level++;
+                        for(int l = e; l < world.enemies_count - 1; l++) {
+                            world.enemies[l] = world.enemies[l + 1];
+                        }
+                        world.enemies_count--;
+                    }
+                }
+            }
+            if(vibration) {
+                notification_message(notification, &vibr1);
+            }
+        }
+
+        view_port_update(view_port);
+        furi_mutex_release(bomber_state->mutex);
+    }
+
+    // Return to normal backlight settings
+    notification_message_block(notification, &sequence_display_backlight_enforce_auto);
+    furi_record_close(RECORD_NOTIFICATION);
+    // Специальная очистка памяти, занимаемой очередью
+    furi_message_queue_free(event_queue);
+
+    // Чистим созданные объекты, связанные с интерфейсом
+    gui_remove_view_port(gui, view_port);
+    view_port_free(view_port);
+
+    furi_mutex_free(bomber_state->mutex);
+    furi_record_close(RECORD_GUI);
+    free(bomber_state);
+
+    return 0;
+}

+ 674 - 0
main_apps_sources/dtmf_dolphin/LICENSE

@@ -0,0 +1,674 @@
+                    GNU GENERAL PUBLIC LICENSE
+                       Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+                            Preamble
+
+  The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+  The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works.  By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users.  We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors.  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+  To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights.  Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received.  You must make sure that they, too, receive
+or can get the source code.  And you must show them these terms so they
+know their rights.
+
+  Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+  For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software.  For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+  Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so.  This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software.  The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable.  Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products.  If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+  Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary.  To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+                       TERMS AND CONDITIONS
+
+  0. Definitions.
+
+  "This License" refers to version 3 of the GNU General Public License.
+
+  "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+  "The Program" refers to any copyrightable work licensed under this
+License.  Each licensee is addressed as "you".  "Licensees" and
+"recipients" may be individuals or organizations.
+
+  To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy.  The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+  A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+  To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy.  Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+  To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies.  Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+  An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License.  If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+  1. Source Code.
+
+  The "source code" for a work means the preferred form of the work
+for making modifications to it.  "Object code" means any non-source
+form of a work.
+
+  A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+  The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form.  A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+  The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities.  However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work.  For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+  The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+  The Corresponding Source for a work in source code form is that
+same work.
+
+  2. Basic Permissions.
+
+  All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met.  This License explicitly affirms your unlimited
+permission to run the unmodified Program.  The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work.  This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+  You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force.  You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright.  Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+  Conveying under any other circumstances is permitted solely under
+the conditions stated below.  Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+  3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+  No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+  When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+  4. Conveying Verbatim Copies.
+
+  You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+  You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+  5. Conveying Modified Source Versions.
+
+  You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+    a) The work must carry prominent notices stating that you modified
+    it, and giving a relevant date.
+
+    b) The work must carry prominent notices stating that it is
+    released under this License and any conditions added under section
+    7.  This requirement modifies the requirement in section 4 to
+    "keep intact all notices".
+
+    c) You must license the entire work, as a whole, under this
+    License to anyone who comes into possession of a copy.  This
+    License will therefore apply, along with any applicable section 7
+    additional terms, to the whole of the work, and all its parts,
+    regardless of how they are packaged.  This License gives no
+    permission to license the work in any other way, but it does not
+    invalidate such permission if you have separately received it.
+
+    d) If the work has interactive user interfaces, each must display
+    Appropriate Legal Notices; however, if the Program has interactive
+    interfaces that do not display Appropriate Legal Notices, your
+    work need not make them do so.
+
+  A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit.  Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+  6. Conveying Non-Source Forms.
+
+  You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+    a) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by the
+    Corresponding Source fixed on a durable physical medium
+    customarily used for software interchange.
+
+    b) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by a
+    written offer, valid for at least three years and valid for as
+    long as you offer spare parts or customer support for that product
+    model, to give anyone who possesses the object code either (1) a
+    copy of the Corresponding Source for all the software in the
+    product that is covered by this License, on a durable physical
+    medium customarily used for software interchange, for a price no
+    more than your reasonable cost of physically performing this
+    conveying of source, or (2) access to copy the
+    Corresponding Source from a network server at no charge.
+
+    c) Convey individual copies of the object code with a copy of the
+    written offer to provide the Corresponding Source.  This
+    alternative is allowed only occasionally and noncommercially, and
+    only if you received the object code with such an offer, in accord
+    with subsection 6b.
+
+    d) Convey the object code by offering access from a designated
+    place (gratis or for a charge), and offer equivalent access to the
+    Corresponding Source in the same way through the same place at no
+    further charge.  You need not require recipients to copy the
+    Corresponding Source along with the object code.  If the place to
+    copy the object code is a network server, the Corresponding Source
+    may be on a different server (operated by you or a third party)
+    that supports equivalent copying facilities, provided you maintain
+    clear directions next to the object code saying where to find the
+    Corresponding Source.  Regardless of what server hosts the
+    Corresponding Source, you remain obligated to ensure that it is
+    available for as long as needed to satisfy these requirements.
+
+    e) Convey the object code using peer-to-peer transmission, provided
+    you inform other peers where the object code and Corresponding
+    Source of the work are being offered to the general public at no
+    charge under subsection 6d.
+
+  A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+  A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling.  In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage.  For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product.  A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+  "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source.  The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+  If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information.  But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+  The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed.  Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+  Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+  7. Additional Terms.
+
+  "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law.  If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+  When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it.  (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.)  You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+  Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+    a) Disclaiming warranty or limiting liability differently from the
+    terms of sections 15 and 16 of this License; or
+
+    b) Requiring preservation of specified reasonable legal notices or
+    author attributions in that material or in the Appropriate Legal
+    Notices displayed by works containing it; or
+
+    c) Prohibiting misrepresentation of the origin of that material, or
+    requiring that modified versions of such material be marked in
+    reasonable ways as different from the original version; or
+
+    d) Limiting the use for publicity purposes of names of licensors or
+    authors of the material; or
+
+    e) Declining to grant rights under trademark law for use of some
+    trade names, trademarks, or service marks; or
+
+    f) Requiring indemnification of licensors and authors of that
+    material by anyone who conveys the material (or modified versions of
+    it) with contractual assumptions of liability to the recipient, for
+    any liability that these contractual assumptions directly impose on
+    those licensors and authors.
+
+  All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10.  If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term.  If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+  If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+  Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+  8. Termination.
+
+  You may not propagate or modify a covered work except as expressly
+provided under this License.  Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+  However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+  Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+  Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License.  If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+  9. Acceptance Not Required for Having Copies.
+
+  You are not required to accept this License in order to receive or
+run a copy of the Program.  Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance.  However,
+nothing other than this License grants you permission to propagate or
+modify any covered work.  These actions infringe copyright if you do
+not accept this License.  Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+  10. Automatic Licensing of Downstream Recipients.
+
+  Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License.  You are not responsible
+for enforcing compliance by third parties with this License.
+
+  An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations.  If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+  You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License.  For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+  11. Patents.
+
+  A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based.  The
+work thus licensed is called the contributor's "contributor version".
+
+  A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version.  For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+  Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+  In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement).  To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+  If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients.  "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+  If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+  A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License.  You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+  Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+  12. No Surrender of Others' Freedom.
+
+  If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all.  For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+  13. Use with the GNU Affero General Public License.
+
+  Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work.  The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+  14. Revised Versions of this License.
+
+  The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+  Each version is given a distinguishing version number.  If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation.  If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+  If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+  Later license versions may give you additional or different
+permissions.  However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+  15. Disclaimer of Warranty.
+
+  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+  16. Limitation of Liability.
+
+  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+  17. Interpretation of Sections 15 and 16.
+
+  If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+                     END OF TERMS AND CONDITIONS
+
+            How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+  If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+    <program>  Copyright (C) <year>  <name of author>
+    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+  You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<https://www.gnu.org/licenses/>.
+
+  The GNU General Public License does not permit incorporating your program
+into proprietary programs.  If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library.  If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.  But first, please read
+<https://www.gnu.org/licenses/why-not-lgpl.html>.

+ 18 - 0
main_apps_sources/dtmf_dolphin/README.md

@@ -0,0 +1,18 @@
+![Image](pics/dialer.jpg)
+
+[Original Link](https://github.com/litui/dtmf_dolphin)
+
+## DTMF Dolphin
+
+DTMF (Dual-Tone Multi-Frequency) dialer, Bluebox, and Redbox.
+
+Now in a release-ready state for both Dialer, Bluebox, and Redbox (US/UK) functionality!
+
+Please note that using the current tone output method, the 2600 tone is scaled about 33 Hz higher than it should be. This is a limitation of the current sample rate.
+
+### Educational Links:
+
+* http://www.phrack.org/issues/25/7.html#article
+* https://en.wikipedia.org/wiki/Dual-tone_multi-frequency_signaling
+* https://en.wikipedia.org/wiki/Blue_box
+* https://en.wikipedia.org/wiki/Red_box_(phreaking)

+ 18 - 0
main_apps_sources/dtmf_dolphin/application.fam

@@ -0,0 +1,18 @@
+App(
+    appid="dtmf_dolphin",
+    name="DTMF Dolphin",
+    apptype=FlipperAppType.EXTERNAL,
+    entry_point="dtmf_dolphin_app",
+    requires=[
+        "storage",
+        "gui",
+        "dialogs",
+    ],
+    fap_icon="phone.png",
+    stack_size=8 * 1024,
+    order=20,
+    fap_category="Tools",
+    fap_author="@litui & @xMasterX",
+    fap_version="1.0",
+    fap_description="DTMF (Dual-Tone Multi-Frequency) dialer, Bluebox, and Redbox.",
+)

+ 89 - 0
main_apps_sources/dtmf_dolphin/dtmf_dolphin.c

@@ -0,0 +1,89 @@
+#include "dtmf_dolphin_i.h"
+
+#include <furi.h>
+#include <furi_hal.h>
+
+static bool dtmf_dolphin_app_custom_event_callback(void* context, uint32_t event) {
+    furi_assert(context);
+    DTMFDolphinApp* app = context;
+    return scene_manager_handle_custom_event(app->scene_manager, event);
+}
+
+static bool dtmf_dolphin_app_back_event_callback(void* context) {
+    furi_assert(context);
+    DTMFDolphinApp* app = context;
+    return scene_manager_handle_back_event(app->scene_manager);
+}
+
+static void dtmf_dolphin_app_tick_event_callback(void* context) {
+    furi_assert(context);
+    DTMFDolphinApp* app = context;
+
+    scene_manager_handle_tick_event(app->scene_manager);
+}
+
+static DTMFDolphinApp* app_alloc() {
+    DTMFDolphinApp* app = malloc(sizeof(DTMFDolphinApp));
+
+    app->gui = furi_record_open(RECORD_GUI);
+    app->view_dispatcher = view_dispatcher_alloc();
+    app->scene_manager = scene_manager_alloc(&dtmf_dolphin_scene_handlers, app);
+    view_dispatcher_enable_queue(app->view_dispatcher);
+    view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
+
+    view_dispatcher_set_custom_event_callback(
+        app->view_dispatcher, dtmf_dolphin_app_custom_event_callback);
+    view_dispatcher_set_navigation_event_callback(
+        app->view_dispatcher, dtmf_dolphin_app_back_event_callback);
+    view_dispatcher_set_tick_event_callback(
+        app->view_dispatcher, dtmf_dolphin_app_tick_event_callback, 100);
+
+    view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
+
+    app->main_menu_list = variable_item_list_alloc();
+    view_dispatcher_add_view(
+        app->view_dispatcher,
+        DTMFDolphinViewMainMenu,
+        variable_item_list_get_view(app->main_menu_list));
+
+    app->dtmf_dolphin_dialer = dtmf_dolphin_dialer_alloc();
+    view_dispatcher_add_view(
+        app->view_dispatcher,
+        DTMFDolphinViewDialer,
+        dtmf_dolphin_dialer_get_view(app->dtmf_dolphin_dialer));
+
+    app->notification = furi_record_open(RECORD_NOTIFICATION);
+    notification_message(app->notification, &sequence_display_backlight_enforce_on);
+
+    scene_manager_next_scene(app->scene_manager, DTMFDolphinSceneStart);
+
+    return app;
+}
+
+static void app_free(DTMFDolphinApp* app) {
+    furi_assert(app);
+    view_dispatcher_remove_view(app->view_dispatcher, DTMFDolphinViewMainMenu);
+    view_dispatcher_remove_view(app->view_dispatcher, DTMFDolphinViewDialer);
+    variable_item_list_free(app->main_menu_list);
+
+    dtmf_dolphin_dialer_free(app->dtmf_dolphin_dialer);
+
+    view_dispatcher_free(app->view_dispatcher);
+    scene_manager_free(app->scene_manager);
+
+    notification_message(app->notification, &sequence_display_backlight_enforce_auto);
+
+    furi_record_close(RECORD_GUI);
+    furi_record_close(RECORD_NOTIFICATION);
+    free(app);
+}
+
+int32_t dtmf_dolphin_app(void* p) {
+    UNUSED(p);
+    DTMFDolphinApp* app = app_alloc();
+
+    view_dispatcher_run(app->view_dispatcher);
+
+    app_free(app);
+    return 0;
+}

+ 270 - 0
main_apps_sources/dtmf_dolphin/dtmf_dolphin_audio.c

@@ -0,0 +1,270 @@
+#include "dtmf_dolphin_audio.h"
+
+DTMFDolphinAudio* current_player;
+
+static void dtmf_dolphin_audio_dma_isr(void* ctx) {
+    FuriMessageQueue* event_queue = ctx;
+
+    if(LL_DMA_IsActiveFlag_HT1(DMA1)) {
+        LL_DMA_ClearFlag_HT1(DMA1);
+
+        DTMFDolphinCustomEvent event = {.type = DTMFDolphinEventDMAHalfTransfer};
+        furi_message_queue_put(event_queue, &event, 0);
+    }
+
+    if(LL_DMA_IsActiveFlag_TC1(DMA1)) {
+        LL_DMA_ClearFlag_TC1(DMA1);
+
+        DTMFDolphinCustomEvent event = {.type = DTMFDolphinEventDMAFullTransfer};
+        furi_message_queue_put(event_queue, &event, 0);
+    }
+}
+
+void dtmf_dolphin_audio_clear_samples(DTMFDolphinAudio* player) {
+    for(size_t i = 0; i < player->buffer_length; i++) {
+        player->sample_buffer[i] = 0;
+    }
+}
+
+DTMFDolphinOsc* dtmf_dolphin_osc_alloc() {
+    DTMFDolphinOsc* osc = malloc(sizeof(DTMFDolphinOsc));
+    osc->cached_freq = 0;
+    osc->offset = 0;
+    osc->period = 0;
+    osc->lookup_table = NULL;
+    return osc;
+}
+
+DTMFDolphinPulseFilter* dtmf_dolphin_pulse_filter_alloc() {
+    DTMFDolphinPulseFilter* pf = malloc(sizeof(DTMFDolphinPulseFilter));
+    pf->duration = 0;
+    pf->period = 0;
+    pf->offset = 0;
+    pf->lookup_table = NULL;
+    return pf;
+}
+
+DTMFDolphinAudio* dtmf_dolphin_audio_alloc() {
+    DTMFDolphinAudio* player = malloc(sizeof(DTMFDolphinAudio));
+    player->buffer_length = SAMPLE_BUFFER_LENGTH;
+    player->half_buffer_length = SAMPLE_BUFFER_LENGTH / 2;
+    player->sample_buffer = malloc(sizeof(uint16_t) * player->buffer_length);
+    player->osc1 = dtmf_dolphin_osc_alloc();
+    player->osc2 = dtmf_dolphin_osc_alloc();
+    player->volume = 1.0f;
+    player->queue = furi_message_queue_alloc(10, sizeof(DTMFDolphinCustomEvent));
+    player->filter = dtmf_dolphin_pulse_filter_alloc();
+    player->playing = false;
+    dtmf_dolphin_audio_clear_samples(player);
+
+    return player;
+}
+
+size_t calc_waveform_period(float freq) {
+    if(!freq) {
+        return 0;
+    }
+    // DMA Rate calculation, thanks to Dr_Zlo
+    float dma_rate = CPU_CLOCK_FREQ / 2 / DTMF_DOLPHIN_HAL_DMA_PRESCALER /
+                     (DTMF_DOLPHIN_HAL_DMA_AUTORELOAD + 1);
+
+    // Using a constant scaling modifier, which likely represents
+    // the combined system overhead and isr latency.
+    return (uint16_t)dma_rate * 2 / freq * 0.801923;
+}
+
+void osc_generate_lookup_table(DTMFDolphinOsc* osc, float freq) {
+    if(osc->lookup_table != NULL) {
+        free(osc->lookup_table);
+    }
+    osc->offset = 0;
+    osc->cached_freq = freq;
+    osc->period = calc_waveform_period(freq);
+    if(!osc->period) {
+        osc->lookup_table = NULL;
+        return;
+    }
+    osc->lookup_table = malloc(sizeof(float) * osc->period);
+
+    for(size_t i = 0; i < osc->period; i++) {
+        osc->lookup_table[i] = sin(i * PERIOD_2_PI / osc->period) + 1;
+    }
+}
+
+void filter_generate_lookup_table(
+    DTMFDolphinPulseFilter* pf,
+    uint16_t pulses,
+    uint16_t pulse_ms,
+    uint16_t gap_ms) {
+    if(pf->lookup_table != NULL) {
+        free(pf->lookup_table);
+    }
+    pf->offset = 0;
+
+    uint16_t gap_period = calc_waveform_period(1000 / (float)gap_ms);
+    uint16_t pulse_period = calc_waveform_period(1000 / (float)pulse_ms);
+    pf->period = pulse_period + gap_period;
+
+    if(!pf->period) {
+        pf->lookup_table = NULL;
+        return;
+    }
+    pf->duration = pf->period * pulses;
+    pf->lookup_table = malloc(sizeof(bool) * pf->duration);
+
+    for(size_t i = 0; i < pf->duration; i++) {
+        pf->lookup_table[i] = i % pf->period < pulse_period;
+    }
+}
+
+float sample_frame(DTMFDolphinOsc* osc) {
+    float frame = 0.0;
+
+    if(osc->period) {
+        frame = osc->lookup_table[osc->offset];
+        osc->offset = (osc->offset + 1) % osc->period;
+    }
+
+    return frame;
+}
+
+bool sample_filter(DTMFDolphinPulseFilter* pf) {
+    bool frame = true;
+
+    if(pf->duration) {
+        if(pf->offset < pf->duration) {
+            frame = pf->lookup_table[pf->offset];
+            pf->offset = pf->offset + 1;
+        } else {
+            frame = false;
+        }
+    }
+
+    return frame;
+}
+
+void dtmf_dolphin_osc_free(DTMFDolphinOsc* osc) {
+    if(osc->lookup_table != NULL) {
+        free(osc->lookup_table);
+    }
+    free(osc);
+}
+
+void dtmf_dolphin_filter_free(DTMFDolphinPulseFilter* pf) {
+    if(pf->lookup_table != NULL) {
+        free(pf->lookup_table);
+    }
+    free(pf);
+}
+
+void dtmf_dolphin_audio_free(DTMFDolphinAudio* player) {
+    furi_message_queue_free(player->queue);
+    dtmf_dolphin_osc_free(player->osc1);
+    dtmf_dolphin_osc_free(player->osc2);
+    dtmf_dolphin_filter_free(player->filter);
+    free(player->sample_buffer);
+    free(player);
+    current_player = NULL;
+}
+
+bool generate_waveform(DTMFDolphinAudio* player, uint16_t buffer_index) {
+    uint16_t* sample_buffer_start = &player->sample_buffer[buffer_index];
+
+    for(size_t i = 0; i < player->half_buffer_length; i++) {
+        float data = 0;
+        if(player->osc2->period) {
+            data = (sample_frame(player->osc1) / 2) + (sample_frame(player->osc2) / 2);
+        } else {
+            data = (sample_frame(player->osc1));
+        }
+        data *= sample_filter(player->filter) ? player->volume : 0.0;
+        data *= UINT8_MAX / 2; // scale -128..127
+        data += UINT8_MAX / 2; // to unsigned
+
+        if(data < 0) {
+            data = 0;
+        }
+
+        if(data > 255) {
+            data = 255;
+        }
+
+        sample_buffer_start[i] = data;
+    }
+
+    return true;
+}
+
+bool dtmf_dolphin_audio_play_tones(
+    float freq1,
+    float freq2,
+    uint16_t pulses,
+    uint16_t pulse_ms,
+    uint16_t gap_ms) {
+    if(current_player != NULL && current_player->playing) {
+        // Cannot start playing while still playing something else
+        return false;
+    }
+    current_player = dtmf_dolphin_audio_alloc();
+
+    osc_generate_lookup_table(current_player->osc1, freq1);
+    osc_generate_lookup_table(current_player->osc2, freq2);
+    filter_generate_lookup_table(current_player->filter, pulses, pulse_ms, gap_ms);
+
+    generate_waveform(current_player, 0);
+    generate_waveform(current_player, current_player->half_buffer_length);
+
+    dtmf_dolphin_dma_init((uint32_t)current_player->sample_buffer, current_player->buffer_length);
+
+    furi_hal_interrupt_set_isr(
+        FuriHalInterruptIdDma1Ch1, dtmf_dolphin_audio_dma_isr, current_player->queue);
+    if(furi_hal_speaker_acquire(1000)) {
+        dtmf_dolphin_speaker_init();
+        dtmf_dolphin_dma_start();
+        dtmf_dolphin_speaker_start();
+        current_player->playing = true;
+        return true;
+    } else {
+        current_player->playing = false;
+        return false;
+    }
+}
+
+bool dtmf_dolphin_audio_stop_tones() {
+    if(current_player != NULL && !current_player->playing) {
+        // Can't stop a player that isn't playing.
+        return false;
+    }
+    while(current_player->filter->offset > 0 &&
+          current_player->filter->offset < current_player->filter->duration) {
+        // run remaining ticks if needed to complete filter sequence
+        dtmf_dolphin_audio_handle_tick();
+    }
+    dtmf_dolphin_speaker_stop();
+    dtmf_dolphin_dma_stop();
+    furi_hal_speaker_release();
+
+    furi_hal_interrupt_set_isr(FuriHalInterruptIdDma1Ch1, NULL, NULL);
+
+    dtmf_dolphin_audio_free(current_player);
+
+    return true;
+}
+
+bool dtmf_dolphin_audio_handle_tick() {
+    bool handled = false;
+
+    if(current_player) {
+        DTMFDolphinCustomEvent event;
+        if(furi_message_queue_get(current_player->queue, &event, 250) == FuriStatusOk) {
+            if(event.type == DTMFDolphinEventDMAHalfTransfer) {
+                generate_waveform(current_player, 0);
+                handled = true;
+            } else if(event.type == DTMFDolphinEventDMAFullTransfer) {
+                generate_waveform(current_player, current_player->half_buffer_length);
+                handled = true;
+            }
+        }
+    }
+    return handled;
+}

+ 54 - 0
main_apps_sources/dtmf_dolphin/dtmf_dolphin_audio.h

@@ -0,0 +1,54 @@
+#pragma once
+// #include "dtmf_dolphin_i.h"
+#include "dtmf_dolphin_event.h"
+#include "dtmf_dolphin_hal.h"
+
+#define SAMPLE_BUFFER_LENGTH 8192
+#define PERIOD_2_PI 6.2832
+#define CPU_CLOCK_FREQ 64000000
+
+typedef struct {
+    float cached_freq;
+    size_t period;
+    float* lookup_table;
+    uint16_t offset;
+} DTMFDolphinOsc;
+
+typedef struct {
+    float duration;
+    size_t period;
+    bool* lookup_table;
+    uint16_t offset;
+} DTMFDolphinPulseFilter;
+
+typedef struct {
+    size_t buffer_length;
+    size_t half_buffer_length;
+    uint8_t* buffer_buffer;
+    uint16_t* sample_buffer;
+    float volume;
+    FuriMessageQueue* queue;
+    DTMFDolphinOsc* osc1;
+    DTMFDolphinOsc* osc2;
+    DTMFDolphinPulseFilter* filter;
+    bool playing;
+} DTMFDolphinAudio;
+
+DTMFDolphinOsc* dtmf_dolphin_osc_alloc();
+
+DTMFDolphinAudio* dtmf_dolphin_audio_alloc();
+
+void dtmf_dolphin_audio_free(DTMFDolphinAudio* player);
+
+void dtmf_dolphin_osc_free(DTMFDolphinOsc* osc);
+
+bool dtmf_dolphin_audio_play_tones(
+    float freq1,
+    float freq2,
+    uint16_t pulses,
+    uint16_t pulse_ms,
+    uint16_t gap_ms);
+
+bool dtmf_dolphin_audio_stop_tones();
+
+bool dtmf_dolphin_audio_handle_tick();

+ 220 - 0
main_apps_sources/dtmf_dolphin/dtmf_dolphin_data.c

@@ -0,0 +1,220 @@
+#include "dtmf_dolphin_data.h"
+
+typedef struct {
+    const uint8_t row;
+    const uint8_t col;
+    const uint8_t span;
+} DTMFDolphinTonePos;
+
+typedef struct {
+    const char* name;
+    const float frequency_1;
+    const float frequency_2;
+    const DTMFDolphinTonePos pos;
+    const uint16_t pulses; // for Redbox
+    const uint16_t pulse_ms; // for Redbox
+    const uint16_t gap_duration; // for Redbox
+} DTMFDolphinTones;
+
+typedef struct {
+    const char* name;
+    DTMFDolphinToneSection block;
+    uint8_t tone_count;
+    DTMFDolphinTones tones[DTMF_DOLPHIN_MAX_TONE_COUNT];
+} DTMFDolphinSceneData;
+
+DTMFDolphinSceneData DTMFDolphinSceneDataDialer = {
+    .name = "Dialer",
+    .block = DTMF_DOLPHIN_TONE_BLOCK_DIALER,
+    .tone_count = 16,
+    .tones = {
+        {"1", 697.0, 1209.0, {0, 0, 1}, 0, 0, 0},
+        {"2", 697.0, 1336.0, {0, 1, 1}, 0, 0, 0},
+        {"3", 697.0, 1477.0, {0, 2, 1}, 0, 0, 0},
+        {"A", 697.0, 1633.0, {0, 3, 1}, 0, 0, 0},
+        {"4", 770.0, 1209.0, {1, 0, 1}, 0, 0, 0},
+        {"5", 770.0, 1336.0, {1, 1, 1}, 0, 0, 0},
+        {"6", 770.0, 1477.0, {1, 2, 1}, 0, 0, 0},
+        {"B", 770.0, 1633.0, {1, 3, 1}, 0, 0, 0},
+        {"7", 852.0, 1209.0, {2, 0, 1}, 0, 0, 0},
+        {"8", 852.0, 1336.0, {2, 1, 1}, 0, 0, 0},
+        {"9", 852.0, 1477.0, {2, 2, 1}, 0, 0, 0},
+        {"C", 852.0, 1633.0, {2, 3, 1}, 0, 0, 0},
+        {"*", 941.0, 1209.0, {3, 0, 1}, 0, 0, 0},
+        {"0", 941.0, 1336.0, {3, 1, 1}, 0, 0, 0},
+        {"#", 941.0, 1477.0, {3, 2, 1}, 0, 0, 0},
+        {"D", 941.0, 1633.0, {3, 3, 1}, 0, 0, 0},
+    }};
+
+DTMFDolphinSceneData DTMFDolphinSceneDataBluebox = {
+    .name = "Bluebox",
+    .block = DTMF_DOLPHIN_TONE_BLOCK_BLUEBOX,
+    .tone_count = 13,
+    .tones = {
+        {"1", 700.0, 900.0, {0, 0, 1}, 0, 0, 0},
+        {"2", 700.0, 1100.0, {0, 1, 1}, 0, 0, 0},
+        {"3", 900.0, 1100.0, {0, 2, 1}, 0, 0, 0},
+        {"4", 700.0, 1300.0, {1, 0, 1}, 0, 0, 0},
+        {"5", 900.0, 1300.0, {1, 1, 1}, 0, 0, 0},
+        {"6", 1100.0, 1300.0, {1, 2, 1}, 0, 0, 0},
+        {"7", 700.0, 1500.0, {2, 0, 1}, 0, 0, 0},
+        {"8", 900.0, 1500.0, {2, 1, 1}, 0, 0, 0},
+        {"9", 1100.0, 1500.0, {2, 2, 1}, 0, 0, 0},
+        {"0", 1300.0, 1500.0, {3, 1, 1}, 0, 0, 0},
+        {"KP", 1100.0, 1700.0, {0, 3, 2}, 0, 0, 0},
+        {"ST", 1500.0, 1700.0, {1, 3, 2}, 0, 0, 0},
+        {"2600", 2600.0, 0.0, {3, 2, 3}, 0, 0, 0},
+    }};
+
+DTMFDolphinSceneData DTMFDolphinSceneDataRedboxUS = {
+    .name = "Redbox (US)",
+    .block = DTMF_DOLPHIN_TONE_BLOCK_REDBOX_US,
+    .tone_count = 4,
+    .tones = {
+        {"Nickel", 1700.0, 2200.0, {0, 0, 5}, 1, 66, 0},
+        {"Dime", 1700.0, 2200.0, {1, 0, 5}, 2, 66, 66},
+        {"Quarter", 1700.0, 2200.0, {2, 0, 5}, 5, 33, 33},
+        {"Dollar", 1700.0, 2200.0, {3, 0, 5}, 1, 650, 0},
+    }};
+
+DTMFDolphinSceneData DTMFDolphinSceneDataRedboxCA = {
+    .name = "Redbox (CA)",
+    .block = DTMF_DOLPHIN_TONE_BLOCK_REDBOX_CA,
+    .tone_count = 3,
+    .tones = {
+        {"Nickel", 2200.0, 0.0, {0, 0, 5}, 1, 66, 0},
+        {"Dime", 2200.0, 0.0, {1, 0, 5}, 2, 66, 66},
+        {"Quarter", 2200.0, 0.0, {2, 0, 5}, 5, 33, 33},
+    }};
+
+DTMFDolphinSceneData DTMFDolphinSceneDataRedboxUK = {
+    .name = "Redbox (UK)",
+    .block = DTMF_DOLPHIN_TONE_BLOCK_REDBOX_UK,
+    .tone_count = 2,
+    .tones = {
+        {"10p", 1000.0, 0.0, {0, 0, 5}, 1, 200, 0},
+        {"50p", 1000.0, 0.0, {1, 0, 5}, 1, 350, 0},
+    }};
+
+DTMFDolphinSceneData DTMFDolphinSceneDataMisc = {
+    .name = "Misc",
+    .block = DTMF_DOLPHIN_TONE_BLOCK_MISC,
+    .tone_count = 3,
+    .tones = {
+        {"CCITT 11", 700.0, 1700.0, {0, 0, 5}, 0, 0, 0},
+        {"CCITT 12", 900.0, 1700.0, {1, 0, 5}, 0, 0, 0},
+        {"CCITT KP2", 1300.0, 1700.0, {2, 0, 5}, 0, 0, 0},
+    }};
+
+DTMFDolphinToneSection current_section;
+DTMFDolphinSceneData* current_scene_data;
+
+void dtmf_dolphin_data_set_current_section(DTMFDolphinToneSection section) {
+    current_section = section;
+
+    switch(current_section) {
+    case DTMF_DOLPHIN_TONE_BLOCK_BLUEBOX:
+        current_scene_data = &DTMFDolphinSceneDataBluebox;
+        break;
+    case DTMF_DOLPHIN_TONE_BLOCK_REDBOX_US:
+        current_scene_data = &DTMFDolphinSceneDataRedboxUS;
+        break;
+    case DTMF_DOLPHIN_TONE_BLOCK_REDBOX_CA:
+        current_scene_data = &DTMFDolphinSceneDataRedboxCA;
+        break;
+    case DTMF_DOLPHIN_TONE_BLOCK_REDBOX_UK:
+        current_scene_data = &DTMFDolphinSceneDataRedboxUK;
+        break;
+    case DTMF_DOLPHIN_TONE_BLOCK_MISC:
+        current_scene_data = &DTMFDolphinSceneDataMisc;
+        break;
+    default: // DTMF_DOLPHIN_TONE_BLOCK_DIALER:
+        current_scene_data = &DTMFDolphinSceneDataDialer;
+        break;
+    }
+}
+
+DTMFDolphinToneSection dtmf_dolphin_data_get_current_section() {
+    return current_section;
+}
+
+DTMFDolphinSceneData* dtmf_dolphin_data_get_current_scene_data() {
+    return current_scene_data;
+}
+
+bool dtmf_dolphin_data_get_tone_frequencies(float* freq1, float* freq2, uint8_t row, uint8_t col) {
+    for(size_t i = 0; i < current_scene_data->tone_count; i++) {
+        DTMFDolphinTones tones = current_scene_data->tones[i];
+        if(tones.pos.row == row && tones.pos.col == col) {
+            freq1[0] = tones.frequency_1;
+            freq2[0] = tones.frequency_2;
+            return true;
+        }
+    }
+    return false;
+}
+
+bool dtmf_dolphin_data_get_filter_data(
+    uint16_t* pulses,
+    uint16_t* pulse_ms,
+    uint16_t* gap_ms,
+    uint8_t row,
+    uint8_t col) {
+    for(size_t i = 0; i < current_scene_data->tone_count; i++) {
+        DTMFDolphinTones tones = current_scene_data->tones[i];
+        if(tones.pos.row == row && tones.pos.col == col) {
+            pulses[0] = tones.pulses;
+            pulse_ms[0] = tones.pulse_ms;
+            gap_ms[0] = tones.gap_duration;
+            return true;
+        }
+    }
+    return false;
+}
+
+const char* dtmf_dolphin_data_get_tone_name(uint8_t row, uint8_t col) {
+    for(size_t i = 0; i < current_scene_data->tone_count; i++) {
+        DTMFDolphinTones tones = current_scene_data->tones[i];
+        if(tones.pos.row == row && tones.pos.col == col) {
+            return tones.name;
+        }
+    }
+    return NULL;
+}
+
+const char* dtmf_dolphin_data_get_current_section_name() {
+    if(current_scene_data) {
+        return current_scene_data->name;
+    }
+    return NULL;
+}
+
+void dtmf_dolphin_tone_get_max_pos(uint8_t* max_rows, uint8_t* max_cols, uint8_t* max_span) {
+    max_rows[0] = 0;
+    max_cols[0] = 0;
+    max_span[0] = 0;
+    uint8_t tmp_rowspan[5] = {0, 0, 0, 0, 0};
+    for(size_t i = 0; i < current_scene_data->tone_count; i++) {
+        DTMFDolphinTones tones = current_scene_data->tones[i];
+        if(tones.pos.row > max_rows[0]) {
+            max_rows[0] = tones.pos.row;
+        }
+        if(tones.pos.col > max_cols[0]) {
+            max_cols[0] = tones.pos.col;
+        }
+        tmp_rowspan[tones.pos.row] += tones.pos.span;
+        if(tmp_rowspan[tones.pos.row] > max_span[0]) max_span[0] = tmp_rowspan[tones.pos.row];
+    }
+    max_rows[0]++;
+    max_cols[0]++;
+}
+
+uint8_t dtmf_dolphin_get_tone_span(uint8_t row, uint8_t col) {
+    for(size_t i = 0; i < current_scene_data->tone_count; i++) {
+        DTMFDolphinTones tones = current_scene_data->tones[i];
+        if(tones.pos.row == row && tones.pos.col == col) {
+            return tones.pos.span;
+        }
+    }
+    return 0;
+}

+ 36 - 0
main_apps_sources/dtmf_dolphin/dtmf_dolphin_data.h

@@ -0,0 +1,36 @@
+#pragma once
+#include <stddef.h>
+#include <stdint.h>
+#include <stdbool.h>
+
+#define DTMF_DOLPHIN_MAX_TONE_COUNT 16
+
+typedef enum {
+    DTMF_DOLPHIN_TONE_BLOCK_DIALER,
+    DTMF_DOLPHIN_TONE_BLOCK_BLUEBOX,
+    DTMF_DOLPHIN_TONE_BLOCK_REDBOX_US,
+    DTMF_DOLPHIN_TONE_BLOCK_REDBOX_UK,
+    DTMF_DOLPHIN_TONE_BLOCK_REDBOX_CA,
+    DTMF_DOLPHIN_TONE_BLOCK_MISC,
+} DTMFDolphinToneSection;
+
+void dtmf_dolphin_data_set_current_section(DTMFDolphinToneSection section);
+
+DTMFDolphinToneSection dtmf_dolphin_data_get_current_section();
+
+bool dtmf_dolphin_data_get_tone_frequencies(float* freq1, float* freq2, uint8_t row, uint8_t col);
+
+bool dtmf_dolphin_data_get_filter_data(
+    uint16_t* pulses,
+    uint16_t* pulse_ms,
+    uint16_t* gap_ms,
+    uint8_t row,
+    uint8_t col);
+
+const char* dtmf_dolphin_data_get_tone_name(uint8_t row, uint8_t col);
+
+const char* dtmf_dolphin_data_get_current_section_name();
+
+void dtmf_dolphin_tone_get_max_pos(uint8_t* max_rows, uint8_t* max_cols, uint8_t* max_span);
+
+uint8_t dtmf_dolphin_get_tone_span(uint8_t row, uint8_t col);

+ 21 - 0
main_apps_sources/dtmf_dolphin/dtmf_dolphin_event.h

@@ -0,0 +1,21 @@
+#pragma once
+
+typedef enum {
+    DTMFDolphinEventVolumeUp = 0,
+    DTMFDolphinEventVolumeDown,
+    DTMFDolphinDialerOkCB,
+    DTMFDolphinEventStartDialer,
+    DTMFDolphinEventStartBluebox,
+    DTMFDolphinEventStartRedboxUS,
+    DTMFDolphinEventStartRedboxUK,
+    DTMFDolphinEventStartRedboxCA,
+    DTMFDolphinEventStartMisc,
+    DTMFDolphinEventPlayTones,
+    DTMFDolphinEventStopTones,
+    DTMFDolphinEventDMAHalfTransfer,
+    DTMFDolphinEventDMAFullTransfer,
+} DTMFDolphinEvent;
+
+typedef struct {
+    DTMFDolphinEvent type;
+} DTMFDolphinCustomEvent;

+ 52 - 0
main_apps_sources/dtmf_dolphin/dtmf_dolphin_hal.c

@@ -0,0 +1,52 @@
+#include "dtmf_dolphin_hal.h"
+
+void dtmf_dolphin_speaker_init() {
+    LL_TIM_InitTypeDef TIM_InitStruct = {0};
+    TIM_InitStruct.Prescaler = DTMF_DOLPHIN_HAL_DMA_PRESCALER;
+    TIM_InitStruct.Autoreload = DTMF_DOLPHIN_HAL_DMA_AUTORELOAD;
+    LL_TIM_Init(FURI_HAL_SPEAKER_TIMER, &TIM_InitStruct);
+
+    LL_TIM_OC_InitTypeDef TIM_OC_InitStruct = {0};
+    TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_PWM1;
+    TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_ENABLE;
+    TIM_OC_InitStruct.CompareValue = 127;
+    LL_TIM_OC_Init(FURI_HAL_SPEAKER_TIMER, FURI_HAL_SPEAKER_CHANNEL, &TIM_OC_InitStruct);
+}
+
+void dtmf_dolphin_speaker_start() {
+    LL_TIM_EnableAllOutputs(FURI_HAL_SPEAKER_TIMER);
+    LL_TIM_EnableCounter(FURI_HAL_SPEAKER_TIMER);
+}
+
+void dtmf_dolphin_speaker_stop() {
+    LL_TIM_DisableAllOutputs(FURI_HAL_SPEAKER_TIMER);
+    LL_TIM_DisableCounter(FURI_HAL_SPEAKER_TIMER);
+}
+
+void dtmf_dolphin_dma_init(uint32_t address, size_t size) {
+    uint32_t dma_dst = (uint32_t) & (FURI_HAL_SPEAKER_TIMER->CCR1);
+
+    LL_DMA_ConfigAddresses(DMA_INSTANCE, address, dma_dst, LL_DMA_DIRECTION_MEMORY_TO_PERIPH);
+    LL_DMA_SetDataLength(DMA_INSTANCE, size);
+
+    LL_DMA_SetPeriphRequest(DMA_INSTANCE, LL_DMAMUX_REQ_TIM16_UP);
+    LL_DMA_SetDataTransferDirection(DMA_INSTANCE, LL_DMA_DIRECTION_MEMORY_TO_PERIPH);
+    LL_DMA_SetChannelPriorityLevel(DMA_INSTANCE, LL_DMA_PRIORITY_VERYHIGH);
+    LL_DMA_SetMode(DMA_INSTANCE, LL_DMA_MODE_CIRCULAR);
+    LL_DMA_SetPeriphIncMode(DMA_INSTANCE, LL_DMA_PERIPH_NOINCREMENT);
+    LL_DMA_SetMemoryIncMode(DMA_INSTANCE, LL_DMA_MEMORY_INCREMENT);
+    LL_DMA_SetPeriphSize(DMA_INSTANCE, LL_DMA_PDATAALIGN_HALFWORD);
+    LL_DMA_SetMemorySize(DMA_INSTANCE, LL_DMA_MDATAALIGN_HALFWORD);
+
+    LL_DMA_EnableIT_TC(DMA_INSTANCE);
+    LL_DMA_EnableIT_HT(DMA_INSTANCE);
+}
+
+void dtmf_dolphin_dma_start() {
+    LL_DMA_EnableChannel(DMA_INSTANCE);
+    LL_TIM_EnableDMAReq_UPDATE(FURI_HAL_SPEAKER_TIMER);
+}
+
+void dtmf_dolphin_dma_stop() {
+    LL_DMA_DisableChannel(DMA_INSTANCE);
+}

+ 33 - 0
main_apps_sources/dtmf_dolphin/dtmf_dolphin_hal.h

@@ -0,0 +1,33 @@
+#pragma once
+#include <furi.h>
+#include <furi_hal.h>
+#include <stm32wb55xx.h>
+#include <stm32wbxx_ll_tim.h>
+#include <stm32wbxx_ll_dma.h>
+
+#define FURI_HAL_SPEAKER_TIMER TIM16
+#define FURI_HAL_SPEAKER_CHANNEL LL_TIM_CHANNEL_CH1
+#define DMA_INSTANCE DMA1, LL_DMA_CHANNEL_1
+
+#define DTMF_DOLPHIN_HAL_DMA_PRESCALER 4
+#define DTMF_DOLPHIN_HAL_DMA_AUTORELOAD 255
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void dtmf_dolphin_speaker_init();
+
+void dtmf_dolphin_speaker_start();
+
+void dtmf_dolphin_speaker_stop();
+
+void dtmf_dolphin_dma_init(uint32_t address, size_t size);
+
+void dtmf_dolphin_dma_start();
+
+void dtmf_dolphin_dma_stop();
+
+#ifdef __cplusplus
+}
+#endif

+ 42 - 0
main_apps_sources/dtmf_dolphin/dtmf_dolphin_i.h

@@ -0,0 +1,42 @@
+#pragma once
+
+#include "scenes/dtmf_dolphin_scene.h"
+
+#include <gui/gui.h>
+#include <gui/view_dispatcher.h>
+#include <gui/scene_manager.h>
+// #include <gui/modules/submenu.h>
+// #include <gui/modules/widget.h>
+#include <gui/modules/variable_item_list.h>
+#include <notification/notification_messages.h>
+#include <input/input.h>
+
+#include "dtmf_dolphin_event.h"
+
+#include "views/dtmf_dolphin_dialer.h"
+
+#define TAG "DTMFDolphin"
+
+enum DTMFDolphinSceneState {
+    DTMFDolphinSceneStateDialer,
+    DTMFDolphinSceneStateBluebox,
+    DTMFDolphinSceneStateRedboxUS,
+    DTMFDolphinSceneStateRedboxUK,
+    DTMFDolphinSceneStateRedboxCA,
+    DTMFDolphinSceneStateMisc,
+};
+
+typedef struct {
+    ViewDispatcher* view_dispatcher;
+    SceneManager* scene_manager;
+    VariableItemList* main_menu_list;
+    DTMFDolphinDialer* dtmf_dolphin_dialer;
+
+    Gui* gui;
+    // ButtonPanel* dialer_button_panel;
+    // ButtonPanel* bluebox_button_panel;
+    // ButtonPanel* redbox_button_panel;
+    NotificationApp* notification;
+} DTMFDolphinApp;
+
+typedef enum { DTMFDolphinViewMainMenu, DTMFDolphinViewDialer } DTMFDolphinView;

BIN
main_apps_sources/dtmf_dolphin/phone.png


BIN
main_apps_sources/dtmf_dolphin/pics/dialer.jpg


+ 30 - 0
main_apps_sources/dtmf_dolphin/scenes/dtmf_dolphin_scene.c

@@ -0,0 +1,30 @@
+#include "dtmf_dolphin_scene.h"
+
+// Generate scene on_enter handlers array
+#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
+void (*const dtmf_dolphin_scene_on_enter_handlers[])(void*) = {
+#include "dtmf_dolphin_scene_config.h"
+};
+#undef ADD_SCENE
+
+// Generate scene on_event handlers array
+#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event,
+bool (*const dtmf_dolphin_scene_on_event_handlers[])(void* context, SceneManagerEvent event) = {
+#include "dtmf_dolphin_scene_config.h"
+};
+#undef ADD_SCENE
+
+// Generate scene on_exit handlers array
+#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_exit,
+void (*const dtmf_dolphin_scene_on_exit_handlers[])(void* context) = {
+#include "dtmf_dolphin_scene_config.h"
+};
+#undef ADD_SCENE
+
+// Initialize scene handlers configuration structure
+const SceneManagerHandlers dtmf_dolphin_scene_handlers = {
+    .on_enter_handlers = dtmf_dolphin_scene_on_enter_handlers,
+    .on_event_handlers = dtmf_dolphin_scene_on_event_handlers,
+    .on_exit_handlers = dtmf_dolphin_scene_on_exit_handlers,
+    .scene_num = DTMFDolphinSceneNum,
+};

+ 29 - 0
main_apps_sources/dtmf_dolphin/scenes/dtmf_dolphin_scene.h

@@ -0,0 +1,29 @@
+#pragma once
+
+#include <gui/scene_manager.h>
+
+// Generate scene id and total number
+#define ADD_SCENE(prefix, name, id) DTMFDolphinScene##id,
+typedef enum {
+#include "dtmf_dolphin_scene_config.h"
+    DTMFDolphinSceneNum,
+} DTMFDolphinScene;
+#undef ADD_SCENE
+
+extern const SceneManagerHandlers dtmf_dolphin_scene_handlers;
+
+// Generate scene on_enter handlers declaration
+#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*);
+#include "dtmf_dolphin_scene_config.h"
+#undef ADD_SCENE
+
+// Generate scene on_event handlers declaration
+#define ADD_SCENE(prefix, name, id) \
+    bool prefix##_scene_##name##_on_event(void* context, SceneManagerEvent event);
+#include "dtmf_dolphin_scene_config.h"
+#undef ADD_SCENE
+
+// Generate scene on_exit handlers declaration
+#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_exit(void* context);
+#include "dtmf_dolphin_scene_config.h"
+#undef ADD_SCENE

+ 2 - 0
main_apps_sources/dtmf_dolphin/scenes/dtmf_dolphin_scene_config.h

@@ -0,0 +1,2 @@
+ADD_SCENE(dtmf_dolphin, start, Start)
+ADD_SCENE(dtmf_dolphin, dialer, Dialer)

+ 49 - 0
main_apps_sources/dtmf_dolphin/scenes/dtmf_dolphin_scene_dialer.c

@@ -0,0 +1,49 @@
+#include "../dtmf_dolphin_i.h"
+// #include "../dtmf_dolphin_data.h"
+// #include "../dtmf_dolphin_audio.h"
+
+void dtmf_dolphin_scene_dialer_on_enter(void* context) {
+    DTMFDolphinApp* app = context;
+    DTMFDolphinScene scene_id = DTMFDolphinSceneDialer;
+    enum DTMFDolphinSceneState state = scene_manager_get_scene_state(app->scene_manager, scene_id);
+
+    switch(state) {
+    case DTMFDolphinSceneStateBluebox:
+        dtmf_dolphin_data_set_current_section(DTMF_DOLPHIN_TONE_BLOCK_BLUEBOX);
+        break;
+    case DTMFDolphinSceneStateRedboxUS:
+        dtmf_dolphin_data_set_current_section(DTMF_DOLPHIN_TONE_BLOCK_REDBOX_US);
+        break;
+    case DTMFDolphinSceneStateRedboxUK:
+        dtmf_dolphin_data_set_current_section(DTMF_DOLPHIN_TONE_BLOCK_REDBOX_UK);
+        break;
+    case DTMFDolphinSceneStateRedboxCA:
+        dtmf_dolphin_data_set_current_section(DTMF_DOLPHIN_TONE_BLOCK_REDBOX_CA);
+        break;
+    case DTMFDolphinSceneStateMisc:
+        dtmf_dolphin_data_set_current_section(DTMF_DOLPHIN_TONE_BLOCK_MISC);
+        break;
+    default:
+        dtmf_dolphin_data_set_current_section(DTMF_DOLPHIN_TONE_BLOCK_DIALER);
+        break;
+    }
+
+    view_dispatcher_switch_to_view(app->view_dispatcher, DTMFDolphinViewDialer);
+}
+
+bool dtmf_dolphin_scene_dialer_on_event(void* context, SceneManagerEvent event) {
+    DTMFDolphinApp* app = context;
+    UNUSED(app);
+    UNUSED(event);
+    bool consumed = false;
+
+    // if(event.type == SceneManagerEventTypeTick) {
+    //     consumed = true;
+    // }
+
+    return consumed;
+}
+
+void dtmf_dolphin_scene_dialer_on_exit(void* context) {
+    UNUSED(context);
+}

+ 94 - 0
main_apps_sources/dtmf_dolphin/scenes/dtmf_dolphin_scene_start.c

@@ -0,0 +1,94 @@
+#include "../dtmf_dolphin_i.h"
+
+static void dtmf_dolphin_scene_start_main_menu_enter_callback(void* context, uint32_t index) {
+    DTMFDolphinApp* app = context;
+    uint8_t cust_event = 255;
+    switch(index) {
+    case 0:
+        cust_event = DTMFDolphinEventStartDialer;
+        break;
+    case 1:
+        cust_event = DTMFDolphinEventStartBluebox;
+        break;
+    case 2:
+        cust_event = DTMFDolphinEventStartRedboxUS;
+        break;
+    case 3:
+        cust_event = DTMFDolphinEventStartRedboxUK;
+        break;
+    case 4:
+        cust_event = DTMFDolphinEventStartRedboxCA;
+        break;
+    case 5:
+        cust_event = DTMFDolphinEventStartMisc;
+        break;
+    default:
+        return;
+    }
+
+    view_dispatcher_send_custom_event(app->view_dispatcher, cust_event);
+}
+
+void dtmf_dolphin_scene_start_on_enter(void* context) {
+    DTMFDolphinApp* app = context;
+    VariableItemList* var_item_list = app->main_menu_list;
+
+    // VariableItem* item;
+    variable_item_list_set_enter_callback(
+        var_item_list, dtmf_dolphin_scene_start_main_menu_enter_callback, app);
+
+    variable_item_list_add(var_item_list, "Dialer", 0, NULL, context);
+    variable_item_list_add(var_item_list, "Bluebox", 0, NULL, context);
+    variable_item_list_add(var_item_list, "Redbox (US)", 0, NULL, context);
+    variable_item_list_add(var_item_list, "Redbox (UK)", 0, NULL, context);
+    variable_item_list_add(var_item_list, "Redbox (CA)", 0, NULL, context);
+    variable_item_list_add(var_item_list, "Misc", 0, NULL, context);
+
+    variable_item_list_set_selected_item(
+        var_item_list, scene_manager_get_scene_state(app->scene_manager, DTMFDolphinSceneStart));
+
+    view_dispatcher_switch_to_view(app->view_dispatcher, DTMFDolphinViewMainMenu);
+}
+
+bool dtmf_dolphin_scene_start_on_event(void* context, SceneManagerEvent event) {
+    DTMFDolphinApp* app = context;
+    UNUSED(app);
+    bool consumed = false;
+
+    if(event.type == SceneManagerEventTypeCustom) {
+        uint8_t sc_state;
+
+        switch(event.event) {
+        case DTMFDolphinEventStartDialer:
+            sc_state = DTMFDolphinSceneStateDialer;
+            break;
+        case DTMFDolphinEventStartBluebox:
+            sc_state = DTMFDolphinSceneStateBluebox;
+            break;
+        case DTMFDolphinEventStartRedboxUS:
+            sc_state = DTMFDolphinSceneStateRedboxUS;
+            break;
+        case DTMFDolphinEventStartRedboxUK:
+            sc_state = DTMFDolphinSceneStateRedboxUK;
+            break;
+        case DTMFDolphinEventStartRedboxCA:
+            sc_state = DTMFDolphinSceneStateRedboxCA;
+            break;
+        case DTMFDolphinEventStartMisc:
+            sc_state = DTMFDolphinSceneStateMisc;
+            break;
+        default:
+            return consumed;
+        }
+        scene_manager_set_scene_state(app->scene_manager, DTMFDolphinSceneDialer, sc_state);
+        scene_manager_next_scene(app->scene_manager, DTMFDolphinSceneDialer);
+
+        consumed = true;
+    }
+    return consumed;
+}
+
+void dtmf_dolphin_scene_start_on_exit(void* context) {
+    DTMFDolphinApp* app = context;
+    variable_item_list_reset(app->main_menu_list);
+}

+ 10 - 0
main_apps_sources/dtmf_dolphin/views/dtmf_dolphin_common.h

@@ -0,0 +1,10 @@
+#pragma once
+#include "../dtmf_dolphin_event.h"
+#include "../dtmf_dolphin_data.h"
+#include "../dtmf_dolphin_audio.h"
+
+#define DTMF_DOLPHIN_NUMPAD_X 1
+#define DTMF_DOLPHIN_NUMPAD_Y 14
+#define DTMF_DOLPHIN_BUTTON_WIDTH 13
+#define DTMF_DOLPHIN_BUTTON_HEIGHT 13
+#define DTMF_DOLPHIN_BUTTON_PADDING 1 // all sides

+ 350 - 0
main_apps_sources/dtmf_dolphin/views/dtmf_dolphin_dialer.c

@@ -0,0 +1,350 @@
+#include "dtmf_dolphin_dialer.h"
+
+#include <gui/elements.h>
+
+typedef struct DTMFDolphinDialer {
+    View* view;
+    DTMFDolphinDialerOkCallback callback;
+    void* context;
+} DTMFDolphinDialer;
+
+typedef struct {
+    DTMFDolphinToneSection section;
+    uint8_t row;
+    uint8_t col;
+    float freq1;
+    float freq2;
+    bool playing;
+    uint16_t pulses;
+    uint16_t pulse_ms;
+    uint16_t gap_ms;
+} DTMFDolphinDialerModel;
+
+static bool dtmf_dolphin_dialer_process_up(DTMFDolphinDialer* dtmf_dolphin_dialer);
+static bool dtmf_dolphin_dialer_process_down(DTMFDolphinDialer* dtmf_dolphin_dialer);
+static bool dtmf_dolphin_dialer_process_left(DTMFDolphinDialer* dtmf_dolphin_dialer);
+static bool dtmf_dolphin_dialer_process_right(DTMFDolphinDialer* dtmf_dolphin_dialer);
+static bool
+    dtmf_dolphin_dialer_process_ok(DTMFDolphinDialer* dtmf_dolphin_dialer, InputEvent* event);
+
+void draw_button(Canvas* canvas, uint8_t row, uint8_t col, bool invert) {
+    uint8_t left = DTMF_DOLPHIN_NUMPAD_X + // ((col + 1) * DTMF_DOLPHIN_BUTTON_PADDING) +
+                   (col * DTMF_DOLPHIN_BUTTON_WIDTH);
+    // (col * DTMF_DOLPHIN_BUTTON_PADDING);
+    uint8_t top = DTMF_DOLPHIN_NUMPAD_Y + // ((row + 1) * DTMF_DOLPHIN_BUTTON_PADDING) +
+                  (row * DTMF_DOLPHIN_BUTTON_HEIGHT);
+    // (row * DTMF_DOLPHIN_BUTTON_PADDING);
+
+    uint8_t span = dtmf_dolphin_get_tone_span(row, col);
+
+    if(span == 0) {
+        return;
+    }
+
+    canvas_set_color(canvas, ColorBlack);
+
+    if(invert)
+        canvas_draw_rbox(
+            canvas,
+            left,
+            top,
+            (DTMF_DOLPHIN_BUTTON_WIDTH * span) - (DTMF_DOLPHIN_BUTTON_PADDING * 2),
+            DTMF_DOLPHIN_BUTTON_HEIGHT - (DTMF_DOLPHIN_BUTTON_PADDING * 2),
+            2);
+    else
+        canvas_draw_rframe(
+            canvas,
+            left,
+            top,
+            (DTMF_DOLPHIN_BUTTON_WIDTH * span) - (DTMF_DOLPHIN_BUTTON_PADDING * 2),
+            DTMF_DOLPHIN_BUTTON_HEIGHT - (DTMF_DOLPHIN_BUTTON_PADDING * 2),
+            2);
+
+    if(invert) canvas_invert_color(canvas);
+
+    canvas_set_font(canvas, FontSecondary);
+    // canvas_set_color(canvas, invert ? ColorWhite : ColorBlack);
+    canvas_draw_str_aligned(
+        canvas,
+        left - 1 + (int)((DTMF_DOLPHIN_BUTTON_WIDTH * span) / 2),
+        top + (int)(DTMF_DOLPHIN_BUTTON_HEIGHT / 2),
+        AlignCenter,
+        AlignCenter,
+        dtmf_dolphin_data_get_tone_name(row, col));
+
+    if(invert) canvas_invert_color(canvas);
+}
+
+void draw_dialer(Canvas* canvas, void* _model) {
+    DTMFDolphinDialerModel* model = _model;
+    uint8_t max_rows;
+    uint8_t max_cols;
+    uint8_t max_span;
+    dtmf_dolphin_tone_get_max_pos(&max_rows, &max_cols, &max_span);
+
+    canvas_set_font(canvas, FontSecondary);
+
+    for(int r = 0; r < max_rows; r++) {
+        for(int c = 0; c < max_cols; c++) {
+            if(model->row == r && model->col == c)
+                draw_button(canvas, r, c, true);
+            else
+                draw_button(canvas, r, c, false);
+        }
+    }
+}
+
+void update_frequencies(DTMFDolphinDialerModel* model) {
+    dtmf_dolphin_data_get_tone_frequencies(&model->freq1, &model->freq2, model->row, model->col);
+    dtmf_dolphin_data_get_filter_data(
+        &model->pulses, &model->pulse_ms, &model->gap_ms, model->row, model->col);
+}
+
+static void dtmf_dolphin_dialer_draw_callback(Canvas* canvas, void* _model) {
+    DTMFDolphinDialerModel* model = _model;
+    if(model->playing) {
+        // Leverage the prioritized draw callback to handle
+        // the DMA so that it doesn't skip.
+        dtmf_dolphin_audio_handle_tick();
+        // Don't do any drawing if audio is playing.
+        canvas_set_font(canvas, FontPrimary);
+        elements_multiline_text_aligned(
+            canvas,
+            canvas_width(canvas) / 2,
+            canvas_height(canvas) / 2,
+            AlignCenter,
+            AlignCenter,
+            "Playing Tones");
+        return;
+    }
+    update_frequencies(model);
+    uint8_t max_rows = 0;
+    uint8_t max_cols = 0;
+    uint8_t max_span = 0;
+    dtmf_dolphin_tone_get_max_pos(&max_rows, &max_cols, &max_span);
+
+    canvas_set_font(canvas, FontPrimary);
+    elements_multiline_text(canvas, 2, 10, dtmf_dolphin_data_get_current_section_name());
+    canvas_draw_line(
+        canvas,
+        (max_span * DTMF_DOLPHIN_BUTTON_WIDTH) + 1,
+        0,
+        (max_span * DTMF_DOLPHIN_BUTTON_WIDTH) + 1,
+        canvas_height(canvas));
+    elements_multiline_text(canvas, (max_span * DTMF_DOLPHIN_BUTTON_WIDTH) + 4, 10, "Detail");
+    canvas_draw_line(
+        canvas, 0, DTMF_DOLPHIN_NUMPAD_Y - 3, canvas_width(canvas), DTMF_DOLPHIN_NUMPAD_Y - 3);
+    // elements_multiline_text_aligned(canvas, 64, 2, AlignCenter, AlignTop, "Dialer Mode");
+
+    draw_dialer(canvas, model);
+
+    FuriString* output = furi_string_alloc();
+
+    if(model->freq1 && model->freq2) {
+        furi_string_cat_printf(
+            output,
+            "Dual Tone\nF1: %u Hz\nF2: %u Hz\n",
+            (unsigned int)model->freq1,
+            (unsigned int)model->freq2);
+    } else if(model->freq1) {
+        furi_string_cat_printf(output, "Single Tone\nF: %u Hz\n", (unsigned int)model->freq1);
+    }
+
+    canvas_set_font(canvas, FontSecondary);
+    canvas_set_color(canvas, ColorBlack);
+    if(model->pulse_ms) {
+        furi_string_cat_printf(output, "P: %u * %u ms\n", model->pulses, model->pulse_ms);
+    }
+    if(model->gap_ms) {
+        furi_string_cat_printf(output, "Gaps: %u ms\n", model->gap_ms);
+    }
+    elements_multiline_text(
+        canvas, (max_span * DTMF_DOLPHIN_BUTTON_WIDTH) + 4, 21, furi_string_get_cstr(output));
+
+    furi_string_free(output);
+}
+
+static bool dtmf_dolphin_dialer_input_callback(InputEvent* event, void* context) {
+    furi_assert(context);
+    DTMFDolphinDialer* dtmf_dolphin_dialer = context;
+    bool consumed = false;
+
+    if(event->type == InputTypeShort) {
+        if(event->key == InputKeyRight) {
+            consumed = dtmf_dolphin_dialer_process_right(dtmf_dolphin_dialer);
+        } else if(event->key == InputKeyLeft) {
+            consumed = dtmf_dolphin_dialer_process_left(dtmf_dolphin_dialer);
+        } else if(event->key == InputKeyUp) {
+            consumed = dtmf_dolphin_dialer_process_up(dtmf_dolphin_dialer);
+        } else if(event->key == InputKeyDown) {
+            consumed = dtmf_dolphin_dialer_process_down(dtmf_dolphin_dialer);
+        }
+
+    } else if(event->key == InputKeyOk) {
+        consumed = dtmf_dolphin_dialer_process_ok(dtmf_dolphin_dialer, event);
+    }
+
+    return consumed;
+}
+
+static bool dtmf_dolphin_dialer_process_up(DTMFDolphinDialer* dtmf_dolphin_dialer) {
+    with_view_model(
+        dtmf_dolphin_dialer->view,
+        DTMFDolphinDialerModel * model,
+        {
+            uint8_t span = 0;
+            uint8_t cursor = model->row;
+            while(span == 0 && cursor > 0) {
+                cursor--;
+                span = dtmf_dolphin_get_tone_span(cursor, model->col);
+            }
+            if(span != 0) {
+                model->row = cursor;
+            }
+        },
+        true);
+    return true;
+}
+
+static bool dtmf_dolphin_dialer_process_down(DTMFDolphinDialer* dtmf_dolphin_dialer) {
+    uint8_t max_rows = 0;
+    uint8_t max_cols = 0;
+    uint8_t max_span = 0;
+    dtmf_dolphin_tone_get_max_pos(&max_rows, &max_cols, &max_span);
+
+    with_view_model(
+        dtmf_dolphin_dialer->view,
+        DTMFDolphinDialerModel * model,
+        {
+            uint8_t span = 0;
+            uint8_t cursor = model->row;
+            while(span == 0 && cursor < max_rows - 1) {
+                cursor++;
+                span = dtmf_dolphin_get_tone_span(cursor, model->col);
+            }
+            if(span != 0) {
+                model->row = cursor;
+            }
+        },
+        true);
+    return true;
+}
+
+static bool dtmf_dolphin_dialer_process_left(DTMFDolphinDialer* dtmf_dolphin_dialer) {
+    with_view_model(
+        dtmf_dolphin_dialer->view,
+        DTMFDolphinDialerModel * model,
+        {
+            uint8_t span = 0;
+            uint8_t cursor = model->col;
+            while(span == 0 && cursor > 0) {
+                cursor--;
+                span = dtmf_dolphin_get_tone_span(model->row, cursor);
+            }
+            if(span != 0) {
+                model->col = cursor;
+            }
+        },
+        true);
+    return true;
+}
+
+static bool dtmf_dolphin_dialer_process_right(DTMFDolphinDialer* dtmf_dolphin_dialer) {
+    uint8_t max_rows = 0;
+    uint8_t max_cols = 0;
+    uint8_t max_span = 0;
+    dtmf_dolphin_tone_get_max_pos(&max_rows, &max_cols, &max_span);
+
+    with_view_model(
+        dtmf_dolphin_dialer->view,
+        DTMFDolphinDialerModel * model,
+        {
+            uint8_t span = 0;
+            uint8_t cursor = model->col;
+            while(span == 0 && cursor < max_cols - 1) {
+                cursor++;
+                span = dtmf_dolphin_get_tone_span(model->row, cursor);
+            }
+            if(span != 0) {
+                model->col = cursor;
+            }
+        },
+        true);
+    return true;
+}
+
+static bool
+    dtmf_dolphin_dialer_process_ok(DTMFDolphinDialer* dtmf_dolphin_dialer, InputEvent* event) {
+    bool consumed = false;
+
+    with_view_model(
+        dtmf_dolphin_dialer->view,
+        DTMFDolphinDialerModel * model,
+        {
+            if(event->type == InputTypePress) {
+                model->playing = dtmf_dolphin_audio_play_tones(
+                    model->freq1, model->freq2, model->pulses, model->pulse_ms, model->gap_ms);
+            } else if(event->type == InputTypeRelease) {
+                model->playing = !dtmf_dolphin_audio_stop_tones();
+            }
+        },
+        true);
+
+    return consumed;
+}
+
+static void dtmf_dolphin_dialer_enter_callback(void* context) {
+    furi_assert(context);
+    DTMFDolphinDialer* dtmf_dolphin_dialer = context;
+
+    with_view_model(
+        dtmf_dolphin_dialer->view,
+        DTMFDolphinDialerModel * model,
+        {
+            model->col = 0;
+            model->row = 0;
+            model->section = 0;
+            model->freq1 = 0.0;
+            model->freq2 = 0.0;
+            model->playing = false;
+        },
+        true);
+}
+
+DTMFDolphinDialer* dtmf_dolphin_dialer_alloc() {
+    DTMFDolphinDialer* dtmf_dolphin_dialer = malloc(sizeof(DTMFDolphinDialer));
+
+    dtmf_dolphin_dialer->view = view_alloc();
+    view_allocate_model(
+        dtmf_dolphin_dialer->view, ViewModelTypeLocking, sizeof(DTMFDolphinDialerModel));
+
+    with_view_model(
+        dtmf_dolphin_dialer->view,
+        DTMFDolphinDialerModel * model,
+        {
+            model->col = 0;
+            model->row = 0;
+            model->section = 0;
+            model->freq1 = 0.0;
+            model->freq2 = 0.0;
+            model->playing = false;
+        },
+        true);
+
+    view_set_context(dtmf_dolphin_dialer->view, dtmf_dolphin_dialer);
+    view_set_draw_callback(dtmf_dolphin_dialer->view, dtmf_dolphin_dialer_draw_callback);
+    view_set_input_callback(dtmf_dolphin_dialer->view, dtmf_dolphin_dialer_input_callback);
+    view_set_enter_callback(dtmf_dolphin_dialer->view, dtmf_dolphin_dialer_enter_callback);
+    return dtmf_dolphin_dialer;
+}
+
+void dtmf_dolphin_dialer_free(DTMFDolphinDialer* dtmf_dolphin_dialer) {
+    furi_assert(dtmf_dolphin_dialer);
+    view_free(dtmf_dolphin_dialer->view);
+    free(dtmf_dolphin_dialer);
+}
+
+View* dtmf_dolphin_dialer_get_view(DTMFDolphinDialer* dtmf_dolphin_dialer) {
+    furi_assert(dtmf_dolphin_dialer);
+    return dtmf_dolphin_dialer->view;
+}

+ 18 - 0
main_apps_sources/dtmf_dolphin/views/dtmf_dolphin_dialer.h

@@ -0,0 +1,18 @@
+#pragma once
+
+#include <gui/view.h>
+#include "dtmf_dolphin_common.h"
+
+typedef struct DTMFDolphinDialer DTMFDolphinDialer;
+typedef void (*DTMFDolphinDialerOkCallback)(InputType type, void* context);
+
+DTMFDolphinDialer* dtmf_dolphin_dialer_alloc();
+
+void dtmf_dolphin_dialer_free(DTMFDolphinDialer* dtmf_dolphin_dialer);
+
+View* dtmf_dolphin_dialer_get_view(DTMFDolphinDialer* dtmf_dolphin_dialer);
+
+void dtmf_dolphin_dialer_set_ok_callback(
+    DTMFDolphinDialer* dtmf_dolphin_dialer,
+    DTMFDolphinDialerOkCallback callback,
+    void* context);

+ 7 - 0
main_apps_sources/esp8266_deauth/FlipperZeroWiFiDeauthModuleDefines.h

@@ -0,0 +1,7 @@
+#define WIFI_MODULE_INIT_VERSION "WFDM_0.1"
+
+#define MODULE_CONTEXT_INITIALIZATION WIFI_MODULE_INIT_VERSION
+
+#define FLIPPERZERO_SERIAL_BAUD 230400
+
+#define NA 0

+ 14 - 0
main_apps_sources/esp8266_deauth/application.fam

@@ -0,0 +1,14 @@
+App(
+    appid="esp8266_deauther",
+    name="[ESP8266] Deauther",
+    apptype=FlipperAppType.EXTERNAL,
+    entry_point="esp8266_deauth_app",
+    requires=["gui"],
+    stack_size=2 * 1024,
+    order=100,
+    fap_icon="wifi_10px.png",
+    fap_category="GPIO",
+    fap_author="@SequoiaSan & @xMasterX",
+    fap_version="1.0",
+    fap_description="DSTIKE Deauther module interface, based on ESP8266",
+)

+ 543 - 0
main_apps_sources/esp8266_deauth/esp8266_deauth.c

@@ -0,0 +1,543 @@
+#include <furi.h>
+#include <furi_hal_console.h>
+#include <furi_hal_gpio.h>
+#include <furi_hal_power.h>
+#include <furi_hal_uart.h>
+#include <gui/canvas_i.h>
+#include <gui/gui.h>
+#include <input/input.h>
+//#include <math.h>
+//#include <notification/notification.h>
+//#include <notification/notification_messages.h>
+//#include <stdlib.h>
+
+#include "FlipperZeroWiFiDeauthModuleDefines.h"
+
+#define DEAUTH_APP_DEBUG 0
+
+#if DEAUTH_APP_DEBUG
+#define APP_NAME_TAG "WiFi_Deauther"
+#define DEAUTH_APP_LOG_I(format, ...) FURI_LOG_I(APP_NAME_TAG, format, ##__VA_ARGS__)
+#define DEAUTH_APP_LOG_D(format, ...) FURI_LOG_D(APP_NAME_TAG, format, ##__VA_ARGS__)
+#define DEAUTH_APP_LOG_E(format, ...) FURI_LOG_E(APP_NAME_TAG, format, ##__VA_ARGS__)
+#else
+#define DEAUTH_APP_LOG_I(format, ...)
+#define DEAUTH_APP_LOG_D(format, ...)
+#define DEAUTH_APP_LOG_E(format, ...)
+#endif // WIFI_APP_DEBUG
+
+#define DISABLE_CONSOLE !DEAUTH_APP_DEBUG
+#define ENABLE_MODULE_POWER 1
+#define ENABLE_MODULE_DETECTION 1
+
+typedef enum EEventType // app internally defined event types
+{ EventTypeKey // flipper input.h type
+} EEventType;
+
+typedef struct SPluginEvent {
+    EEventType m_type;
+    InputEvent m_input;
+} SPluginEvent;
+
+typedef enum EAppContext {
+    Undefined,
+    WaitingForModule,
+    Initializing,
+    ModuleActive,
+} EAppContext;
+
+typedef enum EWorkerEventFlags {
+    WorkerEventReserved = (1 << 0), // Reserved for StreamBuffer internal event
+    WorkerEventStop = (1 << 1),
+    WorkerEventRx = (1 << 2),
+} EWorkerEventFlags;
+
+typedef struct SGpioButtons {
+    GpioPin const* pinButtonUp;
+    GpioPin const* pinButtonDown;
+    GpioPin const* pinButtonOK;
+    GpioPin const* pinButtonBack;
+} SGpioButtons;
+
+typedef struct SWiFiDeauthApp {
+    FuriMutex* mutex;
+    Gui* m_gui;
+    FuriThread* m_worker_thread;
+    //NotificationApp* m_notification;
+    FuriStreamBuffer* m_rx_stream;
+    SGpioButtons m_GpioButtons;
+
+    bool m_wifiDeauthModuleInitialized;
+    bool m_wifiDeauthModuleAttached;
+
+    EAppContext m_context;
+
+    uint8_t m_backBuffer[128 * 8 * 8];
+    //uint8_t m_renderBuffer[128 * 8 * 8];
+
+    uint8_t* m_backBufferPtr;
+    //uint8_t* m_m_renderBufferPtr;
+
+    //uint8_t* m_originalBuffer;
+    //uint8_t** m_originalBufferLocation;
+    size_t m_canvasSize;
+
+    bool m_needUpdateGUI;
+} SWiFiDeauthApp;
+
+/////// INIT STATE ///////
+static void esp8266_deauth_app_init(SWiFiDeauthApp* const app) {
+    app->m_context = Undefined;
+
+    app->m_canvasSize = 128 * 8 * 8;
+    memset(app->m_backBuffer, DEAUTH_APP_DEBUG ? 0xFF : 0x00, app->m_canvasSize);
+    //memset(app->m_renderBuffer, DEAUTH_APP_DEBUG ? 0xFF : 0x00, app->m_canvasSize);
+
+    //app->m_originalBuffer = NULL;
+    //app->m_originalBufferLocation = NULL;
+
+    //app->m_m_renderBufferPtr = app->m_renderBuffer;
+    app->m_backBufferPtr = app->m_backBuffer;
+
+    app->m_GpioButtons.pinButtonUp = &gpio_ext_pc3;
+    app->m_GpioButtons.pinButtonDown = &gpio_ext_pb2;
+    app->m_GpioButtons.pinButtonOK = &gpio_ext_pb3;
+    app->m_GpioButtons.pinButtonBack = &gpio_ext_pa4;
+
+    app->m_needUpdateGUI = false;
+
+#if ENABLE_MODULE_POWER
+    app->m_wifiDeauthModuleInitialized = false;
+#else
+    app->m_wifiDeauthModuleInitialized = true;
+#endif // ENABLE_MODULE_POWER
+
+#if ENABLE_MODULE_DETECTION
+    app->m_wifiDeauthModuleAttached = false;
+#else
+    app->m_wifiDeauthModuleAttached = true;
+#endif
+}
+
+static void esp8266_deauth_module_render_callback(Canvas* const canvas, void* ctx) {
+    furi_assert(ctx);
+    SWiFiDeauthApp* app = ctx;
+    furi_mutex_acquire(app->mutex, FuriWaitForever);
+
+    //if(app->m_needUpdateGUI)
+    //{
+    //    app->m_needUpdateGUI = false;
+
+    //    //app->m_canvasSize = canvas_get_buffer_size(canvas);
+    //    //app->m_originalBuffer = canvas_get_buffer(canvas);
+    //    //app->m_originalBufferLocation = &u8g2_GetBufferPtr(&canvas->fb);
+    //    //u8g2_GetBufferPtr(&canvas->fb) = app->m_m_renderBufferPtr;
+    //}
+
+    //uint8_t* exchangeBuffers = app->m_m_renderBufferPtr;
+    //app->m_m_renderBufferPtr = app->m_backBufferPtr;
+    //app->m_backBufferPtr = exchangeBuffers;
+
+    //if(app->m_needUpdateGUI)
+    //{
+    //    //memcpy(app->m_renderBuffer, app->m_backBuffer, app->m_canvasSize);
+    //    app->m_needUpdateGUI = false;
+    //}
+
+    switch(app->m_context) {
+    case Undefined: {
+        canvas_clear(canvas);
+        canvas_set_font(canvas, FontPrimary);
+
+        const char* strInitializing = "Something wrong";
+        canvas_draw_str(
+            canvas,
+            (128 / 2) - (canvas_string_width(canvas, strInitializing) / 2),
+            (64 / 2) /* - (canvas_current_font_height(canvas) / 2)*/,
+            strInitializing);
+    } break;
+    case WaitingForModule:
+#if ENABLE_MODULE_DETECTION
+        furi_assert(!app->m_wifiDeauthModuleAttached);
+        if(!app->m_wifiDeauthModuleAttached) {
+            canvas_clear(canvas);
+            canvas_set_font(canvas, FontSecondary);
+
+            const char* strInitializing = "Attach WiFi Deauther module";
+            canvas_draw_str(
+                canvas,
+                (128 / 2) - (canvas_string_width(canvas, strInitializing) / 2),
+                (64 / 2) /* - (canvas_current_font_height(canvas) / 2)*/,
+                strInitializing);
+        }
+#endif
+        break;
+    case Initializing:
+#if ENABLE_MODULE_POWER
+    {
+        furi_assert(!app->m_wifiDeauthModuleInitialized);
+        if(!app->m_wifiDeauthModuleInitialized) {
+            canvas_set_font(canvas, FontPrimary);
+
+            const char* strInitializing = "Initializing...";
+            canvas_draw_str(
+                canvas,
+                (128 / 2) - (canvas_string_width(canvas, strInitializing) / 2),
+                (64 / 2) - (canvas_current_font_height(canvas) / 2),
+                strInitializing);
+        }
+    }
+#endif // ENABLE_MODULE_POWER
+    break;
+    case ModuleActive: {
+        uint8_t* buffer = canvas->fb.tile_buf_ptr;
+        app->m_canvasSize = gui_get_framebuffer_size(app->m_gui);
+        memcpy(buffer, app->m_backBuffer, app->m_canvasSize);
+    } break;
+    default:
+        break;
+    }
+
+    furi_mutex_release(app->mutex);
+}
+
+static void
+    esp8266_deauth_module_input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
+    furi_assert(event_queue);
+
+    SPluginEvent event = {.m_type = EventTypeKey, .m_input = *input_event};
+    furi_message_queue_put(event_queue, &event, FuriWaitForever);
+}
+
+static void uart_on_irq_cb(UartIrqEvent ev, uint8_t data, void* context) {
+    furi_assert(context);
+
+    SWiFiDeauthApp* app = context;
+
+    DEAUTH_APP_LOG_I("uart_echo_on_irq_cb");
+
+    if(ev == UartIrqEventRXNE) {
+        DEAUTH_APP_LOG_I("ev == UartIrqEventRXNE");
+        furi_stream_buffer_send(app->m_rx_stream, &data, 1, 0);
+        furi_thread_flags_set(furi_thread_get_id(app->m_worker_thread), WorkerEventRx);
+    }
+}
+
+static int32_t uart_worker(void* context) {
+    furi_assert(context);
+    DEAUTH_APP_LOG_I("[UART] Worker thread init");
+
+    SWiFiDeauthApp* app = context;
+    furi_mutex_acquire(app->mutex, FuriWaitForever);
+    if(app == NULL) {
+        return 1;
+    }
+
+    FuriStreamBuffer* rx_stream = app->m_rx_stream;
+
+    furi_mutex_release(app->mutex);
+
+#if ENABLE_MODULE_POWER
+    bool initialized = false;
+
+    FuriString* receivedString;
+    receivedString = furi_string_alloc();
+#endif // ENABLE_MODULE_POWER
+
+    while(true) {
+        uint32_t events = furi_thread_flags_wait(
+            WorkerEventStop | WorkerEventRx, FuriFlagWaitAny, FuriWaitForever);
+        furi_check((events & FuriFlagError) == 0);
+
+        if(events & WorkerEventStop) break;
+        if(events & WorkerEventRx) {
+            DEAUTH_APP_LOG_I("[UART] Received data");
+            SWiFiDeauthApp* app = context;
+            furi_mutex_acquire(app->mutex, FuriWaitForever);
+            if(app == NULL) {
+                return 1;
+            }
+
+            size_t dataReceivedLength = 0;
+            int index = 0;
+            do {
+                const uint8_t dataBufferSize = 64;
+                uint8_t dataBuffer[dataBufferSize];
+                dataReceivedLength =
+                    furi_stream_buffer_receive(rx_stream, dataBuffer, dataBufferSize, 25);
+                if(dataReceivedLength > 0) {
+#if ENABLE_MODULE_POWER
+                    if(!initialized) {
+                        if(!(dataReceivedLength > strlen(MODULE_CONTEXT_INITIALIZATION))) {
+                            DEAUTH_APP_LOG_I("[UART] Found possible init candidate");
+                            for(uint16_t i = 0; i < dataReceivedLength; i++) {
+                                furi_string_push_back(receivedString, dataBuffer[i]);
+                            }
+                        }
+                    } else
+#endif // ENABLE_MODULE_POWER
+                    {
+                        DEAUTH_APP_LOG_I("[UART] Data copied to backbuffer");
+                        memcpy(app->m_backBuffer + index, dataBuffer, dataReceivedLength);
+                        index += dataReceivedLength;
+                        app->m_needUpdateGUI = true;
+                    }
+                }
+
+            } while(dataReceivedLength > 0);
+
+#if ENABLE_MODULE_POWER
+            if(!app->m_wifiDeauthModuleInitialized) {
+                if(furi_string_cmp_str(receivedString, MODULE_CONTEXT_INITIALIZATION) == 0) {
+                    DEAUTH_APP_LOG_I("[UART] Initialized");
+                    initialized = true;
+                    app->m_wifiDeauthModuleInitialized = true;
+                    app->m_context = ModuleActive;
+                    furi_string_free(receivedString);
+                } else {
+                    DEAUTH_APP_LOG_I("[UART] Not an initialization command");
+                    furi_string_reset(receivedString);
+                }
+            }
+#endif // ENABLE_MODULE_POWER
+
+            furi_mutex_release(app->mutex);
+        }
+    }
+
+    return 0;
+}
+
+int32_t esp8266_deauth_app(void* p) {
+    UNUSED(p);
+
+    DEAUTH_APP_LOG_I("Init");
+
+    // FuriTimer* timer = furi_timer_alloc(blink_test_update, FuriTimerTypePeriodic, event_queue);
+    // furi_timer_start(timer, furi_kernel_get_tick_frequency());
+
+    FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(SPluginEvent));
+
+    SWiFiDeauthApp* app = malloc(sizeof(SWiFiDeauthApp));
+
+    esp8266_deauth_app_init(app);
+
+    furi_hal_gpio_init_simple(app->m_GpioButtons.pinButtonUp, GpioModeOutputPushPull);
+    furi_hal_gpio_init_simple(app->m_GpioButtons.pinButtonDown, GpioModeOutputPushPull);
+    furi_hal_gpio_init_simple(app->m_GpioButtons.pinButtonOK, GpioModeOutputPushPull);
+    furi_hal_gpio_init_simple(app->m_GpioButtons.pinButtonBack, GpioModeOutputPushPull);
+
+    furi_hal_gpio_write(app->m_GpioButtons.pinButtonUp, true);
+    furi_hal_gpio_write(app->m_GpioButtons.pinButtonDown, true);
+    furi_hal_gpio_write(app->m_GpioButtons.pinButtonOK, true);
+    furi_hal_gpio_write(
+        app->m_GpioButtons.pinButtonBack, false); // GPIO15 - Boot fails if pulled HIGH
+
+#if ENABLE_MODULE_DETECTION
+    furi_hal_gpio_init(
+        &gpio_ext_pc0,
+        GpioModeInput,
+        GpioPullUp,
+        GpioSpeedLow); // Connect to the Flipper's ground just to be sure
+    //furi_hal_gpio_add_int_callback(pinD0, input_isr_d0, this);
+    app->m_context = WaitingForModule;
+#else
+#if ENABLE_MODULE_POWER
+    app->m_context = Initializing;
+    uint8_t attempts = 0;
+    while(!furi_hal_power_is_otg_enabled() && attempts++ < 5) {
+        furi_hal_power_enable_otg();
+        furi_delay_ms(10);
+    }
+    furi_delay_ms(200);
+#else
+    app->m_context = ModuleActive;
+#endif
+#endif // ENABLE_MODULE_DETECTION
+
+    app->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
+    if(!app->mutex) {
+        DEAUTH_APP_LOG_E("cannot create mutex\r\n");
+        free(app);
+        return 255;
+    }
+
+    DEAUTH_APP_LOG_I("Mutex created");
+
+    //app->m_notification = furi_record_open(RECORD_NOTIFICATION);
+
+    ViewPort* view_port = view_port_alloc();
+    view_port_draw_callback_set(view_port, esp8266_deauth_module_render_callback, app);
+    view_port_input_callback_set(view_port, esp8266_deauth_module_input_callback, event_queue);
+
+    // Open GUI and register view_port
+    app->m_gui = furi_record_open(RECORD_GUI);
+    gui_add_view_port(app->m_gui, view_port, GuiLayerFullscreen);
+
+    //notification_message(app->notification, &sequence_set_only_blue_255);
+
+    app->m_rx_stream = furi_stream_buffer_alloc(1 * 1024, 1);
+
+    app->m_worker_thread = furi_thread_alloc();
+    furi_thread_set_name(app->m_worker_thread, "WiFiDeauthModuleUARTWorker");
+    furi_thread_set_stack_size(app->m_worker_thread, 1 * 1024);
+    furi_thread_set_context(app->m_worker_thread, app);
+    furi_thread_set_callback(app->m_worker_thread, uart_worker);
+    furi_thread_start(app->m_worker_thread);
+    DEAUTH_APP_LOG_I("UART thread allocated");
+
+    // Enable uart listener
+#if DISABLE_CONSOLE
+    furi_hal_console_disable();
+#endif
+    furi_hal_uart_set_br(FuriHalUartIdUSART1, FLIPPERZERO_SERIAL_BAUD);
+    furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, uart_on_irq_cb, app);
+    DEAUTH_APP_LOG_I("UART Listener created");
+
+    SPluginEvent event;
+    for(bool processing = true; processing;) {
+        FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
+        furi_mutex_acquire(app->mutex, FuriWaitForever);
+
+#if ENABLE_MODULE_DETECTION
+        if(!app->m_wifiDeauthModuleAttached) {
+            if(furi_hal_gpio_read(&gpio_ext_pc0) == false) {
+                DEAUTH_APP_LOG_I("Module Attached");
+                app->m_wifiDeauthModuleAttached = true;
+#if ENABLE_MODULE_POWER
+                app->m_context = Initializing;
+                uint8_t attempts2 = 0;
+                while(!furi_hal_power_is_otg_enabled() && attempts2++ < 3) {
+                    furi_hal_power_enable_otg();
+                    furi_delay_ms(10);
+                }
+#else
+                app->m_context = ModuleActive;
+#endif
+            }
+        }
+#endif // ENABLE_MODULE_DETECTION
+
+        if(event_status == FuriStatusOk) {
+            if(event.m_type == EventTypeKey) {
+                if(app->m_wifiDeauthModuleInitialized) {
+                    if(app->m_context == ModuleActive) {
+                        switch(event.m_input.key) {
+                        case InputKeyUp:
+                            if(event.m_input.type == InputTypePress) {
+                                DEAUTH_APP_LOG_I("Up Press");
+                                furi_hal_gpio_write(app->m_GpioButtons.pinButtonUp, false);
+                            } else if(event.m_input.type == InputTypeRelease) {
+                                DEAUTH_APP_LOG_I("Up Release");
+                                furi_hal_gpio_write(app->m_GpioButtons.pinButtonUp, true);
+                            }
+                            break;
+                        case InputKeyDown:
+                            if(event.m_input.type == InputTypePress) {
+                                DEAUTH_APP_LOG_I("Down Press");
+                                furi_hal_gpio_write(app->m_GpioButtons.pinButtonDown, false);
+                            } else if(event.m_input.type == InputTypeRelease) {
+                                DEAUTH_APP_LOG_I("Down Release");
+                                furi_hal_gpio_write(app->m_GpioButtons.pinButtonDown, true);
+                            }
+                            break;
+                        case InputKeyOk:
+                            if(event.m_input.type == InputTypePress) {
+                                DEAUTH_APP_LOG_I("OK Press");
+                                furi_hal_gpio_write(app->m_GpioButtons.pinButtonOK, false);
+                            } else if(event.m_input.type == InputTypeRelease) {
+                                DEAUTH_APP_LOG_I("OK Release");
+                                furi_hal_gpio_write(app->m_GpioButtons.pinButtonOK, true);
+                            }
+                            break;
+                        case InputKeyBack:
+                            if(event.m_input.type == InputTypePress) {
+                                DEAUTH_APP_LOG_I("Back Press");
+                                furi_hal_gpio_write(app->m_GpioButtons.pinButtonBack, false);
+                            } else if(event.m_input.type == InputTypeRelease) {
+                                DEAUTH_APP_LOG_I("Back Release");
+                                furi_hal_gpio_write(app->m_GpioButtons.pinButtonBack, true);
+                            } else if(event.m_input.type == InputTypeLong) {
+                                DEAUTH_APP_LOG_I("Back Long");
+                                processing = false;
+                            }
+                            break;
+                        default:
+                            break;
+                        }
+                    }
+                } else {
+                    if(event.m_input.key == InputKeyBack) {
+                        if(event.m_input.type == InputTypeShort ||
+                           event.m_input.type == InputTypeLong) {
+                            processing = false;
+                        }
+                    }
+                }
+            }
+        }
+
+#if ENABLE_MODULE_DETECTION
+        if(app->m_wifiDeauthModuleAttached && furi_hal_gpio_read(&gpio_ext_pc0) == true) {
+            DEAUTH_APP_LOG_D("Module Disconnected - Exit");
+            processing = false;
+            app->m_wifiDeauthModuleAttached = false;
+            app->m_wifiDeauthModuleInitialized = false;
+        }
+#endif
+
+        view_port_update(view_port);
+        furi_mutex_release(app->mutex);
+    }
+
+    DEAUTH_APP_LOG_I("Start exit app");
+
+    furi_thread_flags_set(furi_thread_get_id(app->m_worker_thread), WorkerEventStop);
+    furi_thread_join(app->m_worker_thread);
+    furi_thread_free(app->m_worker_thread);
+
+    DEAUTH_APP_LOG_I("Thread Deleted");
+
+    // Reset GPIO pins to default state
+    furi_hal_gpio_init(&gpio_ext_pc0, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
+    furi_hal_gpio_init(&gpio_ext_pc3, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
+    furi_hal_gpio_init(&gpio_ext_pb2, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
+    furi_hal_gpio_init(&gpio_ext_pb3, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
+    furi_hal_gpio_init(&gpio_ext_pa4, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
+
+#if DISABLE_CONSOLE
+    furi_hal_console_enable();
+#endif
+
+    //*app->m_originalBufferLocation = app->m_originalBuffer;
+
+    view_port_enabled_set(view_port, false);
+
+    gui_remove_view_port(app->m_gui, view_port);
+
+    // Close gui record
+    furi_record_close(RECORD_GUI);
+    //furi_record_close(RECORD_NOTIFICATION);
+    app->m_gui = NULL;
+
+    view_port_free(view_port);
+
+    furi_message_queue_free(event_queue);
+
+    furi_stream_buffer_free(app->m_rx_stream);
+
+    furi_mutex_free(app->mutex);
+
+    // Free rest
+    free(app);
+
+    DEAUTH_APP_LOG_I("App freed");
+
+#if ENABLE_MODULE_POWER
+    if(furi_hal_power_is_otg_enabled()) {
+        furi_hal_power_disable_otg();
+    }
+#endif
+
+    return 0;
+}

BIN
main_apps_sources/esp8266_deauth/wifi_10px.png


+ 15 - 0
main_apps_sources/flappy_bird/application.fam

@@ -0,0 +1,15 @@
+App(
+    appid="flappy_bird",
+    name="Flappy Bird",
+    apptype=FlipperAppType.EXTERNAL,
+    entry_point="flappy_game_app",
+    requires=["gui"],
+    stack_size=4 * 1024,
+    order=100,
+    fap_icon="flappy_10px.png",
+    fap_category="Games",
+    fap_icon_assets="assets",
+    fap_author="@DroomOne & @xMasterX",
+    fap_version="1.0",
+    fap_description="Flappy Bird Game",
+)

BIN
main_apps_sources/flappy_bird/assets/bird/frame_01.png


BIN
main_apps_sources/flappy_bird/assets/bird/frame_02.png


BIN
main_apps_sources/flappy_bird/assets/bird/frame_03.png


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

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

BIN
main_apps_sources/flappy_bird/flappy_10px.png


+ 374 - 0
main_apps_sources/flappy_bird/flappy_bird.c

@@ -0,0 +1,374 @@
+#include <stdlib.h>
+
+#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>
+
+#define TAG "Flappy"
+#define DEBUG false
+
+#define FLAPPY_BIRD_HEIGHT 15
+#define FLAPPY_BIRD_WIDTH 10
+
+#define FLAPPY_PILAR_MAX 6
+#define FLAPPY_PILAR_DIST 35
+
+#define FLAPPY_GAB_HEIGHT 25
+#define FLAPPY_GAB_WIDTH 10
+
+#define FLAPPY_GRAVITY_JUMP -1.1
+#define FLAPPY_GRAVITY_TICK 0.15
+
+#define FLIPPER_LCD_WIDTH 128
+#define FLIPPER_LCD_HEIGHT 64
+
+typedef enum {
+    EventTypeTick,
+    EventTypeKey,
+} EventType;
+
+typedef struct {
+    int x;
+    int y;
+} POINT;
+
+typedef struct {
+    float gravity;
+    POINT point;
+    IconAnimation* sprite;
+} BIRD;
+
+typedef struct {
+    POINT point;
+    int height;
+    int visible;
+    bool passed;
+} PILAR;
+
+typedef enum {
+    GameStateLife,
+    GameStateGameOver,
+} State;
+
+typedef struct {
+    BIRD bird;
+    int points;
+    int pilars_count;
+    PILAR pilars[FLAPPY_PILAR_MAX];
+    bool debug;
+    State state;
+    FuriMutex* mutex;
+} GameState;
+
+typedef struct {
+    EventType type;
+    InputEvent input;
+} GameEvent;
+
+typedef enum {
+    DirectionUp,
+    DirectionRight,
+    DirectionDown,
+    DirectionLeft,
+} Direction;
+
+static void flappy_game_random_pilar(GameState* const game_state) {
+    PILAR pilar;
+
+    pilar.passed = false;
+    pilar.visible = 1;
+    pilar.height = random() % (FLIPPER_LCD_HEIGHT - FLAPPY_GAB_HEIGHT) + 1;
+    pilar.point.y = 0;
+    pilar.point.x = FLIPPER_LCD_WIDTH + FLAPPY_GAB_WIDTH + 1;
+
+    game_state->pilars_count++;
+    game_state->pilars[game_state->pilars_count % FLAPPY_PILAR_MAX] = pilar;
+}
+
+static void flappy_game_state_init(GameState* const game_state) {
+    BIRD bird;
+    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;
+    game_state->pilars_count = 0;
+    game_state->points = 0;
+    game_state->state = GameStateLife;
+    memset(game_state->pilars, 0, sizeof(game_state->pilars));
+
+    flappy_game_random_pilar(game_state);
+}
+
+static void flappy_game_state_free(GameState* const game_state) {
+    icon_animation_free(game_state->bird.sprite);
+    free(game_state);
+}
+
+static void flappy_game_tick(GameState* const game_state) {
+    if(game_state->state == GameStateLife) {
+        if(!game_state->debug) {
+            game_state->bird.gravity += FLAPPY_GRAVITY_TICK;
+            game_state->bird.point.y += game_state->bird.gravity;
+        }
+
+        // Checking the location of the last respawned pilar.
+        PILAR* pilar = &game_state->pilars[game_state->pilars_count % FLAPPY_PILAR_MAX];
+        if(pilar->point.x == (FLIPPER_LCD_WIDTH - FLAPPY_PILAR_DIST))
+            flappy_game_random_pilar(game_state);
+
+        // Updating the position/status of the pilars (visiblity, posotion, game points)
+        //        |  |      |  |  |
+        //        |  |      |  |  |
+        //        |__|      |  |__|
+        //   _____X         |      X_____
+        //  |     |         |      |     |   // [Pos + Width of pilar] >= [Bird Pos]
+        //  |_____|         |      |_____|
+        // X <---->         |     X <->
+        // Bird Pos + Lenght of the  bird] >= [Pilar]
+        for(int i = 0; i < FLAPPY_PILAR_MAX; i++) {
+            PILAR* pilar = &game_state->pilars[i];
+            if(pilar != NULL && pilar->visible && game_state->state == GameStateLife) {
+                pilar->point.x--;
+                if(game_state->bird.point.x >= pilar->point.x + FLAPPY_GAB_WIDTH &&
+                   pilar->passed == false) {
+                    pilar->passed = true;
+                    game_state->points++;
+                }
+                if(pilar->point.x < -FLAPPY_GAB_WIDTH) pilar->visible = 0;
+
+                if(game_state->bird.point.y <= 0 - FLAPPY_BIRD_WIDTH) {
+                    game_state->bird.point.y = 64;
+                }
+
+                if(game_state->bird.point.y > 64 - FLAPPY_BIRD_WIDTH) {
+                    game_state->bird.point.y = FLIPPER_LCD_HEIGHT - FLAPPY_BIRD_WIDTH;
+                }
+
+                // Bird inbetween pipes
+                if((game_state->bird.point.x + FLAPPY_BIRD_HEIGHT >= pilar->point.x) &&
+                   (game_state->bird.point.x <= pilar->point.x + FLAPPY_GAB_WIDTH)) {
+                    // Bird below Bottom Pipe
+                    if(game_state->bird.point.y + FLAPPY_BIRD_WIDTH - 2 >=
+                       pilar->height + FLAPPY_GAB_HEIGHT) {
+                        game_state->state = GameStateGameOver;
+                        break;
+                    }
+
+                    // Bird above Upper Pipe
+                    if(game_state->bird.point.y < pilar->height) {
+                        game_state->state = GameStateGameOver;
+                        break;
+                    }
+                }
+            }
+        }
+    }
+}
+
+static void flappy_game_flap(GameState* const game_state) {
+    game_state->bird.gravity = FLAPPY_GRAVITY_JUMP;
+}
+
+static void flappy_game_render_callback(Canvas* const canvas, void* ctx) {
+    furi_assert(ctx);
+    const GameState* game_state = ctx;
+    furi_mutex_acquire(game_state->mutex, FuriWaitForever);
+
+    canvas_draw_frame(canvas, 0, 0, 128, 64);
+
+    if(game_state->state == GameStateLife) {
+        // Pilars
+        for(int i = 0; i < FLAPPY_PILAR_MAX; i++) {
+            const PILAR* pilar = &game_state->pilars[i];
+            if(pilar != NULL && pilar->visible == 1) {
+                canvas_draw_frame(
+                    canvas, pilar->point.x, pilar->point.y, FLAPPY_GAB_WIDTH, pilar->height);
+
+                canvas_draw_frame(
+                    canvas, pilar->point.x + 1, pilar->point.y, FLAPPY_GAB_WIDTH, pilar->height);
+
+                canvas_draw_frame(
+                    canvas,
+                    pilar->point.x + 2,
+                    pilar->point.y,
+                    FLAPPY_GAB_WIDTH - 1,
+                    pilar->height);
+
+                canvas_draw_frame(
+                    canvas,
+                    pilar->point.x,
+                    pilar->point.y + pilar->height + FLAPPY_GAB_HEIGHT,
+                    FLAPPY_GAB_WIDTH,
+                    FLIPPER_LCD_HEIGHT - pilar->height - FLAPPY_GAB_HEIGHT);
+
+                canvas_draw_frame(
+                    canvas,
+                    pilar->point.x + 1,
+                    pilar->point.y + pilar->height + FLAPPY_GAB_HEIGHT,
+                    FLAPPY_GAB_WIDTH - 1,
+                    FLIPPER_LCD_HEIGHT - pilar->height - FLAPPY_GAB_HEIGHT);
+
+                canvas_draw_frame(
+                    canvas,
+                    pilar->point.x + 2,
+                    pilar->point.y + pilar->height + FLAPPY_GAB_HEIGHT,
+                    FLAPPY_GAB_WIDTH - 1,
+                    FLIPPER_LCD_HEIGHT - pilar->height - FLAPPY_GAB_HEIGHT);
+            }
+        }
+
+        // Switch animation
+        game_state->bird.sprite->frame = 1;
+        if(game_state->bird.gravity < -0.5)
+            game_state->bird.sprite->frame = 0;
+        else if(game_state->bird.gravity > 0.5)
+            game_state->bird.sprite->frame = 2;
+
+        canvas_draw_icon_animation(
+            canvas, game_state->bird.point.x, game_state->bird.point.y, game_state->bird.sprite);
+
+        canvas_set_font(canvas, FontSecondary);
+        char buffer[12];
+        snprintf(buffer, sizeof(buffer), "Score: %u", game_state->points);
+        canvas_draw_str_aligned(canvas, 100, 12, AlignCenter, AlignBottom, buffer);
+
+        if(game_state->debug) {
+            char coordinates[20];
+            snprintf(coordinates, sizeof(coordinates), "Y: %u", game_state->bird.point.y);
+            canvas_draw_str_aligned(canvas, 1, 12, AlignCenter, AlignBottom, coordinates);
+        }
+    }
+
+    if(game_state->state == GameStateGameOver) {
+        // Screen is 128x64 px
+        canvas_set_color(canvas, ColorWhite);
+        canvas_draw_box(canvas, 34, 20, 62, 24);
+
+        canvas_set_color(canvas, ColorBlack);
+        canvas_draw_frame(canvas, 34, 20, 62, 24);
+
+        canvas_set_font(canvas, FontPrimary);
+        canvas_draw_str(canvas, 37, 31, "Game Over");
+
+        canvas_set_font(canvas, FontSecondary);
+        char buffer[12];
+        snprintf(buffer, sizeof(buffer), "Score: %u", game_state->points);
+        canvas_draw_str_aligned(canvas, 64, 41, AlignCenter, AlignBottom, buffer);
+    }
+
+    furi_mutex_release(game_state->mutex);
+}
+
+static void flappy_game_input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
+    furi_assert(event_queue);
+
+    GameEvent event = {.type = EventTypeKey, .input = *input_event};
+    furi_message_queue_put(event_queue, &event, FuriWaitForever);
+}
+
+static void flappy_game_update_timer_callback(FuriMessageQueue* event_queue) {
+    furi_assert(event_queue);
+
+    GameEvent event = {.type = EventTypeTick};
+    furi_message_queue_put(event_queue, &event, 0);
+}
+
+int32_t flappy_game_app(void* p) {
+    UNUSED(p);
+    int32_t return_code = 0;
+
+    FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(GameEvent));
+
+    GameState* game_state = malloc(sizeof(GameState));
+    flappy_game_state_init(game_state);
+
+    game_state->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
+    if(!game_state->mutex) {
+        FURI_LOG_E(TAG, "cannot create mutex\r\n");
+        return_code = 255;
+        goto free_and_exit;
+    }
+
+    // Set system callbacks
+    ViewPort* view_port = view_port_alloc();
+    view_port_draw_callback_set(view_port, flappy_game_render_callback, game_state);
+    view_port_input_callback_set(view_port, flappy_game_input_callback, event_queue);
+
+    FuriTimer* timer =
+        furi_timer_alloc(flappy_game_update_timer_callback, FuriTimerTypePeriodic, event_queue);
+    furi_timer_start(timer, furi_kernel_get_tick_frequency() / 25);
+
+    // Open GUI and register view_port
+    Gui* gui = furi_record_open(RECORD_GUI);
+    gui_add_view_port(gui, view_port, GuiLayerFullscreen);
+
+    // Call dolphin deed on game start
+    dolphin_deed(DolphinDeedPluginGameStart);
+
+    GameEvent event;
+    for(bool processing = true; processing;) {
+        FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
+        furi_mutex_acquire(game_state->mutex, FuriWaitForever);
+
+        if(event_status == FuriStatusOk) {
+            // press events
+            if(event.type == EventTypeKey) {
+                if(event.input.type == InputTypePress) {
+                    switch(event.input.key) {
+                    case InputKeyUp:
+                        if(game_state->state == GameStateLife) {
+                            flappy_game_flap(game_state);
+                        }
+
+                        break;
+                    case InputKeyDown:
+                        break;
+                    case InputKeyRight:
+                        break;
+                    case InputKeyLeft:
+                        break;
+                    case InputKeyOk:
+                        if(game_state->state == GameStateGameOver) {
+                            flappy_game_state_init(game_state);
+                        }
+
+                        if(game_state->state == GameStateLife) {
+                            flappy_game_flap(game_state);
+                        }
+
+                        break;
+                    case InputKeyBack:
+                        processing = false;
+                        break;
+                    default:
+                        break;
+                    }
+                }
+            } else if(event.type == EventTypeTick) {
+                flappy_game_tick(game_state);
+            }
+        }
+
+        view_port_update(view_port);
+        furi_mutex_release(game_state->mutex);
+    }
+
+    furi_timer_free(timer);
+    view_port_enabled_set(view_port, false);
+    gui_remove_view_port(gui, view_port);
+    furi_record_close(RECORD_GUI);
+    view_port_free(view_port);
+    furi_mutex_free(game_state->mutex);
+
+free_and_exit:
+    flappy_game_state_free(game_state);
+    furi_message_queue_free(event_queue);
+
+    return return_code;
+}

+ 44 - 0
main_apps_sources/flipper_i2ctools/README.md

@@ -0,0 +1,44 @@
+# flipperzero-i2ctools
+
+[Original link](https://github.com/NaejEL/flipperzero-i2ctools)
+Set of i2c tools for Flipper Zero
+
+![Preview](i2ctools.gif)
+
+## Wiring
+
+C0 -> SCL
+
+C1 -> SDA
+
+GND -> GND
+
+>/!\ Target must use 3v3 logic levels. If you not sure use an i2c isolator like ISO1541
+
+## Tools
+
+### Scanner
+
+Look for i2c peripherals adresses
+
+### Sniffer
+
+Spy i2c traffic
+
+### Sender
+
+Send command to i2c peripherals and read result 
+
+## TODO
+
+- [ ] Read more than 2 bytes in sender mode
+- [ ] Add 10-bits adresses support
+- [ ] Test with rate > 100khz
+- [ ] Save records
+- [ ] Play from files
+- [ ] Kicad module
+- [ ] Improve UI
+- [ ] Refactor Event Management Code
+- [ ] Add Documentation
+- [ ] Remove max data size
+- [ ] Remove max frames read size

+ 15 - 0
main_apps_sources/flipper_i2ctools/application.fam

@@ -0,0 +1,15 @@
+App(
+    appid="i2c_tools",
+    name="[GPIO] i2c Tools",
+    apptype=FlipperAppType.EXTERNAL,
+    entry_point="i2ctools_app",
+    requires=["gui"],
+    stack_size=2 * 1024,
+    order=175,
+    fap_icon="i2ctools.png",
+    fap_category="GPIO",
+    fap_icon_assets="images",
+    fap_author="@NaejEL",
+    fap_version="1.0",
+    fap_description="Set of i2c tools",
+)

+ 35 - 0
main_apps_sources/flipper_i2ctools/i2cscanner.c

@@ -0,0 +1,35 @@
+#include "i2cscanner.h"
+
+void scan_i2c_bus(i2cScanner* i2c_scanner) {
+    i2c_scanner->nb_found = 0;
+    i2c_scanner->scanned = true;
+    // Get the bus
+    furi_hal_i2c_acquire(I2C_BUS);
+    // scan
+    for(uint8_t addr = 0x01; addr <= MAX_I2C_ADDR << 1; addr++) {
+        // Check for peripherals
+        if(furi_hal_i2c_is_device_ready(I2C_BUS, addr, I2C_TIMEOUT)) {
+            // skip even 8-bit addr
+            if(addr % 2 != 0) {
+                continue;
+            }
+            // convert addr to 7-bits
+            i2c_scanner->addresses[i2c_scanner->nb_found] = addr >> 1;
+            i2c_scanner->nb_found++;
+        }
+    }
+    furi_hal_i2c_release(I2C_BUS);
+}
+
+i2cScanner* i2c_scanner_alloc() {
+    i2cScanner* i2c_scanner = malloc(sizeof(i2cScanner));
+    i2c_scanner->nb_found = 0;
+    i2c_scanner->menu_index = 0;
+    i2c_scanner->scanned = false;
+    return i2c_scanner;
+}
+
+void i2c_scanner_free(i2cScanner* i2c_scanner) {
+    furi_assert(i2c_scanner);
+    free(i2c_scanner);
+}

+ 23 - 0
main_apps_sources/flipper_i2ctools/i2cscanner.h

@@ -0,0 +1,23 @@
+#pragma once
+
+#include <furi.h>
+#include <furi_hal.h>
+
+// I2C BUS
+#define I2C_BUS &furi_hal_i2c_handle_external
+#define I2C_TIMEOUT 3
+
+// 7 bits addresses
+#define MAX_I2C_ADDR 0x7F
+
+typedef struct {
+    uint8_t addresses[MAX_I2C_ADDR + 1];
+    uint8_t nb_found;
+    uint8_t menu_index;
+    bool scanned;
+} i2cScanner;
+
+void scan_i2c_bus(i2cScanner* i2c_scanner);
+
+i2cScanner* i2c_scanner_alloc();
+void i2c_scanner_free(i2cScanner* i2c_scanner);

+ 29 - 0
main_apps_sources/flipper_i2ctools/i2csender.c

@@ -0,0 +1,29 @@
+#include "i2csender.h"
+
+void i2c_send(i2cSender* i2c_sender) {
+    furi_hal_i2c_acquire(I2C_BUS);
+    uint8_t adress = i2c_sender->scanner->addresses[i2c_sender->address_idx] << 1;
+    i2c_sender->error = furi_hal_i2c_trx(
+        I2C_BUS,
+        adress,
+        &i2c_sender->value,
+        sizeof(i2c_sender->value),
+        i2c_sender->recv,
+        sizeof(i2c_sender->recv),
+        I2C_TIMEOUT);
+    furi_hal_i2c_release(I2C_BUS);
+    i2c_sender->must_send = false;
+    i2c_sender->sended = true;
+}
+
+i2cSender* i2c_sender_alloc() {
+    i2cSender* i2c_sender = malloc(sizeof(i2cSender));
+    i2c_sender->must_send = false;
+    i2c_sender->sended = false;
+    return i2c_sender;
+}
+
+void i2c_sender_free(i2cSender* i2c_sender) {
+    furi_assert(i2c_sender);
+    free(i2c_sender);
+}

+ 21 - 0
main_apps_sources/flipper_i2ctools/i2csender.h

@@ -0,0 +1,21 @@
+#pragma once
+
+#include <furi.h>
+#include <furi_hal.h>
+#include "i2cscanner.h"
+
+typedef struct {
+    uint8_t address_idx;
+    uint8_t value;
+    uint8_t recv[2];
+    bool must_send;
+    bool sended;
+    bool error;
+
+    i2cScanner* scanner;
+} i2cSender;
+
+void i2c_send();
+
+i2cSender* i2c_sender_alloc();
+void i2c_sender_free(i2cSender* i2c_sender);

+ 101 - 0
main_apps_sources/flipper_i2ctools/i2csniffer.c

@@ -0,0 +1,101 @@
+#include "i2csniffer.h"
+
+void clear_sniffer_buffers(i2cSniffer* i2c_sniffer) {
+    furi_assert(i2c_sniffer);
+    for(uint8_t i = 0; i < MAX_RECORDS; i++) {
+        for(uint8_t j = 0; j < MAX_MESSAGE_SIZE; j++) {
+            i2c_sniffer->frames[i].ack[j] = false;
+            i2c_sniffer->frames[i].data[j] = 0;
+        }
+        i2c_sniffer->frames[i].bit_index = 0;
+        i2c_sniffer->frames[i].data_index = 0;
+    }
+    i2c_sniffer->frame_index = 0;
+    i2c_sniffer->state = I2C_BUS_FREE;
+    i2c_sniffer->first = true;
+}
+
+void start_interrupts(i2cSniffer* i2c_sniffer) {
+    furi_assert(i2c_sniffer);
+    furi_hal_gpio_init(pinSCL, GpioModeInterruptRise, GpioPullNo, GpioSpeedHigh);
+    furi_hal_gpio_add_int_callback(pinSCL, SCLcallback, i2c_sniffer);
+
+    // Add Rise and Fall Interrupt on SDA pin
+    furi_hal_gpio_init(pinSDA, GpioModeInterruptRiseFall, GpioPullNo, GpioSpeedHigh);
+    furi_hal_gpio_add_int_callback(pinSDA, SDAcallback, i2c_sniffer);
+}
+
+void stop_interrupts() {
+    furi_hal_gpio_remove_int_callback(pinSCL);
+    furi_hal_gpio_remove_int_callback(pinSDA);
+    // Reset GPIO pins to default state
+    furi_hal_gpio_init(pinSCL, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
+    furi_hal_gpio_init(pinSDA, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
+}
+
+// Called on Fallin/Rising SDA
+// Used to monitor i2c bus state
+void SDAcallback(void* _i2c_sniffer) {
+    i2cSniffer* i2c_sniffer = _i2c_sniffer;
+    // SCL is low maybe cclock strecching
+    if(furi_hal_gpio_read(pinSCL) == false) {
+        return;
+    }
+    // Check for stop condition: SDA rising while SCL is High
+    if(i2c_sniffer->state == I2C_BUS_STARTED) {
+        if(furi_hal_gpio_read(pinSDA) == true) {
+            i2c_sniffer->state = I2C_BUS_FREE;
+        }
+    }
+    // Check for start condition: SDA falling while SCL is high
+    else if(furi_hal_gpio_read(pinSDA) == false) {
+        i2c_sniffer->state = I2C_BUS_STARTED;
+        if(i2c_sniffer->first) {
+            i2c_sniffer->first = false;
+            return;
+        }
+        i2c_sniffer->frame_index++;
+        if(i2c_sniffer->frame_index >= MAX_RECORDS) {
+            clear_sniffer_buffers(i2c_sniffer);
+        }
+    }
+    return;
+}
+
+// Called on Rising SCL
+// Used to read bus datas
+void SCLcallback(void* _i2c_sniffer) {
+    i2cSniffer* i2c_sniffer = _i2c_sniffer;
+    if(i2c_sniffer->state == I2C_BUS_FREE) {
+        return;
+    }
+    uint8_t frame = i2c_sniffer->frame_index;
+    uint8_t bit = i2c_sniffer->frames[frame].bit_index;
+    uint8_t data_idx = i2c_sniffer->frames[frame].data_index;
+    if(bit < 8) {
+        i2c_sniffer->frames[frame].data[data_idx] <<= 1;
+        i2c_sniffer->frames[frame].data[data_idx] |= (int)furi_hal_gpio_read(pinSDA);
+        i2c_sniffer->frames[frame].bit_index++;
+    } else {
+        i2c_sniffer->frames[frame].ack[data_idx] = !furi_hal_gpio_read(pinSDA);
+        i2c_sniffer->frames[frame].data_index++;
+        i2c_sniffer->frames[frame].bit_index = 0;
+    }
+}
+
+i2cSniffer* i2c_sniffer_alloc() {
+    i2cSniffer* i2c_sniffer = malloc(sizeof(i2cSniffer));
+    i2c_sniffer->started = false;
+    i2c_sniffer->row_index = 0;
+    i2c_sniffer->menu_index = 0;
+    clear_sniffer_buffers(i2c_sniffer);
+    return i2c_sniffer;
+}
+
+void i2c_sniffer_free(i2cSniffer* i2c_sniffer) {
+    furi_assert(i2c_sniffer);
+    if(i2c_sniffer->started) {
+        stop_interrupts();
+    }
+    free(i2c_sniffer);
+}

+ 46 - 0
main_apps_sources/flipper_i2ctools/i2csniffer.h

@@ -0,0 +1,46 @@
+#pragma once
+
+#include <furi.h>
+#include <furi_hal.h>
+
+// I2C Pins
+#define pinSCL &gpio_ext_pc0
+#define pinSDA &gpio_ext_pc1
+
+// Bus States
+typedef enum { I2C_BUS_FREE, I2C_BUS_STARTED } i2cBusStates;
+
+// Max read size of i2c frame by message
+// Arbitraly defined
+// They're not real limit to maximum frames send
+#define MAX_MESSAGE_SIZE 128
+
+// Nb of records
+#define MAX_RECORDS 128
+
+/// @brief Struct used to store our reads
+typedef struct {
+    uint8_t data[MAX_MESSAGE_SIZE];
+    bool ack[MAX_MESSAGE_SIZE];
+    uint8_t bit_index;
+    uint8_t data_index;
+} i2cFrame;
+
+typedef struct {
+    bool started;
+    bool first;
+    i2cBusStates state;
+    i2cFrame frames[MAX_RECORDS];
+    uint8_t frame_index;
+    uint8_t menu_index;
+    uint8_t row_index;
+} i2cSniffer;
+
+void clear_sniffer_buffers(i2cSniffer* i2c_sniffer);
+void start_interrupts(i2cSniffer* i2c_sniffer);
+void stop_interrupts();
+void SDAcallback(void* _i2c_sniffer);
+void SCLcallback(void* _i2c_sniffer);
+
+i2cSniffer* i2c_sniffer_alloc();
+void i2c_sniffer_free(i2cSniffer* i2c_sniffer);

+ 225 - 0
main_apps_sources/flipper_i2ctools/i2ctools.c

@@ -0,0 +1,225 @@
+#include "i2ctools_i.h"
+
+void i2ctools_draw_callback(Canvas* canvas, void* ctx) {
+    furi_assert(ctx);
+    i2cTools* i2ctools = ctx;
+    furi_mutex_acquire(i2ctools->mutex, FuriWaitForever);
+
+    switch(i2ctools->main_view->current_view) {
+    case MAIN_VIEW:
+        draw_main_view(canvas, i2ctools->main_view);
+        break;
+
+    case SCAN_VIEW:
+        draw_scanner_view(canvas, i2ctools->scanner);
+        break;
+
+    case SNIFF_VIEW:
+        draw_sniffer_view(canvas, i2ctools->sniffer);
+        break;
+
+    case SEND_VIEW:
+        draw_sender_view(canvas, i2ctools->sender);
+        break;
+
+    default:
+        break;
+    }
+    furi_mutex_release(i2ctools->mutex);
+}
+
+void i2ctools_input_callback(InputEvent* input_event, void* ctx) {
+    furi_assert(ctx);
+    FuriMessageQueue* event_queue = ctx;
+    furi_message_queue_put(event_queue, input_event, FuriWaitForever);
+}
+
+int32_t i2ctools_app(void* p) {
+    UNUSED(p);
+    FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(InputEvent));
+
+    // Alloc i2ctools
+    i2cTools* i2ctools = malloc(sizeof(i2cTools));
+    i2ctools->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
+    if(!i2ctools->mutex) {
+        FURI_LOG_E(APP_NAME, "cannot create mutex\r\n");
+        free(i2ctools);
+        return -1;
+    }
+
+    // Alloc viewport
+    i2ctools->view_port = view_port_alloc();
+    view_port_draw_callback_set(i2ctools->view_port, i2ctools_draw_callback, i2ctools);
+    view_port_input_callback_set(i2ctools->view_port, i2ctools_input_callback, event_queue);
+
+    // Register view port in GUI
+    Gui* gui = furi_record_open(RECORD_GUI);
+    gui_add_view_port(gui, i2ctools->view_port, GuiLayerFullscreen);
+
+    InputEvent event;
+
+    i2ctools->main_view = i2c_main_view_alloc();
+
+    i2ctools->sniffer = i2c_sniffer_alloc();
+    i2ctools->sniffer->menu_index = 0;
+
+    i2ctools->scanner = i2c_scanner_alloc();
+
+    i2ctools->sender = i2c_sender_alloc();
+    // Share scanner with sender
+    i2ctools->sender->scanner = i2ctools->scanner;
+
+    while(furi_message_queue_get(event_queue, &event, FuriWaitForever) == FuriStatusOk) {
+        // Back
+        if(event.key == InputKeyBack && event.type == InputTypeRelease) {
+            if(i2ctools->main_view->current_view == MAIN_VIEW) {
+                break;
+            } else {
+                if(i2ctools->main_view->current_view == SNIFF_VIEW) {
+                    stop_interrupts();
+                    i2ctools->sniffer->started = false;
+                    i2ctools->sniffer->state = I2C_BUS_FREE;
+                }
+                i2ctools->main_view->current_view = MAIN_VIEW;
+            }
+        }
+        // Up
+        else if(event.key == InputKeyUp && event.type == InputTypeRelease) {
+            if(i2ctools->main_view->current_view == MAIN_VIEW) {
+                if((i2ctools->main_view->menu_index > SCAN_VIEW)) {
+                    i2ctools->main_view->menu_index--;
+                }
+            } else if(i2ctools->main_view->current_view == SCAN_VIEW) {
+                if(i2ctools->scanner->menu_index > 0) {
+                    i2ctools->scanner->menu_index--;
+                }
+            } else if(i2ctools->main_view->current_view == SNIFF_VIEW) {
+                if(i2ctools->sniffer->row_index > 0) {
+                    i2ctools->sniffer->row_index--;
+                }
+            } else if(i2ctools->main_view->current_view == SEND_VIEW) {
+                if(i2ctools->sender->value < 0xFF) {
+                    i2ctools->sender->value++;
+                    i2ctools->sender->sended = false;
+                }
+            }
+        }
+        // Long Up
+        else if(
+            event.key == InputKeyUp &&
+            (event.type == InputTypeLong || event.type == InputTypeRepeat)) {
+            if(i2ctools->main_view->current_view == SCAN_VIEW) {
+                if(i2ctools->scanner->menu_index > 5) {
+                    i2ctools->scanner->menu_index -= 5;
+                }
+            } else if(i2ctools->main_view->current_view == SEND_VIEW) {
+                if(i2ctools->sender->value < 0xF9) {
+                    i2ctools->sender->value += 5;
+                    i2ctools->sender->sended = false;
+                }
+            } else if(i2ctools->main_view->current_view == SNIFF_VIEW) {
+                if(i2ctools->sniffer->row_index > 5) {
+                    i2ctools->sniffer->row_index -= 5;
+                } else {
+                    i2ctools->sniffer->row_index = 0;
+                }
+            }
+        }
+        // Down
+        else if(event.key == InputKeyDown && event.type == InputTypeRelease) {
+            if(i2ctools->main_view->current_view == MAIN_VIEW) {
+                if(i2ctools->main_view->menu_index < MENU_SIZE - 1) {
+                    i2ctools->main_view->menu_index++;
+                }
+            } else if(i2ctools->main_view->current_view == SCAN_VIEW) {
+                if(i2ctools->scanner->menu_index < ((int)i2ctools->scanner->nb_found / 3)) {
+                    i2ctools->scanner->menu_index++;
+                }
+            } else if(i2ctools->main_view->current_view == SNIFF_VIEW) {
+                if((i2ctools->sniffer->row_index + 3) <
+                   (int)i2ctools->sniffer->frames[i2ctools->sniffer->menu_index].data_index) {
+                    i2ctools->sniffer->row_index++;
+                }
+            } else if(i2ctools->main_view->current_view == SEND_VIEW) {
+                if(i2ctools->sender->value > 0x00) {
+                    i2ctools->sender->value--;
+                    i2ctools->sender->sended = false;
+                }
+            }
+        }
+        // Long Down
+        else if(
+            event.key == InputKeyDown &&
+            (event.type == InputTypeLong || event.type == InputTypeRepeat)) {
+            if(i2ctools->main_view->current_view == SEND_VIEW) {
+                if(i2ctools->sender->value > 0x05) {
+                    i2ctools->sender->value -= 5;
+                    i2ctools->sender->sended = false;
+                } else {
+                    i2ctools->sender->value = 0;
+                    i2ctools->sender->sended = false;
+                }
+            } else if(i2ctools->main_view->current_view == SNIFF_VIEW) {
+                if((i2ctools->sniffer->row_index + 8) <
+                   (int)i2ctools->sniffer->frames[i2ctools->sniffer->menu_index].data_index) {
+                    i2ctools->sniffer->row_index += 5;
+                }
+            }
+
+        } else if(event.key == InputKeyOk && event.type == InputTypeRelease) {
+            if(i2ctools->main_view->current_view == MAIN_VIEW) {
+                i2ctools->main_view->current_view = i2ctools->main_view->menu_index;
+            } else if(i2ctools->main_view->current_view == SCAN_VIEW) {
+                scan_i2c_bus(i2ctools->scanner);
+            } else if(i2ctools->main_view->current_view == SEND_VIEW) {
+                i2ctools->sender->must_send = true;
+            } else if(i2ctools->main_view->current_view == SNIFF_VIEW) {
+                if(i2ctools->sniffer->started) {
+                    stop_interrupts();
+                    i2ctools->sniffer->started = false;
+                    i2ctools->sniffer->state = I2C_BUS_FREE;
+                } else {
+                    start_interrupts(i2ctools->sniffer);
+                    i2ctools->sniffer->started = true;
+                    i2ctools->sniffer->state = I2C_BUS_FREE;
+                }
+            }
+        } else if(event.key == InputKeyRight && event.type == InputTypeRelease) {
+            if(i2ctools->main_view->current_view == SEND_VIEW) {
+                if(i2ctools->sender->address_idx < (i2ctools->scanner->nb_found - 1)) {
+                    i2ctools->sender->address_idx++;
+                    i2ctools->sender->sended = false;
+                }
+            } else if(i2ctools->main_view->current_view == SNIFF_VIEW) {
+                if(i2ctools->sniffer->menu_index < i2ctools->sniffer->frame_index) {
+                    i2ctools->sniffer->menu_index++;
+                    i2ctools->sniffer->row_index = 0;
+                }
+            }
+        } else if(event.key == InputKeyLeft && event.type == InputTypeRelease) {
+            if(i2ctools->main_view->current_view == SEND_VIEW) {
+                if(i2ctools->sender->address_idx > 0) {
+                    i2ctools->sender->address_idx--;
+                    i2ctools->sender->sended = false;
+                }
+            } else if(i2ctools->main_view->current_view == SNIFF_VIEW) {
+                if(i2ctools->sniffer->menu_index > 0) {
+                    i2ctools->sniffer->menu_index--;
+                    i2ctools->sniffer->row_index = 0;
+                }
+            }
+        }
+        view_port_update(i2ctools->view_port);
+    }
+    gui_remove_view_port(gui, i2ctools->view_port);
+    view_port_free(i2ctools->view_port);
+    furi_message_queue_free(event_queue);
+    i2c_sniffer_free(i2ctools->sniffer);
+    i2c_scanner_free(i2ctools->scanner);
+    i2c_sender_free(i2ctools->sender);
+    i2c_main_view_free(i2ctools->main_view);
+    furi_mutex_free(i2ctools->mutex);
+    free(i2ctools);
+    furi_record_close(RECORD_GUI);
+    return 0;
+}

BIN
main_apps_sources/flipper_i2ctools/i2ctools.gif


BIN
main_apps_sources/flipper_i2ctools/i2ctools.png


+ 23 - 0
main_apps_sources/flipper_i2ctools/i2ctools_i.h

@@ -0,0 +1,23 @@
+#include <furi.h>
+#include <furi_hal.h>
+#include <gui/gui.h>
+#include <input/input.h>
+
+#include "i2csniffer.h"
+#include "i2cscanner.h"
+#include "i2csender.h"
+#include "views/main_view.h"
+#include "views/sniffer_view.h"
+#include "views/scanner_view.h"
+#include "views/sender_view.h"
+
+// App datas
+typedef struct {
+    FuriMutex* mutex;
+    ViewPort* view_port;
+    i2cMainView* main_view;
+
+    i2cScanner* scanner;
+    i2cSniffer* sniffer;
+    i2cSender* sender;
+} i2cTools;

BIN
main_apps_sources/flipper_i2ctools/images/ButtonDown_7x4.png


BIN
main_apps_sources/flipper_i2ctools/images/ButtonLeft_4x7.png


BIN
main_apps_sources/flipper_i2ctools/images/ButtonRight_4x7.png


BIN
main_apps_sources/flipper_i2ctools/images/ButtonUp_7x4.png


BIN
main_apps_sources/flipper_i2ctools/images/Ok_btn_9x9.png


BIN
main_apps_sources/flipper_i2ctools/images/i2ctools_main_76x59.png


+ 62 - 0
main_apps_sources/flipper_i2ctools/views/main_view.c

@@ -0,0 +1,62 @@
+#include "main_view.h"
+
+void draw_main_view(Canvas* canvas, i2cMainView* main_view) {
+    canvas_clear(canvas);
+    canvas_set_color(canvas, ColorBlack);
+    canvas_draw_rframe(canvas, 0, 0, 128, 64, 3);
+    canvas_draw_icon(canvas, 2, 2, &I_i2ctools_main_76x59);
+    canvas_set_font(canvas, FontPrimary);
+
+    switch(main_view->menu_index) {
+    case SCAN_VIEW:
+        canvas_set_color(canvas, ColorBlack);
+        canvas_draw_str_aligned(
+            canvas, SNIFF_MENU_X, SNIFF_MENU_Y, AlignLeft, AlignTop, SNIFF_MENU_TEXT);
+        canvas_draw_str_aligned(
+            canvas, SEND_MENU_X, SEND_MENU_Y, AlignLeft, AlignTop, SEND_MENU_TEXT);
+        canvas_draw_rbox(canvas, 80, SCAN_MENU_Y - 2, 43, 13, 3);
+        canvas_set_color(canvas, ColorWhite);
+        canvas_draw_str_aligned(
+            canvas, SCAN_MENU_X, SCAN_MENU_Y, AlignLeft, AlignTop, SCAN_MENU_TEXT);
+        break;
+
+    case SNIFF_VIEW:
+        canvas_set_color(canvas, ColorBlack);
+        canvas_draw_str_aligned(
+            canvas, SCAN_MENU_X, SCAN_MENU_Y, AlignLeft, AlignTop, SCAN_MENU_TEXT);
+        canvas_draw_str_aligned(
+            canvas, SEND_MENU_X, SEND_MENU_Y, AlignLeft, AlignTop, SEND_MENU_TEXT);
+        canvas_draw_rbox(canvas, 80, SNIFF_MENU_Y - 2, 43, 13, 3);
+        canvas_set_color(canvas, ColorWhite);
+        canvas_draw_str_aligned(
+            canvas, SNIFF_MENU_X, SNIFF_MENU_Y, AlignLeft, AlignTop, SNIFF_MENU_TEXT);
+        break;
+
+    case SEND_VIEW:
+        canvas_set_color(canvas, ColorBlack);
+        canvas_draw_str_aligned(
+            canvas, SCAN_MENU_X, SCAN_MENU_Y, AlignLeft, AlignTop, SCAN_MENU_TEXT);
+        canvas_draw_str_aligned(
+            canvas, SNIFF_MENU_X, SNIFF_MENU_Y, AlignLeft, AlignTop, SNIFF_MENU_TEXT);
+        canvas_draw_rbox(canvas, 80, SEND_MENU_Y - 2, 43, 13, 3);
+        canvas_set_color(canvas, ColorWhite);
+        canvas_draw_str_aligned(
+            canvas, SEND_MENU_X, SEND_MENU_Y, AlignLeft, AlignTop, SEND_MENU_TEXT);
+        break;
+
+    default:
+        break;
+    }
+}
+
+i2cMainView* i2c_main_view_alloc() {
+    i2cMainView* main_view = malloc(sizeof(i2cMainView));
+    main_view->menu_index = SCAN_VIEW;
+    main_view->current_view = MAIN_VIEW;
+    return main_view;
+}
+
+void i2c_main_view_free(i2cMainView* main_view) {
+    furi_assert(main_view);
+    free(main_view);
+}

+ 38 - 0
main_apps_sources/flipper_i2ctools/views/main_view.h

@@ -0,0 +1,38 @@
+#include <furi.h>
+#include <furi_hal.h>
+#include <gui/gui.h>
+#include <i2c_tools_icons.h>
+#define APP_NAME "I2C Tools"
+
+#define SCAN_MENU_TEXT "Scan"
+#define SCAN_MENU_X 90
+#define SCAN_MENU_Y 13
+
+#define SNIFF_MENU_TEXT "Sniff"
+#define SNIFF_MENU_X 90
+#define SNIFF_MENU_Y 27
+
+#define SEND_MENU_TEXT "Send"
+#define SEND_MENU_X 90
+#define SEND_MENU_Y 41
+
+// Menu
+typedef enum {
+    MAIN_VIEW,
+    SCAN_VIEW,
+    SNIFF_VIEW,
+    SEND_VIEW,
+
+    /* Know menu Size*/
+    MENU_SIZE
+} i2cToolsViews;
+
+typedef struct {
+    i2cToolsViews current_view;
+    i2cToolsViews menu_index;
+} i2cMainView;
+
+void draw_main_view(Canvas* canvas, i2cMainView* main_view);
+
+i2cMainView* i2c_main_view_alloc();
+void i2c_main_view_free(i2cMainView* main_view);

+ 47 - 0
main_apps_sources/flipper_i2ctools/views/scanner_view.c

@@ -0,0 +1,47 @@
+#include "scanner_view.h"
+
+void draw_scanner_view(Canvas* canvas, i2cScanner* i2c_scanner) {
+    canvas_clear(canvas);
+    canvas_set_color(canvas, ColorBlack);
+    canvas_draw_rframe(canvas, 0, 0, 128, 64, 3);
+
+    char count_text[46];
+    char count_text_fmt[] = "Peripherals Found: %d";
+    canvas_set_font(canvas, FontSecondary);
+    snprintf(count_text, sizeof(count_text), count_text_fmt, (int)i2c_scanner->nb_found);
+    canvas_draw_str_aligned(canvas, 3, 3, AlignLeft, AlignTop, count_text);
+    uint8_t x_pos = 0;
+    uint8_t y_pos = 0;
+    uint8_t idx_to_print = 0;
+    for(uint8_t i = 0; i < (int)i2c_scanner->nb_found; i++) {
+        idx_to_print = i + i2c_scanner->menu_index * 3;
+        if(idx_to_print >= MAX_I2C_ADDR) {
+            break;
+        }
+        snprintf(
+            count_text, sizeof(count_text), "0x%02x ", (int)i2c_scanner->addresses[idx_to_print]);
+        const uint8_t x_start = 3;
+        if(i < 4) {
+            x_pos = x_start + (i * 26);
+            y_pos = 15;
+        } else if(i < 8) {
+            x_pos = x_start + ((i - 4) * 26);
+            y_pos = 25;
+        } else if(i < 12) {
+            x_pos = x_start + ((i - 8) * 26);
+            y_pos = 35;
+        } else {
+            break;
+        }
+        canvas_draw_str_aligned(canvas, x_pos, y_pos, AlignLeft, AlignTop, count_text);
+    }
+    // Right cursor
+    y_pos = 14 + i2c_scanner->menu_index;
+    canvas_draw_rbox(canvas, 125, y_pos, 3, 10, 1);
+
+    // Button
+    canvas_draw_rbox(canvas, 45, 48, 45, 13, 3);
+    canvas_set_color(canvas, ColorWhite);
+    canvas_draw_icon(canvas, 50, 50, &I_Ok_btn_9x9);
+    canvas_draw_str_aligned(canvas, 62, 51, AlignLeft, AlignTop, "Scan");
+}

+ 9 - 0
main_apps_sources/flipper_i2ctools/views/scanner_view.h

@@ -0,0 +1,9 @@
+#include <furi.h>
+#include <furi_hal.h>
+#include <gui/gui.h>
+#include <i2c_tools_icons.h>
+#include "../i2cscanner.h"
+
+#define SCAN_TEXT "SCAN"
+
+void draw_scanner_view(Canvas* canvas, i2cScanner* i2c_scanner);

Неке датотеке нису приказане због велике количине промена