# HG changeset patch # User Michiel Broek # Date 1556997531 -7200 # Node ID 7639cfa6aec04a38100b30bddd7e1496aa26d064 # Parent 71e06f6d80fda4f42e7b314e4351800c45062343 Websocket interface is working for the main screen and manual mode. diff -r 71e06f6d80fd -r 7639cfa6aec0 image/version.txt --- a/image/version.txt Sat May 04 11:41:16 2019 +0200 +++ b/image/version.txt Sat May 04 21:18:51 2019 +0200 @@ -1,1 +1,1 @@ -0.1.aa +0.1.av diff -r 71e06f6d80fd -r 7639cfa6aec0 image/w/css/style.css --- a/image/w/css/style.css Sat May 04 11:41:16 2019 +0200 +++ b/image/w/css/style.css Sat May 04 21:18:51 2019 +0200 @@ -55,6 +55,12 @@ border-color: yellow; } +#prompt { + width: 100%; + float: left; + text-align: center; +} + .appbutton { width: 60px; height: 36px; @@ -69,6 +75,13 @@ background-color: #575757; color: white; } +.promptbutton { + width: 80px; + height: 40px; + border-radius: 4px; + background-color: #e7e7e7; color: black; +} + #timer { color: white; text-align: center; diff -r 71e06f6d80fd -r 7639cfa6aec0 image/w/js/webui.js --- a/image/w/js/webui.js Sat May 04 11:41:16 2019 +0200 +++ b/image/w/js/webui.js Sat May 04 21:18:51 2019 +0200 @@ -8,43 +8,107 @@ Screen: -1, setScreen: function(s){ - console.log("Screen:"+s); - switch (s) { - case '0': - case '100': - case '101': - case '102': - case '103': - case '104': - case '105': - case '106': - case '107': - case '201': - $("#mltline").show(); - //$("#mlt01").hide(); - $("#midline").show(); - $("#hltline").show(); - $("#row_info").hide(); - console.log("this is 0"); - break; - case '108': $("#mltline").show(); // to boil - $("#midline").hide(); - $("#hltline").hide(); + Screen = parseInt(s,10); + console.log("Screen:"+Screen); + switch (Screen) { + case 0: $("#mltline").show(); + $("#mlt_table").show(); + $("#but00").text('Hand'); + $("#but20").text('Auto'); + $("#mlt00").show(); + $("#mlt20").show(); + $("#mlt01").hide(); + $("#mlt21").hide(); + $("#midline").show(); + $("#mid00").hide(); + $("#mid20").hide(); + $("#hltline").show(); + $("#hlt_table").show(); + $("#hlt00").hide(); + $("#hlt20").hide(); + $("#hlt01").show(); + $("#hlt21").show(); + $("#hlt01").css("background-color", "#e7e7e7"); + $("#hlt01").css("color", "black"); + $("#but04").text('Info'); + $("#but24").text('Tools'); + $("#row_info").hide(); + $("#prompt").hide(); break; - case '109': $("#mltline").show(); // boil - $("#midline").show(); - $("#hltline").hide(); - break; - case '2': $("#mltline").hide(); + case 2: $("#mltline").hide(); $("#midline").hide(); $("#hltline").hide(); $("#row_info").show(); - console.log("this is 2"); + $("#prompt").hide(); + break; +// case 21: Automaat show recipe and Stop / Start +// Prompt +// Prompt + case 100: + case 101: + case 102: + case 103: + case 104: + case 105: + case 106: + case 107: $("#mltline").show(); + $("#but00").text('+sp'); + $("#but20").text('-sp'); + $("#midline").show(); + $("#hltline").show(); + $("#hlt01").hide(); + $("#hlt21").hide(); + $("#row_info").hide(); + $("#prompt").hide(); break; + case 108: $("#mltline").show(); // to boil + $("#midline").hide(); + $("#hltline").hide(); + $("#prompt").hide(); + break; + case 109: $("#mltline").show(); // boil + $("#midline").show(); + $("#hltline").hide(); + $("#prompt").hide(); + break; + case 200: $("#mltline").hide(); + $("#midline").hide(); + $("#hltline").hide(); + $("#row_info").hide(); + $("#prompt").show(); + break; + case 201: $("#mltline").show(); + $("#mlt00").hide(); + $("#mlt20").hide(); + $("#mlt01").hide(); + $("#mlt21").hide(); + $("#mlt_table").hide(); + $("#but00").text('+sp'); + $("#but20").text('-sp'); + $("#but01").text('Pomp'); + $("#but21").text('Aan'); + $("#midline").show(); + $("#mid00").hide(); + $("#mid20").hide(); + $("#hltline").show(); + $("#hlt00").hide(); + $("#hlt20").hide(); + $("#hlt21").hide(); + $("#hlt_table").hide(); + $("#but03").text('+sp'); + $("#but23").text('-sp'); + $("#but04").text('Stop'); + $("#but24").text('Aan'); + $("#hlt01").css("background-color", "#575757"); + $("#hlt01").css("color", "white"); + $("#row_info").hide(); + $("#prompt").hide(); + break; default: $("#mltline").hide(); $("#midline").hide(); $("#hltline").hide(); - console.log("this is default"); + $("#prompt").hide(); + console.log("this is default screen "+Screen); break; } }, @@ -53,6 +117,15 @@ }, MLT_sp: function(s) { $("#mlt_sp").text(s); + if (Screen == 201) { + if (s != "") { + $("#mlt00").show(); + $("#mlt20").show(); + $("#mlt01").show(); + $("#mlt21").show(); + $("#mlt_table").show(); + } + } }, MLT_power: function(s) { $("#mlt_power").text(s); @@ -74,6 +147,14 @@ }, HLT_sp: function(s) { $("#hlt_sp").text(s); + if (Screen == 201) { + if (s != "") { + $("#hlt00").show(); + $("#hlt20").show(); + $("#hlt21").show(); + $("#hlt_table").show(); + } + } }, HLT_power: function(s) { $("#hlt_power").text(s); @@ -146,13 +227,25 @@ function sendTouch(x, y) { - websocket.send('{"touch":{"x":"'+x+'","y":"'+y+'"}}'); - console.log('Sent {"touch":{"x":"'+x+'","y":"'+y+'"}}'); + websocket.send('{"touch":{"x":'+x+',"y":'+y+'}}'); + console.log('Sent {"touch":{"x":'+x+',"y":'+y+'}}'); } /* Define keys in the screens and their actions. */ $("#ok_info").click( function() { sendTouch(160,220); }); +$("#mlt00").click( function() { sendTouch( 35, 46); }); +$("#mlt20").click( function() { sendTouch(285, 46); }); +$("#mlt01").click( function() { sendTouch( 35, 96); }); +$("#mlt21").click( function() { sendTouch(285, 96); }); +$("#mid00").click( function() { sendTouch( 35,140); }); +$("#mid20").click( function() { sendTouch(285,140); }); +$("#hlt00").click( function() { sendTouch( 35,170); }); +$("#hlt20").click( function() { sendTouch(285,170); }); +$("#hlt01").click( function() { sendTouch( 35,220); }); +$("#hlt21").click( function() { sendTouch(285,220); }); +$("#button_ja").click( function() { sendTouch( 80,120); }); +$("#button_nee").click( function() { sendTouch(240,120); }); websocket.onopen = function(evt) { diff -r 71e06f6d80fd -r 7639cfa6aec0 image/w/webui.html --- a/image/w/webui.html Sat May 04 11:41:16 2019 +0200 +++ b/image/w/webui.html Sat May 04 21:18:51 2019 +0200 @@ -18,8 +18,8 @@ -
- + + @@ -38,15 +38,15 @@
- +
- + - +
@@ -57,13 +57,13 @@ - +
01:23:45
- + @@ -74,7 +74,7 @@ - + @@ -93,40 +93,37 @@
- + - + - + - - +
+
+

