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_power; // Light power
extern uint8_t rotary_changed; // Rotary switch changed
#endif // _SONOFF_H_

View File

@ -203,19 +203,23 @@ 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 {
if (multipress[button_index] < 3) { // Single or Double press
if (WifiState() > WIFI_RESTART) { // WPSconfig, Smartconfig or Wifimanager active
restart_flag = 1;
} else {
ExecuteCommandPower(button_index + multipress[button_index], POWER_TOGGLE, SRC_BUTTON); // Execute Toggle command internally
}
} else { // 3 - 7 press
if (!Settings.flag.button_restrict) {
snprintf_P(scmnd, sizeof(scmnd), kCommands[multipress[button_index] -3]);
ExecuteCommand(scmnd, SRC_BUTTON);
if (multipress[button_index] < 3) { // Single or Double press
if (WifiState() > WIFI_RESTART) { // WPSconfig, Smartconfig or Wifimanager active
restart_flag = 1;
} else {
ExecuteCommandPower(button_index + multipress[button_index], POWER_TOGGLE, SRC_BUTTON); // Execute Toggle command internally
}
} else { // 3 - 7 press
if (!Settings.flag.button_restrict) {
snprintf_P(scmnd, sizeof(scmnd), kCommands[multipress[button_index] -3]);
ExecuteCommand(scmnd, SRC_BUTTON);
}
}
}
}

View File

@ -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,26 +100,42 @@ void RotaryHandler(void)
} else {
noInterrupts();
}
interrupts();
if (rotary_last_position != rotary_position) {
if (MI_DESK_LAMP == Settings.module) { // Mi Desk lamp
int8_t d = Settings.light_dimmer;
d = d + (rotary_position - rotary_last_position);
if (d < 1) {
d = 1;
}
if (d > 100) {
d = 100;
}
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION D_CMND_DIMMER " %d"), rotary_position - rotary_last_position);
AddLog(LOG_LEVEL_DEBUG);
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) {
d = 1;
}
if (d > 100) {
d = 100;
}
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);
Settings.light_dimmer = 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)