-
Notifications
You must be signed in to change notification settings - Fork 0
/
direader.cc
183 lines (163 loc) · 5.93 KB
/
direader.cc
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
* Tilt-wizard
* Copyright (C) 2018 John D. Strunk
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
#include <string>
#include <getopt.h>
#include <iomanip>
#include <unistd.h>
#include "Device.h"
#define _TEXTIFY1(x) #x
#define TEXTIFY(x) _TEXTIFY1(x)
static void
enumerateDevices()
{
Device::DescriptionList devs = Device::enumerateDevices();
std::cout << std::setw(42) << std::left << "Device GUID"
<< "Name" << std::endl;
std::cout << std::setw(70) << std::setfill('=') << "=" << std::endl;
for (Device::DescriptionList::const_iterator i = devs.begin();
i != devs.end(); ++i) {
std::cout << i->guidString << " " << i->deviceName << std::endl;
}
}
void
readDevice(std::string guidString)
{
std::cout << "Looking for device: " << guidString << std::endl;
Device dev(guidString);
Device cooked(guidString, Device::COOKED);
std::cout << "Device name: " << dev.name() << std::endl;
unsigned fwidth = 6;
std::cout << std::right
<< std::setw(2*fwidth) << "cooked"
<< std::setw(fwidth) << "raw"
<< std::setw(fwidth) << "rmin"
<< std::setw(fwidth) << "min"
<< std::setw(fwidth) << "ctr"
<< std::setw(fwidth) << "max"
<< std::setw(fwidth) << "rmax"
<< std::setw(fwidth) << "DZ%"
<< std::setw(fwidth) << "SAT%"
<< std::setw(2*fwidth) << "cooked"
<< std::setw(fwidth) << "raw"
<< std::setw(fwidth) << "rmin"
<< std::setw(fwidth) << "min"
<< std::setw(fwidth) << "ctr"
<< std::setw(fwidth) << "max"
<< std::setw(fwidth) << "rmax"
<< std::setw(fwidth) << "DZ%"
<< std::setw(fwidth) << "SAT%"
<< std::endl;
while (true) {
dev.poll();
cooked.poll();
LONG xMin, xCtr, xMax;
dev.calibration(DIJOFS_X, &xMin, &xCtr, &xMax);
LONG xrMin, xrMax;
dev.range(DIJOFS_X, &xrMin, &xrMax);
LONG yMin, yCtr, yMax;
dev.calibration(DIJOFS_Y, &yMin, &yCtr, &yMax);
LONG yrMin, yrMax;
dev.range(DIJOFS_Y, &yrMin, &yrMax);
std::cout << std::setprecision(0) << std::fixed;
std::cout << std::setw(fwidth) << "x: "
<< std::setw(fwidth) << cooked.position(DIJOFS_X)
<< std::setw(fwidth) << dev.position(DIJOFS_X)
<< std::setw(fwidth) << xrMin
<< std::setw(fwidth) << xMin
<< std::setw(fwidth) << xCtr
<< std::setw(fwidth) << xMax
<< std::setw(fwidth) << xrMax
<< std::setw(fwidth) << dev.deadzone(DIJOFS_X)
<< std::setw(fwidth) << dev.saturation(DIJOFS_X)
<< std::setw(fwidth) << "y: "
<< std::setw(fwidth) << cooked.position(DIJOFS_Y)
<< std::setw(fwidth) << dev.position(DIJOFS_Y)
<< std::setw(fwidth) << yrMin
<< std::setw(fwidth) << yMin
<< std::setw(fwidth) << yCtr
<< std::setw(fwidth) << yMax
<< std::setw(fwidth) << yrMax
<< std::setw(fwidth) << dev.deadzone(DIJOFS_Y)
<< std::setw(fwidth) << dev.saturation(DIJOFS_Y)
<< "\r";
usleep(100000);
}
}
static void
usage(std::string pname)
{
std::cout << std::endl << "Usage:" << std::endl
<< " " << pname.c_str() << " -h|--help" << std::endl
<< " " << pname.c_str() << " -l|--list" << std::endl
<< " " << pname.c_str() << " -d|--device device_guid" << std::endl
<< std::endl
<< " -d, --device device_uuid read from specified device"
<< std::endl
<< " -h, --help this help message"
<< std::endl
<< " -l, --list list available devices"
<< std::endl;
}
static void
printVersion()
{
std::cout << "direader - https://github.com/JohnStrunk/tilt-wizard"
<< std::endl
<< "License: AGPL v3 or later" << std::endl
<< "Version: " << TEXTIFY(GIT_VERSION) << std::endl
<< "Date: " << TEXTIFY(GIT_DATE) << std::endl << std::endl;
}
int main(int argc, char *argv[])
{
printVersion();
std::string devGuid;
char opt;
struct option longopts[] = {
{"device", required_argument, 0, 'd'},
{"list", no_argument, 0, 'l'},
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
while ((opt = getopt_long(argc, argv, "d:hl", longopts, 0)) != -1) {
switch (opt) {
case 'd':
devGuid = optarg;
break;
case 'h':
usage(argv[0]);
exit(EXIT_SUCCESS);
break;
case 'l':
enumerateDevices();
exit(EXIT_SUCCESS);
break;
default: /* '?' */
usage(argv[0]);
exit(EXIT_FAILURE);
}
}
if (!devGuid.empty()) {
readDevice(devGuid);
return 0;
} else {
std::cout << "Must specify one of -d or -h" << std::endl;
usage(argv[0]);
exit(EXIT_FAILURE);
}
}