diff -r 1193bd7d460f -r 6b80a37fdf8d brewpanel/sockio.c --- a/brewpanel/sockio.c Sat Nov 28 21:00:29 2015 +0100 +++ b/brewpanel/sockio.c Wed Dec 02 17:16:41 2015 +0100 @@ -38,10 +38,11 @@ void socket_recv(SGOBJ *dlg) { uint16_t data; + unsigned char cgdata[8]; struct sockaddr_in clntaddr; socklen_t clntlen = sizeof(clntaddr); ssize_t recv_len; - int fd = 0, my_error; + int i, index, fd = 0, my_error; recv_len = recvfrom(sock, &data, sizeof(uint16_t), MSG_DONTWAIT, (struct sockaddr *)&clntaddr, &clntlen); if (recv_len == sizeof(uint16_t)) { @@ -55,6 +56,22 @@ slcdClear(dlg, fd); } else if ((data & SLCD_MHOME) == SLCD_HOME) { slcdHome(dlg, fd); + } else if ((data & SLCD_MCGRAM) == SLCD_CGRAM) { + index = (data & 0x038) >> 3; + for (i = 0; i < 8; i++) { + /* + * Reply with the current keyboard state. Looks too early but the very last reply + * will be sent at the end of this function and we need to take 8 data words. + */ + if (sendto(sock, &keys, sizeof(uint16_t), MSG_DONTWAIT, (struct sockaddr *) &clntaddr, clntlen) == -1) { + syslog(LOG_NOTICE, "socket_recv() sendto error: %s", strerror(errno)); + } + recv_len = recvfrom(sock, &data, sizeof(uint16_t), 0, (struct sockaddr *)&clntaddr, &clntlen); + cgdata[i] = data & 0x00ff; + } + fprintf(stdout, "Got new CGRAM index=%d, %02x %02x %02x %02x %02x %02x %02x %02x\n", index, + cgdata[0], cgdata[1], cgdata[2], cgdata[3], cgdata[4], cgdata[5], cgdata[6], cgdata[7]); + slcdCharDef(dlg, fd, index, cgdata); } else if ((data & SLCD_MDGRAM) == SLCD_DGRAM) { slcdPosition(dlg, fd, data & 0x001f, (data & 0x0060) >> 5); } else if ((data & 0xfe00) == SLCD_DATA) {