support Dimmer < > and / for level move and stop

This commit is contained in:
David Friedland 2021-03-08 22:35:38 -08:00
parent d231bb4731
commit 84352706e9
1 changed files with 17 additions and 1 deletions

View File

@ -1844,6 +1844,16 @@ uint16_t fadeGammaReverse(uint32_t channel, uint16_t vg) {
}
}
uint8_t LightGetCurFadeBri(void) {
uint8_t max_bri = 0;
uint8_t bri_i = 0;
for (uint8_t i = 0; i < LST_MAX; i++) {
bri_i = changeUIntScale(fadeGammaReverse(i, Light.fade_cur_10[i]), 4, 1023, 1, 100);
if (bri_i > max_bri) max_bri = bri_i ;
}
return max_bri;
}
bool LightApplyFade(void) { // did the value chanegd and needs to be applied
static uint32_t last_millis = 0;
uint32_t now = millis();
@ -2711,12 +2721,18 @@ void CmndDimmer(void)
} else {
dimmer = light_state.getDimmer(XdrvMailbox.index);
}
// Handle +/- special command
// Handle +/-/!/</> special commands
if (1 == XdrvMailbox.data_len) {
if ('+' == XdrvMailbox.data[0]) {
XdrvMailbox.payload = (dimmer > (100 - Settings.dimmer_step - 1)) ? 100 : dimmer + Settings.dimmer_step;
} else if ('-' == XdrvMailbox.data[0]) {
XdrvMailbox.payload = (dimmer < (Settings.dimmer_step + 1)) ? 1 : dimmer - Settings.dimmer_step;
} else if ('!' == XdrvMailbox.data[0] && Light.fade_running) {
XdrvMailbox.payload = LightGetCurFadeBri();
} else if ('<' == XdrvMailbox.data[0] ) {
XdrvMailbox.payload = 1;
} else if ('>' == XdrvMailbox.data[0] ) {
XdrvMailbox.payload = 100;
}
}
// If value is ok, change it, otherwise report old value