Skip to content

Commit 80af529

Browse files
committed
upd colorguess
1 parent 5597c36 commit 80af529

14 files changed

+89
-50
lines changed

apps_source_code/color_guess/README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,7 @@ Then run the command:
2929
The application will be compiled and copied onto your device.
3030

3131
## Licensing
32-
This code is open-source and may be used for whatever you want to do with it.
32+
This code is open-source under the conditions of GNU GENERAL PUBLIC LICENSE.
33+
34+
## Credits
35+
Thanks to [Willy-JL](https://github.com/Willy-JL) for assisting in the fine-tuning of the app

apps_source_code/color_guess/application.fam

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ App(
99
],
1010
stack_size=2 * 1024,
1111
order=10,
12-
fap_icon="color_guess_10px.png",
12+
fap_icon="icons/color_guess_10px.png",
1313
fap_icon_assets="icons",
14-
fap_version="1.2",
14+
fap_version="1.5",
1515
fap_category="Games",
1616
fap_author="Leedave",
1717
fap_description="Color Guessing Game",
1818
fap_weburl="https://github.com/leedave/Leeds-Flipper-Zero-Applications",
19-
)
19+
)

apps_source_code/color_guess/color_guess.c

+21-22
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ ColorGuess* color_guess_app_alloc() {
3434
// Load configs
3535
color_guess_read_settings(app);
3636

37-
NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
38-
notification_message(notification, &sequence_display_backlight_on);
37+
notification_message(app->notification, &sequence_display_backlight_on);
3938

4039
//Scene additions
4140
app->view_dispatcher = view_dispatcher_alloc();
@@ -49,30 +48,30 @@ ColorGuess* color_guess_app_alloc() {
4948
app->view_dispatcher, color_guess_tick_event_callback, 100);
5049
view_dispatcher_set_custom_event_callback(
5150
app->view_dispatcher, color_guess_custom_event_callback);
52-
app->submenu = submenu_alloc();
5351

54-
view_dispatcher_add_view(
55-
app->view_dispatcher, ColorGuessViewIdMenu, submenu_get_view(app->submenu));
56-
app->variable_item_list = variable_item_list_alloc();
57-
view_dispatcher_add_view(
58-
app->view_dispatcher,
59-
ColorGuessViewIdSettings,
60-
variable_item_list_get_view(app->variable_item_list));
6152
app->color_guess_startscreen = color_guess_startscreen_alloc();
6253
view_dispatcher_add_view(
6354
app->view_dispatcher,
6455
ColorGuessViewIdStartscreen,
6556
color_guess_startscreen_get_view(app->color_guess_startscreen));
57+
app->submenu = submenu_alloc();
58+
view_dispatcher_add_view(
59+
app->view_dispatcher, ColorGuessViewIdMenu, submenu_get_view(app->submenu));
60+
app->color_guess_play = color_guess_play_alloc();
61+
view_dispatcher_add_view(
62+
app->view_dispatcher,
63+
ColorGuessViewIdPlay,
64+
color_guess_play_get_view(app->color_guess_play));
6665
app->color_guess_color_set = color_guess_color_set_alloc();
6766
view_dispatcher_add_view(
6867
app->view_dispatcher,
6968
ColorGuessViewIdColorSet,
7069
color_guess_color_set_get_view(app->color_guess_color_set));
71-
app->color_guess_play = color_guess_play_alloc();
70+
app->variable_item_list = variable_item_list_alloc();
7271
view_dispatcher_add_view(
7372
app->view_dispatcher,
74-
ColorGuessViewIdPlay,
75-
color_guess_play_get_view(app->color_guess_play));
73+
ColorGuessViewIdSettings,
74+
variable_item_list_get_view(app->variable_item_list));
7675

7776
//End Scene Additions
7877

