state/america works

This commit is contained in:
iou1name 2019-11-21 08:43:02 -05:00
parent 732abf5c2f
commit 53656b1f05
4 changed files with 22 additions and 3 deletions

View File

@ -211,6 +211,8 @@ async def neopixel(request, ws, data):
payload = str(payload)[1:-1].replace(' ', '') payload = str(payload)[1:-1].replace(' ', '')
elif data.get('type') == 'rainbow': elif data.get('type') == 'rainbow':
payload = ','.join(data.get('rainbow_params')) payload = ','.join(data.get('rainbow_params'))
elif data.get('type') == 'america':
payload = ','.join(data.get('america_params'))
request.app['mqtt'].publish(mqtt_msg, payload) request.app['mqtt'].publish(mqtt_msg, payload)
# websocket response is handled under LightStrip.mqtt_callback # websocket response is handled under LightStrip.mqtt_callback

View File

@ -159,7 +159,7 @@ class LightStrip(Device):
self.state = "solid" self.state = "solid"
self.animation = "static", self.animation = "static",
rainbow_params = [0.3, 0.3, 0.3, 0, 2, 4, 127, 128], rainbow_params = [0.3, 0.3, 0.3, 0, 2, 4, 127, 128],
america_params = 8, america_params = [8, 128],
animation_rotate_count = 1, animation_rotate_count = 1,
animation_delay = 200, animation_delay = 200,
@ -191,6 +191,11 @@ class LightStrip(Device):
payload = payload.split(',') payload = payload.split(',')
self.rainbow_params = [float(p) for p in payload[:3]] self.rainbow_params = [float(p) for p in payload[:3]]
self.rainbow_params += [int(p) for p in payload[3:]] self.rainbow_params += [int(p) for p in payload[3:]]
data['rainbow_params'] = self.rainbow_params
elif topic[2] == 'america':
payload = payload.split(',')
self.america_params = [int(n) for n in payload]
data['america_params'] = self.america_params
elif topic[1] == 'strip': elif topic[1] == 'strip':
data['amount'] = topic[2] data['amount'] = topic[2]
if topic[2] == 'full': if topic[2] == 'full':

View File

@ -297,6 +297,10 @@ function neopixel_state(device) {
device.querySelector('#state_rainbow_width_' + device.id).value device.querySelector('#state_rainbow_width_' + device.id).value
] ]
} else if (state_mode === 'america') { } else if (state_mode === 'america') {
data['america_params'] = [
device.querySelector('#state_america_stripe_' + device.id).value,
device.querySelector('#state_america_magnitude_' + device.id).value
]
} }
socket.send('neopixel', data); socket.send('neopixel', data);
} }

View File

@ -101,8 +101,16 @@
</table> </table>
</div> </div>
<div class="state_america" style="display: {% if device.state == 'america' %}block{% else %}none{% endif %}"> <div class="state_america" style="display: {% if device.state == 'america' %}block{% else %}none{% endif %}">
<label for="state_america_stripe_{{ device.id }}">Stripe Length</label> <table>
<input type="number" id="state_america_stripe_{{ device.id }}" min="1" max="256" step="1" value="{{ device.america_params }}"> <tr>
<td><label for="state_america_stripe_{{ device.id }}">Stripe Length</label></td>
<td><input type="number" id="state_america_stripe_{{ device.id }}" min="1" max="256" step="1" value="{{ device.america_params[0] }}" onchange="neopixel_state(this.closest('.device'))"></td>
</tr>
<tr>
<td><label for="state_america_magnitude_{{ device.id }}">Magnitude</label></td>
<td><input type="number" id="state_america_magnitude_{{ device.id }}" min="0" max="255" step="1" value="{{ device.america_params[1] }}" onchange="neopixel_state(this.closest('.device'))"></td>
</tr>
</table>
</div> </div>
</div> </div>
<div class="animation"> <div class="animation">