33#include "../helpers/time.h"
44#include "flipp_pomodoro.h"
55
6- char * next_stage_label [] = {
7- [Work ] = "Get Rest" ,
8- [Rest ] = "Start Work" ,
6+ PomodoroStage stages_sequence [] = {
7+ FlippPomodoroStageFocus ,
8+ FlippPomodoroStageRest ,
9+
10+ FlippPomodoroStageFocus ,
11+ FlippPomodoroStageRest ,
12+
13+ FlippPomodoroStageFocus ,
14+ FlippPomodoroStageRest ,
15+
16+ FlippPomodoroStageFocus ,
17+ FlippPomodoroStageLongBreak ,
918};
1019
11- const PomodoroStage stage_rotaion_map [] = {
12- [Work ] = Rest ,
13- [Rest ] = Work ,
20+ char * current_stage_label [] = {
21+ [FlippPomodoroStageFocus ] = "Continue focus for:" ,
22+ [FlippPomodoroStageRest ] = "Keep rest for:" ,
23+ [FlippPomodoroStageLongBreak ] = "Long Break for:" ,
1424};
1525
16- const PomodoroStage default_stage = Work ;
26+ char * next_stage_label [] = {
27+ [FlippPomodoroStageFocus ] = "Focus" ,
28+ [FlippPomodoroStageRest ] = "Short Break" ,
29+ [FlippPomodoroStageLongBreak ] = "Long Break" ,
30+ };
31+
32+ PomodoroStage flipp_pomodoro__stage_by_index (int index ) {
33+ const int one_loop_size = sizeof (stages_sequence );
34+ return stages_sequence [index % one_loop_size ];
35+ }
1736
1837void flipp_pomodoro__toggle_stage (FlippPomodoroState * state )
1938{
2039 furi_assert (state );
21- state -> stage = stage_rotaion_map [ flipp_pomodoro__get_stage ( state )] ;
40+ state -> current_stage_index = state -> current_stage_index + 1 ;
2241 state -> started_at_timestamp = time_now ();
2342};
2443
2544PomodoroStage flipp_pomodoro__get_stage (FlippPomodoroState * state )
2645{
2746 furi_assert (state );
28- return state -> stage ;
47+ return flipp_pomodoro__stage_by_index (state -> current_stage_index );
48+ };
49+
50+ char * flipp_pomodoro__current_stage_label (FlippPomodoroState * state )
51+ {
52+ furi_assert (state );
53+ return current_stage_label [flipp_pomodoro__get_stage (state )];
2954};
3055
3156char * flipp_pomodoro__next_stage_label (FlippPomodoroState * state )
3257{
3358 furi_assert (state );
34- return next_stage_label [flipp_pomodoro__get_stage (state )];
59+ return next_stage_label [flipp_pomodoro__stage_by_index (state -> current_stage_index + 1 )];
3560};
3661
3762void flipp_pomodoro__destroy (FlippPomodoroState * state )
@@ -43,8 +68,9 @@ void flipp_pomodoro__destroy(FlippPomodoroState *state)
4368uint32_t flipp_pomodoro__current_stage_total_duration (FlippPomodoroState * state )
4469{
4570 const int32_t stage_duration_seconds_map [] = {
46- [Work ] = 25 * TIME_SECONDS_IN_MINUTE ,
47- [Rest ] = 5 * TIME_SECONDS_IN_MINUTE ,
71+ [FlippPomodoroStageFocus ] = 25 * TIME_SECONDS_IN_MINUTE ,
72+ [FlippPomodoroStageRest ] = 5 * TIME_SECONDS_IN_MINUTE ,
73+ [FlippPomodoroStageLongBreak ] = 30 * TIME_SECONDS_IN_MINUTE ,
4874 };
4975
5076 return stage_duration_seconds_map [flipp_pomodoro__get_stage (state )];
@@ -73,6 +99,6 @@ FlippPomodoroState *flipp_pomodoro__new()
7399 FlippPomodoroState * state = malloc (sizeof (FlippPomodoroState ));
74100 const uint32_t now = time_now ();
75101 state -> started_at_timestamp = now ;
76- state -> stage = default_stage ;
102+ state -> current_stage_index = 0 ;
77103 return state ;
78104};
0 commit comments