|
|
@@ -4,7 +4,6 @@
|
|
|
#include <input/input.h>
|
|
|
#include <gui/elements.h>
|
|
|
#include <furi_hal.h>
|
|
|
-#include <gui/modules/submenu.h>
|
|
|
|
|
|
#include "scrambler.h"
|
|
|
#include "furi_hal_random.h"
|
|
|
@@ -23,17 +22,24 @@ static void success_vibration()
|
|
|
furi_hal_vibro_on(false);
|
|
|
return;
|
|
|
}
|
|
|
-void split_array(char original[], int size, char first[], char second[]) {
|
|
|
+void split_array(char original[], int size, char first[], char second[])
|
|
|
+{
|
|
|
int32_t mid = size / 2;
|
|
|
- if (size % 2 != 0) {
|
|
|
+ if (size % 2 != 0)
|
|
|
+ {
|
|
|
mid++;
|
|
|
}
|
|
|
int32_t first_index = 0, second_index = 0;
|
|
|
- for (int32_t i = 0; i < size; i++) {
|
|
|
- if (i < mid) {
|
|
|
+ for (int32_t i = 0; i < size; i++)
|
|
|
+ {
|
|
|
+ if (i < mid)
|
|
|
+ {
|
|
|
first[first_index++] = original[i];
|
|
|
- } else {
|
|
|
- if (i == mid && (original[i] == '2' || original[i] == '\'')) {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (i == mid && (original[i] == '2' || original[i] == '\''))
|
|
|
+ {
|
|
|
continue;
|
|
|
}
|
|
|
second[second_index++] = original[i];
|
|
|
@@ -42,7 +48,12 @@ void split_array(char original[], int size, char first[], char second[]) {
|
|
|
first[first_index] = '\0';
|
|
|
second[second_index] = '\0';
|
|
|
}
|
|
|
-
|
|
|
+void genScramble()
|
|
|
+{
|
|
|
+ scrambleReplace();
|
|
|
+ strcpy(scramble_str, printData());
|
|
|
+ split_array(scramble_str, strlen(scramble_str), scramble_start, scramble_end);
|
|
|
+}
|
|
|
|
|
|
static void draw_callback(Canvas *canvas, void *ctx)
|
|
|
{
|
|
|
@@ -50,18 +61,6 @@ static void draw_callback(Canvas *canvas, void *ctx)
|
|
|
canvas_clear(canvas);
|
|
|
canvas_set_font(canvas, FontPrimary);
|
|
|
canvas_draw_str(canvas, 4, 13, "Rubik's Cube Scrambler");
|
|
|
-
|
|
|
- if (scrambleStarted)
|
|
|
- {
|
|
|
- scrambleReplace();
|
|
|
- strcpy(scramble_str, printData());
|
|
|
- if (notifications_enabled)
|
|
|
- {
|
|
|
- success_vibration();
|
|
|
- }
|
|
|
- split_array(scramble_str, strlen(scramble_str), scramble_start, scramble_end);
|
|
|
- scrambleStarted = 0;
|
|
|
- }
|
|
|
canvas_set_font(canvas, FontSecondary);
|
|
|
canvas_draw_str_aligned(canvas, 64, 28, AlignCenter, AlignCenter, scramble_start);
|
|
|
canvas_draw_str_aligned(canvas, 64, 38, AlignCenter, AlignCenter, scramble_end);
|
|
|
@@ -72,6 +71,7 @@ static void draw_callback(Canvas *canvas, void *ctx)
|
|
|
|
|
|
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);
|
|
|
@@ -99,7 +99,11 @@ int32_t rubiks_cube_scrambler_main(void *p)
|
|
|
|
|
|
if (event.key == InputKeyOk && event.type == InputTypeShort)
|
|
|
{
|
|
|
- scrambleStarted = true;
|
|
|
+ genScramble();
|
|
|
+ if (notifications_enabled)
|
|
|
+ {
|
|
|
+ success_vibration();
|
|
|
+ }
|
|
|
}
|
|
|
if (event.key == InputKeyLeft && event.type == InputTypeShort)
|
|
|
{
|
|
|
@@ -122,7 +126,7 @@ int32_t rubiks_cube_scrambler_main(void *p)
|
|
|
furi_message_queue_free(event_queue);
|
|
|
|
|
|
gui_remove_view_port(gui, view_port);
|
|
|
-
|
|
|
+
|
|
|
view_port_free(view_port);
|
|
|
furi_record_close(RECORD_GUI);
|
|
|
return 0;
|