forked from TripleSpeeder/LTWheelConf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwheels.c
172 lines (150 loc) · 3.85 KB
/
wheels.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
169
170
171
#include "wheels.h"
#include <stdio.h>
int get_nativemode_cmd_DFP(cmdstruct *c)
{
c->cmds[0][0] = 0xf8;
c->cmds[0][1] = 0x01;
c->cmds[0][2] = 0x00;
c->cmds[0][3] = 0x00;
c->cmds[0][4] = 0x00;
c->cmds[0][5] = 0x00;
c->cmds[0][6] = 0x00;
c->cmds[0][7] = 0x00;
c->numCmds = 1;
return 0;
}
int get_nativemode_cmd_DFGT(cmdstruct *c)
{
c->cmds[0][0] = 0xf8;
c->cmds[0][1] = 0x0a;
c->cmds[0][2] = 0x00;
c->cmds[0][3] = 0x00;
c->cmds[0][4] = 0x00;
c->cmds[0][5] = 0x00;
c->cmds[0][6] = 0x00;
c->cmds[0][7] = 0x00;
c->cmds[1][0] = 0xf8;
c->cmds[1][1] = 0x09;
c->cmds[1][2] = 0x03;
c->cmds[1][3] = 0x01;
c->cmds[1][4] = 0x00;
c->cmds[1][5] = 0x00;
c->cmds[1][6] = 0x00;
c->cmds[1][7] = 0x00;
c->numCmds = 2;
return 0;
}
int get_nativemode_cmd_G25(cmdstruct *c)
{
c->cmds[0][0] = 0xf8;
c->cmds[0][1] = 0x10;
c->cmds[0][2] = 0x00;
c->cmds[0][3] = 0x00;
c->cmds[0][4] = 0x00;
c->cmds[0][5] = 0x00;
c->cmds[0][6] = 0x00;
c->cmds[0][7] = 0x00;
c->numCmds = 1;
return 0;
}
int get_nativemode_cmd_G27(cmdstruct *c)
{
c->cmds[0][0] = 0xf8;
c->cmds[0][1] = 0x0a;
c->cmds[0][2] = 0x00;
c->cmds[0][3] = 0x00;
c->cmds[0][4] = 0x00;
c->cmds[0][5] = 0x00;
c->cmds[0][6] = 0x00;
c->cmds[0][7] = 0x00;
c->cmds[1][0] = 0xf8;
c->cmds[1][1] = 0x09;
c->cmds[1][2] = 0x04;
c->cmds[1][3] = 0x01;
c->cmds[1][4] = 0x00;
c->cmds[1][5] = 0x00;
c->cmds[1][6] = 0x00;
c->cmds[1][7] = 0x00;
c->numCmds = 2;
return 0;
}
/* used by DFGT, G25, G27 */
int get_range_cmd(cmdstruct *c, int range)
{
c->cmds[0][0] = 0xf8;
c->cmds[0][1] = 0x81;
c->cmds[0][2] = range & 0x00ff;
c->cmds[0][3] = (range & 0xff00)>>8;
c->cmds[0][4] = 0x00;
c->cmds[0][5] = 0x00;
c->cmds[0][6] = 0x00;
c->cmds[0][7] = 0x00;
c->numCmds = 1;
return 0;
}
/* used by DFP
*
* Credits go to MadCatX, slim.one and lbondar for finding out correct formula
* See http://www.lfsforum.net/showthread.php?p=1593389#post1593389
* http://www.lfsforum.net/showthread.php?p=1595604#post1595604
* http://www.lfsforum.net/showthread.php?p=1603971#post1603971
*/
int get_range_cmd2(cmdstruct *c, int range)
{
/* Prepare command A */
c->cmds[0][0] = 0xf8;
c->cmds[0][1] = 0x00; /* Set later */
c->cmds[0][2] = 0x00;
c->cmds[0][3] = 0x00;
c->cmds[0][4] = 0x00;
c->cmds[0][5] = 0x00;
c->cmds[0][6] = 0x00;
c->cmds[0][7] = 0x00;
/* Prepare command B */
c->cmds[1][0] = 0x81;
c->cmds[1][1] = 0x0b;
c->cmds[1][2] = 0x00;
c->cmds[1][3] = 0x00;
c->cmds[1][4] = 0x00;
c->cmds[1][5] = 0x00;
c->cmds[1][6] = 0x00;
c->cmds[1][7] = 0x00;
c->numCmds = 2;
int rampLeft, rampRight, fullRange;
if (range > 200) {
c->cmds[0][1] = 0x03;
if (range == 900) /* Do not limit the range */
return 0;
else
fullRange = 900;
} else {
c->cmds[0][1] = 0x02;
if (range == 200) /* Do not limit the range */
return 0;
else
fullRange = 200;
}
/* Construct range limiting command */
rampLeft = (((fullRange - range + 1) * 2047) / fullRange);
rampRight = 0xfff - rampLeft;
c->cmds[1][2] = rampLeft >> 4;
c->cmds[1][3] = rampRight >> 4;
c->cmds[1][4] = 0xff;
c->cmds[1][5] = (rampRight & 0xe) << 4 | (rampLeft & 0xe);
c->cmds[1][6] = 0xff;
return 0;
}
/* used by all wheels */
int get_autocenter_cmd(cmdstruct *c, int centerforce, int rampspeed)
{
c->cmds[0][0] = 0xfe;
c->cmds[0][1] = 0x0d;
c->cmds[0][2] = rampspeed & 0x0f;
c->cmds[0][3] = rampspeed & 0x0f;
c->cmds[0][4] = centerforce & 0xff;
c->cmds[0][5] = 0x00;
c->cmds[0][6] = 0x00;
c->cmds[0][7] = 0x00;
c->numCmds = 1;
return 0;
}