diff --git a/events.py b/events.py
index ebff324..2952b51 100644
--- a/events.py
+++ b/events.py
@@ -209,6 +209,8 @@ async def neopixel(request, ws, data):
if data.get('type') == 'solid':
payload = tools.from_html_color(data.get('color'))
payload = str(payload)[1:-1].replace(' ', '')
+ elif data.get('type') == 'rainbow':
+ payload = ','.join(data.get('rainbow_params'))
request.app['mqtt'].publish(mqtt_msg, payload)
# websocket response is handled under LightStrip.mqtt_callback
diff --git a/models.py b/models.py
index 0db5f4c..984e053 100644
--- a/models.py
+++ b/models.py
@@ -165,6 +165,7 @@ class LightStrip(Device):
async def mqtt_callback(self, app, msg):
topic = msg.topic.split('/')
+ payload = msg.payload.decode('utf8')
data = {}
data['ok'] = True
@@ -172,10 +173,10 @@ class LightStrip(Device):
data['change_mode'] = topic[1]
if topic[1] == 'state':
- payload = msg.payload.decode('utf8').split(',')
- payload = [int(num) for num in payload]
data['type'] = topic[2]
if topic[2] == 'solid':
+ payload = payload.split(',')
+ payload = [int(num) for num in payload]
data['amount'] = topic[3]
if topic[3] == 'single':
data['sub_device_id'] = 'led' + topic[4]
@@ -185,8 +186,12 @@ class LightStrip(Device):
elif topic[3] == 'all':
for sub_device in self.sub_devices:
sub_device.color = payload
- save_network(network)
data['color'] = tools.to_html_color(payload)
+ elif topic[2] == 'rainbow':
+ payload = payload.split(',')
+ self.rainbow_params = [float(p) for p in payload[:3]]
+ self.rainbow_params += [int(p) for p in payload[3:]]
+ save_network(network)
res = {'event': 'neopixel', 'data': data}
await app.send_json_all(res)
diff --git a/static/juice.js b/static/juice.js
index e6e95ff..f180395 100644
--- a/static/juice.js
+++ b/static/juice.js
@@ -248,11 +248,15 @@ function delete_device(device) {
socket.send('delete_device', data);
}
-function neopixel_state(sub_device) {
- let device = sub_device.parentElement.parentElement;
+function neopixel_state(device) {
+ let sub_device;
+ if (device.classList.contains('sub_device')) {
+ sub_device = device;
+ device = sub_device.closest('.device');
+ }
let state_mode = device.querySelector('.state_select').value;
let data = {
- device_id: sub_device.parentElement.parentElement.id,
+ device_id: device.id,
change_mode: 'state',
type: state_mode,
}
@@ -273,6 +277,16 @@ function neopixel_state(sub_device) {
data['sub_device_id'] = sub_device.classList[2];
}
} else if (state_mode === 'rainbow') {
+ data['rainbow_params'] = [
+ device.querySelector('#state_rainbow_red_freq_' + device.id).value,
+ device.querySelector('#state_rainbow_green_freq_' + device.id).value,
+ device.querySelector('#state_rainbow_blue_freq_' + device.id).value,
+ device.querySelector('#state_rainbow_red_phase_' + device.id).value,
+ device.querySelector('#state_rainbow_green_phase_' + device.id).value,
+ device.querySelector('#state_rainbow_blue_phase_' + device.id).value,
+ device.querySelector('#state_rainbow_center_' + device.id).value,
+ device.querySelector('#state_rainbow_width_' + device.id).value
+ ]
} else if (state_mode === 'america') {
}
socket.send('neopixel', data);
@@ -311,6 +325,8 @@ function state_solid_amount(radio) {
}
function state_select(select) {
+ let device = select.parentElement.parentElement.parentElement;
+ let sub_devices = device.querySelector('.sub_devices');
if (select.value === 'solid') {
select.parentElement.querySelector('.state_solid').style.display = 'block';
select.parentElement.querySelector('.state_rainbow').style.display = 'none';
@@ -319,10 +335,18 @@ function state_select(select) {
select.parentElement.querySelector('.state_solid').style.display = 'none';
select.parentElement.querySelector('.state_rainbow').style.display = 'block';
select.parentElement.querySelector('.state_america').style.display = 'none';
+ for (let sub_device of sub_devices.children) {
+ let input = sub_device.firstElementChild.firstElementChild;
+ input.disabled = true;
+ }
} else if (select.value === 'america') {
select.parentElement.querySelector('.state_solid').style.display = 'none';
select.parentElement.querySelector('.state_rainbow').style.display = 'none';
select.parentElement.querySelector('.state_america').style.display = 'block';
+ for (let sub_device of sub_devices.children) {
+ let input = sub_device.firstElementChild.firstElementChild;
+ input.disabled = true;
+ }
}
}
diff --git a/templates/index.html b/templates/index.html
index 6e4d095..243ebdf 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -53,56 +53,56 @@
-
+
Red | - + | - + |
Green | - + | - + |
Blue | - + | - + |
- | + | |
- | + |