ADD gear event driven
This commit is contained in:
@@ -38,27 +38,9 @@
|
||||
|
||||
namespace multi_tasking {
|
||||
|
||||
GearDevice::GearDevice() {
|
||||
disco::Joystick::getInstance().setUpCallback(callback(this, &GearDevice::onUp));
|
||||
disco::Joystick::getInstance().setDownCallback(callback(this, &GearDevice::onDown));
|
||||
}
|
||||
|
||||
uint8_t GearDevice::getCurrentGear() { return core_util_atomic_load_u8(&_currentGear); }
|
||||
|
||||
uint8_t GearDevice::getCurrentGearSize() const {
|
||||
return bike_computer::kMaxGearSize - core_util_atomic_load_u8(&_currentGear);
|
||||
}
|
||||
|
||||
void GearDevice::onUp() {
|
||||
if (_currentGear < bike_computer::kMaxGear) {
|
||||
core_util_atomic_incr_u8(&_currentGear, 1);
|
||||
}
|
||||
}
|
||||
|
||||
void GearDevice::onDown() {
|
||||
if (_currentGear > bike_computer::kMinGear) {
|
||||
core_util_atomic_decr_u8(&_currentGear, 1);
|
||||
}
|
||||
GearDevice::GearDevice(Callback<void()> cbOnUp, Callback<void()> cbOnDown) {
|
||||
disco::Joystick::getInstance().setUpCallback(callback(cbOnUp));
|
||||
disco::Joystick::getInstance().setDownCallback(callback(cbOnDown));
|
||||
}
|
||||
|
||||
} // namespace multi_tasking
|
||||
|
||||
Reference in New Issue
Block a user