mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-27 21:26:43 +00:00
Add Serial Dimmer
This commit is contained in:
parent
af8a0e95e5
commit
68da6a07bd
@ -213,12 +213,15 @@ static void dispatch_gpio(const char* topic, const char* payload)
|
||||
|
||||
if(topic == strstr_P(topic, PSTR("relay"))) {
|
||||
topic += 5;
|
||||
val = Parser::is_true(payload);
|
||||
|
||||
} else if(topic == strstr_P(topic, PSTR("led"))) {
|
||||
topic += 3;
|
||||
val = atoi(payload);
|
||||
|
||||
} else if(topic == strstr_P(topic, PSTR("pwm"))) {
|
||||
topic += 3;
|
||||
val = atoi(payload);
|
||||
|
||||
} else {
|
||||
LOG_WARNING(TAG_MSGR, F("Invalid gpio %s"), topic);
|
||||
@ -228,7 +231,6 @@ static void dispatch_gpio(const char* topic, const char* payload)
|
||||
if(Parser::is_only_digits(topic)) {
|
||||
pin = atoi(topic);
|
||||
if(strlen(payload) > 0) {
|
||||
val = Parser::is_true(payload);
|
||||
gpio_set_value(pin, val);
|
||||
} else {
|
||||
gpio_get_value(pin);
|
||||
|
@ -24,6 +24,8 @@ hasp_gpio_config_t gpioConfig[HASP_NUM_GPIO_CONFIG] = {
|
||||
};
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
#include "driver/uart.h"
|
||||
|
||||
class TouchConfig : public ButtonConfig {
|
||||
public:
|
||||
TouchConfig();
|
||||
@ -271,6 +273,20 @@ void gpioSetup()
|
||||
ledcSetup(gpioConfig[i].group, 20000, 12);
|
||||
// attach the channel to the GPIO to be controlled
|
||||
ledcAttachPin(gpioConfig[i].pin, gpioConfig[i].group);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case HASP_GPIO_SERIAL_DIMMER:
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
Serial2.begin(115200, SERIAL_8N1, UART_PIN_NO_CHANGE, gpioConfig[i].pin);
|
||||
delay(20);
|
||||
const char command[5] = "\xEF\x01\x4D\xA3"; // Start Lanbon Dimmer
|
||||
Serial2.print(command);
|
||||
|
||||
char buffer[32];
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("Dimmer: %02x %02x %02x %02x"), command[0], command[1],
|
||||
command[2], command[3]);
|
||||
LOG_VERBOSE(TAG_GPIO, buffer);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
@ -306,7 +322,7 @@ void gpio_set_value(hasp_gpio_config_t gpio, int16_t val)
|
||||
inverted = true;
|
||||
case HASP_GPIO_RELAY:
|
||||
gpio.val = val > 0 ? HIGH : LOW;
|
||||
digitalWrite(gpio.pin, inverted ? !gpio.val : gpio.val);
|
||||
digitalWrite(gpio.pin, inverted ? gpio.val : !gpio.val);
|
||||
break;
|
||||
|
||||
case HASP_GPIO_LED_INVERTED:
|
||||
@ -337,6 +353,22 @@ void gpio_set_value(hasp_gpio_config_t gpio, int16_t val)
|
||||
#endif
|
||||
break;
|
||||
|
||||
case HASP_GPIO_SERIAL_DIMMER: {
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
char command[5] = "\xEF\x02\x00\xED";
|
||||
if(gpio.val == 0) {
|
||||
command[2] = 0x20;
|
||||
} else {
|
||||
command[2] = (uint8_t)gpio.val;
|
||||
command[3] ^= command[2];
|
||||
}
|
||||
Serial2.print(command);
|
||||
LOG_VERBOSE(TAG_GPIO, F("%02x %02x %02x %02x"), command[0], command[1], command[2], command[3]);
|
||||
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
@ -82,6 +82,7 @@ bool gpioSetConfig(const JsonObject& settings);
|
||||
#define HASP_GPIO_DAC_INVERTED 0x51
|
||||
#define HASP_GPIO_ADC 0x52
|
||||
#define HASP_GPIO_ADC_INVERTED 0x53
|
||||
#define HASP_GPIO_SERIAL_DIMMER 0x60
|
||||
#define HASP_GPIO_USER 0xFF
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -1453,6 +1453,9 @@ void webHandleGpioConfig()
|
||||
// case HASP_GPIO_PWM_INVERTED:
|
||||
httpMessage += F("PWM");
|
||||
break;
|
||||
case HASP_GPIO_SERIAL_DIMMER:
|
||||
httpMessage += F("Serial Dimmer");
|
||||
break;
|
||||
default:
|
||||
httpMessage += F("Unknown");
|
||||
}
|
||||
@ -1574,6 +1577,9 @@ void webHandleGpioOptions()
|
||||
selected = (conf.type == HASP_GPIO_RELAY) || (conf.type == HASP_GPIO_RELAY_INVERTED);
|
||||
httpMessage += getOption(HASP_GPIO_RELAY, F("Relay"), selected);
|
||||
|
||||
selected = (conf.type == HASP_GPIO_SERIAL_DIMMER);
|
||||
httpMessage += getOption(HASP_GPIO_SERIAL_DIMMER, F("Serial Dimmer"), selected);
|
||||
|
||||
if(digitalPinHasPWM(webServer.arg(0).toInt())) {
|
||||
selected = (conf.type == HASP_GPIO_PWM) || (conf.type == HASP_GPIO_PWM_INVERTED);
|
||||
httpMessage += getOption(HASP_GPIO_PWM, F("PWM"), selected);
|
||||
|
Loading…
x
Reference in New Issue
Block a user