Refine blink feature
This commit is contained in:
+35
-8
@@ -136,7 +136,10 @@ async def setColor(request):
|
|||||||
|
|
||||||
__setBusyLightColor(color, blBrightness)
|
__setBusyLightColor(color, blBrightness)
|
||||||
|
|
||||||
return {'status': blStatus}
|
return {
|
||||||
|
'status': blStatus,
|
||||||
|
'blinking': blBlinking
|
||||||
|
}
|
||||||
|
|
||||||
@app.route('/api/status/<status>', methods=['GET', 'POST'])
|
@app.route('/api/status/<status>', methods=['GET', 'POST'])
|
||||||
async def setStatus(request, status):
|
async def setStatus(request, status):
|
||||||
@@ -154,7 +157,10 @@ async def setStatus(request, status):
|
|||||||
else:
|
else:
|
||||||
return {'error': 'unknown /api/status/' + lStatus + ' route'}, 404
|
return {'error': 'unknown /api/status/' + lStatus + ' route'}, 404
|
||||||
|
|
||||||
return {'status': blStatus}
|
return {
|
||||||
|
'status': blStatus,
|
||||||
|
'blinking': blBlinking
|
||||||
|
}
|
||||||
|
|
||||||
async def __blinkTask(color, brightness, frequency, duration):
|
async def __blinkTask(color, brightness, frequency, duration):
|
||||||
global blBlinking, blStatus, blColor, blBrightness
|
global blBlinking, blStatus, blColor, blBrightness
|
||||||
@@ -181,7 +187,10 @@ async def __blinkTask(color, brightness, frequency, duration):
|
|||||||
async def blinkStop(request):
|
async def blinkStop(request):
|
||||||
global blBlinking
|
global blBlinking
|
||||||
blBlinking = False
|
blBlinking = False
|
||||||
return {'status': blStatus}
|
return {
|
||||||
|
'status': blStatus,
|
||||||
|
'blinking': blBlinking
|
||||||
|
}
|
||||||
|
|
||||||
@app.post('/api/blink')
|
@app.post('/api/blink')
|
||||||
async def setBlink(request):
|
async def setBlink(request):
|
||||||
@@ -215,7 +224,13 @@ async def setBlink(request):
|
|||||||
# Launch blink task
|
# Launch blink task
|
||||||
asyncio.create_task(__blinkTask(savedColor, savedBrightness, frequency, duration))
|
asyncio.create_task(__blinkTask(savedColor, savedBrightness, frequency, duration))
|
||||||
|
|
||||||
return {'status': 'blinking', 'frequency': frequency, 'duration': duration}
|
elapsed = time.ticks_diff(time.ticks_ms(), blBlinkStartTime) / 1000.0
|
||||||
|
remains = max(0.0, blBlinkDuration - elapsed)
|
||||||
|
isblinking = True
|
||||||
|
return {
|
||||||
|
'status': blStatus,
|
||||||
|
'blinking': blBlinking
|
||||||
|
}
|
||||||
|
|
||||||
@app.get('/api/blink')
|
@app.get('/api/blink')
|
||||||
async def getBlink(request):
|
async def getBlink(request):
|
||||||
@@ -226,7 +241,7 @@ async def getBlink(request):
|
|||||||
remains = 0.0
|
remains = 0.0
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'isblinking': blBlinking,
|
'blinking': blBlinking,
|
||||||
'frequency': blBlinkFrequency,
|
'frequency': blBlinkFrequency,
|
||||||
'duration': blBlinkDuration,
|
'duration': blBlinkDuration,
|
||||||
'remains': remains
|
'remains': remains
|
||||||
@@ -240,13 +255,22 @@ async def getColor(request):
|
|||||||
|
|
||||||
@app.get('/api/status')
|
@app.get('/api/status')
|
||||||
async def getStatus(request):
|
async def getStatus(request):
|
||||||
return {'status': blStatus}
|
return {
|
||||||
|
'status': blStatus,
|
||||||
|
'blinking': blBlinking
|
||||||
|
}
|
||||||
|
|
||||||
@app.get('/api/debug')
|
@app.get('/api/debug')
|
||||||
async def getDebugInfo(request):
|
async def getDebugInfo(request):
|
||||||
r, g, b = blColor
|
r, g, b = blColor
|
||||||
dr, dg, db = neoPixelStrip.__getitem__(0)
|
dr, dg, db = neoPixelStrip.__getitem__(0)
|
||||||
return {'status': blStatus, 'brightness': blBrightness, 'color': {'r': r, 'g': g, 'b': b}, 'dimColor': {'r': dr, 'g': dg, 'b': db}}
|
return {
|
||||||
|
'status': blStatus,
|
||||||
|
'blinking': blBlinking,
|
||||||
|
'brightness': blBrightness,
|
||||||
|
'color': {'r': r, 'g': g, 'b': b},
|
||||||
|
'dimColor': {'r': dr, 'g': dg, 'b': db}
|
||||||
|
}
|
||||||
|
|
||||||
@app.post('/api/mutedeck-webhook')
|
@app.post('/api/mutedeck-webhook')
|
||||||
async def mutedeckWebhook(request):
|
async def mutedeckWebhook(request):
|
||||||
@@ -270,7 +294,10 @@ async def mutedeckWebhook(request):
|
|||||||
else:
|
else:
|
||||||
__setBusyLightStatus('available')
|
__setBusyLightStatus('available')
|
||||||
|
|
||||||
return {'status': blStatus}
|
return {
|
||||||
|
'status': blStatus,
|
||||||
|
'blinking': blBlinking
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@app.post('/shutdown')
|
@app.post('/shutdown')
|
||||||
|
|||||||
@@ -53,25 +53,35 @@ Or directly from [here](streamdeck-plugin/README.md).
|
|||||||
|
|
||||||
## End points
|
## End points
|
||||||
|
|
||||||
| Path | Method | Parameter | Description |
|
| Path | Method | Parameter | Description |
|
||||||
| --- | --- | --- | --- |
|
| --------------------- | ----------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
|
||||||
| /api/color | POST | `color` JSON object | Set the BusyLight color according to the `color` object passed in the request body. Return a `status` object. |
|
| /api/color | POST | `color` JSON object | Set the BusyLight color according to the `color` object passed in the request body. Return a `status` object. |
|
||||||
| /api/color | GET | n/a | Retreive the color currently displayed by the BusyLight. Return a `color` object. |
|
| /api/color | GET | n/a | Retreive the color currently displayed by the BusyLight. Return a `color` object. |
|
||||||
| /api/brightness | POST | `brightness` JSON object | Set the BusyLight brightness according to the `brightness` object passed in the request body. Return a `status` object. |
|
| /api/brightness | POST | `brightness` JSON object | Set the BusyLight brightness according to the `brightness` object passed in the request body. Return a `status` object. |
|
||||||
| /api/brightness | GET | n/a | Retreive the BusyLight brightness. Return a `brightness` object. |
|
| /api/brightness | GET | n/a | Retreive the BusyLight brightness. Return a `brightness` object. |
|
||||||
| /api/status/on | POST / GET | n/a | Light up the BusyLight. White color. Return a `status` object. |
|
| /api/status/on | POST / GET | n/a | Light up the BusyLight. White color. Return a `status` object. |
|
||||||
| /api/status/available | POST / GET | n/a | Set the BusyLight in `available` mode. Green color. Return a `status` object. |
|
| /api/status/available | POST / GET | n/a | Set the BusyLight in `available` mode. Green color. Return a `status` object. |
|
||||||
| /api/status/away | POST / GET | n/a | Set the BusyLight in `away` mode. Yellow color. Return a `status` object. |
|
| /api/status/away | POST / GET | n/a | Set the BusyLight in `away` mode. Yellow color. Return a `status` object. |
|
||||||
| /api/status/busy | POST / GET | n/a | Set the BusyLight in `busy` mode. Red color. Return a `status` object. |
|
| /api/status/busy | POST / GET | n/a | Set the BusyLight in `busy` mode. Red color. Return a `status` object. |
|
||||||
| /api/status/off | POST / GET | n/a | Shutdown the BusyLight. Return a `status` object. |
|
| /api/status | GET | n/a | Retreive the current BusyLight status. Return a `status` object. |
|
||||||
| /api/status | GET | n/a | Retreive the current BusyLight status. Return a `status` object. |
|
| /api/status/off | POST / GET | n/a | Shutdown the BusyLight. Return a `status` object. |
|
||||||
| /api/blink | POST | `blink` JSON object | Make the BusyLight blink. Preserves current color, status and brightness. Return a `status` object. |
|
| /api/blink | POST | `setBlink` JSON object | Make the BusyLight blink. Preserves current color, status and brightness. Return a `status` object. |
|
||||||
| /api/blink | GET | n/a | Retrieve the current BusyLight blink status. Return a `blink` object. |
|
| /api/blink | GET | n/a | Retrieve the current BusyLight blink status. Return a `blink` object. |
|
||||||
| /api/blink/stop | POST | n/a | Stop the BusyLight blinking and restore previous state. Return a `status` object. |
|
| /api/blink/stop | POST | n/a | Stop the BusyLight blinking and restore previous state. Return a `status` object. |
|
||||||
| /api/debug | GET | n/a | Retreive the full BusyLight status. |
|
| /api/debug | GET | n/a | Retreive the full BusyLight status. |
|
||||||
|
|
||||||
## JSON objects
|
## JSON objects
|
||||||
|
|
||||||
|
### `brightness` object
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"brightness": 0.5
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
`brightness`: LED brightness | float | [0.0 .. 1.0]
|
||||||
|
|
||||||
### `color` object
|
### `color` object
|
||||||
|
|
||||||
```json
|
```json
|
||||||
@@ -88,16 +98,6 @@ Or directly from [here](streamdeck-plugin/README.md).
|
|||||||
`b`: BLUE color | integer | [0 .. 255]
|
`b`: BLUE color | integer | [0 .. 255]
|
||||||
`brightness`: LED brightness (optional) | float | [0.0 .. 1.0]
|
`brightness`: LED brightness (optional) | float | [0.0 .. 1.0]
|
||||||
|
|
||||||
### `brightness` object
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"brightness": 0.5
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
`brightness`: LED brightness | float | [0.0 .. 1.0]
|
|
||||||
|
|
||||||
### `blink` object
|
### `blink` object
|
||||||
|
|
||||||
```json
|
```json
|
||||||
@@ -114,15 +114,29 @@ Or directly from [here](streamdeck-plugin/README.md).
|
|||||||
`duration`: total blink duration | float | seconds | 0 = endless
|
`duration`: total blink duration | float | seconds | 0 = endless
|
||||||
`remains`: remaining blink time | float | seconds | 0 if endless
|
`remains`: remaining blink time | float | seconds | 0 if endless
|
||||||
|
|
||||||
|
### `setBlink` object
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"frequency": 2,
|
||||||
|
"duration": 5.0,
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
`frequency`: blink frequency | integer | Hz
|
||||||
|
`duration`: total blink duration | float | seconds | 0 = endless
|
||||||
|
|
||||||
### `status` object
|
### `status` object
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"status": "<STATUS>"
|
"status": "<STATUS>",
|
||||||
|
"blinking": true
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
`<STATUS>` : `on` | `off` | `available` | `away` | `busy` | `colored` | `blinking`
|
`<STATUS>` : `on` | `off` | `available` | `away` | `busy` | `colored`
|
||||||
|
`isblinking`: whether the BusyLight is currently blinking | boolean
|
||||||
|
|
||||||
# MuteDeck integration
|
# MuteDeck integration
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user