mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-24 11:46:34 +00:00
Make output state stick
This commit is contained in:
parent
9cda7d9d66
commit
a1ae1f8d52
@ -210,12 +210,10 @@ static void dispatch_gpio(const char* topic, const char* payload)
|
||||
{
|
||||
#if HASP_USE_GPIO > 0
|
||||
|
||||
int16_t val;
|
||||
uint8_t pin;
|
||||
|
||||
if(topic == strstr_P(topic, PSTR("output"))) topic += 6;
|
||||
|
||||
if(Parser::is_only_digits(topic)) {
|
||||
int16_t val;
|
||||
uint8_t pin;
|
||||
|
||||
pin = atoi(topic);
|
||||
if(strlen(payload) > 0) {
|
||||
|
||||
@ -251,13 +249,13 @@ void dispatch_command(const char* topic, const char* payload)
|
||||
|
||||
/* =============================== Not standard payload commands ===================================== */
|
||||
|
||||
if(topic == strstr_P(topic, PSTR("gpio/"))) {
|
||||
// if(topic == strstr_P(topic, PSTR("gpio/"))) {
|
||||
if(topic == strstr_P(topic, PSTR("output"))) {
|
||||
|
||||
dispatch_gpio(topic + 5, payload);
|
||||
dispatch_gpio(topic + 6, payload);
|
||||
|
||||
// } else if(strcasecmp_P(topic, PSTR("screenshot")) == 0) {
|
||||
// guiTakeScreenshot("/screenshot.bmp"); // Literal String
|
||||
|
||||
} else if((topic[0] == 'p' || topic[0] == 'P') && dispatch_parse_button_attribute(topic, payload)) {
|
||||
return; // matched pxby.attr
|
||||
|
||||
@ -284,7 +282,6 @@ void dispatch_command(const char* topic, const char* payload)
|
||||
#endif // HASP_USE_MQTT
|
||||
|
||||
#endif // HASP_USE_CONFIG
|
||||
|
||||
} else {
|
||||
if(strlen(payload) == 0) {
|
||||
// dispatch_text_line(topic); // Could cause an infinite loop!
|
||||
|
@ -324,7 +324,7 @@ void gpio_get_value(hasp_gpio_config_t gpio)
|
||||
{
|
||||
char payload[32];
|
||||
char topic[12];
|
||||
snprintf_P(topic, sizeof(topic), PSTR("gpio%d"), gpio.pin);
|
||||
snprintf_P(topic, sizeof(topic), PSTR("output%d"), gpio.pin);
|
||||
snprintf_P(payload, sizeof(payload), PSTR("%d"), gpio.val);
|
||||
|
||||
dispatch_state_subtopic(topic, payload);
|
||||
@ -333,12 +333,12 @@ void gpio_get_value(hasp_gpio_config_t gpio)
|
||||
void gpio_get_value(uint8_t pin)
|
||||
{
|
||||
for(uint8_t i = 0; i < HASP_NUM_GPIO_CONFIG; i++) {
|
||||
if(gpioConfig[i].pin == pin) return gpio_get_value(gpioConfig[i]);
|
||||
if(gpioConfig[i].pin == pin && gpioConfigInUse(i)) return gpio_get_value(gpioConfig[i]);
|
||||
}
|
||||
LOG_WARNING(TAG_GPIO, F(D_BULLET "Pin %d is not configured"), pin);
|
||||
}
|
||||
|
||||
void gpio_set_value(hasp_gpio_config_t gpio, int16_t val)
|
||||
void gpio_set_value(hasp_gpio_config_t& gpio, int16_t val)
|
||||
{
|
||||
bool inverted = false;
|
||||
|
||||
@ -405,7 +405,7 @@ void gpio_set_value(hasp_gpio_config_t gpio, int16_t val)
|
||||
void gpio_set_value(uint8_t pin, int16_t val)
|
||||
{
|
||||
for(uint8_t i = 0; i < HASP_NUM_GPIO_CONFIG; i++) {
|
||||
if(gpioConfig[i].pin == pin) return gpio_set_value(gpioConfig[i], val);
|
||||
if(gpioConfig[i].pin == pin && gpioConfigInUse(i)) return gpio_set_value(gpioConfig[i], val);
|
||||
}
|
||||
LOG_WARNING(TAG_GPIO, F(D_BULLET "Pin %d is not configured"), pin);
|
||||
}
|
||||
@ -666,6 +666,7 @@ void gpio_discovery(JsonArray& relay, JsonArray& led)
|
||||
case HASP_GPIO_LED_R_INVERTED:
|
||||
case HASP_GPIO_LED_G_INVERTED:
|
||||
case HASP_GPIO_LED_B_INVERTED:
|
||||
case HASP_GPIO_SERIAL_DIMMER:
|
||||
led.add(gpioConfig[i].pin);
|
||||
break;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user