burrow/lights/catarium/top 0-1 [intensity] 0-1 [warm-cold]
burrow/lights/catarium/bottom 0-1 [intensity] 0-1 [warm-cold]
-burrow/lights/rainbow/<led> 0-255 [R] 0-255 [G] 0-255 [B]
+burrow/lights/rainbow/<led> 0-1 [R] 0-1 [G] 0-1 [B]
+burrow/lights/rainbow/brightness 0-1
bsb/stats/*
bsb/frame hex dump of raw frames received
static bool led_refresh;
struct led {
- byte r, g, b;
+ double r, g, b;
};
static struct led leds[NPIX_NUM_LEDS];
+static double led_brightness = 1;
/*** MQTT ***/
if (!str_has_prefix(m->topic, px))
return;
+ const char *top = m->topic + strlen(px);
+ if (!strcmp(top, "brightness")) {
+ double b = atof(val);
+ if (!(b >= 0 && b <= 1)) {
+ msg(L_ERROR, "Invalid value of %s: %s", m->topic, val);
+ return;
+ }
+ mtx_lock(&led_mutex);
+ led_brightness = b;
+ led_refresh = 1;
+ cnd_broadcast(&led_cond);
+ mtx_unlock(&led_mutex);
+ return;
+ }
+
uint index;
if (str_to_uint(&index, m->topic + strlen(px), NULL, 10 | STN_WHOLE) || index >= NPIX_NUM_LEDS) {
msg(L_ERROR, "Unsupported topic: %s", m->topic);
return;
}
- uint r, g, b;
- if (sscanf(val, "%u%u%u", &r, &g, &b) != 3 || r >= 256 || g >= 256 || b >= 256) {
+ double r, g, b;
+ if (sscanf(val, "%lf%lf%lf", &r, &g, &b) != 3 || !(r >= 0 && r <= 1) || !(g >= 0 && g <= 1) || !(b >= 0 && b <= 1)) {
msg(L_ERROR, "Invalid value of %s: %s", m->topic, val);
return;
}
byte *pkt = npix_packet;
for (int i=0; i < NPIX_NUM_LEDS; i++) {
- *pkt++ = leds[i].r;
- *pkt++ = leds[i].g;
- *pkt++ = leds[i].b;
+ *pkt++ = (int)(leds[i].r * led_brightness * 255);
+ *pkt++ = (int)(leds[i].g * led_brightness * 255);
+ *pkt++ = (int)(leds[i].b * led_brightness * 255);
}
return pkt - npix_packet;