/**************************************************************************** * @file pedal_device.cpp * @author RĂ©mi Heredero * @author Yann Sierro * * @brief Pedal Device implementation (static scheduling) * @date 2024-11-12 * @version 0.1.0 ****************************************************************************/ #include "reset_device.h" // from disco_h747i/wrappers #include #include "joystick.hpp" #include "mbed_trace.h" #if defined(TARGET_DISCO_H747I) #define PUSH_BUTTON BUTTON1 static constexpr uint8_t kPolarityPressed = 1; #endif #if MBED_CONF_MBED_TRACE_ENABLE #define TRACE_GROUP "PedalDevice" #endif // MBED_CONF_MBED_TRACE_ENABLE namespace static_scheduling { static constexpr std::chrono::microseconds kTaskRunTime = 1000000us; ResetDevice::ResetDevice(Timer& timer) : timer_(timer) {} std::chrono::milliseconds ResetDevice::checkReset() { std::chrono::microseconds initialTime = _timer.elapsed_time(); std::chrono::microseconds elapsedTime = std::chrono::microseconds::zero(); // we bound the change to one increment/decrement per call bool isPressed = false; while (elapsedTime < kTaskRunTime) { if(!hasChanged) { isPressed = _resetButton.read() == kPolarityPressed; } elapsedTime = _timer.elapsed_time() - initialTime; } } std::chrono::microseconds ResetDevice::getPressTime() { return _pressTime; } void ResetDevice::onRise() { _pressTime = _timer.elapsed_time(); } }