commands to set button or title

pull/111/merge
Ondřej Hruška 7 years ago
parent 373affb582
commit 3f4b8a94f1
  1. 1
      html_orig/css/app.css
  2. 5
      html_orig/js/app.js
  3. 5
      html_orig/jssrc/appcommon.js
  4. 3
      html_orig/lang/en.php
  5. 7
      html_orig/pages/help.php
  6. 1
      html_orig/sass/layout/_menu.scss
  7. 2
      libesphttpd
  8. 247
      user/ansi_parser.c
  9. 5
      user/ansi_parser.h
  10. 29
      user/ansi_parser.rl
  11. 76
      user/ansi_parser_callbacks.c
  12. 3
      user/ansi_parser_callbacks.h
  13. 26
      user/cgi_main.c
  14. 46
      user/cgi_term_cfg.c
  15. 8
      user/screen.c
  16. 6
      user/screen.h

@ -450,6 +450,7 @@ ul > * {
-ms-user-select: none; -ms-user-select: none;
user-select: none; } user-select: none; }
#menu #brand { #menu #brand {
cursor: pointer;
color: white; color: white;
background: #2b6aa8; background: #2b6aa8;
font-size: 120%; font-size: 120%;

@ -999,8 +999,11 @@ $.ready(function () {
x.removeAttribute('tabindex'); x.removeAttribute('tabindex');
}); });
// brand works as a link back to term in widescreen mode
var br = qs('#brand'); var br = qs('#brand');
br && br.removeAttribute('tabindex'); br && br.addEventListener('click', function() {
location.href='/'; // go to terminal
});
} }
}); });

@ -100,8 +100,11 @@ $.ready(function () {
x.removeAttribute('tabindex'); x.removeAttribute('tabindex');
}); });
// brand works as a link back to term in widescreen mode
var br = qs('#brand'); var br = qs('#brand');
br && br.removeAttribute('tabindex'); br && br.addEventListener('click', function() {
location.href='/'; // go to terminal
});
} }
}); });

@ -26,7 +26,8 @@ return [
'term.explain_initials' => ' 'term.explain_initials' => '
Those are the initial settings used after ESPTerm powers on. Those are the initial settings used after ESPTerm powers on.
The selected colors will also be used after receiving a The selected colors will also be used after receiving a
screen- or attributes-reset command.', screen- or attributes-reset command. Those settings will be
applied immediately after saving to preview the changes live.',
'term.example' => 'Default colors preview', 'term.example' => 'Default colors preview',

@ -333,13 +333,6 @@
The screen size and WiFi settings stay unchanged. The screen size and WiFi settings stay unchanged.
</td> </td>
</tr> </tr>
<tr>
<td>\e]FR\a</td>
<td>--</td>
<td>"Factory Reset", emergency code when you mess up the WiFi, restores SSID to unique default, clears
stored credentials & enters Client+AP mode.
</td>
</tr>
<tr> <tr>
<td>\e[5n</td> <td>\e[5n</td>
<td>--</td> <td>--</td>

@ -16,6 +16,7 @@
} }
#brand { #brand {
cursor: pointer;
color: $menu-fg; color: $menu-fg;
background: darken($menu-bg, 10%); background: darken($menu-bg, 10%);
font-size: 120%; font-size: 120%;

@ -1 +1 @@
Subproject commit f3dd1a25993775bec062a1906ced7b07a7fc9db1 Subproject commit 5f0dd3564fe471dc7e9e352951761044b565ac29

