fixed loads of bugs

This commit is contained in:
Giovanni Harting
2015-07-14 21:23:05 +02:00
parent cf95c346a0
commit 7e2706b81c
3 changed files with 18 additions and 11 deletions

View File

@@ -48,6 +48,8 @@ class Controller:
self.id = cur.lastrowid self.id = cur.lastrowid
cur.execute("UPDATE controller SET pwm_freq=?, channels=?, i2c_device=?, address=? WHERE id = ?", cur.execute("UPDATE controller SET pwm_freq=?, channels=?, i2c_device=?, address=? WHERE id = ?",
(self.pwm_freq, self.channels, self.i2c_device, self.address, self.id)) (self.pwm_freq, self.channels, self.i2c_device, self.address, self.id))
cur.close()
self.db.commit()
def __init__(self, db, channels, i2c_device, address, pwm_freq=-1, cid=-1, from_db=False): def __init__(self, db, channels, i2c_device, address, pwm_freq=-1, cid=-1, from_db=False):
self.pwm_freq = pwm_freq self.pwm_freq = pwm_freq
@@ -81,6 +83,7 @@ class Controller:
def add_stripe(self, stripe): def add_stripe(self, stripe):
self.stripes.append(stripe) self.stripes.append(stripe)
class Stripe: class Stripe:
""" """
A stripe is the smallest controllable unit. A stripe is the smallest controllable unit.
@@ -107,6 +110,7 @@ class Stripe:
"UPDATE stripes SET channel_r = ?, channel_g = ?, channel_b = ?,controller_id = ?, name = ? WHERE id = ?", "UPDATE stripes SET channel_r = ?, channel_g = ?, channel_b = ?,controller_id = ?, name = ? WHERE id = ?",
self.channels + [self.controller.id, self.name, self.id]) self.channels + [self.controller.id, self.name, self.id])
cur.close() cur.close()
self.controller.db.commit()
def read_color(self): def read_color(self):
self._color.rgb = [self.controller.get_channel(channel) ** (1 / 2.8) for channel in self.channels] self._color.rgb = [self.controller.get_channel(channel) ** (1 / 2.8) for channel in self.channels]

View File

@@ -32,7 +32,6 @@ class Daemon:
def __init__(self): def __init__(self):
Daemon.instance = self Daemon.instance = self
config = configparser.ConfigParser()
try: try:
self.config = configparser.ConfigParser() self.config = configparser.ConfigParser()
try: try:
@@ -91,6 +90,7 @@ class Daemon:
class ConnectionHandler(asyncore.dispatcher_with_send): class ConnectionHandler(asyncore.dispatcher_with_send):
def handle_read(self): def handle_read(self):
data = self.recv(5120) data = self.recv(5120)
self.debug = True
if data: if data:
print(data) print(data)
try: try:
@@ -102,8 +102,15 @@ class Daemon:
# TODO: add adapter setting stripe with color here # TODO: add adapter setting stripe with color here
print("recieved action: {}".format(json_decoded['action'])) print("recieved action: {}".format(json_decoded['action']))
elif json_decoded['action'] == "add_controller": elif json_decoded['action'] == "add_controller":
# TODO: add controller adding logic here
print("recieved action: {}".format(json_decoded['action'])) print("recieved action: {}".format(json_decoded['action']))
ncontroller = None
try:
ncontroller = controller.Controller(Daemon.instance.sqldb, json_decoded['channels'],
json_decoded['i2c_dev'], json_decoded['address'])
except OSError as e:
print("Error opening i2c device!")
self.send("{}\n".format(ncontroller.id).encode())
Daemon.instance.controllers.append(ncontroller)
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']))
@@ -112,16 +119,12 @@ class Daemon:
for stripe in json_decoded['stripes']: for stripe in json_decoded['stripes']:
# TODO: add stripe here # TODO: add stripe here
print(len(json_decoded['stripes'])) print(len(json_decoded['stripes']))
elif json_decoded['action'] == "add_controller":
ncontroller = controller.Controller(self.daemon.sqldb, 0, json_decoded['channels'],
json_decoded['i2c_dev'], json_decoded['address'])
self.send(ncontroller.id)
Daemon.instance.controllers.append(ncontroller)
else: else:
print("no action found, ignoring") print("no action found, ignoring")
except (TypeError, ValueError): except TypeError as e:
print("No valid JSON found!") print("No valid JSON found: {}".format(e))
except ValueError:
print("No valid JSON detected!")
class SocketServer(asyncore.dispatcher): class SocketServer(asyncore.dispatcher):
def __init__(self, host, port): def __init__(self, host, port):

View File

@@ -15,7 +15,7 @@ INSERT INTO `meta` VALUES ('db_version','1');
CREATE TABLE "controller" ( CREATE TABLE "controller" (
`id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
`address` TEXT, `address` TEXT,
`i2c_device` TEXT, `i2c_device` INTEGER,
`channels` INTEGER, `channels` INTEGER,
`pwm_freq` INTEGER `pwm_freq` INTEGER
); );