Compare commits

..

1 Commits
master ... work

  1. 2
      front-end
  2. 4
      rel-tpl/flash.sh
  3. 1
      user/api.h
  4. 2
      user/cgi_d2d.c
  5. 191
      user/cgi_system.c
  6. 2
      user/cgi_system.h
  7. 3
      user/config_xmacros.h
  8. 63
      user/io.c
  9. 1
      user/io.h
  10. 2
      user/routes.c
  11. 22
      user/serial.c
  12. 15
      user/syscfg.c
  13. 15
      user/syscfg.h
  14. 1
      user/uart_handler.c
  15. 4
      user/user_main.c
  16. 8
      user/version.h

@ -1 +1 @@
Subproject commit 9aae724df2ce60a144eb9f170bb09bdbd02297df
Subproject commit e25523de11484d306a8cc5cb7b9d3c5839edd916

@ -18,8 +18,8 @@ if [ -z ${ESPTOOL} ]; then
fi
fi
[ -z ${ESPPORT} ] && ESPPORT=/dev/ttyUSB0
[ -z ${ESPBAUD} ] && ESPBAUD=460800
[ -z ESPPORT ] && ESPPORT=/dev/ttyUSB0
[ -z ESPBAUD ] && ESPBAUD=460800
set -x
${ESPTOOL} --port ${ESPPORT} --baud ${ESPBAUD} \

@ -11,6 +11,5 @@
#define API_REBOOT "/api/v1/reboot"
#define API_PING "/api/v1/ping"
#define API_CLEAR "/api/v1/clear"
#define API_GPIO "/api/v1/gpio"
#endif //ESPTERM_API_H

