-
Notifications
You must be signed in to change notification settings - Fork 0
/
Panels.py
63 lines (53 loc) · 1.98 KB
/
Panels.py
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
import math
import logging
from Adafruit_PCA9685 import *
class Panel:
def __init__(self, panels, channel, minimum, maximum):
self.panels = panels
self.channel = channel
self.minimum = minimum
self.maximum = maximum
self.state = 0
self.target = 0
def SetState(self, state):
state = min(max(float(state), 0.0), 1.0)
self.state = state
try:
self.panels.pwm.set_pwm(self.channel, 0, int(self.minimum + state * (self.maximum - self.minimum)))
except IOError:
logging.warning("I2C communication error in Panel.SetState")
def Open(self):
self.SetTarget(1)
def Close(self):
self.SetTarget(0)
def IsOpen(self):
return self.state == 1
def IsClosed(self):
return self.state == 0
class Panels:
def __init__(self, address=64):
try:
self.pwm = PCA9685(address)
self.pwm.set_pwm_freq(50)
except IOError:
logging.warning("I2C communication error in Panels.__init__")
#self.panels = [Panel(self, i, 180, 620) for i in range(13)]
if address == 64: # head panels
self.panels = [Panel(self, i, 180, 620) for i in range(13)]
self.Top = self.panels[0]
self.Panel1 = self.panels[1]
self.Panel2 = self.panels[2]
self.Panel3 = self.panels[3]
self.Panel4 = self.panels[4]
self.Panel7 = self.panels[5]
self.Panel10 = self.panels[6]
self.Panel11 = self.panels[7]
self.Panel13 = self.panels[8]
self.LightsaberLauncherPanel = self.PiePanel1 = self.panels[9] # Lightsaber Launcher
self.LifeFormScannerPanel = self.PiePanel2 = self.panels[10] # Life Form Scanner
self.PiePanel5 = self.panels[11]
self.PiePanel6 = self.panels[12]
def __getitem__(self, i):
return self.panels[i]
def __len__(self):
return len(self.panels)