-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
69 lines (54 loc) · 1.53 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <ncurses.h>
#include <k8055.h>
//#include "cstring.h"
int main(int argc, char **argv) {
int ipid = 0;
WINDOW *mainWin;
int i;
long digitalInput = 0;
long analogInputs[2];
// Open USB device
if(OpenDevice(ipid) < 0) {
printf("Could not open the k8055 (port:%d)\nPlease ensure that the device is correctly connected.\n", ipid);
return EXIT_FAILURE;
}
// Init ncurses
mainWin = initscr();
if(mainWin == NULL) {
fprintf(stderr, "Error initialising ncurses.\n");
return EXIT_FAILURE;
}
// Hide cursor
curs_set(0);
for(;;) {
// Clear window
clear();
// Digital inputs
digitalInput = ReadAllDigital();
if(digitalInput == K8055_ERROR) {
printw("ReadAllDigital() ERROR\n");
}
else {
// Heading
printw("- Digital inputs\n");
// Digital inputs
for (i = 0; i < 5; i++) {
printw("\t%d: %s\n", (i + 1), (digitalInput & (1 << i)) ? "on" : "off");
}
}
if(ReadAllAnalog(&analogInputs[0], &analogInputs[1]) == K8055_ERROR) {
printw("ReadAllAnalog() ERROR\n");
}
else {
printw("Analog 1: 0x%08x\n", analogInputs[0]);
printw("Analog 2: 0x%08x\n", analogInputs[1]);
}
OutputAnalogChannel(1, 0xff);
refresh();
usleep(1000); // 1 millisecond
}
return EXIT_SUCCESS;
}