1+ class DHD :
2+ """
3+ This is the old DHD version. Not recommended. Use the new version instead.
4+ """
5+ def __init__ (self ):
6+ import adafruit_dotstar as dotstar
7+ import board
8+ self .dots = dotstar .DotStar (board .D14 , board .D15 , 39 , brightness = 0.01 )
9+ self .center_dot = dotstar .DotStar (board .D14 , board .D15 , 1 , brightness = 0.15 )
10+
11+ def light_on (self , symbol_number , color ):
12+ """
13+ This helper function activates the light for the dhd button of "symbol" with the "color" specified.
14+ :param symbol_number: The symbol number of which to control.
15+ :param color: The color for the led as a tuple. eg: (250, 117, 0)
16+ :return: nothing is returned.
17+ """
18+ symbol_number_to_dhd_light_map = {0 : 0 , 1 : 25 , 2 : 19 , 3 : 38 , 4 : 20 , 5 : 23 , 6 : 30 , 7 : 28 , 8 : 3 , 9 : 22 ,
19+ 10 : 11 , 11 : 36 , 12 : 34 , 14 : 17 , 15 : 6 , 16 : 9 , 17 : 18 , 18 : 16 , 19 : 26 ,
20+ 20 : 21 , 21 : 37 , 22 : 27 , 23 : 15 , 24 : 29 , 25 : 1 , 26 : 14 , 27 : 4 , 28 : 10 , 29 : 31 ,
21+ 30 : 8 , 31 : 5 , 32 : 24 , 33 : 12 , 34 : 33 , 35 : 7 , 36 : 2 , 37 : 35 , 38 : 32 , 39 : 13 }
22+ self .dots [symbol_number_to_dhd_light_map [symbol_number ]] = color
23+ def lights_off (self ):
24+ """
25+ This method turns off all dhd lights
26+ """
27+ self .dots .fill ((0 , 0 , 0 ))
28+ def center_light_on (self ):
29+ """
30+ A helper function to turn on the centre dhd light. It needs a bit more brightness than the other lights. Hence
31+ this extra method.
32+ """
33+ self .center_dot [0 ] = (255 , 0 , 0 )
34+
35+ import PyCmdMessenger
36+ from pprint import pprint
37+ class DHDv2 :
38+
39+ def __init__ (self , port , baud_rate ):
40+ # Initialize an ArduinoBoard instance.
41+ self .board = PyCmdMessenger .ArduinoBoard (port , baud_rate = baud_rate )
42+
43+ # List of command names (and formats for their associated arguments). These must
44+ # be in the same order as in the sketch.
45+ self .commands = [
46+ ["get_fw_version" , "s" ],
47+ ["get_hw_version" , "s" ],
48+ ["get_identifier" , "s" ],
49+ ["reset" , "" ],
50+ ["evt_error" , "s" ],
51+ ["evt_ack" , "" ],
52+
53+ ["message_bool" , "?" ],
54+ ["message_string" , "s" ],
55+ ["message_int" , "i" ],
56+ ["message_long" , "l" ],
57+ ["message_double" , "d" ],
58+ ["message_color" , "iii" ],
59+
60+ ["clear_all" , "" ], # Turns off all pixels in the RAM buffer.
61+ ["clear_pixel" , "i" ],
62+ # Turns off the pixel at the provided index, in the RAM buffer. [ pixelIndex ]. Index starts at 0.
63+ ["set_all" , "iii" ], # Sets all pixels to color provided, in the RAM buffer. [ red, green, blue ]
64+ ["set_pixel" , "iiii" ],
65+ # Sets pixel to color provided, in the RAM buffer.[ pixelIndex, red, green, blue ]. Index starts at 0.
66+
67+ ["get_pixel_count" , "i" ], # Returns the number of pixels managed by the library instance
68+
69+ ["set_brightness_symbols" , "i" ], # Set brightness for the symbol rings' LEDs.
70+ # ** Per library documentation: "Intended to be called once, in setup(),
71+ # to limit the current/brightness of the LEDs throughout the life of the
72+ # sketch. It is not intended as an animation effect itself! The operation
73+ # of this function is “lossy” — it modifies the current pixel data in RAM,
74+ # not in the show() call — in order to meet NeoPixels’ strict timing
75+ # requirements. Certain animation effects are better served by leaving the
76+ # brightness setting at the default maximum, modulating pixel brightness
77+ # in your own sketch logic and redrawing the full strip with setPixel()."
78+ ["set_brightness_center" , "i" ], # Set brightness for the center LED. Call this once: cautions as above.
79+
80+ ["latch" , "" ], # Transmits the current pixel configuration in the RAM buffer out to the pixels
81+ ]
82+
83+ # Initialize the messenger
84+ self .c = PyCmdMessenger .CmdMessenger (self .board , self .commands )
85+
86+ pass
87+
88+ def getFirmwareVersion (self ):
89+ self .c .send ("get_fw_version" )
90+ return self .c .receive ()[1 ][0 ]
91+
92+ def getHardwareVersion (self ):
93+ self .c .send ("get_hw_version" )
94+ return self .c .receive ()[1 ][0 ]
95+
96+ def getIdentifierString (self ):
97+ self .c .send ("get_identifier" )
98+ return self .c .receive ()[1 ][0 ]
99+
100+ def getPixelColorTuple (self , pixelIndex ):
101+ self .c .send ("get_pixel_color" , pixelIndex )
102+ pprint (self .c .receive ())
103+ return self .c .receive ()[1 ]
104+
105+ def getPixelCount (self ):
106+ self .c .send ("get_pixel_count" )
107+ return self .c .receive ()[1 ][0 ]
108+
109+ def setBrightnessSymbols (self , brightness ):
110+ self .c .send ("set_brightness_symbols" , brightness )
111+ return True
112+
113+ def setBrightnessCenter (self , brightness ):
114+ self .c .send ("set_brightness_center" , brightness )
115+ return True
116+
117+ def setAllPixelsToColor (self , red , green , blue ):
118+ self .c .send ("set_all" , red , green , blue )
119+ return True
120+
121+ def setPixel (self , pixelIndex , red , green , blue ):
122+ symbol_number_to_dhd_light_map = {0 : 0 , 1 : 34 , 2 : 2 , 3 : 21 , 4 : 20 , 5 : 36 , 6 : 29 , 7 : 31 , 8 : 18 , 9 : 37 ,
123+ 10 : 10 , 11 : 23 , 12 : 25 , 14 : 4 , 15 : 15 , 16 : 12 , 17 : 3 , 18 : 5 , 19 : 33 ,
124+ 20 : 38 , 21 : 22 , 22 : 32 , 23 : 6 , 24 : 30 , 25 : 1 , 26 : 7 , 27 : 17 , 28 : 11 , 29 : 28 ,
125+ 30 : 13 , 31 : 16 , 32 : 35 , 33 : 9 , 34 : 26 , 35 : 14 , 36 : 19 , 37 : 24 , 38 : 27 , 39 : 8 }
126+ self .c .send ("set_pixel" , symbol_number_to_dhd_light_map [pixelIndex ], red , green , blue )
127+ return True
128+
129+ def setPixel_use_LED_id (self , pixelIndex , red , green , blue ):
130+ self .c .send ("set_pixel" , pixelIndex , red , green , blue )
131+ return True
132+
133+ def clearAllPixels (self ):
134+ self .c .send ("clear_all" )
135+ return True
136+
137+ def clearPixel (self , pixelIndex ):
138+ self .c .send ("clear_pixel" , pixelIndex )
139+ return True
140+
141+ def latch (self ):
142+ self .c .send ("latch" )
143+ return True
144+
145+ class DhdKeyboardMode :
146+ """
147+ This is just a fallback class that disables all the DHD LED functions in case the DHD is not present. You can use a regular keyboard instead.
148+ To dial Aphopis's base, just hit cFX1K98A on your keyboard.
149+ """
150+
151+ def __init__ (self ):
152+ pass
153+
154+ def getFirmwareVersion (self ):
155+ pass
156+
157+ def getHardwareVersion (self ):
158+ pass
159+
160+ def getIdentifierString (self ):
161+ pass
162+
163+ def getPixelColorTuple (self , pixelIndex ):
164+ pass
165+
166+ def getPixelCount (self ):
167+ pass
168+
169+ def setBrightnessSymbols (self , brightness ):
170+ pass
171+
172+ def setBrightnessCenter (self , brightness ):
173+ pass
174+
175+ def setAllPixelsToColor (self , red , green , blue ):
176+ pass
177+
178+ def setPixel (self , pixelIndex , red , green , blue ):
179+ symbol_number_to_dhd_light_map = {0 : 0 , 1 : 34 , 2 : 2 , 3 : 21 , 4 : 20 , 5 : 36 , 6 : 29 , 7 : 31 , 8 : 18 , 9 : 37 ,
180+ 10 : 10 , 11 : 23 , 12 : 25 , 14 : 4 , 15 : 15 , 16 : 12 , 17 : 3 , 18 : 5 , 19 : 33 ,
181+ 20 : 38 , 21 : 22 , 22 : 32 , 23 : 6 , 24 : 30 , 25 : 1 , 26 : 7 , 27 : 17 , 28 : 11 , 29 : 28 ,
182+ 30 : 13 , 31 : 16 , 32 : 35 , 33 : 9 , 34 : 26 , 35 : 14 , 36 : 19 , 37 : 24 , 38 : 27 , 39 : 8 }
183+ pass
184+
185+ def setPixel_use_LED_id (self , pixelIndex , red , green , blue ):
186+ pass
187+
188+ def clearAllPixels (self ):
189+ pass
190+
191+ def clearPixel (self , pixelIndex ):
192+ pass
193+
194+ def latch (self ):
195+ pass
0 commit comments