RaZe 3 лет назад
Родитель
Сommit
fae3453b59
1 измененных файлов с 53 добавлено и 43 удалено
  1. 53 43
      rubiks_cube_scrambler.c

+ 53 - 43
rubiks_cube_scrambler.c

@@ -7,12 +7,13 @@
 #include "scrambler.h"
 #include "scrambler.h"
 #include <furi_hal.h>
 #include <furi_hal.h>
 
 
-char* currentKeyPressed;
+char *currentKeyPressed;
 int BUFFER = 10;
 int BUFFER = 10;
 char scramble[100] = {0};
 char scramble[100] = {0};
 int notifications_enabled = 0;
 int notifications_enabled = 0;
 
 
-static void success_vibration() {
+static void success_vibration()
+{
     furi_hal_vibro_on(false);
     furi_hal_vibro_on(false);
     furi_hal_vibro_on(true);
     furi_hal_vibro_on(true);
     furi_delay_ms(50);
     furi_delay_ms(50);
@@ -20,90 +21,99 @@ static void success_vibration() {
     return;
     return;
 }
 }
 
 
-static void draw_callback(Canvas* canvas, void* ctx) {
+static void draw_callback(Canvas *canvas, void *ctx)
+{
     UNUSED(ctx);
     UNUSED(ctx);
     canvas_clear(canvas);
     canvas_clear(canvas);
     canvas_set_font(canvas, FontPrimary);
     canvas_set_font(canvas, FontPrimary);
     canvas_draw_str(canvas, 0, 13, "Rubik's Cube Scrambler");
     canvas_draw_str(canvas, 0, 13, "Rubik's Cube Scrambler");
 
 
-        
-    if(strcmp(currentKeyPressed, "OK") == 0) {
-/*         const char* moves[] = {"U", "D", "L", "R", "F", "B"};
-        const char* directions[] = {"", "'", "2"};
-        int index = 0;
-        int prevMove = -1; // Initialize previous move to an invalid value
-        for(int i = 0; i < 10; i++) {
-            int move;
-            do {
-                move = rand() % 6;
-            } while(move == prevMove);
-            int direction = rand() % 3;
-            prevMove = move;
-            index += snprintf(
-                scramble + index,
-                sizeof(scramble) - index,
-                "%s%s ",
-                moves[move],
-                directions[direction]);
-        } */
-        genScramble ();
+    if (strcmp(currentKeyPressed, "OK") == 0)
+    {
+        /*         const char* moves[] = {"U", "D", "L", "R", "F", "B"};
+                const char* directions[] = {"", "'", "2"};
+                int index = 0;
+                int prevMove = -1; // Initialize previous move to an invalid value
+                for(int i = 0; i < 10; i++) {
+                    int move;
+                    do {
+                        move = rand() % 6;
+                    } while(move == prevMove);
+                    int direction = rand() % 3;
+                    prevMove = move;
+                    index += snprintf(
+                        scramble + index,
+                        sizeof(scramble) - index,
+                        "%s%s ",
+                        moves[move],
+                        directions[direction]);
+                } */
+        genScramble();
         scrambleReplace();
         scrambleReplace();
         valid();
         valid();
         char *data = printData();
         char *data = printData();
         strcpy(scramble, data);
         strcpy(scramble, data);
         free(data);
         free(data);
-        if (notifications_enabled) {
+        if (notifications_enabled)
+        {
             success_vibration();
             success_vibration();
         }
         }
         currentKeyPressed = "";
         currentKeyPressed = "";
     }
     }
     canvas_set_font(canvas, FontSecondary);
     canvas_set_font(canvas, FontSecondary);
     canvas_draw_str(canvas, 0, 30, scramble);
     canvas_draw_str(canvas, 0, 30, scramble);
-    
+
     elements_button_center(canvas, "New");
     elements_button_center(canvas, "New");
-    
+
     elements_button_left(canvas, notifications_enabled ? "On" : "Off");
     elements_button_left(canvas, notifications_enabled ? "On" : "Off");
 };
 };
 
 
-
-static void input_callback(InputEvent* input_event, void* ctx) {
+static void input_callback(InputEvent *input_event, void *ctx)
+{
     furi_assert(ctx);
     furi_assert(ctx);
-    FuriMessageQueue* event_queue = ctx;
+    FuriMessageQueue *event_queue = ctx;
     furi_message_queue_put(event_queue, input_event, FuriWaitForever);
     furi_message_queue_put(event_queue, input_event, FuriWaitForever);
 }
 }
 
 
-int32_t rubiks_cube_scrambler_main(void* p) {
+int32_t rubiks_cube_scrambler_main(void *p)
+{
     UNUSED(p);
     UNUSED(p);
-    currentKeyPressed = (char*)malloc(sizeof(char) * BUFFER);
+    currentKeyPressed = (char *)malloc(sizeof(char) * BUFFER);
     InputEvent event;
     InputEvent event;
 
 
-    FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(InputEvent));
+    FuriMessageQueue *event_queue = furi_message_queue_alloc(8, sizeof(InputEvent));
 
 
-    ViewPort* view_port = view_port_alloc();
+    ViewPort *view_port = view_port_alloc();
 
 
     view_port_draw_callback_set(view_port, draw_callback, NULL);
     view_port_draw_callback_set(view_port, draw_callback, NULL);
 
 
     view_port_input_callback_set(view_port, input_callback, event_queue);
     view_port_input_callback_set(view_port, input_callback, event_queue);
-    
-    
-    Gui* gui = furi_record_open(RECORD_GUI);
+
+    Gui *gui = furi_record_open(RECORD_GUI);
     gui_add_view_port(gui, view_port, GuiLayerFullscreen);
     gui_add_view_port(gui, view_port, GuiLayerFullscreen);
 
 
-    while(true) {
+    while (true)
+    {
         furi_check(furi_message_queue_get(event_queue, &event, FuriWaitForever) == FuriStatusOk);
         furi_check(furi_message_queue_get(event_queue, &event, FuriWaitForever) == FuriStatusOk);
 
 
-        if(event.key == InputKeyOk && event.type == InputTypeShort) {
+        if (event.key == InputKeyOk && event.type == InputTypeShort)
+        {
             currentKeyPressed = "OK";
             currentKeyPressed = "OK";
         }
         }
-        if (event.key == InputKeyLeft && event.type == InputTypeShort) {
-            if (notifications_enabled) {
+        if (event.key == InputKeyLeft && event.type == InputTypeShort)
+        {
+            if (notifications_enabled)
+            {
                 notifications_enabled = 0;
                 notifications_enabled = 0;
-            } else {
+            }
+            else
+            {
                 notifications_enabled = 1;
                 notifications_enabled = 1;
                 success_vibration();
                 success_vibration();
             }
             }
         }
         }
-        if(event.key == InputKeyBack) {
+        if (event.key == InputKeyBack)
+        {
             break;
             break;
         }
         }
     }
     }