forked from Grumbel/udraw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
udraw_decoder.hpp
133 lines (110 loc) · 2.71 KB
/
udraw_decoder.hpp
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
// Linux driver for the uDraw graphic tablet
// Copyright (C) 2012 Ingo Ruhnke <[email protected]>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef HEADER_UDRAW_DECODER_HPP
#define HEADER_UDRAW_DECODER_HPP
/*
data[7]; // right
data[8]; // left
data[9]; // up
data[10]; // down
data[0] & 1 // square
data[0] & 2 // cross
data[0] & 8 // triangle
data[0] & 4 // circle
data[1] & 1 // select
data[1] & 2 // start
data[1] & 0x10 // guide
// 0x00 - nothing
// 0x80 - finger
// 0x40 - pen
// weird stuff when pinching (angle)
data[11]
data[12]; // pinch distance
data[13]; // pressure, 0x70 neutral
*/
class UDrawDecoder
{
private:
uint8_t* m_data;
int m_len;
public:
enum {
PEN_MODE = 0x40,
FINGER_MODE = 0x80,
PINCH_MODE
};
UDrawDecoder(uint8_t* data, int len) :
m_data(data), m_len(len)
{
if (m_len < 19)
{
std::ostringstream out;
out << "package size to small: " << m_len;
throw std::runtime_error(out.str());
}
}
int get_x() const
{
// pen: 3px resolution
// finger: 1px resolution
return m_data[15] * 255 + m_data[17];
}
int get_y() const
{
return m_data[16] * 255 + m_data[18];
}
int get_pressure() const
{
return m_data[13] - 0x70;
}
int get_orientation() const
{
return m_data[11] - 0xc0;
}
int get_mode() const
{
//std::cout << int(m_data[11]) << std::endl;
if (0xc0 <= m_data[11] && m_data[11] <= 253)
return PINCH_MODE;
else
return m_data[11];
}
bool get_up() const
{
return m_data[9];
}
bool get_down() const
{
return m_data[10];
}
bool get_left() const
{
return m_data[8];
}
bool get_right() const
{
return m_data[7];
}
bool get_square() const { return m_data[0] & 1; }
bool get_cross() const { return m_data[0] & 2; }
bool get_triangle() const { return m_data[0] & 8; }
bool get_circle() const { return m_data[0] & 4; }
bool get_start() const { return m_data[1] & 1; }
bool get_select() const { return m_data[1] & 2; }
bool get_guide() const { return m_data[1] & 0x10; }
};
#endif
/* EOF */