X-Git-Url: https://git.realraum.at/?p=svn42.git;a=blobdiff_plain;f=rf433rcv%2Fpc%2Frawhid_test.c;h=cd94bdbbce830de1d478d3cbc460eee22fa232c2;hp=7bea89248fc67ba51844261b45a6516ff835ef06;hb=5b00dab1a7d2ac2d8a593f0bd6e85a7194e2c9bd;hpb=deb2b278d460a716e0e2d8be370b1ee8f8963e34 diff --git a/rf433rcv/pc/rawhid_test.c b/rf433rcv/pc/rawhid_test.c index 7bea892..cd94bdb 100644 --- a/rf433rcv/pc/rawhid_test.c +++ b/rf433rcv/pc/rawhid_test.c @@ -1,7 +1,8 @@ #include #include #include - +#include +#include #if defined(OS_LINUX) || defined(OS_MACOSX) #include #include @@ -12,14 +13,22 @@ #include "hid.h" -static char get_keystroke(void); +void sendstr(char * tosend) +{ + rawhid_send(0, tosend, strlen(tosend),1000); +} +int mtime_diff(struct timeval high,struct timeval low) +{ + int result=1000*(high.tv_sec-low.tv_sec); + result+=high.tv_usec/1000-low.tv_usec/1000; + return result; +} -int main() +int main (int argc, char *argv[]) { int i, r, num; - char c, buf[64]; - + char buf[64]; // C-based example is 16C0:0480:FFAB:0200 r = rawhid_open(1, 0x16C0, 0x0480, 0xFFAB, 0x0200); if (r <= 0) { @@ -30,71 +39,66 @@ int main() return -1; } } - printf("found rawhid device\n"); - - while (1) { - // check if any Raw HID packet has arrived - num = rawhid_recv(0, buf, 64, 220); - if (num < 0) { - printf("\nerror reading, device went offline\n"); - rawhid_close(0); - return 0; - } - if (num > 0) { - printf("\nrecv %d bytes:\n", num); - for (i=0; i= 32) { - printf("\ngot key '%c', sending...\n", c); - buf[0] = c; - for (i=1; i<64; i++) { - buf[i] = 0; - } - rawhid_send(0, buf, 64, 100); - } - } +// printf("found rawhid device\n"); + if (argc>1) + { + FILE * f = fopen (argv[1], "r"); + if (strcmp("-",argv[1]) == 0) + f = stdin; + if (!f) + return -3; + printf("Clearing Buffer\n"); + sendstr("c"); // clear the buffer + buf[0]='f'; + size_t len; + while ( ( len = fread(buf+1, 1, 63, f) ) ) + { + + rawhid_send(0, buf, 64, 1000); //fill the buffer + printf("Sending Buffer %d bytes\n",len); + for(i=0;i= 32) return c; - } - return 0; -} - -