Add capability to set LED color (#16)

This commit is contained in:
iGoX 2024-12-27 18:24:20 +01:00
parent 70ba676151
commit 3b47df5146
12 changed files with 243 additions and 122 deletions

View file

@ -1,5 +1,28 @@
# Release notes
## Version 0.2.0.0 (2024-12-28)
### Download
[org.igox.busylight.v0.2.0.0.streamDeckPlugin](download/org.igox.busylight.v0.2.0.0.streamDeckPlugin)
### Features
- Add the capability to set the color diplayed by BusyLigh LEDs.
### Fixes
- None.
### Bugs & known limitations
- None known at publication time.
### Screenshot
![v0.2.0.0 screenshot](img/v0.2.0.0.png)
## Version 0.1.0.0 (2024-12-28)
### Download

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

View file

@ -1,113 +1,128 @@
{
"Name": "iGoX BusyLight",
"Version": "0.1.0.0",
"Author": "iGoX",
"$schema": "https://schemas.elgato.com/streamdeck/plugins/manifest.json",
"Actions": [
{
"Name": "Set status as 'Available'",
"UUID": "org.igox.busylight.status.available",
"Icon": "imgs/actions/status/available/available",
"Tooltip": "Set status as 'Available'",
"PropertyInspectorPath": "ui/status-config.html",
"Controllers": [
"Keypad"
],
"States": [
{
"Image": "imgs/actions/status/available/available",
"TitleAlignment": "bottom"
}
]
},
{
"Name": "Set status as 'Away'",
"UUID": "org.igox.busylight.status.away",
"Icon": "imgs/actions/status/away/away",
"Tooltip": "Set status as 'Away'",
"PropertyInspectorPath": "ui/status-config.html",
"Controllers": [
"Keypad"
],
"States": [
{
"Image": "imgs/actions/status/away/away",
"TitleAlignment": "bottom"
}
]
},
{
"Name": "Set status as 'Busy'",
"UUID": "org.igox.busylight.status.busy",
"Icon": "imgs/actions/status/busy/busy",
"Tooltip": "Set status as 'Busy'",
"PropertyInspectorPath": "ui/status-config.html",
"Controllers": [
"Keypad"
],
"States": [
{
"Image": "imgs/actions/status/busy/busy",
"TitleAlignment": "bottom"
}
]
}
,
{
"Name": "Turn off the BusyLight",
"UUID": "org.igox.busylight.status.off",
"Icon": "imgs/actions/status/off/off",
"Tooltip": "Turn off the BusyLight",
"PropertyInspectorPath": "ui/status-config.html",
"Controllers": [
"Keypad"
],
"States": [
{
"Image": "imgs/actions/status/off/off",
"TitleAlignment": "bottom"
}
]
},
{
"Name": "Set brightness",
"UUID": "org.igox.busylight.brigthness.set",
"Icon": "imgs/actions/brightness/brightness",
"Tooltip": "Set brightness",
"PropertyInspectorPath": "ui/brightness-config.html",
"Controllers": [
"Keypad"
],
"States": [
{
"Image": "imgs/actions/brightness/brightness",
"TitleAlignment": "bottom"
}
]
}
],
"Category": "iGoX BusyLight",
"CategoryIcon": "imgs/plugin/marketplace",
"CodePath": "bin/plugin.js",
"Description": "Control your DIY BusyLight (https://github.com/igox/busylight) from your Stream Deck",
"Icon": "imgs/plugin/marketplace",
"SDKVersion": 2,
"Software": {
"MinimumVersion": "6.4"
},
"OS": [
{
"Platform": "mac",
"MinimumVersion": "10.15"
},
{
"Platform": "windows",
"MinimumVersion": "10"
}
],
"Nodejs": {
"Version": "20",
"Debug": "enabled"
},
"UUID": "org.igox.busylight"
{
"Name": "iGoX BusyLight",
"Version": "0.2.0.0",
"Author": "iGoX",
"$schema": "https://schemas.elgato.com/streamdeck/plugins/manifest.json",
"Actions": [
{
"Name": "Set status as 'Available'",
"UUID": "org.igox.busylight.status.available",
"Icon": "imgs/actions/status/available/available",
"Tooltip": "Set status as 'Available'",
"PropertyInspectorPath": "ui/status-config.html",
"Controllers": [
"Keypad"
],
"States": [
{
"Image": "imgs/actions/status/available/available",
"TitleAlignment": "bottom"
}
]
},
{
"Name": "Set status as 'Away'",
"UUID": "org.igox.busylight.status.away",
"Icon": "imgs/actions/status/away/away",
"Tooltip": "Set status as 'Away'",
"PropertyInspectorPath": "ui/status-config.html",
"Controllers": [
"Keypad"
],
"States": [
{
"Image": "imgs/actions/status/away/away",
"TitleAlignment": "bottom"
}
]
},
{
"Name": "Set status as 'Busy'",
"UUID": "org.igox.busylight.status.busy",
"Icon": "imgs/actions/status/busy/busy",
"Tooltip": "Set status as 'Busy'",
"PropertyInspectorPath": "ui/status-config.html",
"Controllers": [
"Keypad"
],
"States": [
{
"Image": "imgs/actions/status/busy/busy",
"TitleAlignment": "bottom"
}
]
},
{
"Name": "Turn off the BusyLight",
"UUID": "org.igox.busylight.status.off",
"Icon": "imgs/actions/status/off/off",
"Tooltip": "Turn off the BusyLight",
"PropertyInspectorPath": "ui/status-config.html",
"Controllers": [
"Keypad"
],
"States": [
{
"Image": "imgs/actions/status/off/off",
"TitleAlignment": "bottom"
}
]
},
{
"Name": "Set brightness",
"UUID": "org.igox.busylight.brigthness.set",
"Icon": "imgs/actions/brightness/brightness",
"Tooltip": "Set LED brightness",
"PropertyInspectorPath": "ui/brightness-config.html",
"Controllers": [
"Keypad"
],
"States": [
{
"Image": "imgs/actions/brightness/brightness",
"TitleAlignment": "bottom"
}
]
},
{
"Name": "Set color",
"UUID": "org.igox.busylight.color.set",
"Icon": "imgs/actions/color/color",
"Tooltip": "Set BusyLight displayed color",
"PropertyInspectorPath": "ui/color-config.html",
"Controllers": [
"Keypad"
],
"States": [
{
"Image": "imgs/actions/color/color",
"TitleAlignment": "bottom"
}
]
}
],
"Category": "iGoX BusyLight",
"CategoryIcon": "imgs/plugin/marketplace",
"CodePath": "bin/plugin.js",
"Description": "Control your DIY BusyLight (https://github.com/igox/busylight) from your Stream Deck",
"Icon": "imgs/plugin/marketplace",
"SDKVersion": 2,
"Software": {
"MinimumVersion": "6.4"
},
"OS": [
{
"Platform": "mac",
"MinimumVersion": "10.15"
},
{
"Platform": "windows",
"MinimumVersion": "10"
}
],
"Nodejs": {
"Version": "20",
"Debug": "enabled"
},
"UUID": "org.igox.busylight"
}

View file

@ -0,0 +1,33 @@
<!DOCTYPE html>
<html>
<head lang="en">
<title>Configure your BusyLight</title>
<meta charset="utf-8" />
<script src="https://sdpi-components.dev/releases/v3/sdpi-components.js"></script>
<script>
function getGlobalSettings() {
const { streamDeckClient } = SDPIComponents;
const settings = streamDeckClient.getGlobalSettings();
return settings.url || 'http://busylight-esp32.local';
}
</script>
</head>
<body>
<!--
Learn more about property inspector components at https://sdpi-components.dev/docs/components
-->
<sdpi-item label="URL or IP">
<sdpi-textfield
setting="url"
placeholder="http://busylight-esp32.local"
global="true"
value="getGlobalSettings()">
</sdpi-textfield>
</sdpi-item>
<sdpi-item label="Color">
<sdpi-color
setting="color"></sdpi-color>
</sdpi-item>
</body>
</html>

View file

@ -14,9 +14,6 @@
</head>
<body>
<script>
</script>
<!--
Learn more about property inspector components at https://sdpi-components.dev/docs/components
-->

View file

@ -5,7 +5,7 @@ export class SetBrightness extends SingletonAction<BrightnessSettings> {
override async onKeyDown(ev: KeyDownEvent<BrightnessSettings>): Promise<void> {
streamDeck.logger.trace(`>>> Received KeyDownEvent. Settings: ${JSON.stringify(ev.payload.settings)} <<<`);
streamDeck.logger.debug(`>>> Received KeyDownEvent. Settings: ${JSON.stringify(ev.payload.settings)} <<<`);
const { settings } = ev.payload;
settings.brightness ??= 40;
@ -14,14 +14,14 @@ export class SetBrightness extends SingletonAction<BrightnessSettings> {
override onWillAppear(ev: WillAppearEvent<BrightnessSettings>): void | Promise<void> {
streamDeck.logger.trace(`>>> Received WillAppearEvent. Settings: ${JSON.stringify(ev.payload.settings)} <<<`);
streamDeck.logger.debug(`>>> Received WillAppearEvent. Settings: ${JSON.stringify(ev.payload.settings)} <<<`);
return ev.action.setTitle(`${ev.payload.settings.brightness ?? 40}%`);
}
override async onDidReceiveSettings(ev: DidReceiveSettingsEvent<BrightnessSettings>): Promise<void> {
streamDeck.logger.trace(`>>> Received onDidReceiveSettings. Settings: ${JSON.stringify(ev.payload.settings)} <<<`);
streamDeck.logger.debug(`>>> Received onDidReceiveSettings. Settings: ${JSON.stringify(ev.payload.settings)} <<<`);
const { settings } = ev.payload;
await ev.action.setSettings(settings);
@ -33,7 +33,7 @@ async function setBrightness(brightness: number) {
const settings = await streamDeck.settings.getGlobalSettings();
const url = settings.url;
streamDeck.logger.trace(`>>> Sending brightness: ${brightness} to ${url} <<<`);
streamDeck.logger.debug(`>>> Sending brightness: ${brightness} to ${url} <<<`);
fetch(`${url}/api/brightness`,
{
@ -44,7 +44,7 @@ async function setBrightness(brightness: number) {
body: JSON.stringify({"brightness": brightness/100})
})
.then(response => response.json())
.then(data => streamDeck.logger.trace(data));
.then(data => streamDeck.logger.debug(data));
}
type BrightnessSettings = {

View file

@ -0,0 +1,51 @@
import streamDeck, { action, JsonObject, KeyDownEvent, DidReceiveSettingsEvent, SingletonAction } from "@elgato/streamdeck";
@action({ UUID: "org.igox.busylight.color.set" })
export class SetColor extends SingletonAction {
override async onKeyDown(ev: KeyDownEvent<ColorSettings>): Promise<void> {
streamDeck.logger.debug(`>>> Received KeyDownEvent. Settings: ${JSON.stringify(ev.payload.settings)} <<<`);
const { settings } = ev.payload;
settings.color ??= '#FFFFFF';
setColor(hexToRgb(settings.color));
}
override async onDidReceiveSettings(ev: DidReceiveSettingsEvent<ColorSettings>): Promise<void> {
streamDeck.logger.debug(`>>> Received onDidReceiveSettings. Settings: ${JSON.stringify(ev.payload.settings)} <<<`);
const { settings } = ev.payload;
await ev.action.setSettings(settings);
}
}
function hexToRgb(hex: string): { r: number, g: number, b: number } {
const hexNumber = parseInt(hex.replace('#', ''), 16);
const r = (hexNumber >> 16) & 255;
const g = (hexNumber >> 8) & 255;
const b = hexNumber & 255;
return { r, g, b };
}
async function setColor(color: JsonObject) {
const settings = await streamDeck.settings.getGlobalSettings();
const url = settings.url;
streamDeck.logger.debug(`>>> Sending color: ${JSON.stringify({"r": color.r, "g": color.g, "b": color.b})} to ${url} <<<`);
fetch(`${url}/api/color`,
{
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({"r": color.r, "g": color.g, "b": color.b})
})
.then(response => response.json())
.then(data => streamDeck.logger.debug(data));
}
type ColorSettings = {
color?: string;
};

View file

@ -32,7 +32,7 @@ async function setStatus(status: string) {
const settings = await streamDeck.settings.getGlobalSettings();
const url = settings.url;
streamDeck.logger.trace(`>>> Sending status: ${status} to ${url} <<<`);
streamDeck.logger.debug(`>>> Sending status: ${status} to ${url} <<<`);
fetch(`${url}/api/status/${status}`,
{
@ -42,5 +42,5 @@ async function setStatus(status: string) {
}
})
.then(response => response.json())
.then(data => streamDeck.logger.trace(data));
.then(data => streamDeck.logger.debug(data));
}

View file

@ -3,6 +3,7 @@ import streamDeck, { LogLevel, SingletonAction, action, type DidReceiveSettingsE
//import { IncrementCounter } from "./actions/increment-counter";
import { SetStatusAvailable, SetStatusBusy, SetStatusAway, SetStatusOff } from "./actions/set-status";
import { SetBrightness } from "./actions/set-brightness";
import { SetColor } from "./actions/set-color";
// We can enable "trace" logging so that all messages between the Stream Deck, and the plugin are recorded. When storing sensitive information
streamDeck.logger.setLevel(LogLevel.INFO);
@ -13,6 +14,7 @@ streamDeck.actions.registerAction(new SetStatusBusy());
streamDeck.actions.registerAction(new SetStatusAway());
streamDeck.actions.registerAction(new SetStatusOff());
streamDeck.actions.registerAction(new SetBrightness());
streamDeck.actions.registerAction(new SetColor());
// Finally, connect to the Stream Deck.
streamDeck.connect();

Binary file not shown.

After

Width:  |  Height:  |  Size: 125 KiB