test/lpfktest.c

Tue, 26 Aug 2008 22:00:24 +0100

author
Philip Pemberton <philpem@philpem.me.uk>
date
Tue, 26 Aug 2008 22:00:24 +0100
changeset 6
aed399ff850b
parent 0
745037d69d81
child 8
fd84ec9e11df
permissions
-rw-r--r--

fix typo in makefile that broke 'make clean'

     1 #include <stdio.h>
     2 #include <stdbool.h>
     3 #include <time.h>
     4 #include "liblpfk.h"
     6 int main(int argc, char **argv) 
     7 {
     8 	LPFK_CTX	ctx;
     9 	int			i;
    10 	time_t		tm;
    12 	if (argc < 2) {
    13 		printf("Syntax: %s commport\n", argv[0]);
    14 		return -1;
    15 	}
    17 	if ((i = lpfk_open(argv[1], &ctx)) != LPFK_E_OK) {
    18 		switch(i) {
    19 			case LPFK_E_PORT_OPEN:
    20 				printf("Error opening comm port.\n");
    21 				break;
    22 			case LPFK_E_NOT_PRESENT:
    23 				printf("LPFK not connected to specified port.\n");
    24 				break;
    25 			case LPFK_E_COMMS:
    26 				printf("LPFK communications error.\n");
    27 				break;
    28 		}
    29 		return -2;
    30 	}
    32 //	printf("disable: %d\n", lpfk_enable(&ctx, false));
    33 //	printf("enable : %d\n", lpfk_enable(&ctx, true));
    35 	printf("Scanning LEDs, 1-32...\n");
    37 	for (i=0; i<32; i++) {
    38 		if (i>0) {
    39 			lpfk_set_led(&ctx, i-1, false);
    40 		}
    41 		lpfk_set_led(&ctx, i, true);
    42 		usleep(100000);
    43 	}
    45 	// Turn LEDs off
    46 	lpfk_set_leds(&ctx, false);
    48 	printf("Now press the keys on the LPFK...\n");
    50 	// scan keys for 5 seconds
    51 	tm = time(NULL);
    52 	do {
    53 		// read keys
    54 		if ((i = lpfk_read(&ctx)) >= 0) {
    55 			// key buffered, toggle the LED
    56 			printf("Key down: #%d\n", i);
    57 			lpfk_set_led(&ctx, i, !lpfk_get_led(&ctx, i));
    58 		}
    59 	} while ((time(NULL) - tm) < 30);
    61 	lpfk_close(&ctx);
    62 }