X-Git-Url: https://git.realraum.at/?p=svn42.git;a=blobdiff_plain;f=rf433rcv%2Fpc%2Frawhid_test.c;h=cd94bdbbce830de1d478d3cbc460eee22fa232c2;hp=8b1f757d670c81f61f15823a0fab5b7b13fbb2b8;hb=5b00dab1a7d2ac2d8a593f0bd6e85a7194e2c9bd;hpb=2bf5a97c9ca0349c51f33d28c55363b3ebb47251 diff --git a/rf433rcv/pc/rawhid_test.c b/rf433rcv/pc/rawhid_test.c index 8b1f757..cd94bdb 100644 --- a/rf433rcv/pc/rawhid_test.c +++ b/rf433rcv/pc/rawhid_test.c @@ -2,7 +2,7 @@ #include #include #include - +#include #if defined(OS_LINUX) || defined(OS_MACOSX) #include #include @@ -13,17 +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 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) { @@ -38,6 +43,8 @@ int main (int argc, char *argv[]) if (argc>1) { FILE * f = fopen (argv[1], "r"); + if (strcmp("-",argv[1]) == 0) + f = stdin; if (!f) return -3; printf("Clearing Buffer\n"); @@ -56,7 +63,7 @@ int main (int argc, char *argv[]) printf("\n"); } printf("Executing Send command\n"); - sendstr("s\x10"); // send 4 times + sendstr("s\x20"); // send 32 times len = rawhid_recv(0, buf, 64, 255); 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); - } + gettimeofday(&stop_time,NULL); } + sendstr("e"); + return 0; } } - -#if defined(OS_LINUX) || defined(OS_MACOSX) -// Linux (POSIX) implementation of _kbhit(). -// Morgan McGuire, morgan@cs.brown.edu -static int _kbhit() { - static const int STDIN = 0; - static int initialized = 0; - int bytesWaiting; - - if (!initialized) { - // Use termios to turn off line buffering - struct termios term; - tcgetattr(STDIN, &term); - term.c_lflag &= ~ICANON; - tcsetattr(STDIN, TCSANOW, &term); - setbuf(stdin, NULL); - initialized = 1; - } - ioctl(STDIN, FIONREAD, &bytesWaiting); - return bytesWaiting; -} -static char _getch(void) { - char c; - if (fread(&c, 1, 1, stdin) < 1) return 0; - return c; -} -#endif - - -static char get_keystroke(void) -{ - if (_kbhit()) { - char c = _getch(); - if (c >= 32) return c; - } - return 0; -} - -