From: Reinhard T. <sir...@ta...> - 2006-10-02 14:27:12
|
In our appliance, we need some way to access the buttons near our lcd display. Luckily, we found that in drv_HD_LCM162_timer, there is already some checking done fore keypresses. So all I needed to to was to call a function which sends some udp packages. Obviously, this only works on LCM162 devices. Oh well... The patch I use for that is included below. There are some unresolved problems with it: - the portnumber (and perhaps the hostname) should be configurable - the format string could be configurable - documentation is lacking what do you think about this patch? perhaps it could be integrated better with the GPIO or some other driver, but I don't understand the code enough. As said, we needed a simple solution for accessing the buttons on our LCM162 display. would be great if this patch could be merged in a more generic form... === modified file 'drv_HD44780.c' --- drv_HD44780.c 2006-08-10 20:40:46 +0000 +++ drv_HD44780.c 2006-10-02 12:34:14 +0000 @@ -316,6 +316,13 @@ #include "drv_generic_i2c.h" #endif + +/* extra includes for sending udp */ +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <netdb.h> + static char Name[] = "HD44780"; static int Bus; @@ -1197,6 +1204,42 @@ } +static void send_keypress_via_udp(int keynum, int updown) { + int sock; + struct sockaddr_in name; + struct hostent *hostinfo; + char *msg[16]; + + /* Create the socket. */ + sock = socket (PF_INET, SOCK_DGRAM, 0); + if (sock < 0) { + debug("fail to setup sockent: %m"); + return; + } + + name.sin_family = AF_INET; + name.sin_port = htons (11223); + name.sin_addr.s_addr = htonl(INADDR_ANY); + hostinfo = gethostbyname("localhost"); + + if (hostinfo == NULL) { + debug ("gethostbyname on localhost failed. WTF?!"); + return; + } + + snprintf((char *)msg, 16, "key %d state %d\n", keynum, updown); + + name.sin_addr = *(struct in_addr *) hostinfo->h_addr; + sendto(sock, msg, 16, 0, + (struct sockaddr *) &name, sizeof name); + + close(sock); + + return; +} + + + static void drv_HD_LCM162_timer(void __attribute__ ((unused)) * notused) { static unsigned char data = 0x00; @@ -1222,10 +1265,10 @@ updown = (data & mask6 ? 1 : 0); debug("key %d press %d", keynum, updown); + send_keypress_via_udp(keynum, updown); } } - static int drv_HD_start(const char *section, const int quiet) { char *model, *size, *bus; -- Gruesse/greetings, Reinhard Tartler, KeyID 945348A4 |