-
Notifications
You must be signed in to change notification settings - Fork 1
/
Opaq_iaqua.cpp
3276 lines (2887 loc) · 100 KB
/
Opaq_iaqua.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
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
/*
* Opaq is an Open AQuarium Controller firmware. It has been developed for
* supporting several aquarium devices such as ligh dimmers, power management
* outlets, water sensors, and peristaltic pumps. The main purpose is to
* control fresh and salt water aquariums.
*
* Copyright (c) 2016 Andre Pedro. All rights reserved.
*
* This file is part of opaq firmware for aquarium controllers.
*
* opaq firmware is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* opaq firmware is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with opaq firmware. If not, see <http://www.gnu.org/licenses/>.
*
*/
/*
* IAQUA CREDITS TO:
* Dan Cunningham, aka AnotherHobby @ plantedtank.net
* Ryan Truss, aka MrMan
*/
#include "Opaq_iaqua.h"
#include "Opaq_c1.h"
Opaq_iaqua iaqua;
//#include <Time.h>
// #### EVENTS
void Opaq_iaqua::service(unsigned x, unsigned y, unsigned z) {
static touch_evt_type touch_state = TOUCH_UP;
static int n_touch = 0;
static bool touching = false;
bool touch = z > 10;
// detecting touch events
if (touch && (touch_state == TOUCH_UP || touch_state == TOUCH_CLICK)) {
touch_state = TOUCH_DOWN;
touching = true;
n_touch = 0;
} else if (touch &&
(touch_state == TOUCH_DOWN || touch_state == TOUCH_MOVE)) {
touch_state = TOUCH_MOVE;
n_touch++;
} else if (!touch) {
touch_state = TOUCH_UP;
touching = false;
if (n_touch > 0) {
touch_state = TOUCH_CLICK;
}
}
// Serial.println(touch_state);
// Serial.println(n_touch);
// store detected event
if (touch_state == TOUCH_CLICK && eventlist.size() < 10) {
StaticJsonDocument<128> object;
object["type"] = 1;
object["payload"]["x"] = x;
object["payload"]["y"] = y;
object["payload"]["state"] = TOUCH_CLICK;
eventlist.add(object);
}
if (touch_state == TOUCH_CLICK) {
n_touch = 0;
touch_state = TOUCH_UP;
}
}
void Opaq_iaqua::update() {
// get last element from LinkedList
auto doc = eventlist.shift();
// check inactivity event
if (tick > 30) {
disabledscreen = true;
// disable screen [TODO]
}
// if touch then check UI
if (doc["type"] == 1) {
unsigned x = (unsigned)doc["payload"]["x"];
unsigned y = (unsigned)doc["payload"]["y"];
unsigned state = (unsigned)doc["payload"]["state"];
touch_evt_type touch_state = (touch_evt_type)state;
// check inactivity
// enable timer
tick=0;
if (disabledscreen) {
// wake up screen [TODO]
disabledscreen = false;
}
switch (dispScreen) {
case 1: // home screen
homescreen_e(x, y, touch_state);
break;
case 2: // feeding screen
feeding_screen_e(x, y, touch_state);
break;
case 3: // power screen
power_screen_e(x, y, touch_state);
break;
case 4: // settings screen
settings_screen_e(x, y, touch_state);
break;
}
}
}
void Opaq_iaqua::homescreen_e(unsigned x, unsigned y, touch_evt_type id) {
// home screen
if ((x >= 30) && (x <= 90) && (y >= 35) &&
(y <= 86)) // pressed the thermometer to clear a warning
{
if (heaterWarningCleared == false) {
heaterWarningCleared = true; // clear warning
screenHome();
}
}
if ((x >= 150) && (x <= 210) && (y >= 50) &&
(y <= 105)) // pressed the ATO warning to clear
{
if (ATOAlarm) {
Serial.print(F("ATO Alarm cleared.\n"));
ATOAlarm = false; // clear warning
EEPROM.write(44, 0);
myGLCD.setColor(VGA_BLACK);
myGLCD.fillRect(121, 30, 239, 109);
drawATO();
}
}
if ((x >= 10) && (x <= 58) && (y >= 266) && (y <= 314)) // home dock icon
{
screenHome();
// smartStartupPower();
}
if ((x >= 67) && (x <= 115) && (y >= 266) && (y <= 314)) // feeding dock icon
{
screenFeeding();
}
// coordinates of the power putton
if ((x >= 124) && (x <= 172) && (y >= 266) && (y <= 314)) // power dock icon
{
screenPower();
}
// coordinates of the exras button
if ((x >= 181) && (x <= 229) && (y >= 266) &&
(y <= 314)) // settings dock icon
{
screenSettings();
}
}
void Opaq_iaqua::feeding_screen_e(unsigned x, unsigned y, touch_evt_type id) {
// feeding screen
if ((x >= 67) && (x <= 115) && (y >= 223) && (y <= 271)) // stop button
{
feedingStop();
}
if ((x >= 124) && (x <= 172) && (y >= 223) && (y <= 271)) // restart button
{
feedingActive = false;
screenFeeding();
}
if ((x >= 107) && (x <= 129) && (y >= 294) && (y <= 318)) // home button
{
screenHome();
}
}
void Opaq_iaqua::feedingStop() {
if (preFeedPower.pwrFilter == 1)
AlarmPwrFilter_On();
else if (preFeedPower.pwrFilter == 0)
AlarmPwrFilter_Off();
if (preFeedPower.pwrCirc == 1)
AlarmPwrCirc_On();
else if (preFeedPower.pwrCirc == 0)
AlarmPwrCirc_Off();
if (preFeedPower.pwrAux1 == 1)
AlarmPwrAux1_On();
else if (preFeedPower.pwrAux1 == 0)
AlarmPwrAux1_Off();
if (preFeedPower.pwrAux2 == 1)
AlarmPwrAux2_On();
else if (preFeedPower.pwrAux2 == 0)
AlarmPwrAux2_Off();
feedingActive = false; // stop feeding cycle
lastFeedingTime = now();
if (dispScreen == 1) // clear previous data
{
myGLCD.setColor(0, 0, 0);
myGLCD.fillRect(1, 111, 55, 171);
drawFeeding();
}
if (dispScreen == 2)
screenHome(); // Return to the home screen
}
void Opaq_iaqua::power_screen_e(unsigned x, unsigned y, touch_evt_type id) {
// power screen
if ((x >= 69) && (x <= 118) && (y >= 77) && (y <= 125)) // all on
{
// turn on all power outputs
AlarmPwrLight1_On();
AlarmPwrLight2_On();
AlarmPwrFilter_On();
AlarmPwrCirc_On();
AlarmPwrHeat_On();
AlarmPwrCO2_On();
AlarmPwrAux1_On();
AlarmPwrAux2_On();
screenPower(); // redraw screen
} else if ((x >= 125) && (x <= 174) && (y >= 77) && (y <= 125)) // all off
{
// turn off all power outputs
AlarmPwrLight1_Off();
AlarmPwrLight2_Off();
AlarmPwrFilter_Off();
AlarmPwrCirc_Off();
AlarmPwrHeat_Off();
AlarmPwrCO2_Off();
AlarmPwrAux1_Off();
AlarmPwrAux2_Off();
screenPower(); // redraw screen
}
else if ((x >= 107) && (x <= 129) && (y >= 294) && (y <= 318)) // home button
{
screenHome();
}
else if ((x >= 15) && (x <= 64) && (y >= 139) &&
(y <= 187)) // Front lights power
{
// toggle power
if (globalPower.pwrLight1 == 0)
AlarmPwrLight1_On();
else if (globalPower.pwrLight1 == 1)
AlarmPwrLight1_Off();
// draw icons
myFiles.load(15, 139, 48, 48, pwrLightIcon[globalPower.pwrLight1]);
myFiles.load(34, 192, 10, 11, pwrDot[globalPower.pwrLight1]);
} else if ((x >= 69) && (x <= 118) && (y >= 139) &&
(y <= 187)) // Back lights power
{
// toggle power
if (globalPower.pwrLight2 == 0)
AlarmPwrLight2_On();
else if (globalPower.pwrLight2 == 1)
AlarmPwrLight2_Off();
// draw icons
myFiles.load(69, 139, 48, 48, pwrLightIcon[globalPower.pwrLight2]);
myFiles.load(88, 192, 10, 11, pwrDot[globalPower.pwrLight2]);
} else if ((x >= 124) && (x <= 173) && (y >= 139) &&
(y <= 187)) // Filter power
{
// toggle power
if (globalPower.pwrFilter == 0)
AlarmPwrFilter_On();
else if (globalPower.pwrFilter == 1)
AlarmPwrFilter_Off();
// draw icons
myFiles.load(124, 139, 48, 48, pwrFilterIcon[globalPower.pwrFilter]);
myFiles.load(143, 192, 10, 11, pwrDot[globalPower.pwrFilter]);
} else if ((x >= 178) && (x <= 227) && (y >= 139) && (y <= 187)) // Circ power
{
// toggle power
if (globalPower.pwrCirc == 0)
AlarmPwrCirc_On();
else if (globalPower.pwrCirc == 1)
AlarmPwrCirc_Off();
// draw icons
myFiles.load(178, 139, 48, 48, pwrCircIcon[globalPower.pwrCirc]);
myFiles.load(197, 192, 10, 11, pwrDot[globalPower.pwrCirc]);
}
else if ((x >= 15) && (x <= 64) && (y >= 198) && (y <= 246)) // Heat power
{
// toggle power
if (globalPower.pwrHeat == 0)
AlarmPwrHeat_On();
else if (globalPower.pwrHeat == 1)
AlarmPwrHeat_Off();
// draw icons
myFiles.load(15, 212, 48, 48, pwrHeatIcon[globalPower.pwrHeat]);
myFiles.load(34, 264, 10, 11, pwrDot[globalPower.pwrHeat]);
} else if ((x >= 69) && (x <= 118) && (y >= 198) && (y <= 246)) // CO2 power
{
// toggle power
if (globalPower.pwrCO2 == 0)
AlarmPwrCO2_On();
else if (globalPower.pwrCO2 == 1)
AlarmPwrCO2_Off();
// draw icons
myFiles.load(69, 212, 48, 48, pwrCO2Icon[globalPower.pwrCO2]);
myFiles.load(88, 264, 10, 11, pwrDot[globalPower.pwrCO2]);
} else if ((x >= 124) && (x <= 173) && (y >= 198) &&
(y <= 246)) // aux 1 power
{
// toggle power
if (globalPower.pwrAux1 == 0)
AlarmPwrAux1_On();
else if (globalPower.pwrAux1 == 1)
AlarmPwrAux1_Off();
// draw icons
myFiles.load(124, 212, 48, 48, pwrAux1Icon[globalPower.pwrAux1]);
myFiles.load(143, 264, 10, 11, pwrDot[globalPower.pwrAux1]);
} else if ((x >= 178) && (x <= 227) && (y >= 198) &&
(y <= 246)) // aux 2 power
{
// toggle power
if (globalPower.pwrAux2 == 0)
AlarmPwrAux2_On();
else if (globalPower.pwrAux2 == 1)
AlarmPwrAux2_Off();
// draw icons
myFiles.load(178, 212, 48, 48, pwrAux2Icon[globalPower.pwrAux2]);
myFiles.load(197, 264, 10, 11, pwrDot[globalPower.pwrAux2]);
}
}
void Opaq_iaqua::settings_screen_e(unsigned x, unsigned y, touch_evt_type id) {
// settings screen
touchWaitTime = LONG_WAIT;
if ((x >= 107) && (x <= 129) && (y >= 294) && (y <= 318)) // home button
{
screenHome();
}
if ((x >= 10) && (x <= 58) && (y >= 50) && (y <= 113)) {
// only respond to the lights button if they are turned on or PWM
if ((globalPower.pwrLight1 == 1) || (lightCSP == false)) {
if (lightCSP == false)
screenLights();
if (lightCSP == true)
screenLightsIR();
}
} else if ((x >= 67) && (x <= 115) && (y >= 50) && (y <= 113)) {
screenClock();
} else if ((x >= 124) && (x <= 172) && (y >= 50) && (y <= 113)) {
screenFeedSettings();
} else if ((x >= 181) && (x <= 229) && (y >= 50) && (y <= 113)) {
screenSchedule();
} else if ((x >= 10) && (x <= 58) && (y >= 118) && (y <= 181)) {
screenSensors();
} else if ((x >= 67) && (x <= 115) && (y >= 118) && (y <= 181)) {
screenDosing(1);
} else if ((x >= 124) && (x <= 172) && (y >= 118) && (y <= 181)) {
screenScreen();
} else if ((x >= 181) && (x <= 229) && (y >= 118) && (y <= 181)) {
screenATO();
} else if ((x >= 10) && (x <= 58) && (y >= 186) && (y <= 249)) {
screenLunar();
} else if ((x >= 67) && (x <= 115) && (y >= 186) && (y <= 249)) {
if (lightCSP == false) {
selectedChan = 0;
screenColor(selectedChan);
}
} else if ((x >= 124) && (x <= 172) && (y >= 186) && (y <= 249)) {
screenGraphLEDs();
}
}
// ####################################################################################
// ####################################################################################
void Opaq_iaqua::screenHome() // draw main home screen showing overview info
{
dispScreen = 1; // set screen so we can know what screen was touched later
myGLCD.clrScr();
updateTimeDate(true);
// draw dock, home icon, and header
myFiles.load(0, 254, 240, 66, "dock.raw", 4);
myFiles.load(2, 2, 30, 30, "1home.raw", 4);
myGLCD.setFont(arial_bold);
myGLCD.setColor(34, 81, 255);
myGLCD.print(F("HOME"), 36, 12);
// draw lines to divide screen
myGLCD.setColor(130, 130, 130);
myGLCD.drawLine(40, 31, 239, 31); // under header
myGLCD.drawLine(0, 110, 239, 110); // across screen below temp
myGLCD.drawLine(56, 110, 56, 237); // 1st cutting into 4ths
myGLCD.drawLine(105, 110, 105, 237); // 2nd cutting into 4ths
myGLCD.drawLine(168, 110, 168, 237); // 3rd cutting into 4ths
myGLCD.drawLine(120, 31, 120, 110); // cutting top section in half for ATO
myGLCD.drawLine(0, 237, 239, 237); // across above dock
// draw temperature to screen
drawTemp();
// display feeding info
drawFeeding();
myFiles.load(5, 172, 46, 46, "1feed.raw", 4);
// display lighting info
checkLighting();
// get remainding doses
checkDosing();
// display ATO status
drawATO();
// draw power status of outputs
myFiles.load(178, 121, 24, 24, pwrLightIconS[globalPower.pwrLight1], 4);
myFiles.load(206, 121, 24, 24, pwrLightIconS[globalPower.pwrLight2], 4);
myFiles.load(178, 149, 24, 24, pwrFilterIconS[globalPower.pwrFilter], 4);
myFiles.load(206, 149, 24, 24, pwrCircIconS[globalPower.pwrCirc], 4);
myFiles.load(178, 177, 24, 24, pwrHeatIconS[globalPower.pwrHeat], 4);
myFiles.load(206, 177, 24, 24, pwrCO2IconS[globalPower.pwrCO2], 4);
myFiles.load(178, 205, 24, 24, pwrAux1IconS[globalPower.pwrAux1], 4);
myFiles.load(206, 205, 24, 24, pwrAux2IconS[globalPower.pwrAux2], 4);
}
void Opaq_iaqua::screenFeeding() // draw the feeding screen
{
dispScreen = 2;
// touchWaitTime = LONG_WAIT;
myGLCD.clrScr();
updateTimeDate(true);
// draw header and footer
myGLCD.setColor(130, 130, 130);
myGLCD.drawLine(40, 31, 239, 31); // under header
myGLCD.drawLine(0, 307, 239, 307); // at footer
myFiles.load(2, 2, 30, 30, "2feed.raw", 2);
myGLCD.setFont(arial_bold);
myGLCD.setColor(0, 184, 19);
myGLCD.print(F("FEEDING"), 36, 12);
myFiles.load(107, 294, 26, 26, "foothome.raw", 2);
myGLCD.setFont(arial_bold);
myGLCD.setColor(0, 184, 19);
myGLCD.print(F("TIME REMAINING"), CENTER, 60);
myGLCD.setColor(240, 240, 255);
// buttons to stop and restart feeding
myFiles.load(67, 223, 48, 48, "2stop.raw", 2);
myFiles.load(124, 223, 48, 48, "2restart.raw", 2);
// picture of fish eating
myFiles.load(74, 110, 92, 92, "2feeding.raw", 2);
// checkFeeding();
}
void Opaq_iaqua::screenPower() // draw the screen to turn power outputs on/off
{
dispScreen = 3;
// touchWaitTime = LONG_WAIT;
myGLCD.clrScr();
updateTimeDate(true);
// draw footer
myGLCD.setColor(130, 130, 130);
myGLCD.drawLine(40, 31, 239, 31); // under header
myGLCD.drawLine(0, 307, 104, 307); // left footer
myGLCD.drawLine(136, 307, 239, 307); // right footer
myFiles.load(107, 294, 26, 26, "foothome.raw", 2);
// draw header
myFiles.load(2, 2, 30, 30, "3power.raw", 2);
myGLCD.setFont(arial_bold);
myGLCD.setColor(222, 8, 51);
myGLCD.print(F("POWER"), 36, 12);
myGLCD.setColor(255, 255, 255);
myGLCD.print(F("MASTER"), CENTER, 52);
// all on and all off buttons
myFiles.load(73, 77, 40, 40, "3allon.raw", 2);
myFiles.load(128, 77, 40, 40, "3alloff.raw", 2);
// load all power icons and power dots
myFiles.load(15, 139, 48, 48, pwrLightIcon[globalPower.pwrLight1], 4);
myFiles.load(34, 192, 10, 11, pwrDot[globalPower.pwrLight1], 4);
myFiles.load(69, 139, 48, 48, pwrLightIcon[globalPower.pwrLight2], 4);
myFiles.load(88, 192, 10, 11, pwrDot[globalPower.pwrLight2], 4);
myFiles.load(124, 139, 48, 48, pwrFilterIcon[globalPower.pwrFilter], 4);
myFiles.load(143, 192, 10, 11, pwrDot[globalPower.pwrFilter], 4);
myFiles.load(178, 139, 48, 48, pwrCircIcon[globalPower.pwrCirc], 4);
myFiles.load(197, 192, 10, 11, pwrDot[globalPower.pwrCirc], 4);
myFiles.load(15, 212, 48, 48, pwrHeatIcon[globalPower.pwrHeat], 4);
myFiles.load(34, 264, 10, 11, pwrDot[globalPower.pwrHeat], 4);
myFiles.load(69, 212, 48, 48, pwrCO2Icon[globalPower.pwrCO2], 4);
myFiles.load(88, 264, 10, 11, pwrDot[globalPower.pwrCO2], 4);
myFiles.load(124, 212, 48, 48, pwrAux1Icon[globalPower.pwrAux1], 4);
myFiles.load(143, 264, 10, 11, pwrDot[globalPower.pwrAux1], 4);
myFiles.load(178, 212, 48, 48, pwrAux2Icon[globalPower.pwrAux2], 4);
myFiles.load(197, 264, 10, 11, pwrDot[globalPower.pwrAux2], 4);
}
void Opaq_iaqua::screenSettings() // draw the screen that has all of the extra
// settings apps
{
dispScreen = 4;
// touchWaitTime = LONG_WAIT;
myGLCD.clrScr();
updateTimeDate(true);
// draw header
myFiles.load(2, 2, 30, 30, "4extras.raw", 2);
myGLCD.setFont(arial_bold);
myGLCD.setColor(255, 77, 0);
myGLCD.print(F("SETTINGS "), 36, 12);
myGLCD.setColor(130, 130, 130);
myGLCD.drawLine(40, 31, 239, 31); // under header
myGLCD.drawLine(0, 307, 104, 307); // left footer
myGLCD.drawLine(136, 307, 239, 307); // right footer
myFiles.load(107, 294, 26, 26, "foothome.raw", 2); // footer home button
if ((globalPower.pwrLight1 == 1) || (lightCSP == false)) {
myFiles.load(10, 50, 48, 63, "4lights.raw", 2);
} else {
myFiles.load(10, 50, 48, 63, "4lightsF.raw", 2);
}
myFiles.load(67, 50, 48, 63, "4clock.raw", 2);
myFiles.load(124, 50, 48, 63, "4feeding.raw", 2);
myFiles.load(181, 50, 48, 63, "4sched.raw", 2);
myFiles.load(10, 118, 48, 63, "4sensors.raw", 2);
myFiles.load(67, 118, 48, 63, "4dosing.raw", 2);
myFiles.load(124, 118, 48, 63, "4screen.raw", 2);
myFiles.load(181, 118, 48, 63, "4ato.raw", 2);
myFiles.load(10, 186, 48, 63, "4lunar.raw", 2);
if (lightCSP == true)
myFiles.load(67, 186, 48, 63, "4colorF.raw",
2); // gray out icon for IR lights
if (lightCSP == false)
myFiles.load(67, 186, 48, 63, "4color.raw", 2);
myFiles.load(124, 186, 48, 63, "4graph.raw", 2);
}
void Opaq_iaqua::drawLEDBarGraph(byte barNum, int value) {
int x, y;
char char5[5];
Serial.print(F("Bar:"));
Serial.println(barNum);
Serial.print(F("Percent:"));
Serial.println(value);
// determine xy coordinates based on bar being displayed
if (barNum == 1) {
x = 10;
y = 185;
}
if (barNum == 2) {
x = 48;
y = 185;
}
if (barNum == 3) {
x = 86;
y = 185;
}
if (barNum == 4) {
x = 124;
y = 185;
}
if (barNum == 5) {
x = 162;
y = 185;
}
if (barNum == 6) {
x = 200;
y = 185;
}
// erase old bargraph & percentage
myGLCD.setColor(0, 0, 0);
myGLCD.fillRect(x - 3, y - 10, x + 28, y - 1);
myGLCD.fillRect(x + 1, y + 1, x + 27, y + 99);
// draw new bargraph
myGLCD.setColor(VGAColor[barColors[barNum - 1]]);
myGLCD.drawRect(x, y, x + 28, y + 100);
myGLCD.fillRect(x, (y + 100 - value), x + 28, (y + 100));
// write percentage
myGLCD.setFont(Sinclair_S);
myGLCD.setColor(VGA_WHITE);
itoa(value, char5, 10);
strcat(char5, "%");
if (value < 100)
x = x + 8;
if (value < 10)
x = x + 8;
myGLCD.print(char5, x - 3, y - 10);
}
void Opaq_iaqua::screenLights() // draw the screen for configuring the lights
{
dispScreen = 5;
// touchWaitTime = LONG_WAIT;
myGLCD.clrScr();
updateTimeDate(true);
// draw header
myFiles.load(2, 2, 30, 30, "5lights.raw", 2);
myGLCD.setFont(arial_bold);
myGLCD.setColor(185, 55, 255);
myGLCD.print(F("LIGHT MODES"), 36, 12);
myGLCD.setColor(130, 130, 130);
myGLCD.drawLine(40, 31, 239, 31); // under header
myGLCD.drawLine(0, 307, 104, 307); // left footer
myGLCD.drawLine(136, 307, 239, 307); // right footer
myGLCD.drawLine(0, 94, 239, 94); // vertical center line
myGLCD.drawLine(0, 168, 239, 168); // vertical center line
myFiles.load(107, 294, 26, 26, "footextr.raw", 2); // footer button
// draw buttons based on current mode (either selected or not selected)
if (currentLightMode == 0) // high sun
{
myFiles.load(10, 39, 48, 48, lightModeS[0], 2);
myFiles.load(10, 39, 48, 48, lightMode[0], 2);
myFiles.load(67, 39, 48, 48, lightMode[1], 2);
myFiles.load(124, 39, 48, 48, lightMode[2], 2);
myFiles.load(181, 39, 48, 48, lightMode[3], 2);
myFiles.load(10, 101, 48, 63, lightEdit[1], 2);
myFiles.load(181, 101, 48, 63, lightResync[1], 2);
// get RGBW for high sun
currentColor.chan1 = EEPROM.read(400);
currentColor.chan2 = EEPROM.read(401);
currentColor.chan3 = EEPROM.read(402);
currentColor.chan4 = EEPROM.read(403);
currentColor.chan5 = EEPROM.read(404);
currentColor.chan6 = EEPROM.read(405);
// draw bargraphs
drawLEDBarGraph(1, currentColor.chan1);
drawLEDBarGraph(2, currentColor.chan2);
drawLEDBarGraph(3, currentColor.chan3);
drawLEDBarGraph(4, currentColor.chan4);
drawLEDBarGraph(5, currentColor.chan5);
drawLEDBarGraph(6, currentColor.chan6);
if (lightCSP == false) {
if (PCA9685Installed == true) // if using PCA9685 scale values to 12-bit
{
currentColor.chan1 = map(currentColor.chan1, 0, 100, 0, 4095);
currentColor.chan2 = map(currentColor.chan2, 0, 100, 0, 4095);
currentColor.chan3 = map(currentColor.chan3, 0, 100, 0, 4095);
currentColor.chan4 = map(currentColor.chan4, 0, 100, 0, 4095);
currentColor.chan5 = map(currentColor.chan5, 0, 100, 0, 4095);
currentColor.chan6 = map(currentColor.chan6, 0, 100, 0, 4095);
} else // otherwise scale to 8-bit
{
currentColor.chan1 = map(currentColor.chan1, 0, 100, 0, 255);
currentColor.chan2 = map(currentColor.chan2, 0, 100, 0, 255);
currentColor.chan3 = map(currentColor.chan3, 0, 100, 0, 255);
currentColor.chan4 = map(currentColor.chan4, 0, 100, 0, 255);
currentColor.chan5 = map(currentColor.chan5, 0, 100, 0, 255);
currentColor.chan6 = map(currentColor.chan6, 0, 100, 0, 255);
}
}
} else if (currentLightMode == 1) // mid sun
{
myFiles.load(10, 39, 48, 48, lightMode[0], 2);
myFiles.load(67, 39, 48, 48, lightModeS[1], 2);
myFiles.load(124, 39, 48, 48, lightMode[2], 2);
myFiles.load(181, 39, 48, 48, lightMode[3], 2);
myFiles.load(10, 101, 48, 63, lightEdit[1], 2);
myFiles.load(181, 101, 48, 63, lightResync[1], 2);
// get RGBW for mid sun
currentColor.chan1 = EEPROM.read(410);
currentColor.chan2 = EEPROM.read(411);
currentColor.chan3 = EEPROM.read(412);
currentColor.chan4 = EEPROM.read(413);
currentColor.chan5 = EEPROM.read(414);
currentColor.chan6 = EEPROM.read(415);
// draw bargraphs
drawLEDBarGraph(1, currentColor.chan1);
drawLEDBarGraph(2, currentColor.chan2);
drawLEDBarGraph(3, currentColor.chan3);
drawLEDBarGraph(4, currentColor.chan4);
drawLEDBarGraph(5, currentColor.chan5);
drawLEDBarGraph(6, currentColor.chan6);
if (lightCSP == false) {
if (PCA9685Installed == true) // if using PCA9685 scale values to 12-bit
{
currentColor.chan1 = map(currentColor.chan1, 0, 100, 0, 4095);
currentColor.chan2 = map(currentColor.chan2, 0, 100, 0, 4095);
currentColor.chan3 = map(currentColor.chan3, 0, 100, 0, 4095);
currentColor.chan4 = map(currentColor.chan4, 0, 100, 0, 4095);
currentColor.chan5 = map(currentColor.chan5, 0, 100, 0, 4095);
currentColor.chan6 = map(currentColor.chan6, 0, 100, 0, 4095);
} else // otherwise scale to 8-bit
{
currentColor.chan1 = map(currentColor.chan1, 0, 100, 0, 255);
currentColor.chan2 = map(currentColor.chan2, 0, 100, 0, 255);
currentColor.chan3 = map(currentColor.chan3, 0, 100, 0, 255);
currentColor.chan4 = map(currentColor.chan4, 0, 100, 0, 255);
currentColor.chan5 = map(currentColor.chan5, 0, 100, 0, 255);
currentColor.chan6 = map(currentColor.chan6, 0, 100, 0, 255);
}
}
} else if (currentLightMode == 2) // low sun
{
myFiles.load(10, 39, 48, 48, lightMode[0], 2);
myFiles.load(67, 39, 48, 48, lightMode[1], 2);
myFiles.load(124, 39, 48, 48, lightModeS[2], 2);
myFiles.load(181, 39, 48, 48, lightMode[3], 2);
myFiles.load(10, 101, 48, 63, lightEdit[1], 2);
myFiles.load(181, 101, 48, 63, lightResync[1], 2);
// get RGBW for low sun
currentColor.chan1 = EEPROM.read(420);
currentColor.chan2 = EEPROM.read(421);
currentColor.chan3 = EEPROM.read(422);
currentColor.chan4 = EEPROM.read(423);
currentColor.chan5 = EEPROM.read(424);
currentColor.chan6 = EEPROM.read(425);
// draw bargraphs
drawLEDBarGraph(1, currentColor.chan1);
drawLEDBarGraph(2, currentColor.chan2);
drawLEDBarGraph(3, currentColor.chan3);
drawLEDBarGraph(4, currentColor.chan4);
drawLEDBarGraph(5, currentColor.chan5);
drawLEDBarGraph(6, currentColor.chan6);
if (lightCSP == false) {
if (PCA9685Installed == true) // if using PCA9685 scale values to 12-bit
{
currentColor.chan1 = map(currentColor.chan1, 0, 100, 0, 4095);
currentColor.chan2 = map(currentColor.chan2, 0, 100, 0, 4095);
currentColor.chan3 = map(currentColor.chan3, 0, 100, 0, 4095);
currentColor.chan4 = map(currentColor.chan4, 0, 100, 0, 4095);
currentColor.chan5 = map(currentColor.chan5, 0, 100, 0, 4095);
currentColor.chan6 = map(currentColor.chan6, 0, 100, 0, 4095);
} else // otherwise scale to 8-bit
{
currentColor.chan1 = map(currentColor.chan1, 0, 100, 0, 255);
currentColor.chan2 = map(currentColor.chan2, 0, 100, 0, 255);
currentColor.chan3 = map(currentColor.chan3, 0, 100, 0, 255);
currentColor.chan4 = map(currentColor.chan4, 0, 100, 0, 255);
currentColor.chan5 = map(currentColor.chan5, 0, 100, 0, 255);
currentColor.chan6 = map(currentColor.chan6, 0, 100, 0, 255);
}
}
} else if (currentLightMode == 3) // moon
{
myFiles.load(10, 39, 48, 48, lightMode[0], 2);
myFiles.load(67, 39, 48, 48, lightMode[1], 2);
myFiles.load(124, 39, 48, 48, lightMode[2], 2);
myFiles.load(181, 39, 48, 48, lightModeS[3], 2);
myFiles.load(10, 101, 48, 63, lightEdit[1], 2);
myFiles.load(181, 101, 48, 63, lightResync[1], 2);
// get RGBW for moon
currentColor.chan1 = EEPROM.read(430);
currentColor.chan2 = EEPROM.read(431);
currentColor.chan3 = EEPROM.read(432);
currentColor.chan4 = EEPROM.read(433);
currentColor.chan5 = EEPROM.read(434);
currentColor.chan6 = EEPROM.read(435);
// draw bargraphs
drawLEDBarGraph(1, currentColor.chan1);
drawLEDBarGraph(2, currentColor.chan2);
drawLEDBarGraph(3, currentColor.chan3);
drawLEDBarGraph(4, currentColor.chan4);
drawLEDBarGraph(5, currentColor.chan5);
drawLEDBarGraph(6, currentColor.chan6);
if (lightCSP == false) {
if (PCA9685Installed == true) // if using PCA9685 scale values to 12-bit
{
currentColor.chan1 = map(currentColor.chan1, 0, 100, 0, 4095);
currentColor.chan2 = map(currentColor.chan2, 0, 100, 0, 4095);
currentColor.chan3 = map(currentColor.chan3, 0, 100, 0, 4095);
currentColor.chan4 = map(currentColor.chan4, 0, 100, 0, 4095);
currentColor.chan5 = map(currentColor.chan5, 0, 100, 0, 4095);
currentColor.chan6 = map(currentColor.chan6, 0, 100, 0, 4095);
} else // otherwise scale to 8-bit
{
currentColor.chan1 = map(currentColor.chan1, 0, 100, 0, 255);
currentColor.chan2 = map(currentColor.chan2, 0, 100, 0, 255);
currentColor.chan3 = map(currentColor.chan3, 0, 100, 0, 255);
currentColor.chan4 = map(currentColor.chan4, 0, 100, 0, 255);
currentColor.chan5 = map(currentColor.chan5, 0, 100, 0, 255);
currentColor.chan6 = map(currentColor.chan6, 0, 100, 0, 255);
}
}
} else if ((currentLightMode == 4) ||
(currentLightMode == 5)) // lights in transition or unknown
{
myFiles.load(10, 39, 48, 48, lightMode[0], 2);
myFiles.load(67, 39, 48, 48, lightMode[1], 2);
myFiles.load(124, 39, 48, 48, lightMode[2], 2);
myFiles.load(181, 39, 48, 48, lightMode[3], 2);
myFiles.load(10, 101, 48, 63, lightEdit[0], 2);
myFiles.load(181, 101, 48, 63, lightResync[1], 2);
if (lightCSP == true) {
// draw bargraphs
drawLEDBarGraph(1, currentColor.chan1);
drawLEDBarGraph(2, currentColor.chan2);
drawLEDBarGraph(3, currentColor.chan3);
drawLEDBarGraph(4, currentColor.chan4);
drawLEDBarGraph(5, 0);
drawLEDBarGraph(6, 0);
} else {
byte temp1, temp2, temp3, temp4, temp5, temp6;
if (PCA9685Installed == true) // if using PCA9685 scale values to 12-bit
{
temp1 = map(currentColor.chan1, 0, 4095, 0, 100);
temp2 = map(currentColor.chan2, 0, 4095, 0, 100);
temp3 = map(currentColor.chan3, 0, 4095, 0, 100);
temp4 = map(currentColor.chan4, 0, 4095, 0, 100);
temp5 = map(currentColor.chan5, 0, 4095, 0, 100);
temp6 = map(currentColor.chan6, 0, 4095, 0, 100);
} else {
temp1 = map(currentColor.chan1, 0, 255, 0, 100);
temp2 = map(currentColor.chan2, 0, 255, 0, 100);
temp3 = map(currentColor.chan3, 0, 255, 0, 100);
temp4 = map(currentColor.chan4, 0, 255, 0, 100);
temp5 = map(currentColor.chan5, 0, 255, 0, 100);
temp6 = map(currentColor.chan6, 0, 255, 0, 100);
}
// draw bargraphs
drawLEDBarGraph(1, temp1);
drawLEDBarGraph(2, temp2);
drawLEDBarGraph(3, temp3);
drawLEDBarGraph(4, temp4);
drawLEDBarGraph(5, temp5);
drawLEDBarGraph(6, temp6);
}
}
// draw the rest of the buttons disabled until the edit button is pressed
myFiles.load(67, 101, 48, 63, lightSave[0], 2);
myFiles.load(124, 101, 48, 63, lightCancel[0], 2);
tempColor = currentColor;
myGLCD.setFont(Sinclair_S);
myGLCD.setColor(255, 255, 255);
}
void Opaq_iaqua::screenClock() // draw the screen for setting the date/time
{
dispScreen = 6;
myGLCD.clrScr();
updateTimeDate(true);
// draw header
myFiles.load(2, 2, 30, 30, "6clock.raw", 2);
myGLCD.setFont(arial_bold);
myGLCD.setColor(47, 168, 208);
myGLCD.print(F("CLOCK"), 36, 12);
myGLCD.print(F("TIME"), CENTER, 46);
myGLCD.print(F("DATE"), CENTER, 167);
myGLCD.setColor(130, 130, 130);
myGLCD.drawLine(40, 31, 239, 31); // under header
myGLCD.drawLine(0, 155, 239, 155); // center line
myGLCD.setFont(Sinclair_S);
myGLCD.setColor(255, 255, 255);
// draw clock buttons and text
myGLCD.print("24H", 12, 72);
myFiles.load(12, 89, 24, 24, arrowButton[0], 2);
myFiles.load(12, 119, 24, 24, arrowButton[1], 2);
myGLCD.print("M", 91, 72);
myFiles.load(83, 89, 24, 24, arrowButton[0], 2);
myFiles.load(83, 119, 24, 24, arrowButton[1], 2);
myGLCD.print("S", 172, 72);
myFiles.load(164, 89, 24, 24, arrowButton[0], 2);
myFiles.load(164, 119, 24, 24, arrowButton[1], 2);
// draw date buttons and text
myGLCD.print("M", 20, 194);
myFiles.load(12, 211, 24, 24, arrowButton[0], 2);
myFiles.load(12, 241, 24, 24, arrowButton[1], 2);
myGLCD.print("D", 91, 194);
myFiles.load(83, 211, 24, 24, arrowButton[0], 2);
myFiles.load(83, 241, 24, 24, arrowButton[1], 2);
myGLCD.print("Y", 172, 194);
myFiles.load(164, 211, 24, 24, arrowButton[0], 2);
myFiles.load(164, 241, 24, 24, arrowButton[1], 2);
myGLCD.setFont(arial_bold);
myGLCD.setColor(255, 77, 0);
saveRTC.Hour = hour();
saveRTC.Minute = minute();
saveRTC.Second = 0; // always have 0 seconds
saveRTC.Day = day();
saveRTC.Month = month();
saveRTC.Year = (year() - 1970);
char char3[3];
char char3t[3];
// draw the date and time to the screen
itoa(saveRTC.Hour, char3, 10);
if (saveRTC.Hour >= 0 && saveRTC.Hour <= 9) // add a zero
{
itoa(0, char3t, 10); // make char3t 0
strcat(char3t, char3);
strcpy(char3, char3t);
}
myGLCD.print(char3, 45, 108);
itoa(saveRTC.Minute, char3, 10);
if (saveRTC.Minute >= 0 && saveRTC.Minute <= 9) // add a zero
{
itoa(0, char3t, 10); // make char3t 0
strcat(char3t, char3);
strcpy(char3, char3t);
}
myGLCD.print(char3, 123, 108);
myGLCD.print("00", 201, 108);
itoa(saveRTC.Month, char3, 10);
if (saveRTC.Month >= 0 && saveRTC.Month <= 9) // add a zero
{
itoa(0, char3t, 10); // make char3t 0
strcat(char3t, char3);
strcpy(char3, char3t);
}
myGLCD.print(char3, 45, 230);
itoa(saveRTC.Day, char3, 10);
if (saveRTC.Day >= 0 && saveRTC.Day <= 9) // add a zero
{
itoa(0, char3t, 10); // make char3t 0
strcat(char3t, char3);
strcpy(char3, char3t);
}
myGLCD.print(char3, 123, 230);
// saveRTC.Year is offset from 1970 so we subtract 30 from number to get
// offset from 2000
itoa((saveRTC.Year - 30), char3, 10);
if (((saveRTC.Year - 30) >= 0) && ((saveRTC.Year - 30) <= 9)) // add a zero
{
itoa(0, char3t, 10); // make char3t 0