forked from ranenbg/Arduino-FFB-gui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Slajder_class.pde
148 lines (138 loc) · 4.08 KB
/
Slajder_class.pde
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
class Slajder {
color c;
float x, y, s, am, axisVal;
String l, la, lb;
xyCal[] yLimits = new xyCal[2];
boolean yLimitsVisible, ffb;
float[] pCal = new float[2];
int id;
Slajder(color acolor, float posx, float posy, float size, float axisMax, String label, String labela, String labelb, boolean ffbaxis) {
c = acolor;
x = posx;
y = posy;
s = size;
am = axisMax;
l = label;
la = labela;
lb = labelb;
ffb = ffbaxis;
yLimits[0] = new xyCal(x-2.8*s, y, s, s, 3, la);
yLimits[1] = new xyCal(x-2.8*s, y-2*axisScale, s, s, 3, lb);
yLimits[0].active = true;
yLimits[1].active = true;
yLimitsVisible = false;
pCal[0] = 0; // minimum cal value
pCal[1] = axisMax; // maximum cal value
}
void update(int i) {
if (i == 0) { // X-axis
axisVal = gpad.getSlider("Xaxis").getValue();
if (axisVal != prevaxis) wheelMoved = true;
} else if (i == 1) { // Y-axis
axisVal = gpad.getSlider("Yaxis").getValue();
} else if (i == 2) { // Z-axis
axisVal = gpad.getSlider("Zaxis").getValue();
} else if (i == 3) { // RX-axis
axisVal = gpad.getSlider("RXaxis").getValue();
} else if (i == 4) { // RY-axis
axisVal = gpad.getSlider("RYaxis").getValue();
} else {
axisVal = 0.0;
}
// update axis view with FFB marking
if (FFBAxisIndex == i) {
ffb = true; // axis with FFB mark
} else {
ffb = false; // axis without FFB mark
}
setpCal();
id = i;
}
void getyLimits(int i) { // get yLimits value from mouse position
yLimits[i].y = mouseY; // update yLimits y position
updateyLimitsLimit(i);
checkyLimitsLimit(i);
}
void setpCal() { // set pedal calibration from wheel control
for (int i=0; i<yLimits.length; i++) {
if (yLimits[i].changing) {
getyLimits(i);
pCal[i] = getpCalFromyLimits(i);
}
}
}
void updateCal(float min, float max) {
pCal[0] = min;
pCal[1] = max;
for (int i=0; i<yLimits.length; i++) {
yLimits[i].y = convertToyLimits(i);
updateyLimitsLimit(i);
checkyLimitsLimit(i);
}
}
float getpCalFromyLimits(int i) { // convert graph coordinates into pCal values
return map(yLimits[i].y, y, y-2*axisScale, 0, am);
}
float convertToyLimits(int i) { // convert pCal values into graph coordinates
return map(pCal[i], 0, am, y, y-2*axisScale);
}
void updateyLimitsLimit(int i) { // update pedal calibration limits in the scaled units
if (i == 0) {
yLimits[i].limits[2] = yLimits[i+1].y + s; // d low limit is e
yLimits[i].limits[3] = y - 0*s/2; // d high limit is 2*axisScale
}
if (i == 1) {
yLimits[i].limits[2] = y-2*axisScale + 0*s/2; // e low limit is 0
yLimits[i].limits[3] = yLimits[i-1].y - s; // e high limit is d
}
}
void checkyLimitsLimit(int i) { // checks if scaled pCal values are withing limits and limit them if they are not
if (yLimits[i].y <= yLimits[i].limits[2]) {
yLimits[i].y = yLimits[i].limits[2];
} else if (yLimits[i].y >= yLimits[i].limits[3]) {
yLimits[i].y = yLimits[i].limits[3];
}
}
void show() {
fill(c);
strokeWeight(1);
stroke(255);
pushMatrix();
rectMode(CORNER);
rect(x, y, s, -axisScale-axisVal*axisScale);
translate(x-15, y);
float n = axisScale/10;
float m = n/5;
for (int i = 0; i > -20; i--) {
for (int j = 0; j > -5; j--) {
line(0, i*n, 10, i*n);
line(0, j*m + i*n, 5, j*m + i*n);
}
}
line(0, -20*n, 10, -20*n);
fill(255);
text(round(map(axisVal, -1, 1, 0, am)), 0, -(2*n+1)*10);
if (ffb) {
noFill();
//stroke(c);
rect(15, 14, 18, -10);
textSize(0.8*font_size);
//fill(c);
text("FFB", 15, 13);
}
fill(255);
textSize(font_size);
if (id < 3) {
text(l, -2, 20);
} else {
text(l, -font_size/2, 20);
}
popMatrix();
if (yLimitsVisible) {
for (int j=0; j<yLimits.length; j++) {
yLimits[j].updateColors(ctrl_btn+ctrl_sh_btn+2*(id-1)+j);
yLimits[j].showPointer(2.8*s, 0);
}
}
}
}