gpio setting persistent

This commit is contained in:
martin-ger
2019-02-19 16:58:11 +01:00
parent 43e4cc5d04
commit 804f4bfbea
8 changed files with 83 additions and 54 deletions
+3
View File
@@ -152,6 +152,9 @@ Most of the set-commands are effective only after save and reset.
- set client_watchdog _secs_: sets the client watchdog timeout - if there are no packets received for _secs_ from any connected client the repeater resets ("none" = no timeout, default)
- set vmin _voltage_: sets the minimum battery voltage in mV. If Vdd drops below, the ESP goes into deep sleep. If 0, nothing happens
- set vmin_sleep _secs_: sets the time interval in seconds the ESP sleeps on low voltage
- gpio [0-16] _mode_ [_in_|_in_pullup|_out_]: configures a GPIO port of the ESP (saved to flash)
- gpio [0-16] _set_ [_high_|_low_]: writes to an output port
- gpio [0-16] _get_: reads from an input port
# Status LED
In default config GPIO2 is configured to drive a status LED (connected to GND) with the following indications:
Binary file not shown.
Binary file not shown.
+2 -2
View File
@@ -1,3 +1,3 @@
83db266f74801f2d9236314c6beccb0cd2c085c9 firmware/0x02000.bin
37cc650900e4df9fa368f84a2b49f8d0dc986e59 firmware/0x82000.bin
0b4a8a907b1042cc0a5df43b7e61a98eb6724f3c firmware/0x02000.bin
421d80d57e62bb6e4bad5f3a101c1b9e01037252 firmware/0x82000.bin
9bd7d25204d71b3db5f35e0b2def8a6aaa7f765c firmware/0x00000.bin
+5
View File
@@ -160,6 +160,11 @@ uint32_t reg0, reg1, reg3;
os_sprintf(config->ota_host,"%s", "none");
config->ota_port = 80;
#endif
#if GPIO_CMDS
int i;
for (i=0; i<17; i++)
config->gpiomode[1] = UNDEFINED;
#endif
}
int ICACHE_FLASH_ATTR config_load(sysconfig_p config)
+9
View File
@@ -22,6 +22,12 @@ typedef enum {
AUTOMESH_OFF = 0, AUTOMESH_LEARNING, AUTOMESH_OPERATIONAL
} automeshmode;
#if GPIO_CMDS
typedef enum {
UNDEFINED = 0, OUT, IN, IN_PULLUP
} gpio_mode;
#endif
typedef struct {
// To check if the structure is initialized or not in flash
uint32_t magic_number;
@@ -139,6 +145,9 @@ typedef struct {
uint8_t ota_host[64];
uint16_t ota_port;
#endif
#if GPIO_CMDS
gpio_mode gpiomode[17];
#endif
} sysconfig_t, *sysconfig_p;
int config_load(sysconfig_p config);
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef _USER_CONFIG_
#define _USER_CONFIG_
#define ESP_REPEATER_VERSION "V2.2.5"
#define ESP_REPEATER_VERSION "V2.2.6"
#define LOCAL_ACCESS 0x01
#define REMOTE_ACCESS 0x02
+63 -51
View File
@@ -2530,7 +2530,7 @@ void ICACHE_FLASH_ATTR console_handle_command(struct espconn *pespconn)
if (strcmp(tokens[0], "gpio") == 0)
{
/*
* For gpio commands at least 4 tokens "gpio" pin:"[0-16]" action:"mode|set|get" value:"low|high|out|in" is needed
* For gpio commands at least 4 tokens "gpio" pin:"[0-16]" action:"mode|set|get" value:"low|high|out|in|in_pullup" is needed
* hence the check
* Examples:
* Set GPIO pin 04 mode to output:
@@ -2549,64 +2549,62 @@ void ICACHE_FLASH_ATTR console_handle_command(struct espconn *pespconn)
}
else
{
uint8_t pin;
char *action;
char *value;
pin = atoi(tokens[1]); // 0-16
action = tokens[2]; // mode|set|get
value = tokens[3]; // low|high|out|in
uint16_t pin = atoi(tokens[1]); // 0-16
uint8_t *action = tokens[2]; // mode|set|get
uint8_t *value = nTokens == 4 ? tokens[3] : "";
if ((pin < 0) && (pin > 16))
{
os_sprintf(response, "Invalid pin number (try 0-16)");
goto command_handled;
}
if (!((strcmp(action, "mode") == 0) || (strcmp(action, "set") == 0) || (strcmp(action, "get") == 0)))
{
os_sprintf(response, "Invalid action (try mode, set, or get)");
goto command_handled;
}
if (strcmp(action, "mode") == 0)
{
if (!((strcmp(value, "in") == 0) || (strcmp(value, "out") == 0)))
{
os_sprintf(response, "Invalid mode (try in or out)");
goto command_handled;
}
}
if (strcmp(action, "set") == 0)
{
if (!((strcmp(value, "high") == 0) || (strcmp(value, "low") == 0)))
{
os_sprintf(response, "Invalid value (try low or high)");
goto command_handled;
}
}
if (strcmp(action, "mode") == 0)
{
easygpio_pinMode(pin, EASYGPIO_NOPULL, (strcmp(value, "in") == 0) ? EASYGPIO_INPUT : EASYGPIO_OUTPUT);
}
if (strcmp(action, "set") == 0)
{
easygpio_outputSet(pin, (strcmp(value, "high") == 0) ? 1 : 0);
}
if (strcmp(action, "get") == 0)
{
uint8_t pinVal = easygpio_inputGet(pin);
os_sprintf(response, "%d", pinVal);
os_sprintf_flash(response, "Invalid pin number (try 0-16)\r\n");
goto command_handled;
}
os_sprintf(response, "Successfuly executed %d %s %s\r\n", pin, action, value);
goto command_handled;
if (strcmp(action, "mode")==0)
{
if (strcmp(value, "in")==0)
{
easygpio_pinMode(pin, EASYGPIO_NOPULL, EASYGPIO_INPUT);
config.gpiomode[pin] = IN;
goto command_handled;
}
if (strcmp(value, "out")==0)
{
easygpio_pinMode(pin, EASYGPIO_NOPULL, EASYGPIO_OUTPUT);
config.gpiomode[pin] = OUT;
goto command_handled;
}
if (strcmp(value, "in_pullup")==0)
{
easygpio_pinMode(pin, EASYGPIO_PULLUP, EASYGPIO_OUTPUT);
config.gpiomode[pin] = IN_PULLUP;
goto command_handled;
}
os_sprintf_flash(response, "Invalid mode (in, in_pullup, or out)\r\n");
}
if (strcmp(action, "set")==0)
{
if (strcmp(value, "high")==0)
{
easygpio_outputSet(pin, 1);
goto command_handled;
}
if (strcmp(value, "low")==0)
{
easygpio_outputSet(pin, 0);
goto command_handled;
}
os_sprintf_flash(response, "Invalid value (high or low)\r\n");
}
if (strcmp(action, "get")==0)
{
uint16_t pinVal = easygpio_inputGet(pin);
os_sprintf(response, "%d\r\n", pinVal);
goto command_handled;
}
}
}
#endif
@@ -3637,6 +3635,20 @@ struct espconn *pCon;
easygpio_outputSet(USER_GPIO_OUT, config.gpio_out_status);
#endif
#if GPIO_CMDS
for (i=0; i<17; i++) {
if (config.gpiomode[i] == OUT) {
easygpio_pinMode(i, EASYGPIO_NOPULL, EASYGPIO_OUTPUT);
}
if (config.gpiomode[i] == IN) {
easygpio_pinMode(i, EASYGPIO_NOPULL, EASYGPIO_INPUT);
}
if (config.gpiomode[i] == IN_PULLUP) {
easygpio_pinMode(i, EASYGPIO_PULLUP, EASYGPIO_INPUT);
}
}
#endif
// In Automesh STA and AP passwords and credentials are the same
if (config.automesh_mode != AUTOMESH_OFF) {
os_memcpy(config.ap_ssid, config.ssid, sizeof(config.ssid));