diff --git a/LedD/controller.py b/LedD/controller.py index fbda7a0..d72b646 100644 --- a/LedD/controller.py +++ b/LedD/controller.py @@ -44,9 +44,11 @@ class Controller: def save_to_db(self): cur = self.db.cursor() if self.id == -1: - cur.execute("INSERT INTO controller DEFAULT VALUES") + cur.execute("INSERT INTO controller (pwm_freq, channels, i2c_device, address) VALUES ()", + (self.pwm_freq, self.channels, self.i2c_device, self.address)) self.id = cur.lastrowid - cur.execute("UPDATE controller SET pwm_freq=?, channels=?, i2c_device=?, address=? WHERE id = ?", + else: + 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)) cur.close() self.db.commit() diff --git a/LedD/daemon.py b/LedD/daemon.py index b089af5..dbffb65 100644 --- a/LedD/daemon.py +++ b/LedD/daemon.py @@ -21,7 +21,7 @@ import json import sqlite3 import os import sys - +import traceback from . import controller @@ -60,6 +60,11 @@ class Daemon: sys.exit(0) def check_db(self): + """ + Checks database version + :return: database validity + :rtype: bool + """ c = self.sqldb.cursor() try: c.execute("SELECT value FROM meta WHERE option = 'db_version'") @@ -125,6 +130,7 @@ class Daemon: print("No valid JSON found: {}".format(e)) except ValueError: print("No valid JSON detected!") + traceback.print_exc(file=sys.stdout) class SocketServer(asyncore.dispatcher): def __init__(self, host, port): diff --git a/start.py b/start.py index d8f9239..77d5c72 100644 --- a/start.py +++ b/start.py @@ -1,3 +1,25 @@ +from pkgutil import iter_modules + +if "smbus" not in (name for loader, name, ispkg in iter_modules()): + print("smbus not found, installing replacement") + + + class SMBus: + def __init__(self, i2c_address): + self.i2c_address = i2c_address + self.channels = {} + + def write_word_data(self, cmd, val): + if (cmd - 6) % 4 == 0: + self.channels[(cmd - 6) / 4] = val + + def read_word_data(self, cmd): + return self.channels[(cmd - 8) / 4] + + + import sys + + sys.modules['smbus'] = SMBus import LedD.daemon if __name__ == "__main__":