diff --git a/multi_tasking/bike_system.cpp b/multi_tasking/bike_system.cpp index 53ed6c2..a50fa00 100644 --- a/multi_tasking/bike_system.cpp +++ b/multi_tasking/bike_system.cpp @@ -191,6 +191,7 @@ void BikeSystem::speedDistanceTask() { const auto pedalRotationTime = _pedalDevice.getCurrentRotationTime(); _speedometer.setCurrentRotationTime(pedalRotationTime); + _speedometer.setGearSize(getCurrentGearSize()); _currentSpeed = _speedometer.getCurrentSpeed(); diff --git a/multi_tasking/bike_system.hpp b/multi_tasking/bike_system.hpp index c9149a0..19b449f 100644 --- a/multi_tasking/bike_system.hpp +++ b/multi_tasking/bike_system.hpp @@ -82,6 +82,9 @@ class BikeSystem { uint8_t getCurrentGearSize(); void setCurrentGear(uint8_t gear); + void dispatch_isr_events(); + void dispatch_events(); + // timer instance used for loggint task time and used by ResetDevice std::chrono::microseconds _resetTime = std::chrono::microseconds::zero(); std::chrono::microseconds _onGearUpTime = std::chrono::microseconds::zero(); @@ -90,16 +93,23 @@ class BikeSystem { Timer _timer; // data member that represents the device for manipulating the gear GearDevice _gearDevice; + ////////////////////////////////////////////////////////////// // shared resources between the main thread and the isr thread uint8_t _currentGear = bike_computer::kMinGear; uint8_t _currentGearSize = bike_computer::kMinGearSize; ////////////////////////////////////////////////////////////// + // data member that represents the device for manipulating the pedal rotation // speed/time PedalDevice _pedalDevice; + + ////////////////////////////////////////////////////////////// + // shared resources between the main thread and the isr thread float _currentSpeed = 0.0f; float _traveledDistance = 0.0f; + ////////////////////////////////////////////////////////////// + // data member that represents the device used for resetting ResetDevice _resetDevice; // data member that represents the device display @@ -126,9 +136,6 @@ class BikeSystem { // Tread for isr events Thread _isrEventThread; - - void dispatch_isr_events(); - void dispatch_events(); }; } // namespace multi_tasking diff --git a/multi_tasking/pedal_device.cpp b/multi_tasking/pedal_device.cpp index c4c5214..06ecdb5 100644 --- a/multi_tasking/pedal_device.cpp +++ b/multi_tasking/pedal_device.cpp @@ -36,10 +36,9 @@ namespace multi_tasking { -PedalDevice::PedalDevice() { - disco::Joystick::getInstance().setLeftCallback(callback(this, &PedalDevice::onLeft)); - disco::Joystick::getInstance().setRightCallback( - callback(this, &PedalDevice::onRight)); +PedalDevice::PedalDevice(Callback cbOnLeft, Callback cbOnRight) { + disco::Joystick::getInstance().setLeftCallback(callback(cbOnLeft)); + disco::Joystick::getInstance().setRightCallback(callback(cbOnRight)); } std::chrono::milliseconds PedalDevice::getCurrentRotationTime() { diff --git a/multi_tasking/pedal_device.hpp b/multi_tasking/pedal_device.hpp index 60ab832..8787548 100644 --- a/multi_tasking/pedal_device.hpp +++ b/multi_tasking/pedal_device.hpp @@ -33,7 +33,8 @@ namespace multi_tasking { class PedalDevice { public: - PedalDevice(); // NOLINT(runtime/references) + PedalDevice(Callback cbOnLeft, + Callback cbOnRight); // NOLINT(runtime/references) // make the class non copyable PedalDevice(PedalDevice&) = delete; @@ -43,12 +44,6 @@ class PedalDevice { std::chrono::milliseconds getCurrentRotationTime(); private: - // private methods - void onLeft(); - void onRight(); - void increaseRotationSpeed(); - void decreaseRotationSpeed(); - // data members volatile uint32_t _currentStep = static_cast( (bike_computer::kInitialPedalRotationTime - bike_computer::kMinPedalRotationTime)