This repository has been archived by the owner on Dec 17, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
menufunctions.c
1451 lines (1340 loc) · 31.3 KB
/
menufunctions.c
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
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <wiringPi.h>
#include <lcd.h>
#include <stdio.h>
#include <mcp23017.h>
#include "finalHeader.h"
//GLOBAL VARIABLES
extern unsigned char devices[rows][columns];
extern int failedCon[126][126];
extern int page; // variables to keep track of page and line
extern int line;
extern int set;
extern int conStatus;
extern int lcdhdl;
extern int hour;
extern int min;
extern int day;
extern char dayTime[2];
extern int entry;
extern int mcClock[3];
int lcdBusy;
int holdFlag = 0;
extern int hvacSetting;
int toRoom = 1;
extern int mainHalt; //used to halt the main program while alternate threads while they complete critical tasks. (adding devices)
int threadGreenLight; //gives permission to threads to coninue once the main reaches a safe stopping point for mainHalt usage.
int buttonPressed;
/**********************************************************************
<void updateDisplay>
Description: This function directly communicates with the up, down,
sync, and enter button in other to change the difeerent lcd pages
and displays it on the lcd.
************************************************************************/
void updateDisplay(void)
{
//-Display section
//-come back to this section each time a line or a page is updated
if(!buttonPressed)
{
buttonPressed = smartDelay(20);
}
if(buttonPressed == 0)
{
return;
}
else if(buttonPressed == syncSwitch)
{
page = 7;
line = 0;
}
printf("\nFor logic:\nPage: %d\nLine: %d\n", page,line);
switch(page)
{
case 0:
page0();//MainDisplay
break;
case 1:
page1();//settings
break;
case 2:
page2();//settingsConfig
break;
case 3:
page3();//errorPage1
break;
case 4:
page4();//setTimeDisplay
break;
case 5:
page5and6();//errorPage2
break;
case 6:
page5and6();//warningPage
break;
case 7:
page7();//syncMenu
break;
case 8:
page8();//manageDeviceMenu
break;
case 9:
page9();//addDeviceMenu
break;
case 10:
page10();//removeDeviceMenu
break;
case 11:
page11();//remDevWarn
break;
case 12:
page12();//removing devices action
break;
case 13:
page13();//Room select for addReg.
break;
}
display(page, line, set);
buttonPressed = 0;
return;
}
/**********************************************************************
void lcdInitialization(void)
Description: This function initialises the Lcd by calling the LCD
Init function of lcd.h. It also creates the LCD handler variable
that will be used to control the lcd display
************************************************************************/
void lcdinitialization(void)
{
//LCD initialization and handle set up
lcdhdl = lcdInit(2,16,4,LCD_RS, LCD_E, LCD_D4, LCD_D5, LCD_D6, LCD_D7,0,0,0,0);
return;
}
/********************************************************************
void lcdBoot(void)
Description: This function is an introductory page which shows
the name, of all the group members, class, and semester. This is
the page been displayed each time the device boots in other to
provide a brief intro to the user
********************************************************************/
void lcdBoot(void)
{
lcdClear(lcdhdl);
lcdPosition(lcdhdl,0,0); //Postion cursor on the first line in the first column
lcdPuts(lcdhdl,"Christa McDaniel"); //prints our names, class, term, and group number
delay(1000);
lcdPosition(lcdhdl,0,1);
lcdPuts(lcdhdl,"Raul Rojas ");
delay(1000);
lcdPosition(lcdhdl,0,0);
lcdPuts(lcdhdl,"Alex Fotso ");
delay(1000);
lcdPosition(lcdhdl,0,0);
lcdPuts(lcdhdl,"ECET 4720-Group2");
lcdPosition(lcdhdl,0,1);
lcdPuts(lcdhdl,"Fall 2016 ");
delay(2000);
lcdClear(lcdhdl); //clears LCD
delay(2000);
lcdClear(lcdhdl);
lcdPosition(lcdhdl,0,0);
lcdPuts(lcdhdl,"Syncing.. Press");
lcdPosition(lcdhdl,0,1);
lcdPuts(lcdhdl,"Sync to finish.");
return;
}
void dispTime(void)
{
while(lcdBusy)
{}
lcdBusy = 1;
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, "Time: %02d:%02d %cM", mcClock[arrHr], mcClock[arrMin], dayTime[day]);
lcdBusy = 0;
return;
}
/********************************************************************
void mainDisplay(void)
Description: This function provides the lcd page for the default
display of the master control. This is the display when the
master cpntrol is in stand by mode or doing nothing. It displays
The time and the connection statue of the Master Control
********************************************************************/
void mainDisplay(void)
{
lcdClear (lcdhdl);
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, "Time: %02d:%02d %cM", mcClock[arrHr], mcClock[arrMin], dayTime[day]);
if(conStatus)
{
lcdPosition(lcdhdl,0,1);
lcdPrintf(lcdhdl, " Status: Errors ");
}
else
{
lcdPosition(lcdhdl,0,1);
lcdPrintf(lcdhdl, " Status: Ok ");
}
//lcdPosition(lcdhdl,14,0);
return;
}
/********************************************************************
void lcdInitialization(void)
Description: This function displays the different options the
user has at his disposal when using the master control. This
functions include taking direct control of the HVAC and
displaying the Connectiom errors or warnings.
*********************************************************************/
void settings(int lines)
{
lcdClear(lcdhdl);
if (lines == 0)
{
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, "-> HVAC Settings");
lcdPosition(lcdhdl,0,1);
lcdPrintf(lcdhdl, " Error Page");
}
else if (lines == 1)
{
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, " HVAC Settings");
lcdPosition(lcdhdl,0,1);
lcdPrintf(lcdhdl, "-> Error Page");
}
else if(lines == 2)
{
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, "-> Set Time");
lcdPosition(lcdhdl,0,1);
lcdPrintf(lcdhdl, " BACK ");
}
else if(lines == 3)
{
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, " Set Time");
lcdPosition(lcdhdl,0,1);
lcdPrintf(lcdhdl, " -> BACK ");
}
else if(lines > 3 || lines < 0)
{
printf("line out of range in settings page.\n");
}
return;
}
/********************************************************************
void settingConfig(int)
Description: This function displays the setting details when the
setting option is selected form the HVAC setting page.
It provides the user with the cooling or the heating option
********************************************************************/
void settingConfig(int lines)
{
lcdClear(lcdhdl);
if (lines == 0)
{
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, "-> Heating");
lcdPosition(lcdhdl,0,1);
lcdPrintf(lcdhdl, " Cooling");
}
else if (lines ==1)
{
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, " Heating");
lcdPosition(lcdhdl,0,1);
lcdPrintf(lcdhdl, "-> Cooling");
}
else if (lines == 2)
{
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, "-> Fan");
lcdPosition(lcdhdl,0,1);
lcdPrintf(lcdhdl, " Auto");
}
else if(lines == 3)
{
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, " Fan");
lcdPosition(lcdhdl,0,1);
lcdPrintf(lcdhdl, "-> Auto");
}
else if(lines == 4)
{
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, " Auto");
lcdPosition(lcdhdl,0,1);
lcdPrintf(lcdhdl, " -> BACK");
}
else if(lines > 4 || lines < 0)
{
printf("line out of range in settingsConfig page.\n");
}
return;
}
/********************************************************************
void errorPage1(void)
Description: This function is the display when the error option
is selected from the Settung page. It provided the user with the
option of displaying warning messages or connection errors
messages
********************************************************************/
int errors = 0;
void errorPage1(int lines)
{
errors = countErrors();
lcdClear(lcdhdl);
int warnings = failedCon[0][1];
if (lines == 0)
{
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, "-> Errors: %d",errors);
lcdPosition(lcdhdl,0,1);
lcdPrintf(lcdhdl, " Warnings: %d",warnings);
}
else if(lines == 1)
{
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, " Errors: %d",errors);
lcdPosition(lcdhdl,0,1);
lcdPrintf(lcdhdl, "-> Warnings: %d",warnings);
}
else if(lines == 2)
{
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, " Warnings: %d",warnings);
lcdPosition(lcdhdl,0,1);
lcdPrintf(lcdhdl, " -> BACK");
}
else if(lines > 2 || lines < 0)
{
printf("line out of range in errorPage1 page.\n");
}
return;
}
/********************************************************************
void errorPage2(void)
Description: This function displays the error messages. When the
user is done reading, he presses the enter key in other to return
to the main display
*********************************************************************/
void errorPage2(void)
{
lcdClear(lcdhdl);
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, "Connect. failed with %d devices", errors);
return;
}
/********************************************************************
void warningPage(void)
Description: This function displays the warning generated.
The user has to press the enter key when he is done reading in
other to return to the main menu
**********************************************************************/
void warningPage(void)
{
if(failedCon[0][1] == 1)
{
lcdClear(lcdhdl);
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, "Cannot achieve");
lcdPosition(lcdhdl,0,1);
lcdPrintf(lcdhdl, "desired temps");
delay(1500);
lcdClear(lcdhdl);
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, "Update Hvac ");
lcdPosition(lcdhdl,0,1);
lcdPrintf(lcdhdl, "Settings.");
delay(1500);
page = 2;
line = 0;
lcdBusy = 0;
display(page, line, set);
}
return;
}
/********************************************************************
void display(int, int)
Description: This function gives priority to the page the user
calls. It eases the use of the Update display function
********************************************************************/
void display(int pages, int lines, int time)
{
while(lcdBusy)
{}
lcdBusy = 1;
printf("For Display:\nPage: %d\nLine: %d\n", page,line);
switch(pages)
{
case 0:
mainDisplay();
break;
case 1:
settings(lines);
break;
case 2:
settingConfig(lines);
break;
case 3:
errorPage1(lines);
break;
case 4:
setTimeDisplay(time);
break;
case 5:
errorPage2();
break;
case 6:
warningPage();
break;
case 7:
syncMenu(lines);
break;
case 8:
manageDeviceMenu(lines);
break;
case 9:
addDeviceMenu(lines);
break;
case 10:
removeDeviceMenu(lines);
break;
case 11:
remDevWarn();
break;
case 12:
SuccessMessage(0,page);
break;
case 13:
toRoomMenu();
break;
}
lcdBusy = 0;
return;
}
/********************************************************************
int smartDisplay(int)
Description: This function creates a delay while listening to
switches. In case a switch is pressed, the delay is aborted and
the pin number of the switched pressed is returned
********************************************************************/
int smartDelay(int i)
{
int j = 0;
int buttonPressed = 0;//return variable.
if(i<20)i=20;//ensure at least 20ms as minimum delay.
i=i/20;//converting time into loop iterations
//iterates i times and exits at i=0 or if power switch is off
while(i != 0 && !digitalRead(pwrSwitch))
{
if(!digitalRead(entSwitch))
{
//wait untill button is released.
while(!digitalRead(entSwitch))
{
delay(20);
}
buttonPressed=entSwitch;
}
else if(!digitalRead(dwnSwitch))
{
while(!digitalRead(dwnSwitch))
{
if(page ==4)
{
if(j >= 25)
{
holdFlag = 1;
delay(100);
if (set == 0)
{
if (hour == 1)
{
hour = 12;
}
else
{
hour = (hour - 1)%13;
}
mcClock[arrHr] = hour;
}
else if (set ==1)
{
if (min == 0)
{
min = 59;
}
else
{
min = (min - 1)%60;
}
mcClock[arrMin] = min;
}
setTimeDisplay(set);
}
else
{
j++;
}
}
delay(20);
}
holdFlag = 0;
j=0;
buttonPressed=dwnSwitch;
}
else if(!digitalRead(upSwitch))
{
while(!digitalRead(upSwitch))
{
if(page ==4)
{
if(j >= 25)
{
holdFlag = 1;
delay(100);
if (set==0)
{
if(hour == 12)
{
hour = 1;
}
else
{
hour = (hour +1)%13;
}
mcClock[arrHr] = hour;
}
else if(set == 1)
{
min = (min+1) % 60;
mcClock[arrMin] = min;
}
setTimeDisplay(set);
}
else
{
j++;
}
}
delay(20);
}
holdFlag = 0;
j = 0;
buttonPressed=upSwitch;
}
else if(!digitalRead(syncSwitch))
{
while(!digitalRead(syncSwitch))
{
delay(20);
}
buttonPressed=syncSwitch;
}
else if(!digitalRead(rstSwitch))
{
while(!digitalRead(rstSwitch))
{
delay(20);
}
buttonPressed=rstSwitch;
}
//if a button was pressed exit loop.
if(buttonPressed!=0)
{
break;
}
else
{
//decriment i and delay 20ms.
i--;
delay(20);
}
}
//return the pin # of button pressed or 0 if none pressed.
return buttonPressed;
}
/********************************************************************
void syncMenu(int)
Description: This function mainly displays the setting options
when the sync button is pressed. The mainoptions it proposses
are Manage Device option and the Re-initialisation option
********************************************************************/
void syncMenu(int lines)
{
lcdClear(lcdhdl);
if (!lines)
{
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, "-> Manage Devices");
lcdPosition(lcdhdl,0,1);
lcdPrintf(lcdhdl, " Re-initialize");
}
else if (lines == 1)
{
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, " Manage Device");
lcdPosition(lcdhdl,0,1);
lcdPrintf(lcdhdl, "-> Re-initialize");
}
else if(lines == 2)
{
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, " Re-initialize");
lcdPosition(lcdhdl,0,1);
lcdPrintf(lcdhdl, " -> Back");
}
else if(lines > 2 || lines < 0)
{
printf("line out of range in syncMenu page.\n");
}
return;
}
/***********************************************************************
<manageDeviceMenu>
Description: This function presents the user with the option of
managing the connected devices. He has the choice of either
adding a device or removing a device. By device we mean thermostat
an Registers
************************************************************************/
void manageDeviceMenu(int lines)
{
lcdClear(lcdhdl);
if (lines == 0)
{
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, "-> Add Device");
lcdPosition(lcdhdl,0,1);
lcdPrintf(lcdhdl, " Remove Device");
}
else if(lines == 1)
{
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, " Add Device");
lcdPosition(lcdhdl,0,1);
lcdPrintf(lcdhdl, "-> Remove Device");
}
else if(lines == 2)
{
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, " Remove Device");
lcdPosition(lcdhdl,0,1);
lcdPrintf(lcdhdl, " -> BACK");
}
else if(lines > 2 || lines < 0)
{
printf("line out of range in manageDeviceMenu page.\n");
}
return;
}
/********************************************************************
<addDeviceMenu>
Description: This function provides the menu display for the
user to select between adding a thermostate or adding a register.
********************************************************************/
void addDeviceMenu(int lines)
{
lcdClear(lcdhdl);
if (!lines)
{
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, "-> Add Register");
lcdPosition(lcdhdl,0,1);
lcdPrintf(lcdhdl, " Add Thermo");
}
else if (lines == 1)
{
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, " Add Register");
lcdPosition(lcdhdl,0,1);
lcdPrintf(lcdhdl, "-> Add Thermo");
}
else if(lines == 2)
{
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, " ADD Thermo");
lcdPosition(lcdhdl,0,1);
lcdPrintf(lcdhdl, " -> BACK");
}
else if(lines > 2 || lines < 0)
{
printf("line out of range in settings page.\n");
}
return;
}
void remDevWarn (void)//page 11
{
lcdClear(lcdhdl);
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, "Remove Unconnect-ed devices?");
return;
}
/********************************************************************
void removeDeviceMenu(int)
description: This function provides the lcd display for the user
to remove a device. It presents the number of device disconected,
and this corresponds to the actual number the user has
disconnected then, he can select the yes option to remove all
those devices. he can also selects the No option which will
bring him back to the Home menu
*********************************************************************/
void removeDeviceMenu(int lines)//page 10
{
/*lcdClear(lcdhdl);
if (!lines)
{
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, "-> Remove Register");
lcdPosition(lcdhdl,0,1);
lcdPrintf(lcdhdl, " Remove Thermo");
}
else
{
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, " Remove Register");
lcdPosition(lcdhdl,0,1);
lcdPrintf(lcdhdl, "-> Remove Thermo");
}*/
lcdClear(lcdhdl);
int critErrors = countErrors();
if (!lines)
{
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, "Remove %d devices", critErrors);
lcdPosition(lcdhdl,0,1);
lcdPrintf(lcdhdl, "->YES NO");
}
else if(lines ==1)
{
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, "Remove %d devices", critErrors);
lcdPosition(lcdhdl,0,1);
lcdPrintf(lcdhdl, " YES ->NO");
}
else if(lines > 1 || lines < 0)
{
printf("line out of range in settings page.\n");
}
return;
}
/********************************************************************
<function name>
<description>
********************************************************************/
void SuccessMessage(int lines, int pages)
{
//printf("in successMessage()\n");
if (pages == 2)
{
if (lines == 0)
{
lcdClear (lcdhdl);
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, "Heating configured");
hvacSetting = 2;
//digitalWrite(FAN, 0);
//digitalWrite(COOL, 1);
//digitalWrite(HEAT, 0);
}
else if(lines == 1)
{
lcdClear (lcdhdl);
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, "Cooling Configured ");
hvacSetting = 1;
//digitalWrite(FAN, 0);
//digitalWrite(HEAT, 1);
//digitalWrite(COOL, 0);
}
else if(lines ==2)
{
lcdClear (lcdhdl);
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, "Fan Configured ");
hvacSetting = 3;
//digitalWrite(HEAT, 1);
//digitalWrite(COOL, 1);
//digitalWrite(FAN, 0);
}
else if(lines == 3)
{
lcdClear (lcdhdl);
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, "Auto Configured ");
hvacSetting = 0;
}
else if(lines > 3 || lines < 0)
{
printf("line out of range in SuccessMessage page 2.\n");
}
printf("hvacSetting: %d\n", hvacSetting);
}
else if(pages == 9)
{
if (lines == 0)
{
lcdClear (lcdhdl);
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, " Register Added");
lcdPosition(lcdhdl,0,1);
lcdPrintf(lcdhdl, " Successfully ");
}
else if(lines ==1)
{
lcdClear (lcdhdl);
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, " Thermostate Added ");
lcdPosition(lcdhdl,0,1);
lcdPrintf(lcdhdl, " Successfully ");
}
else if(lines == 2)//failed to add device message.
{
lcdClear (lcdhdl);
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, "Failed to add");
lcdPosition(lcdhdl,0,1);
lcdPrintf(lcdhdl, "Device.");
}
else if(lines == 3)//instruction message for add device.
{
lcdClear (lcdhdl);
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, "Press sync");
lcdPosition(lcdhdl,0,1);
lcdPrintf(lcdhdl, "button to cancel");
}
else if(lines == 4)
{
lcdClear (lcdhdl);
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, "No thermostats");
lcdPosition(lcdhdl,0,1);
lcdPrintf(lcdhdl, "to add to.");
}
else if(lines > 4 || lines < 0)
{
printf("line out of range in SuccessMessage page 9.\n");
}
}
else if (pages == 12)
{
if (lines == 0)
{
lcdClear (lcdhdl);
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, "Devices Removed");
lcdPosition(lcdhdl,0,1);
lcdPrintf(lcdhdl, "Successfully ");
page = 0;
line = 0;
}
else if(lines > 0 || lines < 0)
{
printf("line out of range in SuccessMessage page 10.\n");
}
}
delay(2000);
return;
}
/*void setTimeDisplay(int timeSet)
{
// We use the global variables for time created above in other to display the set time.
lcdClear(lcdhdl);
if (timeSet == 0)
{
lcdPosition(lcdhdl,3,1);
lcdPrintf(lcdhdl, "^");
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, " %02d : %02d %cM", hour, min, dayTime[day]);
}
else if (timeSet == 1)
{
lcdPosition(lcdhdl,8,1);
lcdPrintf(lcdhdl, "^");
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, " %02d : %02d %cM", hour, min, dayTime[day]);
}
else
{
lcdPosition(lcdhdl,11,1);
lcdPrintf(lcdhdl, "^");
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, " %02d : %02d %cM", hour, min, dayTime[day]);
}
}*/
void setTimeDisplay(int set)
{
// We use the global variables for time created above in other to display the set time.
if(holdFlag)
{
lcdPosition(lcdhdl,0,1);
lcdPrintf(lcdhdl, " %02d : %02d %cM", mcClock[arrHr], mcClock[arrMin], dayTime[day]);
return;
}
lcdClear(lcdhdl);
lcdPosition(lcdhdl,0,1);
lcdPrintf(lcdhdl, " %02d : %02d %cM", mcClock[arrHr], mcClock[arrMin], dayTime[day]);
if (set == 0)
{
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, "Set Hour");
}
else if (set == 1)
{
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, "Set Minutes");
}
else if(set == 2)
{
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, "-> Set AM/PM");
}
else if(set > 2 || set < 0)
{
printf("set out of range in setTimeDisplay.\n");
}
return;
}
void toRoomMenu(void)
{
lcdPosition(lcdhdl,0,0);
lcdPrintf(lcdhdl, "Add register to ");
lcdPosition(lcdhdl,0,1);
lcdPrintf(lcdhdl, "room: %d <- ", toRoom);
return;
}
void page0(void)//mainDisplay
{
//use smart display to detect if any switch is pressed
//take action only if the enter key is pressed
//When enter switch is pressed, we update the page and go back to the display section for the new display
if(buttonPressed == entSwitch)
{
page = 1;
}
return;
}
void page1(void)//settings
{
// if enter key is pressed, we update the page and go to display section to show the new display
//if the up or down button is pressed, we update the line and go back to the display to outline the new line
if (buttonPressed==entSwitch)
{
if ( line == 0)
{
page = 2;
}
else if (line == 1)
{
page = 3;
}
else if (line == 2)
{
page = 4;
}
else if (line == 3) // Back line, if pressed we return to previous screen
{
page = 0;