Document Light commands

This commit is contained in:
Theo Arends 2020-01-22 16:14:03 +01:00
parent fb485dabd3
commit 7ea60116cf
1 changed files with 75 additions and 48 deletions

View File

@ -2185,6 +2185,13 @@ void CmndSupportColor(void)
void CmndColor(void)
{
// Color - Show current RGBWW color state
// Color1 - Change color to RGBWW
// Color2 - Change color to RGBWW but retain brightness (=dimmer)
// Color3 - Change color to RGB of WS2812 Clock Second
// Color4 - Change color to RGB of WS2812 Clock Minute
// Color5 - Change color to RGB of WS2812 Clock Hour
// Color6 - Change color to RGB of WS2812 Clock Marker
if ((Light.subtype > LST_SINGLE) && (XdrvMailbox.index > 0) && (XdrvMailbox.index <= 6)) {
CmndSupportColor();
}
@ -2192,6 +2199,8 @@ void CmndColor(void)
void CmndWhite(void)
{
// White - Show current White (=Dimmer2) state
// White 0..100 - Set White colors dimmer state
if (Light.pwm_multi_channels) { return; }
if ( ((Light.subtype >= LST_RGBW) || (LST_COLDWARM == Light.subtype)) && (XdrvMailbox.index == 1)) {
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 100)) {
@ -2205,6 +2214,10 @@ void CmndWhite(void)
void CmndChannel(void)
{
// Channel<x> - Show current Channel state
// Channel<x> 0..100 - Set Channel dimmer state
// Channel<x> + - Incerement Channel in steps of 10
// Channel<x> - - Decrement Channel in steps of 10
if ((XdrvMailbox.index >= Light.device) && (XdrvMailbox.index < Light.device + Light.subtype )) {
uint32_t light_index = XdrvMailbox.index - Light.device;
power_t coldim = 0; // bit flag to update
@ -2249,48 +2262,35 @@ void CmndChannel(void)
void CmndHsbColor(void)
{
// HsbColor - Show current HSB
// HsbColor 360,100,100 - Set Hue, Saturation and Brighthness
// HsbColor 360,100 - Set Hue and Saturation
// HsbColor 360 - Set Hue
// HsbColor1 360 - Set Hue
// HsbColor2 100 - Set Saturation
// HsbColor3 100 - Set Brightness
if (Light.subtype >= LST_RGB) {
bool validHSB = (XdrvMailbox.data_len > 0);
if (validHSB) {
uint16_t HSB[3];
if (XdrvMailbox.data_len > 0) {
uint16_t c_hue;
uint8_t c_sat;
light_state.getHSB(&c_hue, &c_sat, nullptr);
uint32_t HSB[3];
HSB[0] = c_hue;
HSB[1] = c_sat;
HSB[2] = light_state.getBriRGB();
char *substr = strstr(XdrvMailbox.data, ",");
if (substr != nullptr) { // Command with comma separated parameters, Hue (0<H<360), Saturation (0<S<100) AND optional Brightness (0<B<100)
HSB[0] = atoi(XdrvMailbox.data);
for (uint32_t i = 1; i < 3; i++) {
substr++;
HSB[i] = atoi(substr);
if ((2 == XdrvMailbox.index) || (3 == XdrvMailbox.index)) {
if ((uint32_t)XdrvMailbox.payload > 100) { XdrvMailbox.payload = 100; }
HSB[XdrvMailbox.index-1] = changeUIntScale(XdrvMailbox.payload, 0, 100, 0, 255);
} else {
uint32_t paramcount = ParseParameters(3, HSB);
if (HSB[0] > 360) { HSB[0] = 360; }
for (uint32_t i = 1; i < paramcount; i++) {
if (HSB[i] > 100) { HSB[i] == 100; }
HSB[i] = changeUIntScale(HSB[i], 0, 100, 0, 255); // change sat and bri to 0..255
substr = strstr(substr, ",");
if (substr == nullptr) {
break;
}
}
if (substr != nullptr) {
validHSB = false;
}
} else { // Command with only 1 parameter, Hue (0<H<360), Saturation (0<S<100) OR Brightness (0<B<100)
if (1 == XdrvMailbox.index) {
HSB[0] = XdrvMailbox.payload;
} else if ((XdrvMailbox.index > 1) && (XdrvMailbox.index < 4)) {
HSB[XdrvMailbox.index-1] = changeUIntScale(XdrvMailbox.payload,0,100,0,255);
} else {
validHSB = false;
}
}
if (validHSB) {
light_controller.changeHSB(HSB[0], HSB[1], HSB[2]);
LightPreparePower(1);
}
light_controller.changeHSB(HSB[0], HSB[1], HSB[2]);
LightPreparePower(1);
} else {
LightState(0);
}
@ -2299,6 +2299,11 @@ void CmndHsbColor(void)
void CmndScheme(void)
{
// Scheme 0..12 - Select one of schemes 0 to 12
// Scheme 2 - Select scheme 2
// Scheme 2,0 - Select scheme 2 with color wheel set to 0 (HSB Red)
// Scheme + - Select next scheme
// Scheme - - Select previous scheme
if (Light.subtype >= LST_RGB) {
uint32_t max_scheme = Light.max_scheme;
@ -2332,6 +2337,8 @@ void CmndScheme(void)
void CmndWakeup(void)
{
// Wakeup - Start wakeup light
// Wakeup 0..100 - Start wakeup light to dimmer value 0..100
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 100)) {
light_controller.changeDimmer(XdrvMailbox.payload);
}
@ -2343,6 +2350,10 @@ void CmndWakeup(void)
void CmndColorTemperature(void)
{
// CT - Show current color temperature
// CT 153..500 - Set color temperature
// CT + - Incerement color temperature in steps of 34
// CT - - Decrement color temperature in steps of 34
if (Light.pwm_multi_channels) { return; }
if ((LST_COLDWARM == Light.subtype) || (LST_RGBCW == Light.subtype)) { // ColorTemp
uint32_t ct = light_state.getCT();
@ -2365,6 +2376,12 @@ void CmndColorTemperature(void)
void CmndDimmer(void)
{
// Dimmer - Show current Dimmer state
// Dimmer0 0..100 - Change both RGB and W(W) Dimmers
// Dimmer1 0..100 - Change RGB Dimmer
// Dimmer2 0..100 - Change W(W) Dimmer
// Dimmer<x> + - Incerement Dimmer in steps of 10
// Dimmer<x> - - Decrement Dimmer in steps of 10
uint32_t dimmer;
if (XdrvMailbox.index > 2) { XdrvMailbox.index = 1; }
@ -2406,6 +2423,8 @@ void CmndDimmer(void)
void CmndDimmerRange(void)
{
// DimmerRange - Show current dimmer range as used by Tuya and PS16DZ Dimmers
// DimmerRange 0,100 - Set dimmer hardware range from 0 to 100 and restart
if (XdrvMailbox.data_len > 0) {
uint32_t parm[2];
parm[0] = Settings.dimmer_hw_min;
@ -2425,6 +2444,10 @@ void CmndDimmerRange(void)
void CmndLedTable(void)
{
// LedTable - Show current LedTable state
// LedTable 0 - Turn LedTable Off
// LedTable On - Turn LedTable On
// LedTable Toggle - Toggle LedTable state
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 2)) {
switch (XdrvMailbox.payload) {
case 0: // Off
@ -2442,20 +2465,13 @@ void CmndLedTable(void)
void CmndRgbwwTable(void)
{
// RgbWwTable - Show current RGBWW State
// RgbWwTable 255,255,255,255,255 - Set RGBWW state to maximum
if ((XdrvMailbox.data_len > 0)) {
if (strstr(XdrvMailbox.data, ",") != nullptr) { // Command with up to 5 comma separated parameters
for (uint32_t i = 0; i < LST_RGBCW; i++) {
char *substr;
if (0 == i) {
substr = strtok(XdrvMailbox.data, ",");
} else {
substr = strtok(nullptr, ",");
}
if (substr != nullptr) {
Settings.rgbwwTable[i] = atoi(substr);
}
}
uint32_t parm[LST_RGBCW -1];
uint32_t parmcount = ParseParameters(LST_RGBCW, parm);
for (uint32_t i = 0; i < parmcount; i++) {
Settings.rgbwwTable[i] = parm[i];
}
Light.update = true;
}
@ -2464,11 +2480,15 @@ void CmndRgbwwTable(void)
for (uint32_t i = 0; i < LST_RGBCW; i++) {
snprintf_P(scolor, sizeof(scolor), PSTR("%s%s%d"), scolor, (i > 0) ? "," : "", Settings.rgbwwTable[i]);
}
ResponseCmndIdxChar(scolor);
ResponseCmndChar(scolor);
}
void CmndFade(void)
{
// Fade - Show current Fade state
// Fade 0 - Turn Fade Off
// Fade On - Turn Fade On
// Fade Toggle - Toggle Fade state
switch (XdrvMailbox.payload) {
case 0: // Off
case 1: // On
@ -2483,7 +2503,11 @@ void CmndFade(void)
}
void CmndSpeed(void)
{ // 1 - fast, 40 - very slow
{
// Speed 1 - Fast
// Speed 40 - Very slow
// Speed + - Increment Speed
// Speed - - Decrement Speed
if (1 == XdrvMailbox.data_len) {
if (('+' == XdrvMailbox.data[0]) && (Settings.light_speed > 1)) {
XdrvMailbox.payload = Settings.light_speed - 1;
@ -2500,6 +2524,8 @@ void CmndSpeed(void)
void CmndWakeupDuration(void)
{
// WakeUpDuration - Show current Wake Up duration in seconds
// WakeUpDuration 60 - Set Wake Up duration to 60 seconds
if ((XdrvMailbox.payload > 0) && (XdrvMailbox.payload < 3001)) {
Settings.light_wakeup = XdrvMailbox.payload;
Light.wakeup_active = 0;
@ -2508,7 +2534,8 @@ void CmndWakeupDuration(void)
}
void CmndUndocA(void)
{ // Theos legacy status
{
// Theos legacy status
char scolor[LIGHT_COLOR_SIZE];
LightGetColor(scolor, true); // force hex whatever Option 17
scolor[6] = '\0'; // RGB only