fremoclock  1_3A01
FREMO Clock - Software for UTG
UserInterfaceMenuNormal.c
Go to the documentation of this file.
1 
31 /*
32  Copyright (C) 2007 Bernd Wisotzki
33 
34  This library is free software; you can redistribute it and/or
35  modify it under the terms of the GNU Lesser General Public
36  License as published by the Free Software Foundation; either
37  version 2.1 of the License, or (at your option) any later version.
38 
39  This library is distributed in the hope that it will be useful,
40  but WITHOUT ANY WARRANTY; without even the implied warranty of
41  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
42  Lesser General Public License for more details.
43 
44  You should have received a copy of the GNU Lesser General Public
45  License along with this library; if not, write to the Free Software
46  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
47 */
48 
49 /* -- System wide includes -------------------------------------------------- */
50 
51 #include <stdint.h> // typedef uint8_t
52 #include <stdbool.h> // typedef bool, true, false
53 
54 /* -- Special Includes e.g. Onboard or direct attached Equipment ------------ */
55 //TODO: cleanup of imports, add comments what is imported
56 #include "ClockKernel.h" // clock kernel
57 #include "lcd.h"
58 #include "PushButton.h" // push buttons
59 //#include "uart.h" // logging
60 #include "UserInterfaceLcdNormal.h"
61 #include "UserInterfaceMenu.h" // menuFastFwd_t
63 
64 /* -- Variables ------------------------------------------------------------- */
65 
69 typedef enum
70 {
71  START = 0,
72  CURRENT = 1,
73  TARGET = 2
74 } tTimes;
75 
76 /* -- Function prototypes internal functions -------------------------------- */
77 
78 // for comment see below
79 static void UserInterfaceNormalQuickTo(menuFastFwd_t ucbut);
80 
81 // for comment see below
82 static void UserInterfaceMenueNormalTime(tTimes which);
83 
84 /* -- Standard functions ---------------------------------------------------- */
85 
90 {
92  uint8_t utimef = 0;
93  bool endTimeReached = false;
94 
95  for(;;)
96  {
98  // no MENU_NORMAL_STOP in following selection because clock is stopped
102 
103  // single shot enter
105  {
106  if (ucbut1 == MENU_NORMAL_START)
107  {
108  ClockSetStatus(ClockIsRunning()); // Uhrstart!!
109  for(;;)
110  {
112  // reached end time??
113  fclock_t clock = ClockGetTime();
114  if ((clock.hour == ClockReadEndTimeHour())
115  && (clock.minute == ClockReadEndTimeMinute()))
116  {
117  ClockSetStatus(0); // Uhrstop!!
118  endTimeReached = true;
119  break;
120  }
121  // single shot enter
123  {
124  ClockSetStatus(0); // Uhrstop!!
125  break;
126  }
127  // single shot button up
129  {
130  utimef = ClockReadTimeFactor();
131  utimef++;
132  ClockSetTimeFactor(utimef);
133  }
134  // single shot button down
136  {
137  utimef = ClockReadTimeFactor();
138  utimef--;
139  ClockSetTimeFactor(utimef);
140  }
141  }
142  }
143  else //(ucbut1 == MENU_NORMAL_BACK)
144  {
145  return;
146  }
147  }
148  if (endTimeReached)
149  {
150  // call menu for quick running to start time
152  endTimeReached = false;
153  }
154  // single shot back
156  {
157  return;
158  }
159  }
160 }
161 
166 {
167  menuFastFwd_t ucbut1 = MENU_FASTFWD_START; // start time, 00:00, back
168  uint16_t uiperiod;
169 
170  lcd_clear();
171  for(;;)
172  {
174  ucbut1 = (menuFastFwd_t) PushButtonGetUpDownValue(ucbut1,
177 
178  // single shot enter
180  {
181  // Quick forward to start time or 00:00
182  if ((ucbut1 == MENU_FASTFWD_START) || (ucbut1 == MENU_FASTFWD_NULL))
183  {
184  uiperiod = ClockReadPeriod();
185  ClockSetPeriod(10); // change polarity each second
187  ClockSetPeriod(uiperiod);
188  }
189  else // ucbut1 >=2 exit
190  {
191  return;
192  }
193 
194  }
195  // single shot back "emergency exit"
197  {
198  return;
199  }
200  }
201 }
202 
207 {
208  uint8_t ucbut1 = 0;
209 
210  ucbut1 = ClockReadTimeFactor();
211  for(;;)
212  {
216 
217  // single shot enter
219  {
220  ClockSetTimeFactor(ucbut1);
221  return;
222  }
223  // single shot back
225  {
226  return;
227  }
228  }
229 }
230 
235 {
237  return;
238 }
239 
244 {
246  return;
247 }
248 
253 {
255  return;
256 }
257 
258 /* -- private functions ----------------------------------------------------- */
259 
265 {
267  uint8_t ucminute;
268  uint8_t uchour;
269 
270  if (ucbut == MENU_FASTFWD_START)
271  {
272  ucminute = ClockReadStartTimeMinute();
273  uchour = ClockReadStartTimeHour();
274  }
275  else //(ucbut == MENU_FASTFWD_NULL)
276  {
277  ucminute = 0;
278  uchour = 0;
279  }
280 
281  for(;;) //just as normal clock operation start/stop/back
282  {
283  UserInterfaceLcdNormalQuickClock(ucbut, ucbut2, ucminute, uchour);
284  // no MENU_NORMAL_STOP in following selection because clock is stopped
288  // single shot enter
290  {
291  if (ucbut2 == MENU_NORMAL_START)
292  {
293  ClockSetStatus(ClockIsRunning()); // Uhrstart!!
294  for(;;)
295  {
297  ucminute, uchour);
298  // reached time??
299  fclock_t clock = ClockGetTime();
300  if ((clock.hour == uchour) && (clock.minute == ucminute))
301  {
302  ClockSetStatus(0); // Uhrstop!!
303  break;
304  }
305  // single shot enter (stop)
307  {
308  ClockSetStatus(0); // Uhrstop!!
309  break;
310  }
311  }
312  }
313  else //(ucbut2 == MENU_NORMAL_BACK)
314  {
315  return;
316  }
317  }
318  // single shot back
320  {
321  return;
322  }
323  }
324 }
325 
331 {
332  menuSetTime_t ucbut1 = 1; // 0=minute, 1=hour, 2=back
333  uint8_t ucbut2 = 0; // time
334  uint8_t uctime = 0;
335  fclock_t clkTemp = (fclock_t)CLOCK_MIDNIGHT;
336 
337  for(;;)
338  {
339  switch (which)
340  {
341  case START : UserInterfaceLcdNormalStartTime(ucbut1); break;
342  case CURRENT: UserInterfaceLcdNormalCurrentTime(ucbut1); break;
343  case TARGET : UserInterfaceLcdNormalTargetTime(ucbut1); break;
344  }
345  ucbut1 = (menuSetTime_t) PushButtonGetUpDownValue(ucbut1,
347  MENU_SET_BACK);
348  // single shot enter
350  {
351  // Set minute
352  if (ucbut1 == MENU_SET_MINUTE)
353  {
354  switch (which)
355  {
356  case START :
357  ucbut2 = ClockReadStartTimeMinute();
358  uctime = ClockReadStartTimeHour();
359  break;
360  case CURRENT :
361  clkTemp = ClockGetTime();
362  ucbut2 = clkTemp.minute;
363  uctime = clkTemp.hour;
364  break;
365  case TARGET :
366  ucbut2 = ClockReadEndTimeMinute();
367  uctime = ClockReadEndTimeHour();
368  break;
369  }
370  for(;;)
371  {
372  switch (which)
373  {
374  case START:
375  UserInterfaceLcdNormalStartTimeSet(ucbut2, uctime);
376  break;
377  case CURRENT:
378  UserInterfaceLcdNormalCurrentTimeSet(ucbut2, uctime);
379  break;
380  case TARGET:
381  UserInterfaceLcdNormalTargetTimeSet(ucbut2, uctime);
382  break;
383  }
384  ucbut2 = PushButtonGetUpDownValue(ucbut2, 0, 59);
385  // single shot enter
387  {
388  switch (which)
389  {
390  case START:
391  ClockSetStartTimeMinute(ucbut2);
392  break;
393  case CURRENT:
394  clkTemp = ClockGetTime();
395  clkTemp.minute = ucbut2;
396  ClockSetTime(clkTemp);
397  break;
398  case TARGET:
399  ClockSetEndTimeMinute(ucbut2);
400  break;
401  }
402  break;
403  }
404  // single shot back
406  {
407  break;
408  }
409  }
410  }
411  // Set hour
412  else if (ucbut1 == MENU_SET_HOUR)
413  {
414  switch (which)
415  {
416  case START :
417  uctime = ClockReadStartTimeMinute();
418  ucbut2 = ClockReadStartTimeHour();
419  break;
420  case CURRENT :
421  clkTemp = ClockGetTime();
422  uctime = clkTemp.minute;
423  ucbut2 = clkTemp.hour;
424  break;
425  case TARGET :
426  uctime = ClockReadEndTimeMinute();
427  ucbut2 = ClockReadEndTimeHour();
428  break;
429  }
430  for(;;)
431  {
432  switch (which)
433  {
434  case START:
435  UserInterfaceLcdNormalStartTimeSet(uctime, ucbut2);
436  break;
437  case CURRENT:
438  UserInterfaceLcdNormalCurrentTimeSet(uctime, ucbut2);
439  break;
440  case TARGET:
441  UserInterfaceLcdNormalTargetTimeSet(uctime, ucbut2);
442  break;
443  }
444  ucbut2 = PushButtonGetUpDownValue(ucbut2, 0, 23);
445  // single shot enter
447  {
448  switch (which)
449  {
450  case START:
451  ClockSetStartTimeHour(ucbut2);
452  break;
453  case CURRENT:
454  clkTemp = ClockGetTime();
455  clkTemp.hour = ucbut2;
456  ClockSetTime(clkTemp);
457  break;
458  case TARGET:
459  ClockSetEndTimeHour(ucbut2);
460  break;
461  }
462  break;
463  }
464  // single shot back
466  {
467  break;
468  }
469  }
470  }
471  else //(ucbut1 == MENU_SET_BACK)
472  {
473  return;
474  }
475  }
476  // single shot back "emergency exit"
478  {
479  return;
480  }
481  }
482 }
uint8_t ClockIsRunning(void)
Value used as parameter to ClockSetStatus() to start clock.
Definition: ClockKernel.c:228
Edit target time.
"SvSrt" | Schneller Vorlauf bis Startzeit
bool PushButtonSingleShotBack(void)
Test if button back is pressed.
Definition: PushButton.c:158
Subroutines for UserInterfaceMenu.
void UserInterfaceLcdNormalStartTimeSet(uint8_t ucminute, uint8_t uchour)
Write LCD display "NmSZt".
"Zurck" | Zurueck
A struct with hour and minute.
Definition: ClockKernel.h:69
void ClockSetTime(fclock_t newValue)
Set actual time.
Definition: ClockKernel.c:301
void UserInterfaceLcdNormalCurrentTimeSet(uint8_t ucminute, uint8_t uchour)
Write LCD display "NmAZt".
void UserInterfaceMenueNormalTimeFactor(void)
Set time factor.
uint8_t ClockReadTimeFactor(void)
Get time factor.
Definition: ClockKernel.c:350
void ClockSetStatus(uint8_t ucStatus)
Set status of pulse generator.
Definition: ClockKernel.c:187
Subroutines for acess to LCD for Normal.
Edit current time.
uint8_t ClockReadEndTimeMinute(void)
Get the minute of the end time.
Definition: ClockKernel.c:422
static void UserInterfaceMenueNormalTime(tTimes which)
Menu normal: edit time value ("NmSZt", "NmAZt" or "NmZZt").
void ClockSetStartTimeMinute(uint8_t ucMinute)
Set the minute of the start time.
Definition: ClockKernel.c:362
#define CLOCK_TIME_FACTOR_MIN
minimum *10 (10 = 1:1,0)
Definition: ClockKernel.h:96
void UserInterfaceMenueNormalCurrentTime(void)
Set current time.
void UserInterfaceMenueNormalClock(void)
Normal clock operation.
void UserInterfaceLcdNormalQuick(menuFastFwd_t ucbut)
Write LCD display in Normal Mode ("NmSvr").
Subroutines for UserInterfaceMenuNormal.
void lcd_clear(void)
Clear and home the LCD.
Definition: lcd.c:179
void ClockSetStartTimeHour(uint8_t ucHour)
Set the hour of the start time.
Definition: ClockKernel.c:386
void UserInterfaceLcdNormalTargetTime(menuSetTime_t ucbut)
Write LCD display "NmZZt".
void UserInterfaceLcdNormalCurrentTime(menuSetTime_t ucbut)
Write LCD display "NmAZt".
void UserInterfaceLcdNormalTimeFactor(uint8_t ucbut)
Write LCD display while setting time factor.
uint8_t minute
minute value 0..59
Definition: ClockKernel.h:71
void ClockSetEndTimeHour(uint8_t ucHour)
Set the hour of the end time.
Definition: ClockKernel.c:434
void ClockSetEndTimeMinute(uint8_t ucMinute)
Set the minute of the end time.
Definition: ClockKernel.c:410
menuFastFwd_t
Enum used for Fast Forward Menu to select between Start Time or 00:00.
void UserInterfaceMenueNormalStartTime(void)
Set start time.
void UserInterfaceLcdNormalStartTime(menuSetTime_t ucbut)
Write LCD display "NmSZt".
void UserInterfaceMenueNormalTargetTime(void)
Set target time.
bool PushButtonSingleShotUp(void)
Test if button up is pressed.
Definition: PushButton.c:169
Push button debouncing module for Atmel AVR.
menuSetTime_t
Enum used for Menus where Hour and Minute of a time value are modified.
#define CLOCK_TIME_FACTOR_MAX
maximum *10 (119 = 1:11.9)
Definition: ClockKernel.h:97
bool PushButtonSingleShotDown(void)
Test if button down is pressed.
Definition: PushButton.c:180
void ClockSetPeriod(uint16_t uiPeriod)
Set length of model minute in 100ms.
Definition: ClockKernel.c:239
"Zurck" | Zurueck
menuNormalClock_t
Enum used for Normal Clock Menu.
uint8_t PushButtonGetUpDownValue(uint8_t ucbut, uint8_t ucmin, uint8_t ucmax)
Get selection value by up and down button.
Definition: PushButton.c:217
"Minte" | Minute einstellen
void UserInterfaceLcdNormalTargetTimeSet(uint8_t ucminute, uint8_t uchour)
Write LCD display "NmZZt".
uint8_t ClockReadEndTimeHour(void)
Get the hour of the end time.
Definition: ClockKernel.c:446
uint8_t hour
hour value 0..23
Definition: ClockKernel.h:70
void ClockSetTimeFactor(uint8_t ucFactor)
Set time factor.
Definition: ClockKernel.c:331
LCD interface header file.
"Stnde" | Stunde einstellen
void UserInterfaceLcdNormalQuickClock(menuFastFwd_t ucbut, menuNormalClock_t ucbut1, uint8_t ucminute, uint8_t uchour)
Write LCD display in Normal Mode ("SvSrt" or "SvNul").
Edit start time.
void UserInterfaceLcdNormalClock(menuNormalClock_t ucbut)
Write LCD display in Normal Mode ("NmUhr").
#define CLOCK_MIDNIGHT
"00:00" alias "24:00"
Definition: ClockKernel.h:74
uint16_t ClockReadPeriod(void)
Get length of model minute in 100ms.
Definition: ClockKernel.c:255
"Stop " | Uhr Stoppen
void UserInterfaceMenueNormalQuick(void)
Quick step forward.
bool PushButtonSingleShotEnter(void)
Test if button enter is pressed.
Definition: PushButton.c:147
uint8_t ClockReadStartTimeHour(void)
Get the hour of the start time.
Definition: ClockKernel.c:398
uint8_t ClockReadStartTimeMinute(void)
Get the minute of the start time.
Definition: ClockKernel.c:374
tTimes
Used as parameter type for UserInterfaceMenueNormalTime()
User function called by timer ISR.
"Start" | Uhr Start
static void UserInterfaceNormalQuickTo(menuFastFwd_t ucbut)
Fast forward.
fclock_t ClockGetTime(void)
Get actual time.
Definition: ClockKernel.c:317
"SvNul" | Schneller Vorlauf bis 00:00
"Zurck" | Zurueck