@@ -86,16 +85,21 @@ void color_guess_app_free(ColorGuess* app) {
8685
scene_manager_free(app->scene_manager);
8786

8887
// View Dispatcher
89-
view_dispatcher_remove_view(app->view_dispatcher, ColorGuessViewIdMenu);
9088
view_dispatcher_remove_view(app->view_dispatcher, ColorGuessViewIdStartscreen);
91-
view_dispatcher_remove_view(app->view_dispatcher, ColorGuessViewIdColorSet);
89+
color_guess_startscreen_free(app->color_guess_startscreen);
90+
view_dispatcher_remove_view(app->view_dispatcher, ColorGuessViewIdMenu);
91+
submenu_free(app->submenu);
9292
view_dispatcher_remove_view(app->view_dispatcher, ColorGuessViewIdPlay);
93+
color_guess_play_free(app->color_guess_play);
94+
view_dispatcher_remove_view(app->view_dispatcher, ColorGuessViewIdColorSet);
95+
color_guess_color_set_free(app->color_guess_color_set);
9396
view_dispatcher_remove_view(app->view_dispatcher, ColorGuessViewIdSettings);
94-
submenu_free(app->submenu);
97+
variable_item_list_free(app->variable_item_list);
9598

9699
view_dispatcher_free(app->view_dispatcher);
97100

98-
// GUI
101+
// Records
102+
furi_record_close(RECORD_NOTIFICATION);
99103
furi_record_close(RECORD_GUI);
100104

101105
app->view_port = NULL;
@@ -113,11 +117,6 @@ int32_t color_guess_app(void* p) {
113117
return 255;
114118
}
115119

116-
if(!furi_hal_region_is_provisioned()) {
117-
color_guess_app_free(app);
118-
return 1;
119-
}
120-
121120
view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
122121

123122
scene_manager_next_scene(app->scene_manager, ColorGuessSceneStartscreen);

apps_source_code/color_guess/color_guess.h

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "views/color_guess_startscreen.h"
1818
#include "helpers/color_guess_storage.h"
1919

20+
#define COLOR_GUESS_VERSION "1.5"
2021
#define TAG "Color_Guess"
2122

2223
typedef struct {
-7.64 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
## 1.5
2+
- Additional Memory Management fixes by Willy-JL
3+
- Redraw Issue fixed by Willy-JL
4+
- Added GNU License
5+
- Added version number
6+
7+
## 1.4
8+
- Prevent value changing on win view
9+
- Fix issues with FW build 0.99.x
10+
11+
## 1.3
12+
- Patched Memory Leak in storage
13+
14+
## v1.2
15+
- Updated compatibility to 0.95.0-rc
16+
17+
## v1.1
18+
- Updated Launch Screen GFX
19+
120
## v1.0
221

322
First release to Application Catalog

apps_source_code/color_guess/helpers/color_guess_haptic.h

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#pragma once
2+
13
#include <notification/notification_messages.h>
24

35
void color_guess_play_happy_bump(void* context);

apps_source_code/color_guess/helpers/color_guess_led.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
#pragma once
22

33
void color_guess_led_set_rgb(void* context, int red, int green, int blue);
44

apps_source_code/color_guess/helpers/color_guess_storage.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ void color_guess_read_settings(void* context) {
8585
FURI_LOG_E(TAG, "Cannot open file %s", COLOR_GUESS_SETTINGS_SAVE_PATH);
8686
color_guess_close_config_file(fff_file);
8787
color_guess_close_storage();
88+
furi_string_free(temp_str);
8889
return;
8990
}
9091

@@ -95,14 +96,15 @@ void color_guess_read_settings(void* context) {
9596
furi_string_free(temp_str);
9697
return;
9798
}
98-
furi_string_free(temp_str);
9999

100100
if(file_version < COLOR_GUESS_SETTINGS_FILE_VERSION) {
101101
FURI_LOG_I(TAG, "old config version, will be removed.");
102102
color_guess_close_config_file(fff_file);
103103
color_guess_close_storage();
104+
furi_string_free(temp_str);
104105
return;
105106
}
107+
furi_string_free(temp_str);
106108

107109
flipper_format_read_uint32(fff_file, COLOR_GUESS_SETTINGS_KEY_HAPTIC, &app->haptic, 1);
108110
flipper_format_read_uint32(fff_file, COLOR_GUESS_SETTINGS_KEY_LED, &app->led, 1);
Loading

apps_source_code/color_guess/scenes/color_guess_scene_play.c

+7
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ bool color_guess_scene_play_on_event(void* context, SceneManagerEvent event) {
3939
consumed = true;
4040
break;
4141
}
42+
} else if(event.type == SceneManagerEventTypeTick) {
43+
// Redraw on tick event to update timer
44+
with_view_model(
45+
color_guess_play_get_view(app->color_guess_play),
46+
void* model,
47+
{ UNUSED(model); },
48+
true);
4249
}
4350

4451
return consumed;

apps_source_code/color_guess/views/color_guess_color_set.c

-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
#include <gui/elements.h>
88
#include <dolphin/dolphin.h>
99

10-
//extern const Icon* digits[17];
11-
1210
struct ColorGuessColorSet {
1311
View* view;
1412
ColorGuessColorSetCallback callback;

apps_source_code/color_guess/views/color_guess_play.c

+25-18
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
#include <input/input.h>
99
#include <gui/elements.h>
1010
#include <dolphin/dolphin.h>
11-
12-
//extern const Icon* digits[17];
11+
#include <lib/datetime/datetime.h>
1312

1413
struct ColorGuessPlay {
1514
View* view;
@@ -215,9 +214,11 @@ bool color_guess_play_input(InputEvent* event, void* context) {
215214
instance->view,
216215
ColorGuessPlayModel * model,
217216
{
218-
model->cursorpos--;
219-
if(model->cursorpos < 0) {
220-
model->cursorpos = 5;
217+
if(model->success != 1) {
218+
model->cursorpos--;
219+
if(model->cursorpos < 0) {
220+
model->cursorpos = 5;
221+
}
221222
}
222223
},
223224
true);
@@ -227,9 +228,11 @@ bool color_guess_play_input(InputEvent* event, void* context) {
227228
instance->view,
228229
ColorGuessPlayModel * model,
229230
{
230-
model->cursorpos++;
231-
if(model->cursorpos > 5) {
232-
model->cursorpos = 0;
231+
if(model->success != 1) {
232+
model->cursorpos++;
233+
if(model->cursorpos > 5) {
234+
model->cursorpos = 0;
235+
}
233236
}
234237
},
235238
true);
@@ -239,12 +242,14 @@ bool color_guess_play_input(InputEvent* event, void* context) {
239242
instance->view,
240243
ColorGuessPlayModel * model,
241244
{
242-
model->digit[model->cursorpos]++;
243-
if(model->digit[model->cursorpos] > 15) {
244-
model->digit[model->cursorpos] = 0;
245+
if(model->success != 1) {
246+
model->digit[model->cursorpos]++;
247+
if(model->digit[model->cursorpos] > 15) {
248+
model->digit[model->cursorpos] = 0;
249+
}
250+
color_guess_play_calculate_closeness(instance, model);
251+
play_haptic(instance->context, model);
245252
}
246-
color_guess_play_calculate_closeness(instance, model);
247-
play_haptic(instance->context, model);
248253
},
249254
true);
250255
break;
@@ -253,12 +258,14 @@ bool color_guess_play_input(InputEvent* event, void* context) {
253258
instance->view,
254259
ColorGuessPlayModel * model,
255260
{
256-
model->digit[model->cursorpos]--;
257-
if(model->digit[model->cursorpos] < 0) {
258-
model->digit[model->cursorpos] = 15;
261+
if(model->success != 1) {
262+
model->digit[model->cursorpos]--;
263+
if(model->digit[model->cursorpos] < 0) {
264+
model->digit[model->cursorpos] = 15;
265+
}
266+
color_guess_play_calculate_closeness(instance, model);
267+
play_haptic(instance->context, model);
259268
}
260-
color_guess_play_calculate_closeness(instance, model);
261-
play_haptic(instance->context, model);
262269
},
263270
true);
264271
break;

apps_source_code/color_guess/views/color_guess_startscreen.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ void color_guess_startscreen_set_callback(
2828

2929
void color_guess_startscreen_draw(Canvas* canvas, ColorGuessStartscreenModel* model) {
3030
UNUSED(model);
31+
char buffer[64];
3132
canvas_clear(canvas);
3233
canvas_set_color(canvas, ColorBlack);
3334
canvas_set_font(canvas, FontPrimary);
@@ -36,6 +37,8 @@ void color_guess_startscreen_draw(Canvas* canvas, ColorGuessStartscreenModel* mo
3637
canvas_set_font(canvas, FontSecondary);
3738
canvas_draw_str_aligned(canvas, 54, 22, AlignLeft, AlignTop, "Guess the color");
3839
canvas_draw_str_aligned(canvas, 54, 32, AlignLeft, AlignTop, "on Flipper's LED");
40+
snprintf(buffer, sizeof(buffer), "Ver. %s", COLOR_GUESS_VERSION);
41+
canvas_draw_str_aligned(canvas, 92, 56, AlignLeft, AlignTop, buffer);
3942
elements_button_center(canvas, "Start");
4043
}
4144

@@ -115,8 +118,6 @@ ColorGuessStartscreen* color_guess_startscreen_alloc() {
115118
void color_guess_startscreen_free(ColorGuessStartscreen* instance) {
116119
furi_assert(instance);
117120

118-
with_view_model(
119-
instance->view, ColorGuessStartscreenModel * model, { UNUSED(model); }, true);
120121
view_free(instance->view);
121122
free(instance);
122123
}

0 commit comments

Comments
 (0)