ADD gear event driven

This commit is contained in:
fastium
2024-12-31 13:47:36 +01:00
parent 34a57162ba
commit f64b8bdd9a
4 changed files with 107 additions and 53 deletions

View File

@@ -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