فهرست منبع

Squashed 'simonsays/' changes from 695d20979..f794200af

f794200af fixing some big bugs
3b05ec86b move apps
REVERT: 695d20979 awesome image from flipper-zero.netlify.app
REVERT: 743610414 remove unused vars and fixed load bug
REVERT: b3d5eeb4c bugfix: don't jump straight to game over screen
REVERT: 5b1595f9d minor comment clean up
REVERT: 35dcc9cbc Licensing
REVERT: 2146d0d3b update readme
REVERT: 00b66aba7 Add sound per move
REVERT: 242721c0e first commit to add sound feedback
REVERT: b2d7ae500 utilize numberOfMillisecondsBeforeShapeDisappears
REVERT: 4f3d87829 add automatic save and load
REVERT: 1ed832e52 Make images accessible
REVERT: 4ee1f7090 remove build system specific configs
REVERT: 3b2b6d7c2 ignore binary for now
REVERT: 655136ff7 Update readme and add screenshot
REVERT: 931166603 More appropriate .gitignore for flipper zero
REVERT: ad097ca94 Remove platform agnostic Simon Says
REVERT: d0a8c2592 initial release of Simon Says game
REVERT: ca88ad4d8 update application icon
REVERT: ea1041815 add image assets
REVERT: 1031cc612 update application.fam mainifest
REVERT: 6c1d2ee96 Ignore VS Code configs
REVERT: 2588baa7e Merge pull request #1 from SimplyMinimal/simonController
REVERT: 967226b7e Added the logic for the game in simonsays_controller.h. simonsays_cli.c contains a CLI version of the game.
REVERT: 0f017643a base main game init commit
REVERT: e3331a1de Adding base game
REVERT: d76e7b5ea Initial commit

git-subtree-dir: simonsays
git-subtree-split: f794200af1d65a0dc22fdcdef7d0727e82a48bdf
Willy-JL 2 سال پیش
والد
کامیت
ef480bb5d9
5فایلهای تغییر یافته به همراه24 افزوده شده و 24 حذف شده
  1. BIN
      1.png
  2. BIN
      2.png
  3. BIN
      3.png
  4. 1 1
      application.fam
  5. 23 23
      simon_says.c



+ 1 - 1
application.fam

@@ -9,7 +9,7 @@ App(
     # fap_version=(0, 1),  # (major, minor)
     # fap_version=(0, 1),  # (major, minor)
     fap_icon="simon_says.png",  # 10x10 1-bit PNG
     fap_icon="simon_says.png",  # 10x10 1-bit PNG
     fap_description="A Simon Says Game",
     fap_description="A Simon Says Game",
-    fap_author="SimplyMinimal,ShehabAttia96",
+    fap_author="@SimplyMinimal & @ShehabAttia96",
     fap_weburl="https://github.com/SimplyMinimal/FlipperZero-SimonSays",
     fap_weburl="https://github.com/SimplyMinimal/FlipperZero-SimonSays",
     fap_icon_assets="images",  # Image assets to compile for this application
     fap_icon_assets="images",  # Image assets to compile for this application
 )
 )

+ 23 - 23
simon_says.c

@@ -69,6 +69,7 @@ typedef struct {
 
 
     uint32_t last_button_press_tick;
     uint32_t last_button_press_tick;
     NotificationApp* notification;
     NotificationApp* notification;
+    FuriMutex* mutex;
 } SimonData;
 } SimonData;
 
 
 /* ============================== Sequences ============================== */
 /* ============================== Sequences ============================== */
@@ -189,25 +190,25 @@ void draw_current_score(Canvas* canvas, const SimonData* simon_data) {
     canvas_draw_str_aligned(canvas, SCREEN_XRES / 2 + 4, 2, AlignCenter, AlignTop, str_score);
     canvas_draw_str_aligned(canvas, SCREEN_XRES / 2 + 4, 2, AlignCenter, AlignTop, str_score);
 }
 }
 
 
-void play_sound_up(SimonData* const app) {
+void play_sound_up(const SimonData* app) {
     if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(30)) {
     if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(30)) {
         furi_hal_speaker_start(NOTE_UP, app->volume);
         furi_hal_speaker_start(NOTE_UP, app->volume);
     }
     }
 }
 }
 
 
-void play_sound_down(SimonData* const app) {
+void play_sound_down(const SimonData* app) {
     if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(30)) {
     if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(30)) {
         furi_hal_speaker_start(NOTE_DOWN, app->volume);
         furi_hal_speaker_start(NOTE_DOWN, app->volume);
     }
     }
 }
 }
 
 
-void play_sound_left(SimonData* const app) {
+void play_sound_left(const SimonData* app) {
     if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(30)) {
     if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(30)) {
         furi_hal_speaker_start(NOTE_LEFT, app->volume);
         furi_hal_speaker_start(NOTE_LEFT, app->volume);
     }
     }
 }
 }
 
 
-void play_sound_right(SimonData* const app) {
+void play_sound_right(const SimonData* app) {
     if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(30)) {
     if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(30)) {
         furi_hal_speaker_start(NOTE_RIGHT, app->volume);
         furi_hal_speaker_start(NOTE_RIGHT, app->volume);
     }
     }
