-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprobeDial.c
169 lines (148 loc) · 3.72 KB
/
probeDial.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include <stdio.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#define NDIALS 8
#define DIAL_NUMBER(event_code) (event_code & 0xFF)
#define DIAL_0_IN_USE 0x00000001
#define DIAL_1_IN_USE 0x00000002
#define DIAL_2_IN_USE 0x00000004
#define DIAL_3_IN_USE 0x00000008
#define DIAL_4_IN_USE 0x00000010
#define DIAL_5_IN_USE 0x00000020
#define DIAL_6_IN_USE 0x00000040
#define DIAL_7_IN_USE 0x00000080
#define DIAL_0_ENABLE 0x00000100
#define DIAL_1_ENABLE 0x00000200
#define DIAL_2_ENABLE 0x00000400
#define DIAL_3_ENABLE 0x00000800
#define DIAL_4_ENABLE 0x00001000
#define DIAL_5_ENABLE 0x00002000
#define DIAL_6_ENABLE 0x00004000
#define DIAL_7_ENABLE 0x00008000
#define DIALS_ENABLE 0x80000000
typedef struct inputevent {
short dialNum;
short unused;
int delta;
} Event;
typedef struct dialCallbackDataStruc {
void (*proc)();
void *ClientData;
} dialCallbackStruc;
static dialCallbackStruc dialCallback[NDIALS] = {
{NULL, NULL}, {NULL, NULL},
{NULL, NULL}, {NULL, NULL},
{NULL, NULL}, {NULL, NULL},
{NULL, NULL}, {NULL, NULL}
};
int dialsUp = 0;
static int fd;
static char buf[16];
static char tmp;
static Event *event = (Event *) buf;
static int byt_cnt;
static int red;
static float dials[NDIALS] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
static unsigned int dialStatus = 0;
int probeInitializeDials() {
/*
if ((fd = open("/dev/dialbox", O_RDWR)) == -1) {
perror("probeInitializeDials : Open failed for /dev/dialbox:");
return -1;
}
dialStatus |= DIALS_ENABLE;
*/
dialStatus = 0;
return 0;
}
int probeDialIsPresent() {
return (dialStatus & DIALS_ENABLE);
}
int probeDialInUsed(n)
int n;
{
if ((n >= 0) && (n <NDIALS)) {
return (dialStatus & (unsigned int) (1 << n));
} else {
fprintf(stderr,"dialInUsed : Dial number out of range!\n");
return -1;
}
}
int probeDisableDial(n)
int n;
{
if ((n >= 0) && (n <NDIALS)) {
dialStatus &= ~((unsigned int) (0x00000100 << n));
} else {
fprintf(stderr,"probeDisableCallback : Dial number out of range!\n");
return -1;
}
}
int probeEnableDial(n)
int n;
{
if ((n >= 0) && (n <NDIALS)) {
dialStatus |= (unsigned int) (0x00000100 << n);
} else {
fprintf(stderr,"probeEnableCallback : Dial number out of range!\n");
return -1;
}
}
int probeAddDialCallback(n,proc,ClientData)
int n;
void *proc;
void *ClientData;
{
if ((n >= 0) && (n < NDIALS)) {
dialCallback[n].proc = proc;
dialCallback[n].ClientData = ClientData;
dialStatus |= (unsigned int) (1 << n);
probeEnableDial(n);
return 0;
} else {
fprintf(stderr,"probeAddDialCallback : Dial number out of range!\n");
return -1;
}
}
int probeRemoveDialCallback(n)
int n;
{
if ((n >= 0) && (n < NDIALS)) {
dialCallback[n].proc = NULL;
dialStatus &= ~((unsigned int) (1 << n));
probeDisableDial(n);
return 0;
} else {
fprintf(stderr,"probeRemoveDialCallback : Dial number out of range!\n");
}
return -1;
}
int probeScanDials() {
int tmp, n;
if (ioctl(fd, FIONREAD, &byt_cnt) == -1 || byt_cnt == 0) return 0;
if((red = read(fd, buf, sizeof(buf))) == 16) {
n = DIAL_NUMBER(event->dialNum);
if ((dialCallback[n].proc)
&& (dialStatus & (unsigned int) (0x00000100 << n))) {
(*(dialCallback[n].proc)) (event->delta,
dialCallback[n].ClientData, NULL);
}
} else {
fprintf(stderr, "read %d bytes\n", red);
return -1;
}
}
dumpDials(delta, i, reason)
int delta;
int i, reason;
{
dials[i] += ((float) delta) / 64;
if (dials[i] >= 360.0) {
dials[i] -= 360.0;
}
if (dials[i] <= -360.0) {
dials[i] += 360.0;
}
printf("%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n",
dials[0],dials[1],dials[2],dials[3],dials[4],dials[5],dials[6],dials[7]);
}