@ -10,17 +10,19 @@ static const char _ansi_actions[] = {
0, 1, 0, 1, 1, 1, 2, 1, 0, 1, 0, 1, 1, 1, 2, 1,
3, 1, 4, 1, 5, 1, 6, 1, 3, 1, 4, 1, 5, 1, 6, 1,
7, 1, 8, 1, 9, 1, 10, 1, 7, 1, 8, 1, 9, 1, 10, 1,
11, 1, 12 11, 1, 12, 1, 13, 1, 14, 2,
9, 10, 2, 9, 11
}; };
static const char _ansi_eof_actions[] = { static const char _ansi_eof_actions[] = {
0, 13, 13, 13, 13, 13, 13, 13, 0, 13, 13, 13, 13, 13, 13, 13,
13, 13, 13, 13, 13, 13, 0, 0, 13, 13, 13, 13, 13, 13, 13, 13,
0 13, 13, 13, 13, 13, 13, 13, 13,
13, 13, 0, 0, 0, 0, 0
}; };
static const int ansi_start = 1; static const int ansi_start = 1;
static const int ansi_first_final = 14; static const int ansi_first_final = 26;
static const int ansi_error = 0; static const int ansi_error = 0;
static const int ansi_en_CSI_body = 3; static const int ansi_en_CSI_body = 3;
@ -54,6 +56,8 @@ ansi_parser(const char *newdata, size_t len)
static int csi_ni; //!< Number of the active digit static int csi_ni; //!< Number of the active digit
static int csi_n[CSI_N_MAX]; //!< Param digits static int csi_n[CSI_N_MAX]; //!< Param digits
static char csi_char; //!< CSI action char (end) static char csi_char; //!< CSI action char (end)
static char osc_buffer[OSC_CHAR_MAX];
static int osc_bi;
if (len == 0) len = strlen(newdata); if (len == 0) len = strlen(newdata);
@ -65,17 +69,17 @@ ansi_parser(const char *newdata, size_t len)
// Init Ragel on the first run // Init Ragel on the first run
if (cs == -1) { if (cs == -1) {
/* #line 69 "user/ansi_parser.c" */ /* #line 73 "user/ansi_parser.c" */
{ {
cs = ansi_start; cs = ansi_start;
} }
/* #line 44 "user/ansi_parser.rl" */ /* #line 46 "user/ansi_parser.rl" */
} }
// The parser // The parser
/* #line 79 "user/ansi_parser.c" */ /* #line 83 "user/ansi_parser.c" */
{ {
const char *_acts; const char *_acts;
unsigned int _nacts; unsigned int _nacts;
@ -101,7 +105,7 @@ case 2:
goto tr2; goto tr2;
case 0: case 0:
goto _out; goto _out;
case 14: case 26:
if ( (*p) == 27 ) if ( (*p) == 27 )
goto tr1; goto tr1;
goto tr0; goto tr0;
@ -135,55 +139,118 @@ case 4:
} else } else
goto tr11; goto tr11;
goto tr2; goto tr2;
case 15: case 27:
goto tr2; goto tr2;
case 5: case 5:
switch( (*p) ) { switch( (*p) ) {
case 70: goto tr12; case 66: goto tr12;
case 87: goto tr13; case 84: goto tr13;
case 87: goto tr14;
} }
goto tr2; goto tr2;
case 6: case 6:
if ( (*p) == 82 ) if ( (*p) == 84 )
goto tr14; goto tr15;
goto tr2; goto tr2;
case 7: case 7:
if ( (*p) == 78 )
goto tr16;
goto tr2;
case 8:
if ( 48 <= (*p) && (*p) <= 57 )
goto tr17;
goto tr2;
case 9:
if ( (*p) == 61 )
goto tr18;
goto tr2;
case 10:
if ( (*p) == 27 )
goto tr2;
goto tr19;
case 11:
switch( (*p) ) { switch( (*p) ) {
case 7: goto tr15; case 7: goto tr20;
case 27: goto tr16; case 27: goto tr21;
} }
goto tr19;
case 28:
switch( (*p) ) {
case 7: goto tr20;
case 27: goto tr21;
}
goto tr19;
case 12:
if ( (*p) == 92 )
goto tr22;
goto tr2;
case 29:
goto tr2;
case 13:
if ( (*p) == 73 )
goto tr23;
goto tr2;
case 14:
if ( (*p) == 84 )
goto tr24;
goto tr2;
case 15:
if ( (*p) == 76 )
goto tr25;
goto tr2; goto tr2;
case 16: case 16:
if ( (*p) == 69 )
goto tr26;
goto tr2; goto tr2;
case 8: case 17:
if ( (*p) == 61 )
goto tr27;
goto tr2;
case 18:
if ( (*p) == 27 )
goto tr2;
goto tr28;
case 19:
switch( (*p) ) {
case 7: goto tr29;
case 27: goto tr30;
}
goto tr28;
case 30:
switch( (*p) ) {
case 7: goto tr29;
case 27: goto tr30;
}
goto tr28;
case 20:
if ( (*p) == 92 ) if ( (*p) == 92 )
goto tr15; goto tr31;
goto tr2; goto tr2;
case 9: case 21:
if ( 48 <= (*p) && (*p) <= 57 ) if ( 48 <= (*p) && (*p) <= 57 )
goto tr17; goto tr32;
goto tr2; goto tr2;
case 10: case 22:
if ( (*p) == 59 ) if ( (*p) == 59 )
goto tr18; goto tr33;
if ( 48 <= (*p) && (*p) <= 57 ) if ( 48 <= (*p) && (*p) <= 57 )
goto tr17; goto tr32;
goto tr2; goto tr2;
case 11: case 23:
if ( 48 <= (*p) && (*p) <= 57 ) if ( 48 <= (*p) && (*p) <= 57 )
goto tr19; goto tr34;
goto tr2; goto tr2;
case 12: case 24:
switch( (*p) ) { switch( (*p) ) {
case 7: goto tr20; case 7: goto tr35;
case 27: goto tr21; case 27: goto tr36;
} }
if ( 48 <= (*p) && (*p) <= 57 ) if ( 48 <= (*p) && (*p) <= 57 )
goto tr19; goto tr34;
goto tr2; goto tr2;
case 13: case 25:
if ( (*p) == 92 ) if ( (*p) == 92 )
goto tr20; goto tr35;
goto tr2; goto tr2;
} }
@ -194,21 +261,36 @@ case 13:
tr9: cs = 4; goto f8; tr9: cs = 4; goto f8;
tr10: cs = 4; goto f9; tr10: cs = 4; goto f9;
tr12: cs = 6; goto _again; tr12: cs = 6; goto _again;
tr14: cs = 7; goto _again; tr15: cs = 7; goto _again;
tr16: cs = 8; goto _again; tr16: cs = 8; goto _again;
tr13: cs = 9; goto _again; tr17: cs = 9; goto f8;
tr17: cs = 10; goto f8; tr18: cs = 10; goto _again;
tr18: cs = 11; goto f9; tr19: cs = 11; goto f11;
tr19: cs = 12; goto f8; tr21: cs = 12; goto _again;
tr21: cs = 13; goto _again; tr13: cs = 13; goto _again;
tr3: cs = 14; goto f2; tr23: cs = 14; goto _again;
tr4: cs = 14; goto f3; tr24: cs = 15; goto _again;
tr5: cs = 14; goto f4; tr25: cs = 16; goto _again;
tr6: cs = 14; goto f5; tr26: cs = 17; goto _again;
tr7: cs = 14; goto f6; tr27: cs = 18; goto _again;
tr11: cs = 15; goto f10; tr28: cs = 19; goto f11;
tr15: cs = 16; goto f11; tr30: cs = 20; goto _again;
tr20: cs = 16; goto f12; tr14: cs = 21; goto _again;
tr32: cs = 22; goto f8;
tr33: cs = 23; goto f9;
tr34: cs = 24; goto f8;
tr36: cs = 25; goto _again;
tr3: cs = 26; goto f2;
tr4: cs = 26; goto f3;
tr5: cs = 26; goto f4;
tr6: cs = 26; goto f5;
tr7: cs = 26; goto f6;
tr11: cs = 27; goto f10;
tr20: cs = 28; goto f12;
tr22: cs = 29; goto f13;
tr31: cs = 29; goto f15;
tr35: cs = 29; goto f16;
tr29: cs = 30; goto f14;
f1: _acts = _ansi_actions + 1; goto execFuncs; f1: _acts = _ansi_actions + 1; goto execFuncs;
f4: _acts = _ansi_actions + 3; goto execFuncs; f4: _acts = _ansi_actions + 3; goto execFuncs;
@ -218,24 +300,28 @@ case 13:
f10: _acts = _ansi_actions + 11; goto execFuncs; f10: _acts = _ansi_actions + 11; goto execFuncs;
f0: _acts = _ansi_actions + 13; goto execFuncs; f0: _acts = _ansi_actions + 13; goto execFuncs;
f5: _acts = _ansi_actions + 15; goto execFuncs; f5: _acts = _ansi_actions + 15; goto execFuncs;
f11: _acts = _ansi_actions + 17; goto execFuncs; f16: _acts = _ansi_actions + 17; goto execFuncs;
f12: _acts = _ansi_actions + 19; goto execFuncs; f11: _acts = _ansi_actions + 19; goto execFuncs;
f6: _acts = _ansi_actions + 21; goto execFuncs; f15: _acts = _ansi_actions + 21; goto execFuncs;
f2: _acts = _ansi_actions + 23; goto execFuncs; f13: _acts = _ansi_actions + 23; goto execFuncs;
f3: _acts = _ansi_actions + 25; goto execFuncs; f6: _acts = _ansi_actions + 25; goto execFuncs;
f2: _acts = _ansi_actions + 27; goto execFuncs;
f3: _acts = _ansi_actions + 29; goto execFuncs;
f14: _acts = _ansi_actions + 31; goto execFuncs;
f12: _acts = _ansi_actions + 34; goto execFuncs;
execFuncs: execFuncs:
_nacts = *_acts++; _nacts = *_acts++;
while ( _nacts-- > 0 ) { while ( _nacts-- > 0 ) {
switch ( *_acts++ ) { switch ( *_acts++ ) {
case 0: case 0:
/* #line 55 "user/ansi_parser.rl" */ /* #line 58 "user/ansi_parser.rl" */
{ {
apars_handle_plainchar((*p)); apars_handle_plainchar((*p));
} }
break; break;
case 1: case 1:
/* #line 62 "user/ansi_parser.rl" */ /* #line 65 "user/ansi_parser.rl" */
{ {
// Reset the CSI builder // Reset the CSI builder
csi_leading = csi_char = 0; csi_leading = csi_char = 0;
@ -250,13 +336,13 @@ execFuncs:
} }
break; break;
case 2: case 2:
/* #line 75 "user/ansi_parser.rl" */ /* #line 78 "user/ansi_parser.rl" */
{ {
csi_leading = (*p); csi_leading = (*p);
} }
break; break;
case 3: case 3:
/* #line 79 "user/ansi_parser.rl" */ /* #line 82 "user/ansi_parser.rl" */
{ {
// x10 + digit // x10 + digit
if (csi_ni < CSI_N_MAX) { if (csi_ni < CSI_N_MAX) {
@ -265,13 +351,13 @@ execFuncs:
} }
break; break;
case 4: case 4:
/* #line 86 "user/ansi_parser.rl" */ /* #line 89 "user/ansi_parser.rl" */
{ {
csi_ni++; csi_ni++;
} }
break; break;
case 5: case 5:
/* #line 90 "user/ansi_parser.rl" */ /* #line 93 "user/ansi_parser.rl" */
{ {
csi_char = (*p); csi_char = (*p);
@ -281,14 +367,14 @@ execFuncs:
} }
break; break;
case 6: case 6:
/* #line 98 "user/ansi_parser.rl" */ /* #line 101 "user/ansi_parser.rl" */
{ {
apars_handle_badseq(); apars_handle_badseq();
{cs = 1;goto _again;} {cs = 1;goto _again;}
} }
break; break;
case 7: case 7:
/* #line 115 "user/ansi_parser.rl" */ /* #line 118 "user/ansi_parser.rl" */
{ {
csi_ni = 0; csi_ni = 0;
@ -297,47 +383,64 @@ execFuncs:
csi_n[i] = 0; csi_n[i] = 0;
} }
osc_bi = 0;
osc_buffer[0] = '\0';
{cs = 5;goto _again;} {cs = 5;goto _again;}
} }
break; break;
case 8: case 8:
/* #line 126 "user/ansi_parser.rl" */ /* #line 132 "user/ansi_parser.rl" */
{ {
apars_handle_OSC_FactoryReset(); apars_handle_OSC_SetScreenSize(csi_n[0], csi_n[1]);
{cs = 1;goto _again;} {cs = 1;goto _again;}
} }
break; break;
case 9: case 9:
/* #line 131 "user/ansi_parser.rl" */ /* #line 137 "user/ansi_parser.rl" */
{ {
apars_handle_OSC_SetScreenSize(csi_n[0], csi_n[1]); osc_buffer[osc_bi++] = (*p);
{cs = 1;goto _again;}
} }
break; break;
case 10: case 10:
/* #line 142 "user/ansi_parser.rl" */ /* #line 141 "user/ansi_parser.rl" */
{
osc_buffer[osc_bi++] = '\0';
apars_handle_OSC_SetTitle(osc_buffer);
{cs = 1;goto _again;}
}
break;
case 11:
/* #line 147 "user/ansi_parser.rl" */
{
osc_buffer[osc_bi++] = '\0';
apars_handle_OSC_SetButton(csi_n[0], osc_buffer);
{cs = 1;goto _again;}
}
break;
case 12:
/* #line 159 "user/ansi_parser.rl" */
{ {
// Reset screen // Reset screen
apars_handle_RESET_cmd(); apars_handle_RESET_cmd();
{cs = 1;goto _again;} {cs = 1;goto _again;}
} }
break; break;
case 11: case 13:
/* #line 148 "user/ansi_parser.rl" */ /* #line 165 "user/ansi_parser.rl" */
{ {
apars_handle_saveCursorAttrs(); apars_handle_saveCursorAttrs();
{cs = 1;goto _again;} {cs = 1;goto _again;}
} }
break; break;
case 12: case 14:
/* #line 153 "user/ansi_parser.rl" */ /* #line 170 "user/ansi_parser.rl" */
{ {
apars_handle_restoreCursorAttrs(); apars_handle_restoreCursorAttrs();
{cs = 1;goto _again;} {cs = 1;goto _again;}
} }
break; break;
/* #line 341 "user/ansi_parser.c" */ /* #line 444 "user/ansi_parser.c" */
} }
} }
goto _again; goto _again;
@ -355,7 +458,7 @@ _again:
while ( __nacts-- > 0 ) { while ( __nacts-- > 0 ) {
switch ( *__acts++ ) { switch ( *__acts++ ) {
case 6: case 6:
/* #line 98 "user/ansi_parser.rl" */ /* #line 101 "user/ansi_parser.rl" */
{ {
apars_handle_badseq(); apars_handle_badseq();
{cs = 1; if ( p == pe ) {cs = 1; if ( p == pe )
@ -363,7 +466,7 @@ _again:
goto _again;} goto _again;}
} }
break; break;
/* #line 367 "user/ansi_parser.c" */ /* #line 470 "user/ansi_parser.c" */
} }
} }
} }
@ -371,6 +474,6 @@ goto _again;}
_out: {} _out: {}
} }
/* #line 173 "user/ansi_parser.rl" */ /* #line 190 "user/ansi_parser.rl" */
} }