Written by Michiel Broek © 2018 +

+
+

Parts are written by Chris Morgan, Brett Beauregard, Blake Felt, LoBo and David Antliff. +

+
+ +
+
- - - +
+ + +
-
-
-

- Written by Michiel Broek © 2018 -

-
-

- Parts are written by Chris Morgan, Brett Beauregard, Blake Felt, LoBo and David Antliff. -

-
- -
-

diff -r 71e06f6d80fd -r 7639cfa6aec0 main/buttons.c --- a/main/buttons.c Sat May 04 11:41:16 2019 +0200 +++ b/main/buttons.c Sat May 04 21:18:51 2019 +0200 @@ -12,6 +12,9 @@ const char *mashTypes[] = { "Infusion", "Temperature", "Decoction" }; const char *SSR2Types[] = { "Uit", "HLT of MLT", "HLT en MLT", "Idle" }; +uint8_t WS_pressed = 0; ///< Websocket button received +uint16_t WS_pointer_x = 0; ///< Websocket coordinate x +uint16_t WS_pointer_y = 0; ///< Websocket coordinate y #define EDIT_TYPE_TEXT 0 ///< Editor type is text #define EDIT_TYPE_INT 1 ///< Editor type is integer @@ -134,7 +137,13 @@ return rc; } - if (v_pressed) { + if (WS_pressed) { + v_pressed = true; + vx = WS_pointer_x; + vy = WS_pointer_y; + WS_pressed = 0; + return -1; + } else if (v_pressed) { rc = Buttons_Search(vx, vy); v_pressed = false; vx = vy = -1; @@ -146,6 +155,15 @@ +void WS_touched(int x, int y) +{ + WS_pointer_x = x; + WS_pointer_y = y; + WS_pressed = 1; +} + + + static const uint8_t alphalow_tab[] = { 'q','w','e','r','t','y','u','i','o','p', 'a','s','d','f','g','h','j','k','l', 'z','x','c','v','b','n','m' }; diff -r 71e06f6d80fd -r 7639cfa6aec0 main/buttons.h --- a/main/buttons.h Sat May 04 11:41:16 2019 +0200 +++ b/main/buttons.h Sat May 04 21:18:51 2019 +0200 @@ -68,6 +68,13 @@ int Buttons_Scan(void); /** + * @brief Insert button coordinates received from a websocket. + * @param x The touched X position. + * @param y The touched Y position. + */ +void WS_touched(int x, int y); + +/** * @brief Scan keyboard, all characters, 4 screens. * @return The ASCII code of the key, or -1 if no key is pressed. */ diff -r 71e06f6d80fd -r 7639cfa6aec0 main/task_http.c --- a/main/task_http.c Sat May 04 11:41:16 2019 +0200 +++ b/main/task_http.c Sat May 04 21:18:51 2019 +0200 @@ -6,6 +6,7 @@ #include "config.h" #include "mbedtls/base64.h" #include "mbedtls/sha1.h" +#include "cJSON.h" static const char *TAG = "task_http"; @@ -14,6 +15,8 @@ static TaskHandle_t xTaskHTTP = NULL; static TaskHandle_t xTaskQueue = NULL; +cJSON *root = NULL; +cJSON *touch = NULL; /** @@ -21,8 +24,9 @@ * @param buf The buffer * @param buflen Length of the buffer */ +#if 0 void dump_buf(char *buf, uint16_t buflen); - +#endif /** @@ -214,6 +218,8 @@ */ void websock_callback(uint8_t num, WEBSOCKET_TYPE_t type, char* msg, uint64_t len) { + char jbuf[128]; + switch(type) { case WEBSOCKET_CONNECT: ESP_LOGI(TAG,"Websocket client %i connected!",num); @@ -232,13 +238,32 @@ break; case WEBSOCKET_TEXT: + /* + * Handle json actions from the web clients, like button presses. + */ + if (len < 128) { // Safety, messages are small. + memcpy(jbuf, msg, len); + jbuf[len] = '\0'; + if ((root = cJSON_Parse(jbuf))) { + if ((touch = cJSON_GetObjectItem(root,"touch"))) { + int x = cJSON_GetObjectItem(touch, "x")->valueint; + int y = cJSON_GetObjectItem(touch, "y")->valueint; + WS_touched(x, y); + break; + } else { + ESP_LOGI(TAG,"not json touch"); + } + cJSON_Delete(root); + } else { + ESP_LOGI(TAG,"not json"); + } + } + // Log if the message in not processed. ESP_LOGI(TAG,"Websocket client %i sent text message of size %i:\n%s",num,(uint32_t)len,msg); - dump_buf(msg, len); break; case WEBSOCKET_BIN: ESP_LOGI(TAG,"Websocket client %i sent bin message of size %i:\n",num,(uint32_t)len); - dump_buf(msg, len); break; case WEBSOCKET_PING: @@ -253,6 +278,7 @@ +#if 0 void dump_buf(char *buf, uint16_t buflen) { int i = 0, l = 1; @@ -277,6 +303,7 @@ } printf("\n"); } +#endif @@ -398,7 +425,9 @@ return; } +#if 0 dump_buf(buf, buflen); +#endif if (strstr(buf, "GET /")) { ESP_LOGI(TAG, "%s request: %s", ipstr, buf);