Esempio n. 1
0
 def __init__(self):
     try:
       status = sqlhelper.readstatus()
       self.program = status["program"]
       self.delay = status["delay"]
       self.bright = status["bright"]
       self.power = status["power"]
       self.mode = status["mode"]
       self.shifter = status["shifter"]
       self.sync = status["sync"]
       self.timerset = status["timerset"]
       self.ontime = datetime.strptime(status["ontime"],"%H:%M")
       self.offtime = datetime.strptime(status["offtime"],"%H:%M")
     except:
       self.program = 0
       self.delay = 0.5
       self.bright = 1.0
       self.power = 0
       self.mode = 1
       self.shifter = 0
       self.sync = 1
       self.timerset = 0
       self.ontime = datetime.strptime("18:30","%H:%M")
       self.offtime = datetime.strptime("6:30","%H:%M")
     led1 = LED(0,1,2) #instantiate 3 LED objects for this 3 bulb system
     led2 = LED(3,4,5) #LED(R,G,B) = PWM board pin numbers
     led3 = LED(6,7,8)
     global t # list used to cycle thru each bulb
     t = [led1, led2, led3] # one LED object per rgb bulb
     global c #dicts used for holding color object references
     c = sqlhelper.updatedicts() # returns dictionary c = {pk:color object}
     global m # list of mode methods
     global m2 # list of colors used in certain methods (key in m2 is fk to m)
     m,m2 = self.updatemodes()
     sqlhelper.getmodenames()
Esempio n. 2
0
 def shift3separate(self, colors): # colors must be list of color primary keys or string hexcodes "#AA33FF"
   c = sqlhelper.updatedicts()
   ncolors = []
   try: # try and find color objects in dict c from primary keys
     for color in colors:
       ncolors.append(c[int(color)])
   except:  # if that fails the color objects are generated from hexcodes
     for color in colors:
       ncolors.append(Color(color))
   u = []
   y = 0
   for x in t:
     maxdiff = max(abs(x.redpwm - ncolors[y].redpwm*self.bright), abs(x.greenpwm - ncolors[y].greenpwm*self.bright), abs(x.bluepwm - ncolors[y].bluepwm*self.bright))
     x.reddiff = abs(x.redpwm - ncolors[y].redpwm*self.bright)
     x.greendiff = abs(x.greenpwm - ncolors[y].greenpwm*self.bright)
     x.bluediff = abs(x.bluepwm - ncolors[y].bluepwm*self.bright)
     u.append(maxdiff)
     y += 1
     if y >= len(t): y = 0
   maxdiff = max(u)
   y = 0
   for x in t:
     x.redpwm = int(ncolors[y].redpwm*self.bright)
     x.greenpwm = int(ncolors[y].greenpwm*self.bright)
     x.bluepwm = int(ncolors[y].bluepwm*self.bright)
     x.color = colors[y]
     y += 1
     if y >= len(t): y = 0
Esempio n. 3
0
 def turnon(self, color): # color must be a color primary key or string hexcode "#AA33FF"
     c = sqlhelper.updatedicts()
     try: 
         ncolor = c[color] # try and find color object in dict c from primary key
     except: 
         ncolor = Color(color) # if that fails the color object is generated from hexcode
     for x in t: 
         x.redpwm = int(ncolor.redpwm*self.bright)
         x.greenpwm = int(ncolor.greenpwm*self.bright)
         x.bluepwm = int(ncolor.bluepwm*self.bright)
         x.color = color
Esempio n. 4
0
 def turnon3separate(self, colors): # colors must be list of color primary keys or string hexcodes "#AA33FF"
     c = sqlhelper.updatedicts()
     ncolors = []
     try: # try and find color objects in dict c from primary keys
         for color in colors:
             ncolors.append(c[color])
     except:  # if that fails the color objects are generated from hexcodes
         for color in colors:
             ncolors.append(Color(color))
     y = 0
     for x in t:
         x.redpwm = int(ncolors[y].redpwm*self.bright)
         x.greenpwm = int(ncolors[y].greenpwm*self.bright)
         x.bluepwm = int(ncolors[y].bluepwm*self.bright)
         x.color = colors[y]
         y += 1
         if y >= len(colors): y = 0
Esempio n. 5
0
 def shift(self, color): # color must be a color primary key or string hexcode "#AA33FF"
   c = sqlhelper.updatedicts()
   try: 
       ncolor = c[color] # try and find color object in dict c from primary key
   except: 
       ncolor = Color(color) # if that fails the color object is generated from hexcode
   u = []
   for x in t:
     maxdiff = max(abs(x.redpwm - ncolor.redpwm*self.bright), abs(x.greenpwm - ncolor.greenpwm*self.bright), abs(x.bluepwm - ncolor.bluepwm*self.bright))
     x.reddiff = abs(x.redpwm - ncolor.redpwm*self.bright)
     x.greendiff = abs(x.greenpwm - ncolor.greenpwm*self.bright)
     x.bluediff = abs(x.bluepwm - ncolor.bluepwm*self.bright)
     u.append(maxdiff)
   maxdiff = max(u)
   for x in t:
     x.redpwm = int(ncolor.redpwm*self.bright)
     x.greenpwm = int(ncolor.greenpwm*self.bright)
     x.bluepwm = int(ncolor.bluepwm*self.bright)
     x.color = color
