diff options
author | Uros Majstorovic <majstor@majstor.org> | 2020-02-19 06:47:43 +0100 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2020-02-19 06:47:43 +0100 |
commit | 6666a131ab36b1d96a854da80524d860f9a3884b (patch) | |
tree | 5039423cb8c5592c20f8dd3aec417158ac058484 /code/fe310/eos/sock.c | |
parent | 15bddabc5cbe0e751fadcaaa7f7c7c36bca61331 (diff) |
eve long press/double tap/inertial scroll
spi flush bugfix
resolved dependecies: spi -> net; event -> net
renamed various handlers
Diffstat (limited to 'code/fe310/eos/sock.c')
-rw-r--r-- | code/fe310/eos/sock.c | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/code/fe310/eos/sock.c b/code/fe310/eos/sock.c index 077c93d..5e3dc67 100644 --- a/code/fe310/eos/sock.c +++ b/code/fe310/eos/sock.c @@ -8,27 +8,33 @@ #include "sock.h" -static eos_evt_fptr_t evt_handler[EOS_SOCK_MAX_SOCK]; +static eos_evt_handler_t evt_handler[EOS_SOCK_MAX_SOCK]; static uint16_t evt_handler_flags_buf_free = 0; static uint16_t evt_handler_flags_buf_acq = 0; -static void sock_handler_evt(unsigned char type, unsigned char *buffer, uint16_t len) { +static void sock_handle_evt(unsigned char type, unsigned char *buffer, uint16_t len) { + unsigned char sock; if ((buffer == NULL) || (len < 2)) { eos_evtq_bad_handler(type, buffer, len); eos_net_free(buffer, 0); return; } - if (buffer[0] == EOS_SOCK_MTYPE_PKT) { - uint8_t sock = buffer[1]; - if (sock && (sock <= EOS_SOCK_MAX_SOCK)) { - sock--; - } else { + sock = buffer[1]; + if ((sock == 0) || (sock > EOS_SOCK_MAX_SOCK)) { + eos_evtq_bad_handler(type, buffer, len); + eos_net_free(buffer, 0); + } + + sock--; + switch(buffer[0]) { + case EOS_SOCK_MTYPE_PKT: + evt_handler[sock](type, buffer, len); + break; + default: eos_evtq_bad_handler(type, buffer, len); eos_net_free(buffer, 0); - return; - } - _eos_net_handle(type, buffer, len, sock, evt_handler, &evt_handler_flags_buf_free, &evt_handler_flags_buf_acq); + break; } } @@ -38,16 +44,12 @@ void eos_sock_init(void) { for (i=0; i<EOS_SOCK_MAX_SOCK; i++) { evt_handler[i] = eos_evtq_bad_handler; } - eos_net_set_handler(EOS_NET_MTYPE_SOCK, sock_handler_evt, 0); + eos_net_set_handler(EOS_NET_MTYPE_SOCK, sock_handle_evt); } -void eos_sock_set_handler(int sock, eos_evt_fptr_t handler, uint8_t flags) { - if (sock && (sock <= EOS_SOCK_MAX_SOCK)) { - sock--; - } else { - return; - } - _eos_net_set_handler(sock, handler, evt_handler, flags, &evt_handler_flags_buf_free, &evt_handler_flags_buf_acq); +void eos_sock_set_handler(unsigned char sock, eos_evt_handler_t handler) { + if (handler == NULL) handler = eos_evtq_bad_handler; + if (sock && (sock <= EOS_SOCK_MAX_SOCK)) evt_handler[sock - 1] = handler; } int eos_sock_open_udp(void) { @@ -73,14 +75,14 @@ int eos_sock_open_udp(void) { return sock; } -void eos_sock_close(int sock) { +void eos_sock_close(unsigned char sock) { unsigned char *buffer = eos_net_alloc(); buffer[0] = EOS_SOCK_MTYPE_CLOSE; buffer[1] = sock; eos_net_send(EOS_NET_MTYPE_SOCK, buffer, 2, 1); } -int eos_sock_sendto(int sock, unsigned char *buffer, uint16_t size, unsigned char more, EOSNetAddr *addr) { +int eos_sock_sendto(unsigned char sock, unsigned char *buffer, uint16_t size, unsigned char more, EOSNetAddr *addr) { unsigned char type = EOS_NET_MTYPE_SOCK; buffer[0] = EOS_SOCK_MTYPE_PKT; |