test/lpfktest.c

Wed, 28 Jul 2010 15:14:54 +0100

author
Philip Pemberton <philpem@philpem.me.uk>
date
Wed, 28 Jul 2010 15:14:54 +0100
changeset 12
f8996e336619
parent 8
fd84ec9e11df
child 13
23a3d358dad3
permissions
-rw-r--r--

Fixed omission: lpfkbinclock wasn't compiled by default.

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