ADD cpplint args in action file

This commit is contained in:
fastium 2024-12-18 10:32:03 +01:00 committed by Fastium
parent f8077db299
commit c0335b38a4
23 changed files with 384 additions and 387 deletions

View File

@ -15,6 +15,8 @@ repos:
rev: "1.6.1" rev: "1.6.1"
hooks: hooks:
- id: cpplint - id: cpplint
name: cpplint
entry: cpplint --linelength=90 --filter=-build/include_subdir,-whitespace/indent,-build/namespaces,-build/c++11
- repo: local - repo: local
hooks: hooks:
- id: cppcheck - id: cppcheck

View File

@ -24,16 +24,15 @@
#include <chrono> #include <chrono>
#include "static_scheduling/bike_system.hpp"
#include "static_scheduling_with_event/bike_system.hpp"
#include "greentea-client/test_env.h" #include "greentea-client/test_env.h"
#include "mbed.h" #include "mbed.h"
#include "static_scheduling/bike_system.hpp"
#include "static_scheduling_with_event/bike_system.hpp"
#include "task_logger.hpp" #include "task_logger.hpp"
#include "unity/unity.h" #include "unity/unity.h"
#include "utest/utest.h" #include "utest/utest.h"
using namespace utest::v1; namespace utest::v1 {
// test_bike_system handler function // test_bike_system handler function
static void test_bike_system() { static void test_bike_system() {
@ -80,7 +79,8 @@ static void test_bike_system_event_queue() {
// run the bike system in a separate thread // run the bike system in a separate thread
Thread 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 // let the bike system run for 20 secs
ThisThread::sleep_for(20s); ThisThread::sleep_for(20s);
@ -157,3 +157,4 @@ static Case cases[] = {
static Specification specification(greentea_setup, cases); static Specification specification(greentea_setup, cases);
int main() { return !Harness::run(specification); } int main() { return !Harness::run(specification); }
}; // namespace utest::v1

View File

@ -29,7 +29,7 @@
#include "unity/unity.h" #include "unity/unity.h"
#include "utest/utest.h" #include "utest/utest.h"
using namespace utest::v1; namespace utest::v1 {
// test_hdc1000 test handler function // test_hdc1000 test handler function
static control_t test_sensor_device(const size_t call_count) { static control_t test_sensor_device(const size_t call_count) {
@ -67,3 +67,4 @@ static Case cases[] = {Case("test sensor device", test_sensor_device)};
static Specification specification(greentea_setup, cases); static Specification specification(greentea_setup, cases);
int main() { return !Harness::run(specification); } int main() { return !Harness::run(specification); }
}; // namespace utest::v1

View File

@ -31,8 +31,7 @@
#include "static_scheduling/gear_device.hpp" #include "static_scheduling/gear_device.hpp"
#include "unity/unity.h" #include "unity/unity.h"
#include "utest/utest.h" #include "utest/utest.h"
namespace utest::v1 {
using namespace utest::v1;
// allow for 0.1 km/h difference // allow for 0.1 km/h difference
static constexpr float kAllowedSpeedDelta = 0.1f; static constexpr float kAllowedSpeedDelta = 0.1f;
@ -352,3 +351,4 @@ static Case cases[] = {
static Specification specification(greentea_setup, cases); static Specification specification(greentea_setup, cases);
int main() { return !Harness::run(specification); } int main() { return !Harness::run(specification); }
}; // namespace utest::v1

View File

@ -27,7 +27,7 @@
#include "unity/unity.h" #include "unity/unity.h"
#include "utest/utest.h" #include "utest/utest.h"
using namespace utest::v1; namespace utest::v1 {
// test handler function // test handler function
static control_t always_succeed(const size_t call_count) { static control_t always_succeed(const size_t call_count) {
@ -52,3 +52,4 @@ static Case cases[] = {Case("always succeed test", always_succeed)};
static Specification specification(greentea_setup, cases); static Specification specification(greentea_setup, cases);
int main() { return !Harness::run(specification); } int main() { return !Harness::run(specification); }
}; // namespace utest::v1

View File

@ -24,12 +24,12 @@
* @version 0.2.0 * @version 0.2.0
***************************************************************************/ ***************************************************************************/
#include "greentea-client/test_env.h" #include "greentea-client/test_env.h" // NOLINT
#include "mbed.h" #include "mbed.h" // NOLINT
#include "unity/unity.h" #include "unity/unity.h" // NOLINT
#include "utest/utest.h" #include "utest/utest.h" // NOLINT
using namespace utest::v1; namespace utest::v1 {
struct Test { struct Test {
Test() { Test() {
_instanceCount++; _instanceCount++;
@ -145,7 +145,7 @@ void test_unique_ptr_transfer() {
p2.reset(); p2.reset();
TEST_ASSERT_EQUAL(0, Test::_instanceCount); TEST_ASSERT_EQUAL(0, Test::_instanceCount);
TEST_ASSERT(!p1); TEST_ASSERT(!p1); // cppcheck-suppress accessMoved
TEST_ASSERT(!p2); TEST_ASSERT(!p2);
} }
@ -223,8 +223,6 @@ void test_unique_ptr_swap() {
TEST_ASSERT_EQUAL(0, Test::_instanceCount); TEST_ASSERT_EQUAL(0, Test::_instanceCount);
} }
/******************* /*******************
* RAW PTR EXERCISE * * RAW PTR EXERCISE *
*******************/ *******************/
@ -286,3 +284,4 @@ static Case cases[] = {
static Specification specification(greentea_setup, cases); static Specification specification(greentea_setup, cases);
int main() { return !Harness::run(specification); } int main() { return !Harness::run(specification); }
}; // namespace utest::v1

View File

@ -57,16 +57,12 @@ static constexpr std::chrono::milliseconds kCPUTaskPeriod = 1600ms;
static constexpr std::chrono::milliseconds kCPUTaskDelay = 0ms; static constexpr std::chrono::milliseconds kCPUTaskDelay = 0ms;
static constexpr std::chrono::milliseconds kCPUTaskComputationTime = 0ms; static constexpr std::chrono::milliseconds kCPUTaskComputationTime = 0ms;
BikeSystem::BikeSystem()
BikeSystem::BikeSystem() : : _gearDevice(_timer),
_gearDevice(_timer),
_pedalDevice(_timer), _pedalDevice(_timer),
_resetDevice(_timer), _resetDevice(_timer),
_speedometer(_timer), _speedometer(_timer),
_cpuLogger(_timer) _cpuLogger(_timer) {}
{
}
void BikeSystem::start() { void BikeSystem::start() {
tr_info("Starting Super-Loop without event handling"); tr_info("Starting Super-Loop without event handling");
@ -88,8 +84,6 @@ void BikeSystem::start() {
speedDistanceTask(); // 200ms : 1300ms -> 1500ms speedDistanceTask(); // 200ms : 1300ms -> 1500ms
resetTask(); // 100ms : 1500ms -> 1600ms resetTask(); // 100ms : 1500ms -> 1600ms
// register the time at the end of the cyclic schedule period and print the // register the time at the end of the cyclic schedule period and print the
// elapsed time for the period // elapsed time for the period
std::chrono::microseconds endTime = _timer.elapsed_time(); std::chrono::microseconds endTime = _timer.elapsed_time();
@ -97,8 +91,6 @@ void BikeSystem::start() {
std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime); std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime);
tr_debug("Repeating cycle time is %" PRIu64 " milliseconds", cycle.count()); tr_debug("Repeating cycle time is %" PRIu64 " milliseconds", cycle.count());
// TODO: implement loop exit when applicable
// Done
bool fStop = false; bool fStop = false;
core_util_atomic_load(&fStop); core_util_atomic_load(&fStop);
if (fStop) { if (fStop) {
@ -108,12 +100,10 @@ void BikeSystem::start() {
#if !defined(MBED_TEST_MODE) #if !defined(MBED_TEST_MODE)
_cpuLogger.printStats(); _cpuLogger.printStats();
#endif #endif
} }
} }
void BikeSystem::startWithEventQueue() { void BikeSystem::startWithEventQueue() {
tr_info("Starting Super-Loop with event handling"); tr_info("Starting Super-Loop with event handling");
init(); init();
@ -125,7 +115,8 @@ void BikeSystem::startWithEventQueue() {
gearEvent.period(kGearTaskPeriod); gearEvent.period(kGearTaskPeriod);
gearEvent.post(); gearEvent.post();
Event<void()> speedDistanceEvent(&eventQueue, callback(this, &BikeSystem::speedDistanceTask)); Event<void()> speedDistanceEvent(&eventQueue,
callback(this, &BikeSystem::speedDistanceTask));
speedDistanceEvent.delay(kSpeedDistanceTaskDelay); speedDistanceEvent.delay(kSpeedDistanceTaskDelay);
speedDistanceEvent.period(kSpeedDistanceTaskPeriod); speedDistanceEvent.period(kSpeedDistanceTaskPeriod);
speedDistanceEvent.post(); speedDistanceEvent.post();
@ -140,7 +131,8 @@ void BikeSystem::startWithEventQueue() {
resetEvent.period(kResetTaskPeriod); resetEvent.period(kResetTaskPeriod);
resetEvent.post(); resetEvent.post();
Event<void()> temperatureEvent(&eventQueue, callback(this, &BikeSystem::temperatureTask)); Event<void()> temperatureEvent(&eventQueue,
callback(this, &BikeSystem::temperatureTask));
temperatureEvent.delay(kTemperatureTaskDelay); temperatureEvent.delay(kTemperatureTaskDelay);
temperatureEvent.period(kTemperatureTaskPeriod); temperatureEvent.period(kTemperatureTaskPeriod);
temperatureEvent.post(); temperatureEvent.post();
@ -195,8 +187,7 @@ void BikeSystem::gearTask() {
_currentGearSize = _gearDevice.getCurrentGearSize(); _currentGearSize = _gearDevice.getCurrentGearSize();
_taskLogger.logPeriodAndExecutionTime( _taskLogger.logPeriodAndExecutionTime(
_timer, advembsof::TaskLogger::kGearTaskIndex, taskStartTime _timer, advembsof::TaskLogger::kGearTaskIndex, taskStartTime);
);
} }
void BikeSystem::speedDistanceTask() { void BikeSystem::speedDistanceTask() {
@ -211,8 +202,7 @@ void BikeSystem::speedDistanceTask() {
_traveledDistance = _speedometer.getDistance(); _traveledDistance = _speedometer.getDistance();
_taskLogger.logPeriodAndExecutionTime( _taskLogger.logPeriodAndExecutionTime(
_timer, advembsof::TaskLogger::kSpeedTaskIndex, taskStartTime _timer, advembsof::TaskLogger::kSpeedTaskIndex, taskStartTime);
);
} }
void BikeSystem::temperatureTask() { void BikeSystem::temperatureTask() {
@ -225,11 +215,8 @@ void BikeSystem::temperatureTask() {
tr_warn("Tick2 %" PRIu64, _timer.elapsed_time().count()); tr_warn("Tick2 %" PRIu64, _timer.elapsed_time().count());
ThisThread::sleep_for( ThisThread::sleep_for(std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::duration_cast<std::chrono::milliseconds>( kTemperatureTaskComputationTime - (_timer.elapsed_time() - taskStartTime)));
kTemperatureTaskComputationTime - (_timer.elapsed_time() - taskStartTime)
)
);
// simulate task computation by waiting for the required task computation time // simulate task computation by waiting for the required task computation time
@ -263,11 +250,8 @@ void BikeSystem::displayTask1() {
_displayDevice.displaySpeed(_currentSpeed); _displayDevice.displaySpeed(_currentSpeed);
_displayDevice.displayDistance(_traveledDistance); _displayDevice.displayDistance(_traveledDistance);
ThisThread::sleep_for( ThisThread::sleep_for(std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::duration_cast<std::chrono::milliseconds>( kDisplayTask1ComputationTime - (_timer.elapsed_time() - taskStartTime)));
kDisplayTask1ComputationTime - (_timer.elapsed_time() - taskStartTime)
)
);
// simulate task computation by waiting for the required task computation time // simulate task computation by waiting for the required task computation time
@ -285,11 +269,8 @@ void BikeSystem::displayTask2() {
_displayDevice.displayTemperature(_currentTemperature); _displayDevice.displayTemperature(_currentTemperature);
ThisThread::sleep_for( ThisThread::sleep_for(std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::duration_cast<std::chrono::milliseconds>( kDisplayTask2ComputationTime - (_timer.elapsed_time() - taskStartTime)));
kDisplayTask2ComputationTime - (_timer.elapsed_time() - taskStartTime)
)
);
// simulate task computation by waiting for the required task computation time // simulate task computation by waiting for the required task computation time
@ -301,8 +282,6 @@ void BikeSystem::displayTask2() {
_timer, advembsof::TaskLogger::kDisplayTask2Index, taskStartTime); _timer, advembsof::TaskLogger::kDisplayTask2Index, taskStartTime);
} }
void BikeSystem::cpuTask() { void BikeSystem::cpuTask() { _cpuLogger.printStats(); }
_cpuLogger.printStats();
}
} // namespace static_scheduling } // namespace static_scheduling

View File

@ -25,9 +25,9 @@
#pragma once #pragma once
// from advembsof // from advembsof
#include "cpu_logger.hpp"
#include "display_device.hpp" #include "display_device.hpp"
#include "task_logger.hpp" #include "task_logger.hpp"
#include "cpu_logger.hpp"
// from common // from common
#include "sensor_device.hpp" #include "sensor_device.hpp"

View File

@ -1,3 +1,16 @@
// 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 * @file pedal_device.cpp
* @author Rémi Heredero <remi@heredero.ch> * @author Rémi Heredero <remi@heredero.ch>
@ -26,16 +39,15 @@ namespace static_scheduling {
PedalDevice::PedalDevice(Timer& timer) : _timer(timer) {} PedalDevice::PedalDevice(Timer& timer) : _timer(timer) {}
std::chrono::milliseconds PedalDevice::getCurrentRotationTime() { std::chrono::milliseconds PedalDevice::getCurrentRotationTime() {
// TODO
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 hasChanged = false; bool hasChanged = false;
while (elapsedTime < kTaskRunTime) { while (elapsedTime < kTaskRunTime) {
if (!hasChanged) { if (!hasChanged) {
disco::Joystick::State joystickState = disco::Joystick::getInstance().getState(); disco::Joystick::State joystickState =
disco::Joystick::getInstance().getState();
switch (joystickState) { switch (joystickState) {
case disco::Joystick::State::LeftPressed: case disco::Joystick::State::LeftPressed:
@ -69,4 +81,4 @@ namespace static_scheduling {
_pedalRotationTime += bike_computer::kDeltaPedalRotationTime; _pedalRotationTime += bike_computer::kDeltaPedalRotationTime;
} }
} } // namespace static_scheduling

View File

@ -1,3 +1,17 @@
// 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 * @file reset_device.cpp
* @author Rémi Heredero <remi@heredero.ch> * @author Rémi Heredero <remi@heredero.ch>
@ -21,7 +35,6 @@
static constexpr uint8_t kPolarityPressed = 1; static constexpr uint8_t kPolarityPressed = 1;
#endif #endif
#if MBED_CONF_MBED_TRACE_ENABLE #if MBED_CONF_MBED_TRACE_ENABLE
#define TRACE_GROUP "ResetDevice" #define TRACE_GROUP "ResetDevice"
#endif // MBED_CONF_MBED_TRACE_ENABLE #endif // MBED_CONF_MBED_TRACE_ENABLE
@ -47,17 +60,10 @@ namespace static_scheduling {
} }
return isPressed; return isPressed;
} }
std::chrono::microseconds ResetDevice::getPressTime() { std::chrono::microseconds ResetDevice::getPressTime() { return _pressTime; }
return _pressTime;
}
void ResetDevice::onRise() { void ResetDevice::onRise() { _pressTime = _timer.elapsed_time(); }
_pressTime = _timer.elapsed_time();
}
} // namespace static_scheduling
}

View File

@ -63,19 +63,14 @@ static constexpr std::chrono::milliseconds kCPUTaskPeriod = 1600ms;
static constexpr std::chrono::milliseconds kCPUTaskDelay = 1200ms; static constexpr std::chrono::milliseconds kCPUTaskDelay = 1200ms;
static constexpr std::chrono::milliseconds kCPUTaskComputationTime = 100ms; static constexpr std::chrono::milliseconds kCPUTaskComputationTime = 100ms;
BikeSystem::BikeSystem()
BikeSystem::BikeSystem() : : _gearDevice(),
_gearDevice(),
_pedalDevice(), _pedalDevice(),
_resetDevice(callback(this, &BikeSystem::onReset)), _resetDevice(callback(this, &BikeSystem::onReset)),
_speedometer(_timer), _speedometer(_timer),
_cpuLogger(_timer) _cpuLogger(_timer) {}
{
}
void BikeSystem::start() { void BikeSystem::start() {
tr_info("Starting Super-Loop with event handling"); tr_info("Starting Super-Loop with event handling");
init(); init();
@ -87,7 +82,8 @@ void BikeSystem::start() {
gearEvent.period(kGearTaskPeriod); gearEvent.period(kGearTaskPeriod);
gearEvent.post(); gearEvent.post();
Event<void()> speedDistanceEvent(&eventQueue, callback(this, &BikeSystem::speedDistanceTask)); Event<void()> speedDistanceEvent(&eventQueue,
callback(this, &BikeSystem::speedDistanceTask));
speedDistanceEvent.delay(kSpeedDistanceTaskDelay); speedDistanceEvent.delay(kSpeedDistanceTaskDelay);
speedDistanceEvent.period(kSpeedDistanceTaskPeriod); speedDistanceEvent.period(kSpeedDistanceTaskPeriod);
speedDistanceEvent.post(); speedDistanceEvent.post();
@ -102,7 +98,8 @@ void BikeSystem::start() {
resetEvent.period(kResetTaskPeriod); resetEvent.period(kResetTaskPeriod);
resetEvent.post(); resetEvent.post();
Event<void()> temperatureEvent(&eventQueue, callback(this, &BikeSystem::temperatureTask)); Event<void()> temperatureEvent(&eventQueue,
callback(this, &BikeSystem::temperatureTask));
temperatureEvent.delay(kTemperatureTaskDelay); temperatureEvent.delay(kTemperatureTaskDelay);
temperatureEvent.period(kTemperatureTaskPeriod); temperatureEvent.period(kTemperatureTaskPeriod);
temperatureEvent.post(); temperatureEvent.post();
@ -162,8 +159,7 @@ void BikeSystem::gearTask() {
_currentGearSize = _gearDevice.getCurrentGearSize(); _currentGearSize = _gearDevice.getCurrentGearSize();
_taskLogger.logPeriodAndExecutionTime( _taskLogger.logPeriodAndExecutionTime(
_timer, advembsof::TaskLogger::kGearTaskIndex, taskStartTime _timer, advembsof::TaskLogger::kGearTaskIndex, taskStartTime);
);
} }
void BikeSystem::speedDistanceTask() { void BikeSystem::speedDistanceTask() {
@ -177,8 +173,7 @@ void BikeSystem::speedDistanceTask() {
_traveledDistance = _speedometer.getDistance(); _traveledDistance = _speedometer.getDistance();
_taskLogger.logPeriodAndExecutionTime( _taskLogger.logPeriodAndExecutionTime(
_timer, advembsof::TaskLogger::kSpeedTaskIndex, taskStartTime _timer, advembsof::TaskLogger::kSpeedTaskIndex, taskStartTime);
);
} }
void BikeSystem::temperatureTask() { void BikeSystem::temperatureTask() {
@ -191,11 +186,8 @@ void BikeSystem::temperatureTask() {
// tr_warn("Tick2 %" PRIu64, _timer.elapsed_time().count()); // tr_warn("Tick2 %" PRIu64, _timer.elapsed_time().count());
ThisThread::sleep_for( ThisThread::sleep_for(std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::duration_cast<std::chrono::milliseconds>( kTemperatureTaskComputationTime - (_timer.elapsed_time() - taskStartTime)));
kTemperatureTaskComputationTime - (_timer.elapsed_time() - taskStartTime)
)
);
_taskLogger.logPeriodAndExecutionTime( _taskLogger.logPeriodAndExecutionTime(
_timer, advembsof::TaskLogger::kTemperatureTaskIndex, taskStartTime); _timer, advembsof::TaskLogger::kTemperatureTaskIndex, taskStartTime);
@ -223,11 +215,8 @@ void BikeSystem::displayTask1() {
_displayDevice.displaySpeed(_currentSpeed); _displayDevice.displaySpeed(_currentSpeed);
_displayDevice.displayDistance(_traveledDistance); _displayDevice.displayDistance(_traveledDistance);
ThisThread::sleep_for( ThisThread::sleep_for(std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::duration_cast<std::chrono::milliseconds>( kDisplayTask1ComputationTime - (_timer.elapsed_time() - taskStartTime)));
kDisplayTask1ComputationTime - (_timer.elapsed_time() - taskStartTime)
)
);
_taskLogger.logPeriodAndExecutionTime( _taskLogger.logPeriodAndExecutionTime(
_timer, advembsof::TaskLogger::kDisplayTask1Index, taskStartTime); _timer, advembsof::TaskLogger::kDisplayTask1Index, taskStartTime);
@ -238,18 +227,13 @@ void BikeSystem::displayTask2() {
_displayDevice.displayTemperature(_currentTemperature); _displayDevice.displayTemperature(_currentTemperature);
ThisThread::sleep_for( ThisThread::sleep_for(std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::duration_cast<std::chrono::milliseconds>( kDisplayTask2ComputationTime - (_timer.elapsed_time() - taskStartTime)));
kDisplayTask2ComputationTime - (_timer.elapsed_time() - taskStartTime)
)
);
_taskLogger.logPeriodAndExecutionTime( _taskLogger.logPeriodAndExecutionTime(
_timer, advembsof::TaskLogger::kDisplayTask2Index, taskStartTime); _timer, advembsof::TaskLogger::kDisplayTask2Index, taskStartTime);
} }
void BikeSystem::cpuTask() { void BikeSystem::cpuTask() { _cpuLogger.printStats(); }
_cpuLogger.printStats();
}
} // namespace static_scheduling } // namespace static_scheduling_with_event

View File

@ -25,9 +25,9 @@
#pragma once #pragma once
// from advembsof // from advembsof
#include "cpu_logger.hpp"
#include "display_device.hpp" #include "display_device.hpp"
#include "task_logger.hpp" #include "task_logger.hpp"
#include "cpu_logger.hpp"
// from common // from common
#include "sensor_device.hpp" #include "sensor_device.hpp"
@ -108,4 +108,4 @@ class BikeSystem {
advembsof::CPULogger _cpuLogger; advembsof::CPULogger _cpuLogger;
}; };
} // namespace static_scheduling } // namespace static_scheduling_with_event

View File

@ -38,17 +38,12 @@
namespace static_scheduling_with_event { namespace static_scheduling_with_event {
GearDevice::GearDevice() { GearDevice::GearDevice() {
disco::Joystick::getInstance().setUpCallback( disco::Joystick::getInstance().setUpCallback(callback(this, &GearDevice::onUp));
callback(this, &GearDevice::onUp)); disco::Joystick::getInstance().setDownCallback(callback(this, &GearDevice::onDown));
disco::Joystick::getInstance().setDownCallback(
callback(this, &GearDevice::onDown));
} }
uint8_t GearDevice::getCurrentGear() { uint8_t GearDevice::getCurrentGear() { return core_util_atomic_load_u8(&_currentGear); }
return core_util_atomic_load_u8(&_currentGear);
}
uint8_t GearDevice::getCurrentGearSize() const { uint8_t GearDevice::getCurrentGearSize() const {
return bike_computer::kMaxGearSize - core_util_atomic_load_u8(&_currentGear); 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

View File

@ -33,7 +33,7 @@ namespace static_scheduling_with_event {
class GearDevice { class GearDevice {
public: public:
explicit GearDevice(); // NOLINT(runtime/references) GearDevice(); // NOLINT(runtime/references)
// make the class non copyable // make the class non copyable
GearDevice(GearDevice&) = delete; GearDevice(GearDevice&) = delete;
@ -51,4 +51,4 @@ class GearDevice {
volatile uint8_t _currentGear = bike_computer::kMinGear; volatile uint8_t _currentGear = bike_computer::kMinGear;
}; };
} // namespace static_scheduling } // namespace static_scheduling_with_event

View File

@ -1,3 +1,17 @@
// 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 * @file pedal_device.cpp
* @author Rémi Heredero <remi@heredero.ch> * @author Rémi Heredero <remi@heredero.ch>
@ -23,18 +37,15 @@
namespace static_scheduling_with_event { namespace static_scheduling_with_event {
PedalDevice::PedalDevice() { PedalDevice::PedalDevice() {
disco::Joystick::getInstance().setLeftCallback( disco::Joystick::getInstance().setLeftCallback(callback(this, &PedalDevice::onLeft));
callback(this, &PedalDevice::onLeft)
);
disco::Joystick::getInstance().setRightCallback( 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); 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() {
@ -51,12 +62,8 @@ namespace static_scheduling_with_event {
} }
} }
void PedalDevice::onLeft() { void PedalDevice::onLeft() { decreaseRotationSpeed(); }
decreaseRotationSpeed();
}
void PedalDevice::onRight() { void PedalDevice::onRight() { increaseRotationSpeed(); }
increaseRotationSpeed();
}
} } // namespace static_scheduling_with_event

View File

@ -51,10 +51,9 @@ class PedalDevice {
// data members // data members
volatile uint32_t _currentStep = static_cast<uint32_t>( volatile uint32_t _currentStep = static_cast<uint32_t>(
( (bike_computer::kInitialPedalRotationTime - bike_computer::kMinPedalRotationTime)
bike_computer::kInitialPedalRotationTime - bike_computer::kMinPedalRotationTime .count() /
).count() / bike_computer::kDeltaPedalRotationTime.count() bike_computer::kDeltaPedalRotationTime.count());
);
}; };
} // namespace static_scheduling } // namespace static_scheduling_with_event

View File

@ -1,3 +1,17 @@
// 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 * @file reset_device.cpp
* @author Rémi Heredero <remi@heredero.ch> * @author Rémi Heredero <remi@heredero.ch>
@ -21,7 +35,6 @@
static constexpr uint8_t kPolarityPressed = 1; static constexpr uint8_t kPolarityPressed = 1;
#endif #endif
#if MBED_CONF_MBED_TRACE_ENABLE #if MBED_CONF_MBED_TRACE_ENABLE
#define TRACE_GROUP "ResetDevice" #define TRACE_GROUP "ResetDevice"
#endif // MBED_CONF_MBED_TRACE_ENABLE #endif // MBED_CONF_MBED_TRACE_ENABLE
@ -32,5 +45,4 @@ namespace static_scheduling_with_event {
_resetButton.fall(cb); _resetButton.fall(cb);
} }
} // namespace static_scheduling_with_event
}

View File

@ -39,10 +39,9 @@ class ResetDevice {
ResetDevice& operator=(ResetDevice&) = delete; ResetDevice& operator=(ResetDevice&) = delete;
private: private:
// data members // data members
// instance representing the reset button // instance representing the reset button
InterruptIn _resetButton; InterruptIn _resetButton;
}; };
} // namespace static_scheduling } // namespace static_scheduling_with_event