2024-11-12 15:17:17 +01:00
|
|
|
/****************************************************************************
|
2024-11-12 15:52:39 +01:00
|
|
|
* @file reset_device.cpp
|
2024-11-12 15:17:17 +01:00
|
|
|
* @author Rémi Heredero <remi@heredero.ch>
|
|
|
|
* @author Yann Sierro <yannsierro.pro@gmail.com>
|
|
|
|
*
|
2024-11-12 15:52:39 +01:00
|
|
|
* @brief Reset Device implementation (static scheduling)
|
2024-11-12 15:17:17 +01:00
|
|
|
* @date 2024-11-12
|
|
|
|
* @version 0.1.0
|
|
|
|
****************************************************************************/
|
|
|
|
|
2024-11-12 15:52:39 +01:00
|
|
|
#include "reset_device.hpp"
|
2024-11-12 15:17:17 +01:00
|
|
|
|
|
|
|
// from disco_h747i/wrappers
|
|
|
|
#include <chrono>
|
|
|
|
|
|
|
|
#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 {
|
|
|
|
|
2024-11-17 14:20:38 +01:00
|
|
|
static constexpr std::chrono::microseconds kTaskRunTime = 100000us;
|
2024-11-12 15:17:17 +01:00
|
|
|
|
2024-11-12 15:52:39 +01:00
|
|
|
ResetDevice::ResetDevice(Timer& timer) : _timer(timer), _resetButton(PUSH_BUTTON) {
|
|
|
|
_resetButton.rise(callback(this, &ResetDevice::onRise));
|
|
|
|
}
|
2024-11-12 15:17:17 +01:00
|
|
|
|
2024-11-12 15:52:39 +01:00
|
|
|
bool ResetDevice::checkReset() {
|
2024-11-12 15:17:17 +01:00
|
|
|
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) {
|
2024-11-12 15:52:39 +01:00
|
|
|
if(!isPressed) {
|
2024-11-12 15:17:17 +01:00
|
|
|
isPressed = _resetButton.read() == kPolarityPressed;
|
|
|
|
}
|
|
|
|
elapsedTime = _timer.elapsed_time() - initialTime;
|
|
|
|
}
|
|
|
|
|
2024-11-12 15:52:39 +01:00
|
|
|
return isPressed;
|
|
|
|
|
2024-11-12 15:17:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
std::chrono::microseconds ResetDevice::getPressTime() {
|
|
|
|
return _pressTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResetDevice::onRise() {
|
|
|
|
_pressTime = _timer.elapsed_time();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|