forked from RonanValadez34/DPI_Computer_UI
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.py
More file actions
2094 lines (1829 loc) · 78.8 KB
/
main.py
File metadata and controls
2094 lines (1829 loc) · 78.8 KB
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
import os
# os.environ['DISPLAY'] = ":0.0"
# os.environ['KIVY_WINDOW'] = 'egl_rpi'
from kivy.app import App
from kivy.core.window import Window
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.clock import Clock
from pidev.MixPanel import MixPanel
from pidev.kivy.PassCodeScreen import PassCodeScreen
from pidev.kivy.PauseScreen import PauseScreen
from pidev.kivy import DPEAButton
from pidev.kivy import ImageButton
from pidev.kivy.selfupdatinglabel import SelfUpdatingLabel
from kivy.uix.slider import Slider
from dpeaDPi.DPiComputer import *
from dpeaDPi.DPiStepper import *
from time import sleep
from datetime import datetime
time = datetime
MIXPANEL_TOKEN = "x"
MIXPANEL = MixPanel("Project Name", MIXPANEL_TOKEN)
# screens
SCREEN_MANAGER = ScreenManager()
MAIN_SCREEN_NAME = 'main'
STEPPER_SCREEN_NAME = 'stepper'
SERVO_SCREEN_NAME = "servo"
DC_SCREEN_NAME = "DC"
STEPPER_STARTUP_SCREEN_NAME = 'StepperStartup'
BUTTON_SCREEN_NAME = "button"
INPUT_SCREEN_NAME = "input"
OUTPUT_SCREEN_NAME = "output"
NEOPIXEL_SCREEN_NAME = "Neopixel"
ENCODER_SCREEN_NAME = "Encoder"
POTENTIOMETER_SCREEN_NAME = "Potentiometer"
# associated variables for StepperScreen
dpiStepper = DPiStepper()
dpiStepper.setBoardNumber(0)
microStepping = ""
stepperSpeed = ""
stepperAcceleration = ""
stepper0Distance = ""
stepper1Distance = ""
stepper2Distance = ""
stepper_num = ""
distanceUnits = ""
direction = ""
# StepperMotorStartupScreen variables
homingType = ""
homingDirection = ""
homingSpeed = ""
stepperLinearHomeValue = ""
stepperAngularHomeValue = ""
homingUnits = ""
homeMaxDistance = ""
hasTransmission = False
gearRatio = ""
# associated variables for DC and Servo
dpiComputer = DPiComputer()
dpiComputer.initialize()
speedDC0 = ""
speedDC1 = ""
my_angle0 = ""
my_angle1 = ""
servo_number = ""
# associated variables for Button Class, uses dpiComputer
button_num = ""
redValue_pressed = ""
greenValue_pressed = ""
blueValue_pressed = ""
redValue_not_pressed = ""
blueValue_not_pressed = ""
greenValue_not_pressed = ""
# associated variables for Neopixel class, uses dpiComputer
neopixel0_redValue = ""
neopixel0_blueValue = ""
neopixel0_greenValue = ""
neopixel1_redValue = ""
neopixel1_blueValue = ""
neopixel1_greenValue = ""
numNeopixels0 = ""
neopixel_array0 = []
neopixel_array1 = []
numNeopixels1 = ""
index = ""
# variables for encoder, uses dpiComputer
encoder0_position = ""
encoder1_position = ""
# variables for potentiometer, uses dpiComputer
potentiometer0_value = ""
potentiometer1_value = ""
class ProjectNameGUI(App):
"""
Class to handle running the GUI Application
"""
def build(self):
"""
Build the application
:return: Kivy Screen Manager instance
"""
return SCREEN_MANAGER
Window.clearcolor = (1, 1, 1, 1) # White
class MainScreen(Screen):
"""
Class to handle the main screen and its associated touch events
"""
def pressed(self):
"""
Function called on button touch event for button with id: testButton
:return: None
"""
print("Callback from MainScreen.pressed()")
@staticmethod
def exit_program():
"""
Quit the program.
:return: None
"""
quit()
class PotentiometerScreen(Screen):
"""
Class to handle the PotentiometerScreen and its associated touch events
"""
potentiometer0_value = ""
potentiometer1_value = ""
def __init__(self, **kwargs):
Builder.load_file('PotentiometerScreen.kv')
super(PotentiometerScreen, self).__init__(**kwargs)
Clock.schedule_interval(self.readPotentiometer, .01)
@staticmethod
def transition_back():
"""
Transition back to the main screen
:return:
"""
SCREEN_MANAGER.current = MAIN_SCREEN_NAME
@staticmethod
def exit_program():
"""
Quit the program.
:return: None
"""
quit()
# reads the analog value from the potentiometer, and updates the associated label
def readPotentiometer(self, dt):
potentiometer0_value = str(dpiComputer.readAnalog(0))
self.ids.potentiometer0_label.text = "Potentiometer 0 Value: " + potentiometer0_value
potentiometer1_value = str(dpiComputer.readAnalog(1))
self.ids.potentiometer1_label.text = "Potentiometer 1 Value: " + potentiometer1_value
class EncoderScreen(Screen):
"""
Class to handle the EncoderScreen and its associated touch events
"""
encoder0_position = ""
encoder1_position = ""
def __init__(self, **kwargs):
Builder.load_file('EncoderScreen.kv')
super(EncoderScreen, self).__init__(**kwargs)
Clock.schedule_interval(self.readEncoder, .01)
@staticmethod
def transition_back():
"""
Transition back to the main screen
:return:
"""
SCREEN_MANAGER.current = MAIN_SCREEN_NAME
@staticmethod
def exit_program():
"""
Quit the program.
:return: None
"""
quit()
# reads the encoder position, and updates associated label
def readEncoder(self, dt):
encoder0_position = str(dpiComputer.readEncoder(0))
self.ids.encoder0_value.text = "Encoder 0 Position: " + encoder0_position
encoder1_position = str(dpiComputer.readEncoder(1))
self.ids.encoder1_value.text = "Encoder 1 Position: " + encoder1_position
class NeopixelScreen(Screen):
"""
Class to handle the Neopixel screen and its associated touch events
"""
neopixel0_redValue = ""
neopixel0_blueValue = ""
neopixel0_greenValue = ""
neopixel1_redValue = ""
neopixel1_blueValue = ""
neopixel1_greenValue = ""
numNeopixels0 = ""
numNeopixels1 = ""
neopixel_array = []
neopixel_array1 = []
index = ""
def __init__(self, **kwargs):
Builder.load_file('NeopixelScreen.kv')
super(NeopixelScreen, self).__init__(**kwargs)
def transition_back(self):
"""
Transition back to the main screen. Powers off all Neopixels. Reset buttons and labels
:return:
"""
global neopixel_array
global neopixel_array1
global numNeopixels0
global numNeopixels1
global neopixel0_redValue
global neopixel0_greenValue
global neopixel0_blueValue
global neopixel1_redValue
global neopixel1_greenValue
global neopixel1_blueValue
global index
index = ""
numNeopixels0 = "200"
numNeopixels1 = "200"
neopixel0_redValue = ""
neopixel0_blueValue = ""
neopixel0_greenValue = ""
neopixel1_redValue = ""
neopixel1_blueValue = ""
neopixel1_greenValue = ""
neopixel_array = [(0, 0, 0)] * int(numNeopixels0)
dpiComputer.writeNeopixelByArray(0, neopixel_array)
neopixel_array1 = [(0, 0, 0)] * int(numNeopixels1)
dpiComputer.writeNeopixelByArray(1, neopixel_array1)
# deselect neopixel strip labels
self.ids.neopixel0.text = "Neopixel 0"
self.ids.neopixel1.text = "Neopixel 1"
# deselect number of neopixel and index labels
self.ids.num_neopixels.text = "Number of Neopixels"
self.ids.index.text = "Index"
# deselect color labels
self.ids.set_red.text = "Set Red Value"
self.ids.set_green.text = "Set Green Value"
self.ids.set_blue.text = "Set Blue Value"
# reset labels
self.ids.red_value.text = "R1: "
self.ids.green_value.text = "G1: "
self.ids.blue_value.text = "B1: "
self.ids.number_neopixels_value.text = "Number of Neopixels:"
self.ids.index_value.text = "Index: "
SCREEN_MANAGER.current = MAIN_SCREEN_NAME
@staticmethod
def exit_program():
"""
Quit the program.
:return: None
"""
quit()
# selects Neopixel 0
def selectNeopixel0(self):
global index
global numNeopixels0
numNeopixels0 = ""
index = ""
self.ids.neopixel0.text = "Neopixel 0*"
self.ids.neopixel1.text = "Neopixel 1"
self.ids.red_value.text = "R1: "
self.ids.green_value.text = "G1: "
self.ids.blue_value.text = "B1: "
self.ids.number_neopixels_value.text = "Number of Neopixels:"
self.ids.index_value.text = "Index: " + index
# selects Neopixel 1
def selectNeopixel1(self):
global index
global numNeopixels1
numNeopixels1 = ""
index = ""
self.ids.neopixel1.text = "Neopixel 1*"
self.ids.neopixel0.text = "Neopixel 0"
self.ids.red_value.text = "R1: "
self.ids.green_value.text = "G1: "
self.ids.blue_value.text = "B1: "
self.ids.number_neopixels_value.text = "Number of Neopixels:"
self.ids.index_value.text = "Index: " + index
# select number of neopixels to input
def selectNumberOfNeopixels(self):
self.ids.num_neopixels.text = "Number of Neopixels*"
self.ids.index.text = "Index"
# selects index to input
def selectIndex(self):
self.ids.num_neopixels.text = "Number of Neopixels"
self.ids.index.text = "Index*"
# selects red value to input
def selectRed1(self):
self.ids.set_red.text = "Set Red Value*"
self.ids.set_green.text = "Set Green Value"
self.ids.set_blue.text = "Set Blue Value"
# selects green value to input
def selectGreen1(self):
self.ids.set_red.text = "Set Red Value"
self.ids.set_green.text = "Set Green Value*"
self.ids.set_blue.text = "Set Blue Value"
# selects blue value to input
def selectBlue1(self):
self.ids.set_red.text = "Set Red Value"
self.ids.set_green.text = "Set Green Value"
self.ids.set_blue.text = "Set Blue Value*"
# reads input from keyboard to set the colors
def setColor(self, input):
global neopixel0_redValue
global neopixel0_greenValue
global neopixel0_blueValue
global neopixel0_redValue2
global neopixel0_greenValue2
global neopixel0_blueValue2
global neopixel1_redValue
global neopixel1_blueValue
global neopixel1_greenValue
if self.ids.neopixel0.text == "Neopixel 0*":
if self.ids.set_red.text == "Set Red Value*":
neopixel0_redValue += str(input)
self.ids.red_value.text = "R1: " + neopixel0_redValue
if self.ids.set_green.text == "Set Green Value*":
neopixel0_greenValue += str(input)
self.ids.green_value.text = "G1: " + neopixel0_greenValue
if self.ids.set_blue.text == "Set Blue Value*":
neopixel0_blueValue += str(input)
self.ids.blue_value.text = "B1: " + neopixel0_blueValue
if self.ids.neopixel1.text == "Neopixel 1*":
if self.ids.set_red.text == "Set Red Value*":
neopixel1_redValue += str(input)
self.ids.red_value.text = "R1: " + neopixel1_redValue
if self.ids.set_green.text == "Set Green Value*":
neopixel1_greenValue += str(input)
self.ids.green_value.text = "G1: " + neopixel1_greenValue
if self.ids.set_blue.text == "Set Blue Value*":
neopixel1_blueValue += str(input)
self.ids.blue_value.text = "B1: " + neopixel1_blueValue
# reads input for number of neopixels and index keyboard
def readKeyboardInput(self, num):
global numNeopixels0
global numNeopixels1
global index
if self.ids.neopixel0.text == "Neopixel 0*":
if self.ids.num_neopixels.text == "Number of Neopixels*":
numNeopixels0 += str(num)
self.ids.number_neopixels_value.text = "Number of Neopixels: " + numNeopixels0
if self.ids.index.text == "Index*":
index += str(num)
self.ids.index_value.text = "Index: " + index
if self.ids.neopixel1.text == "Neopixel 1*":
if self.ids.num_neopixels.text == "Number of Neopixels*":
numNeopixels1 += str(num)
self.ids.number_neopixels_value.text = "Number of Neopixels: " + numNeopixels1
if self.ids.index.text == "Index*":
index += str(num)
self.ids.index_value.text = "Index: " + index
# removes input for number of neopixels and index keyboard
def removeKeyboardInput(self):
global numNeopixels0
global numNeopixels1
global index
if self.ids.neopixel0.text == "Neopixel 0*":
if self.ids.num_neopixels.text == "Number of Neopixels*":
numNeopixels0 = numNeopixels0[:-1]
self.ids.number_neopixels_value.text = "Number of Neopixels: " + numNeopixels0
if self.ids.index.text == "Index*":
index = index[:-1]
self.ids.index_value.text = "Index: " + index
if self.ids.neopixel1.text == "Neopixel 1*":
if self.ids.num_neopixels.text == "Number of Neopixels*":
numNeopixels1 = numNeopixels1[:-1]
self.ids.number_neopixels_value.text = "Number of Neopixels: " + numNeopixels1
if self.ids.index.text == "Index*":
index = index[:-1]
self.ids.index_value.text = "Index: " + index
# deletes color value
def removeColor(self):
global neopixel0_redValue
global neopixel0_greenValue
global neopixel0_blueValue
global neopixel1_redValue
global neopixel1_blueValue
global neopixel1_greenValue
if self.ids.neopixel0.text == "Neopixel 0*":
if self.ids.set_red.text == "Set Red Value*":
neopixel0_redValue = neopixel0_redValue[:-1]
self.ids.red_value.text = "R1: " + neopixel0_redValue
if self.ids.set_green.text == "Set Green Value*":
neopixel0_greenValue = neopixel0_greenValue[:-1]
self.ids.green_value.text = "G1: " + neopixel0_greenValue
if self.ids.set_blue.text == "Set Blue Value*":
neopixel0_blueValue = neopixel0_blueValue[:-1]
self.ids.blue_value.text = "B1: " + neopixel0_blueValue
if self.ids.neopixel1.text == "Neopixel 1*":
if self.ids.set_red.text == "Set Red Value*":
neopixel1_redValue = neopixel1_redValue[:-1]
self.ids.red_value.text = "R1: " + neopixel1_redValue
if self.ids.set_green.text == "Set Green Value*":
neopixel1_greenValue = neopixel1_greenValue[:-1]
self.ids.green_value.text = "G1: " + neopixel1_greenValue
if self.ids.set_blue.text == "Set Blue Value*":
neopixel1_blueValue = neopixel1_blueValue[:-1]
self.ids.blue_value.text = "B1: " + neopixel1_blueValue
# sets the neopixels color
def setIndividualNeopixel(self):
global neopixel0_redValue
global neopixel0_greenValue
global neopixel0_blueValue
global neopixel1_redValue
global neopixel1_blueValue
global neopixel1_greenValue
global neopixel_array
global neopixel_array1
global index
try:
if self.ids.neopixel0.text == "Neopixel 0*":
neopixel_array[int(index)] = (
int(neopixel0_redValue), int(neopixel0_greenValue), int(neopixel0_blueValue))
dpiComputer.writeNeopixelByArray(0, neopixel_array)
if self.ids.neopixel1.text == "Neopixel 1*":
neopixel_array1[int(index)] = (
int(neopixel1_redValue), int(neopixel1_greenValue), int(neopixel1_blueValue))
dpiComputer.writeNeopixelByArray(1, neopixel_array1)
self.ids.error_neopixel.text = ""
except ValueError:
self.ids.error_neopixel.text = "Invalid input, review instructions again"
# creates array of neopixels, and turns the neopixels off
def setNeopixelsoff(self):
global neopixel_array
global neopixel_array1
global numNeopixels0
global numNeopixels1
try:
self.ids.error_neopixel.text = ""
if self.ids.neopixel0.text == "Neopixel 0*":
neopixel_array = [(0, 0, 0)] * int(numNeopixels0)
dpiComputer.writeNeopixelByArray(0, neopixel_array)
if self.ids.neopixel1.text == "Neopixel 1*":
neopixel_array1 = [(0, 0, 0)] * int(numNeopixels1)
dpiComputer.writeNeopixelByArray(1, neopixel_array1)
except ValueError:
self.ids.error_neopixel.text = "Invalid input, review instructions again"
class OutputScreen(Screen):
"""
Class to handle the output screen and its associated touch events
"""
def __init__(self, **kwargs):
Builder.load_file('OutputScreen.kv')
super(OutputScreen, self).__init__(**kwargs)
def transition_back(self):
"""
Transition back to the main screen. set output to low for all OUTPUTS
:return:
"""
dpiComputer.writeDigitalOut(dpiComputer.OUT_CONNECTOR__OUT_0, False)
self.ids.OUT_0.text = "OUT 0: LOW"
dpiComputer.writeDigitalOut(dpiComputer.OUT_CONNECTOR__OUT_1, False)
self.ids.OUT_1.text = "OUT 1: LOW"
dpiComputer.writeDigitalOut(dpiComputer.OUT_CONNECTOR__OUT_2, False)
self.ids.OUT_2.text = "OUT 2: LOW"
dpiComputer.writeDigitalOut(dpiComputer.OUT_CONNECTOR__OUT_3, False)
self.ids.OUT_3.text = "OUT 3: LOW"
SCREEN_MANAGER.current = MAIN_SCREEN_NAME
@staticmethod
def exit_program():
"""
Quit the program. This should set all outputs to low
:return: None
"""
dpiComputer.writeDigitalOut(dpiComputer.OUT_CONNECTOR__OUT_0, False)
dpiComputer.writeDigitalOut(dpiComputer.OUT_CONNECTOR__OUT_1, False)
dpiComputer.writeDigitalOut(dpiComputer.OUT_CONNECTOR__OUT_2, False)
dpiComputer.writeDigitalOut(dpiComputer.OUT_CONNECTOR__OUT_3, False)
quit()
# toggles OUT 0 between HIGH and LOW
def WriteValue0(self):
if self.ids.OUT_0.text == "OUT 0: LOW":
dpiComputer.writeDigitalOut(dpiComputer.OUT_CONNECTOR__OUT_0, True)
self.ids.OUT_0.text = "OUT 0: HIGH"
else:
dpiComputer.writeDigitalOut(dpiComputer.OUT_CONNECTOR__OUT_0, False)
self.ids.OUT_0.text = "OUT 0: LOW"
# toggles OUT 1 between HIGH and LOW
def WriteValue1(self):
if self.ids.OUT_1.text == "OUT 1: LOW":
dpiComputer.writeDigitalOut(dpiComputer.OUT_CONNECTOR__OUT_1, True)
self.ids.OUT_1.text = "OUT 1: HIGH"
else:
dpiComputer.writeDigitalOut(dpiComputer.OUT_CONNECTOR__OUT_1, False)
self.ids.OUT_1.text = "OUT 1: LOW"
# toggles OUT 2 between HIGH and LOW
def WriteValue2(self):
if self.ids.OUT_2.text == "OUT 2: LOW":
dpiComputer.writeDigitalOut(dpiComputer.OUT_CONNECTOR__OUT_2, True)
self.ids.OUT_2.text = "OUT 2: HIGH"
else:
dpiComputer.writeDigitalOut(dpiComputer.OUT_CONNECTOR__OUT_2, False)
self.ids.OUT_2.text = "OUT 2: LOW"
# toggles OUT 3 between HIGH and LOW
def WriteValue3(self):
if self.ids.OUT_3.text == "OUT 3: LOW":
dpiComputer.writeDigitalOut(dpiComputer.OUT_CONNECTOR__OUT_3, True)
self.ids.OUT_3.text = "OUT 3: HIGH"
else:
dpiComputer.writeDigitalOut(dpiComputer.OUT_CONNECTOR__OUT_3, False)
self.ids.OUT_3.text = "OUT 3: LOW"
class InputScreen(Screen):
"""
Class to handle the Input screen and its associated touch events
"""
def __init__(self, **kwargs):
Builder.load_file('InputScreen.kv')
super(InputScreen, self).__init__(**kwargs)
Clock.schedule_interval(self.readInput, .1)
def transition_back(self):
"""
Transition back to the main screen
:return:
"""
self.ids.IN_0.text = "IN 0"
self.ids.IN_1.text = "IN 1"
self.ids.IN_2.text = "IN 2"
self.ids.IN_3.text = "IN 3"
SCREEN_MANAGER.current = MAIN_SCREEN_NAME
@staticmethod
def exit_program():
"""
Quit the program. This should reset all buttons
:return: None
"""
quit()
# selects IN0 to read
def selectIN0(self):
self.ids.IN_0.text = "IN 0*"
self.ids.IN_1.text = "IN 1"
self.ids.IN_2.text = "IN 2"
self.ids.IN_3.text = "IN 3"
# selects IN1 to read
def selectIN1(self):
self.ids.IN_0.text = "IN 0"
self.ids.IN_1.text = "IN 1*"
self.ids.IN_2.text = "IN 2"
self.ids.IN_3.text = "IN 3"
# selects IN2 to read
def selectIN2(self):
self.ids.IN_0.text = "IN 0"
self.ids.IN_1.text = "IN 1"
self.ids.IN_2.text = "IN 2*"
self.ids.IN_3.text = "IN 3"
# selects IN3 to read
def selectIN3(self):
self.ids.IN_0.text = "IN 0"
self.ids.IN_1.text = "IN 1"
self.ids.IN_2.text = "IN 2"
self.ids.IN_3.text = "IN 3*"
# reads input of selected IN
def readInput(self, dt):
if self.ids.IN_0.text == "IN 0*":
if dpiComputer.readDigitalIn(dpiComputer.IN_CONNECTOR__IN_0):
sleep(.1)
if dpiComputer.readDigitalIn(dpiComputer.IN_CONNECTOR__IN_0): # a little debounce logic
self.ids.sensor_value.text = "HIGH"
else:
self.ids.sensor_value.text = "LOW"
sleep(.1)
if self.ids.IN_1.text == "IN 1*":
if dpiComputer.readDigitalIn(dpiComputer.IN_CONNECTOR__IN_1):
sleep(.1)
if dpiComputer.readDigitalIn(dpiComputer.IN_CONNECTOR__IN_1): # a little debounce logic
self.ids.sensor_value.text = "HIGH"
else:
self.ids.sensor_value.text = "LOW"
sleep(.1)
if self.ids.IN_2.text == "IN 2*":
if dpiComputer.readDigitalIn(dpiComputer.IN_CONNECTOR__IN_2):
sleep(.1)
if dpiComputer.readDigitalIn(dpiComputer.IN_CONNECTOR__IN_2): # a little debounce logic
self.ids.sensor_value.text = "HIGH"
else:
self.ids.sensor_value.text = "LOW"
sleep(.1)
if self.ids.IN_3.text == "IN 3*":
if dpiComputer.readDigitalIn(dpiComputer.IN_CONNECTOR__IN_3):
sleep(.1)
if dpiComputer.readDigitalIn(dpiComputer.IN_CONNECTOR__IN_3): # a little debounce logic
self.ids.sensor_value.text = "HIGH"
else:
self.ids.sensor_value.text = "LOW"
sleep(.1)
class ButtonScreen(Screen):
"""
Class to handle the button screen and its associated touch events
"""
button_num = ""
redValue_pressed = ""
blueValue_pressed = ""
greenValue_pressed = ""
redValue_not_pressed = ""
blueValue_not_pressed = ""
greenValue_not_pressed = ""
def __init__(self, **kwargs):
Builder.load_file('ButtonScreen.kv')
super(ButtonScreen, self).__init__(**kwargs)
Clock.schedule_interval(self.getButtonStatus, .001)
# transition back should unselect all buttons, reset labels, and disable clock
def transition_back(self):
"""
Transition back to the main screen
:return:
"""
global redValue_pressed
global greenValue_pressed
global blueValue_pressed
global redValue_not_pressed
global greenValue_not_pressed
global blueValue_not_pressed
redValue_pressed = ""
greenValue_pressed = ""
blueValue_pressed = ""
redValue_not_pressed = ""
greenValue_not_pressed = ""
blueValue_not_pressed = ""
Clock.unschedule(self.getButtonStatus)
dpiComputer.writeRGBButtonColor(0, 0, 0, 0)
dpiComputer.writeRGBButtonColor(1, 0, 0, 0)
self.ids.button_1.text = "Button 1"
self.ids.button_0.text = "Button 0"
self.ids.set_red_not_pressed.text = "Set Red Value\nNot Pressed"
self.ids.set_green_not_pressed.text = "Set Green Value\nNot Pressed"
self.ids.set_blue_not_pressed.text = "Set Blue Value\nNot Pressed"
self.ids.set_red_pressed.text = "Set Red Value Pressed"
self.ids.set_green_pressed.text = "Set Green Value Pressed"
self.ids.set_blue_pressed.text = "Set Blue Value Pressed"
# reset color labels:
self.ids.red_value_not_pressed.text = "Red Value Not Pressed:"
self.ids.green_value_not_pressed.text = "Green Value Not Pressed:"
self.ids.blue_value_not_pressed.text = "Blue Value Not Pressed:"
self.ids.red_value_pressed.text = "Red Value Pressed:"
self.ids.green_value_pressed.text = "Green Value Pressed:"
self.ids.blue_value_pressed.text = "Blue Value Pressed:"
SCREEN_MANAGER.current = MAIN_SCREEN_NAME
def exit_program(self):
"""
Quit the program. This should turn off RGB buttons, reset kivy buttons and labels
:return: None
"""
Clock.unschedule(self.getButtonStatus)
dpiComputer.writeRGBButtonColor(0, 0, 0, 0)
dpiComputer.writeRGBButtonColor(1, 0, 0, 0)
self.ids.button_1.text = "Button 1"
self.ids.button_0.text = "Button 0"
self.ids.set_red_not_pressed.text = "Set Red Value\nNot Pressed"
self.ids.set_green_not_pressed.text = "Set Green Value\nNot Pressed"
self.ids.set_blue_not_pressed.text = "Set Blue Value\nNot Pressed"
self.ids.set_red_pressed.text = "Set Red Value Pressed"
self.ids.set_green_pressed.text = "Set Green Value Pressed"
self.ids.set_blue_pressed.text = "Set Blue Value Pressed"
quit()
# checks the button status, pressed or not pressed
def getButtonStatus(self, dt):
global redValue_pressed
global greenValue_pressed
global blueValue_pressed
global redValue_not_pressed
global greenValue_not_pressed
global blueValue_not_pressed
if self.ids.button_0.text == "Button 0*":
button_value = dpiComputer.readRGBButtonSwitch(0) # read the button
if button_value:
if redValue_pressed == "" or greenValue_pressed == "" or blueValue_pressed == "":
red = 255
green = 0
blue = 0
else:
red = int(redValue_pressed)
green = int(greenValue_pressed)
blue = int(blueValue_pressed)
self.ids.button_immediate_value.text = "Button pressed"
dpiComputer.writeRGBButtonColor(0, red, green, blue)
else:
if redValue_not_pressed == "" or greenValue_not_pressed == "" or blueValue_not_pressed == "":
red = 64
green = 240
blue = 255
else:
red = int(redValue_not_pressed)
green = int(greenValue_not_pressed)
blue = int(blueValue_not_pressed)
self.ids.button_immediate_value.text = "Button not pressed"
dpiComputer.writeRGBButtonColor(0, red, green, blue)
if self.ids.button_1.text == "Button 1*":
button_value = dpiComputer.readRGBButtonSwitch(1) # read the button
if button_value == True:
if redValue_pressed == "" or greenValue_pressed == "" or blueValue_pressed == "":
red = 255
green = 0
blue = 0
else:
red = int(redValue_pressed)
green = int(greenValue_pressed)
blue = int(blueValue_pressed)
self.ids.button_immediate_value.text = "Button pressed"
dpiComputer.writeRGBButtonColor(1, red, green, blue) # set button to RED if pushed
else:
if (redValue_not_pressed == "") or (greenValue_not_pressed == "") or (blueValue_not_pressed == ""):
red = 64
green = 240
blue = 255
else:
red = int(redValue_not_pressed)
green = int(greenValue_not_pressed)
blue = int(blueValue_not_pressed)
self.ids.button_immediate_value.text = "Button not pressed"
dpiComputer.writeRGBButtonColor(1, red, green, blue)
# selects button 0 to use
def selectButton0(self):
global redValue_pressed
global greenValue_pressed
global blueValue_pressed
global redValue_not_pressed
global greenValue_not_pressed
global blueValue_not_pressed
redValue_pressed = ""
greenValue_pressed = ""
blueValue_pressed = ""
redValue_not_pressed = ""
greenValue_not_pressed = ""
blueValue_not_pressed = ""
self.ids.button_0.text = "Button 0*"
self.ids.button_1.text = "Button 1"
Clock.schedule_interval(self.getButtonStatus, .01)
# selects button 1 to use
def selectButton1(self):
global redValue_pressed
global greenValue_pressed
global blueValue_pressed
global redValue_not_pressed
global greenValue_not_pressed
global blueValue_not_pressed
redValue_pressed = ""
greenValue_pressed = ""
blueValue_pressed = ""
redValue_not_pressed = ""
greenValue_not_pressed = ""
blueValue_not_pressed = ""
self.ids.button_0.text = "Button 0"
self.ids.button_1.text = "Button 1*"
Clock.schedule_interval(self.getButtonStatus, .01)
# selects red not pressed value to input
def selectRedNotPressed(self):
self.ids.set_red_not_pressed.text = "Set Red Value\nNot Pressed*"
self.ids.set_green_not_pressed.text = "Set Green Value\nNot Pressed"
self.ids.set_blue_not_pressed.text = "Set Blue Value\nNot Pressed"
self.ids.set_red_pressed.text = "Set Red Value Pressed"
self.ids.set_green_pressed.text = "Set Green Value Pressed"
self.ids.set_blue_pressed.text = "Set Blue Value Pressed"
# selects green not pressed value to input
def selectGreenNotPressed(self):
self.ids.set_red_not_pressed.text = "Set Red Value\nNot Pressed"
self.ids.set_green_not_pressed.text = "Set Green Value\nNot Pressed*"
self.ids.set_blue_not_pressed.text = "Set Blue Value\nNot Pressed"
self.ids.set_red_pressed.text = "Set Red Value Pressed"
self.ids.set_green_pressed.text = "Set Green Value Pressed"
self.ids.set_blue_pressed.text = "Set Blue Value Pressed"
# selects blue not pressed value to input
def selectBlueNotPressed(self):
self.ids.set_red_not_pressed.text = "Set Red Value\nNot Pressed"
self.ids.set_green_not_pressed.text = "Set Green Value\nNot Pressed"
self.ids.set_blue_not_pressed.text = "Set Blue Value\nNot Pressed*"
self.ids.set_red_pressed.text = "Set Red Value Pressed"
self.ids.set_green_pressed.text = "Set Green Value Pressed"
self.ids.set_blue_pressed.text = "Set Blue Value Pressed"
# selects red pressed value to input
def selectRedPressed(self):
self.ids.set_red_pressed.text = "Set Red Value Pressed*"
self.ids.set_green_pressed.text = "Set Green Value Pressed"
self.ids.set_blue_pressed.text = "Set Blue Value Pressed"
self.ids.set_red_not_pressed.text = "Set Red Value\nNot Pressed"
self.ids.set_green_not_pressed.text = "Set Green Value\nNot Pressed"
self.ids.set_blue_not_pressed.text = "Set Blue Value\nNot Pressed"
# selects green pressed value to input
def selectGreenPressed(self):
self.ids.set_red_pressed.text = "Set Red Value Pressed"
self.ids.set_green_pressed.text = "Set Green Value Pressed*"
self.ids.set_blue_pressed.text = "Set Blue Value Pressed"
self.ids.set_red_not_pressed.text = "Set Red Value\nNot Pressed"
self.ids.set_green_not_pressed.text = "Set Green Value\nNot Pressed"
self.ids.set_blue_not_pressed.text = "Set Blue Value\nNot Pressed"
# selects blue pressed value to input
def selectBluePressed(self):
self.ids.set_red_pressed.text = "Set Red Value Pressed"
self.ids.set_green_pressed.text = "Set Green Value Pressed"
self.ids.set_blue_pressed.text = "Set Blue Value Pressed*"
self.ids.set_red_not_pressed.text = "Set Red Value\nNot Pressed"
self.ids.set_green_not_pressed.text = "Set Green Value\nNot Pressed"
self.ids.set_blue_not_pressed.text = "Set Blue Value\nNot Pressed"
# reads input from keyboard to set the colors
def setColor(self, input):
global redValue_pressed
global greenValue_pressed
global blueValue_pressed
global redValue_not_pressed
global greenValue_not_pressed
global blueValue_not_pressed
if self.ids.set_red_not_pressed.text == "Set Red Value\nNot Pressed*":
redValue_not_pressed += str(input)
self.ids.red_value_not_pressed.text = "Red Value Not Pressed:" + redValue_not_pressed
if self.ids.set_green_not_pressed.text == "Set Green Value\nNot Pressed*":
greenValue_not_pressed += str(input)
self.ids.green_value_not_pressed.text = "Green Value Not Pressed:" + greenValue_not_pressed
if self.ids.set_blue_not_pressed.text == "Set Blue Value\nNot Pressed*":
blueValue_not_pressed += str(input)
self.ids.blue_value_not_pressed.text = "Blue Value Not Pressed: " + blueValue_not_pressed
if self.ids.set_red_pressed.text == "Set Red Value Pressed*":
redValue_pressed += str(input)
self.ids.red_value_pressed.text = "Red Value Pressed:" + redValue_pressed
if self.ids.set_green_pressed.text == "Set Green Value Pressed*":
greenValue_pressed += str(input)
self.ids.green_value_pressed.text = "Green Value Pressed:" + greenValue_pressed
if self.ids.set_blue_pressed.text == "Set Blue Value Pressed*":
blueValue_pressed += str(input)
self.ids.blue_value_pressed.text = "Blue Value Pressed: " + blueValue_pressed
# deletes color value
def removeColor(self):
global redValue_pressed
global greenValue_pressed
global blueValue_pressed
global redValue_not_pressed
global greenValue_not_pressed
global blueValue_not_pressed
if self.ids.set_red_not_pressed.text == "Set Red Value\nNot Pressed*":
redValue_not_pressed = redValue_not_pressed[:-1]
self.ids.red_value_not_pressed.text = "Red Value Not Pressed:" + redValue_not_pressed
if self.ids.set_green_not_pressed.text == "Set Green Value\nNot Pressed*":
greenValue_not_pressed = greenValue_not_pressed[:-1]
self.ids.green_value_not_pressed.text = "Green Value Not Pressed:" + greenValue_not_pressed
if self.ids.set_blue_not_pressed.text == "Set Blue Value\nNot Pressed*":
blueValue_not_pressed = blueValue_not_pressed[:-1]
self.ids.blue_value_not_pressed.text = "Blue Value Not Pressed: " + blueValue_not_pressed
if self.ids.set_red_pressed.text == "Set Red Value Pressed*":
redValue_pressed = redValue_pressed[:-1]
self.ids.red_value_pressed.text = "Red Value Pressed:" + redValue_pressed
if self.ids.set_green_pressed.text == "Set Green Value Pressed*":
greenValue_pressed = greenValue_pressed[:-1]
self.ids.green_value_pressed.text = "Green Value Pressed:" + greenValue_pressed
if self.ids.set_blue_pressed.text == "Set Blue Value Pressed*":
blueValue_pressed = blueValue_pressed[:-1]
self.ids.blue_value_pressed.text = "Blue Value Pressed: " + blueValue_pressed
# check to see if button is pressed, red is pressed, green is not pressed
def testPressed(self):
global redValue_pressed
global greenValue_pressed
global blueValue_pressed
global redValue_not_pressed
global greenValue_not_pressed
global blueValue_not_pressed
if self.ids.button_0.text == "Button 0*":
button_value = dpiComputer.readRGBButtonSwitch(0) # read the button
if button_value == True:
if redValue_pressed == "" or greenValue_pressed == "" or blueValue_pressed == "":
red = 255