@ -178,7 +178,7 @@ d2d_parse_command(char *msg)
else if (strstarts(msg, "H;")) {
if (request_pending) return false;
// Send a HTTP request
// Send a esp-esp message
msg += 2;
const char *method = NULL;
const char *params = NULL;

@ -10,8 +10,7 @@
#include "cgi_logging.h"
#define SET_REDIR_SUC "/cfg/system"
void buildInputsJson(char *buff);
#define SET_REDIR_ERR SET_REDIR_SUC"?err="
static ETSTimer tmr;
@ -83,18 +82,7 @@ cgiSystemCfgSetParams(HttpdConnData *connData)
char redir_url_buf[100];
char *redir_url = redir_url_buf;
if (GET_ARG("redir")) {
strncpy(redir_url, buff, 40);
u32 len = strlen(buff);
if (len > 40) len = 40;
redir_url += len;
} else {
redir_url += sprintf(redir_url, SET_REDIR_SUC);
}
char *end_of_redir_url = redir_url;
redir_url += sprintf(redir_url, "?err=");
char *end_of_failed_redir_url = redir_url;
redir_url += sprintf(redir_url, SET_REDIR_ERR);
// we'll test if anything was printed by looking for \0 in failed_keys_buf
if (connData->conn == NULL) {
@ -186,16 +174,14 @@ cgiSystemCfgSetParams(HttpdConnData *connData)
(void)redir_url;
(void)uart_changed; // unused
if (*end_of_failed_redir_url == '\0') {
if (redir_url_buf[strlen(SET_REDIR_ERR)] == 0) {
// All was OK
cgi_info("Set system params - success, saving...");
sysconf_apply_settings();
persist_store();
strcpy(end_of_redir_url, "?msg=Settings%20saved%20and%20applied.");
httpdRedirect(connData, redir_url_buf);
httpdRedirect(connData, SET_REDIR_SUC "?msg=Settings%20saved%20and%20applied.");
} else {
cgi_warn("Some settings did not validate, asking for correction");
@ -212,40 +198,6 @@ cgiSystemCfgSetParams(HttpdConnData *connData)
return HTTPD_CGI_DONE;
}
static void tplSystemCfgFill(char *token, char *buff)
{
buff[0] = '\0';
const bool admin = false;
const bool tpl=true;
#define XSTRUCT sysconf
#define X XGET_CGI_FUNC_RETURN
XTABLE_SYSCONF
#undef X
#undef XSTRUCT
if (streq(token, "def_access_name")) {
sprintf(buff, "%s", DEF_ACCESS_NAME);
return;
}
if (streq(token, "def_access_pw")) {
sprintf(buff, "%s", DEF_ACCESS_PW);
return;
}
if (streq(token, "def_admin_pw")) {
sprintf(buff, "%s", DEFAULT_ADMIN_PW);
return;
}
if (streq(token, "gpio_initial")) {
buildInputsJson(buff);
return;
}
}
httpd_cgi_state ICACHE_FLASH_ATTR
tplSystemCfg(HttpdConnData *connData, char *token, void **arg)
@ -258,132 +210,27 @@ tplSystemCfg(HttpdConnData *connData, char *token, void **arg)
return HTTPD_CGI_DONE;
}
tplSystemCfgFill(token, buff);
tplSend(connData, buff, -1);
return HTTPD_CGI_DONE;
}
static ETSTimer tmrPulse;
static void ICACHE_FLASH_ATTR tmrPulseCb(void *arg)
{
u32 mask = sysconf->gpio2_conf==GPIOCONF_OFF ? 0x30 : 0x34;
u32 argu = (u32) arg;
u32 set_on = argu & mask;
u32 set_off = (argu >> 16) & mask;
gpio_output_set(set_off, set_on, 0, 0); // the args are swapped here to achieve the opposite
}
void ICACHE_FLASH_ATTR
buildInputsJson(char *buff)
{
u32 inputs = gpio_input_get();
sprintf(buff, "{\"io2\":%d,\"io4\":%d,\"io5\":%d}",
((inputs&(1<<2)) != 0),
((inputs&(1<<4)) != 0),
((inputs&(1<<5)) != 0)
);
}
/**
* API to set GPIOs
*
* @param connData
* @return
*/
httpd_cgi_state ICACHE_FLASH_ATTR cgiGPIO(HttpdConnData *connData)
{
char buff[32];
if (connData->conn==NULL) {
//Connection aborted. Clean up.
return HTTPD_CGI_DONE;
}
bool set = 0;
u32 inputs = gpio_input_get();
strcpy(buff, ""); // fallback
// args are do2, do4, do5, pulse. Values: 0 - off, 1 - on, t - toggle. pulse is in ms
const bool admin = false;
const bool tpl=true;
s8 set_d2 = -1, set_d4 = -1, set_d5 = -1;
if (sysconf->gpio2_conf == GPIOCONF_OUT_START_0 || sysconf->gpio2_conf == GPIOCONF_OUT_START_1) {
if (GET_ARG("do2")) {
if (buff[0] == 't') {
set = ((inputs & (1<<2)) == 0);
} else {
set = buff[0] == '1';
}
set_d2 = set;
gpio_output_set((uint32) (set << 2), (uint32) ((!set) << 2), 0, 0);
}
}
#define XSTRUCT sysconf
#define X XGET_CGI_FUNC
XTABLE_SYSCONF
#undef X
#undef XSTRUCT
if (sysconf->gpio4_conf == GPIOCONF_OUT_START_0 || sysconf->gpio4_conf == GPIOCONF_OUT_START_1) {
if (GET_ARG("do4")) {
if (buff[0] == 't') {
set = ((inputs & (1<<4)) == 0);
} else {
set = buff[0] == '1';
}
set_d4 = set;
gpio_output_set((uint32) (set << 4), (uint32) ((!set) << 4), 0, 0);
}
if (streq(token, "def_access_name")) {
sprintf(buff, "%s", DEF_ACCESS_NAME);
}
if (sysconf->gpio5_conf == GPIOCONF_OUT_START_0 || sysconf->gpio5_conf == GPIOCONF_OUT_START_1) {
if (GET_ARG("do5")) {
if (buff[0] == 't') {
set = ((inputs & (1<<5)) == 0);
} else {
set = buff[0] == '1';
}
set_d5 = set;
gpio_output_set((uint32) (set << 5), (uint32) ((!set) << 5), 0, 0);
}
else if (streq(token, "def_access_pw")) {
sprintf(buff, "%s", DEF_ACCESS_PW);
}
if (GET_ARG("pulse")) {
int duration = atoi(buff);
if (duration > 0) {
u32 cmd = 0;
if (set_d2 != -1) {
if (set_d2) { cmd |= 1<<2; } else { cmd |= 1<<(16+2); }
}
if (set_d4 != -1) {
if (set_d4) { cmd |= 1<<4; } else { cmd |= 1<<(16+4); }
}
if (set_d5 != -1) {
if (set_d5) { cmd |= 1<<5; } else { cmd |= 1<<(16+5); }
}
os_timer_disarm(&tmrPulse);
os_timer_setfn(&tmrPulse, tmrPulseCb, (void*) cmd);
os_timer_arm(&tmrPulse, duration, false);
}
else if (streq(token, "def_admin_pw")) {
sprintf(buff, "%s", DEFAULT_ADMIN_PW);
}
httpdStartResponse(connData, 200);
httpdHeader(connData, "Content-Type", "application/json");
httpdEndHeaders(connData);
// refresh inputs
buildInputsJson(buff);
httpdSend(connData, buff, -1);
tplSend(connData, buff, -1);
return HTTPD_CGI_DONE;
}
/** "GPIO" page */
httpd_cgi_state ICACHE_FLASH_ATTR
tplGpio(HttpdConnData *connData, char *token, void **arg)
{
return tplSystemCfg(connData, token, arg);
}

@ -9,7 +9,5 @@ httpd_cgi_state cgiResetDevice(HttpdConnData *connData);
httpd_cgi_state cgiSystemCfgSetParams(HttpdConnData *connData);
httpd_cgi_state tplSystemCfg(HttpdConnData *connData, char *token, void **arg);
httpd_cgi_state cgiResetScreen(HttpdConnData *connData);
httpd_cgi_state cgiGPIO(HttpdConnData *connData);
httpd_cgi_state tplGpio(HttpdConnData *connData, char *token, void **arg);
#endif // CGI_PING_H

@ -88,9 +88,6 @@ enum xset_result xset_ustring(const char *name, u8 *field, const char *buff, con
#define XGET_CGI_FUNC(type, name, suffix, deref, xget, xset, xsarg, xnotify, allow) \
if ((allow) && streq(token, #name)) xget(buff, deref XSTRUCT->name);
#define XGET_CGI_FUNC_RETURN(type, name, suffix, deref, xget, xset, xsarg, xnotify, allow) \
if ((allow) && streq(token, #name)) { xget(buff, deref XSTRUCT->name); return; }
#define XSTRUCT_FIELD(type, name, suffix, deref, xget, xset, xsarg, xnotify, allow) \
type name suffix;

@ -98,10 +98,7 @@ static void ICACHE_FLASH_ATTR resetBtnTimerCb(void *arg) {
} else {
// Switch LED pins back to UART mode
PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD);
if (sysconf->gpio2_conf == GPIOCONF_OFF) {
// only if uart is enabled
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_U1TXD_BK);
}
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_U1TXD_BK);
if (resetCnt>=12) { //6 secs pressed - FR (timer is at 500 ms)
info("Restoring to default settings via BOOT button!");
@ -143,61 +140,3 @@ void ICACHE_FLASH_ATTR ioInit() {
}
}
struct pinmapping {
bool set;
bool reset;
bool enable;
bool disable;
bool input;
bool pullup;
};
void ICACHE_FLASH_ATTR userGpioInit(void)
{
const struct pinmapping pin_mappings[5] = {
// S R E D I P
{0, 1, 0, 1, 0, 0}, // OFF
{0, 1, 1, 0, 0, 0}, // OUT 0
{1, 0, 1, 0, 0, 0}, // OUT 1
{0, 0, 0, 1, 1, 1}, // IN PULL
{0, 0, 0, 1, 1, 0}, // IN NOPULL
};
u8 num;
const struct pinmapping *pm;
// GPIO2
num = 2;
pm = &pin_mappings[sysconf->gpio2_conf];
gpio_output_set((uint32) (pm->set << num), (uint32) (pm->reset << num), (uint32) (pm->enable << num), (uint32) (pm->disable << num));
if (pm->pullup) {
PIN_PULLUP_EN(PERIPHS_IO_MUX_GPIO2_U);
} else {
PIN_PULLUP_DIS(PERIPHS_IO_MUX_GPIO2_U);
}
if (sysconf->gpio2_conf == GPIOCONF_OFF) {
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_U1TXD_BK);
} else {
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2);
}
// GPIO4
num = 4;
pm = &pin_mappings[sysconf->gpio4_conf];
gpio_output_set((uint32) (pm->set << num), (uint32) (pm->reset << num), (uint32) (pm->enable << num), (uint32) (pm->disable << num));
if (pm->pullup) {
PIN_PULLUP_EN(PERIPHS_IO_MUX_GPIO4_U);
} else {
PIN_PULLUP_DIS(PERIPHS_IO_MUX_GPIO4_U);
}
// GPIO5
num = 5;
pm = &pin_mappings[sysconf->gpio5_conf];
gpio_output_set((uint32) (pm->set << num), (uint32) (pm->reset << num), (uint32) (pm->enable << num), (uint32) (pm->disable << num));
if (pm->pullup) {
PIN_PULLUP_EN(PERIPHS_IO_MUX_GPIO5_U);
} else {
PIN_PULLUP_DIS(PERIPHS_IO_MUX_GPIO5_U);
}
}

@ -2,6 +2,5 @@
#define IO_H
void ioInit(void);
void userGpioInit(void);
#endif

@ -103,7 +103,6 @@ const HttpdBuiltInUrl routes[] ESP_CONST_DATA = {
ROUTE_TPL_FILE("/", tplScreen, "/term.tpl"),
ROUTE_TPL_FILE("/about/?", tplAbout, "/about.tpl"),
ROUTE_FILE("/help/?", "/help.html"),
ROUTE_TPL_FILE("/cfg/gpio/?", tplGpio, "/cfg_gpio.tpl"),
// --- Sockets ---
ROUTE_WS(URL_WS_UPDATE, updateSockConnect),
@ -115,7 +114,6 @@ const HttpdBuiltInUrl routes[] ESP_CONST_DATA = {
ROUTE_CGI(API_PING"/?", cgiPing),
ROUTE_CGI(API_CLEAR"/?", cgiResetScreen),
ROUTE_CGI(API_D2D_MSG"/?", cgiD2DMessage),
ROUTE_CGI(API_GPIO"/?", cgiGPIO),
ROUTE_REDIRECT("/cfg/?", "/cfg/wifi"),

@ -11,12 +11,10 @@ static ETSTimer flushLogTimer;
static void buf_putc(char c)
{
if (sysconf->gpio2_conf == GPIOCONF_OFF) {
if (lb_ls != lb_nw) {
logbuf[lb_nw++] = c;
if (lb_nw >= DEBUG_LOGBUF_SIZE) lb_nw = 0;
}
}
if (lb_ls != lb_nw) {
logbuf[lb_nw++] = c;
if (lb_nw >= DEBUG_LOGBUF_SIZE) lb_nw = 0;
}
}
static void ICACHE_FLASH_ATTR
@ -44,9 +42,7 @@ buf_pop(void *unused)
LOCAL void my_putc(char c)
{
if (sysconf->gpio2_conf == GPIOCONF_OFF) {
UART_WriteCharCRLF(UART1, (u8) c, 200);
}
UART_WriteCharCRLF(UART1, (u8) c, 200);
}
/**
@ -83,14 +79,6 @@ void ICACHE_FLASH_ATTR serialInit(void)
UART_SetStopBits(UART0, (UartStopBitsNum) sysconf->uart_stopbits);
UART_SetBaudrate(UART0, sysconf->uart_baudrate);
// GPIO2 may be used as a remotely controlled GPIO
if (sysconf->gpio2_conf == GPIOCONF_OFF) {
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_U1TXD_BK);
} else {
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2);
// further config of the GPIO will be done in persist.c after calling this func
}
info("COM SERIAL: %d baud, %s parity, %s stopbit(s)",
sysconf->uart_baudrate,
(sysconf->uart_parity == PARITY_NONE ? "NONE" : (sysconf->uart_parity == PARITY_ODD ? "ODD" : "EVEN")),

@ -7,7 +7,6 @@
#include "uart_driver.h"
#include "serial.h"
#include "cgi_logging.h"
#include "io.h"
SystemConfigBundle * const sysconf = &persist.current.sysconf;
@ -120,14 +119,6 @@ sysconf_apply_settings(void)
changed = true;
}
if (sysconf->config_version < 2) {
dbg("Upgrading syscfg to v 2");
sysconf->gpio2_conf = GPIOCONF_OFF;
sysconf->gpio4_conf = GPIOCONF_OUT_START_0;
sysconf->gpio5_conf = GPIOCONF_OUT_START_0;
changed = true;
}
sysconf->config_version = SYSCONF_VERSION;
if (changed) {
@ -137,9 +128,6 @@ sysconf_apply_settings(void)
// uart settings live here, but the CGI handler + form has been moved to the Terminal config page
serialInit();
// initialize user GPIOs
userGpioInit();
system_update_cpu_freq((uint8) (sysconf->overclock ? 160 : 80));
}
@ -155,7 +143,4 @@ sysconf_restore_defaults(void)
strcpy((char *)sysconf->access_pw, DEF_ACCESS_PW);
strcpy((char *)sysconf->access_name, DEF_ACCESS_NAME);
sysconf->overclock = false;
sysconf->gpio2_conf = GPIOCONF_OFF; // means 'use debug uart'
sysconf->gpio4_conf = GPIOCONF_OUT_START_0;
sysconf->gpio5_conf = GPIOCONF_OUT_START_0;
}

@ -11,7 +11,7 @@
// Size designed for the wifi config structure
// Must be constant to avoid corrupting user config after upgrade
#define SYSCONF_SIZE 300
#define SYSCONF_VERSION 2
#define SYSCONF_VERSION 1
#define DEF_ACCESS_PW "1234"
#define DEF_ACCESS_NAME "espterm"
@ -25,14 +25,6 @@ enum pwlock {
PWLOCK_MAX = 5,
};
enum gpioconf {
GPIOCONF_OFF = 0,
GPIOCONF_OUT_START_0 = 1,
GPIOCONF_OUT_START_1 = 2,
GPIOCONF_IN_PULL = 3,
GPIOCONF_IN_NOPULL = 4,
};
//....Type................Name..Suffix...............Deref..XGET............XSET.........................NOTIFY....Allow
// Deref is used to pass the field to xget. Cast is used to convert the &'d field to what xset wants (needed for static arrays)
#define XTABLE_SYSCONF \
@ -47,9 +39,7 @@ enum gpioconf {
X(uchar, access_name, [32], /**/, xget_ustring, xset_ustring, NULL, /**/, admin|tpl) \
\
X(bool, overclock, /**/, /**/, xget_bool, xset_bool, NULL, /**/, 1) \
X(u8, gpio2_conf, /**/, /**/, xget_dec, xset_u8, NULL, /**/, 1) \
X(u8, gpio4_conf, /**/, /**/, xget_dec, xset_u8, NULL, /**/, 1) \
X(u8, gpio5_conf, /**/, /**/, xget_dec, xset_u8, NULL, /**/, 1)
typedef struct {
#define X XSTRUCT_FIELD
@ -64,7 +54,6 @@ typedef struct {
// char access_pw[64]; // access password
// char access_name[32]; // access name
// bool overclock;
// bool debug_uart;
} SystemConfigBundle;
extern SystemConfigBundle * const sysconf;

@ -56,7 +56,6 @@ void ICACHE_FLASH_ATTR UART_Init(void)
// U1TXD (GPIO2)
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_U1TXD_BK);
PIN_PULLUP_DIS(PERIPHS_IO_MUX_GPIO2_U);
// Configure the UART peripherals
UART_SetWordLength(UART0, EIGHT_BITS); // main

@ -96,8 +96,6 @@ static ETSTimer prHeapTimer;
//Main routine. Initialize stdout, the I/O, filesystem and the webserver and we're done.
void ICACHE_FLASH_ATTR user_init(void)
{
sysconf->gpio2_conf = GPIOCONF_OFF; // enable debug UART for the start-up (sysconf is not loaded yet)
ansi_parser_inhibit = true;
serialInitBase();
@ -112,7 +110,7 @@ void ICACHE_FLASH_ATTR user_init(void)
banner_gap();
banner("================ ESPTerm ================");
banner_info();
banner_info("Project by Ondrej Hruska, 2017-2018");
banner_info("Project by Ondrej Hruska, 2017");
banner_info();
banner_info(TERMINAL_GITHUB_REPO_NOPROTO);
banner_info();

@ -9,10 +9,10 @@
#define STR(x) STR_HELPER(x)
#define FW_V_MAJOR 2
#define FW_V_MINOR 4
#define FW_V_PATCH 0
#define FW_V_SUFFIX "-pre2"
#define FW_CODENAME "Damselfly"
#define FW_V_MINOR 3
#define FW_V_PATCH 1
#define FW_V_SUFFIX ""
#define FW_CODENAME "Cricket" // 2.3
#define FW_CODENAME_QUOTED "\""FW_CODENAME"\""
#define FW_VERSION STR(FW_V_MAJOR) "." STR(FW_V_MINOR) "." STR(FW_V_PATCH) FW_V_SUFFIX

Loading…
Cancel
Save