diff --git a/CMakeLists.txt b/CMakeLists.txt index 830715e..d76df33 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,6 @@ set(PICO_SDK_PATH /home/kenji/programming/pico/c/pico-sdk) if (NOT DEFINED PICO_BOARD) set(PICO_BOARD pico_w) endif() -#set(PICO_BOARD pico2_w) include (${PICO_SDK_PATH}/external/pico_sdk_import.cmake) project(${PROJECT} C CXX ASM) diff --git a/html/index.html b/html/index.html index c83e767..85ecd98 100644 --- a/html/index.html +++ b/html/index.html @@ -332,6 +332,7 @@ function sendKeys(curKeys, is_mouse) { } } else if (socket.readyState == WebSocket.CLOSED) { socket = new WebSocket("ws://" + window.location.hostname + ":8080/"); + socket.onmessage = function (event) { updateLEDs(event.data); }; setTimeout( function () { sendKeys(curKeys, is_mouse); }, 10); } else { setTimeout( function () { sendKeys(curKeys, is_mouse); }, 10); diff --git a/websocket.c b/websocket.c index 064fcad..9df358a 100644 --- a/websocket.c +++ b/websocket.c @@ -70,7 +70,7 @@ static void ws_state_free(struct ws_state *wss) { } else { struct ws_state * last; for (last = ws_connections; last->next != NULL; last = last->next) { - if (last->next = wss) { + if (last->next == wss) { last->next = wss->next; break; } @@ -187,6 +187,8 @@ static err_t ws_recv(void *arg, struct altcp_pcb *pcb, struct pbuf *p, err_t err // called when data has been sent over the websocket static err_t ws_sent(void *arg, struct altcp_pcb *pcb, uint16_t len) { + (void) pcb; + struct ws_state *wss = (struct ws_state *)arg; LWIP_DEBUGF(WS_DEBUG | LWIP_DBG_TRACE, ("ws_sent %p\n", (void*) pcb)); @@ -309,13 +311,11 @@ static err_t ws_handshake(struct altcp_pcb *pcb, struct ws_state *wss, struct pb // create response packet with encoded response key unsigned char response[sizeof(WS_RESPONSE) + sizeof(key_base64)+3]; - //strncpy(response, WS_RESPONSE, sizeof(WS_RESPONSE)); - //strlcpy(&response[sizeof(WS_RESPONSE)-1], key_base64, strlen(key_base64)); size_t count = sprintf(response, "%s%s\r\n\r\n", WS_RESPONSE, key_base64); // send completed data packet LWIP_DEBUGF(WS_DEBUG, ("ws_handshake: sending response\n")); - if(altcp_write(pcb, response, strlen(response), TCP_WRITE_FLAG_COPY) == ERR_OK) { + if(altcp_write(pcb, response, count, TCP_WRITE_FLAG_COPY) == ERR_OK) { wss->active = true; } @@ -341,6 +341,7 @@ static err_t ws_handshake(struct altcp_pcb *pcb, struct ws_state *wss, struct pb // handle reading of websocket data and pass to ws_receive_cb static err_t ws_read(struct altcp_pcb *pcb, struct ws_state *wss, struct pbuf *p) { + (void) pcb; uint8_t *data = (uint8_t *) p->payload; uint16_t len = p->len; @@ -365,12 +366,6 @@ static err_t ws_read(struct altcp_pcb *pcb, struct ws_state *wss, struct pbuf *p // lwIP's pbuf only handles 16-bit lengths, so error LWIP_DEBUGF(WS_DEBUG, ("ws_read: received 64-bit length %u\n", msg_len)); return ERR_MEM; - - //memcpy(&msg_len, &data[2], 4); - //if (len >= 10) { - // msg = &data[10]; - //} - //break; default: if (len >= 6) { msg = &data[6];