test/lpfktest.c

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