-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_acc.cpp
896 lines (742 loc) · 30 KB
/
main_acc.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
#include <Arduino_FreeRTOS.h>
#include <LiquidCrystal.h>
#include <arduino.h>
#include <task.h>
#include <timers.h>
#include <semphr.h> // add the FreeRTOS functions for Semaphores (or Flags).
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
#define TICK_SHIFT ( 24UL )
#define ALM_TRG_SHIFT ( 23UL )
#define STARTUP_SHIFT ( 22UL )
#define STATE_SHIFT ( 20UL )
#define ALM_EN_SHIFT ( 19UL )
#define FLD_SHIFT ( 17UL )
#define ALM_DURATION_SEC ( 60UL )
enum ALM_TRG
{
ALM_TRG_OFF = ( 0UL<<ALM_TRG_SHIFT ),
ALM_TRG_ON = ( 1UL<<ALM_TRG_SHIFT )
}alm_trg;
enum STATE
{
NORMAL = ( 0UL<<STATE_SHIFT ),
TIME_SET = ( 1UL<<STATE_SHIFT ),
ALARM_SET = ( 2UL<<STATE_SHIFT )
} State;
enum ACTIVE_FIELD
{
ACT_SEC = ( 0UL<<FLD_SHIFT ),
ACT_HH = ( 1UL<<FLD_SHIFT ),
ACT_MM = ( 2UL<<FLD_SHIFT ),
ACT_ALM = ( 3UL<<FLD_SHIFT )
} act_fld;
enum ALM_EN
{
ALM_EN_OFF = ( 0UL<<ALM_EN_SHIFT ),
ALM_EN_ON = ( 1UL<<ALM_EN_SHIFT )
}alm_en;
#define TICK_MASK ((uint32_t) ( 1UL<<TICK_SHIFT ))
#define ALM_TRG_MASK ((uint32_t) ( 1UL<<ALM_TRG_SHIFT ))
#define STARTUP_MASK ((uint32_t) ( 1UL<<STARTUP_SHIFT ))
#define STATE_MASK ((uint32_t) ( 3UL<<STATE_SHIFT ))
#define ALM_EN_MASK ((uint32_t) ( 1UL<<ALM_EN_SHIFT ))
#define FLD_MASK ((uint32_t) ( 3UL<<FLD_SHIFT ))
#define TIME_MASK ((uint32_t) 0x0001FFFF)
/* Priorities at which the tasks are created. */
#define tskReadInput_PRIORITY ( tskIDLE_PRIORITY + 1 )
#define tskReadTime_PRIORITY ( tskIDLE_PRIORITY + 2 )
#define tskController_PRIORITY ( tskIDLE_PRIORITY + 4 )
#define tskWriteDC_PRIORITY ( tskIDLE_PRIORITY + 3 )
/* The rate at which time-tick is sent from ReadTime to Controller.
The times are converted from milliseconds to ticks using the pdMS_TO_TICKS() macro. */
#define ReadTime_FREQUENCY_MS pdMS_TO_TICKS( 1000UL ) // Send Tick every 1000 mS
/* The rate at which keyboard input is checked by ReadLPC.
The times are converted from milliseconds to ticks using the pdMS_TO_TICKS() macro. */
#define ReadInput_FREQUENCY_MS pdMS_TO_TICKS( 50UL )
/* The number of items the queue can hold at once. */
#define QUEUE_LENGTH ( 6 )
/* Number of cycles to debounce switches in tskReadInput() */
#define DEBOUNCE ( 2 )
/* The values sent to the queueController. */
#define btnRIGHT ( 0UL )
#define btnUP ( 1UL )
#define btnDOWN ( 2UL )
#define btnLEFT ( 3UL )
#define btnSELECT ( 4UL )
#define btnNONE ( 5UL )
#define TIME_TICK ( 6UL )
/*-----------------------------------------------------------*/
/*
* The tasks as described in the Decomposition.pdf file.
*/
static void tskReadInput (void *pvParameters);
static void tskReadTime (void *pvParameters);
static void tskController(void *pvParameters);
static void tskWriteDC (void *pvParameters);
//static TaskHandle_t htskWriteLC;
/*-----------------------------------------------------------*/
/* The queue used by Controller and WriteDC tasks. */
static QueueHandle_t queueWriteDC = NULL;
/* The queue used by ReadLPC, ReadTime, and Controller tasks. */
static QueueHandle_t queueController = NULL;
void main_acc(void)
{
Serial.println();
Serial.println();
Serial.println("Starting ACC");
/* Create the queues. */
queueWriteDC = xQueueCreate(QUEUE_LENGTH, sizeof(uint32_t));
queueController = xQueueCreate(QUEUE_LENGTH, sizeof(uint32_t));
lcd.begin(16, 2); // start the library
lcd.setCursor(0,0);
lcd.print("Push the buttons"); // print a simple message
// if ((queueController != NULL))
if (( queueWriteDC != NULL ) && (queueController != NULL))
{
/* Create the tasks. */
xTaskCreate(tskReadInput, /* The function that implements the task. */
"ReadInput", /* The text name assigned to the task - for debug only as it is not used by the kernel. */
configMINIMAL_STACK_SIZE+5, /* The size of the stack to allocate to the task. */
NULL, /* The parameter passed to the task - not used in this simple case. */
tskReadInput_PRIORITY, /* The priority assigned to the task. */
NULL ); /* The task handle is not required, so NULL is passed. */
xTaskCreate(tskReadTime, "ReadTime", configMINIMAL_STACK_SIZE+5, NULL,
tskReadTime_PRIORITY, NULL );
xTaskCreate(tskController, "Controller", configMINIMAL_STACK_SIZE+15, NULL,
tskController_PRIORITY, NULL);
// xTaskCreate(tskWriteDC, "WriteLC", configMINIMAL_STACK_SIZE+60, NULL,
// tskWriteDC_PRIORITY, NULL);
xTaskCreate(tskWriteDC, "WriteLC", configMINIMAL_STACK_SIZE+30, NULL,
tskWriteDC_PRIORITY, NULL);
}
// Now the Task scheduler, which takes over control of scheduling individual Tasks, is automatically started.
// No need to call vTaskStartScheduler();
}
static void tskReadInput(void *pvParameters)
{
TickType_t xNextWakeTime;
const TickType_t xBlockTime = ReadInput_FREQUENCY_MS;
uint32_t ulReceivedValue = btnNONE;
uint32_t ulQueuedValue = btnNONE;
uint32_t ulLastValue = btnNONE;
int val;
uint8_t cnt = 0;
uint32_t curBtn;
uint32_t lastBtn = btnNONE;
/* Prevent the compiler warning about the unused parameter. */
(void)pvParameters;
/* Initialise xNextWakeTime - this only needs to be done once. */
xNextWakeTime = xTaskGetTickCount();
for (;; )
{
/* Check Key Input */
val = analogRead(0); // read the value from the sensor
if (val >= 652) curBtn = btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
if (val < 38) curBtn = btnRIGHT;
if (val < 136 && val >= 38) curBtn = btnUP;
if (val < 259 && val >= 136) curBtn = btnDOWN;
if (val < 410 && val >= 259) curBtn = btnLEFT;
if (val < 652 && val >= 410) curBtn = btnSELECT;
/* Debounce Key Input */
if(curBtn == lastBtn)
{
cnt++;
if(cnt >= DEBOUNCE)
{
ulQueuedValue = curBtn;
cnt = 0;
}
}
lastBtn = curBtn;
/* Send Key Input to Queue if New Key Pressed */
if(ulQueuedValue != ulLastValue)
{
Serial.print("ReadInput: ");
switch(ulQueuedValue)
{
case btnNONE:
Serial.println("NONE");
break;
case btnRIGHT:
Serial.println("RIGHT");
break;
case btnUP:
Serial.println("UP");
break;
case btnDOWN:
Serial.println("DOWN");
break;
case btnLEFT:
Serial.println("LEFT");
break;
case btnSELECT:
Serial.println("SELECT");
break;
}
/* queue input. */
xQueueSend(queueController, &ulQueuedValue, 0U);
ulLastValue = ulQueuedValue;
}
}
/* Place this task in the blocked state until it is time to run again.
While in the Blocked state this task will not consume any CPU time. */
vTaskDelayUntil(&xNextWakeTime, xBlockTime);
}
/*-----------------------------------------------------------*/
static void tskReadTime(void *pvParameters)
{
TickType_t xNextWakeTime;
const TickType_t xBlockTime = ReadTime_FREQUENCY_MS;
uint32_t ulQueuedValue;
/* Prevent the compiler warning about the unused parameter. */
(void)pvParameters;
/* Initialise xNextWakeTime - this only needs to be done once. */
xNextWakeTime = xTaskGetTickCount();
for (;; )
{
/* queue time-tick. */
Serial.println("ReadTime: Produce TICK");
ulQueuedValue = TIME_TICK;
xQueueSend(queueController, &ulQueuedValue, 0U);
/* Place this task in the blocked state until it is time to run again.
While in the Blocked state this task will not consume any CPU time. */
vTaskDelayUntil(&xNextWakeTime, xBlockTime);
}
}
/*-----------------------------------------------------------*/
static void tskController(void *pvParameters)
{
uint32_t ulReceivedValue;
static uint32_t ulQueuedValue;
static uint32_t NTime, STime, ATime;
uint32_t hr;
uint32_t mn;
// Initialize flags
alm_trg = ALM_TRG_OFF;
alm_en = ALM_EN_OFF;
act_fld = ACT_HH;
State = TIME_SET;
bool bNEWSTATE = true;
bool bStartUp = true;
ulReceivedValue = btnNONE;
/* Prevent the compiler warning about the unused parameter. */
(void)pvParameters;
for (;; )
{
/* Wait until something arrives in the queue - this task will block indefinitely.
It will not use any CPU time while it is in the Blocked state. */
xQueueReceive(queueController, &ulReceivedValue, portMAX_DELAY);
Serial.print("Controller: ");
switch(ulReceivedValue)
{
case btnNONE:
Serial.println("NONE");
break;
case btnRIGHT:
Serial.println("RIGHT");
break;
case btnUP:
Serial.println("UP");
break;
case btnDOWN:
Serial.println("DOWN");
break;
case btnLEFT:
Serial.println("LEFT");
break;
case btnSELECT:
Serial.println("SELECT");
break;
}
/* State Machine */
switch(State)
{
/******************************************** NORMAL State ********************************************/
case NORMAL:
if(bNEWSTATE)
{
Serial.println("NORMAL State");
bNEWSTATE = false;
act_fld = ACT_SEC;
ulQueuedValue &= ~(FLD_MASK);
ulQueuedValue |= act_fld;
// Change State
ulQueuedValue &= ~(STATE_MASK);
ulQueuedValue |= State;
//
// Clear and Re-set active field
act_fld = ACT_SEC;
ulQueuedValue &= ~(FLD_MASK);
ulQueuedValue |= act_fld;
// Clear and Replace STime
ulQueuedValue &= ~(TIME_MASK);
ulQueuedValue |= NTime;
Serial.print("Normal: ");
Serial.println(ulQueuedValue);
}
switch(ulReceivedValue)
{
case btnUP:
State = TIME_SET;
bNEWSTATE = true;
break;
case btnDOWN:
State = ALARM_SET;
bNEWSTATE = true;
break;
case btnSELECT:
// alm_trg = ALM_TRG_OFF;
ulQueuedValue &= ~(ALM_TRG_MASK);
break;
case TIME_TICK:
// Clear and Replace with updated NTime
ulQueuedValue &= ~(TIME_MASK);
ulQueuedValue |= NTime;
Serial.println(); Serial.print("Compare NTIME and ATime: "); Serial.print(NTime); Serial.print(" "); Serial.println(ATime);
if(NTime==ATime && alm_en==ALM_EN_ON)
{
// alm_trg = ALM_TRG_ON;
ulQueuedValue &= ~(ALM_TRG_MASK);
ulQueuedValue |= ALM_TRG_MASK;
}
if(NTime == ATime+ALM_DURATION_SEC)
{
// alm_trg = ALM_TRG_OFF;
ulQueuedValue &= ~(ALM_TRG_MASK);
}
break;
}
xQueueSend(queueWriteDC, &ulQueuedValue, 0U);
break;
/******************************************** END of NORMAL State ********************************************/
/******************************************** TIME_SET State ********************************************/
case TIME_SET:
bool bUPDATE_TIME;
if(bNEWSTATE)
{
bNEWSTATE = false;
bUPDATE_TIME = false;
act_fld = ACT_HH;
ulQueuedValue &= ~(FLD_MASK);
ulQueuedValue |= act_fld;
// Change State
ulQueuedValue &= ~(STATE_MASK);
ulQueuedValue |= State;
// Use current NTime (current time) but set seconds to 00
hr = (uint32_t)(NTime/3600UL);
mn = (uint32_t)((NTime - hr*3600UL)/60UL);
STime = hr*3600UL+mn*60UL;
// Clear and Replace STime
ulQueuedValue &= ~(TIME_MASK);
ulQueuedValue |= STime;
if(bStartUp)
ulQueuedValue |= STARTUP_MASK;
Serial.println(ulQueuedValue);
}
switch(ulReceivedValue)
{
case btnSELECT:
if(!bStartUp)
{
State = NORMAL;
bNEWSTATE = true;
if(bUPDATE_TIME)
{
NTime = STime;
}
}
break;
case btnLEFT:
if(act_fld == ACT_MM)
act_fld = ACT_HH;
break;
case btnRIGHT:
if(act_fld == ACT_HH)
act_fld = ACT_MM;
break;
case btnUP:
bStartUp = false;
bUPDATE_TIME = true;
// Clear StartUp Bit
ulQueuedValue &= ~(STARTUP_MASK);
switch(act_fld)
{
case ACT_HH:
Serial.println("Incrementing up hour");
STime += 3600UL;
if(STime >= 24UL*3600UL)
STime -= 24UL*3600UL;
break;
case ACT_MM:
hr = (uint32_t)(STime/3600UL);
mn = (uint32_t)((STime - hr*3600UL)/60UL);
mn++;
if(mn>59UL)
mn = 0UL;
STime = hr*3600UL+mn*60UL;
break;
}
break;
case btnDOWN:
bStartUp = false;
bUPDATE_TIME = true;
// Clear StartUp Bit
ulQueuedValue &= ~(STARTUP_MASK);
switch(act_fld)
{
case ACT_HH:
// Serial.print("Incrementing down hour "); Serial.println(STime);
if(STime<3600UL)
STime += 23UL*3600UL;
else
STime -= 3600UL;
break;
case ACT_MM:
hr = (uint32_t)(STime/3600UL);
mn = (uint32_t)((STime - hr*3600UL)/60UL);
if(mn==0UL)
mn = 59UL;
else
mn--;
STime = hr*3600UL+mn*60UL;
break;
}
}
ulQueuedValue &= ~(FLD_MASK);
ulQueuedValue |= act_fld;
// Clear and Re-set active field
ulQueuedValue &= ~(FLD_MASK);
ulQueuedValue |= act_fld;
// Clear and Replace STime
ulQueuedValue &= ~(TIME_MASK);
ulQueuedValue |= STime;
xQueueSend(queueWriteDC, &ulQueuedValue, 0U);
break;
/******************************************** END of TIME_SET State ********************************************/
/******************************************** ALARM_SET State ********************************************/
case ALARM_SET:
if(bNEWSTATE)
{
Serial.println("ALARM_SET State");
bNEWSTATE = false;
ulQueuedValue &= ~(ALM_EN_MASK);
ulQueuedValue |= alm_en;
Serial.print("alm_en: "); Serial.println(alm_en);
// Initialize active field to HH
act_fld = ACT_HH;
ulQueuedValue &= ~(FLD_MASK);
ulQueuedValue |= act_fld;
// Change State
ulQueuedValue &= ~(STATE_MASK);
ulQueuedValue |= State;
// Clear and Replace NTime with ATime
ulQueuedValue &= ~(TIME_MASK);
ulQueuedValue |= ATime;
}
switch(ulReceivedValue)
{
case btnSELECT:
if(!bStartUp)
{
State = NORMAL;
bNEWSTATE = true;
}
break;
case btnLEFT:
if(act_fld == ACT_MM)
act_fld = ACT_HH;
else if(act_fld == ACT_ALM)
act_fld = ACT_MM;
break;
case btnRIGHT:
if(act_fld == ACT_HH)
act_fld = ACT_MM;
else if(act_fld == ACT_MM)
act_fld = ACT_ALM;
break;
case btnUP:
switch(act_fld)
{
case ACT_HH:
// Serial.println("Incrementing up hour");
ATime += 3600UL;
if(ATime >= 24UL*3600UL)
ATime -= 24UL*3600UL;
break;
case ACT_MM:
hr = (uint32_t)(ATime/3600UL);
mn = (uint32_t)((ATime - hr*3600UL)/60UL);
mn++;
if(mn>59UL)
mn = 0UL;
ATime = hr*3600UL+mn*60UL;
break;
case ACT_ALM:
alm_en = ALM_EN_ON;
// ulQueuedValue &= ~(ALM_EN_MASK);
// ulQueuedValue |= alm_en;
break;
}
break;
case btnDOWN:
switch(act_fld)
{
case ACT_HH:
// Serial.print("Incrementing down hour "); Serial.println(ATime);
if(ATime<3600UL)
ATime += 23UL*3600UL;
else
ATime -= 3600UL;
break;
case ACT_MM:
hr = (uint32_t)(ATime/3600UL);
mn = (uint32_t)((ATime - hr*3600UL)/60UL);
if(mn==0UL)
mn = 59UL;
else
mn--;
ATime = hr*3600UL+mn*60UL;
break;
case ACT_ALM:
alm_en = ALM_EN_OFF;
// ulQueuedValue &= ~(ALM_EN_MASK);
// ulQueuedValue |= alm_en;
break;
}
}
// Clear and Re-set alarm enable
ulQueuedValue &= ~(ALM_EN_MASK);
ulQueuedValue |= alm_en;
// Clear and Re-set active field
ulQueuedValue &= ~(FLD_MASK);
ulQueuedValue |= act_fld;
// Clear and Replace STime
ulQueuedValue &= ~(TIME_MASK);
ulQueuedValue |= ATime;
xQueueSend(queueWriteDC, &ulQueuedValue, 0U);
break;
}
/******************************************** END of ALARM_SET State ********************************************/
/******************************************** END OF STATE MACHINE ********************************************/
switch(ulReceivedValue)
{
case TIME_TICK:
Serial.println("TICK");
if(~bStartUp)
{
if(NTime<24UL*3600UL)
NTime++;
else
NTime = 0UL;
}
//Set Tick bit
ulQueuedValue &= ~(TICK_MASK);
ulQueuedValue |= TICK_MASK;
/* queue input. */
xQueueSend(queueWriteDC, &ulQueuedValue, 0U);
// Clear Tick bit
ulQueuedValue &= ~(TICK_MASK);
break;
}
}
}
/*-----------------------------------------------------------*/
static void tskWriteDC( void *pvParameters )
{
uint32_t ulReceivedValue;
uint32_t tm;
uint32_t hh, mm;
int buzzerPin = 11;
pinMode(buzzerPin, OUTPUT);
char *meridien;
bool bFlash=false;
/* Prevent the compiler warning about the unused parameter. */
( void ) pvParameters;
for( ;; )
{
/* Wait until something arrives in the queue - this task will block indefinitely.
It will not use any CPU time while it is in the Blocked state. */
xQueueReceive(queueWriteDC, &ulReceivedValue, portMAX_DELAY);
Serial.print("WriteDC:");
Serial.print(ulReceivedValue); Serial.print(" ");
tm = (uint32_t) ulReceivedValue&TIME_MASK;
Serial.print(tm); Serial.print(" ");
hh = (uint32_t) tm/3600UL;
mm = (uint32_t) (tm-hh*3600UL)/60UL;
Serial.print("Startup Mask: "); Serial.println(ulReceivedValue&STARTUP_MASK);
// uint32_t curstate = ulReceivedValue&STATE_MASK;
// uint32_t curfield = ulReceivedValue&FLD_MASK;
// uint32_t cur_alrm_en = ulReceivedValue&ALM_EN_MASK;
// uint32_t cur_alrm_trg = ulReceivedValue&ALM_TRG_MASK;
// Serial.print("State Mask: "); Serial.println((ulReceivedValue&STATE_MASK));
// Serial.print("Field Mask: "); Serial.println((ulReceivedValue&FLD_MASK));
// Serial.print("ALM_EN Mask: "); Serial.println((ulReceivedValue&ALM_EN_MASK));
Serial.print("ALM_TRG Mask: "); Serial.println((ulReceivedValue&ALM_TRG_MASK));
if(hh<12UL)
meridien = "AM";
else
meridien = "PM";
if(!(ulReceivedValue&STARTUP_MASK) && (hh==0UL))
hh = 12UL;
else if(hh>=13)
hh -= 12;
Serial.print(hh); Serial.print(":");
if(mm<10UL) Serial.print("0");
Serial.print(mm); Serial.print(" ");
Serial.print(meridien);
Serial.println();
lcd.clear();
lcd.setCursor(2,0);
if(hh<10UL)
lcd.print(" ");
if(ulReceivedValue&TICK_MASK)
bFlash = !bFlash;
// switch(curstate)
switch(ulReceivedValue&STATE_MASK)
{
case NORMAL:
lcd.print(hh);
Serial.print("bFlash: "); Serial.println(bFlash);
if(bFlash)
lcd.print(":");
else
lcd.print(" ");
if(mm<10)
lcd.print("0");
lcd.print(mm);
lcd.print(" ");
lcd.print(meridien);
digitalWrite(buzzerPin, LOW);
if((ulReceivedValue&ALM_EN_MASK)==ALM_EN_ON)
{
if(!(ulReceivedValue&ALM_TRG_MASK))
lcd.print(" ALM");
else
{
if(bFlash)
{
lcd.print(" ALM");
digitalWrite(buzzerPin, HIGH);
}
else
{
lcd.print(" ");
digitalWrite(buzzerPin, LOW);
}
}
}
break;
case TIME_SET:
// if(curfield == ACT_HH)
if((ulReceivedValue&FLD_MASK) == ACT_HH)
{
if(bFlash)
lcd.print(hh);
else
if(hh<10UL)
lcd.print(" ");
else
lcd.print(" ");
}
else
lcd.print(hh);
lcd.print(":");
// if(curfield == ACT_MM)
if((ulReceivedValue&FLD_MASK) == ACT_MM)
{
if(bFlash)
{
if(mm<10)
lcd.print("0");
lcd.print(mm);
}
else
lcd.print(" ");
}
else
{
if(mm<10)
lcd.print("0");
lcd.print(mm);
}
lcd.print(" ");
if((ulReceivedValue&FLD_MASK) == ACT_HH)
{
if(bFlash )
lcd.print(meridien);
else
lcd.print(" ");
}
else
lcd.print(meridien);
lcd.setCursor(2,1);
lcd.print("Set Time");
break;
case ALARM_SET:
if((ulReceivedValue&FLD_MASK) == ACT_HH)
{
if(bFlash)
lcd.print(hh);
else
if(hh<10UL)
lcd.print(" ");
else
lcd.print(" ");
}
else
lcd.print(hh);
lcd.print(":");
if((ulReceivedValue&FLD_MASK) == ACT_MM)
{
if(bFlash)
{
if(mm<10)
lcd.print("0");
lcd.print(mm);
}
else
lcd.print(" ");
}
else
{
if(mm<10)
lcd.print("0");
lcd.print(mm);
}
lcd.print(" ");
if((ulReceivedValue&FLD_MASK) == ACT_HH)
{
if(bFlash)
lcd.print(meridien);
else
lcd.print(" ");
}
else
lcd.print(meridien);
// lcd.print(" ");
if((ulReceivedValue&FLD_MASK)==ACT_ALM)
{
if(bFlash)
{
if((ulReceivedValue&ALM_EN_MASK)==ALM_EN_ON)
lcd.print(" ON ");
else
lcd.print(" OFF");
}
else
lcd.print(" ");
}
else
{
if((ulReceivedValue&ALM_EN_MASK)==ALM_EN_ON)
lcd.print(" ON ");
else
lcd.print(" OFF");
}
// lcd.setCursor(2,1);
// lcd.print("Set Alarm");
break;
}
}
}
/*-----------------------------------------------------------*/