8
8
9
9
extern const Icon * digits [17 ];
10
10
11
+ int colorsEasy [] = {
12
+ 0xff0000 ,
13
+ 0x00ff00 ,
14
+ 0x0000ff ,
15
+ 0xffff00 ,
16
+ 0xff00ff ,
17
+ 0x00ffff ,
18
+ 0xffffff ,
19
+ 0x500000 ,
20
+ 0x005000 ,
21
+ 0x505000 ,
22
+ 0x505050 ,
23
+ 0x500050 ,
24
+ 0x005050 ,
25
+ };
26
+
11
27
struct ColorGuessPlay {
12
28
View * view ;
13
29
ColorGuessPlayCallback callback ;
14
30
void * context ;
15
31
};
16
32
33
+
17
34
typedef struct {
18
35
ColorGuessPlayStatus status ;
19
36
int cursorpos ;
20
37
int digit [6 ];
38
+ int color ;
21
39
int time_spent ;
22
40
int timestamp_start ;
41
+ int closeness ;
23
42
} ColorGuessPlayModel ;
24
43
25
44
void color_guess_play_set_callback (
@@ -32,6 +51,41 @@ void color_guess_play_set_callback(
32
51
instance -> context = context ;
33
52
}
34
53
54
+ void color_guess_play_new_round (void * context , ColorGuessPlayModel * model ) {
55
+ furi_assert (context );
56
+ ColorGuess * app = context ;
57
+ //Reset timer
58
+ FuriHalRtcDateTime date_time ;
59
+ furi_hal_rtc_get_datetime (& date_time );
60
+ model -> timestamp_start = furi_hal_rtc_datetime_to_timestamp (& date_time );
61
+
62
+ //Set random color
63
+ NotificationMessage notification_led_message_1 ;
64
+ notification_led_message_1 .type = NotificationMessageTypeLedRed ;
65
+ NotificationMessage notification_led_message_2 ;
66
+ notification_led_message_2 .type = NotificationMessageTypeLedGreen ;
67
+ NotificationMessage notification_led_message_3 ;
68
+ notification_led_message_3 .type = NotificationMessageTypeLedBlue ;
69
+
70
+ model -> color = colorsEasy [rand () % ARR_SIZE (colorsEasy )];
71
+ notification_led_message_1 .data .led .value = ((model -> color >> 16 ) & 0xFF );
72
+ notification_led_message_2 .data .led .value = ((model -> color >> 8 ) & 0xFF );
73
+ notification_led_message_3 .data .led .value = ((model -> color ) & 0xFF );
74
+
75
+ model -> closeness = ((model -> color >> 8 ) & 0xFF );
76
+
77
+ const NotificationSequence notification_sequence = {
78
+ & notification_led_message_1 ,
79
+ & notification_led_message_2 ,
80
+ & notification_led_message_3 ,
81
+ & message_do_not_reset ,
82
+ NULL ,
83
+ };
84
+ notification_message (app -> notification , & notification_sequence );
85
+ furi_thread_flags_wait (0 , FuriFlagWaitAny , 10 ); //Delay, prevent removal from RAM before LED value set
86
+
87
+ }
88
+
35
89
void parse_time_str (char * buffer , int32_t sec ) {
36
90
//int seconds = sec % 60;
37
91
//int minutes = (sec % (60 * 60)) / 60;
@@ -46,7 +100,6 @@ void parse_time_str(char* buffer, int32_t sec) {
46
100
void color_guess_play_draw (Canvas * canvas , ColorGuessPlayModel * model ) {
47
101
const int cursorOffset = 30 ;
48
102
const int newCursorPos = (model -> cursorpos * 12 ) + cursorOffset ;
49
- const int closeness = 0 ;
50
103
FuriHalRtcDateTime date_time ;
51
104
furi_hal_rtc_get_datetime (& date_time );
52
105
uint32_t timestamp = furi_hal_rtc_datetime_to_timestamp (& date_time );
@@ -58,7 +111,7 @@ void color_guess_play_draw(Canvas* canvas, ColorGuessPlayModel* model) {
58
111
59
112
//snprintf(timer_string, TIMER_LENGHT, TIMER_FORMAT, date_time.minute, date_time.second);
60
113
parse_time_str (timer_string , time_elapsed );
61
- snprintf (closeness_string , CLOSENESS_LENGTH , CLOSENESS_FORMAT , closeness );
114
+ snprintf (closeness_string , CLOSENESS_LENGTH , CLOSENESS_FORMAT , model -> closeness );
62
115
63
116
canvas_clear (canvas );
64
117
canvas_set_color (canvas , ColorBlack );
@@ -85,9 +138,7 @@ static void color_guess_play_model_init(ColorGuessPlayModel* const model) {
85
138
for (int i = 0 ;i < 6 ; i ++ ) {
86
139
model -> digit [i ] = 0 ;
87
140
}
88
- FuriHalRtcDateTime date_time ;
89
- furi_hal_rtc_get_datetime (& date_time );
90
- model -> timestamp_start = furi_hal_rtc_datetime_to_timestamp (& date_time );
141
+ model -> closeness = 0 ;
91
142
}
92
143
93
144
bool color_guess_play_input (InputEvent * event , void * context ) {
@@ -176,6 +227,7 @@ void color_guess_play_enter(void* context) {
176
227
ColorGuessPlayModel * model ,
177
228
{
178
229
color_guess_play_model_init (model );
230
+ color_guess_play_new_round (instance -> context , model );
179
231
},
180
232
true
181
233
);
0 commit comments