@ -2,18 +2,21 @@
#define ANSI_PARSER_H #define ANSI_PARSER_H
#include <stdlib.h> #include <stdlib.h>
#include <screen.h>
// Max nr of CSI parameters // Max nr of CSI parameters
#define CSI_N_MAX 3 #define CSI_N_MAX 3
#define OSC_CHAR_MAX TERM_TITLE_LEN
extern void apars_handle_badseq(void); extern void apars_handle_badseq(void);
extern void apars_handle_CSI(char leadchar, int *params, char keychar); extern void apars_handle_CSI(char leadchar, int *params, char keychar);
extern void apars_handle_RESET_cmd(void); extern void apars_handle_RESET_cmd(void);
extern void apars_handle_plainchar(char c); extern void apars_handle_plainchar(char c);
extern void apars_handle_OSC_FactoryReset(void);
extern void apars_handle_OSC_SetScreenSize(int rows, int cols); extern void apars_handle_OSC_SetScreenSize(int rows, int cols);
extern void apars_handle_saveCursorAttrs(void); extern void apars_handle_saveCursorAttrs(void);
extern void apars_handle_restoreCursorAttrs(void); extern void apars_handle_restoreCursorAttrs(void);
extern void apars_handle_OSC_SetButton(int num, const char *buffer);
extern void apars_handle_OSC_SetTitle(const char *buffer);
/** /**
* \brief Linear ANSI chars stream parser * \brief Linear ANSI chars stream parser

@ -30,6 +30,8 @@ ansi_parser(const char *newdata, size_t len)
static int csi_ni; //!< Number of the active digit static int csi_ni; //!< Number of the active digit
static int csi_n[CSI_N_MAX]; //!< Param digits static int csi_n[CSI_N_MAX]; //!< Param digits
static char csi_char; //!< CSI action char (end) static char csi_char; //!< CSI action char (end)
static char osc_buffer[OSC_CHAR_MAX];
static int osc_bi;
if (len == 0) len = strlen(newdata); if (len == 0) len = strlen(newdata);
@ -49,6 +51,7 @@ ansi_parser(const char *newdata, size_t len)
ESC = 27; ESC = 27;
NOESC = (any - ESC); NOESC = (any - ESC);
TOK_ST = ESC '\\'; # String terminator - used for OSC commands TOK_ST = ESC '\\'; # String terminator - used for OSC commands
OSC_END = ('\a' | ESC '\\');
# --- Regular characters to be printed --- # --- Regular characters to be printed ---
@ -120,23 +123,37 @@ ansi_parser(const char *newdata, size_t len)
csi_n[i] = 0; csi_n[i] = 0;
} }
osc_bi = 0;
osc_buffer[0] = '\0';
fgoto OSC_body; fgoto OSC_body;
} }
action OSC_fr { action OSC_resize {
apars_handle_OSC_FactoryReset(); apars_handle_OSC_SetScreenSize(csi_n[0], csi_n[1]);
fgoto main; fgoto main;
} }
action OSC_resize { action OSC_text_char {
apars_handle_OSC_SetScreenSize(csi_n[0], csi_n[1]); osc_buffer[osc_bi++] = fc;
}
action OSC_title {
osc_buffer[osc_bi++] = '\0';
apars_handle_OSC_SetTitle(osc_buffer);
fgoto main;
}
action OSC_button {
osc_buffer[osc_bi++] = '\0';
apars_handle_OSC_SetButton(csi_n[0], osc_buffer);
fgoto main; fgoto main;
} }
OSC_body := ( OSC_body := (
("FR" ('\a' | ESC '\\') @OSC_fr) | ("BTN" digit @CSI_digit '=' (NOESC @OSC_text_char)+ OSC_END @OSC_button) |
('W' (digit @CSI_digit)+ ';' @CSI_semi (digit @CSI_digit)+ ('\a' | ESC '\\') @OSC_resize) ("TITLE=" (NOESC @OSC_text_char)+ OSC_END @OSC_title) |
('W' (digit @CSI_digit)+ ';' @CSI_semi (digit @CSI_digit)+ OSC_END @OSC_resize)
) $!errBadSeq; ) $!errBadSeq;
action RESET_cmd { action RESET_cmd {

@ -9,6 +9,7 @@
#include "screen.h" #include "screen.h"
#include "ansi_parser.h" #include "ansi_parser.h"
#include "uart_driver.h" #include "uart_driver.h"
#include "persist.h"
static char utf_collect[4]; static char utf_collect[4];
static int utf_i = 0; static int utf_i = 0;
@ -256,80 +257,33 @@ void ICACHE_FLASH_ATTR apars_handle_restoreCursorAttrs(void)
void ICACHE_FLASH_ATTR void ICACHE_FLASH_ATTR
apars_handle_RESET_cmd(void) apars_handle_RESET_cmd(void)
{ {
// XXX maybe user wanted to reset the module instead?
screen_reset(); screen_reset();
} }
/** /**
* Handle a factory reset request * Handle a screen resize request
*/ */
void ICACHE_FLASH_ATTR void ICACHE_FLASH_ATTR
apars_handle_OSC_FactoryReset(void) apars_handle_OSC_SetScreenSize(int rows, int cols)
{ {
warn("-------- Factory reset --------"); info("OSC: Set screen size to %d x %d", rows, cols);
dbg("Switching to Client+AP mode");
// Send acknowledgement message to UART0
// User is performing this manually, so we can just print it as string
UART_WriteString(UART0, "\r\nFACTORY RESET\r\n", UART_TIMEOUT_US);
// Disconnect from AP if connected screen_resize(rows, cols);
int opmode = wifi_get_opmode();
if (opmode != SOFTAP_MODE) {
wifi_station_disconnect();
} }
// Both must be enabled so we can manipulate their settings
wifi_set_opmode(STATIONAP_MODE);
// --- AP config ---
dbg("AP WiFi channel: 6");
struct softap_config apconf;
wifi_softap_get_config(&apconf);
apconf.authmode=AUTH_OPEN; // Disable access protection
apconf.channel=6; // Reset channel; user may have set bad channel in the UI
// generate unique AP name
u8 mac[6];
wifi_get_macaddr(SOFTAP_IF, mac);
sprintf((char*)apconf.ssid, "TERM-%02X%02X%02X", mac[3], mac[4], mac[5]);
apconf.ssid_len = (u8)strlen((char*)apconf.ssid);
info("New AP name: %s", (char*)apconf.ssid);
// --- Station ---
dbg("Erasing stored WiFi credentials...");
struct station_config staconf;
wifi_station_get_config(&staconf);
// clear info about SSID
staconf.ssid[0]=0;
staconf.bssid_set=0;
staconf.password[0]=0;
dbg("Commiting changes..."); void ICACHE_FLASH_ATTR
wifi_softap_set_config(&apconf); apars_handle_OSC_SetButton(int num, const char *buffer)
wifi_station_set_config(&staconf); {
strncpy(termconf_scratch.btn[num-1], buffer, TERM_BTN_LEN);
UART_WriteString(UART0, "Factory Reset complete, device reset.\r\n\r\n", UART_TIMEOUT_US); dbg("Term set BTN%d = %s", num, buffer);
// TODO notify
info("*** FACTORY RESET COMPLETE ***");
dbg("Device reset...");
// Reboot to clean STA+AP mode with Channel X & reset AP SSID.
system_restart();
} }
/**
* Handle a screen resize request
*/
void ICACHE_FLASH_ATTR void ICACHE_FLASH_ATTR
apars_handle_OSC_SetScreenSize(int rows, int cols) apars_handle_OSC_SetTitle(const char *buffer)
{ {
info("OSC: Set screen size to %d x %d", rows, cols); strncpy(termconf_scratch.title, buffer, TERM_TITLE_LEN);
dbg("Term set TITLE = %s", buffer);
screen_resize(rows, cols); // TODO notify
} }