Esempio n. 6
0
 def run(self):
   c = sqlhelper.updatedicts()
   m,m2 = self.updatemodes()
   q = queue.Queue()
   t1 = threading.Thread(target=self.checkcodes,args=(q,))
   t1.daemon = True
   t1.start()
   delay = timedelta(milliseconds=1)
   then = datetime.now() + delay
   while True:
     now = datetime.now()
     if now > then:
       then = now + delay
       try:
         y = q.get()
         try:
           t2.do_run = False
         except: pass
         if y.get("power"):
           if int(y["power"]) == 0:
             self.fadeoff()
             self.power = 0
             self.writestatus()
             print("Power turned off")
           elif int(y["power"]) == 1:
             self.power = 1
             self.writestatus()
             t2 = self.enginestatuscheck()
             print("Power turned on")
         if y.get("sync"):
           self.sync = int(y["sync"])
           self.writestatus()
           t2 = self.enginestatuscheck()
           print("Sync updated")
         if y.get("shifter"):
           self.shifter = int(y["shifter"])
           self.writestatus()
           t2 = self.enginestatuscheck()
           print("Shifter updated")
         if y.get("colors"):
           z = y["colors"] 
           c = sqlhelper.updatedicts()
           self.shift3separate(z)
           self.power = 1
           self.program = 0
           self.writestatus()
           print("Colors updated")
         if y.get("color"):
           x = y["color"]
           self.shift(x)
           self.power = 1
           self.program = 0
           self.writestatus()
           print("Custom color")
         if y.get("bright"):
           self.bright = float(y["bright"])
           self.writestatus()
           t2 = self.enginestatuscheck()
           print("Brightness updated")
         if y.get("delay"):
           self.delay = float(y["delay"] )
           self.writestatus()
           t2 = self.enginestatuscheck()
           print("Delay updated")
         if y.get("mode"):
           m,m2 = self.updatemodes()
           self.mode = int(y["mode"])
           self.program = 1
           if self.mode in m2:
             t2 = threading.Thread(target=m[self.mode],args=(m2[self.mode],))
           else: t2 = threading.Thread(target=m[self.mode])
           t2.daemon = True
           t2.start()
           self.power = 1
           self.writestatus()
           print("Mode updated")
         if y.get("addmode"):
           u = y["addmode"] # will give list ["name","1,2,3"]
           sqlhelper.addmode(u[0],u[1])
           m,m2 = self.updatemodes()
           self.writestatus()
           t2 = self.enginestatuscheck()
           print("New mode saved")
         if y.get("save"):
           u = y["save"] # will give list ["name","hexcode"]
           sqlhelper.addcolortodb(u[0],u[1])
           c = sqlhelper.updatedicts()
           self.writestatus()
           t2 = self.enginestatuscheck()
           print("New color saved")
         if y.get("deletemode"):
           u = y["deletemode"] # will give hexcode string
           sqlhelper.deletemode(u)
           m,m2 = self.updatemodes()
           self.writestatus()
           t2 = self.enginestatuscheck()
           print("Mode removed")
         if y.get("delete"):
           u = y["delete"] # will give hexcode string
           sqlhelper.deletecolorfromdb(u)
           c = sqlhelper.updatedicts()
           self.writestatus()
           t2 = self.enginestatuscheck()
           print("Color removed")
         time.sleep(.1)
       except KeyboardInterrupt:
         print("KeyboardInterrupt")
         break
   try:
     t1.do_run = False
     t1.join()
     t2.do_run = False
     t2.join()
   except: pass
Esempio n. 7
0
            t2 = self.enginestatuscheck()
            print("Mode removed")
          if y.get("delete"):
            u = y["delete"] # will give hexcode string
            sqlhelper.deletecolorfromdb(u)
            c = sqlhelper.updatedicts()
            self.writestatus()
            t2 = self.enginestatuscheck()
            print("Color removed")
          time.sleep(.1)
        except KeyboardInterrupt:
          print("KeyboardInterrupt")
          break
    try:
      t1.do_run = False
      t1.join()
      t2.do_run = False
      t2.join()
    except: pass

if __name__=="__main__":
  sys = System() #create object
  c = sqlhelper.updatedicts()
  # sys.turnon3separate([1,4,6])
  # time.sleep(1)
  # sys.turnoff() #turn off
  # sys.writestatus()
  sys.run() #start main program
  # sys.turnoff()
  # print("Done")