Initial commit
BIN
3D-files-to-print/Busylight v2.f3d
Normal file
BIN
3D-files-to-print/LED cover.stl
Normal file
BIN
3D-files-to-print/LED support bottom.stl
Normal file
BIN
3D-files-to-print/LED support top.stl
Normal file
11
3D-files-to-print/README.md
Normal file
@@ -0,0 +1,11 @@
|
||||
Loctite glue and hot glue gun are you friends :smile:
|
||||
|
||||
All files can be printed in PLA. \
|
||||
To have a nice light diffusion, I printed the `LED cover.stl` file in [_vase mode_](https://all3dp.com/2/cura-vase-mode-all-you-need-to-know/).
|
||||
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
BIN
3D-files-to-print/Raiser.stl
Normal file
BIN
3D-files-to-print/USB holder.stl
Normal file
BIN
3D-files-to-print/USB plate.stl
Normal file
BIN
3D-files-to-print/img/busylight-3d-build-1.jpg
Normal file
|
After Width: | Height: | Size: 194 KiB |
BIN
3D-files-to-print/img/busylight-3d-build-2.jpg
Normal file
|
After Width: | Height: | Size: 193 KiB |
BIN
3D-files-to-print/img/busylight-3d.jpg
Normal file
|
After Width: | Height: | Size: 57 KiB |
36
ESP32/boot.py
Normal file
@@ -0,0 +1,36 @@
|
||||
# This file is executed on every boot (including wake-boot from deepsleep)
|
||||
# It is executed before main.py
|
||||
import os, machine
|
||||
import network
|
||||
import gc
|
||||
|
||||
gc.collect()
|
||||
|
||||
|
||||
# --- WIFI Configuration ---
|
||||
SSID = '<YOUR WIFI SSID>' # Set the WIFI network SSID
|
||||
PASSWORD = '<YOUR WIFI PASSWORD>' # Set the WIFI network password
|
||||
network.country('<YOUR COUNTRY CODE>') # Set the country code for the WIFI (ISO 3166-1 Alpha-2 country code)
|
||||
network.hostname('igox-busylight') # Hostname that will identify this device on the network
|
||||
# --------------------------
|
||||
|
||||
# Function to connect to the WIFI
|
||||
def boot_wifi_connect():
|
||||
wlan = network.WLAN(network.STA_IF)
|
||||
if not wlan.isconnected():
|
||||
print('connecting to network...')
|
||||
wlan.active(True)
|
||||
wlan.connect(SSID, PASSWORD)
|
||||
while not wlan.isconnected():
|
||||
pass
|
||||
ip, mask, gateway, dns = wlan.ifconfig()
|
||||
|
||||
# Print the network configuration
|
||||
print('\nNetwork config:')
|
||||
print('- IP address: ' + ip)
|
||||
print('- Network mask: ' + mask)
|
||||
print('- Network gateway: ' + gateway)
|
||||
print('- DNS server: ' + dns + '\n')
|
||||
|
||||
# Connect to the WIFI when booting
|
||||
boot_wifi_connect()
|
||||
219
ESP32/main.py
Normal file
@@ -0,0 +1,219 @@
|
||||
from microdot import Microdot, send_file
|
||||
import machine, sys, neopixel, time
|
||||
|
||||
app = Microdot()
|
||||
|
||||
# Difine NeoPixel object
|
||||
nbPixels = 12*2
|
||||
pinPixelStrip = 16 # ESP32 D1 Mini
|
||||
neoPixelStrip = neopixel.NeoPixel(machine.Pin(pinPixelStrip), nbPixels)
|
||||
|
||||
# Define status colors
|
||||
statusColors = {
|
||||
'BUSY': (255,0,0), # red
|
||||
'AVAILABLE': (0,255,0), # green
|
||||
'AWAY': (246,190,0), # cyan
|
||||
'OFF': (0, 0, 0), # off
|
||||
'ON': (255, 255, 255) # white
|
||||
}
|
||||
|
||||
# Store BusyLight default global status
|
||||
blColor = statusColors.get('OFF')
|
||||
blStatus = 'off'
|
||||
blPreviousStatus='off'
|
||||
blBrightness = 0.1 # Adjust the brightness (0.0 - 1.0)
|
||||
|
||||
def __setColor(color):
|
||||
r, g , b = color
|
||||
r = int(r * blBrightness)
|
||||
g = int(g * blBrightness)
|
||||
b = int(b * blBrightness)
|
||||
return (r, g, b)
|
||||
|
||||
def __setBusyLightColor(color, brightness):
|
||||
global blBrightness
|
||||
blBrightness = brightness
|
||||
global blColor
|
||||
blColor = color
|
||||
neoPixelStrip.fill(__setColor(color))
|
||||
neoPixelStrip.write()
|
||||
|
||||
global blStatus
|
||||
blStatus = 'colored'
|
||||
|
||||
def __setBusyLightStatus(status):
|
||||
status = status.upper()
|
||||
color = statusColors.get(status)
|
||||
__setBusyLightColor(color, blBrightness)
|
||||
|
||||
global blStatus
|
||||
blStatus = status.lower()
|
||||
|
||||
# Microdot APP routes
|
||||
|
||||
@app.get('/static/<path:path>')
|
||||
async def staticRoutes(request, path):
|
||||
if '..' in path:
|
||||
# directory traversal is not allowed
|
||||
return {'error': '4040 Not found'}, 404
|
||||
return send_file('static/' + path)
|
||||
|
||||
@app.get('/')
|
||||
async def getIndex(request):
|
||||
return send_file('static/index.html')
|
||||
|
||||
@app.get('/api/brightness')
|
||||
async def getBrightness(request):
|
||||
return {'brightness': blBrightness}
|
||||
|
||||
@app.post('/api/brightness')
|
||||
async def setBrightness(request):
|
||||
brightness = request.json.get("brightness")
|
||||
|
||||
if brightness is None:
|
||||
return {'error': 'missing brightness parameter'}, 400
|
||||
|
||||
if type(brightness) is float \
|
||||
or type(brightness) is int:
|
||||
if brightness < 0 or brightness > 1:
|
||||
return {'error': 'brigthness out of bound (0.0 - 1.0)'}, 400
|
||||
else:
|
||||
return {'error': 'wrong brigthness type (float)'}, 400
|
||||
|
||||
# Save blStatus
|
||||
global blStatus
|
||||
status = blStatus
|
||||
|
||||
# Apply new brightness to current color
|
||||
color = blColor
|
||||
__setBusyLightColor(color, brightness)
|
||||
|
||||
# Restore global status
|
||||
blStatus = status
|
||||
|
||||
global blBrightness
|
||||
blBrightness = brightness
|
||||
|
||||
return {'brightness': blBrightness}
|
||||
|
||||
|
||||
@app.post('/api/color')
|
||||
async def setColor(request):
|
||||
|
||||
r = request.json.get("r")
|
||||
g = request.json.get("g")
|
||||
b = request.json.get("b")
|
||||
|
||||
if bool(r is None or g is None or b is None):
|
||||
return {'error': 'missing color'}, 400
|
||||
else:
|
||||
if type(r) is int \
|
||||
and type(g) is int \
|
||||
and type(b) is int:
|
||||
color = (r, g, b)
|
||||
else:
|
||||
return {'error': 'wrong color type (int)'}, 400
|
||||
|
||||
if (r < 0 or r > 255) \
|
||||
or (g < 0 or g > 255) \
|
||||
or (b < 0 or b > 255):
|
||||
return {'error': 'color out of bound (0 - 255)'}, 400
|
||||
|
||||
brightness = request.json.get("brightness")
|
||||
|
||||
if not brightness is None:
|
||||
if type(brightness) is float \
|
||||
or type(brightness) is int:
|
||||
if brightness < 0 or brightness > 1:
|
||||
return {'error': 'brightness out of bound (0.0 - 1.0)'}, 400
|
||||
else:
|
||||
return {'error': 'wrong brightness type (float)'}, 400
|
||||
__setBusyLightColor(color, brightness)
|
||||
|
||||
__setBusyLightColor(color, blBrightness)
|
||||
|
||||
return {'status': blStatus}
|
||||
|
||||
@app.route('/api/status/<status>', methods=['GET', 'POST'])
|
||||
async def setStatus(request, status):
|
||||
lStatus = status.lower()
|
||||
if lStatus == 'on':
|
||||
__setBusyLightStatus('ON')
|
||||
elif lStatus == 'off':
|
||||
__setBusyLightStatus('OFF')
|
||||
elif lStatus == 'available':
|
||||
__setBusyLightStatus('AVAILABLE')
|
||||
elif lStatus == 'away':
|
||||
__setBusyLightStatus('AWAY')
|
||||
elif lStatus == 'busy':
|
||||
__setBusyLightStatus('BUSY')
|
||||
else:
|
||||
return {'error': 'unknown /api/status/' + lStatus + ' route'}, 404
|
||||
|
||||
return {'status': blStatus}
|
||||
|
||||
@app.get('/api/color')
|
||||
async def getColor(request):
|
||||
r, g, b = neoPixelStrip.__getitem__(0)
|
||||
return {'color': {'r': r, 'g': g, 'b': b}}
|
||||
|
||||
@app.get('/api/status')
|
||||
async def getStatus(request):
|
||||
return {'status': blStatus}
|
||||
|
||||
@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}}
|
||||
|
||||
@app.post('/api/mutedeck-webhook')
|
||||
async def mutedeckWebhook(request):
|
||||
|
||||
if request.json.get('control') != 'system':
|
||||
if request.json.get('call') == 'active':
|
||||
if request.json.get('mute') == 'active':
|
||||
isMuted = True
|
||||
else:
|
||||
isMuted = False
|
||||
|
||||
if request.json.get('video') == 'active':
|
||||
isVideoOn = True
|
||||
else:
|
||||
isVideoOn = False
|
||||
|
||||
if isMuted:
|
||||
__setBusyLightStatus('away')
|
||||
else:
|
||||
__setBusyLightStatus('busy')
|
||||
else:
|
||||
__setBusyLightStatus('available')
|
||||
|
||||
return {'status': blStatus}
|
||||
|
||||
|
||||
@app.post('/shutdown')
|
||||
async def shutdown(request):
|
||||
request.app.shutdown()
|
||||
return 'The server is shutting down...'
|
||||
|
||||
# Startup effect
|
||||
def startUpSeq():
|
||||
print('Start seq begins')
|
||||
__setBusyLightStatus('OFF')
|
||||
time.sleep_ms(100)
|
||||
__setBusyLightStatus('BUSY')
|
||||
time.sleep_ms(200)
|
||||
__setBusyLightStatus('AWAY')
|
||||
time.sleep_ms(300)
|
||||
__setBusyLightStatus('AVAILABLE')
|
||||
time.sleep_ms(500)
|
||||
__setBusyLightStatus('OFF')
|
||||
print('Start seq is ended')
|
||||
__setBusyLightColor(statusColors.get('OFF'), 0.1)
|
||||
|
||||
startUpSeq()
|
||||
|
||||
# Start API webserver
|
||||
if __name__ == '__main__':
|
||||
app.run(port=80, debug=True)
|
||||
289
ESP32/static/index.html
Normal file
@@ -0,0 +1,289 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>BusyLight</title>
|
||||
<script src="static/libs/busylight-api.js"></script>
|
||||
<script src="static/libs/jscolor.min.js"></script>
|
||||
<style>
|
||||
/* General Reset */
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Arial', sans-serif;
|
||||
background: linear-gradient(135deg, #1a1a2e, #16213e);
|
||||
color: #ffffff;
|
||||
text-align: center;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* Glassmorphism Container */
|
||||
section {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
backdrop-filter: blur(10px);
|
||||
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||
padding: 30px;
|
||||
border-radius: 20px;
|
||||
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
|
||||
width: 90%;
|
||||
max-width: 500px;
|
||||
animation: fadeIn 0.5s ease-in-out;
|
||||
}
|
||||
|
||||
@keyframes fadeIn {
|
||||
from { opacity: 0; transform: translateY(-20px); }
|
||||
to { opacity: 1; transform: translateY(0); }
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 28px;
|
||||
margin-bottom: 30px;
|
||||
color: #ffffff;
|
||||
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
/* Radio Buttons */
|
||||
div {
|
||||
margin: 20px 0;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 15px;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 12px;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
div:hover {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
label {
|
||||
font-size: 20px;
|
||||
font-weight: 500;
|
||||
margin-right: 15px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
input[type="radio"] {
|
||||
appearance: none;
|
||||
width: 25px;
|
||||
height: 25px;
|
||||
border-radius: 50%;
|
||||
border: 3px solid #ffffff;
|
||||
transition: all 0.3s ease;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
input[type="radio"]:checked {
|
||||
background: #4CAF50;
|
||||
border-color: #4CAF50;
|
||||
box-shadow: 0 0 10px rgba(76, 175, 80, 0.7);
|
||||
}
|
||||
|
||||
/* Color Picker Button */
|
||||
#colorPicker {
|
||||
background: linear-gradient(135deg, #007bff, #0056b3);
|
||||
border: none;
|
||||
padding: 15px 30px;
|
||||
color: white;
|
||||
font-size: 18px;
|
||||
border-radius: 12px;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
box-shadow: 0 4px 12px rgba(0, 123, 255, 0.3);
|
||||
}
|
||||
|
||||
#colorPicker:hover {
|
||||
background: linear-gradient(135deg, #0056b3, #003d80);
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 6px 16px rgba(0, 123, 255, 0.4);
|
||||
}
|
||||
|
||||
/* Brightness Slider */
|
||||
input[type="range"] {
|
||||
width: 100%;
|
||||
cursor: pointer;
|
||||
-webkit-appearance: none;
|
||||
background: linear-gradient(135deg, #4CAF50, #45a049);
|
||||
height: 10px;
|
||||
border-radius: 5px;
|
||||
outline: none;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
input[type="range"]::-webkit-slider-thumb {
|
||||
-webkit-appearance: none;
|
||||
width: 25px;
|
||||
height: 25px;
|
||||
background: #ffffff;
|
||||
border-radius: 50%;
|
||||
cursor: pointer;
|
||||
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
input[type="range"]:hover::-webkit-slider-thumb {
|
||||
transform: scale(1.1);
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
|
||||
}
|
||||
|
||||
/* Responsive Design */
|
||||
@media (max-width: 600px) {
|
||||
section {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
label {
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
input[type="radio"] {
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
}
|
||||
|
||||
#colorPicker {
|
||||
padding: 12px 24px;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
input[type="range"]::-webkit-slider-thumb {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body onload="initForm()">
|
||||
<section>
|
||||
<h1>BusyLight Status</h1>
|
||||
<div>
|
||||
<input type="radio" name="status" id="off" value="off" onclick="putStatus(this.value)" />
|
||||
<label for="off">OFF</label>
|
||||
</div>
|
||||
<div>
|
||||
<input type="radio" name="status" id="busy" value="busy" onclick="putStatus(this.value)" />
|
||||
<label for="busy">Busy</label>
|
||||
</div>
|
||||
<div>
|
||||
<input type="radio" name="status" id="available" value="available" onclick="putStatus(this.value)" />
|
||||
<label for="available">Available</label>
|
||||
</div>
|
||||
<div>
|
||||
<input type="radio" name="status" id="away" value="away" onclick="putStatus(this.value)" />
|
||||
<label for="away">Away</label>
|
||||
</div>
|
||||
<div>
|
||||
<input type="radio" name="status" id="colored" value="colored" onclick="openColorPicker()" />
|
||||
<label for="colored">Colored</label>
|
||||
<button id="colorPicker">Pick color</button>
|
||||
</div>
|
||||
<div>
|
||||
<input type="range" id="brightness" name="brightness" min="0" max="100" step="1" onchange="putBrightness(this.value)"/>
|
||||
<label for="brightness">Brightness</label>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<script>
|
||||
jscolor.presets.rgb = {
|
||||
format: 'rgb',
|
||||
alphaChannel: false
|
||||
};
|
||||
|
||||
var colorPickerOpts = {};
|
||||
colorPickerOpts["preset"] = "rgb";
|
||||
colorPickerOpts["format"] = "rgb";
|
||||
colorPickerOpts["alphaChannel"] = false;
|
||||
colorPickerOpts["onChange"] = "putColor(this)";
|
||||
var colorPicker = new JSColor("#colorPicker", colorPickerOpts);
|
||||
|
||||
async function initForm() {
|
||||
var s = await getStatus();
|
||||
var c = await getColor();
|
||||
var b = await getBrightness();
|
||||
|
||||
var statusRadio;
|
||||
switch (s.status) {
|
||||
case 'off':
|
||||
statusRadio = document.getElementById('off');
|
||||
break;
|
||||
case 'busy':
|
||||
statusRadio = document.getElementById('busy');
|
||||
break;
|
||||
case 'available':
|
||||
statusRadio = document.getElementById('available');
|
||||
break;
|
||||
case 'away':
|
||||
statusRadio = document.getElementById('away');
|
||||
break;
|
||||
case 'colored':
|
||||
statusRadio = document.getElementById('colored');
|
||||
colorPicker.fromString('rgb(' + c.color.r + ',' + c.color.g + ',' + c.color.b + ')');
|
||||
break;
|
||||
}
|
||||
statusRadio.checked = true;
|
||||
|
||||
brightnessRange = document.getElementById('brightness');
|
||||
brightnessRange.value = b.brightness * 100;
|
||||
|
||||
setColorPickerColor(s.status);
|
||||
}
|
||||
|
||||
function openColorPicker() {
|
||||
colorPicker.show();
|
||||
}
|
||||
|
||||
async function putColor(picker) {
|
||||
var color = {};
|
||||
color.r = Math.round(picker.channel('R'));
|
||||
color.g = Math.round(picker.channel('G'));
|
||||
color.b = Math.round(picker.channel('B'));
|
||||
var s = await setColor(color);
|
||||
statusRadio = document.getElementById('colored');
|
||||
statusRadio.checked = true;
|
||||
}
|
||||
|
||||
async function putStatus(status) {
|
||||
var s = await setStatus(status);
|
||||
setColorPickerColor(status);
|
||||
}
|
||||
|
||||
function setColorPickerColor(status) {
|
||||
switch (status) {
|
||||
case 'off':
|
||||
colorPicker.fromString('rgb(0,0,0)');
|
||||
break;
|
||||
case 'busy':
|
||||
colorPicker.fromString('rgb(255,0,0)');
|
||||
break;
|
||||
case 'available':
|
||||
colorPicker.fromString('rgb(0,255,0)');
|
||||
break;
|
||||
case 'away':
|
||||
colorPicker.fromString('rgb(246,190,0)');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
async function putBrightness(value) {
|
||||
var brightness = {};
|
||||
brightness.brightness = value/100;
|
||||
var b = await setBrightness(brightness);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
70
ESP32/static/libs/busylight-api.js
Normal file
@@ -0,0 +1,70 @@
|
||||
async function setStatus(status = '') {
|
||||
// Les options par défaut sont indiquées par *
|
||||
const response = await fetch(`/api/status/${status}`, {
|
||||
method: "POST", // *GET, POST, PUT, DELETE, etc.
|
||||
cache: "no-cache", // *default, no-cache, reload, force-cache, only-if-cached
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
});
|
||||
return response.json(); // transforme la réponse JSON reçue en objet JavaScript natif
|
||||
}
|
||||
|
||||
async function getStatus() {
|
||||
// Les options par défaut sont indiquées par *
|
||||
const response = await fetch(`/api/status`, {
|
||||
method: "GET", // *GET, POST, PUT, DELETE, etc.
|
||||
cache: "no-cache" // *default, no-cache, reload, force-cache, only-if-cached
|
||||
});
|
||||
return response.json(); // transforme la réponse JSON reçue en objet JavaScript natif
|
||||
}
|
||||
|
||||
async function setColor(color = {}) {
|
||||
// Les options par défaut sont indiquées par *
|
||||
const response = await fetch(`/api/color`, {
|
||||
method: "POST", // *GET, POST, PUT, DELETE, etc.
|
||||
cache: "no-cache", // *default, no-cache, reload, force-cache, only-if-cached
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify(color) // le type utilisé pour le corps doit correspondre à l'en-tête "Content-Type"
|
||||
});
|
||||
return response.json(); // transforme la réponse JSON reçue en objet JavaScript natif
|
||||
}
|
||||
|
||||
async function getColor() {
|
||||
// Les options par défaut sont indiquées par *
|
||||
const response = await fetch(`/api/color`, {
|
||||
method: "GET", // *GET, POST, PUT, DELETE, etc.
|
||||
cache: "no-cache", // *default, no-cache, reload, force-cache, only-if-cached
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
});
|
||||
return response.json(); // transforme la réponse JSON reçue en objet JavaScript natif
|
||||
}
|
||||
|
||||
async function setBrightness(brightness = {}) {
|
||||
// Les options par défaut sont indiquées par *
|
||||
const response = await fetch(`/api/brightness`, {
|
||||
method: "POST", // *GET, POST, PUT, DELETE, etc.
|
||||
cache: "no-cache", // *default, no-cache, reload, force-cache, only-if-cached
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify(brightness) // le type utilisé pour le corps doit correspondre à l'en-tête "Content-Type"
|
||||
});
|
||||
return response.json(); // transforme la réponse JSON reçue en objet JavaScript natif
|
||||
}
|
||||
|
||||
async function getBrightness() {
|
||||
// Les options par défaut sont indiquées par *
|
||||
const response = await fetch(`/api/brightness`, {
|
||||
method: "GET", // *GET, POST, PUT, DELETE, etc.
|
||||
cache: "no-cache", // *default, no-cache, reload, force-cache, only-if-cached
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
});
|
||||
return response.json(); // transforme la réponse JSON reçue en objet JavaScript natif
|
||||
}
|
||||
1
ESP32/static/libs/jscolor.min.js
vendored
Normal file
162
README.md
@@ -1,2 +1,162 @@
|
||||
# busylight
|
||||
# Table of Content
|
||||
|
||||
1. [What's this project?](#whats-this-project)
|
||||
2. [Web UI](#web-ui)
|
||||
3. [Stream Deck plug-in](#stream-deck-plug-in)
|
||||
4. [BusyLight API](#busylight-api)
|
||||
5. [MuteDeck integration](#mutedeck-integration)
|
||||
6. [Electronic parts](#electronic-parts)
|
||||
7. [Firmware installation](#firmware-installation)
|
||||
8. [3D files - Enclosure](#3d-files---enclosure)
|
||||
9. [Wiring / Soldering](#wiring--soldering)
|
||||
10. [Tools & libs](#tools--libs)
|
||||
|
||||
|
||||
# What's this project?
|
||||
|
||||
**Let people know if they can bother you with light signals!**
|
||||
|
||||
A cheap, simple to build, nice looking and portable DIY **Busy Light**.
|
||||
|
||||
It comes with a with a simplistic but neat **Web UI** and a simple (but hopefully convenient) **Rest API**.
|
||||
|
||||
| Controlled by Stream Deck with REST API | Light roll |
|
||||
|-------------------------------------------------|---------------------------------------|
|
||||
|  |  |
|
||||
|
||||

|
||||
|
||||
# Web UI
|
||||
A very simplistic but neat UI is available on port `80` (thanks @nicolaeser). \
|
||||
Default hostname is `igox-busylight`.
|
||||
|
||||
You can try to reach the web UI @ [http://igox-busylight.local](http://igox-busylight.local).
|
||||
|
||||
| What an neat UI ! :smile: |
|
||||
|---------------------------|
|
||||
|  |
|
||||
|
||||
# Stream Deck plug-in
|
||||
You can download a Stream Deck plugin to control your BusyLight:
|
||||
|
||||
[](https://marketplace.elgato.com/product/igox-busylight-7448a0be-6dd6-4711-ba0d-86c52b9075b9)
|
||||
|
||||
|
||||
Or directly from [here](streamdeck-plugin/README.md).
|
||||
|
||||
# BusyLight API
|
||||
## 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 displyed 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/debug | GET | n/a | Retreive the full BusyLight status. |
|
||||
|
||||
## JSON objects
|
||||
### `color` object
|
||||
|
||||
```
|
||||
{
|
||||
"r": 255,
|
||||
"g": 0,
|
||||
"b": 127,
|
||||
"brightness": 0.5
|
||||
}
|
||||
```
|
||||
`r`: RED color | integer | [0 .. 255]\
|
||||
`g`: GREEN color | integer | [0 .. 255]\
|
||||
`b`: BLUE color | integer | [0 .. 255]\
|
||||
`brightness`: LED brighness (optional) | float | [0.0 .. 1.0]
|
||||
|
||||
### `brightness` object
|
||||
|
||||
```
|
||||
{
|
||||
"brightness": 0.5
|
||||
}
|
||||
```
|
||||
`brightness`: LED brighness | float | [0.0 .. 1.0]
|
||||
|
||||
### `status` object
|
||||
|
||||
```
|
||||
{
|
||||
"status": "<STATUS>"
|
||||
}
|
||||
```
|
||||
|
||||
\<STATUS\> : `on` | `off` | `available` | `away` | `busy` | `colored`
|
||||
|
||||
|
||||
# MuteDeck integration
|
||||
The `POST api/mutedeck-webhook` endpoint aims to collect [MuteDeck](https://mutedeck.com/help/docs/notifications.html#enabling-the-webhook-integration) webhook callbacks.
|
||||
|
||||
It will automatically switch to the BusyLight in:
|
||||
- busy mode (Red color) when entering a meeting with Mic `ON` **and** camera `ON`.
|
||||
- away mode (Yellow color) when entering a meeting with Mic `OFF` **and** camera `ON`.
|
||||
- away mode (Yellow color) if the mic is muted during a meeting.
|
||||
- available mode (Green color) when exiting/closing a meeting.
|
||||
|
||||
| MuteDeck Configuration |
|
||||
|---------------------------------------------------|
|
||||
|  |
|
||||
|
||||
# Electronic parts
|
||||
| Parts | Links (Amazon - not affiliated) |
|
||||
|-------------------------|-----------------------------------------------------------------------------------------------------------|
|
||||
| Micro-controler | [D1 ESP32 Mini NodeMCU](https://www.amazon.fr/dp/B0CDXB48DZ) - USB C version |
|
||||
| Led rings (x2) | [AZDelivery 5 x LED Ring 5V RGB compatible avec WS2812B 12-Bit 38mm](https://www.amazon.fr/dp/B07V1GGKHV) |
|
||||
| Battery | [Anker PowerCore 5000mAh](https://www.amazon.fr/dp/B01CU1EC6Y) |
|
||||
| USB A to USB C adapter | [USB A to USB C adapter](https://www.amazon.fr/dp/B0BYK917NM) |
|
||||
|
||||
# Firmware installation
|
||||
|
||||
**(1)** Flash your ESP32 with [Micropython](https://micropython.org/download/ESP32_GENERIC/).
|
||||
|
||||
**(2)** Install [microdot](https://microdot.readthedocs.io/en/latest/index.html) library on the ESP32. This can easily be done using [Thonny](https://thonny.org):
|
||||
|
||||
| Tools > Manage plug-ins | lib selection |
|
||||
|-------------------------------|-------------------------------------|
|
||||
|  |  |
|
||||
|
||||
**(3)** Edit the `WIFI Configuration` section in the [boot.py](ESP32/boot.py) file.
|
||||
|
||||
**(4)** Copy the content of [ESP32](ESP32/) folder with the modified `boot.py` file to the root of your ESP32 file system. Again, can easily be done using [Thonny](https://thonny.org):
|
||||
|
||||

|
||||
|
||||
**Done!**
|
||||
|
||||
# 3D files - Enclosure
|
||||
|
||||
All the required 3D files (STLs and f3d project) to 3D print the enclosure are available in the [3D-files-to-print](3D-files-to-print/) folder.
|
||||
|
||||

|
||||
|
||||
# Wiring / Soldering
|
||||
|
||||

|
||||
|
||||
You can see a final assembly image [here](3D-files-to-print/README.md).
|
||||
|
||||
# Tools & libs
|
||||
|
||||
## Thonny
|
||||
https://thonny.org
|
||||
|
||||
## Micropython
|
||||
https://micropython.org
|
||||
|
||||
## Microdot
|
||||
https://microdot.readthedocs.io/en/latest/index.html
|
||||
|
||||
## JSColor
|
||||
https://jscolor.com
|
||||
|
||||
BIN
img/busylight-showoff.mp4
Normal file
BIN
img/busylight.gif
Normal file
|
After Width: | Height: | Size: 150 KiB |
BIN
img/busylight.jpg
Normal file
|
After Width: | Height: | Size: 108 KiB |
BIN
img/elgato-marketplace.png
Normal file
|
After Width: | Height: | Size: 3.0 KiB |
BIN
img/file-copy.png
Normal file
|
After Width: | Height: | Size: 154 KiB |
BIN
img/lib-install.png
Normal file
|
After Width: | Height: | Size: 195 KiB |
BIN
img/lib-menu.png
Normal file
|
After Width: | Height: | Size: 109 KiB |
BIN
img/mutedeck-webhook-conf.png
Normal file
|
After Width: | Height: | Size: 61 KiB |
BIN
img/web-ui.png
Normal file
|
After Width: | Height: | Size: 126 KiB |
BIN
img/wiring-soldering.png
Normal file
|
After Width: | Height: | Size: 2.2 MiB |
103
streamdeck-plugin/README.md
Normal file
@@ -0,0 +1,103 @@
|
||||
# BusyLight Stream Deck plugin - Release notes
|
||||
|
||||
## Version 0.3.1.0 (2024-01-06)
|
||||
|
||||
### Download
|
||||
|
||||
[org.igox.busylight.v0.3.1.0.streamDeckPlugin](download/org.igox.busylight.v0.3.1.0.streamDeckPlugin)
|
||||
|
||||
### Features
|
||||
|
||||
- None added
|
||||
|
||||
### Enhancements
|
||||
|
||||
- Add colored button for "Set color" action.
|
||||
- Add colored button for "Set brightness" action.
|
||||
- Update plugin and plugin category icons
|
||||
|
||||
### Fixes
|
||||
|
||||
- None.
|
||||
|
||||
### Bugs & known limitations
|
||||
|
||||
- None known at publication time.
|
||||
|
||||
### Screenshot
|
||||
|
||||

|
||||
|
||||
## Version 0.3.0.0 (2024-01-06)
|
||||
|
||||
### Download
|
||||
|
||||
[org.igox.busylight.v0.3.0.0.streamDeckPlugin](download/org.igox.busylight.v0.3.0.0.streamDeckPlugin)
|
||||
|
||||
### Features
|
||||
|
||||
- None added
|
||||
|
||||
### Enhancements
|
||||
|
||||
- Rework icons to comply with plugin guidelines for Elgato Marketplace
|
||||
- Combine the 3 "status" actions into a single action and having the status be selected with a dropdown
|
||||
|
||||
### Fixes
|
||||
|
||||
- None.
|
||||
|
||||
### Bugs & known limitations
|
||||
|
||||
- None known at publication time.
|
||||
|
||||
### Screenshot
|
||||
|
||||

|
||||
|
||||
## 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
|
||||
|
||||

|
||||
|
||||
|
||||
## Version 0.1.0.0 (2024-12-28)
|
||||
|
||||
### Download
|
||||
|
||||
[org.igox.busylight.v0.1.0.0.streamDeckPlugin](download/org.igox.busylight.v0.1.0.0.streamDeckPlugin)
|
||||
|
||||
### Features
|
||||
|
||||
- Quick action buttons to set the BusyLight status (Available: green, Away: yellow, Busy: red).
|
||||
- Quick action button to turn off the BusyLight.
|
||||
- Button to set the BusyLight brightness.
|
||||
|
||||
### Fixes
|
||||
|
||||
- None: initial version of the plugin.
|
||||
|
||||
### Bugs & known limitations
|
||||
|
||||
- None known at publication time.
|
||||
|
||||
### Screenshot
|
||||
|
||||

|
||||
6
streamdeck-plugin/busylight/.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
# Node.js
|
||||
node_modules/
|
||||
|
||||
# Stream Deck files
|
||||
*.sdPlugin/bin
|
||||
*.sdPlugin/logs
|
||||
20
streamdeck-plugin/busylight/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Attach to Plugin",
|
||||
"type": "node",
|
||||
"request": "attach",
|
||||
"processId": "${command:PickProcess}",
|
||||
"outFiles": [
|
||||
"${workspaceFolder}/bin/**/*.js"
|
||||
],
|
||||
"resolveSourceMapLocations": [
|
||||
"${workspaceFolder}/**"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
17
streamdeck-plugin/busylight/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
/* JSON schemas */
|
||||
"json.schemas": [
|
||||
{
|
||||
"fileMatch": [
|
||||
"**/manifest.json"
|
||||
],
|
||||
"url": "https://schemas.elgato.com/streamdeck/plugins/manifest.json"
|
||||
},
|
||||
{
|
||||
"fileMatch": [
|
||||
"**/layouts/*.json"
|
||||
],
|
||||
"url": "https://schemas.elgato.com/streamdeck/plugins/layout.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
After Width: | Height: | Size: 101 KiB |
|
After Width: | Height: | Size: 101 KiB |
|
After Width: | Height: | Size: 101 KiB |
|
After Width: | Height: | Size: 101 KiB |
|
After Width: | Height: | Size: 224 KiB |
|
After Width: | Height: | Size: 224 KiB |
|
After Width: | Height: | Size: 101 KiB |
|
After Width: | Height: | Size: 101 KiB |
|
After Width: | Height: | Size: 573 KiB |
|
After Width: | Height: | Size: 573 KiB |
|
After Width: | Height: | Size: 99 KiB |
|
After Width: | Height: | Size: 99 KiB |
|
After Width: | Height: | Size: 99 KiB |
|
After Width: | Height: | Size: 99 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 575 KiB |
|
After Width: | Height: | Size: 575 KiB |
|
After Width: | Height: | Size: 33 KiB |
|
After Width: | Height: | Size: 33 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 45 KiB |
|
After Width: | Height: | Size: 108 KiB |
|
After Width: | Height: | Size: 108 KiB |
@@ -0,0 +1,80 @@
|
||||
{
|
||||
"Name": "iGoX BusyLight",
|
||||
"Version": "0.3.1.0",
|
||||
"Author": "iGoX",
|
||||
"$schema": "https://schemas.elgato.com/streamdeck/plugins/manifest.json",
|
||||
"Actions": [
|
||||
{
|
||||
"Name": "Set BusyLight status",
|
||||
"UUID": "org.igox.busylight.status.set",
|
||||
"Icon": "imgs/actions/icons/status/status",
|
||||
"Tooltip": "Set BusyLight status",
|
||||
"PropertyInspectorPath": "ui/status-config.html",
|
||||
"Controllers": [
|
||||
"Keypad"
|
||||
],
|
||||
"States": [
|
||||
{
|
||||
"Image": "imgs/actions/icons/status/status",
|
||||
"TitleAlignment": "bottom"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Name": "Set brightness",
|
||||
"UUID": "org.igox.busylight.brigthness.set",
|
||||
"Icon": "imgs/actions/icons/brightness/brightness",
|
||||
"Tooltip": "Set LED brightness",
|
||||
"PropertyInspectorPath": "ui/brightness-config.html",
|
||||
"Controllers": [
|
||||
"Keypad"
|
||||
],
|
||||
"States": [
|
||||
{
|
||||
"Image": "imgs/actions/icons/brightness/brightness",
|
||||
"TitleAlignment": "bottom"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Name": "Set color",
|
||||
"UUID": "org.igox.busylight.color.set",
|
||||
"Icon": "imgs/actions/icons/color/color",
|
||||
"Tooltip": "Set BusyLight displayed color",
|
||||
"PropertyInspectorPath": "ui/color-config.html",
|
||||
"Controllers": [
|
||||
"Keypad"
|
||||
],
|
||||
"States": [
|
||||
{
|
||||
"Image": "imgs/actions/icons/color/color",
|
||||
"TitleAlignment": "bottom"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"Category": "iGoX BusyLight",
|
||||
"CategoryIcon": "imgs/plugin/category-icon",
|
||||
"CodePath": "bin/plugin.js",
|
||||
"Description": "Control your DIY BusyLight (https://github.com/igox/busylight) from your Stream Deck",
|
||||
"Icon": "imgs/plugin/icon",
|
||||
"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"
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<!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>
|
||||
<script>
|
||||
|
||||
</script>
|
||||
<!--
|
||||
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="Brightness">
|
||||
<sdpi-range
|
||||
setting="brightness"
|
||||
min="10"
|
||||
max="100"
|
||||
default="40"
|
||||
value="40"
|
||||
step="5"
|
||||
showlabels="true">
|
||||
<span slot="min">10%</span>
|
||||
<span slot="max">100%</span>
|
||||
</sdpi-range>
|
||||
</sdpi-item>
|
||||
</body>
|
||||
</html>
|
||||
@@ -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>
|
||||
@@ -0,0 +1,38 @@
|
||||
<!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="Status">
|
||||
<sdpi-select setting="status" placeholder="Please choose a status">
|
||||
<option value="available">Available</option>
|
||||
<option value="away">Away</option>
|
||||
<option value="busy">Busy</option>
|
||||
<option value="on">On</option>
|
||||
<option value="off">Off</option>
|
||||
</sdpi-select>
|
||||
</sdpi-item>
|
||||
</body>
|
||||
</html>
|
||||
2395
streamdeck-plugin/busylight/package-lock.json
generated
Normal file
22
streamdeck-plugin/busylight/package.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"scripts": {
|
||||
"build": "rollup -c",
|
||||
"watch": "rollup -c -w --watch.onEnd=\"streamdeck restart org.igox.busylight\""
|
||||
},
|
||||
"type": "module",
|
||||
"devDependencies": {
|
||||
"@elgato/cli": "^1.1.0",
|
||||
"@rollup/plugin-commonjs": "^28.0.0",
|
||||
"@rollup/plugin-node-resolve": "^15.2.2",
|
||||
"@rollup/plugin-terser": "^0.4.4",
|
||||
"@rollup/plugin-typescript": "^12.1.0",
|
||||
"@tsconfig/node20": "^20.1.2",
|
||||
"@types/node": "~20.15.0",
|
||||
"rollup": "^4.0.2",
|
||||
"tslib": "^2.6.2",
|
||||
"typescript": "^5.2.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@elgato/streamdeck": "^1.0.0"
|
||||
}
|
||||
}
|
||||
49
streamdeck-plugin/busylight/rollup.config.mjs
Normal file
@@ -0,0 +1,49 @@
|
||||
import commonjs from "@rollup/plugin-commonjs";
|
||||
import nodeResolve from "@rollup/plugin-node-resolve";
|
||||
import terser from "@rollup/plugin-terser";
|
||||
import typescript from "@rollup/plugin-typescript";
|
||||
import path from "node:path";
|
||||
import url from "node:url";
|
||||
|
||||
const isWatching = !!process.env.ROLLUP_WATCH;
|
||||
const sdPlugin = "org.igox.busylight.sdPlugin";
|
||||
|
||||
/**
|
||||
* @type {import('rollup').RollupOptions}
|
||||
*/
|
||||
const config = {
|
||||
input: "src/plugin.ts",
|
||||
output: {
|
||||
file: `${sdPlugin}/bin/plugin.js`,
|
||||
sourcemap: isWatching,
|
||||
sourcemapPathTransform: (relativeSourcePath, sourcemapPath) => {
|
||||
return url.pathToFileURL(path.resolve(path.dirname(sourcemapPath), relativeSourcePath)).href;
|
||||
}
|
||||
},
|
||||
plugins: [
|
||||
{
|
||||
name: "watch-externals",
|
||||
buildStart: function () {
|
||||
this.addWatchFile(`${sdPlugin}/manifest.json`);
|
||||
},
|
||||
},
|
||||
typescript({
|
||||
mapRoot: isWatching ? "./" : undefined
|
||||
}),
|
||||
nodeResolve({
|
||||
browser: false,
|
||||
exportConditions: ["node"],
|
||||
preferBuiltins: true
|
||||
}),
|
||||
commonjs(),
|
||||
!isWatching && terser(),
|
||||
{
|
||||
name: "emit-module-package-file",
|
||||
generateBundle() {
|
||||
this.emitFile({ fileName: "package.json", source: `{ "type": "module" }`, type: "asset" });
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
export default config;
|
||||
58
streamdeck-plugin/busylight/src/actions/set-brightness.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import streamDeck, { action, DidReceiveSettingsEvent, WillAppearEvent, KeyDownEvent, PropertyInspectorDidAppearEvent, SingletonAction } from "@elgato/streamdeck";
|
||||
|
||||
@action({ UUID: "org.igox.busylight.brigthness.set" })
|
||||
export class SetBrightness extends SingletonAction<BrightnessSettings> {
|
||||
|
||||
override async onKeyDown(ev: KeyDownEvent<BrightnessSettings>): Promise<void> {
|
||||
|
||||
streamDeck.logger.debug(`>>> Received KeyDownEvent. Settings: ${JSON.stringify(ev.payload.settings)} <<<`);
|
||||
|
||||
const { settings } = ev.payload;
|
||||
settings.brightness ??= 40;
|
||||
setBrightness(settings.brightness);
|
||||
}
|
||||
|
||||
override onWillAppear(ev: WillAppearEvent<BrightnessSettings>): void | Promise<void> {
|
||||
|
||||
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.debug(`>>> Received onDidReceiveSettings. Settings: ${JSON.stringify(ev.payload.settings)} <<<`);
|
||||
|
||||
const { settings } = ev.payload;
|
||||
await ev.action.setSettings(settings);
|
||||
await ev.action.setTitle(`${settings.brightness}%`);
|
||||
}
|
||||
|
||||
override async onPropertyInspectorDidAppear(ev: PropertyInspectorDidAppearEvent<BrightnessSettings>): Promise<void> {
|
||||
streamDeck.logger.debug(`>>> Received onPropertyInspectorDidAppear. Setting action icon <<<`);
|
||||
|
||||
await ev.action.setImage(`imgs/actions/buttons/brigthness/brigthness.png`);
|
||||
}
|
||||
}
|
||||
|
||||
async function setBrightness(brightness: number) {
|
||||
const settings = await streamDeck.settings.getGlobalSettings();
|
||||
const url = settings.url;
|
||||
|
||||
streamDeck.logger.debug(`>>> Sending brightness: ${brightness} to ${url} <<<`);
|
||||
|
||||
fetch(`${url}/api/brightness`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify({"brightness": brightness/100})
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => streamDeck.logger.debug(data));
|
||||
}
|
||||
|
||||
type BrightnessSettings = {
|
||||
brightness?: number;
|
||||
};
|
||||
57
streamdeck-plugin/busylight/src/actions/set-color.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import streamDeck, { action, JsonObject, KeyDownEvent, DidReceiveSettingsEvent, PropertyInspectorDidAppearEvent, 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);
|
||||
}
|
||||
|
||||
override async onPropertyInspectorDidAppear(ev: PropertyInspectorDidAppearEvent<ColorSettings>): Promise<void> {
|
||||
streamDeck.logger.debug(`>>> Color button property inspector diplayed! <<<`);
|
||||
|
||||
await ev.action.setImage(`imgs/actions/buttons/colored/colored.png`);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
};
|
||||
40
streamdeck-plugin/busylight/src/actions/set-status.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import streamDeck, { action, KeyDownEvent, SingletonAction, DidReceiveSettingsEvent } from "@elgato/streamdeck";
|
||||
|
||||
@action({ UUID: "org.igox.busylight.status.set" })
|
||||
export class SetStatus extends SingletonAction {
|
||||
override async onKeyDown(ev: KeyDownEvent<statusSettings>): Promise<void> {
|
||||
const { settings } = ev.payload;
|
||||
settings.status ??= 'available';
|
||||
setStatus(settings.status);
|
||||
}
|
||||
|
||||
override async onDidReceiveSettings(ev: DidReceiveSettingsEvent<statusSettings>): Promise<void> {
|
||||
const { settings } = ev.payload;
|
||||
let status = settings.status;
|
||||
streamDeck.logger.debug(`>>> Config status changed to: ${status} <<<`);
|
||||
|
||||
await ev.action.setImage(`imgs/actions/buttons/${status}/${status}.png`);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
async function setStatus(status: string) {
|
||||
const settings = await streamDeck.settings.getGlobalSettings();
|
||||
const url = settings.url;
|
||||
|
||||
streamDeck.logger.debug(`>>> Sending status: ${status} to ${url} <<<`);
|
||||
|
||||
fetch(`${url}/api/status/${status}`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => streamDeck.logger.debug(data));
|
||||
}
|
||||
|
||||
type statusSettings = {
|
||||
status?: string;
|
||||
};
|
||||
16
streamdeck-plugin/busylight/src/plugin.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import streamDeck, { LogLevel, SingletonAction, action, type DidReceiveSettingsEvent } from "@elgato/streamdeck";
|
||||
|
||||
import { SetStatus} 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);
|
||||
|
||||
// Register the actions.
|
||||
streamDeck.actions.registerAction(new SetStatus());
|
||||
streamDeck.actions.registerAction(new SetBrightness());
|
||||
streamDeck.actions.registerAction(new SetColor());
|
||||
|
||||
// Finally, connect to the Stream Deck.
|
||||
streamDeck.connect();
|
||||
17
streamdeck-plugin/busylight/tsconfig.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"extends": "@tsconfig/node20/tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"customConditions": [
|
||||
"node"
|
||||
],
|
||||
"module": "ES2022",
|
||||
"moduleResolution": "Bundler",
|
||||
"noImplicitOverride": true
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
]
|
||||
}
|
||||
BIN
streamdeck-plugin/img/v0.1.0.0.png
Normal file
|
After Width: | Height: | Size: 134 KiB |
BIN
streamdeck-plugin/img/v0.2.0.0.png
Normal file
|
After Width: | Height: | Size: 152 KiB |
BIN
streamdeck-plugin/img/v0.3.0.0.png
Normal file
|
After Width: | Height: | Size: 104 KiB |
BIN
streamdeck-plugin/img/v0.3.1.0.png
Normal file
|
After Width: | Height: | Size: 236 KiB |