@ -5,9 +5,10 @@ void apars_handle_badseq(void);
void apars_handle_CSI(char leadchar, int *params, char keychar); void apars_handle_CSI(char leadchar, int *params, char keychar);
void apars_handle_RESET_cmd(void); void apars_handle_RESET_cmd(void);
void apars_handle_plainchar(char c); void apars_handle_plainchar(char c);
void apars_handle_OSC_FactoryReset(void);
void apars_handle_OSC_SetScreenSize(int rows, int cols); void apars_handle_OSC_SetScreenSize(int rows, int cols);
void apars_handle_saveCursorAttrs(void); void apars_handle_saveCursorAttrs(void);
void apars_handle_restoreCursorAttrs(void); void apars_handle_restoreCursorAttrs(void);
void apars_handle_OSC_SetButton(int num, const char *buffer);
void apars_handle_OSC_SetTitle(const char *buffer);
#endif //ESP_VT100_FIRMWARE_ANSI_PARSER_CALLBACKS_H #endif //ESP_VT100_FIRMWARE_ANSI_PARSER_CALLBACKS_H

@ -23,29 +23,23 @@ httpd_cgi_state ICACHE_FLASH_ATTR tplScreen(HttpdConnData *connData, char *token
} }
char buff[100]; char buff[100];
char buff2[10];
if (streq(token, "term_title")) { if (streq(token, "term_title")) {
httpdSend(connData, termconf->title, -1); httpdSend(connData, termconf_scratch.title, -1);
}
else if (streq(token, "btn1")) {
httpdSend(connData, termconf->btn1, -1);
}
else if (streq(token, "btn2")) {
httpdSend(connData, termconf->btn2, -1);
}
else if (streq(token, "btn3")) {
httpdSend(connData, termconf->btn3, -1);
}
else if (streq(token, "btn4")) {
httpdSend(connData, termconf->btn4, -1);
}
else if (streq(token, "btn5")) {
httpdSend(connData, termconf->btn5, -1);
} }
else if (streq(token, "theme")) { else if (streq(token, "theme")) {
sprintf(buff, "%d", termconf->theme); sprintf(buff, "%d", termconf->theme);
httpdSend(connData, buff, -1); httpdSend(connData, buff, -1);
} }
else {
for (int i = 1; i <= 5; i++) {
sprintf(buff2, "btn%d", i);
if (streq(token, buff2)) {
httpdSend(connData, termconf_scratch.btn[i-1], -1);
}
}
}
return HTTPD_CGI_DONE; return HTTPD_CGI_DONE;
} }

