WIP
This commit is contained in:
@@ -187,41 +187,39 @@ int calibrateJoystick(Joystick *js)
|
||||
ERROR(ERRNO_NULLPOINTER);
|
||||
}
|
||||
curmillis = millis();
|
||||
if ( js->state == JOYSTICK_STATE_CALIBRATING ) {
|
||||
if ( js->x.calibration.start_time == 0 || js->y.calibration.start_time == 0 ) {
|
||||
// Starting a new calibration cycle
|
||||
Serial.printf("Starting a new calibration cycle\n");
|
||||
js->x.calibration.low = 65535;
|
||||
js->x.calibration.high = 0;
|
||||
js->y.calibration.low = 65535;
|
||||
js->y.calibration.high = 0;
|
||||
js->x.calibration.start_time = curmillis;
|
||||
js->y.calibration.start_time = curmillis;
|
||||
return ERRNO_SUCCESS;
|
||||
}
|
||||
if ( (curmillis - js->x.calibration.start_time) >= js->x.calibration.stable_time ) {
|
||||
js->state = JOYSTICK_STATE_CALIBRATED;
|
||||
js->x.calibration.start_time = 0;
|
||||
js->y.calibration.start_time = 0;
|
||||
Serial.printf("Calibrated joystick to x: <%d, %d> y <%d, %d>\n",
|
||||
js->x.calibration.low,
|
||||
js->x.calibration.high,
|
||||
js->y.calibration.low,
|
||||
js->y.calibration.high);
|
||||
return ERRNO_SUCCESS;
|
||||
}
|
||||
x = analogRead(js->x.pin);
|
||||
if ( x < js->x.calibration.low ) {
|
||||
js->x.calibration.low = x;
|
||||
} else if ( x > js->x.calibration.high ) {
|
||||
js->x.calibration.high = x;
|
||||
}
|
||||
y = analogRead(js->y.pin);
|
||||
if ( y < js->y.calibration.low ) {
|
||||
js->y.calibration.low = y;
|
||||
} else if ( y > js->y.calibration.high ) {
|
||||
js->y.calibration.high = y;
|
||||
}
|
||||
if ( js->x.calibration.start_time == 0 || js->y.calibration.start_time == 0 ) {
|
||||
// Starting a new calibration cycle
|
||||
Serial.printf("Starting a new calibration cycle\n");
|
||||
js->x.calibration.low = 65535;
|
||||
js->x.calibration.high = 0;
|
||||
js->y.calibration.low = 65535;
|
||||
js->y.calibration.high = 0;
|
||||
js->x.calibration.start_time = curmillis;
|
||||
js->y.calibration.start_time = curmillis;
|
||||
return ERRNO_SUCCESS;
|
||||
}
|
||||
if ( (curmillis - js->x.calibration.start_time) >= js->x.calibration.stable_time ) {
|
||||
js->state = JOYSTICK_STATE_CALIBRATED;
|
||||
js->x.calibration.start_time = 0;
|
||||
js->y.calibration.start_time = 0;
|
||||
Serial.printf("Calibrated joystick to x: <%d, %d> y <%d, %d>\n",
|
||||
js->x.calibration.low,
|
||||
js->x.calibration.high,
|
||||
js->y.calibration.low,
|
||||
js->y.calibration.high);
|
||||
return ERRNO_SUCCESS;
|
||||
}
|
||||
x = analogRead(js->x.pin);
|
||||
if ( x < js->x.calibration.low ) {
|
||||
js->x.calibration.low = x;
|
||||
} else if ( x > js->x.calibration.high ) {
|
||||
js->x.calibration.high = x;
|
||||
}
|
||||
y = analogRead(js->y.pin);
|
||||
if ( y < js->y.calibration.low ) {
|
||||
js->y.calibration.low = y;
|
||||
} else if ( y > js->y.calibration.high ) {
|
||||
js->y.calibration.high = y;
|
||||
}
|
||||
return ERRNO_SUCCESS;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user