ADD ResetDevice
This commit is contained in:
parent
7b62a3634b
commit
874a968f5c
59
static_scheduling/reset_device.cpp
Normal file
59
static_scheduling/reset_device.cpp
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* @file pedal_device.cpp
|
||||||
|
* @author Rémi Heredero <remi@heredero.ch>
|
||||||
|
* @author Yann Sierro <yannsierro.pro@gmail.com>
|
||||||
|
*
|
||||||
|
* @brief Pedal Device implementation (static scheduling)
|
||||||
|
* @date 2024-11-12
|
||||||
|
* @version 0.1.0
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include "reset_device.h"
|
||||||
|
|
||||||
|
// 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 {
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
56
static_scheduling/reset_device.hpp
Normal file
56
static_scheduling/reset_device.hpp
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
// Copyright 2022 Haute école d'ingénierie et d'architecture de Fribourg
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* @file reset_device.hpp
|
||||||
|
* @author Serge Ayer <serge.ayer@hefr.ch>
|
||||||
|
*
|
||||||
|
* @brief ResetDevice header file (static scheduling)
|
||||||
|
*
|
||||||
|
* @date 2023-08-20
|
||||||
|
* @version 1.0.0
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "mbed.h"
|
||||||
|
|
||||||
|
namespace static_scheduling {
|
||||||
|
|
||||||
|
class ResetDevice {
|
||||||
|
public:
|
||||||
|
explicit ResetDevice(Timer& timer); // NOLINT(runtime/references)
|
||||||
|
|
||||||
|
// make the class non copyable
|
||||||
|
ResetDevice(ResetDevice&) = delete;
|
||||||
|
ResetDevice& operator=(ResetDevice&) = delete;
|
||||||
|
|
||||||
|
// method called for checking the reset status
|
||||||
|
bool checkReset();
|
||||||
|
|
||||||
|
// for computing the response time
|
||||||
|
std::chrono::microseconds getPressTime();
|
||||||
|
|
||||||
|
private:
|
||||||
|
// called when the button is pressed
|
||||||
|
void onRise();
|
||||||
|
|
||||||
|
// data members
|
||||||
|
// instance representing the reset button
|
||||||
|
InterruptIn _resetButton;
|
||||||
|
Timer& _timer;
|
||||||
|
std::chrono::microseconds _pressTime;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace static_scheduling
|
Loading…
x
Reference in New Issue
Block a user