@ -98,29 +98,12 @@ cgiTermCfgSetParams(HttpdConnData *connData)
strncpy_safe(termconf->title, buff, 64); // ATTN those must match the values in strncpy_safe(termconf->title, buff, 64); // ATTN those must match the values in
} }
if (GET_ARG("btn1")) { for (int i = 1; i <= 5; i++) {
dbg("Button1 default text: \"%s\"", buff); sprintf(buff, "btn%d", i);
strncpy_safe(termconf->btn1, buff, 10); if (GET_ARG(buff)) {
dbg("Button%d default text: \"%s\"", i, buff);
strncpy_safe(termconf->btn[i-1], buff, TERM_BTN_LEN);
} }
if (GET_ARG("btn2")) {
dbg("Button1 default text: \"%s\"", buff);
strncpy_safe(termconf->btn2, buff, 10);
}
if (GET_ARG("btn3")) {
dbg("Button1 default text: \"%s\"", buff);
strncpy_safe(termconf->btn3, buff, 10);
}
if (GET_ARG("btn4")) {
dbg("Button1 default text: \"%s\"", buff);
strncpy_safe(termconf->btn4, buff, 10);
}
if (GET_ARG("btn5")) {
dbg("Button1 default text: \"%s\"", buff);
strncpy_safe(termconf->btn5, buff, 10);
} }
if (redir_url_buf[strlen(SET_REDIR_ERR)] == 0) { if (redir_url_buf[strlen(SET_REDIR_ERR)] == 0) {
@ -145,6 +128,7 @@ tplTermCfg(HttpdConnData *connData, char *token, void **arg)
{ {
#define BUFLEN 100 #define BUFLEN 100
char buff[BUFLEN]; char buff[BUFLEN];
char buff2[10];
if (token == NULL) { if (token == NULL) {
// We're done // We're done
@ -171,20 +155,14 @@ tplTermCfg(HttpdConnData *connData, char *token, void **arg)
else if (streq(token, "term_title")) { else if (streq(token, "term_title")) {
strncpy_safe(buff, termconf->title, BUFLEN); strncpy_safe(buff, termconf->title, BUFLEN);
} }
else if (streq(token, "btn1")) { else {
strncpy_safe(buff, termconf->btn1, BUFLEN); for (int i = 1; i <= 5; i++) {
} sprintf(buff2, "btn%d", i);
else if (streq(token, "btn2")) { if (streq(token, buff2)) {
strncpy_safe(buff, termconf->btn2, BUFLEN); strncpy_safe(buff, termconf->btn[i-1], BUFLEN);
} break;
else if (streq(token, "btn3")) {
strncpy_safe(buff, termconf->btn3, BUFLEN);
} }
else if (streq(token, "btn4")) {
strncpy_safe(buff, termconf->btn4, BUFLEN);
} }
else if (streq(token, "btn5")) {
strncpy_safe(buff, termconf->btn5, BUFLEN);
} }
httpdSend(connData, buff, -1); httpdSend(connData, buff, -1);

@ -18,11 +18,9 @@ void terminal_restore_defaults(void)
termconf->width = 26; termconf->width = 26;
termconf->height = 10; termconf->height = 10;
sprintf(termconf->title, "ESPTerm"); sprintf(termconf->title, "ESPTerm");
sprintf(termconf->btn1, "1"); for(int i=1; i <= 5; i++) {
sprintf(termconf->btn2, "2"); sprintf(termconf->btn[i-1], "%d", i);
sprintf(termconf->btn3, "3"); }
sprintf(termconf->btn4, "4");
sprintf(termconf->btn5, "5");
} }
/** /**

@ -47,11 +47,7 @@ typedef struct {
u8 default_bg; u8 default_bg;
u8 default_fg; u8 default_fg;
char title[TERM_TITLE_LEN]; char title[TERM_TITLE_LEN];
char btn1[TERM_BTN_LEN]; char btn[5][TERM_BTN_LEN];
char btn2[TERM_BTN_LEN];
char btn3[TERM_BTN_LEN];
char btn4[TERM_BTN_LEN];
char btn5[TERM_BTN_LEN];
u8 theme; u8 theme;
u8 _filler[ u8 _filler[

Loading…
Cancel
Save