Add gpio settings

This commit is contained in:
fvanroie 2020-05-02 16:10:02 +02:00
parent 2936147e50
commit 9ff231532c
3 changed files with 78 additions and 6 deletions

View File

@ -55,7 +55,8 @@ void dispatchOutput(int output, bool state)
#elif defined(STM32F4xx)
digitalWrite(HASP_OUTPUT_PIN, state);
#else
analogWrite(pin, state ? 1023 : 0);
digitalWrite(D1, state);
// analogWrite(pin, state ? 1023 : 0);
#endif
}
}

View File

@ -87,10 +87,10 @@ void gpioAddButton(uint8_t pin, uint8_t input_mode, uint8_t default_state, uint8
ButtonConfig * buttonConfig = button[i]->getButtonConfig();
buttonConfig->setEventHandler(gpio_event_cb);
buttonConfig->setFeature(ButtonConfig::kFeatureClick);
buttonConfig->setFeature(ButtonConfig::kFeatureDoubleClick);
buttonConfig->clearFeature(ButtonConfig::kFeatureDoubleClick);
buttonConfig->setFeature(ButtonConfig::kFeatureLongPress);
buttonConfig->setFeature(ButtonConfig::kFeatureRepeatPress);
buttonConfig->setFeature(ButtonConfig::kFeatureSuppressClickBeforeDoubleClick);
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;
@ -107,7 +107,10 @@ void gpioSetup()
aceButtonSetup();
//gpioConfig[0] = PD15 * 256 + 5 + (INPUT << 3);
gpioAddButton(D1, INPUT_PULLUP, HIGH, 1);
#if defined(ARDUINO_ARCH_ESP8266)
gpioAddButton(D2, INPUT_PULLUP, HIGH, 1);
pinMode(D1, OUTPUT);
#endif
for(uint8_t i = 0; i < HASP_NUM_GPIO_CONFIG; i++) {
uint8_t pin = (gpioConfig[i] >> 8) & 0xFF;

View File

@ -1278,6 +1278,11 @@ void webHandleConfig()
httpMessage +=
F("<p><form method='get' action='/config/hasp'><button type='submit'>HASP Settings</button></form></p>");
#if HASP_USE_GPIO > 0
httpMessage +=
F("<p><form method='get' action='/config/gpio'><button type='submit'>GPIO Settings</button></form></p>");
#endif
httpMessage +=
F("<p><form method='get' action='/config/debug'><button type='submit'>Debug Settings</button></form></p>");
@ -1489,9 +1494,69 @@ void webHandleHttpConfig()
}
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////
void webHandleGpioConfig()
{ // http://plate01/config/gpio
if(!httpIsAuthenticated(F("config/gpio"))) return;
DynamicJsonDocument settings(256);
debugGetConfig(settings.to<JsonObject>());
String httpMessage((char *)0);
httpMessage.reserve(HTTP_PAGE_SIZE);
httpMessage += F("<h1>");
httpMessage += httpGetNodename();
httpMessage += F("</h1><hr>");
httpMessage += F("<form method='POST' action='/config'>");
uint16_t baudrate = settings[FPSTR(F_CONFIG_BAUD)].as<uint16_t>();
httpMessage += F("<p><b>Serial Port</b> <select id='baud' name='baud'>");
httpMessage += getOption(1, F("Disabled"), baudrate == 1); // Don't use 0 here which is default 115200
httpMessage += getOption(960, F("9600"), baudrate == 960);
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' "
"name='host' maxlength=31 placeholder='logserver' value='");
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'>");
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'");
if(settings[FPSTR(F_CONFIG_PROTOCOL)].as<uint8_t>() == 0) httpMessage += F(" checked");
httpMessage += F(">IETF (RFC 5424) &nbsp; <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 +=
PSTR("<p><form method='get' action='/config'><button type='submit'>Configuration</button></form></p>");
webSendPage(httpGetNodename(), httpMessage.length(), false);
webServer.sendContent(httpMessage);
httpMessage.clear();
webSendFooter();
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void webHandleDebugConfig()
{ // http://plate01/config/http
{ // http://plate01/config/debug
if(!httpIsAuthenticated(F("config/debug"))) return;
DynamicJsonDocument settings(256);
@ -1851,6 +1916,9 @@ void httpSetup()
#endif
#if HASP_USE_WIFI > 0
webServer.on(F("/config/wifi"), webHandleWifiConfig);
#endif
#if HASP_USE_GPIO > 0
webServer.on(F("/config/gpio"), webHandleGpioConfig);
#endif
webServer.on(F("/screenshot"), webHandleScreenshot);
webServer.on(F("/saveConfig"), webHandleSaveConfig);