mirror of https://github.com/arendst/Tasmota.git
Change color temp with rotary when Button1 pressed
This commit is contained in:
parent
b5ad2c8c06
commit
9f030ae431
|
@ -261,5 +261,6 @@ const uint8_t kIFan02Speed[MAX_FAN_SPEED][3] = {{6,6,6}, {7,6,6}, {7,7,6}, {7,6,
|
|||
|
||||
extern uint8_t light_device; // Light device number
|
||||
extern uint8_t light_power; // Light power
|
||||
extern uint8_t rotary_changed; // Rotary switch changed
|
||||
|
||||
#endif // _SONOFF_H_
|
||||
|
|
|
@ -203,6 +203,9 @@ void ButtonHandler(void)
|
|||
multipress[button_index] = 1;
|
||||
}
|
||||
}
|
||||
if ((MI_DESK_LAMP == Settings.module) && (button_index == 0) && (rotary_changed) && (light_power)) {
|
||||
rotary_changed = 0; // Color temp changed, no need to turn of the light
|
||||
} else {
|
||||
if (single_press && SendKey(0, button_index + multipress[button_index], POWER_TOGGLE)) { // Execute Toggle command via MQTT if ButtonTopic is set
|
||||
// Success
|
||||
} else {
|
||||
|
@ -219,6 +222,7 @@ void ButtonHandler(void)
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
multipress[button_index] = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ uint8_t rotary_state = 0;
|
|||
uint8_t rotary_position = 128;
|
||||
uint8_t rotary_last_position = 128;
|
||||
uint8_t interrupts_in_use = 0;
|
||||
uint8_t rotary_changed = 0;
|
||||
|
||||
/********************************************************************************************/
|
||||
|
||||
|
@ -99,10 +100,23 @@ void RotaryHandler(void)
|
|||
} else {
|
||||
noInterrupts();
|
||||
}
|
||||
interrupts();
|
||||
|
||||
if (rotary_last_position != rotary_position) {
|
||||
if (MI_DESK_LAMP == Settings.module) { // Mi Desk lamp
|
||||
if (holdbutton[0]) {
|
||||
rotary_changed = 1;
|
||||
// button1 is pressed: set color temperature
|
||||
int16_t t = LightGetColorTemp();
|
||||
t = t + (rotary_position - rotary_last_position);
|
||||
if (t < 153) {
|
||||
t = 153;
|
||||
}
|
||||
if (t > 500) {
|
||||
t = 500;
|
||||
}
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION D_CMND_COLORTEMPERATURE " %d"), rotary_position - rotary_last_position);
|
||||
AddLog(LOG_LEVEL_DEBUG);
|
||||
LightSetColorTemp((uint16_t)t);
|
||||
} else {
|
||||
int8_t d = Settings.light_dimmer;
|
||||
d = d + (rotary_position - rotary_last_position);
|
||||
if (d < 1) {
|
||||
|
@ -114,11 +128,14 @@ void RotaryHandler(void)
|
|||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION D_CMND_DIMMER " %d"), rotary_position - rotary_last_position);
|
||||
AddLog(LOG_LEVEL_DEBUG);
|
||||
|
||||
LightSetDimmer(d);
|
||||
LightSetDimmer((uint8_t)d);
|
||||
Settings.light_dimmer = d;
|
||||
}
|
||||
rotary_last_position = rotary_position;
|
||||
}
|
||||
rotary_last_position = 128;
|
||||
rotary_position = 128;
|
||||
}
|
||||
interrupts();
|
||||
}
|
||||
|
||||
void RotaryLoop(void)
|
||||
|
|
Loading…
Reference in New Issue