Change color temp with rotary when Button1 pressed

This commit is contained in:
dh.harald 2019-01-15 00:45:19 +00:00
parent b5ad2c8c06
commit 9f030ae431
3 changed files with 47 additions and 25 deletions

View File

@ -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_device; // Light device number
extern uint8_t light_power; // Light power extern uint8_t light_power; // Light power
extern uint8_t rotary_changed; // Rotary switch changed
#endif // _SONOFF_H_ #endif // _SONOFF_H_

View File

@ -203,6 +203,9 @@ void ButtonHandler(void)
multipress[button_index] = 1; 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 if (single_press && SendKey(0, button_index + multipress[button_index], POWER_TOGGLE)) { // Execute Toggle command via MQTT if ButtonTopic is set
// Success // Success
} else { } else {
@ -219,6 +222,7 @@ void ButtonHandler(void)
} }
} }
} }
}
multipress[button_index] = 0; multipress[button_index] = 0;
} }
} }

View File

@ -29,6 +29,7 @@ uint8_t rotary_state = 0;
uint8_t rotary_position = 128; uint8_t rotary_position = 128;
uint8_t rotary_last_position = 128; uint8_t rotary_last_position = 128;
uint8_t interrupts_in_use = 0; uint8_t interrupts_in_use = 0;
uint8_t rotary_changed = 0;
/********************************************************************************************/ /********************************************************************************************/
@ -99,10 +100,23 @@ void RotaryHandler(void)
} else { } else {
noInterrupts(); noInterrupts();
} }
interrupts();
if (rotary_last_position != rotary_position) { if (rotary_last_position != rotary_position) {
if (MI_DESK_LAMP == Settings.module) { // Mi Desk lamp 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; int8_t d = Settings.light_dimmer;
d = d + (rotary_position - rotary_last_position); d = d + (rotary_position - rotary_last_position);
if (d < 1) { 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); snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION D_CMND_DIMMER " %d"), rotary_position - rotary_last_position);
AddLog(LOG_LEVEL_DEBUG); AddLog(LOG_LEVEL_DEBUG);
LightSetDimmer(d); LightSetDimmer((uint8_t)d);
Settings.light_dimmer = d; Settings.light_dimmer = d;
} }
rotary_last_position = rotary_position;
} }
rotary_last_position = 128;
rotary_position = 128;
}
interrupts();
} }
void RotaryLoop(void) void RotaryLoop(void)