ADD modification from issue
This commit is contained in:
commit
4c9a0e25a7
@ -1,24 +1,27 @@
|
||||
files: ^main.cpp
|
||||
files: ^main.cpp|^static_scheduling|^static_scheduling_with_event|^TESTS
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v4.3.0
|
||||
hooks:
|
||||
- id: check-yaml
|
||||
args: [--allow-multiple-documents]
|
||||
- id: end-of-file-fixer
|
||||
- id: trailing-whitespace
|
||||
- repo: https://github.com/pre-commit/mirrors-clang-format
|
||||
rev: 'v14.0.6'
|
||||
- repo: https://github.com/pre-commit/mirrors-clang-format
|
||||
rev: "v14.0.6"
|
||||
hooks:
|
||||
- id: clang-format
|
||||
- repo: https://github.com/cpplint/cpplint
|
||||
rev: '1.6.1'
|
||||
- repo: https://github.com/cpplint/cpplint
|
||||
rev: "1.6.1"
|
||||
hooks:
|
||||
- id: cpplint
|
||||
- repo: local
|
||||
name: cpplint
|
||||
entry: cpplint --linelength=90 --filter=-build/include_subdir,-whitespace/indent,-build/namespaces,-build/c++11
|
||||
- repo: local
|
||||
hooks:
|
||||
- id: cppcheck
|
||||
name: cppcheck
|
||||
require_serial: true
|
||||
entry: cppcheck --enable=all --suppress=missingInclude:* --inline-suppr -i mbed-os --std=c++14 --error-exitcode=1
|
||||
entry: cppcheck --enable=all --suppress=missingInclude --inline-suppr -i mbed-os --std=c++14 --error-exitcode=1
|
||||
# --suppress=missingIncludeSystem
|
||||
language: system
|
@ -24,16 +24,16 @@
|
||||
|
||||
#include <chrono>
|
||||
|
||||
#include "static_scheduling/bike_system.hpp"
|
||||
#include "static_scheduling_with_event/bike_system.hpp"
|
||||
|
||||
#include "greentea-client/test_env.h"
|
||||
#include "mbed.h"
|
||||
#include "static_scheduling/bike_system.hpp"
|
||||
#include "static_scheduling_with_event/bike_system.hpp"
|
||||
#include "task_logger.hpp"
|
||||
#include "unity/unity.h"
|
||||
#include "utest/utest.h"
|
||||
|
||||
using namespace utest::v1;
|
||||
namespace utest {
|
||||
namespace v1 {
|
||||
|
||||
// test_bike_system handler function
|
||||
static void test_bike_system() {
|
||||
@ -80,7 +80,8 @@ static void test_bike_system_event_queue() {
|
||||
|
||||
// run the bike system in a separate thread
|
||||
Thread thread;
|
||||
thread.start(callback(&bikeSystem, &static_scheduling::BikeSystem::startWithEventQueue));
|
||||
thread.start(
|
||||
callback(&bikeSystem, &static_scheduling::BikeSystem::startWithEventQueue));
|
||||
|
||||
// let the bike system run for 20 secs
|
||||
ThisThread::sleep_for(20s);
|
||||
@ -139,9 +140,9 @@ static void test_bike_system_with_event() {
|
||||
}
|
||||
}
|
||||
|
||||
static utest::v1::status_t greentea_setup(const size_t number_of_cases) {
|
||||
// Here, we specify the timeout (60s) and the host test (a built-in host test or the
|
||||
// name of our Python file)
|
||||
static status_t greentea_setup(const size_t number_of_cases) {
|
||||
// Here, we specify the timeout (60s) and the host test (a built-in host test
|
||||
// or the name of our Python file)
|
||||
GREENTEA_SETUP(180, "default_auto");
|
||||
|
||||
return greentea_test_setup_handler(number_of_cases);
|
||||
@ -156,4 +157,7 @@ static Case cases[] = {
|
||||
|
||||
static Specification specification(greentea_setup, cases);
|
||||
|
||||
int main() { return !Harness::run(specification); }
|
||||
}; // namespace v1
|
||||
}; // namespace utest
|
||||
|
||||
int main() { return !utest::v1::Harness::run(utest::v1::specification); }
|
||||
|
@ -29,7 +29,8 @@
|
||||
#include "unity/unity.h"
|
||||
#include "utest/utest.h"
|
||||
|
||||
using namespace utest::v1;
|
||||
namespace utest {
|
||||
namespace v1 {
|
||||
|
||||
// test_hdc1000 test handler function
|
||||
static control_t test_sensor_device(const size_t call_count) {
|
||||
@ -53,9 +54,9 @@ static control_t test_sensor_device(const size_t call_count) {
|
||||
return CaseNext;
|
||||
}
|
||||
|
||||
static utest::v1::status_t greentea_setup(const size_t number_of_cases) {
|
||||
// Here, we specify the timeout (60s) and the host test (a built-in host test or the
|
||||
// name of our Python file)
|
||||
static status_t greentea_setup(const size_t number_of_cases) {
|
||||
// Here, we specify the timeout (60s) and the host test (a built-in host test
|
||||
// or the name of our Python file)
|
||||
GREENTEA_SETUP(60, "default_auto");
|
||||
|
||||
return greentea_test_setup_handler(number_of_cases);
|
||||
@ -65,5 +66,7 @@ static utest::v1::status_t greentea_setup(const size_t number_of_cases) {
|
||||
static Case cases[] = {Case("test sensor device", test_sensor_device)};
|
||||
|
||||
static Specification specification(greentea_setup, cases);
|
||||
}; // namespace v1
|
||||
}; // namespace utest
|
||||
|
||||
int main() { return !Harness::run(specification); }
|
||||
int main() { return !utest::v1::Harness::run(utest::v1::specification); }
|
||||
|
@ -32,13 +32,14 @@
|
||||
#include "unity/unity.h"
|
||||
#include "utest/utest.h"
|
||||
|
||||
using namespace utest::v1;
|
||||
|
||||
// allow for 0.1 km/h difference
|
||||
static constexpr float kAllowedSpeedDelta = 0.1f;
|
||||
// allow for 1m difference
|
||||
static constexpr float kAllowedDistanceDelta = 1.0f / 1000.0;
|
||||
|
||||
namespace utest {
|
||||
namespace v1 {
|
||||
|
||||
// function called by test handler functions for verifying the current speed
|
||||
void check_current_speed(const std::chrono::milliseconds& pedalRotationTime,
|
||||
uint8_t traySize,
|
||||
@ -75,7 +76,8 @@ float compute_distance(const std::chrono::milliseconds& pedalRotationTime,
|
||||
float trayGearRatio = static_cast<float>(traySize) / static_cast<float>(gearSize);
|
||||
float distancePerPedalTurn = trayGearRatio * wheelCircumference;
|
||||
|
||||
// distancePerPedalTurn is expressed in m, divide per 1000 for a distance in km
|
||||
// distancePerPedalTurn is expressed in m, divide per 1000 for a distance in
|
||||
// km
|
||||
return (distancePerPedalTurn * pedalRotations) / 1000.0;
|
||||
}
|
||||
|
||||
@ -86,7 +88,8 @@ void check_distance(const std::chrono::milliseconds& pedalRotationTime,
|
||||
float wheelCircumference,
|
||||
const std::chrono::milliseconds& travelTime,
|
||||
float distance) {
|
||||
// distancePerPedalTurn is expressed in m, divide per 1000 for a distance in km
|
||||
// distancePerPedalTurn is expressed in m, divide per 1000 for a distance in
|
||||
// km
|
||||
float expectedDistance = compute_distance(
|
||||
pedalRotationTime, traySize, gearSize, wheelCircumference, travelTime);
|
||||
printf(" Expected distance is %f, current distance is %f\n",
|
||||
@ -334,9 +337,9 @@ static control_t test_reset(const size_t call_count) {
|
||||
return CaseNext;
|
||||
}
|
||||
|
||||
static utest::v1::status_t greentea_setup(const size_t number_of_cases) {
|
||||
// Here, we specify the timeout (60s) and the host test (a built-in host test or the
|
||||
// name of our Python file)
|
||||
static status_t greentea_setup(const size_t number_of_cases) {
|
||||
// Here, we specify the timeout (60s) and the host test (a built-in host test
|
||||
// or the name of our Python file)
|
||||
GREENTEA_SETUP(180, "default_auto");
|
||||
|
||||
return greentea_test_setup_handler(number_of_cases);
|
||||
@ -350,5 +353,7 @@ static Case cases[] = {
|
||||
Case("test speedometer reset", test_reset)};
|
||||
|
||||
static Specification specification(greentea_setup, cases);
|
||||
}; // namespace v1
|
||||
}; // namespace utest
|
||||
|
||||
int main() { return !Harness::run(specification); }
|
||||
int main() { return !utest::v1::Harness::run(utest::v1::specification); }
|
||||
|
@ -27,7 +27,8 @@
|
||||
#include "unity/unity.h"
|
||||
#include "utest/utest.h"
|
||||
|
||||
using namespace utest::v1;
|
||||
namespace utest {
|
||||
namespace v1 {
|
||||
|
||||
// test handler function
|
||||
static control_t always_succeed(const size_t call_count) {
|
||||
@ -38,9 +39,9 @@ static control_t always_succeed(const size_t call_count) {
|
||||
return CaseNext;
|
||||
}
|
||||
|
||||
static utest::v1::status_t greentea_setup(const size_t number_of_cases) {
|
||||
// Here, we specify the timeout (60s) and the host test (a built-in host test or the
|
||||
// name of our Python file)
|
||||
static status_t greentea_setup(const size_t number_of_cases) {
|
||||
// Here, we specify the timeout (60s) and the host test (a built-in host test
|
||||
// or the name of our Python file)
|
||||
GREENTEA_SETUP(60, "default_auto");
|
||||
|
||||
return greentea_test_setup_handler(number_of_cases);
|
||||
@ -51,4 +52,7 @@ static Case cases[] = {Case("always succeed test", always_succeed)};
|
||||
|
||||
static Specification specification(greentea_setup, cases);
|
||||
|
||||
int main() { return !Harness::run(specification); }
|
||||
}; // namespace v1
|
||||
}; // namespace utest
|
||||
|
||||
int main() { return !utest::v1::Harness::run(utest::v1::specification); }
|
||||
|
@ -24,12 +24,14 @@
|
||||
* @version 0.2.0
|
||||
***************************************************************************/
|
||||
|
||||
#include "greentea-client/test_env.h"
|
||||
#include "mbed.h"
|
||||
#include "unity/unity.h"
|
||||
#include "utest/utest.h"
|
||||
#include "greentea-client/test_env.h" // NOLINT
|
||||
#include "mbed.h" // NOLINT
|
||||
#include "unity/unity.h" // NOLINT
|
||||
#include "utest/utest.h" // NOLINT
|
||||
|
||||
namespace utest {
|
||||
namespace v1 {
|
||||
|
||||
using namespace utest::v1;
|
||||
struct Test {
|
||||
Test() {
|
||||
_instanceCount++;
|
||||
@ -48,7 +50,8 @@ struct Test {
|
||||
uint32_t Test::_instanceCount = 0;
|
||||
|
||||
/**
|
||||
* Test that a shared pointer correctly manages the lifetime of the underlying raw pointer
|
||||
* Test that a shared pointer correctly manages the lifetime of the underlying
|
||||
* raw pointer
|
||||
*/
|
||||
void test_single_sharedptr_lifetime() {
|
||||
// Sanity-check value of counter
|
||||
@ -66,8 +69,8 @@ void test_single_sharedptr_lifetime() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that multiple instances of shared pointers correctly manage the reference count
|
||||
* to release the object at the correct point
|
||||
* Test that multiple instances of shared pointers correctly manage the
|
||||
* reference count to release the object at the correct point
|
||||
*/
|
||||
void test_instance_sharing() {
|
||||
std::shared_ptr<Test> shared_ptr1(nullptr);
|
||||
@ -97,8 +100,8 @@ void test_instance_sharing() {
|
||||
}
|
||||
|
||||
/**********************
|
||||
* UNIQUE PTR EXERCISE *
|
||||
**********************/
|
||||
* UNIQUE PTR EXERCISE *
|
||||
**********************/
|
||||
|
||||
/*
|
||||
* Check normal lifetime on a unique_ptr
|
||||
@ -132,12 +135,12 @@ void test_unique_ptr_transfer() {
|
||||
TEST_ASSERT_EQUAL(0, Test::_instanceCount);
|
||||
|
||||
{
|
||||
//create p1
|
||||
// create p1
|
||||
std::unique_ptr<Test> p1 = std::make_unique<Test>();
|
||||
TEST_ASSERT_EQUAL(Test::kMagicNumber, p1->_value);
|
||||
TEST_ASSERT_EQUAL(1, Test::_instanceCount);
|
||||
|
||||
//transfer p1 to p2
|
||||
// transfer p1 to p2
|
||||
std::unique_ptr<Test> p2 = std::move(p1);
|
||||
TEST_ASSERT_EQUAL(Test::kMagicNumber, p2->_value);
|
||||
TEST_ASSERT_EQUAL(1, Test::_instanceCount);
|
||||
@ -145,7 +148,7 @@ void test_unique_ptr_transfer() {
|
||||
p2.reset();
|
||||
|
||||
TEST_ASSERT_EQUAL(0, Test::_instanceCount);
|
||||
TEST_ASSERT(!p1);
|
||||
TEST_ASSERT(!p1); // cppcheck-suppress accessMoved
|
||||
TEST_ASSERT(!p2);
|
||||
}
|
||||
|
||||
@ -160,13 +163,13 @@ void test_unique_ptr_release() {
|
||||
TEST_ASSERT_EQUAL(0, Test::_instanceCount);
|
||||
|
||||
{
|
||||
//create p1
|
||||
// create p1
|
||||
std::unique_ptr<Test> p1 = std::make_unique<Test>();
|
||||
TEST_ASSERT_EQUAL(Test::kMagicNumber, p1->_value);
|
||||
TEST_ASSERT_EQUAL(1, Test::_instanceCount);
|
||||
|
||||
//transfer and release p1 to p2
|
||||
Test * p2 = p1.release();
|
||||
// transfer and release p1 to p2
|
||||
Test* p2 = p1.release();
|
||||
TEST_ASSERT_EQUAL(Test::kMagicNumber, p2->_value);
|
||||
TEST_ASSERT_EQUAL(1, Test::_instanceCount);
|
||||
|
||||
@ -192,21 +195,21 @@ void test_unique_ptr_swap() {
|
||||
const uint32_t number1 = 65;
|
||||
const uint32_t number2 = 42;
|
||||
|
||||
//create p1
|
||||
// create p1
|
||||
std::unique_ptr<Test> p1 = std::make_unique<Test>();
|
||||
TEST_ASSERT_EQUAL(Test::kMagicNumber, p1->_value);
|
||||
TEST_ASSERT_EQUAL(1, Test::_instanceCount);
|
||||
p1->_value = number1;
|
||||
TEST_ASSERT_EQUAL(number1, p1->_value);
|
||||
|
||||
//create p2
|
||||
// create p2
|
||||
std::unique_ptr<Test> p2 = std::make_unique<Test>();
|
||||
TEST_ASSERT_EQUAL(Test::kMagicNumber, p2->_value);
|
||||
TEST_ASSERT_EQUAL(2, Test::_instanceCount);
|
||||
p2->_value = number2;
|
||||
TEST_ASSERT_EQUAL(number2, p2->_value);
|
||||
|
||||
//swap
|
||||
// swap
|
||||
p1.swap(p2);
|
||||
|
||||
TEST_ASSERT_EQUAL(number1, p2->_value);
|
||||
@ -223,14 +226,13 @@ void test_unique_ptr_swap() {
|
||||
TEST_ASSERT_EQUAL(0, Test::_instanceCount);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************
|
||||
* RAW PTR EXERCISE *
|
||||
*******************/
|
||||
* RAW PTR EXERCISE *
|
||||
*******************/
|
||||
|
||||
/**
|
||||
* Test that a shared pointer correctly manages the lifetime of the underlying raw pointer
|
||||
* Test that a shared pointer correctly manages the lifetime of the underlying
|
||||
* raw pointer
|
||||
*/
|
||||
void test_single_raw_ptr_lifetime() {
|
||||
// Sanity-check value of counter
|
||||
@ -242,7 +244,7 @@ void test_single_raw_ptr_lifetime() {
|
||||
TEST_ASSERT_EQUAL(1, Test::_instanceCount);
|
||||
TEST_ASSERT_EQUAL(Test::kMagicNumber, t1._value);
|
||||
|
||||
Test * p1 = &t1;
|
||||
Test* p1 = &t1;
|
||||
TEST_ASSERT_EQUAL(1, Test::_instanceCount);
|
||||
TEST_ASSERT_EQUAL(Test::kMagicNumber, p1->_value);
|
||||
|
||||
@ -260,9 +262,9 @@ void test_single_raw_ptr_lifetime() {
|
||||
TEST_ASSERT_EQUAL(0, Test::_instanceCount);
|
||||
}
|
||||
|
||||
static utest::v1::status_t greentea_setup(const size_t number_of_cases) {
|
||||
// Here, we specify the timeout (60s) and the host test (a built-in host test or the
|
||||
// name of our Python file)
|
||||
static status_t greentea_setup(const size_t number_of_cases) {
|
||||
// Here, we specify the timeout (60s) and the host test (a built-in host test
|
||||
// or the name of our Python file)
|
||||
GREENTEA_SETUP(60, "default_auto");
|
||||
return greentea_test_setup_handler(number_of_cases);
|
||||
}
|
||||
@ -285,4 +287,7 @@ static Case cases[] = {
|
||||
|
||||
static Specification specification(greentea_setup, cases);
|
||||
|
||||
int main() { return !Harness::run(specification); }
|
||||
}; // namespace v1
|
||||
}; // namespace utest
|
||||
|
||||
int main() { return !utest::v1::Harness::run(utest::v1::specification); }
|
||||
|
@ -110,7 +110,7 @@ void Speedometer::computeSpeed() {
|
||||
// TODO : done
|
||||
//Distance run with one pedal turn = tray size / rear gear size * circumference of the wheel
|
||||
constexpr float ms_in_hour = static_cast<float>(3600 * 1000);
|
||||
float pedal_rotation_per_hour = ms_in_hour / static_cast<float>(_pedalRotationTime.count());
|
||||
float pedal_rotation_per_hour = ms_in_hour / std::chrono::duration_cast<std::chrono::milliseconds>(_pedalRotationTime).count();
|
||||
float gear_ratio = static_cast<float>(kTraySize) / static_cast<float>(this->_gearSize);
|
||||
float wheel_dist_km = static_cast<float>(this->kWheelCircumference) / 1000.0;
|
||||
this->_currentSpeed = gear_ratio * wheel_dist_km * pedal_rotation_per_hour;
|
||||
|
@ -57,16 +57,12 @@ static constexpr std::chrono::milliseconds kCPUTaskPeriod = 1600ms;
|
||||
static constexpr std::chrono::milliseconds kCPUTaskDelay = 0ms;
|
||||
static constexpr std::chrono::milliseconds kCPUTaskComputationTime = 0ms;
|
||||
|
||||
|
||||
BikeSystem::BikeSystem() :
|
||||
_gearDevice(_timer),
|
||||
BikeSystem::BikeSystem()
|
||||
: _gearDevice(_timer),
|
||||
_pedalDevice(_timer),
|
||||
_resetDevice(_timer),
|
||||
_speedometer(_timer),
|
||||
_cpuLogger(_timer)
|
||||
{
|
||||
|
||||
}
|
||||
_cpuLogger(_timer) {}
|
||||
|
||||
void BikeSystem::start() {
|
||||
tr_info("Starting Super-Loop without event handling");
|
||||
@ -88,8 +84,6 @@ void BikeSystem::start() {
|
||||
speedDistanceTask(); // 200ms : 1300ms -> 1500ms
|
||||
resetTask(); // 100ms : 1500ms -> 1600ms
|
||||
|
||||
|
||||
|
||||
// register the time at the end of the cyclic schedule period and print the
|
||||
// elapsed time for the period
|
||||
std::chrono::microseconds endTime = _timer.elapsed_time();
|
||||
@ -97,23 +91,19 @@ void BikeSystem::start() {
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime);
|
||||
tr_debug("Repeating cycle time is %" PRIu64 " milliseconds", cycle.count());
|
||||
|
||||
// TODO: implement loop exit when applicable
|
||||
// Done
|
||||
bool fStop = false;
|
||||
core_util_atomic_load(&fStop);
|
||||
if (fStop) {
|
||||
break;
|
||||
}
|
||||
|
||||
#if !defined(MBED_TEST_MODE)
|
||||
#if !defined(MBED_TEST_MODE)
|
||||
_cpuLogger.printStats();
|
||||
#endif
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void BikeSystem::startWithEventQueue() {
|
||||
|
||||
tr_info("Starting Super-Loop with event handling");
|
||||
|
||||
init();
|
||||
@ -125,7 +115,8 @@ void BikeSystem::startWithEventQueue() {
|
||||
gearEvent.period(kGearTaskPeriod);
|
||||
gearEvent.post();
|
||||
|
||||
Event<void()> speedDistanceEvent(&eventQueue, callback(this, &BikeSystem::speedDistanceTask));
|
||||
Event<void()> speedDistanceEvent(&eventQueue,
|
||||
callback(this, &BikeSystem::speedDistanceTask));
|
||||
speedDistanceEvent.delay(kSpeedDistanceTaskDelay);
|
||||
speedDistanceEvent.period(kSpeedDistanceTaskPeriod);
|
||||
speedDistanceEvent.post();
|
||||
@ -140,7 +131,8 @@ void BikeSystem::startWithEventQueue() {
|
||||
resetEvent.period(kResetTaskPeriod);
|
||||
resetEvent.post();
|
||||
|
||||
Event<void()> temperatureEvent(&eventQueue, callback(this, &BikeSystem::temperatureTask));
|
||||
Event<void()> temperatureEvent(&eventQueue,
|
||||
callback(this, &BikeSystem::temperatureTask));
|
||||
temperatureEvent.delay(kTemperatureTaskDelay);
|
||||
temperatureEvent.period(kTemperatureTaskPeriod);
|
||||
temperatureEvent.post();
|
||||
@ -150,12 +142,12 @@ void BikeSystem::startWithEventQueue() {
|
||||
display2Event.period(kDisplayTask2Period);
|
||||
display2Event.post();
|
||||
|
||||
#if !defined(MBED_TEST_MODE)
|
||||
#if !defined(MBED_TEST_MODE)
|
||||
Event<void()> cpuEvent(&eventQueue, callback(this, &BikeSystem::cpuTask));
|
||||
cpuEvent.delay(kCPUTaskDelay);
|
||||
cpuEvent.period(kCPUTaskPeriod);
|
||||
cpuEvent.post();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
eventQueue.dispatch_forever();
|
||||
}
|
||||
@ -195,8 +187,7 @@ void BikeSystem::gearTask() {
|
||||
_currentGearSize = _gearDevice.getCurrentGearSize();
|
||||
|
||||
_taskLogger.logPeriodAndExecutionTime(
|
||||
_timer, advembsof::TaskLogger::kGearTaskIndex, taskStartTime
|
||||
);
|
||||
_timer, advembsof::TaskLogger::kGearTaskIndex, taskStartTime);
|
||||
}
|
||||
|
||||
void BikeSystem::speedDistanceTask() {
|
||||
@ -211,8 +202,7 @@ void BikeSystem::speedDistanceTask() {
|
||||
_traveledDistance = _speedometer.getDistance();
|
||||
|
||||
_taskLogger.logPeriodAndExecutionTime(
|
||||
_timer, advembsof::TaskLogger::kSpeedTaskIndex, taskStartTime
|
||||
);
|
||||
_timer, advembsof::TaskLogger::kSpeedTaskIndex, taskStartTime);
|
||||
}
|
||||
|
||||
void BikeSystem::temperatureTask() {
|
||||
@ -225,18 +215,16 @@ void BikeSystem::temperatureTask() {
|
||||
|
||||
tr_warn("Tick2 %" PRIu64, _timer.elapsed_time().count());
|
||||
|
||||
ThisThread::sleep_for(
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
kTemperatureTaskComputationTime - (_timer.elapsed_time() - taskStartTime)
|
||||
)
|
||||
);
|
||||
ThisThread::sleep_for(std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
kTemperatureTaskComputationTime - (_timer.elapsed_time() - taskStartTime)));
|
||||
|
||||
// simulate task computation by waiting for the required task computation time
|
||||
|
||||
// std::chrono::microseconds elapsedTime = std::chrono::microseconds::zero();
|
||||
// while (elapsedTime < kTemperatureTaskComputationTime) {
|
||||
// elapsedTime = _timer.elapsed_time() - taskStartTime;
|
||||
// }
|
||||
// std::chrono::microseconds elapsedTime =
|
||||
// std::chrono::microseconds::zero(); while (elapsedTime <
|
||||
// kTemperatureTaskComputationTime) {
|
||||
// elapsedTime = _timer.elapsed_time() - taskStartTime;
|
||||
// }
|
||||
|
||||
_taskLogger.logPeriodAndExecutionTime(
|
||||
_timer, advembsof::TaskLogger::kTemperatureTaskIndex, taskStartTime);
|
||||
@ -263,18 +251,16 @@ void BikeSystem::displayTask1() {
|
||||
_displayDevice.displaySpeed(_currentSpeed);
|
||||
_displayDevice.displayDistance(_traveledDistance);
|
||||
|
||||
ThisThread::sleep_for(
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
kDisplayTask1ComputationTime - (_timer.elapsed_time() - taskStartTime)
|
||||
)
|
||||
);
|
||||
ThisThread::sleep_for(std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
kDisplayTask1ComputationTime - (_timer.elapsed_time() - taskStartTime)));
|
||||
|
||||
// simulate task computation by waiting for the required task computation time
|
||||
|
||||
// std::chrono::microseconds elapsedTime = std::chrono::microseconds::zero();
|
||||
// while (elapsedTime < kDisplayTask1ComputationTime) {
|
||||
// elapsedTime = _timer.elapsed_time() - taskStartTime;
|
||||
// }
|
||||
// std::chrono::microseconds elapsedTime =
|
||||
// std::chrono::microseconds::zero(); while (elapsedTime <
|
||||
// kDisplayTask1ComputationTime) {
|
||||
// elapsedTime = _timer.elapsed_time() - taskStartTime;
|
||||
// }
|
||||
|
||||
_taskLogger.logPeriodAndExecutionTime(
|
||||
_timer, advembsof::TaskLogger::kDisplayTask1Index, taskStartTime);
|
||||
@ -285,24 +271,20 @@ void BikeSystem::displayTask2() {
|
||||
|
||||
_displayDevice.displayTemperature(_currentTemperature);
|
||||
|
||||
ThisThread::sleep_for(
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
kDisplayTask2ComputationTime - (_timer.elapsed_time() - taskStartTime)
|
||||
)
|
||||
);
|
||||
ThisThread::sleep_for(std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
kDisplayTask2ComputationTime - (_timer.elapsed_time() - taskStartTime)));
|
||||
|
||||
// simulate task computation by waiting for the required task computation time
|
||||
|
||||
// std::chrono::microseconds elapsedTime = std::chrono::microseconds::zero();
|
||||
// while (elapsedTime < kDisplayTask2ComputationTime) {
|
||||
// elapsedTime = _timer.elapsed_time() - taskStartTime;
|
||||
// }
|
||||
// std::chrono::microseconds elapsedTime =
|
||||
// std::chrono::microseconds::zero(); while (elapsedTime <
|
||||
// kDisplayTask2ComputationTime) {
|
||||
// elapsedTime = _timer.elapsed_time() - taskStartTime;
|
||||
// }
|
||||
_taskLogger.logPeriodAndExecutionTime(
|
||||
_timer, advembsof::TaskLogger::kDisplayTask2Index, taskStartTime);
|
||||
}
|
||||
|
||||
void BikeSystem::cpuTask() {
|
||||
_cpuLogger.printStats();
|
||||
}
|
||||
void BikeSystem::cpuTask() { _cpuLogger.printStats(); }
|
||||
|
||||
} // namespace static_scheduling
|
@ -25,9 +25,9 @@
|
||||
#pragma once
|
||||
|
||||
// from advembsof
|
||||
#include "cpu_logger.hpp"
|
||||
#include "display_device.hpp"
|
||||
#include "task_logger.hpp"
|
||||
#include "cpu_logger.hpp"
|
||||
|
||||
// from common
|
||||
#include "sensor_device.hpp"
|
||||
|
@ -1,12 +1,25 @@
|
||||
// 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 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-09
|
||||
* @version 0.1.0
|
||||
****************************************************************************/
|
||||
* @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-09
|
||||
* @version 0.1.0
|
||||
****************************************************************************/
|
||||
|
||||
#include "pedal_device.hpp"
|
||||
|
||||
@ -22,20 +35,19 @@
|
||||
|
||||
namespace static_scheduling {
|
||||
|
||||
static constexpr std::chrono::microseconds kTaskRunTime = 200000us;
|
||||
static constexpr std::chrono::microseconds kTaskRunTime = 200000us;
|
||||
|
||||
PedalDevice::PedalDevice(Timer& timer) : _timer(timer) {}
|
||||
PedalDevice::PedalDevice(Timer& timer) : _timer(timer) {}
|
||||
|
||||
|
||||
std::chrono::milliseconds PedalDevice::getCurrentRotationTime() {
|
||||
// TODO
|
||||
std::chrono::milliseconds PedalDevice::getCurrentRotationTime() {
|
||||
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 hasChanged = false;
|
||||
while (elapsedTime < kTaskRunTime) {
|
||||
if (!hasChanged) {
|
||||
disco::Joystick::State joystickState = disco::Joystick::getInstance().getState();
|
||||
disco::Joystick::State joystickState =
|
||||
disco::Joystick::getInstance().getState();
|
||||
|
||||
switch (joystickState) {
|
||||
case disco::Joystick::State::LeftPressed:
|
||||
@ -59,14 +71,14 @@ namespace static_scheduling {
|
||||
elapsedTime = _timer.elapsed_time() - initialTime;
|
||||
}
|
||||
return _pedalRotationTime;
|
||||
}
|
||||
|
||||
void PedalDevice::increaseRotationSpeed() {
|
||||
_pedalRotationTime -= bike_computer::kDeltaPedalRotationTime;
|
||||
}
|
||||
|
||||
void PedalDevice::decreaseRotationSpeed() {
|
||||
_pedalRotationTime += bike_computer::kDeltaPedalRotationTime;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PedalDevice::increaseRotationSpeed() {
|
||||
_pedalRotationTime -= bike_computer::kDeltaPedalRotationTime;
|
||||
}
|
||||
|
||||
void PedalDevice::decreaseRotationSpeed() {
|
||||
_pedalRotationTime += bike_computer::kDeltaPedalRotationTime;
|
||||
}
|
||||
|
||||
} // namespace static_scheduling
|
||||
|
@ -1,12 +1,26 @@
|
||||
// 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.cpp
|
||||
* @author Rémi Heredero <remi@heredero.ch>
|
||||
* @author Yann Sierro <yannsierro.pro@gmail.com>
|
||||
*
|
||||
* @brief Reset Device implementation (static scheduling)
|
||||
* @date 2024-11-12
|
||||
* @version 0.1.0
|
||||
****************************************************************************/
|
||||
* @file reset_device.cpp
|
||||
* @author Rémi Heredero <remi@heredero.ch>
|
||||
* @author Yann Sierro <yannsierro.pro@gmail.com>
|
||||
*
|
||||
* @brief Reset Device implementation (static scheduling)
|
||||
* @date 2024-11-12
|
||||
* @version 0.1.0
|
||||
****************************************************************************/
|
||||
|
||||
#include "reset_device.hpp"
|
||||
|
||||
@ -21,43 +35,35 @@
|
||||
static constexpr uint8_t kPolarityPressed = 1;
|
||||
#endif
|
||||
|
||||
|
||||
#if MBED_CONF_MBED_TRACE_ENABLE
|
||||
#define TRACE_GROUP "ResetDevice"
|
||||
#endif // MBED_CONF_MBED_TRACE_ENABLE
|
||||
|
||||
namespace static_scheduling {
|
||||
|
||||
static constexpr std::chrono::microseconds kTaskRunTime = 100000us;
|
||||
static constexpr std::chrono::microseconds kTaskRunTime = 100000us;
|
||||
|
||||
ResetDevice::ResetDevice(Timer& timer) : _timer(timer), _resetButton(PUSH_BUTTON) {
|
||||
ResetDevice::ResetDevice(Timer& timer) : _timer(timer), _resetButton(PUSH_BUTTON) {
|
||||
_resetButton.rise(callback(this, &ResetDevice::onRise));
|
||||
}
|
||||
}
|
||||
|
||||
bool ResetDevice::checkReset() {
|
||||
bool 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(!isPressed) {
|
||||
if (!isPressed) {
|
||||
isPressed = _resetButton.read() == kPolarityPressed;
|
||||
}
|
||||
elapsedTime = _timer.elapsed_time() - initialTime;
|
||||
}
|
||||
|
||||
return isPressed;
|
||||
|
||||
}
|
||||
|
||||
std::chrono::microseconds ResetDevice::getPressTime() {
|
||||
return _pressTime;
|
||||
}
|
||||
|
||||
void ResetDevice::onRise() {
|
||||
_pressTime = _timer.elapsed_time();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
std::chrono::microseconds ResetDevice::getPressTime() { return _pressTime; }
|
||||
|
||||
void ResetDevice::onRise() { _pressTime = _timer.elapsed_time(); }
|
||||
|
||||
} // namespace static_scheduling
|
||||
|
@ -63,19 +63,14 @@ static constexpr std::chrono::milliseconds kCPUTaskPeriod = 1600ms;
|
||||
static constexpr std::chrono::milliseconds kCPUTaskDelay = 1200ms;
|
||||
static constexpr std::chrono::milliseconds kCPUTaskComputationTime = 100ms;
|
||||
|
||||
|
||||
BikeSystem::BikeSystem() :
|
||||
_gearDevice(),
|
||||
BikeSystem::BikeSystem()
|
||||
: _gearDevice(),
|
||||
_pedalDevice(),
|
||||
_resetDevice(callback(this, &BikeSystem::onReset)),
|
||||
_speedometer(_timer),
|
||||
_cpuLogger(_timer)
|
||||
{
|
||||
|
||||
}
|
||||
_cpuLogger(_timer) {}
|
||||
|
||||
void BikeSystem::start() {
|
||||
|
||||
tr_info("Starting Super-Loop with event handling");
|
||||
|
||||
init();
|
||||
@ -87,7 +82,8 @@ void BikeSystem::start() {
|
||||
gearEvent.period(kGearTaskPeriod);
|
||||
gearEvent.post();
|
||||
|
||||
Event<void()> speedDistanceEvent(&eventQueue, callback(this, &BikeSystem::speedDistanceTask));
|
||||
Event<void()> speedDistanceEvent(&eventQueue,
|
||||
callback(this, &BikeSystem::speedDistanceTask));
|
||||
speedDistanceEvent.delay(kSpeedDistanceTaskDelay);
|
||||
speedDistanceEvent.period(kSpeedDistanceTaskPeriod);
|
||||
speedDistanceEvent.post();
|
||||
@ -102,7 +98,8 @@ void BikeSystem::start() {
|
||||
resetEvent.period(kResetTaskPeriod);
|
||||
resetEvent.post();
|
||||
|
||||
Event<void()> temperatureEvent(&eventQueue, callback(this, &BikeSystem::temperatureTask));
|
||||
Event<void()> temperatureEvent(&eventQueue,
|
||||
callback(this, &BikeSystem::temperatureTask));
|
||||
temperatureEvent.delay(kTemperatureTaskDelay);
|
||||
temperatureEvent.period(kTemperatureTaskPeriod);
|
||||
temperatureEvent.post();
|
||||
@ -112,12 +109,12 @@ void BikeSystem::start() {
|
||||
display2Event.period(kDisplayTask2Period);
|
||||
display2Event.post();
|
||||
|
||||
#if !defined(MBED_TEST_MODE)
|
||||
#if !defined(MBED_TEST_MODE)
|
||||
Event<void()> cpuEvent(&eventQueue, callback(this, &BikeSystem::cpuTask));
|
||||
cpuEvent.delay(kCPUTaskDelay);
|
||||
cpuEvent.period(kCPUTaskPeriod);
|
||||
cpuEvent.post();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
eventQueue.dispatch_forever();
|
||||
}
|
||||
@ -162,8 +159,7 @@ void BikeSystem::gearTask() {
|
||||
_currentGearSize = _gearDevice.getCurrentGearSize();
|
||||
|
||||
_taskLogger.logPeriodAndExecutionTime(
|
||||
_timer, advembsof::TaskLogger::kGearTaskIndex, taskStartTime
|
||||
);
|
||||
_timer, advembsof::TaskLogger::kGearTaskIndex, taskStartTime);
|
||||
}
|
||||
|
||||
void BikeSystem::speedDistanceTask() {
|
||||
@ -177,25 +173,21 @@ void BikeSystem::speedDistanceTask() {
|
||||
_traveledDistance = _speedometer.getDistance();
|
||||
|
||||
_taskLogger.logPeriodAndExecutionTime(
|
||||
_timer, advembsof::TaskLogger::kSpeedTaskIndex, taskStartTime
|
||||
);
|
||||
_timer, advembsof::TaskLogger::kSpeedTaskIndex, taskStartTime);
|
||||
}
|
||||
|
||||
void BikeSystem::temperatureTask() {
|
||||
auto taskStartTime = _timer.elapsed_time();
|
||||
|
||||
//tr_warn("Tick1 %" PRIu64, _timer.elapsed_time().count());
|
||||
// tr_warn("Tick1 %" PRIu64, _timer.elapsed_time().count());
|
||||
|
||||
// no need to protect access to data members (single threaded)
|
||||
_currentTemperature = _sensorDevice.readTemperature();
|
||||
|
||||
//tr_warn("Tick2 %" PRIu64, _timer.elapsed_time().count());
|
||||
// tr_warn("Tick2 %" PRIu64, _timer.elapsed_time().count());
|
||||
|
||||
ThisThread::sleep_for(
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
kTemperatureTaskComputationTime - (_timer.elapsed_time() - taskStartTime)
|
||||
)
|
||||
);
|
||||
ThisThread::sleep_for(std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
kTemperatureTaskComputationTime - (_timer.elapsed_time() - taskStartTime)));
|
||||
|
||||
_taskLogger.logPeriodAndExecutionTime(
|
||||
_timer, advembsof::TaskLogger::kTemperatureTaskIndex, taskStartTime);
|
||||
@ -223,11 +215,8 @@ void BikeSystem::displayTask1() {
|
||||
_displayDevice.displaySpeed(_currentSpeed);
|
||||
_displayDevice.displayDistance(_traveledDistance);
|
||||
|
||||
ThisThread::sleep_for(
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
kDisplayTask1ComputationTime - (_timer.elapsed_time() - taskStartTime)
|
||||
)
|
||||
);
|
||||
ThisThread::sleep_for(std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
kDisplayTask1ComputationTime - (_timer.elapsed_time() - taskStartTime)));
|
||||
|
||||
_taskLogger.logPeriodAndExecutionTime(
|
||||
_timer, advembsof::TaskLogger::kDisplayTask1Index, taskStartTime);
|
||||
@ -238,18 +227,13 @@ void BikeSystem::displayTask2() {
|
||||
|
||||
_displayDevice.displayTemperature(_currentTemperature);
|
||||
|
||||
ThisThread::sleep_for(
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
kDisplayTask2ComputationTime - (_timer.elapsed_time() - taskStartTime)
|
||||
)
|
||||
);
|
||||
ThisThread::sleep_for(std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
kDisplayTask2ComputationTime - (_timer.elapsed_time() - taskStartTime)));
|
||||
|
||||
_taskLogger.logPeriodAndExecutionTime(
|
||||
_timer, advembsof::TaskLogger::kDisplayTask2Index, taskStartTime);
|
||||
}
|
||||
|
||||
void BikeSystem::cpuTask() {
|
||||
_cpuLogger.printStats();
|
||||
}
|
||||
void BikeSystem::cpuTask() { _cpuLogger.printStats(); }
|
||||
|
||||
} // namespace static_scheduling
|
||||
} // namespace static_scheduling_with_event
|
||||
|
@ -25,9 +25,9 @@
|
||||
#pragma once
|
||||
|
||||
// from advembsof
|
||||
#include "cpu_logger.hpp"
|
||||
#include "display_device.hpp"
|
||||
#include "task_logger.hpp"
|
||||
#include "cpu_logger.hpp"
|
||||
|
||||
// from common
|
||||
#include "sensor_device.hpp"
|
||||
@ -108,4 +108,4 @@ class BikeSystem {
|
||||
advembsof::CPULogger _cpuLogger;
|
||||
};
|
||||
|
||||
} // namespace static_scheduling
|
||||
} // namespace static_scheduling_with_event
|
||||
|
@ -38,17 +38,12 @@
|
||||
|
||||
namespace static_scheduling_with_event {
|
||||
|
||||
|
||||
GearDevice::GearDevice() {
|
||||
disco::Joystick::getInstance().setUpCallback(
|
||||
callback(this, &GearDevice::onUp));
|
||||
disco::Joystick::getInstance().setDownCallback(
|
||||
callback(this, &GearDevice::onDown));
|
||||
disco::Joystick::getInstance().setUpCallback(callback(this, &GearDevice::onUp));
|
||||
disco::Joystick::getInstance().setDownCallback(callback(this, &GearDevice::onDown));
|
||||
}
|
||||
|
||||
uint8_t GearDevice::getCurrentGear() {
|
||||
return core_util_atomic_load_u8(&_currentGear);
|
||||
}
|
||||
uint8_t GearDevice::getCurrentGear() { return core_util_atomic_load_u8(&_currentGear); }
|
||||
|
||||
uint8_t GearDevice::getCurrentGearSize() const {
|
||||
return bike_computer::kMaxGearSize - core_util_atomic_load_u8(&_currentGear);
|
||||
@ -66,4 +61,4 @@ void GearDevice::onDown() {
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace static_scheduling
|
||||
} // namespace static_scheduling_with_event
|
||||
|
@ -33,7 +33,7 @@ namespace static_scheduling_with_event {
|
||||
|
||||
class GearDevice {
|
||||
public:
|
||||
explicit GearDevice(); // NOLINT(runtime/references)
|
||||
GearDevice(); // NOLINT(runtime/references)
|
||||
|
||||
// make the class non copyable
|
||||
GearDevice(GearDevice&) = delete;
|
||||
@ -51,4 +51,4 @@ class GearDevice {
|
||||
volatile uint8_t _currentGear = bike_computer::kMinGear;
|
||||
};
|
||||
|
||||
} // namespace static_scheduling
|
||||
} // namespace static_scheduling_with_event
|
||||
|
@ -1,12 +1,26 @@
|
||||
// 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 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-17
|
||||
* @version 1.1.0
|
||||
****************************************************************************/
|
||||
* @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-17
|
||||
* @version 1.1.0
|
||||
****************************************************************************/
|
||||
|
||||
#include "pedal_device.hpp"
|
||||
|
||||
@ -22,41 +36,34 @@
|
||||
|
||||
namespace static_scheduling_with_event {
|
||||
|
||||
PedalDevice::PedalDevice() {
|
||||
disco::Joystick::getInstance().setLeftCallback(
|
||||
callback(this, &PedalDevice::onLeft)
|
||||
);
|
||||
PedalDevice::PedalDevice() {
|
||||
disco::Joystick::getInstance().setLeftCallback(callback(this, &PedalDevice::onLeft));
|
||||
disco::Joystick::getInstance().setRightCallback(
|
||||
callback(this, &PedalDevice::onRight)
|
||||
);
|
||||
}
|
||||
callback(this, &PedalDevice::onRight));
|
||||
}
|
||||
|
||||
|
||||
std::chrono::milliseconds PedalDevice::getCurrentRotationTime() {
|
||||
std::chrono::milliseconds PedalDevice::getCurrentRotationTime() {
|
||||
uint32_t currentStep = core_util_atomic_load_u32(&_currentStep);
|
||||
return bike_computer::kMinPedalRotationTime + currentStep * bike_computer::kDeltaPedalRotationTime;
|
||||
}
|
||||
return bike_computer::kMinPedalRotationTime +
|
||||
currentStep * bike_computer::kDeltaPedalRotationTime;
|
||||
}
|
||||
|
||||
void PedalDevice::increaseRotationSpeed() {
|
||||
void PedalDevice::increaseRotationSpeed() {
|
||||
uint32_t currentStep = core_util_atomic_load_u32(&_currentStep);
|
||||
if (currentStep > 0) {
|
||||
core_util_atomic_decr_u32(&_currentStep, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PedalDevice::decreaseRotationSpeed() {
|
||||
void PedalDevice::decreaseRotationSpeed() {
|
||||
uint32_t currentStep = core_util_atomic_load_u32(&_currentStep);
|
||||
if (currentStep < bike_computer::kNbrOfSteps) {
|
||||
core_util_atomic_incr_u32(&_currentStep, 1);
|
||||
}
|
||||
}
|
||||
|
||||
void PedalDevice::onLeft() {
|
||||
decreaseRotationSpeed();
|
||||
}
|
||||
|
||||
void PedalDevice::onRight() {
|
||||
increaseRotationSpeed();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PedalDevice::onLeft() { decreaseRotationSpeed(); }
|
||||
|
||||
void PedalDevice::onRight() { increaseRotationSpeed(); }
|
||||
|
||||
} // namespace static_scheduling_with_event
|
||||
|
@ -51,10 +51,9 @@ class PedalDevice {
|
||||
|
||||
// data members
|
||||
volatile uint32_t _currentStep = static_cast<uint32_t>(
|
||||
(
|
||||
bike_computer::kInitialPedalRotationTime - bike_computer::kMinPedalRotationTime
|
||||
).count() / bike_computer::kDeltaPedalRotationTime.count()
|
||||
);
|
||||
(bike_computer::kInitialPedalRotationTime - bike_computer::kMinPedalRotationTime)
|
||||
.count() /
|
||||
bike_computer::kDeltaPedalRotationTime.count());
|
||||
};
|
||||
|
||||
} // namespace static_scheduling
|
||||
} // namespace static_scheduling_with_event
|
||||
|
@ -1,12 +1,26 @@
|
||||
// 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.cpp
|
||||
* @author Rémi Heredero <remi@heredero.ch>
|
||||
* @author Yann Sierro <yannsierro.pro@gmail.com>
|
||||
*
|
||||
* @brief Reset Device implementation (static scheduling with event)
|
||||
* @date 2024-11-17
|
||||
* @version 1.1.0
|
||||
****************************************************************************/
|
||||
* @file reset_device.cpp
|
||||
* @author Rémi Heredero <remi@heredero.ch>
|
||||
* @author Yann Sierro <yannsierro.pro@gmail.com>
|
||||
*
|
||||
* @brief Reset Device implementation (static scheduling with event)
|
||||
* @date 2024-11-17
|
||||
* @version 1.1.0
|
||||
****************************************************************************/
|
||||
|
||||
#include "reset_device.hpp"
|
||||
|
||||
@ -21,16 +35,14 @@
|
||||
static constexpr uint8_t kPolarityPressed = 1;
|
||||
#endif
|
||||
|
||||
|
||||
#if MBED_CONF_MBED_TRACE_ENABLE
|
||||
#define TRACE_GROUP "ResetDevice"
|
||||
#endif // MBED_CONF_MBED_TRACE_ENABLE
|
||||
|
||||
namespace static_scheduling_with_event {
|
||||
|
||||
ResetDevice::ResetDevice(Callback<void()> cb) : _resetButton(PUSH_BUTTON) {
|
||||
ResetDevice::ResetDevice(Callback<void()> cb) : _resetButton(PUSH_BUTTON) {
|
||||
_resetButton.fall(cb);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
} // namespace static_scheduling_with_event
|
||||
|
@ -39,10 +39,9 @@ class ResetDevice {
|
||||
ResetDevice& operator=(ResetDevice&) = delete;
|
||||
|
||||
private:
|
||||
|
||||
// data members
|
||||
// instance representing the reset button
|
||||
InterruptIn _resetButton;
|
||||
};
|
||||
|
||||
} // namespace static_scheduling
|
||||
} // namespace static_scheduling_with_event
|
||||
|
Loading…
x
Reference in New Issue
Block a user