mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-25 20:26:41 +00:00
Initial gpio configuration
This commit is contained in:
parent
b24d8b077a
commit
d90b577252
@ -16,6 +16,46 @@ uint16_t gpioConfig[HASP_NUM_GPIO_CONFIG];
|
|||||||
using namespace ace_button;
|
using namespace ace_button;
|
||||||
static AceButton * button[HASP_NUM_INPUTS];
|
static AceButton * button[HASP_NUM_INPUTS];
|
||||||
|
|
||||||
|
struct hasp_gpio_config_t {
|
||||||
|
const uint8_t pin;
|
||||||
|
const uint8_t group;
|
||||||
|
const uint8_t io_mode;
|
||||||
|
bool default_state;
|
||||||
|
};
|
||||||
|
|
||||||
|
// An array of button pins, led pins, and the led states. Cannot be const
|
||||||
|
// because ledState is mutable.
|
||||||
|
hasp_gpio_config_t gpioConfig2[HASP_NUM_GPIO_CONFIG] = {
|
||||||
|
{2, 8, INPUT, LOW},
|
||||||
|
{3, 9, OUTPUT, LOW},
|
||||||
|
{4, 10, INPUT, HIGH},
|
||||||
|
{5, 11, OUTPUT, LOW},
|
||||||
|
{6, 12, INPUT, LOW},
|
||||||
|
};
|
||||||
|
|
||||||
|
#if defined(ARDUINO_ARCH_ESP32)
|
||||||
|
class TouchConfig : public ButtonConfig {
|
||||||
|
public:
|
||||||
|
TouchConfig();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// Number of iterations to sample the capacitive switch. Higher number
|
||||||
|
// provides better smoothing but increases the time taken for a single read.
|
||||||
|
static const uint8_t kSamples = 10;
|
||||||
|
|
||||||
|
// The threshold value which is considered to be a "touch" on the switch.
|
||||||
|
static const long kTouchThreshold = 70;
|
||||||
|
|
||||||
|
int readButton(uint8_t pin) override
|
||||||
|
{
|
||||||
|
// long total = mSensor.capacitiveSensor(kSamples);
|
||||||
|
return (touchRead(pin) > kTouchThreshold) ? LOW : HIGH;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TouchConfig touchConfig();
|
||||||
|
#endif
|
||||||
|
|
||||||
static void gpio_event_cb(AceButton * button, uint8_t eventType, uint8_t buttonState)
|
static void gpio_event_cb(AceButton * button, uint8_t eventType, uint8_t buttonState)
|
||||||
{
|
{
|
||||||
char buffer[16];
|
char buffer[16];
|
||||||
@ -73,13 +113,16 @@ void IRAM_ATTR gpioLoop(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void gpioAddButton(uint8_t pin, uint8_t input_mode, uint8_t default_state, uint8_t channel)
|
void gpioAddButton( uint8_t pin, uint8_t input_mode, uint8_t default_state, uint8_t channel)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
for(i = 0; i < HASP_NUM_INPUTS; i++) {
|
for(i = 0; i < HASP_NUM_INPUTS; i++) {
|
||||||
|
|
||||||
if(!button[i]) {
|
if(!button[i]) {
|
||||||
button[i] = new AceButton(pin, default_state, channel);
|
button[i] = new AceButton(pin, default_state, channel);
|
||||||
|
// button[i]->init(pin, default_state, channel);
|
||||||
|
|
||||||
if(button[i]) {
|
if(button[i]) {
|
||||||
pinMode(pin, input_mode);
|
pinMode(pin, input_mode);
|
||||||
@ -90,9 +133,42 @@ void gpioAddButton(uint8_t pin, uint8_t input_mode, uint8_t default_state, uint8
|
|||||||
buttonConfig->clearFeature(ButtonConfig::kFeatureDoubleClick);
|
buttonConfig->clearFeature(ButtonConfig::kFeatureDoubleClick);
|
||||||
buttonConfig->setFeature(ButtonConfig::kFeatureLongPress);
|
buttonConfig->setFeature(ButtonConfig::kFeatureLongPress);
|
||||||
buttonConfig->clearFeature(ButtonConfig::kFeatureRepeatPress);
|
buttonConfig->clearFeature(ButtonConfig::kFeatureRepeatPress);
|
||||||
buttonConfig->clearFeature(ButtonConfig::kFeatureSuppressClickBeforeDoubleClick); // Causes annoying pauses
|
buttonConfig->clearFeature(
|
||||||
|
ButtonConfig::kFeatureSuppressClickBeforeDoubleClick); // Causes annoying pauses
|
||||||
|
|
||||||
Log.verbose(F("GPIO: Button%d created on pin %d (channel %d) mode %d default %d"), i, pin, channel, input_mode,default_state);
|
Log.verbose(F("GPIO: Button%d created on pin %d (channel %d) mode %d default %d"), i, pin, channel,
|
||||||
|
input_mode, default_state);
|
||||||
|
gpioUsedInputCount = i + 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Log.error(F("GPIO: Failed to create Button%d pin %d (channel %d). All %d slots available are in use!"), i, pin,
|
||||||
|
channel, HASP_NUM_INPUTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
void gpioAddTouchButton( uint8_t pin, uint8_t input_mode, uint8_t default_state, uint8_t channel)
|
||||||
|
{
|
||||||
|
uint8_t i;
|
||||||
|
for(i = 0; i < HASP_NUM_INPUTS; i++) {
|
||||||
|
|
||||||
|
if(!button[i]) {
|
||||||
|
button[i] = new AceButton();
|
||||||
|
|
||||||
|
if(button[i]) {
|
||||||
|
pinMode(pin, input_mode);
|
||||||
|
|
||||||
|
ButtonConfig * buttonConfig = button[i]->getButtonConfig();
|
||||||
|
buttonConfig->setEventHandler(gpio_event_cb);
|
||||||
|
buttonConfig->setFeature(ButtonConfig::kFeatureClick);
|
||||||
|
buttonConfig->clearFeature(ButtonConfig::kFeatureDoubleClick);
|
||||||
|
buttonConfig->setFeature(ButtonConfig::kFeatureLongPress);
|
||||||
|
buttonConfig->clearFeature(ButtonConfig::kFeatureRepeatPress);
|
||||||
|
buttonConfig->clearFeature(
|
||||||
|
ButtonConfig::kFeatureSuppressClickBeforeDoubleClick); // Causes annoying pauses
|
||||||
|
|
||||||
|
Log.verbose(F("GPIO: Button%d created on pin %d (channel %d) mode %d default %d"), i, pin, channel,
|
||||||
|
input_mode, default_state);
|
||||||
gpioUsedInputCount = i + 1;
|
gpioUsedInputCount = i + 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -106,18 +182,24 @@ void gpioSetup()
|
|||||||
{
|
{
|
||||||
aceButtonSetup();
|
aceButtonSetup();
|
||||||
|
|
||||||
//gpioConfig[0] = PD15 * 256 + 5 + (INPUT << 3);
|
// gpioConfig[0] = PD15 * 256 + 5 + (INPUT << 3);
|
||||||
#if defined(ARDUINO_ARCH_ESP8266)
|
#if defined(ARDUINO_ARCH_ESP8266)
|
||||||
gpioAddButton(D2, INPUT_PULLUP, HIGH, 1);
|
gpioAddButton( D2, INPUT_PULLUP, HIGH, 1);
|
||||||
|
pinMode(D1, OUTPUT);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(ARDUINO_ARCH_ESP32)
|
||||||
|
gpioAddButton( D2, INPUT, HIGH, 1);
|
||||||
pinMode(D1, OUTPUT);
|
pinMode(D1, OUTPUT);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for(uint8_t i = 0; i < HASP_NUM_GPIO_CONFIG; i++) {
|
for(uint8_t i = 0; i < HASP_NUM_GPIO_CONFIG; i++) {
|
||||||
uint8_t pin = (gpioConfig[i] >> 8) & 0xFF;
|
uint8_t pin = (gpioConfig[i] >> 8) & 0xFF;
|
||||||
uint8_t channel = gpioConfig[i] & 0b111; // 3bit
|
uint8_t channel = gpioConfig[i] & 0b111; // 3bit
|
||||||
uint8_t input_mode = (gpioConfig[i] >> 3) & 0b11; // 2bit gpio mode
|
uint8_t input_mode = (gpioConfig[i] >> 3) & 0b11; // 2bit gpio mode
|
||||||
uint8_t gpiotype = (gpioConfig[i] >> 5) & 0b111; // 3bit
|
//uint8_t input_mode = gpioConfig[i].io_mode
|
||||||
uint8_t default_state = gpioConfig[i] & 0b1; // 1bit: 0=LOW, 1=HIGH
|
uint8_t gpiotype = (gpioConfig[i] >> 5) & 0b111; // 3bit
|
||||||
|
uint8_t default_state = gpioConfig[i] & 0b1; // 1bit: 0=LOW, 1=HIGH
|
||||||
|
|
||||||
switch(input_mode) {
|
switch(input_mode) {
|
||||||
case 1:
|
case 1:
|
||||||
@ -138,7 +220,7 @@ void gpioSetup()
|
|||||||
switch(gpiotype) {
|
switch(gpiotype) {
|
||||||
case HASP_GPIO_SWITCH:
|
case HASP_GPIO_SWITCH:
|
||||||
case HASP_GPIO_BUTTON:
|
case HASP_GPIO_BUTTON:
|
||||||
// gpioAddButton(pin, input_mode, default_state, channel);
|
// gpioAddButton(gpioConfig[i].io_mode.pin, input_mode, gpioConfig[i].default_state, gpioConfig[i].group);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HASP_GPIO_RELAY:
|
case HASP_GPIO_RELAY:
|
||||||
|
@ -1510,40 +1510,18 @@ void webHandleGpioConfig()
|
|||||||
|
|
||||||
httpMessage += F("<form method='POST' action='/config'>");
|
httpMessage += F("<form method='POST' action='/config'>");
|
||||||
|
|
||||||
uint16_t baudrate = settings[FPSTR(F_CONFIG_BAUD)].as<uint16_t>();
|
httpMessage += F("<table><tr><th>Pin</th><th>Type</th><th>Channel</th><th>Normal</th><th>Options</th></tr>");
|
||||||
httpMessage += F("<p><b>Serial Port</b> <select id='baud' name='baud'>");
|
httpMessage += F("<tr><td>D1</td><td>Button</td><td>1</td><td>High</td><td>Options</td><tr>");
|
||||||
httpMessage += getOption(1, F("Disabled"), baudrate == 1); // Don't use 0 here which is default 115200
|
httpMessage += F("<tr><td>D2</td><td>Switch</td><td>2</td><td>High</td><td>Options</td><tr>");
|
||||||
httpMessage += getOption(960, F("9600"), baudrate == 960);
|
httpMessage += F("<tr><td>D4</td><td>Backligth</td><td>15</td><td>Low</td><td>Options</td><tr>");
|
||||||
httpMessage += getOption(1920, F("19200"), baudrate == 1920);
|
|
||||||
httpMessage += getOption(3840, F("38400"), baudrate == 3840);
|
|
||||||
httpMessage += getOption(5760, F("57600"), baudrate == 5760);
|
|
||||||
httpMessage += getOption(7488, F("74880"), baudrate == 7488);
|
|
||||||
httpMessage += getOption(11520, F("115200"), baudrate == 11520);
|
|
||||||
httpMessage += F("</select></p><p><b>Telemetry Period</b> <i><small>(Seconds, 0=disable)</small></i> "
|
|
||||||
"<input id='teleperiod' required name='teleperiod' type='number' min='0' max='65535' value='");
|
|
||||||
httpMessage += settings[FPSTR(F_DEBUG_TELEPERIOD)].as<String>();
|
|
||||||
httpMessage += F("'></p>");
|
|
||||||
|
|
||||||
httpMessage += F("<b>Syslog Hostame</b> <i><small>(optional)</small></i><input id='host' "
|
for (uint8_t i=0; i<NUM_DIGITAL_PINS; i++) {
|
||||||
"name='host' maxlength=31 placeholder='logserver' value='");
|
httpMessage += F("<tr><td>D4</td><td>Backligth</td><td>15</td><td>Low</td><td>Options</td><tr>");
|
||||||
httpMessage += settings[FPSTR(F_CONFIG_HOST)].as<String>();
|
}
|
||||||
httpMessage += F("'><br/><b>Syslog Port</b> <i><small>(optional)</small></i> <input id='port' required "
|
|
||||||
"name='port' type='number' min='0' max='65535' value='");
|
|
||||||
httpMessage += settings[FPSTR(F_CONFIG_PORT)].as<String>();
|
|
||||||
|
|
||||||
httpMessage += F("'><b>Syslog Facility</b> <select id='log' name='log'>");
|
httpMessage += F("</table>");
|
||||||
uint8_t logid = settings[FPSTR(F_CONFIG_LOG)].as<uint8_t>();
|
|
||||||
for(uint8_t i = 0; i < 8; i++) {
|
|
||||||
httpMessage += getOption(i, String(F("Local")) + i, i == logid);
|
|
||||||
}
|
|
||||||
|
|
||||||
httpMessage += F("</select></br><b>Syslog Protocol</b> <input id='proto' name='proto' type='radio' value='0'");
|
// httpMessage += F("</p><p><button type='submit' name='save' value='debug'>Save Settings</button></p></form>");
|
||||||
if(settings[FPSTR(F_CONFIG_PROTOCOL)].as<uint8_t>() == 0) httpMessage += F(" checked");
|
|
||||||
httpMessage += F(">IETF (RFC 5424) <input id='proto' name='proto' type='radio' value='1'");
|
|
||||||
if(settings[FPSTR(F_CONFIG_PROTOCOL)].as<uint8_t>() == 1) httpMessage += F(" checked");
|
|
||||||
httpMessage += F(">BSD (RFC 3164)");
|
|
||||||
|
|
||||||
httpMessage += F("</p><p><button type='submit' name='save' value='debug'>Save Settings</button></p></form>");
|
|
||||||
|
|
||||||
httpMessage +=
|
httpMessage +=
|
||||||
PSTR("<p><form method='get' action='/config'><button type='submit'>Configuration</button></form></p>");
|
PSTR("<p><form method='get' action='/config'><button type='submit'>Configuration</button></form></p>");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user