added info about the new commands to help. also e]FRa is removed bc it is no longer useful for anything
This commit is contained in:
@@ -276,14 +276,14 @@ void ICACHE_FLASH_ATTR
|
||||
apars_handle_OSC_SetButton(int num, const char *buffer)
|
||||
{
|
||||
strncpy(termconf_scratch.btn[num-1], buffer, TERM_BTN_LEN);
|
||||
dbg("Term set BTN%d = %s", num, buffer);
|
||||
// TODO notify
|
||||
info("OSC: Set BTN%d = %s", num, buffer);
|
||||
screen_notifyChange(CHANGE_LABELS);
|
||||
}
|
||||
|
||||
void ICACHE_FLASH_ATTR
|
||||
apars_handle_OSC_SetTitle(const char *buffer)
|
||||
{
|
||||
strncpy(termconf_scratch.title, buffer, TERM_TITLE_LEN);
|
||||
dbg("Term set TITLE = %s", buffer);
|
||||
// TODO notify
|
||||
info("OSC: Set TITLE = %s", buffer);
|
||||
screen_notifyChange(CHANGE_LABELS);
|
||||
}
|
||||
|
||||
+59
-6
@@ -9,9 +9,28 @@
|
||||
#define SOCK_BUF_LEN 2048
|
||||
static char sock_buff[SOCK_BUF_LEN];
|
||||
|
||||
static void notifyTimCb(void *arg) {
|
||||
volatile bool notify_available = true;
|
||||
|
||||
static ETSTimer notifyTim;
|
||||
static ETSTimer notifyTim2;
|
||||
|
||||
// we're trying to do a kind of mutex here, without the actual primitives
|
||||
// this might glitch, very rarely.
|
||||
// it's recommended to put some delay between setting labels and updating the screen.
|
||||
|
||||
static void ICACHE_FLASH_ATTR
|
||||
notifyTimCb(void *arg) {
|
||||
void *data = NULL;
|
||||
|
||||
if (!notify_available) {
|
||||
// postpone a little
|
||||
os_timer_disarm(¬ifyTim);
|
||||
os_timer_setfn(¬ifyTim, notifyTimCb, NULL);
|
||||
os_timer_arm(¬ifyTim, 1, 0);
|
||||
return;
|
||||
}
|
||||
notify_available = false;
|
||||
|
||||
for (int i = 0; i < 20; i++) {
|
||||
httpd_cgi_state cont = screenSerializeToBuffer(sock_buff, SOCK_BUF_LEN, &data);
|
||||
int flg = 0;
|
||||
@@ -21,21 +40,53 @@ static void notifyTimCb(void *arg) {
|
||||
if (cont == HTTPD_CGI_DONE) break;
|
||||
}
|
||||
|
||||
// cleanup
|
||||
screenSerializeToBuffer(NULL, SOCK_BUF_LEN, &data);
|
||||
|
||||
notify_available = true;
|
||||
}
|
||||
|
||||
static void ICACHE_FLASH_ATTR
|
||||
notifyLabelsTimCb(void *arg)
|
||||
{
|
||||
if (!notify_available) {
|
||||
// postpone a little
|
||||
os_timer_disarm(¬ifyTim2);
|
||||
os_timer_setfn(¬ifyTim2, notifyLabelsTimCb, NULL);
|
||||
os_timer_arm(¬ifyTim2, 1, 0);
|
||||
return;
|
||||
}
|
||||
notify_available = false;
|
||||
|
||||
screenSerializeLabelsToBuffer(sock_buff, SOCK_BUF_LEN);
|
||||
cgiWebsockBroadcast(URL_WS_UPDATE, sock_buff, (int) strlen(sock_buff), 0);
|
||||
|
||||
notify_available = true;
|
||||
}
|
||||
|
||||
static ETSTimer notifyTim;
|
||||
|
||||
/**
|
||||
* Broadcast screen state to sockets.
|
||||
* This is a callback for the Screen module,
|
||||
* called after each visible screen modification.
|
||||
*/
|
||||
void ICACHE_FLASH_ATTR screen_notifyChange(void)
|
||||
void ICACHE_FLASH_ATTR screen_notifyChange(ScreenNotifyChangeTopic topic)
|
||||
{
|
||||
os_timer_disarm(¬ifyTim);
|
||||
os_timer_setfn(¬ifyTim, notifyTimCb, NULL);
|
||||
os_timer_arm(¬ifyTim, 20, 0);
|
||||
// this is not the most ideal/cleanest implementation
|
||||
// PRs are welcome for a nicer update "queue" solution
|
||||
|
||||
if (topic == CHANGE_LABELS) {
|
||||
// separate timer from content change timer, to avoid losing that update
|
||||
os_timer_disarm(¬ifyTim2);
|
||||
os_timer_setfn(¬ifyTim2, notifyLabelsTimCb, NULL);
|
||||
os_timer_arm(¬ifyTim2, SCREEN_NOTIFY_DELAY_MS, 0);
|
||||
}
|
||||
else if (topic == CHANGE_CONTENT) {
|
||||
// throttle delay
|
||||
os_timer_disarm(¬ifyTim);
|
||||
os_timer_setfn(¬ifyTim, notifyTimCb, NULL);
|
||||
os_timer_arm(¬ifyTim, SCREEN_NOTIFY_DELAY_MS, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/** Socket received a message */
|
||||
@@ -45,6 +96,8 @@ void ICACHE_FLASH_ATTR updateSockRx(Websock *ws, char *data, int len, int flags)
|
||||
// Add terminator if missing (seems to randomly happen)
|
||||
data[len] = 0;
|
||||
|
||||
// TODO re-implement those, use single byte markers and B2 encoding
|
||||
|
||||
dbg("Sock RX str: %s, len %d", data, len);
|
||||
|
||||
if (strstarts(data, "STR:")) {
|
||||
|
||||
@@ -3,7 +3,10 @@
|
||||
|
||||
#define URL_WS_UPDATE "/term/update.ws"
|
||||
|
||||
#include "screen.h"
|
||||
|
||||
/** Update websocket connect callback */
|
||||
void updateSockConnect(Websock *ws);
|
||||
void screen_notifyChange(ScreenNotifyChangeTopic topic);
|
||||
|
||||
#endif //CGI_SOCKETS_H
|
||||
|
||||
+23
-23
@@ -96,7 +96,7 @@ static volatile int notifyLock = 0;
|
||||
|
||||
#define NOTIFY_DONE() do { \
|
||||
if (notifyLock > 0) notifyLock--; \
|
||||
if (notifyLock == 0) screen_notifyChange(); \
|
||||
if (notifyLock == 0) screen_notifyChange(CHANGE_CONTENT); \
|
||||
} while(0)
|
||||
|
||||
/**
|
||||
@@ -371,8 +371,8 @@ screen_cursor_move(int dy, int dx)
|
||||
|
||||
cursor.x += dx;
|
||||
cursor.y += dy;
|
||||
if (cursor.x >= W) cursor.x = W - 1;
|
||||
if (cursor.x < 0) cursor.x = 0;
|
||||
if (cursor.x >= (int)W) cursor.x = W - 1;
|
||||
if (cursor.x < (int)0) cursor.x = 0;
|
||||
|
||||
if (cursor.y < 0) {
|
||||
move = -cursor.y;
|
||||
@@ -674,6 +674,25 @@ encode2B(u16 number, WordB2 *stru)
|
||||
stru->lsb += 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* buffer should be at least 64+5*10+6 long (title + buttons + 6), ie. 120
|
||||
* @param buffer
|
||||
* @param buf_len
|
||||
*/
|
||||
void ICACHE_FLASH_ATTR
|
||||
screenSerializeLabelsToBuffer(char *buffer, size_t buf_len)
|
||||
{
|
||||
// let's just assume it's long enough - called with the huge websocket buffer
|
||||
sprintf(buffer, "T%s|%s|%s|%s|%s|%s",
|
||||
termconf_scratch.title,
|
||||
termconf_scratch.btn[0],
|
||||
termconf_scratch.btn[1],
|
||||
termconf_scratch.btn[2],
|
||||
termconf_scratch.btn[3],
|
||||
termconf_scratch.btn[4]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize the screen to a data buffer. May need multiple calls if the buffer is insufficient in size.
|
||||
*
|
||||
@@ -728,7 +747,7 @@ screenSerializeToBuffer(char *buffer, size_t buf_len, void **data)
|
||||
, &w5);
|
||||
|
||||
// H W X Y Attribs
|
||||
bufprint("%c%c%c%c%c%c%c%c%c%c", w1.lsb, w1.msb, w2.lsb, w2.msb, w3.lsb, w3.msb, w4.lsb, w4.msb, w5.lsb, w5.msb);
|
||||
bufprint("S%c%c%c%c%c%c%c%c%c%c", w1.lsb, w1.msb, w2.lsb, w2.msb, w3.lsb, w3.msb, w4.lsb, w4.msb, w5.lsb, w5.msb);
|
||||
}
|
||||
|
||||
int i = ss->index;
|
||||
@@ -749,12 +768,6 @@ screenSerializeToBuffer(char *buffer, size_t buf_len, void **data)
|
||||
|
||||
if (repCnt == 0) {
|
||||
// No repeat
|
||||
|
||||
// All this crap is needed because it's JSON and also
|
||||
// embedded in HTML (hence the angle brackets)
|
||||
|
||||
// TODO use the encoding magic correctly
|
||||
|
||||
if (cell0->bold != ss->lastBold || cell0->fg != ss->lastFg || cell0->bg != ss->lastBg) {
|
||||
encode2B((u16) (
|
||||
cell0->fg |
|
||||
@@ -771,19 +784,6 @@ screenSerializeToBuffer(char *buffer, size_t buf_len, void **data)
|
||||
bufprint("%c", c);
|
||||
}
|
||||
|
||||
// TODO do correctly JSON encoding
|
||||
//
|
||||
// char c = cell0->c;
|
||||
// if (c == '"' || c == '\\') {
|
||||
// bufprint("\\%c", c);
|
||||
// }
|
||||
// else if (c == '<' || c == '>' || c == '\'' || c == '/' || c == '&') {
|
||||
// bufprint("\\u00%02X", (int)c);
|
||||
// }
|
||||
// else {
|
||||
// bufprint("%c", c);
|
||||
// }
|
||||
|
||||
ss->lastFg = cell0->fg;
|
||||
ss->lastBg = cell0->bg;
|
||||
ss->lastBold = cell0->bold;
|
||||
|
||||
+11
-1
@@ -41,6 +41,13 @@
|
||||
#define TERM_BTN_LEN 10
|
||||
#define TERM_TITLE_LEN 64
|
||||
|
||||
typedef enum {
|
||||
CHANGE_CONTENT,
|
||||
CHANGE_LABELS,
|
||||
} ScreenNotifyChangeTopic;
|
||||
|
||||
#define SCREEN_NOTIFY_DELAY_MS 20
|
||||
|
||||
typedef struct {
|
||||
u32 width;
|
||||
u32 height;
|
||||
@@ -91,6 +98,9 @@ typedef uint8_t Color;
|
||||
|
||||
httpd_cgi_state screenSerializeToBuffer(char *buffer, size_t buf_len, void **data);
|
||||
|
||||
void screenSerializeLabelsToBuffer(char *buffer, size_t buf_len);
|
||||
|
||||
|
||||
typedef struct {
|
||||
u8 lsb;
|
||||
u8 msb;
|
||||
@@ -187,6 +197,6 @@ void screen_putchar(const char *ch);
|
||||
void screen_dd(void);
|
||||
#endif
|
||||
|
||||
extern void screen_notifyChange(void);
|
||||
extern void screen_notifyChange(ScreenNotifyChangeTopic topic);
|
||||
|
||||
#endif // SCREEN_H
|
||||
|
||||
Reference in New Issue
Block a user