@@ -222,13 +223,10 @@ void stop_sound() {
 
 
 /* Main Render Function */
 /* Main Render Function */
 void simon_draw_callback(Canvas* canvas, void* ctx) {
 void simon_draw_callback(Canvas* canvas, void* ctx) {
-    SimonData* const simon_state = acquire_mutex((ValueMutex*)ctx, 25);
-    if(simon_state == NULL) {
-        if(DEBUG_MSG) FURI_LOG_E(TAG, "[simon_draw_callback] Null simon state");
-        return;
-    }
+    furi_assert(ctx);
+    const SimonData* simon_state = ctx;
+    furi_mutex_acquire(simon_state->mutex, FuriWaitForever);
 
 
-    UNUSED(ctx);
     canvas_clear(canvas);
     canvas_clear(canvas);
 
 
     // ######################### Main Menu #########################
     // ######################### Main Menu #########################
@@ -358,7 +356,7 @@ void simon_draw_callback(Canvas* canvas, void* ctx) {
     //TODO
     //TODO
 
 
     //release the mutex
     //release the mutex
-    release_mutex((ValueMutex*)ctx, simon_state);
+    furi_mutex_release(simon_state->mutex);
 }
 }
 
 
 /* ======================== Input Handling ============================== */
 /* ======================== Input Handling ============================== */
@@ -556,8 +554,9 @@ int32_t simon_says_app_entry(void* p) {
     FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(InputEvent));
     FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(InputEvent));
 
 
     SimonData* simon_state = malloc(sizeof(SimonData));
     SimonData* simon_state = malloc(sizeof(SimonData));
-    ValueMutex simon_state_value_mutex;
-    if(!init_mutex(&simon_state_value_mutex, simon_state, sizeof(SimonData))) {
+
+    simon_state->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
+    if(!simon_state->mutex) {
         FURI_LOG_E(TAG, "cannot create mutex\r\n");
         FURI_LOG_E(TAG, "cannot create mutex\r\n");
         free(simon_state);
         free(simon_state);
         return -1;
         return -1;
@@ -565,7 +564,7 @@ int32_t simon_says_app_entry(void* p) {
 
 
     // Configure view port
     // Configure view port
     ViewPort* view_port = view_port_alloc();
     ViewPort* view_port = view_port_alloc();
-    view_port_draw_callback_set(view_port, simon_draw_callback, &simon_state_value_mutex);
+    view_port_draw_callback_set(view_port, simon_draw_callback, simon_state);
     view_port_input_callback_set(view_port, simon_input_callback, event_queue);
     view_port_input_callback_set(view_port, simon_input_callback, event_queue);
 
 
     // Register view port in GUI
     // Register view port in GUI
@@ -578,7 +577,7 @@ int32_t simon_says_app_entry(void* p) {
     InputEvent input;
     InputEvent input;
 
 
     // Show Main Menu Screen
     // Show Main Menu Screen
-    load_game(simon_state);
+    //load_game(simon_state);
     restart_game_after_gameover(simon_state);
     restart_game_after_gameover(simon_state);
     simon_state->gameState = mainMenu;
     simon_state->gameState = mainMenu;
 
 
@@ -587,15 +586,16 @@ int32_t simon_says_app_entry(void* p) {
 
 
         FuriStatus q_status = furi_message_queue_get(
         FuriStatus q_status = furi_message_queue_get(
             event_queue, &input, simon_state->numberOfMillisecondsBeforeShapeDisappears);
             event_queue, &input, simon_state->numberOfMillisecondsBeforeShapeDisappears);
+        furi_mutex_acquire(simon_state->mutex, FuriWaitForever);
 
 
         if(q_status == FuriStatusOk) {
         if(q_status == FuriStatusOk) {
-            FURI_LOG_D(TAG, "Got input event: %d", input.key);
+            //FURI_LOG_D(TAG, "Got input event: %d", input.key);
             //break out of the loop if the back key is pressed
             //break out of the loop if the back key is pressed
             if(input.key == InputKeyBack && input.type == InputTypeLong) {
             if(input.key == InputKeyBack && input.type == InputTypeLong) {
                 // Save high score before quitting
                 // Save high score before quitting
-                if(simon_state->is_new_highscore) {
-                    save_game(simon_state);
-                }
+                //if(simon_state->is_new_highscore) {
+                //  save_game(simon_state);
+                //}
                 break;
                 break;
             }
             }
 
 
@@ -636,12 +636,10 @@ int32_t simon_says_app_entry(void* p) {
                         break;
                         break;
                     }
                     }
                 } else {
                 } else {
-                    FURI_LOG_D(TAG, "Input type is not short");
+                    //FURI_LOG_D(TAG, "Input type is not short");
                     simon_state->set_board_neutral = true;
                     simon_state->set_board_neutral = true;
                 }
                 }
             }
             }
-        } else {
-            FURI_LOG_E(TAG, "cannot get message from queue\r\n");
         }
         }
 
 
         // @todo Animation Loop for debug
         // @todo Animation Loop for debug
@@ -650,6 +648,7 @@ int32_t simon_says_app_entry(void* p) {
         //     simon_state->set_board_neutral = !simon_state->set_board_neutral;
         //     simon_state->set_board_neutral = !simon_state->set_board_neutral;
         // }
         // }
 
 
+        furi_mutex_release(simon_state->mutex);
         view_port_update(view_port);
         view_port_update(view_port);
     }
     }
 
 
@@ -658,9 +657,10 @@ int32_t simon_says_app_entry(void* p) {
     gui_remove_view_port(gui, view_port);
     gui_remove_view_port(gui, view_port);
     view_port_free(view_port);
     view_port_free(view_port);
     furi_message_queue_free(event_queue);
     furi_message_queue_free(event_queue);
-    free(simon_state);
+    furi_mutex_free(simon_state->mutex);
     furi_record_close(RECORD_NOTIFICATION);
     furi_record_close(RECORD_NOTIFICATION);
     furi_record_close(RECORD_GUI);
     furi_record_close(RECORD_GUI);
+    free(simon_state);
 
 
     return 0;
     return 0;
 }
 }