Skip to content

Commit

Permalink
maximum brightness
Browse files Browse the repository at this point in the history
  • Loading branch information
LelandSindt committed Sep 8, 2021
1 parent a655923 commit b51d804
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions lumen.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#lumenCommand = { 'animation' : 'None' }

num_pixels = 12
max_bright = 255

if os.environ.get('PIXELS') != None:
num_pixels = int(os.environ.get('PIXELS'))
Expand Down Expand Up @@ -199,6 +200,21 @@ def do_PUT(self):
self.send_header("Content-type", "json")
self.end_headers()
self.wfile.write(bytes('{"response":"fail"}', "utf-8"))
elif self.path == "/lumen/max_bright":
length = self.headers['Content-Length']
global max_bright
max_bright = parseMaxBright(self.rfile.read(int(length)).decode("utf-8"))
if max_bright != None:
self.send_response(200)
self.send_header("Content-type", "json")
self.end_headers()
self.wfile.write(bytes('{"response":"ok"}', "utf-8"))
logging.debug("new max bright value: " + str(max_bright))
else:
self.send_response(400)
self.send_header("Content-type", "json")
self.end_headers()
self.wfile.write(bytes('{"response":"fail"}', "utf-8"))
else:
self.send_response(404)
self.end_headers()
Expand All @@ -218,18 +234,26 @@ def valueTransition(valueFrom, valueTo):

def pixelFillWrapper(color):
if os.environ.get('SKIP_PIXELS') == None:
pixels.fill(color)
pixels.fill(apply_bright(color, max_bright))
pixels.show()
else:
logging.debug(msg="color: " + str(color) + ", max_bright: " + str(max_bright))

def pixelWrapper(pixel, color):
try:
if os.environ.get('SKIP_PIXELS') == None:
pixels[pixel] = color
pixels[pixel] = apply_bright(color, max_bright)
else:
logging.debug(msg="pixel: " + str(pixel) + ", color: " + str(color) )
logging.debug(msg="pixel: " + str(pixel) + ", color: " + str(color) + ", max_bright: " + str(max_bright))
except Exception as e:
logging.debug("doh! ", exc_info=e)

def parseMaxBright(payload):
try:
return json.loads(payload).get('max_bright',255)
except:
return 255

def parseCommand(payload):
command = {}
try:
Expand Down

0 comments on commit b51d804

Please sign in to comment.