ADD part of mail for pedal device

This commit is contained in:
fastium 2024-12-31 16:02:42 +01:00
parent 36e4a07102
commit 946e86025c
4 changed files with 16 additions and 14 deletions

View File

@ -191,6 +191,7 @@ void BikeSystem::speedDistanceTask() {
const auto pedalRotationTime = _pedalDevice.getCurrentRotationTime(); const auto pedalRotationTime = _pedalDevice.getCurrentRotationTime();
_speedometer.setCurrentRotationTime(pedalRotationTime); _speedometer.setCurrentRotationTime(pedalRotationTime);
_speedometer.setGearSize(getCurrentGearSize()); _speedometer.setGearSize(getCurrentGearSize());
_currentSpeed = _speedometer.getCurrentSpeed(); _currentSpeed = _speedometer.getCurrentSpeed();

View File

@ -82,6 +82,9 @@ class BikeSystem {
uint8_t getCurrentGearSize(); uint8_t getCurrentGearSize();
void setCurrentGear(uint8_t gear); void setCurrentGear(uint8_t gear);
void dispatch_isr_events();
void dispatch_events();
// timer instance used for loggint task time and used by ResetDevice // timer instance used for loggint task time and used by ResetDevice
std::chrono::microseconds _resetTime = std::chrono::microseconds::zero(); std::chrono::microseconds _resetTime = std::chrono::microseconds::zero();
std::chrono::microseconds _onGearUpTime = std::chrono::microseconds::zero(); std::chrono::microseconds _onGearUpTime = std::chrono::microseconds::zero();
@ -90,16 +93,23 @@ class BikeSystem {
Timer _timer; Timer _timer;
// data member that represents the device for manipulating the gear // data member that represents the device for manipulating the gear
GearDevice _gearDevice; GearDevice _gearDevice;
////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////
// shared resources between the main thread and the isr thread // shared resources between the main thread and the isr thread
uint8_t _currentGear = bike_computer::kMinGear; uint8_t _currentGear = bike_computer::kMinGear;
uint8_t _currentGearSize = bike_computer::kMinGearSize; uint8_t _currentGearSize = bike_computer::kMinGearSize;
////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////
// data member that represents the device for manipulating the pedal rotation // data member that represents the device for manipulating the pedal rotation
// speed/time // speed/time
PedalDevice _pedalDevice; PedalDevice _pedalDevice;
//////////////////////////////////////////////////////////////
// shared resources between the main thread and the isr thread
float _currentSpeed = 0.0f; float _currentSpeed = 0.0f;
float _traveledDistance = 0.0f; float _traveledDistance = 0.0f;
//////////////////////////////////////////////////////////////
// data member that represents the device used for resetting // data member that represents the device used for resetting
ResetDevice _resetDevice; ResetDevice _resetDevice;
// data member that represents the device display // data member that represents the device display
@ -126,9 +136,6 @@ class BikeSystem {
// Tread for isr events // Tread for isr events
Thread _isrEventThread; Thread _isrEventThread;
void dispatch_isr_events();
void dispatch_events();
}; };
} // namespace multi_tasking } // namespace multi_tasking

View File

@ -36,10 +36,9 @@
namespace multi_tasking { namespace multi_tasking {
PedalDevice::PedalDevice() { PedalDevice::PedalDevice(Callback<void()> cbOnLeft, Callback<void()> cbOnRight) {
disco::Joystick::getInstance().setLeftCallback(callback(this, &PedalDevice::onLeft)); disco::Joystick::getInstance().setLeftCallback(callback(cbOnLeft));
disco::Joystick::getInstance().setRightCallback( disco::Joystick::getInstance().setRightCallback(callback(cbOnRight));
callback(this, &PedalDevice::onRight));
} }
std::chrono::milliseconds PedalDevice::getCurrentRotationTime() { std::chrono::milliseconds PedalDevice::getCurrentRotationTime() {

View File

@ -33,7 +33,8 @@ namespace multi_tasking {
class PedalDevice { class PedalDevice {
public: public:
PedalDevice(); // NOLINT(runtime/references) PedalDevice(Callback<void()> cbOnLeft,
Callback<void()> cbOnRight); // NOLINT(runtime/references)
// make the class non copyable // make the class non copyable
PedalDevice(PedalDevice&) = delete; PedalDevice(PedalDevice&) = delete;
@ -43,12 +44,6 @@ class PedalDevice {
std::chrono::milliseconds getCurrentRotationTime(); std::chrono::milliseconds getCurrentRotationTime();
private: private:
// private methods
void onLeft();
void onRight();
void increaseRotationSpeed();
void decreaseRotationSpeed();
// data members // data members
volatile uint32_t _currentStep = static_cast<uint32_t>( volatile uint32_t _currentStep = static_cast<uint32_t>(
(bike_computer::kInitialPedalRotationTime - bike_computer::kMinPedalRotationTime) (bike_computer::kInitialPedalRotationTime - bike_computer::kMinPedalRotationTime)