6
6
const GUI_RECT toastRect = {START_X + TITLE_END_Y - (TOAST_Y_PAD * 2 ), TOAST_Y_PAD , LCD_WIDTH - START_X , TITLE_END_Y - TOAST_Y_PAD };
7
7
const GUI_RECT toastIconRect = {START_X , TOAST_Y_PAD , START_X + TITLE_END_Y - (TOAST_Y_PAD * 2 ), TITLE_END_Y - TOAST_Y_PAD };
8
8
9
- // toast notification variables
10
- static TOAST toastlist [TOAST_MSG_COUNT ];
9
+ static struct
10
+ {
11
+ DIALOG_TYPE style ;
12
+ uint8_t isNew ;
13
+ char text [TOAST_MSG_LENGTH ];
14
+ } toastlist [TOAST_MSG_COUNT ];
11
15
12
16
static uint8_t nextToastIndex = 0 ; // next index to store new toast
13
17
static uint8_t curToastDisplay = 0 ; // current toast notification being displayed
@@ -24,11 +28,9 @@ void addToast(DIALOG_TYPE style, char * text)
24
28
{
25
29
LCD_WAKE ();
26
30
27
- TOAST t ;
28
- strscpy (t .text , text , TOAST_MSG_LENGTH );
29
- t .style = style ;
30
- t .isNew = true;
31
- toastlist [nextToastIndex ] = t ;
31
+ strscpy (toastlist [nextToastIndex ].text , text , TOAST_MSG_LENGTH );
32
+ toastlist [nextToastIndex ].style = style ;
33
+ toastlist [nextToastIndex ].isNew = true;
32
34
nextToastIndex = (nextToastIndex + 1 ) % TOAST_MSG_COUNT ;
33
35
}
34
36
@@ -41,7 +43,7 @@ bool toastRunning(void)
41
43
// check if any new notification is available
42
44
bool toastAvailable (void )
43
45
{
44
- for (int i = 0 ; i < TOAST_MSG_COUNT ; i ++ )
46
+ for (uint8_t i = 0 ; i < TOAST_MSG_COUNT ; i ++ )
45
47
{
46
48
if (toastlist [i ].isNew == true)
47
49
return true;
@@ -62,29 +64,35 @@ void drawToast(bool redraw)
62
64
63
65
// draw icon
64
66
uint8_t * icon ;
65
- uint8_t cursound ;
66
- if (toastlist [curToastDisplay ].style == DIALOG_TYPE_ERROR )
67
- {
68
- GUI_SetColor (NOTIF_ICON_ERROR_BG_COLOR );
69
- icon = IconCharSelect (CHARICON_ERROR );
70
- cursound = SOUND_ERROR ;
71
- }
72
- else if (toastlist [curToastDisplay ].style == DIALOG_TYPE_SUCCESS )
67
+ SOUND cursound ;
68
+
69
+ switch (toastlist [curToastDisplay ].style )
73
70
{
74
- GUI_SetColor (NOTIF_ICON_SUCCESS_BG_COLOR );
75
- icon = IconCharSelect (CHARICON_OK_ROUND );
76
- cursound = SOUND_SUCCESS ;
71
+ case DIALOG_TYPE_ERROR :
72
+ GUI_SetColor (NOTIF_ICON_ERROR_BG_COLOR );
73
+ icon = IconCharSelect (CHARICON_ERROR );
74
+ cursound = SOUND_ERROR ;
75
+ break ;
76
+
77
+ case DIALOG_TYPE_SUCCESS :
78
+ GUI_SetColor (NOTIF_ICON_SUCCESS_BG_COLOR );
79
+ icon = IconCharSelect (CHARICON_OK_ROUND );
80
+ cursound = SOUND_SUCCESS ;
81
+ break ;
82
+
83
+ default :
84
+ GUI_SetColor (NOTIF_ICON_INFO_BG_COLOR );
85
+ icon = IconCharSelect (CHARICON_INFO );
86
+ cursound = SOUND_TOAST ;
87
+ break ;
77
88
}
78
- else
89
+
90
+ if (!redraw ) // if notification is new
79
91
{
80
- GUI_SetColor (NOTIF_ICON_INFO_BG_COLOR );
81
- icon = IconCharSelect (CHARICON_INFO );
82
- cursound = SOUND_TOAST ;
92
+ BUZZER_PLAY (cursound ); // play sound
93
+ nextToastTime = OS_GetTimeMs () + SEC_TO_MS (TOAST_DURATION ); // set new timer
83
94
}
84
95
85
- if (cursound >= 0 && !redraw )
86
- BUZZER_PLAY (cursound );
87
-
88
96
GUI_SetTextMode (GUI_TEXTMODE_TRANS );
89
97
GUI_FillPrect (& toastIconRect );
90
98
GUI_SetColor (NOTIF_ICON_FG_COLOR );
@@ -99,21 +107,14 @@ void drawToast(bool redraw)
99
107
// set current toast notification as old/completed
100
108
toastlist [curToastDisplay ].isNew = false;
101
109
102
- // set new timer if notification is new
103
- if (!redraw )
104
- nextToastTime = OS_GetTimeMs () + SEC_TO_MS (TOAST_DURATION );
105
-
106
110
GUI_RestoreColorDefault ();
107
111
}
108
112
}
109
113
110
114
// check and control toast notification display
111
115
void loopToast (void )
112
116
{
113
- if (getMenuType () == MENU_TYPE_FULLSCREEN )
114
- return ;
115
-
116
- if (OS_GetTimeMs () > nextToastTime )
117
+ if (getMenuType () != MENU_TYPE_FULLSCREEN && OS_GetTimeMs () > nextToastTime )
117
118
{
118
119
if (toastAvailable ())
119
120
{
@@ -130,36 +131,32 @@ void loopToast(void)
130
131
}
131
132
132
133
// add new message to notification queue
133
- void addNotification (DIALOG_TYPE style , char * title , char * text , bool ShowDialog )
134
+ void addNotification (DIALOG_TYPE style , char * title , char * text , bool draw_dialog )
134
135
{
135
136
LCD_WAKE ();
136
137
137
- if (nextMsgIndex > MAX_MSG_COUNT - 1 )
138
+ if (nextMsgIndex >= MAX_MSG_COUNT )
138
139
{
139
140
// remove oldest message and move all messages up one step
140
- for (int i = 0 ; i < MAX_MSG_COUNT - 1 ; i ++ )
141
- {
142
- memcpy (& msglist [i ], & msglist [i + 1 ], sizeof (NOTIFICATION ));
143
- }
141
+ memmove (msglist , & msglist [1 ], (MAX_MSG_COUNT - 1 ) * (sizeof (NOTIFICATION )));
144
142
nextMsgIndex = MAX_MSG_COUNT - 1 ;
145
143
}
146
144
147
145
// store message
148
- msglist [nextMsgIndex ].style = style ;
146
+ msglist [nextMsgIndex ].style = style ;
149
147
strscpy (msglist [nextMsgIndex ].text , text , MAX_MSG_LENGTH );
150
148
strscpy (msglist [nextMsgIndex ].title , title , MAX_MSG_TITLE_LENGTH );
149
+ nextMsgIndex ++ ;
151
150
152
- if (ShowDialog && MENU_IS_NOT (menuNotification ))
153
- popupReminder (style , (uint8_t * )title , (uint8_t * )msglist [nextMsgIndex ].text );
154
-
155
- if (nextMsgIndex < MAX_MSG_COUNT ) nextMsgIndex += 1 ; //(nextMsgIndex + 1) % MAX_MSG_COUNT;
151
+ if (draw_dialog && MENU_IS_NOT (menuNotification ))
152
+ popupReminder (style , (uint8_t * )title , (uint8_t * )text );
156
153
157
154
if (notificationHandler != NULL )
158
155
notificationHandler ();
159
156
160
157
notificationDot ();
161
158
162
- statusScreen_setMsg ((uint8_t * )title , (uint8_t * )text );
159
+ statusScreenSetMsg ((uint8_t * )title , (uint8_t * )text );
163
160
}
164
161
165
162
// replay a notification
@@ -172,30 +169,27 @@ void replayNotification(uint8_t index)
172
169
// retrieve a stored notification
173
170
NOTIFICATION * getNotification (uint8_t index )
174
171
{
175
- if (strlen ( msglist [index ].title ) > 0 && strlen ( msglist [index ].text ) > 0 )
172
+ if (msglist [index ].title [ 0 ] != '\0' && msglist [index ].text [ 0 ] != '\0' )
176
173
return & msglist [index ];
177
174
else
178
175
return NULL ;
179
176
}
180
177
181
178
bool hasNotification (void )
182
179
{
183
- if (nextMsgIndex == 0 )
184
- return false;
185
- else
186
- return true;
180
+ return (nextMsgIndex != 0 );
187
181
}
188
182
189
183
void clearNotification (void )
190
184
{
191
185
nextMsgIndex = 0 ;
192
186
for (int i = 0 ; i < MAX_MSG_COUNT ; i ++ )
193
187
{
194
- msglist [i ].text [0 ] = 0 ;
195
- msglist [i ].title [0 ] = 0 ;
188
+ msglist [i ].text [0 ] = '\0' ;
189
+ msglist [i ].title [0 ] = '\0' ;
196
190
}
197
191
notificationDot ();
198
- statusScreen_setReady ();
192
+ statusScreenSetReady ();
199
193
}
200
194
201
195
// check if pressed on titlebar area
0 commit comments