-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dual_ADNS9800.h
171 lines (140 loc) · 3.59 KB
/
Dual_ADNS9800.h
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
#include "ADNS9800.h"
const uint16_t x_scale = 1;
const uint16_t y_scale = 1;
template <const int SS, const int MOT, const int RST>
class adns_ctrl :
public adns::controller<SS, MOT, RST> {
public:
adns_ctrl() {
}
~adns_ctrl() {
}
void setup();
void loop();
uint16_t get_x() const;
uint16_t get_y() const;
uint16_t get_x_dist() const;
uint16_t get_y_dist() const;
uint16_t get_squal() const;
void set_xy(uint16_t x, uint16_t y);
void set_xy_dist(uint16_t x_sum, uint16_t y_sum);
void set_squal(byte s);
void clear();
void print() const;
private:
void print_header() const;
void print_xy() const;
void print_xy_dist() const;
void print_squal() const;
void print_nl() const;
private:
uint16_t _x;
uint16_t _y;
uint16_t _x_dist;
uint16_t _y_dist;
byte _squal;
};
template <const int SS, const int MOT, const int RST>
uint16_t adns_ctrl<SS, MOT, RST>::get_x() const
{
return _x;
}
template <const int SS, const int MOT, const int RST>
uint16_t adns_ctrl<SS, MOT, RST>::get_y() const
{
return _y;
}
template <const int SS, const int MOT, const int RST>
uint16_t adns_ctrl<SS, MOT, RST>::get_x_dist() const
{
return _x_dist;
}
template <const int SS, const int MOT, const int RST>
uint16_t adns_ctrl<SS, MOT, RST>::get_y_dist() const
{
return _y_dist;
}
template <const int SS, const int MOT, const int RST>
uint16_t adns_ctrl<SS, MOT, RST>::get_squal() const
{
return _squal;
}
template <const int SS, const int MOT, const int RST>
void adns_ctrl<SS, MOT, RST>::set_xy(uint16_t x, uint16_t y)
{
_x = x;
_y = y;
}
template <const int SS, const int MOT, const int RST>
void adns_ctrl<SS, MOT, RST>::set_xy_dist(uint16_t x_dist, uint16_t y_dist)
{
_x_dist = x_dist;
_y_dist = y_dist;
}
template <const int SS, const int MOT, const int RST>
void adns_ctrl<SS, MOT, RST>::set_squal(byte s)
{
_squal = s;
}
template <const int SS, const int MOT, const int RST>
void adns_ctrl<SS, MOT, RST>::clear()
{
}
template <const int SS, const int MOT, const int RST>
void adns_ctrl<SS, MOT, RST>::print_header() const
{
Serial.print("@D,");
Serial.print(SS);
Serial.print(",");
}
template <const int SS, const int MOT, const int RST>
void adns_ctrl<SS, MOT, RST>::print_xy() const
{
int16_t x = adns::controller<SS, MOT, RST>::convert_twos_compliment(_x);
int16_t y = adns::controller<SS, MOT, RST>::convert_twos_compliment(_y);
Serial.print(x);
Serial.print(",");
Serial.print(y);
Serial.print(",");
}
template <const int SS, const int MOT, const int RST>
void adns_ctrl<SS, MOT, RST>::print_xy_dist() const
{
int16_t x_dist = adns::controller<SS, MOT, RST>::convert_twos_compliment(_x_dist);
int16_t y_dist = adns::controller<SS, MOT, RST>::convert_twos_compliment(_y_dist);
Serial.print(x_dist);
Serial.print(",");
Serial.print(y_dist);
Serial.print("");
}
template <const int SS, const int MOT, const int RST>
void adns_ctrl<SS, MOT, RST>::print_squal() const
{
Serial.print(_squal);
Serial.print(",");
}
template <const int SS, const int MOT, const int RST>
void adns_ctrl<SS, MOT, RST>::print_nl() const
{
Serial.println(",00000000");
}
template <const int SS, const int MOT, const int RST>
void adns_ctrl<SS, MOT, RST>::print() const
{
print_header();
print_squal();
//print_xy();
print_xy_dist();
adns::controller<SS, MOT, RST>::print_time();
print_nl();
}
template <const int SS, const int MOT, const int RST>
void adns_ctrl<SS, MOT, RST>::setup()
{
adns::controller<SS, MOT, RST>::setup();
}
template <const int SS, const int MOT, const int RST>
void adns_ctrl<SS, MOT, RST>::loop()
{
adns::controller<SS, MOT, RST>::loop();
}