Update method name: __setBusyLightColor -> __setDimmedColor
This commit is contained in:
+15
-19
@@ -34,7 +34,7 @@ def __setColor(color):
|
||||
b = int(b * blBrightness)
|
||||
return (r, g, b)
|
||||
|
||||
def __setBusyLightColor(color, brightness):
|
||||
def __setDimmedColor(color, brightness):
|
||||
global blBrightness
|
||||
blBrightness = brightness
|
||||
global blColor
|
||||
@@ -48,7 +48,7 @@ def __setBusyLightColor(color, brightness):
|
||||
def __setBusyLightStatus(status):
|
||||
status = status.upper()
|
||||
color = statusColors.get(status)
|
||||
__setBusyLightColor(color, blBrightness)
|
||||
__setDimmedColor(color, blBrightness)
|
||||
|
||||
global blStatus
|
||||
blStatus = status.lower()
|
||||
@@ -90,7 +90,7 @@ async def setBrightness(request):
|
||||
|
||||
# Apply new brightness to current color
|
||||
color = blColor
|
||||
__setBusyLightColor(color, brightness)
|
||||
__setDimmedColor(color, brightness)
|
||||
|
||||
# Restore global status
|
||||
blStatus = status
|
||||
@@ -132,9 +132,9 @@ async def setColor(request):
|
||||
return {'error': 'brightness out of bound (0.0 - 1.0)'}, 400
|
||||
else:
|
||||
return {'error': 'wrong brightness type (float)'}, 400
|
||||
__setBusyLightColor(color, brightness)
|
||||
__setDimmedColor(color, brightness)
|
||||
|
||||
__setBusyLightColor(color, blBrightness)
|
||||
__setDimmedColor(color, blBrightness)
|
||||
|
||||
return {
|
||||
'status': blStatus,
|
||||
@@ -162,13 +162,13 @@ async def setStatus(request, status):
|
||||
'blinking': blBlinking
|
||||
}
|
||||
|
||||
async def __blinkTask(color, brightness, frequency, duration):
|
||||
global blBlinking, blStatus, blColor, blBrightness
|
||||
async def __blinkTask(frequency, duration):
|
||||
global blBlinking, blColor, blBrightness
|
||||
blBlinking = True
|
||||
interval = 1.0 / (frequency * 2) # half period in seconds
|
||||
elapsed = 0.0
|
||||
while blBlinking:
|
||||
neoPixelStrip.fill(__setColor(color))
|
||||
neoPixelStrip.fill(__setDimmedColor(blColor, blBrightness))
|
||||
neoPixelStrip.write()
|
||||
await asyncio.sleep(interval)
|
||||
neoPixelStrip.fill((0, 0, 0))
|
||||
@@ -180,8 +180,7 @@ async def __blinkTask(color, brightness, frequency, duration):
|
||||
break
|
||||
# Restore previous state
|
||||
blBlinking = False
|
||||
__setBusyLightColor(color, brightness)
|
||||
blStatus = blPreviousStatus
|
||||
__setDimmedColor(blColor, blBrightness)
|
||||
|
||||
@app.post('/api/blink/stop')
|
||||
async def blinkStop(request):
|
||||
@@ -200,21 +199,18 @@ async def setBlink(request):
|
||||
if frequency is None or duration is None:
|
||||
return {'error': 'missing frequency or duration parameter'}, 400
|
||||
|
||||
if not isinstance(frequency, int) or frequency <= 0:
|
||||
return {'error': 'frequency must be a positive integer (Hz)'}, 400
|
||||
if not isinstance(frequency, float) or frequency <= 0:
|
||||
return {'error': 'frequency must be a positive float (Hz)'}, 400
|
||||
|
||||
if not (isinstance(duration, (int, float))) or duration < 0:
|
||||
return {'error': 'duration must be a positive float in seconds (0 = endless)'}, 400
|
||||
|
||||
# Save current state
|
||||
global blPreviousStatus, blBlinking, blBlinkFrequency, blBlinkDuration, blBlinkStartTime
|
||||
blPreviousStatus = blStatus
|
||||
savedColor = blColor
|
||||
savedBrightness = blBrightness
|
||||
global blBlinking, blBlinkFrequency, blBlinkDuration, blBlinkStartTime
|
||||
|
||||
# Stop any ongoing blink
|
||||
blBlinking = False
|
||||
await asyncio.sleep(0)
|
||||
await asyncio.sleep(0.5)
|
||||
|
||||
# Save blink params
|
||||
blBlinkFrequency = frequency
|
||||
@@ -222,7 +218,7 @@ async def setBlink(request):
|
||||
blBlinkStartTime = time.ticks_ms()
|
||||
|
||||
# Launch blink task
|
||||
asyncio.create_task(__blinkTask(savedColor, savedBrightness, frequency, duration))
|
||||
asyncio.create_task(__blinkTask(frequency, duration))
|
||||
|
||||
elapsed = time.ticks_diff(time.ticks_ms(), blBlinkStartTime) / 1000.0
|
||||
remains = max(0.0, blBlinkDuration - elapsed)
|
||||
@@ -308,7 +304,7 @@ async def shutdown(request):
|
||||
# Startup effect
|
||||
def startUpSeq():
|
||||
print('Start seq begins')
|
||||
__setBusyLightColor(statusColors.get('OFF'), 0.1)
|
||||
__setDimmedColor(statusColors.get('OFF'), 0.1)
|
||||
time.sleep_ms(100)
|
||||
__setBusyLightStatus('BUSY')
|
||||
time.sleep_ms(200)
|
||||
|
||||
Reference in New Issue
Block a user