Browse Source

Change light transition time via MQTT or API (#1412)

alexa
Xose Pérez 6 years ago
parent
commit
fcf59d04cd
2 changed files with 38 additions and 1 deletions
  1. +1
    -0
      code/espurna/config/general.h
  2. +37
    -1
      code/espurna/light.ino

+ 1
- 0
code/espurna/config/general.h View File

@ -773,6 +773,7 @@
#define MQTT_TOPIC_BRIGHTNESS "brightness" #define MQTT_TOPIC_BRIGHTNESS "brightness"
#define MQTT_TOPIC_MIRED "mired" #define MQTT_TOPIC_MIRED "mired"
#define MQTT_TOPIC_KELVIN "kelvin" #define MQTT_TOPIC_KELVIN "kelvin"
#define MQTT_TOPIC_TRANSITION "transition"
#define MQTT_STATUS_ONLINE "1" // Value for the device ON message #define MQTT_STATUS_ONLINE "1" // Value for the device ON message
#define MQTT_STATUS_OFFLINE "0" // Value for the device OFF message (will) #define MQTT_STATUS_OFFLINE "0" // Value for the device OFF message (will)


+ 37
- 1
code/espurna/light.ino View File

@ -504,6 +504,7 @@ void _lightMQTTCallback(unsigned int type, const char * topic, const char * payl
mqttSubscribe(MQTT_TOPIC_KELVIN); mqttSubscribe(MQTT_TOPIC_KELVIN);
mqttSubscribe(MQTT_TOPIC_COLOR_RGB); mqttSubscribe(MQTT_TOPIC_COLOR_RGB);
mqttSubscribe(MQTT_TOPIC_COLOR_HSV); mqttSubscribe(MQTT_TOPIC_COLOR_HSV);
mqttSubscribe(MQTT_TOPIC_TRANSITION);
} }
// Group color // Group color
@ -561,6 +562,12 @@ void _lightMQTTCallback(unsigned int type, const char * topic, const char * payl
return; return;
} }
// Transitions
if (t.equals(MQTT_TOPIC_TRANSITION)) {
lightTransitionTime(atol(payload));
return;
}
// Channel // Channel
if (t.startsWith(MQTT_TOPIC_CHANNEL)) { if (t.startsWith(MQTT_TOPIC_CHANNEL)) {
unsigned int channelID = t.substring(strlen(MQTT_TOPIC_CHANNEL)+1).toInt(); unsigned int channelID = t.substring(strlen(MQTT_TOPIC_CHANNEL)+1).toInt();
@ -658,7 +665,7 @@ void lightUpdate(bool save, bool forward, bool group_forward) {
// Update channels // Update channels
for (unsigned int i=0; i < _light_channel.size(); i++) { for (unsigned int i=0; i < _light_channel.size(); i++) {
_light_channel[i].target = _light_state && _light_channel[i].state ? _light_channel[i].value : 0; _light_channel[i].target = _light_state && _light_channel[i].state ? _light_channel[i].value : 0;
DEBUG_MSG_P("[LIGHT] Channel #%u target value: %u\n", i, _light_channel[i].target);
//DEBUG_MSG_P("[LIGHT] Channel #%u target value: %u\n", i, _light_channel[i].target);
} }
// Configure color transition // Configure color transition
@ -774,6 +781,26 @@ void lightBrightnessStep(int steps) {
lightBrightness(_light_brightness + steps * LIGHT_STEP); lightBrightness(_light_brightness + steps * LIGHT_STEP);
} }
unsigned long lightTransitionTime() {
if (_light_use_transitions) {
return _light_transition_time;
} else {
return 0;
}
}
void lightTransitionTime(unsigned long m) {
if (0 == m) {
_light_use_transitions = false;
} else {
_light_use_transitions = true;
_light_transition_time = m;
}
setSetting("useTransitions", _light_use_transitions);
setSetting("lightTime", _light_transition_time);
saveSettings();
}
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// SETUP // SETUP
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -918,6 +945,15 @@ void _lightAPISetup() {
} }
apiRegister(MQTT_TOPIC_TRANSITION,
[](char * buffer, size_t len) {
snprintf_P(buffer, len, PSTR("%d"), lightTransitionTime());
},
[](const char * payload) {
lightTransitionTime(atol(payload));
}
);
apiRegister(MQTT_TOPIC_BRIGHTNESS, apiRegister(MQTT_TOPIC_BRIGHTNESS,
[](char * buffer, size_t len) { [](char * buffer, size_t len) {
snprintf_P(buffer, len, PSTR("%d"), _light_brightness); snprintf_P(buffer, len, PSTR("%d"), _light_brightness);


Loading…
Cancel
Save