FIX ResetDevice

- Initialisation
- Callback
- return of checkReset
This commit is contained in:
Rémi Heredero 2024-11-12 15:52:39 +01:00 committed by Fastium
parent 874a968f5c
commit 6d0452d9ca

View File

@ -1,14 +1,14 @@
/**************************************************************************** /****************************************************************************
* @file pedal_device.cpp * @file reset_device.cpp
* @author Rémi Heredero <remi@heredero.ch> * @author Rémi Heredero <remi@heredero.ch>
* @author Yann Sierro <yannsierro.pro@gmail.com> * @author Yann Sierro <yannsierro.pro@gmail.com>
* *
* @brief Pedal Device implementation (static scheduling) * @brief Reset Device implementation (static scheduling)
* @date 2024-11-12 * @date 2024-11-12
* @version 0.1.0 * @version 0.1.0
****************************************************************************/ ****************************************************************************/
#include "reset_device.h" #include "reset_device.hpp"
// from disco_h747i/wrappers // from disco_h747i/wrappers
#include <chrono> #include <chrono>
@ -30,20 +30,24 @@ namespace static_scheduling {
static constexpr std::chrono::microseconds kTaskRunTime = 1000000us; static constexpr std::chrono::microseconds kTaskRunTime = 1000000us;
ResetDevice::ResetDevice(Timer& timer) : timer_(timer) {} ResetDevice::ResetDevice(Timer& timer) : _timer(timer), _resetButton(PUSH_BUTTON) {
_resetButton.rise(callback(this, &ResetDevice::onRise));
}
std::chrono::milliseconds ResetDevice::checkReset() { bool ResetDevice::checkReset() {
std::chrono::microseconds initialTime = _timer.elapsed_time(); std::chrono::microseconds initialTime = _timer.elapsed_time();
std::chrono::microseconds elapsedTime = std::chrono::microseconds::zero(); std::chrono::microseconds elapsedTime = std::chrono::microseconds::zero();
// we bound the change to one increment/decrement per call // we bound the change to one increment/decrement per call
bool isPressed = false; bool isPressed = false;
while (elapsedTime < kTaskRunTime) { while (elapsedTime < kTaskRunTime) {
if(!hasChanged) { if(!isPressed) {
isPressed = _resetButton.read() == kPolarityPressed; isPressed = _resetButton.read() == kPolarityPressed;
} }
elapsedTime = _timer.elapsed_time() - initialTime; elapsedTime = _timer.elapsed_time() - initialTime;
} }
return isPressed;
} }
std::chrono::microseconds ResetDevice::getPressTime() { std::chrono::microseconds ResetDevice::getPressTime() {