Skip to content

Commit 685ddff

Browse files
authored
Merge pull request #2 from Cupprum/dev
chore: make if statements more readable
2 parents 91517a4 + 1f49bb8 commit 685ddff

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

blinker.c

+10-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ static void timer_callback(void* context) {
1414
uint32_t current_time = furi_get_tick() / 1000; // seconds
1515
uint32_t elapsed_time = (furi_get_tick() - app->start_time) / 1000; // seconds
1616

17-
if(elapsed_time >= app->duration * 60) {
17+
bool elapsed_time_passed = elapsed_time >= app->duration * 60;
18+
if(elapsed_time_passed) {
1819
app->time_out = true;
1920
elapsed_time = app->duration * 60;
2021
}
@@ -26,7 +27,11 @@ static void timer_callback(void* context) {
2627
(elapsed_time * (app->max_interval - app->min_interval) / (app->duration * 60));
2728
// Execute on first run and afterwards every 5 seconds.
2829
// Do not run after 'duration' has passed, which means after time_out.
29-
if(app->last_check == 0 || app->last_check + 5 < current_time || app->time_out == true) {
30+
31+
bool start = app->last_check == 0;
32+
bool time_for_new_check = app->last_check + 5 < current_time; // Run every 5 seconds
33+
34+
if(start || time_for_new_check || app->time_out) {
3035
app->last_check = current_time;
3136

3237
// Equation: 1 minute in miliseconds divided by number of cycles,
@@ -56,7 +61,8 @@ static bool back_button_callback(void* context) {
5661
furi_hal_light_set(LightBlue, 0);
5762
}
5863

59-
if(app->current_view != Main) {
64+
bool back_to_main_menu = app->current_view != Main;
65+
if(back_to_main_menu) {
6066
app->current_view = Main;
6167
view_dispatcher_switch_to_view(app->view_dispatcher, Main);
6268
return true;
@@ -103,6 +109,7 @@ static void number_picker_view(
103109
uint32_t current,
104110
uint32_t min,
105111
uint32_t max) {
112+
106113
number_input_set_header_text(app->number_input, header);
107114
number_input_set_result_callback(
108115
app->number_input, number_picker_callback, app, current, min, max);

0 commit comments

Comments
 (0)