mirror of
https://github.com/arendst/Tasmota.git
synced 2025-08-02 07:27:42 +00:00
Refactor light driver saving code space
Refactor light driver saving code space
This commit is contained in:
parent
b9302d9ab9
commit
38c6254833
@ -266,8 +266,6 @@ const uint8_t kDefaultRfCode[9] PROGMEM = { 0x21, 0x16, 0x01, 0x0E, 0x03, 0x48,
|
||||
* Extern global variables
|
||||
\*********************************************************************************************/
|
||||
|
||||
extern uint8_t light_device; // Light device number
|
||||
extern power_t light_power; // Light power
|
||||
extern uint8_t rotary_changed; // Rotary switch changed
|
||||
|
||||
#endif // _SONOFF_H_
|
||||
|
@ -631,8 +631,8 @@ void MqttShowState(void)
|
||||
|
||||
for (uint32_t i = 1; i <= devices_present; i++) {
|
||||
#ifdef USE_LIGHT
|
||||
if ((light_device) && (i >= light_device)) {
|
||||
if (i == light_device) { LightState(1); } // call it only once
|
||||
if ((LightDevice()) && (i >= LightDevice())) {
|
||||
if (i == LightDevice()) { LightState(1); } // call it only once
|
||||
} else {
|
||||
#endif
|
||||
ResponseAppend_P(PSTR(",\"%s\":\"%s\""), GetPowerDevice(stemp1, i, sizeof(stemp1), Settings.flag.device_index_enable), GetStateText(bitRead(power, i-1)));
|
||||
|
@ -237,7 +237,7 @@ void ButtonHandler(void)
|
||||
}
|
||||
}
|
||||
#ifdef USE_LIGHT
|
||||
if ((MI_DESK_LAMP == my_module_type) && (button_index == 0) && (rotary_changed) && (light_power)) {
|
||||
if ((MI_DESK_LAMP == my_module_type) && (button_index == 0) && (rotary_changed) && (LightPower())) {
|
||||
rotary_changed = 0; // Color temp changed, no need to turn of the light
|
||||
} else {
|
||||
#endif
|
||||
|
@ -68,7 +68,7 @@ void update_rotary(void) ICACHE_RAM_ATTR;
|
||||
void update_rotary(void)
|
||||
{
|
||||
if (MI_DESK_LAMP == my_module_type){
|
||||
if (light_power) {
|
||||
if (LightPower()) {
|
||||
update_position();
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -250,7 +250,7 @@ void HAssAnnounceRelayLight(void)
|
||||
strncpy_P(stemp3, Settings.flag.not_power_linked?PSTR("last"):PSTR("brightness"), sizeof(stemp3));
|
||||
TryResponseAppend_P(HASS_DISCOVER_LIGHT_DIMMER, brightness_command_topic, state_topic, stemp3);
|
||||
|
||||
if (light_subtype >= LST_RGB) {
|
||||
if (Light.subtype >= LST_RGB) {
|
||||
char *rgb_command_topic = stemp1;
|
||||
|
||||
GetTopic_P(rgb_command_topic, CMND, mqtt_topic, D_CMND_COLOR);
|
||||
@ -263,14 +263,14 @@ void HAssAnnounceRelayLight(void)
|
||||
TryResponseAppend_P(HASS_DISCOVER_LIGHT_SCHEME, effect_command_topic, state_topic);
|
||||
|
||||
}
|
||||
if (LST_RGBW == light_subtype) {
|
||||
if (LST_RGBW == Light.subtype) {
|
||||
char *white_temp_command_topic = stemp1;
|
||||
|
||||
GetTopic_P(white_temp_command_topic, CMND, mqtt_topic, D_CMND_WHITE);
|
||||
Shorten(&white_temp_command_topic, prefix);
|
||||
TryResponseAppend_P(HASS_DISCOVER_LIGHT_WHITE, white_temp_command_topic, state_topic);
|
||||
}
|
||||
if ((LST_COLDWARM == light_subtype) || (LST_RGBWC == light_subtype)) {
|
||||
if ((LST_COLDWARM == Light.subtype) || (LST_RGBWC == Light.subtype)) {
|
||||
char *color_temp_command_topic = stemp1;
|
||||
|
||||
GetTopic_P(color_temp_command_topic, CMND, mqtt_topic, D_CMND_COLORTEMPERATURE);
|
||||
|
@ -245,11 +245,11 @@ char prev_y_str[24] = "\0";
|
||||
|
||||
uint8_t getLocalLightSubtype(uint8_t device) {
|
||||
if (light_type) {
|
||||
if (device >= light_device) {
|
||||
if (device >= Light.device) {
|
||||
if (Settings.flag3.pwm_multi_channels) {
|
||||
return LST_SINGLE; // If SetOption68, each channel acts like a dimmer
|
||||
} else {
|
||||
return light_subtype; // the actual light
|
||||
return Light.subtype; // the actual light
|
||||
}
|
||||
} else {
|
||||
return LST_NONE; // relays
|
||||
@ -268,7 +268,7 @@ void HueLightStatus1(uint8_t device, String *response)
|
||||
uint8_t sat = 0;
|
||||
uint8_t bri = 254;
|
||||
uint32_t echo_gen = findEchoGeneration(); // 1 for 1st gen =+ Echo Dot 2nd gen, 2 for 2nd gen and above
|
||||
// local_light_subtype simulates the light_subtype for 'device'
|
||||
// local_light_subtype simulates the Light.subtype for 'device'
|
||||
// For relays LST_NONE, for dimmers LST_SINGLE
|
||||
uint8_t local_light_subtype = getLocalLightSubtype(device);
|
||||
|
||||
@ -458,7 +458,7 @@ void HueLights(String *path)
|
||||
bool on = false;
|
||||
bool change = false; // need to change a parameter to the light
|
||||
uint8_t device = 1;
|
||||
uint8_t local_light_subtype = light_subtype;
|
||||
uint8_t local_light_subtype = Light.subtype;
|
||||
uint8_t maxhue = (devices_present > MAX_HUE_DEVICES) ? MAX_HUE_DEVICES : devices_present;
|
||||
|
||||
path->remove(0,path->indexOf("/lights")); // Remove until /lights
|
||||
@ -535,7 +535,7 @@ void HueLights(String *path)
|
||||
response.replace("{id", String(device));
|
||||
response.replace("{cm", "bri");
|
||||
response.replace("{re", String(tmp));
|
||||
if (LST_SINGLE <= light_subtype) {
|
||||
if (LST_SINGLE <= Light.subtype) {
|
||||
change = true;
|
||||
}
|
||||
resp = true;
|
||||
@ -576,7 +576,7 @@ void HueLights(String *path)
|
||||
response.replace("{id", String(device));
|
||||
response.replace("{cm", "hue");
|
||||
response.replace("{re", String(tmp));
|
||||
if (LST_RGB <= light_subtype) {
|
||||
if (LST_RGB <= Light.subtype) {
|
||||
g_gotct = false;
|
||||
change = true;
|
||||
}
|
||||
@ -592,7 +592,7 @@ void HueLights(String *path)
|
||||
response.replace("{id", String(device));
|
||||
response.replace("{cm", "sat");
|
||||
response.replace("{re", String(tmp));
|
||||
if (LST_RGB <= light_subtype) {
|
||||
if (LST_RGB <= Light.subtype) {
|
||||
g_gotct = false;
|
||||
change = true;
|
||||
}
|
||||
@ -606,7 +606,7 @@ void HueLights(String *path)
|
||||
response.replace("{id", String(device));
|
||||
response.replace("{cm", "ct");
|
||||
response.replace("{re", String(ct));
|
||||
if ((LST_COLDWARM == light_subtype) || (LST_RGBW <= light_subtype)) {
|
||||
if ((LST_COLDWARM == Light.subtype) || (LST_RGBW <= Light.subtype)) {
|
||||
g_gotct = true;
|
||||
change = true;
|
||||
}
|
||||
|
@ -222,7 +222,7 @@ void Ws2812Gradient(uint32_t schemenr)
|
||||
uint32_t range = (uint32_t)ceil((float)Settings.light_pixels / (float)repeat);
|
||||
uint32_t gradRange = (uint32_t)ceil((float)range / (float)(scheme.count - 1));
|
||||
uint32_t speed = ((Settings.light_speed * 2) -1) * (STATES / 10);
|
||||
uint32_t offset = speed > 0 ? strip_timer_counter / speed : 0;
|
||||
uint32_t offset = speed > 0 ? Light.strip_timer_counter / speed : 0;
|
||||
|
||||
WsColor oldColor, currentColor;
|
||||
Ws2812GradientColor(schemenr, &oldColor, range, gradRange, offset);
|
||||
@ -233,9 +233,9 @@ void Ws2812Gradient(uint32_t schemenr)
|
||||
}
|
||||
if (Settings.light_speed > 0) {
|
||||
// Blend old and current color based on time for smooth movement.
|
||||
c.R = map(strip_timer_counter % speed, 0, speed, oldColor.red, currentColor.red);
|
||||
c.G = map(strip_timer_counter % speed, 0, speed, oldColor.green, currentColor.green);
|
||||
c.B = map(strip_timer_counter % speed, 0, speed, oldColor.blue, currentColor.blue);
|
||||
c.R = map(Light.strip_timer_counter % speed, 0, speed, oldColor.red, currentColor.red);
|
||||
c.G = map(Light.strip_timer_counter % speed, 0, speed, oldColor.green, currentColor.green);
|
||||
c.B = map(Light.strip_timer_counter % speed, 0, speed, oldColor.blue, currentColor.blue);
|
||||
}
|
||||
else {
|
||||
// No animation, just use the current color.
|
||||
@ -269,7 +269,7 @@ void Ws2812Bars(uint32_t schemenr)
|
||||
if (kWidth[Settings.light_width] > maxSize) { maxSize = 0; }
|
||||
|
||||
uint32_t speed = ((Settings.light_speed * 2) -1) * (STATES / 10);
|
||||
uint32_t offset = (speed > 0) ? strip_timer_counter / speed : 0;
|
||||
uint32_t offset = (speed > 0) ? Light.strip_timer_counter / speed : 0;
|
||||
|
||||
WsColor mcolor[scheme.count];
|
||||
memcpy(mcolor, scheme.colors, sizeof(mcolor));
|
||||
@ -366,7 +366,7 @@ char* Ws2812GetColor(uint32_t led, char* scolor)
|
||||
sl_ledcolor[1] = lcolor.G;
|
||||
sl_ledcolor[2] = lcolor.B;
|
||||
scolor[0] = '\0';
|
||||
for (uint32_t i = 0; i < light_subtype; i++) {
|
||||
for (uint32_t i = 0; i < Light.subtype; i++) {
|
||||
if (Settings.flag.decimal_text) {
|
||||
snprintf_P(scolor, 25, PSTR("%s%s%d"), scolor, (i > 0) ? "," : "", sl_ledcolor[i]);
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user