⚡️ Fix noisy ADC - 16x oversampling with 12-bit ADC (#23867)
This commit is contained in:
committed by
Scott Lahteine
parent
c87eded8f6
commit
260b40d145
@ -68,13 +68,13 @@ Joystick joystick;
|
||||
void Joystick::report() {
|
||||
SERIAL_ECHOPGM("Joystick");
|
||||
#if HAS_JOY_ADC_X
|
||||
SERIAL_ECHOPGM_P(SP_X_STR, JOY_X(x.raw));
|
||||
SERIAL_ECHOPGM_P(SP_X_STR, JOY_X(x.getraw()));
|
||||
#endif
|
||||
#if HAS_JOY_ADC_Y
|
||||
SERIAL_ECHOPGM_P(SP_Y_STR, JOY_Y(y.raw));
|
||||
SERIAL_ECHOPGM_P(SP_Y_STR, JOY_Y(y.getraw()));
|
||||
#endif
|
||||
#if HAS_JOY_ADC_Z
|
||||
SERIAL_ECHOPGM_P(SP_Z_STR, JOY_Z(z.raw));
|
||||
SERIAL_ECHOPGM_P(SP_Z_STR, JOY_Z(z.getraw()));
|
||||
#endif
|
||||
#if HAS_JOY_ADC_EN
|
||||
SERIAL_ECHO_TERNARY(READ(JOY_EN_PIN), " EN=", "HIGH (dis", "LOW (en", "abled)");
|
||||
@ -91,29 +91,29 @@ Joystick joystick;
|
||||
if (READ(JOY_EN_PIN)) return;
|
||||
#endif
|
||||
|
||||
auto _normalize_joy = [](float &axis_jog, const int16_t raw, const int16_t (&joy_limits)[4]) {
|
||||
auto _normalize_joy = [](float &axis_jog, const raw_adc_t raw, const raw_adc_t (&joy_limits)[4]) {
|
||||
if (WITHIN(raw, joy_limits[0], joy_limits[3])) {
|
||||
// within limits, check deadzone
|
||||
if (raw > joy_limits[2])
|
||||
axis_jog = (raw - joy_limits[2]) / float(joy_limits[3] - joy_limits[2]);
|
||||
else if (raw < joy_limits[1])
|
||||
axis_jog = (raw - joy_limits[1]) / float(joy_limits[1] - joy_limits[0]); // negative value
|
||||
axis_jog = int16_t(raw - joy_limits[1]) / float(joy_limits[1] - joy_limits[0]); // negative value
|
||||
// Map normal to jog value via quadratic relationship
|
||||
axis_jog = SIGN(axis_jog) * sq(axis_jog);
|
||||
}
|
||||
};
|
||||
|
||||
#if HAS_JOY_ADC_X
|
||||
static constexpr int16_t joy_x_limits[4] = JOY_X_LIMITS;
|
||||
_normalize_joy(norm_jog.x, JOY_X(x.raw), joy_x_limits);
|
||||
static constexpr raw_adc_t joy_x_limits[4] = JOY_X_LIMITS;
|
||||
_normalize_joy(norm_jog.x, JOY_X(x.getraw()), joy_x_limits);
|
||||
#endif
|
||||
#if HAS_JOY_ADC_Y
|
||||
static constexpr int16_t joy_y_limits[4] = JOY_Y_LIMITS;
|
||||
_normalize_joy(norm_jog.y, JOY_Y(y.raw), joy_y_limits);
|
||||
static constexpr raw_adc_t joy_y_limits[4] = JOY_Y_LIMITS;
|
||||
_normalize_joy(norm_jog.y, JOY_Y(y.getraw()), joy_y_limits);
|
||||
#endif
|
||||
#if HAS_JOY_ADC_Z
|
||||
static constexpr int16_t joy_z_limits[4] = JOY_Z_LIMITS;
|
||||
_normalize_joy(norm_jog.z, JOY_Z(z.raw), joy_z_limits);
|
||||
static constexpr raw_adc_t joy_z_limits[4] = JOY_Z_LIMITS;
|
||||
_normalize_joy(norm_jog.z, JOY_Z(z.getraw()), joy_z_limits);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user