added get/set controller functions
This commit is contained in:
@@ -1,3 +1,25 @@
|
|||||||
|
import smbus
|
||||||
|
|
||||||
|
PCA9685_SUBADR1 = 0x2
|
||||||
|
PCA9685_SUBADR2 = 0x3
|
||||||
|
PCA9685_SUBADR3 = 0x4
|
||||||
|
|
||||||
|
PCA9685_MODE1 = 0x00
|
||||||
|
PCA9685_MODE2 = 0x01
|
||||||
|
PCA9685_PRESCALE = 0xFE
|
||||||
|
PCA9685_RESET = 0xFE
|
||||||
|
|
||||||
|
LED0_ON_L = 0x06
|
||||||
|
LED0_ON_H = 0x07
|
||||||
|
LED0_OFF_L = 0x08
|
||||||
|
LED0_OFF_H = 0x09
|
||||||
|
|
||||||
|
ALLLED_ON_L = 0xFA
|
||||||
|
ALLLED_ON_H = 0xFB
|
||||||
|
ALLLED_OFF_L = 0xFC
|
||||||
|
ALLLED_OFF_H = 0xFD
|
||||||
|
|
||||||
|
|
||||||
class Controller:
|
class Controller:
|
||||||
"""
|
"""
|
||||||
A controller controls a number of stripes.
|
A controller controls a number of stripes.
|
||||||
@@ -22,6 +44,7 @@ class Controller:
|
|||||||
self.pwm_freq = pwm_freq
|
self.pwm_freq = pwm_freq
|
||||||
self.channels = channels
|
self.channels = channels
|
||||||
self.i2c_device = i2c_device
|
self.i2c_device = i2c_device
|
||||||
|
self.bus = smbus.SMBus(i2c_device)
|
||||||
self.address = address
|
self.address = address
|
||||||
self.id = cid
|
self.id = cid
|
||||||
self.db = db
|
self.db = db
|
||||||
@@ -36,6 +59,13 @@ class Controller:
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<Controller stripes={} cid={}>".format(len(self.stripes), self.id)
|
return "<Controller stripes={} cid={}>".format(len(self.stripes), self.id)
|
||||||
|
|
||||||
|
def set_channel(self, channel, val):
|
||||||
|
self.bus.write_word_data(self.address, LED0_OFF_L + 4 * channel, val*4095)
|
||||||
|
self.bus.write_word_data(self.address, LED0_ON_L + 4 * channel, 0)
|
||||||
|
|
||||||
|
def get_channel(self, channel):
|
||||||
|
return self.bus.read_word_data(self.address, LED0_OFF_L + 4 * channel)
|
||||||
|
|
||||||
|
|
||||||
class Stripe:
|
class Stripe:
|
||||||
"""
|
"""
|
||||||
|
@@ -90,9 +90,10 @@ class Daemon:
|
|||||||
def handle_read(self):
|
def handle_read(self):
|
||||||
data = self.recv(5120)
|
data = self.recv(5120)
|
||||||
if data:
|
if data:
|
||||||
|
print(data)
|
||||||
try:
|
try:
|
||||||
json.dumps(data, sort_keys=True, indent=4, separators=(',', ': '))
|
json_decoded = json.loads(data.decode())
|
||||||
json_decoded = json.loads(data)
|
print(json.dumps(json_decoded, sort_keys=True, indent=4, separators=(',', ': ')))
|
||||||
|
|
||||||
if "action" in json_decoded:
|
if "action" in json_decoded:
|
||||||
if json_decoded['action'] == "set_color":
|
if json_decoded['action'] == "set_color":
|
||||||
@@ -104,10 +105,11 @@ class Daemon:
|
|||||||
elif json_decoded['action'] == "get_color":
|
elif json_decoded['action'] == "get_color":
|
||||||
# TODO: add stripe color get logic
|
# TODO: add stripe color get logic
|
||||||
print("recieved action: {}".format(json_decoded['action']))
|
print("recieved action: {}".format(json_decoded['action']))
|
||||||
except TypeError:
|
else:
|
||||||
print("No JSON found!")
|
print("no action found, ignoring")
|
||||||
else:
|
except (TypeError, ValueError):
|
||||||
print("no action found, ignoring")
|
print("No valid JSON found!")
|
||||||
|
|
||||||
|
|
||||||
class SocketServer(asyncore.dispatcher):
|
class SocketServer(asyncore.dispatcher):
|
||||||
def __init__(self, host, port):
|
def __init__(self, host, port):
|
||||||
|
Reference in New Issue
Block a user