add cgi for setting background image

work
Ondřej Hruška 7 years ago
parent ef3b02e68c
commit c0adc253b4
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 2
      front-end
  2. 4
      user/apars_osc.c
  3. 13
      user/cgi_term_cfg.c
  4. 48
      user/screen.c
  5. 10
      user/screen.h
  6. 2
      user/user_main.c

@ -1 +1 @@
Subproject commit d4931c1f3125b5df1ad86c5a755f29c679a9b142
Subproject commit bd933657f453586cd837c84b410d081f2fd958ce

@ -49,6 +49,10 @@ apars_handle_osc(char *buffer)
buffer[0] = 'G';
notify_growl(buffer);
}
else if (n == 70) {
// ESPTerm: backdrop
screen_set_backdrop(buffer);
}
else if (n >= 81 && n <= 85) {
// ESPTerm: action button label
screen_set_button_text(n - 80, buffer);

@ -256,10 +256,16 @@ cgiTermCfgSetParams(HttpdConnData *connData)
if (GET_ARG("term_title")) {
cgi_dbg("Terminal title default text: \"%s\"", buff);
strncpy_safe(termconf->title, buff, 64); // ATTN those must match the values in
strncpy_safe(termconf->title, buff, TERM_TITLE_LEN); // ATTN those must match the values in
topics |= TOPIC_CHANGE_TITLE;
}
if (GET_ARG("backdrop")) {
cgi_dbg("Terminal backdrop url: \"%s\"", buff);
strncpy_safe(termconf->backdrop, buff, TERM_BACKDROP_LEN); // ATTN those must match the values in
topics |= TOPIC_CHANGE_BACKDROP;
}
for (int btn_i = 1; btn_i <= TERM_BTN_COUNT; btn_i++) {
sprintf(buff, "btn%d", btn_i);
if (GET_ARG(buff)) {
@ -416,7 +422,7 @@ cgiTermCfgSetParams(HttpdConnData *connData)
httpd_cgi_state ICACHE_FLASH_ATTR
tplTermCfg(HttpdConnData *connData, char *token, void **arg)
{
#define BUFLEN TERM_TITLE_LEN
#define BUFLEN 100 // large enough for backdrop
char buff[BUFLEN];
char buff2[10];
@ -492,6 +498,9 @@ tplTermCfg(HttpdConnData *connData, char *token, void **arg)
else if (streq(token, "term_title")) {
strncpy_safe(buff, termconf->title, BUFLEN);
}
else if (streq(token, "backdrop")) {
strncpy_safe(buff, termconf->backdrop, BUFLEN);
}
else if (streq(token, "uart_baud")) {
sprintf(buff, "%d", sysconf->uart_baudrate);
}

@ -213,6 +213,7 @@ terminal_restore_defaults(void)
termconf->debugbar = SCR_DEF_DEBUGBAR;
termconf->allow_decopt_12 = SCR_DEF_DECOPT12;
termconf->ascii_debug = SCR_DEF_ASCIIDEBUG;
termconf->backdrop[0] = 0;
}
/**
@ -247,6 +248,11 @@ terminal_apply_settings_noclear(void)
termconf->ascii_debug = SCR_DEF_ASCIIDEBUG;
changed = 1;
}
if (termconf->config_version < 4) {
persist_dbg("termconf: Updating to version %d", 1);
termconf->backdrop[0] = 0;
changed = 1;
}
termconf->config_version = TERMCONF_VERSION;
@ -385,6 +391,7 @@ screen_reset_do(bool size, bool labels)
if (labels) {
strcpy(termconf_live.title, termconf->title);
strcpy(termconf_live.backdrop, termconf->backdrop);
for (int i = 1; i <= TERM_BTN_COUNT; i++) {
strcpy(termconf_live.btn[i], termconf->btn[i]);
@ -394,7 +401,7 @@ screen_reset_do(bool size, bool labels)
termconf_live.show_buttons = termconf->show_buttons;
termconf_live.show_config_links = termconf->show_config_links;
topics |= TOPIC_CHANGE_TITLE | TOPIC_CHANGE_BUTTONS;
topics |= TOPIC_CHANGE_TITLE | TOPIC_CHANGE_BUTTONS | TOPIC_CHANGE_BACKDROP;
}
// initial values in the save buffer in case of receiving restore without storing first
@ -1009,6 +1016,18 @@ screen_set_button_text(int num, const char *text)
NOTIFY_DONE(TOPIC_CHANGE_BUTTONS);
}
/**
* Helper function to set terminalbackdrop
* @param url - url
*/
void ICACHE_FLASH_ATTR
screen_set_backdrop(const char *url)
{
NOTIFY_LOCK();
strncpy(termconf_live.backdrop, url, TERM_BACKDROP_LEN);
NOTIFY_DONE(TOPIC_CHANGE_BACKDROP);
}
/**
* Shift screen upwards
*/
@ -1907,6 +1926,7 @@ screenSerializeToBuffer(char *buffer, size_t buf_len, ScreenNotifyTopics topics,
#define TOPICMARK_BELL '!'
#define TOPICMARK_CURSOR 'C'
#define TOPICMARK_SCREEN 'S'
#define TOPICMARK_BACKDROP 'W'
if (ss == NULL) {
// START!
@ -2025,9 +2045,11 @@ screenSerializeToBuffer(char *buffer, size_t buf_len, ScreenNotifyTopics topics,
bufput_c(TOPICMARK_TITLE);
int len = (int) strlen(termconf_live.title);
memcpy(bb, termconf_live.title, len);
bb += len;
remain -= len;
if (len > 0) {
memcpy(bb, termconf_live.title, len);
bb += len;
remain -= len;
}
bufput_c('\x01');
END_TOPIC
@ -2038,11 +2060,25 @@ screenSerializeToBuffer(char *buffer, size_t buf_len, ScreenNotifyTopics topics,
for (int i = 0; i < TERM_BTN_COUNT; i++) {
int len = (int) strlen(termconf_live.btn[i]);
memcpy(bb, termconf_live.btn[i], len);
if (len > 0) {
memcpy(bb, termconf_live.btn[i], len);
bb += len;
remain -= len;
}
bufput_c('\x01');
}
END_TOPIC
BEGIN_TOPIC(TOPIC_CHANGE_BACKDROP, TERM_BACKDROP_LEN+1+1)
bufput_c(TOPICMARK_BACKDROP);
int len = (int) strlen(termconf_live.backdrop);
if (len > 0) {
memcpy(bb, termconf_live.backdrop, len);
bb += len;
remain -= len;
bufput_c('\x01');
}
bufput_c('\x01');
END_TOPIC
BEGIN_TOPIC(TOPIC_INTERNAL, 45)

@ -38,6 +38,7 @@
#define TERM_BTN_MSG_LEN 10
#define TERM_TITLE_LEN 64
#define TERM_BTN_COUNT 5
#define TERM_BACKDROP_LEN 100
#define SCR_DEF_DISPLAY_TOUT_MS 12
#define SCR_DEF_DISPLAY_COOLDOWN_MS 35
@ -74,8 +75,8 @@ enum CursorShape {
// Size designed for the terminal config structure
// Must be constant to avoid corrupting user config after upgrade
#define TERMCONF_SIZE 300
#define TERMCONF_VERSION 3
#define TERMCONF_SIZE 400
#define TERMCONF_VERSION 4
typedef struct {
u32 width;
@ -100,6 +101,7 @@ typedef struct {
bool debugbar;
bool allow_decopt_12;
bool ascii_debug;
char backdrop[TERM_BACKDROP_LEN];
} TerminalConfigBundle;
// Live config
@ -148,6 +150,8 @@ void screen_resize(int rows, int cols);
void screen_set_title(const char *title);
/** Set a button text */
void screen_set_button_text(int num, const char *text);
/** Change backdrop */
void screen_set_backdrop(const char *url);
// --- Encoding ---
@ -169,6 +173,7 @@ enum ScreenSerializeTopic {
TOPIC_CHANGE_CURSOR = (1<<5),
TOPIC_INTERNAL = (1<<6), // debugging internal state
TOPIC_BELL = (1<<7), // beep
TOPIC_CHANGE_BACKDROP = (1<<8),
TOPIC_FLAG_NOCLEAN = (1<<15), // do not clean dirty extents
// combos
@ -177,6 +182,7 @@ enum ScreenSerializeTopic {
TOPIC_CHANGE_CONTENT_ALL |
TOPIC_CHANGE_CURSOR |
TOPIC_CHANGE_TITLE |
TOPIC_CHANGE_BACKDROP |
TOPIC_CHANGE_BUTTONS,
};

@ -150,6 +150,8 @@ static void ICACHE_FLASH_ATTR user_start(void *unused)
// Critically important for client application if any kind of screen persistence / content re-use is needed
UART_WriteChar(UART0, CAN, UART_TIMEOUT_US); // 0x18 - 24 - CAN
dbg("tsize=%d", sizeof(TerminalConfigBundle));
#if DEBUG_HEAP
// Heap use timer & blink
TIMER_START(&prHeapTimer, prHeapTimerCb, HEAP_TIMER_MS, 1);

Loading…
Cancel
Save