proj: switching to Linux

This commit is contained in:
2025-07-06 11:00:29 +02:00
parent 9ebbedb04a
commit 8f0dbd4cbd
23 changed files with 255 additions and 170 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
idf_component_register(
INCLUDE_DIRS "."
INCLUDE_DIRS "include"
REQUIRES devHal
)
@@ -0,0 +1,62 @@
#pragma once
#include "stepperDrv.hpp"
#include "stepperMotor.hpp"
#include <cmath>
class WatchMotor {
static constexpr uint8_t Positions = 6;
public:
using AllmostFinishedCb = void (*)(uint8_t newIdx);
WatchMotor(IStepperMotor &stepper, AllmostFinishedCb onDone)
: _stepper(stepper),
_onFinCb(onDone) {
}
void moveTo(uint8_t position, uint8_t profile, int minJumps, float accel, float speed) {
auto sign = position % 6;
int minTurns = minJumps / 6;
float corr = 0.0F;
float currentPos = _stepper.getScaledPos() * 6;
if ((_currentIndex > 4) && (currentPos < 2)) {
corr = 6 - _currentIndex - currentPos;
} else if ((_currentIndex < 2) && (currentPos > 2)) {
corr = _currentIndex + 6 - currentPos;
} else {
corr = _currentIndex - currentPos;
}
int steps = 0;
if (_currentIndex < sign) {
steps = (sign - _currentIndex);
} else if (_currentIndex >= sign) {
steps = (sign + 6 - _currentIndex);
}
steps += minTurns * 6;
if (steps < minJumps) {
steps += 6;
}
float delta = 2.0F * std::numbers::pi / 6 * steps;
ESP_LOGD("MV", "Moving to %d by %.2f + %.2f", sign, delta, corr);
_stepper.moveBy(delta + corr, profile, accel, speed, [&]() {
if (_onFinCb) {
_onFinCb(position);
}
});
_currentIndex = sign;
}
float getScaled() { return _stepper.getScaledPos() * 6; }
uint8_t getIndex() { return _currentIndex; }
private:
IStepperMotor &_stepper;
uint8_t _currentIndex{};
AllmostFinishedCb _onFinCb{};
};
+1
View File
@@ -0,0 +1 @@
// Dummy file
@@ -0,0 +1,4 @@
UnitTestsFrame()
target_link_libraries(${moduleName} PUBLIC
devHal
)
@@ -0,0 +1,105 @@
/**
* @file TestableUTest.cpp
* @author Gustice
* @brief
*
* @copyright Copyright (c) 2024
*/
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest/doctest.h"
#include <iostream>
#include <numbers>
#include "watchFace.hpp"
class StepperMotorMock : public IStepperMotor {
public:
void moveBy(float angle, uint8_t profile = 0) override {
lastAngle = angle;
lastProfile = profile;
}
void moveBy(float angle, uint8_t profile, float accel, float speed, std::function<void()> profileDone = nullptr) override {
lastAngle = angle;
lastProfile = profile;
}
float getScaledPos() const override {
return nextPos;
}
uint16_t getQuanted() const override {
return 0;
}
float lastAngle{};
uint8_t lastProfile{};
float lastAccel{};
float lastSpeed{};
float nextPos{};
};
void onFin(uint8_t idx) {
}
class WatchFaceFixture {
using PositionStore = StepperMotor::Position<50, 5>;
public:
protected:
static constexpr int MicroSteps = 32;
StepperMotorMock motor;
WatchMotor sut{motor, onFin};
private:
};
TEST_CASE_FIXTURE(WatchFaceFixture, "Moving simple steps") {
auto next = 0*std::numbers::pi/3;
motor.nextPos = next;
sut.moveTo(1, 0, 0, 1, 1);
auto delta = 1*std::numbers::pi/3;
CHECK(motor.lastAngle == doctest::Approx(delta).epsilon(0.000625)); // MicroStep tolerance
motor.nextPos = 1.0F/6;
sut.moveTo(2, 0, 0, 1, 1);
CHECK(motor.lastAngle == doctest::Approx(delta).epsilon(0.000625)); // MicroStep tolerance
motor.nextPos = 2.0F/6;
sut.moveTo(3, 0, 0, 1, 1);
CHECK(motor.lastAngle == doctest::Approx(delta).epsilon(0.000625)); // MicroStep tolerance
motor.nextPos = 3.0F/6;
sut.moveTo(4, 0, 0, 1, 1);
CHECK(motor.lastAngle == doctest::Approx(delta).epsilon(0.000625)); // MicroStep tolerance
motor.nextPos = 4.0F/6;
sut.moveTo(5, 0, 0, 1, 1);
CHECK(motor.lastAngle == doctest::Approx(delta).epsilon(0.000625)); // MicroStep tolerance
motor.nextPos = 5.0F/6;
sut.moveTo(6, 0, 0, 1, 1);
CHECK(motor.lastAngle == doctest::Approx(delta).epsilon(0.000625)); // MicroStep tolerance
motor.nextPos = 6.0F/6;
sut.moveTo(1, 0, 0, 1, 1);
CHECK(motor.lastAngle == doctest::Approx(delta).epsilon(0.000625)); // MicroStep tolerance
motor.nextPos = 1.0F/6;
sut.moveTo(2, 0, 0, 1, 1);
CHECK(motor.lastAngle == doctest::Approx(delta).epsilon(0.000625)); // MicroStep tolerance
}
TEST_CASE_FIXTURE(WatchFaceFixture, "Moving multiple turns") {
auto next = 0*std::numbers::pi/3;
motor.nextPos = next;
sut.moveTo(1, 0, 0, 1, 1);
auto delta = 1*std::numbers::pi/3;
CHECK(motor.lastAngle == doctest::Approx(delta).epsilon(0.000625)); // MicroStep tolerance
motor.nextPos = 1.0F/6;
sut.moveTo(1, 0, 0, 1, 1);
CHECK(motor.lastAngle == doctest::Approx(6*delta).epsilon(0.000625)); // MicroStep tolerance
motor.nextPos = 1.0F/6;
sut.moveTo(1, 0, 7, 1, 1);
CHECK(motor.lastAngle == doctest::Approx(12*delta).epsilon(0.000625)); // MicroStep tolerance
}
-50
View File
@@ -1,50 +0,0 @@
#pragma once
#include "StepperDrv8833.hpp"
#include "stepperMotor.hpp"
#include <cmath>
class WatchMotor {
static constexpr uint8_t Positions = 6;
public:
WatchMotor(StepperMotor &stepper, OutputPort &sleep)
: _stepper(stepper),
_motorSleep(sleep) {
_motorSleep.write(false);
}
void moveTo(uint8_t sign, uint8_t profile = 0) {
sign = sign % 6;
float delta = 2.0F * std::numbers::pi;
float corr = 0.0F;
float currentPos = _stepper.getScaledPos() * 6;
if ((_currentIndex > 4) && (currentPos < 2)) {
corr = 6 - _currentIndex - currentPos;
} else if ((_currentIndex < 2) && (currentPos > 2)) {
corr = _currentIndex + 6 - currentPos;
} else {
corr = _currentIndex - currentPos;
}
// stepper.getScaledPos() * 6
if (_currentIndex < sign) {
delta = delta / 6 * (sign - _currentIndex);
} else if (_currentIndex > sign) {
delta = delta / 6 * (sign + 6 - _currentIndex);
}
ESP_LOGD("MV", "Moving to %d by %.2f + %.2f", sign, delta, corr);
_stepper.moveBy(delta + corr, profile);
_currentIndex = sign;
}
float getScaled() { return _stepper.getScaledPos() * 6; }
uint8_t getIndex() { return _currentIndex; }
private:
StepperMotor &_stepper;
OutputPort &_motorSleep;
uint8_t _currentIndex{};
};