Two axis analog (2x potmeter) joystick driver.
Diff: Joystick.cpp
- Revision:
- 3:cd36fdbb23f8
- Parent:
- 0:f76f52dc57f7
- Child:
- 4:f2f560cb71fe
--- a/Joystick.cpp Thu Feb 09 19:36:26 2017 +0000 +++ b/Joystick.cpp Mon Feb 13 07:10:23 2017 +0000 @@ -13,7 +13,16 @@ void Joystick::process() { JoystickValue newValue(_xIn.read_u16(), _yIn.read_u16()); - if (_calibrated) + if (!_calibrated) //Calibrating + { + _center.x = (_center.x + newValue.x) / 2; + _center.y = (_center.y + newValue.y) / 2; + if (++_calibrationCounter >= JOYSTICK_CALIBRATION_CYCLES) + { + _calibrated = true; + } + } + else if (!_locked) //Normal process if not locked { if (newValue.x < _center.x - JOYSTICK_CENTER_DEADZONE) { @@ -55,15 +64,5 @@ _onChange(_joyValue, joyPrev); } } - else - { - _center.x = (_center.x + newValue.x) / 2; - _center.y = (_center.y + newValue.y) / 2; - if (++_calibrationCounter >= JOYSTICK_CALIBRATION_CYCLES) - { - _calibrated = true; - } - } } -