From 5dbb5929467766a452c4a713f6c494f8da181379 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Mon, 30 Oct 2017 21:25:56 +0100 Subject: [PATCH] added OSC for color buttons --- front-end | 2 +- user/apars_osc.c | 4 ++++ user/screen.c | 41 +++++++++++++++++++++++++++++++---------- user/screen.h | 1 + 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/front-end b/front-end index 445d78d..30af1ad 160000 --- a/front-end +++ b/front-end @@ -1 +1 @@ -Subproject commit 445d78d4e18a976902753375351c2a39337dcac2 +Subproject commit 30af1ad2f67cf100541e06ccd3760e9562f2f672 diff --git a/user/apars_osc.c b/user/apars_osc.c index 9be0a6a..40c062b 100644 --- a/user/apars_osc.c +++ b/user/apars_osc.c @@ -44,6 +44,10 @@ handle_espterm_osc(int n0, int n1, char *buffer) // Button message screen_set_button_message(n1, buffer); } + else if (n0 == 30) { + // Button color + screen_set_button_color(n1, buffer); + } else goto bad; return; diff --git a/user/screen.c b/user/screen.c index a940305..366771b 100644 --- a/user/screen.c +++ b/user/screen.c @@ -1218,12 +1218,13 @@ void ICACHE_FLASH_ATTR screen_set_button_text(int num, const char *text) { NOTIFY_LOCK(); - if (num == 1) strncpy(termconf_live.btn1, text, TERM_BTN_LEN); - else if (num == 2) strncpy(termconf_live.btn2, text, TERM_BTN_LEN); - else if (num == 3) strncpy(termconf_live.btn3, text, TERM_BTN_LEN); - else if (num == 4) strncpy(termconf_live.btn4, text, TERM_BTN_LEN); - else if (num == 5) strncpy(termconf_live.btn5, text, TERM_BTN_LEN); + + if (num >= 1 && num <= TERM_BTN_COUNT) { + char *buf = TERM_BTN_N(&termconf_live, num - 1); + strncpy(buf, text, TERM_BTN_MSG_LEN); + } else ansi_warn("Bad button num: %d", num); + NOTIFY_DONE(TOPIC_CHANGE_BUTTONS); } @@ -1236,12 +1237,32 @@ void ICACHE_FLASH_ATTR screen_set_button_message(int num, const char *msg) { NOTIFY_LOCK(); - if (num == 1) strncpy(termconf_live.bm1, msg, TERM_BTN_MSG_LEN); - else if (num == 2) strncpy(termconf_live.bm2, msg, TERM_BTN_MSG_LEN); - else if (num == 3) strncpy(termconf_live.bm3, msg, TERM_BTN_MSG_LEN); - else if (num == 4) strncpy(termconf_live.bm4, msg, TERM_BTN_MSG_LEN); - else if (num == 5) strncpy(termconf_live.bm5, msg, TERM_BTN_MSG_LEN); + + if (num >= 1 && num <= TERM_BTN_COUNT) { + char *buf = TERM_BM_N(&termconf_live, num - 1); + strncpy(buf, msg, TERM_BTN_MSG_LEN); + } else ansi_warn("Bad button num: %d", num); + + NOTIFY_DONE(TOPIC_CHANGE_BUTTONS); +} + +/** + * Helper function to set terminal button label + * @param num - button number 1-5 + * @param str - button text + */ +void ICACHE_FLASH_ATTR +screen_set_button_color(int num, const char *buf) +{ + NOTIFY_LOCK(); + + if (num >= 1 && num <= TERM_BTN_COUNT) { + u32 *fieldptr = &termconf_live.bc1 + (num-1); + xset_term_color("", fieldptr, buf, NULL); + } + else ansi_warn("Bad button num: %d", num); + NOTIFY_DONE(TOPIC_CHANGE_BUTTONS); } diff --git a/user/screen.h b/user/screen.h index f7c2b6f..ca37c8e 100644 --- a/user/screen.h +++ b/user/screen.h @@ -191,6 +191,7 @@ void screen_set_title(const char *title); /** Set a button text */ void screen_set_button_text(int num, const char *text); void screen_set_button_message(int num, const char *msg); +void screen_set_button_color(int num, const char *buf); void screen_set_button_count(int count); /** Change backdrop */ void screen_set_backdrop(const char *url);