@@ -23,8 +23,10 @@ typedef struct {
23
23
int color ;
24
24
int time_spent ;
25
25
int timestamp_start ;
26
+ int prev_closeness ;
26
27
int closeness ;
27
28
int difficulty ;
29
+ int success ;
28
30
} ColorGuessPlayModel ;
29
31
30
32
void color_guess_play_set_callback (
@@ -37,13 +39,36 @@ void color_guess_play_set_callback(
37
39
instance -> context = context ;
38
40
}
39
41
42
+ void play_happy_bop (void * context , ColorGuessPlayModel * model ) {
43
+ ColorGuess * app = context ;
44
+ if (model -> success == 1 ) {
45
+ for (int i = 0 ; i < 4 ; i ++ ) {
46
+ notification_message (app -> notification , & sequence_set_vibro_on );
47
+ furi_thread_flags_wait (0 , FuriFlagWaitAny , 50 );
48
+ notification_message (app -> notification , & sequence_reset_vibro );
49
+ furi_thread_flags_wait (0 , FuriFlagWaitAny , 100 );
50
+ }
51
+ } else if (model -> closeness > model -> prev_closeness ) {
52
+ notification_message (app -> notification , & sequence_set_vibro_on );
53
+ furi_thread_flags_wait (0 , FuriFlagWaitAny , 20 );
54
+ notification_message (app -> notification , & sequence_reset_vibro );
55
+ } else if (model -> closeness < model -> prev_closeness ) {
56
+ notification_message (app -> notification , & sequence_set_vibro_on );
57
+ furi_thread_flags_wait (0 , FuriFlagWaitAny , 100 );
58
+ notification_message (app -> notification , & sequence_reset_vibro );
59
+ }
60
+ }
61
+
40
62
void color_guess_play_new_round (void * context , ColorGuessPlayModel * model ) {
41
63
furi_assert (context );
42
64
ColorGuess * app = context ;
43
65
//Reset timer
44
66
FuriHalRtcDateTime date_time ;
45
67
furi_hal_rtc_get_datetime (& date_time );
46
68
model -> timestamp_start = furi_hal_rtc_datetime_to_timestamp (& date_time );
69
+ model -> success = 0 ;
70
+ model -> closeness = 0 ;
71
+ model -> prev_closeness = 0 ;
47
72
48
73
//Set random color
49
74
NotificationMessage notification_led_message_1 ;
@@ -65,8 +90,6 @@ void color_guess_play_new_round(void* context, ColorGuessPlayModel* model) {
65
90
notification_led_message_2 .data .led .value = ((model -> color >> 8 ) & 0xFF );
66
91
notification_led_message_3 .data .led .value = ((model -> color ) & 0xFF );
67
92
68
- //model->closeness = ((model->color >> 8) & 0xFF);
69
-
70
93
const NotificationSequence notification_sequence = {
71
94
& notification_led_message_1 ,
72
95
& notification_led_message_2 ,
@@ -79,7 +102,9 @@ void color_guess_play_new_round(void* context, ColorGuessPlayModel* model) {
79
102
}
80
103
81
104
void color_guess_play_calculate_closeness (void * context , ColorGuessPlayModel * model ) {
82
- UNUSED (context );
105
+ furi_assert (context );
106
+ ColorGuess * app = context ;
107
+ UNUSED (app );
83
108
int userRed = (model -> digit [0 ] * 16 ) + model -> digit [1 ];
84
109
int userGreen = (model -> digit [2 ] * 16 ) + model -> digit [3 ];
85
110
int userBlue = (model -> digit [4 ] * 16 ) + model -> digit [5 ];
@@ -93,13 +118,15 @@ void color_guess_play_calculate_closeness(void* context, ColorGuessPlayModel* mo
93
118
float percentageRed = 100 - ((distanceRed / 255.0 ) * 100 ); //make sure one number is float, otherwise C will calc wrong
94
119
float percentageGreen = 100 - ((distanceGreen / 255.0 ) * 100 );
95
120
float percentageBlue = 100 - ((distanceBlue / 255.0 ) * 100 );
121
+ if (percentageRed == 100 && percentageGreen == 100 && percentageBlue == 100 ) {
122
+ model -> success = 1 ;
123
+ }
96
124
float fullPercentage = (percentageRed + percentageGreen + percentageBlue ) / 3 ;
125
+ model -> prev_closeness = model -> closeness ;
97
126
model -> closeness = round (fullPercentage );
98
127
}
99
128
100
129
void parse_time_str (char * buffer , int32_t sec ) {
101
- //int seconds = sec % 60;
102
- //int minutes = (sec % (60 * 60)) / 60;
103
130
snprintf (
104
131
buffer ,
105
132
TIMER_LENGHT ,
@@ -128,17 +155,38 @@ void drawDifficulty(Canvas* canvas, ColorGuessPlayModel* model) {
128
155
}
129
156
130
157
void color_guess_play_draw (Canvas * canvas , ColorGuessPlayModel * model ) {
158
+ char timer_string [TIMER_LENGHT ];
159
+ if (model -> success == 1 ) {
160
+ parse_time_str (timer_string , model -> time_spent );
161
+ canvas_clear (canvas );
162
+ canvas_set_color (canvas , ColorBlack );
163
+ canvas_set_font (canvas , FontPrimary );
164
+ canvas_draw_str_aligned (canvas , 64 , 2 , AlignCenter , AlignTop , "You won!!" );
165
+ canvas_set_font (canvas , FontSecondary );
166
+ elements_button_center (canvas , "New Round" );
167
+ canvas_set_font (canvas , FontBigNumbers );
168
+ canvas_draw_str_aligned (canvas , 64 , 16 , AlignCenter , AlignTop , timer_string );
169
+
170
+ canvas_draw_icon (canvas , 18 , 32 , digits [16 ]);
171
+ canvas_draw_icon (canvas , 30 , 32 , digits [model -> digit [0 ]]);
172
+ canvas_draw_icon (canvas , 42 , 32 , digits [model -> digit [1 ]]);
173
+ canvas_draw_icon (canvas , 54 , 32 , digits [model -> digit [2 ]]);
174
+ canvas_draw_icon (canvas , 66 , 32 , digits [model -> digit [3 ]]);
175
+ canvas_draw_icon (canvas , 78 , 32 , digits [model -> digit [4 ]]);
176
+ canvas_draw_icon (canvas , 90 , 32 , digits [model -> digit [5 ]]);
177
+
178
+ return ;
179
+ }
131
180
const int cursorOffset = 30 ;
132
181
const int newCursorPos = (model -> cursorpos * 12 ) + cursorOffset ;
133
182
FuriHalRtcDateTime date_time ;
134
183
furi_hal_rtc_get_datetime (& date_time );
135
184
uint32_t timestamp = furi_hal_rtc_datetime_to_timestamp (& date_time );
136
185
uint32_t time_elapsed = timestamp - model -> timestamp_start ;
137
-
138
- char timer_string [TIMER_LENGHT ];
139
- char closeness_string [4 ];
140
- UNUSED (time_elapsed );
186
+ model -> time_spent = time_elapsed ;
141
187
188
+ char closeness_string [4 ];
189
+
142
190
//snprintf(timer_string, TIMER_LENGHT, TIMER_FORMAT, date_time.minute, date_time.second);
143
191
parse_time_str (timer_string , time_elapsed );
144
192
snprintf (closeness_string , CLOSENESS_LENGTH , CLOSENESS_FORMAT , model -> closeness );
@@ -224,6 +272,7 @@ bool color_guess_play_input(InputEvent* event, void* context) {
224
272
model -> digit [model -> cursorpos ] = 0 ;
225
273
}
226
274
color_guess_play_calculate_closeness (instance , model );
275
+ play_happy_bop (instance -> context , model );
227
276
},
228
277
true);
229
278
break ;
@@ -237,6 +286,7 @@ bool color_guess_play_input(InputEvent* event, void* context) {
237
286
model -> digit [model -> cursorpos ] = 15 ;
238
287
}
239
288
color_guess_play_calculate_closeness (instance , model );
289
+ play_happy_bop (instance -> context , model );
240
290
},
241
291
true);
242
292
break ;
@@ -245,9 +295,13 @@ bool color_guess_play_input(InputEvent* event, void* context) {
245
295
instance -> view ,
246
296
ColorGuessPlayModel * model ,
247
297
{
248
- model -> difficulty ++ ;
249
- if (model -> difficulty > 2 ) {
250
- model -> difficulty = 0 ;
298
+ if (model -> success == 1 ) {
299
+ model -> success = 0 ;
300
+ } else {
301
+ model -> difficulty ++ ;
302
+ if (model -> difficulty > 2 ) {
303
+ model -> difficulty = 0 ;
304
+ }
251
305
}
252
306
color_guess_play_new_round (instance -> context , model );
253
307
},
0 commit comments