mirror of https://github.com/arendst/Tasmota.git
Add rotary encoder color control
Add rotary encoder color control when button pressed and postpone flash writes while turning rotary.
This commit is contained in:
parent
e52961b3b4
commit
828a64815b
|
@ -88,10 +88,18 @@ void RotaryHandler(void) {
|
||||||
Rotary.busy = true;
|
Rotary.busy = true;
|
||||||
int rotary_position = Rotary.position - Rotary.last_position;
|
int rotary_position = Rotary.position - Rotary.last_position;
|
||||||
|
|
||||||
|
if (Settings.save_data) {
|
||||||
|
if (save_data_counter < 2) {
|
||||||
|
save_data_counter = 2; // Postpone flash writes while rotary is turned
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (Button.hold_timer[0]) { // Button1 is pressed: set color temperature
|
if (Button.hold_timer[0]) { // Button1 is pressed: set color temperature
|
||||||
// AddLog_P2(LOG_LEVEL_DEBUG, PSTR("ROT: " D_CMND_COLORTEMPERATURE " %d"), rotary_position);
|
// AddLog_P2(LOG_LEVEL_DEBUG, PSTR("ROT: " D_CMND_COLORTEMPERATURE " %d"), rotary_position);
|
||||||
Rotary.changed = 1;
|
Rotary.changed = 1;
|
||||||
LightColorTempOffset(rotary_position * 4);
|
if (!LightColorTempOffset(rotary_position * 4)) { // Ct from 153 - 500
|
||||||
|
LightColorOffset(rotary_position * 4); // Hue from 0 - 359
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// AddLog_P2(LOG_LEVEL_DEBUG, PSTR("ROT: " D_CMND_DIMMER " %d"), rotary_position);
|
// AddLog_P2(LOG_LEVEL_DEBUG, PSTR("ROT: " D_CMND_DIMMER " %d"), rotary_position);
|
||||||
LightDimmerOffset(rotary_position);
|
LightDimmerOffset(rotary_position);
|
||||||
|
|
|
@ -1478,14 +1478,31 @@ void LightSetBri(uint8_t device, uint8_t bri) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LightColorTempOffset(int32_t offset) {
|
void LightColorOffset(int32_t offset) {
|
||||||
|
uint16_t hue;
|
||||||
|
uint8_t sat;
|
||||||
|
light_state.getHSB(&hue, &sat, nullptr); // Allow user control over Saturation
|
||||||
|
hue += offset;
|
||||||
|
if (hue < 0) { hue = 0; }
|
||||||
|
if (hue > 359) { hue = 359; }
|
||||||
|
if (!Light.pwm_multi_channels) {
|
||||||
|
light_state.setHS(hue, sat);
|
||||||
|
} else {
|
||||||
|
light_state.setHS(hue, 255);
|
||||||
|
light_state.setBri(255); // If multi-channel, force bri to max, it will be later dimmed to correct value
|
||||||
|
}
|
||||||
|
light_controller.calcLevels(Light.new_color);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LightColorTempOffset(int32_t offset) {
|
||||||
int32_t ct = LightGetColorTemp();
|
int32_t ct = LightGetColorTemp();
|
||||||
if (0 == ct) { return; } // CT not supported
|
if (0 == ct) { return false; } // CT not supported
|
||||||
ct += offset;
|
ct += offset;
|
||||||
if (ct < CT_MIN) { ct = CT_MIN; }
|
if (ct < CT_MIN) { ct = CT_MIN; }
|
||||||
else if (ct > CT_MAX) { ct = CT_MAX; }
|
else if (ct > CT_MAX) { ct = CT_MAX; }
|
||||||
|
|
||||||
LightSetColorTemp(ct);
|
LightSetColorTemp(ct);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LightSetColorTemp(uint16_t ct)
|
void LightSetColorTemp(uint16_t ct)
|
||||||
|
|
Loading…
Reference in New Issue