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