mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-26 12:46:37 +00:00
Add moodlight brightness
This commit is contained in:
parent
637668d9b1
commit
64eeb49a78
@ -42,12 +42,7 @@ uint32_t dispatchLastMillis = -3000000; // force discovery
|
|||||||
uint8_t nCommands = 0;
|
uint8_t nCommands = 0;
|
||||||
haspCommand_t commands[20];
|
haspCommand_t commands[20];
|
||||||
|
|
||||||
struct moodlight_t
|
moodlight_t moodlight = {.brightness = 255};
|
||||||
{
|
|
||||||
uint8_t power;
|
|
||||||
uint8_t r, g, b;
|
|
||||||
};
|
|
||||||
moodlight_t moodlight;
|
|
||||||
|
|
||||||
static void dispatch_config(const char* topic, const char* payload);
|
static void dispatch_config(const char* topic, const char* payload);
|
||||||
// void dispatch_group_value(uint8_t groupid, int16_t state, lv_obj_t * obj);
|
// void dispatch_group_value(uint8_t groupid, int16_t state, lv_obj_t * obj);
|
||||||
@ -705,6 +700,7 @@ void dispatch_moodlight(const char* topic, const char* payload)
|
|||||||
if(!json["r"].isNull()) moodlight.r = json["r"].as<uint8_t>();
|
if(!json["r"].isNull()) moodlight.r = json["r"].as<uint8_t>();
|
||||||
if(!json["g"].isNull()) moodlight.g = json["g"].as<uint8_t>();
|
if(!json["g"].isNull()) moodlight.g = json["g"].as<uint8_t>();
|
||||||
if(!json["b"].isNull()) moodlight.b = json["b"].as<uint8_t>();
|
if(!json["b"].isNull()) moodlight.b = json["b"].as<uint8_t>();
|
||||||
|
if(!json["brightness"].isNull()) moodlight.brightness = json["brightness"].as<uint8_t>();
|
||||||
|
|
||||||
if(!json[F("color")].isNull()) {
|
if(!json[F("color")].isNull()) {
|
||||||
if(!json[F("color")]["r"].isNull()) {
|
if(!json[F("color")]["r"].isNull()) {
|
||||||
@ -725,10 +721,7 @@ void dispatch_moodlight(const char* topic, const char* payload)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if HASP_USE_GPIO > 0
|
#if HASP_USE_GPIO > 0
|
||||||
if(moodlight.power)
|
gpio_set_moodlight(moodlight);
|
||||||
gpio_set_moodlight(moodlight.r, moodlight.g, moodlight.b);
|
|
||||||
else
|
|
||||||
gpio_set_moodlight(0, 0, 0);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -740,8 +733,8 @@ void dispatch_moodlight(const char* topic, const char* payload)
|
|||||||
snprintf_P(
|
snprintf_P(
|
||||||
// buffer, sizeof(buffer),
|
// buffer, sizeof(buffer),
|
||||||
// PSTR("{\"state\":\"%s\",\"color\":\"#%02x%02x%02x\",\"r\":%u,\"g\":%u,\"b\":%u}"),
|
// PSTR("{\"state\":\"%s\",\"color\":\"#%02x%02x%02x\",\"r\":%u,\"g\":%u,\"b\":%u}"),
|
||||||
buffer, sizeof(buffer), PSTR("{\"state\":\"%s\",\"color\":{\"r\":%u,\"g\":%u,\"b\":%u}}"),
|
buffer, sizeof(buffer), PSTR("{\"state\":\"%s\",\"color\":{\"r\":%u,\"g\":%u,\"b\":%u,\"brightness\":%u}}"),
|
||||||
moodlight.power ? "ON" : "OFF", moodlight.r, moodlight.g, moodlight.b);
|
moodlight.power ? "ON" : "OFF", moodlight.r, moodlight.g, moodlight.b, moodlight.brightness);
|
||||||
dispatch_state_subtopic(out_topic, buffer);
|
dispatch_state_subtopic(out_topic, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1000,9 +993,7 @@ void dispatchSetup()
|
|||||||
}
|
}
|
||||||
|
|
||||||
IRAM_ATTR void dispatchLoop()
|
IRAM_ATTR void dispatchLoop()
|
||||||
{
|
{}
|
||||||
lv_task_handler(); // process animations
|
|
||||||
}
|
|
||||||
|
|
||||||
#if 1 || ARDUINO
|
#if 1 || ARDUINO
|
||||||
void dispatchEverySecond()
|
void dispatchEverySecond()
|
||||||
|
@ -575,8 +575,20 @@ bool gpio_set_pin_value(uint8_t pin, int32_t val)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Updates the RGB pins directly, rgb are already normalized values
|
// Updates the RGB pins directly, rgb are already normalized values
|
||||||
void gpio_set_moodlight(uint8_t r, uint8_t g, uint8_t b)
|
void gpio_set_moodlight(moodlight_t& moodlight)
|
||||||
{
|
{
|
||||||
|
uint8_t r = 0;
|
||||||
|
uint8_t g = 0;
|
||||||
|
uint8_t b = 0;
|
||||||
|
|
||||||
|
if(moodlight.power && moodlight.brightness) {
|
||||||
|
r = (moodlight.r * moodlight.brightness + 127) / 255;
|
||||||
|
g = (moodlight.g * moodlight.brightness + 127) / 255;
|
||||||
|
b = (moodlight.b * moodlight.brightness + 127) / 255;
|
||||||
|
} else {
|
||||||
|
moodlight.power = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// RGBXX https://stackoverflow.com/questions/39949331/how-to-calculate-rgbaw-amber-white-from-rgb-for-leds
|
// RGBXX https://stackoverflow.com/questions/39949331/how-to-calculate-rgbaw-amber-white-from-rgb-for-leds
|
||||||
for(uint8_t i = 0; i < HASP_NUM_GPIO_CONFIG; i++) {
|
for(uint8_t i = 0; i < HASP_NUM_GPIO_CONFIG; i++) {
|
||||||
switch(gpioConfig[i].type) {
|
switch(gpioConfig[i].type) {
|
||||||
@ -591,6 +603,16 @@ void gpio_set_moodlight(uint8_t r, uint8_t g, uint8_t b)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(uint8_t i = 0; i < HASP_NUM_GPIO_CONFIG; i++) {
|
||||||
|
switch(gpioConfig[i].type) {
|
||||||
|
case HASP_GPIO_LED_B:
|
||||||
|
case HASP_GPIO_LED_G:
|
||||||
|
case HASP_GPIO_LED_R:
|
||||||
|
LOG_VERBOSE(TAG_GPIO, F(D_BULLET D_GPIO_PIN " %d => %d"), gpioConfig[i].pin, gpioConfig[i].val);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool gpioIsSystemPin(uint8_t gpio)
|
bool gpioIsSystemPin(uint8_t gpio)
|
||||||
|
@ -31,7 +31,7 @@ void gpio_set_normalized_group_values(uint8_t group, int32_t val, int32_t min, i
|
|||||||
// void gpio_set_gpio_state(uint8_t pin, uint16_t state);
|
// void gpio_set_gpio_state(uint8_t pin, uint16_t state);
|
||||||
bool gpio_get_value(uint8_t pin, uint16_t& val);
|
bool gpio_get_value(uint8_t pin, uint16_t& val);
|
||||||
bool gpio_set_pin_value(uint8_t pin, int32_t val);
|
bool gpio_set_pin_value(uint8_t pin, int32_t val);
|
||||||
void gpio_set_moodlight(uint8_t r, uint8_t g, uint8_t b);
|
void gpio_set_moodlight(moodlight_t& moodlight);
|
||||||
|
|
||||||
void gpio_discovery(JsonArray& relay, JsonArray& led);
|
void gpio_discovery(JsonArray& relay, JsonArray& led);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user