Skip to content

Commit

Permalink
5 channel ledenet controller (#10)
Browse files Browse the repository at this point in the history
* Added ledenet protocol

* Updated to use protocol

* Changed protocol to always be uppwer
  • Loading branch information
Brent Hughes authored and Danielhiversen committed Dec 23, 2016
1 parent fc46123 commit c71c7d6
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions flux_led/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,14 +450,16 @@ def __init__(self, ipaddr, port=5577, timeout=5):
self.port = port
self.timeout = timeout

self.protocol = None

self.raw_state = None
self._is_on = False
self._mode = None
self._rgb = [0, 0, 0]
self._warm_white = 0
self._cold_white = 0
self._brightness = 0
self._socket = None
self._socket = None
self._lock = threading.Lock()

self.connect(2)
Expand Down Expand Up @@ -588,7 +590,7 @@ def __str__(self):
mode_str = "Unknown mode 0x{:x}".format(pattern)
if pattern == 0x62:
mode_str += " (tmp)"
mode_str += " raw state: "
mode_str += " raw state: "
for _r in rx:
mode_str += str(_r) + ","
return "{} [{}]".format(power_str, mode_str)
Expand Down Expand Up @@ -636,6 +638,10 @@ def setWarmWhite255(self, level, persist=True, retry=2):
msg.append(0x00)
msg.append(0x00)
msg.append(int(level))

if self.protocol == "LEDENET":
msg.append(int(level))

msg.append(0x0f)
msg.append(0x0f)
try:
Expand Down Expand Up @@ -665,6 +671,10 @@ def setRgbw(self, r,g,b,w, persist=True, brightness=None, retry=2):
msg.append(int(g))
msg.append(int(b))
msg.append(int(w))

if self.protocol == "LEDENET":
msg.append(0x00)

msg.append(0x0f)
msg.append(0x0f)
try:
Expand Down Expand Up @@ -692,6 +702,10 @@ def setRgb(self, r,g,b, persist=True, brightness=None, retry=2):
msg.append(int(r))
msg.append(int(g))
msg.append(int(b))

if self.protocol == "LEDENET":
msg.append(0x00)

msg.append(0x00)
msg.append(0xf0)
msg.append(0x0f)
Expand Down Expand Up @@ -770,6 +784,9 @@ def setClock(self):
msg.append(0x0f)
self._send_msg(msg)

def setProtocol(self, protocol):
self.protocol = protocol.upper()

def setPresetPattern(self, pattern, speed):

PresetPattern.valtostr(pattern)
Expand Down Expand Up @@ -1290,6 +1307,9 @@ def parseArgs():
"and other mode specific settings. Use --timerhelp for more details.")


parser.add_option("--protocol", dest="protocol", default=None, metavar="PROTOCOL",
help="Set the device protocol. Currently only supports LEDENET")

other_group.add_option("-v", "--volatile",
action="store_true", dest="volatile", default=False,
help="Don't persist mode setting with hard power cycle (RGB and WW modes only).")
Expand Down Expand Up @@ -1400,6 +1420,7 @@ def main():
info = dict()
info['ipaddr'] = addr
info['id'] = 'Unknown ID'

bulb_info_list.append(info)


Expand All @@ -1417,6 +1438,9 @@ def main():
if options.setclock:
bulb.setClock()

if options.protocol:
bulb.setProtocol(options.protocol)

if options.ww is not None:
print("Setting warm white mode, level: {}%".format(options.ww))
bulb.setWarmWhite(options.ww, not options.volatile)
Expand Down

0 comments on commit c71c7d6

Please sign in to comment.