Skip to content

Commit f3bef69

Browse files
authored
Merge pull request #3 from leedave/feature/color_guess_dev2
first display of random colors in game mode
2 parents ac4da8f + 6b430c2 commit f3bef69

File tree

2 files changed

+58
-5
lines changed

2 files changed

+58
-5
lines changed

Games/color_guess/views/color_guess_play.c

+57-5
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,37 @@
88

99
extern const Icon* digits[17];
1010

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+
1127
struct ColorGuessPlay {
1228
View* view;
1329
ColorGuessPlayCallback callback;
1430
void* context;
1531
};
1632

33+
1734
typedef struct {
1835
ColorGuessPlayStatus status;
1936
int cursorpos;
2037
int digit[6];
38+
int color;
2139
int time_spent;
2240
int timestamp_start;
41+
int closeness;
2342
} ColorGuessPlayModel;
2443

2544
void color_guess_play_set_callback(
@@ -32,6 +51,41 @@ void color_guess_play_set_callback(
3251
instance->context = context;
3352
}
3453

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+
3589
void parse_time_str(char* buffer, int32_t sec) {
3690
//int seconds = sec % 60;
3791
//int minutes = (sec % (60 * 60)) / 60;
@@ -46,7 +100,6 @@ void parse_time_str(char* buffer, int32_t sec) {
46100
void color_guess_play_draw(Canvas* canvas, ColorGuessPlayModel* model) {
47101
const int cursorOffset = 30;
48102
const int newCursorPos = (model->cursorpos * 12) + cursorOffset;
49-
const int closeness = 0;
50103
FuriHalRtcDateTime date_time;
51104
furi_hal_rtc_get_datetime(&date_time);
52105
uint32_t timestamp = furi_hal_rtc_datetime_to_timestamp(&date_time);
@@ -58,7 +111,7 @@ void color_guess_play_draw(Canvas* canvas, ColorGuessPlayModel* model) {
58111

59112
//snprintf(timer_string, TIMER_LENGHT, TIMER_FORMAT, date_time.minute, date_time.second);
60113
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);
62115

63116
canvas_clear(canvas);
64117
canvas_set_color(canvas, ColorBlack);
@@ -85,9 +138,7 @@ static void color_guess_play_model_init(ColorGuessPlayModel* const model) {
85138
for (int i = 0;i < 6; i++) {
86139
model->digit[i] = 0;
87140
}
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;
91142
}
92143

93144
bool color_guess_play_input(InputEvent* event, void* context) {
@@ -176,6 +227,7 @@ void color_guess_play_enter(void* context) {
176227
ColorGuessPlayModel * model,
177228
{
178229
color_guess_play_model_init(model);
230+
color_guess_play_new_round(instance->context, model);
179231
},
180232
true
181233
);

Games/color_guess/views/color_guess_play.h

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ extern const Icon* digits[17];
99
#define TIMER_LENGHT 12
1010
#define CLOSENESS_LENGTH 7
1111
#define CLOSENESS_FORMAT "%d%%"
12+
#define ARR_SIZE(arr) ( sizeof((arr)) / sizeof((arr[0])) )
1213

1314
typedef struct ColorGuessPlay ColorGuessPlay;
1415

0 commit comments

Comments
 (0)