test/lpfktest.c

Tue, 26 Aug 2008 22:13:49 +0100

author
Philip Pemberton <philpem@philpem.me.uk>
date
Tue, 26 Aug 2008 22:13:49 +0100
changeset 9
1519a9a8d924
parent 8
fd84ec9e11df
child 13
23a3d358dad3
permissions
-rw-r--r--

added #ifdef DEBUG around "key down" debug printf

     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(&ctx, argv[1])) != 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 }