1.1 diff -r 000000000000 -r 745037d69d81 test/lpfktest.c 1.2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.3 +++ b/test/lpfktest.c Tue Aug 26 12:45:33 2008 +0100 1.4 @@ -0,0 +1,63 @@ 1.5 +#include <stdio.h> 1.6 +#include <stdbool.h> 1.7 +#include <time.h> 1.8 +#include "liblpfk.h" 1.9 + 1.10 +int main(int argc, char **argv) 1.11 +{ 1.12 + LPFK_CTX ctx; 1.13 + int i; 1.14 + time_t tm; 1.15 + 1.16 + if (argc < 2) { 1.17 + printf("Syntax: %s commport\n", argv[0]); 1.18 + return -1; 1.19 + } 1.20 + 1.21 + if ((i = lpfk_open(argv[1], &ctx)) != LPFK_E_OK) { 1.22 + switch(i) { 1.23 + case LPFK_E_PORT_OPEN: 1.24 + printf("Error opening comm port.\n"); 1.25 + break; 1.26 + case LPFK_E_NOT_PRESENT: 1.27 + printf("LPFK not connected to specified port.\n"); 1.28 + break; 1.29 + case LPFK_E_COMMS: 1.30 + printf("LPFK communications error.\n"); 1.31 + break; 1.32 + } 1.33 + return -2; 1.34 + } 1.35 + 1.36 +// printf("disable: %d\n", lpfk_enable(&ctx, false)); 1.37 +// printf("enable : %d\n", lpfk_enable(&ctx, true)); 1.38 + 1.39 + printf("Scanning LEDs, 1-32...\n"); 1.40 + 1.41 + for (i=0; i<32; i++) { 1.42 + if (i>0) { 1.43 + lpfk_set_led(&ctx, i-1, false); 1.44 + } 1.45 + lpfk_set_led(&ctx, i, true); 1.46 + usleep(100000); 1.47 + } 1.48 + 1.49 + // Turn LEDs off 1.50 + lpfk_set_leds(&ctx, false); 1.51 + 1.52 + printf("Now press the keys on the LPFK...\n"); 1.53 + 1.54 + // scan keys for 5 seconds 1.55 + tm = time(NULL); 1.56 + do { 1.57 + // read keys 1.58 + if ((i = lpfk_read(&ctx)) >= 0) { 1.59 + // key buffered, toggle the LED 1.60 + printf("Key down: #%d\n", i); 1.61 + lpfk_set_led(&ctx, i, !lpfk_get_led(&ctx, i)); 1.62 + } 1.63 + } while ((time(NULL) - tm) < 30); 1.64 + 1.65 + lpfk_close(&ctx); 1.66 +} 1.67 +