diff --git a/ESP32/main.py b/ESP32/main.py index 53b10e0..6e11466 100644 --- a/ESP32/main.py +++ b/ESP32/main.py @@ -136,7 +136,10 @@ async def setColor(request): __setBusyLightColor(color, blBrightness) - return {'status': blStatus} + return { + 'status': blStatus, + 'blinking': blBlinking + } @app.route('/api/status/', methods=['GET', 'POST']) async def setStatus(request, status): @@ -154,7 +157,10 @@ async def setStatus(request, status): else: return {'error': 'unknown /api/status/' + lStatus + ' route'}, 404 - return {'status': blStatus} + return { + 'status': blStatus, + 'blinking': blBlinking + } async def __blinkTask(color, brightness, frequency, duration): global blBlinking, blStatus, blColor, blBrightness @@ -181,7 +187,10 @@ async def __blinkTask(color, brightness, frequency, duration): async def blinkStop(request): global blBlinking blBlinking = False - return {'status': blStatus} + return { + 'status': blStatus, + 'blinking': blBlinking + } @app.post('/api/blink') async def setBlink(request): @@ -215,7 +224,13 @@ async def setBlink(request): # Launch blink task 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') async def getBlink(request): @@ -226,7 +241,7 @@ async def getBlink(request): remains = 0.0 return { - 'isblinking': blBlinking, + 'blinking': blBlinking, 'frequency': blBlinkFrequency, 'duration': blBlinkDuration, 'remains': remains @@ -240,13 +255,22 @@ async def getColor(request): @app.get('/api/status') async def getStatus(request): - return {'status': blStatus} + return { + 'status': blStatus, + 'blinking': blBlinking + } @app.get('/api/debug') async def getDebugInfo(request): r, g, b = blColor 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') async def mutedeckWebhook(request): @@ -270,7 +294,10 @@ async def mutedeckWebhook(request): else: __setBusyLightStatus('available') - return {'status': blStatus} + return { + 'status': blStatus, + 'blinking': blBlinking + } @app.post('/shutdown') diff --git a/README.md b/README.md index 888c385..62d2dff 100644 --- a/README.md +++ b/README.md @@ -53,25 +53,35 @@ Or directly from [here](streamdeck-plugin/README.md). ## End points -| 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 | 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 | 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/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/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/blink | POST | `blink` 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/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. | +| 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 | 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 | 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/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/busy | POST / GET | n/a | Set the BusyLight in `busy` mode. Red color. 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 | `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/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. | ## JSON objects +### `brightness` object + +```json +{ + "brightness": 0.5 +} +``` + +`brightness`: LED brightness | float | [0.0 .. 1.0] + ### `color` object ```json @@ -88,16 +98,6 @@ Or directly from [here](streamdeck-plugin/README.md). `b`: BLUE color | integer | [0 .. 255] `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 ```json @@ -112,17 +112,31 @@ Or directly from [here](streamdeck-plugin/README.md). `isblinking`: whether the BusyLight is currently blinking | boolean `frequency`: blink frequency | integer | Hz `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 ```json { - "status": "" + "status": "", + "blinking": true } ``` -`` : `on` | `off` | `available` | `away` | `busy` | `colored` | `blinking` +`` : `on` | `off` | `available` | `away` | `busy` | `colored` +`isblinking`: whether the BusyLight is currently blinking | boolean # MuteDeck integration