From 8f0dbd4cbd1ecfccc6fd97581b5ad5844c00d9f6 Mon Sep 17 00:00:00 2001 From: Gustice Date: Sun, 6 Jul 2025 11:00:29 +0200 Subject: [PATCH] proj: switching to Linux --- .vscode/launch.json | 33 ++++++ components/watchFace/CMakeLists.txt | 2 +- components/watchFace/include/watchFace.hpp | 62 +++++++++++ components/watchFace/src/watchFace.cpp | 1 + components/watchFace/uTest/CMakeLists.txt | 4 + components/watchFace/uTest/WatchFaceUTest.cpp | 105 ++++++++++++++++++ components/watchFace/watchFace.hpp | 50 --------- core | 2 +- doc/LiveShowProject/CatasWatchProject.lsb | Bin 10011 -> 17935 bytes doc/LiveShowProject/CatasWatchProject.lsc | Bin 213 -> 213 bytes doc/LiveShowProject/CatasWatchProject.lsd | Bin 170056 -> 170057 bytes doc/LiveShowProject/CatasWatchProject.lsh | Bin 212 -> 212 bytes doc/LiveShowProject/CatasWatchProject.lsp | Bin 644 -> 644 bytes doc/LiveShowProject/CatasWatchProject.lsu | Bin 1104 -> 1172 bytes doc/LiveShowProject/CatasWatchProject.lsx | Bin 3591 -> 3591 bytes doc/LiveShowProject/CatasWatchProject.spi | Bin 2024 -> 2335 bytes main/watchMain.cpp | 37 +++--- main/watchMain.hpp | 2 +- startCode.sh | 3 + test/integration/main/movementTests.cpp | 30 ++++- test/unitOnHost/CMakeLists.txt | 23 +--- test/unitOnHost/ReadMe.md | 28 ----- test/unitOnHost/test_core.cmake | 43 ------- 23 files changed, 255 insertions(+), 170 deletions(-) create mode 100644 components/watchFace/include/watchFace.hpp create mode 100644 components/watchFace/src/watchFace.cpp create mode 100644 components/watchFace/uTest/CMakeLists.txt create mode 100644 components/watchFace/uTest/WatchFaceUTest.cpp delete mode 100644 components/watchFace/watchFace.hpp create mode 100644 startCode.sh delete mode 100644 test/unitOnHost/ReadMe.md delete mode 100644 test/unitOnHost/test_core.cmake diff --git a/.vscode/launch.json b/.vscode/launch.json index 2511a38..b28858f 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,6 +10,39 @@ "type": "espidf", "name": "Launch", "request": "launch" + }, + { + "name": "C/C++: g++.exe debug selected file", + "type": "cppdbg", + "request": "launch", + // "program": "${fileDirname}\\${fileBasenameNoExtension}.exe", + "program": "${workspaceFolder}/test/unitOnHost/build/watchFace/watchFaceTest.exe", + // "program": "${workspaceFolder}/core/test/unitOnHost/build/devHal/devHalTest.exe", + + "args": [], + "stopAtEntry": false, + "cwd": "${fileDirname}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "miDebuggerPath": "C:\\msys64\\ucrt64\\bin\\gdb.exe", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + }, + { + "description": "Set Disassembly Flavor to Intel", + "text": "-gdb-set disassembly-flavor intel", + "ignoreFailures": true + } + ], + "existing": false, + // "preLaunchTask": "C/C++: g++.exe build active file", + "detail": "preLaunchTask: C/C++: g++.exe build active file", + "taskDetail": "compiler: C:\\msys64\\ucrt64\\bin\\g++.exe", + "taskStatus": "Detected Task" } ] } \ No newline at end of file diff --git a/components/watchFace/CMakeLists.txt b/components/watchFace/CMakeLists.txt index 8af9e6b..1f000f4 100644 --- a/components/watchFace/CMakeLists.txt +++ b/components/watchFace/CMakeLists.txt @@ -1,4 +1,4 @@ idf_component_register( - INCLUDE_DIRS "." + INCLUDE_DIRS "include" REQUIRES devHal ) diff --git a/components/watchFace/include/watchFace.hpp b/components/watchFace/include/watchFace.hpp new file mode 100644 index 0000000..b22c76b --- /dev/null +++ b/components/watchFace/include/watchFace.hpp @@ -0,0 +1,62 @@ +#pragma once + +#include "stepperDrv.hpp" +#include "stepperMotor.hpp" +#include + +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{}; +}; diff --git a/components/watchFace/src/watchFace.cpp b/components/watchFace/src/watchFace.cpp new file mode 100644 index 0000000..569eacb --- /dev/null +++ b/components/watchFace/src/watchFace.cpp @@ -0,0 +1 @@ +// Dummy file diff --git a/components/watchFace/uTest/CMakeLists.txt b/components/watchFace/uTest/CMakeLists.txt new file mode 100644 index 0000000..e3852fa --- /dev/null +++ b/components/watchFace/uTest/CMakeLists.txt @@ -0,0 +1,4 @@ +UnitTestsFrame() +target_link_libraries(${moduleName} PUBLIC + devHal +) \ No newline at end of file diff --git a/components/watchFace/uTest/WatchFaceUTest.cpp b/components/watchFace/uTest/WatchFaceUTest.cpp new file mode 100644 index 0000000..21d219c --- /dev/null +++ b/components/watchFace/uTest/WatchFaceUTest.cpp @@ -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 +#include + +#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 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 +} \ No newline at end of file diff --git a/components/watchFace/watchFace.hpp b/components/watchFace/watchFace.hpp deleted file mode 100644 index c7ceca3..0000000 --- a/components/watchFace/watchFace.hpp +++ /dev/null @@ -1,50 +0,0 @@ -#pragma once - -#include "StepperDrv8833.hpp" -#include "stepperMotor.hpp" -#include - -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{}; -}; diff --git a/core b/core index c85bfa2..1ce930d 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit c85bfa2afc665dbfc2b80af81e4919f613001ed4 +Subproject commit 1ce930dff89584e944b3eb779bb6de0da4c45fa7 diff --git a/doc/LiveShowProject/CatasWatchProject.lsb b/doc/LiveShowProject/CatasWatchProject.lsb index 7323c019428be2c957f1558726f4a550a8709f67..ef0f7d12d83432cd259cbe7abccec701b3a609ba 100644 GIT binary patch literal 17935 zcmeI4&2G~`6op-&?=f`23gbjVrAkv)Y%3wbg00&)BoN0@;!;w?8+F6;uwuoEcVK*- zdnRp(JvT)8o3Yf!ZG7zXB&{nnND;1VeZ=? zYkY}MF0%AI>Gb2b<0Lqwwcr_TR4Y5s$N7D$4}ASguN?$G+r2y;yjH5+OX7}x)N7M` zI!IJL9VKT+dGa-nE+>;CdP+a}Gz^Q4isd5fOw~8l&4zi{jnn>M+EVZ1UY5qEraSl+u5fT5mEW9Zd#Y_iO=xyZ^IHX&;a*-MWlOvzp@g(YNjSaK%d z^rv$eBm8s@ooAETY{p!#qR`05=GfG(x{RgqM24l&**xVpmb)Q5cEMStuV9%r}ZT3XMBx^Rn0a6Rcuk*VVeDt7Tmh3DB6%iFX|pF1CRwu|Os)h+gtqoLLgE^Z)C4qvi;@c%BVZC5 z&m`BjNo=i|G!oaCT#Tdf#2!bZ@i+oUgu8?zH36Gc(uBL7$$xukmjD?bono?b?52Uq z=1w z)~mkMM3O6G6Ee>x${d~u*@RBU=6++zVXhEMmaP&?Y63fcPcFtKq-?UGo=wy_LR}e~ zkgbx<9mf)$2(g52ZCFwhC~nB#^u70$r*o6=ir6$V&nB0-@kGX^(XEZm?Z*-!y9`Un cwggMv1P*@C>!y^gOUPm97n-vl|B=%)nnhG>vjIw zCSl-pF~UPeA7-;Ze*Wu@e>->N{Nr%_@y@*+)Q{qFIT^23Rrq4#)3hA?99`a( z#piN48-H3%+;KQ^ufs_@V+a0qzC8OE{`Jux9k>s}hpL!f_j<#-a=h}-{%GENs#ep< z)k!g0+&|7vt8)InH#iC3tWWT#^yhV?A2P#!_z|w3)}Sd~K2>CMUpH6tcJkt)6FFis zax@^xk<*bsbR)Nzj@%kh_;bZ#AM`XK$0V; zBVTqSw^$zXun5%e#XH_eXI6uCx17wqJn!U=SRVHTax@^xkyDYMjqI1+G*8?v#+Zsc zHsHu(PDcLidzY*Htcit1!0+y5?py6sx9RKpzIjIXH)#XL&F$BEE_&skU%*s!nqIob zW?IXrF(9NB`9&oSc zb~1h(g?l~W=mktQiT8S%;$euSnrFPa+sU!v=g1MuafOFPAn6_(YLM>8>D+DOPr6$y zhkF{iHDJjtrz5ukfF!q=j@%lsV-VoT>sVL>!i|5K`&RqpRUJ89l)0|P?_0|S#5P=E(0pabN?022pLU;^XBf>Z!X C#t6p% diff --git a/doc/LiveShowProject/CatasWatchProject.lsd b/doc/LiveShowProject/CatasWatchProject.lsd index 58223a05fcedf191f750dcc1f6305453543dad8c..070cb005080ca65ddcd12c649a531f54820ae699 100644 GIT binary patch delta 529 zcmX@Hf$QW3t_>%cCM&Z_PCmgTH`#z$U@{-G^yD8*Vw2BEifs;K-px2!i&bcHH9OB_ zF;)?At~!igEG^Ug^mzxFt4U<-E)|`7p28 zg?y z`~M$Io+u`}xkjL#k?}uNaUJ92slqkvTejC8KXP7gvZ1)j%cCO>47n;gh4J9!?v%H(fMl9Q(hi){{L-px2!i&YXV;lZjh`3I9Y zSYih2CdSFh?DCTZS>-0nGV@LjWfg}@-e5n)IQam##N-8>(wnbxUWRa%aZ7Bz!F_>o z@*+;@$t$?UHs9psWZax5J&SSkM1gt;Yw{}Ln#uc>xhD6?Do#G2!Z|rg3EYIM8L{DBLp)A}06-S~cKax-vDu9Y3 z=*iNOI+OKy1x49{bMx~{G9U^V7z(Nw7?@%w=Su20F$2XI8F+#-N=r&oi{kwYQu7?3 z27_fdd=hgD;{DUoV0yu#>=4mBkl^HAVcE%>C6gxeh)BVF-`pkD-X+Djy-SK|e=Pt> CiEx+z diff --git a/doc/LiveShowProject/CatasWatchProject.lsh b/doc/LiveShowProject/CatasWatchProject.lsh index 229de58a26231fc1a6496abc3d3307f850f87d47..5c6d4b860d51ff7ba25a31da25b8624a6e49c607 100644 GIT binary patch delta 52 zcmcb@c!hC7DI?>=GF4RzU1LXG3kzLSQ(YHxT~|j&20;S@T|-k{Qx{z$M_o5pT}Km! Hi3dagUZ)Io delta 52 zcmcb@c!hC7DI>$gGF4RrT|-k{Qx{zeV_gFmT@z;p20;T0U1LXG3kzLSQ(YHxT~|lO Hi3dagTAK`4 diff --git a/doc/LiveShowProject/CatasWatchProject.lsp b/doc/LiveShowProject/CatasWatchProject.lsp index 19cdd3b7efd0ab52175565c9e2e5ea9cb4e68907..49b5e5123f27ef352685d24309d34b2e8cc2cc6e 100644 GIT binary patch delta 16 XcmZo+ZDHN;g^|%>;(F=H0!$?UFfRpV delta 16 XcmZo+ZDHN;g^|&G;(F=H0!$?UFee3M diff --git a/doc/LiveShowProject/CatasWatchProject.lsu b/doc/LiveShowProject/CatasWatchProject.lsu index a8a763e40f579e4ccfbd257f4dc4fab86b8cb01d..076cef2a4e2d36cec1e017d1061a08d59e97961b 100644 GIT binary patch delta 178 zcmcb>F@^whk}^wgq>7alP(OrFSO$hdX#LT1&;TukCn z{(dmOl8J}Cc+Fb|*7DrR_KY%ttPE(t{(=Bl#J+s3632r#hwL9f`R!o-Vfz;n5c%F2 sS>2NApY1`V?`Gr%vvry8FdGybOy0;S3gqiBmAg*% HXK@7pW5*L3 diff --git a/doc/LiveShowProject/CatasWatchProject.lsx b/doc/LiveShowProject/CatasWatchProject.lsx index 82a165c703808fd805bf2a563dd4556c0821b60a..2d7a2b0255ea7893803cd41ab7ceb205262eba3c 100644 GIT binary patch delta 18 ZcmZpdX_whx%flEr`8<=~<{qAEMgTfZ1`7ZH delta 18 ZcmZpdX_whx%fonV@_8n|%{@HTi~v6027mwn diff --git a/doc/LiveShowProject/CatasWatchProject.spi b/doc/LiveShowProject/CatasWatchProject.spi index 08fa45da8cdb49c8a07e7feb592179eb39c2c595..3ec597e449e8844931eb7bd574f183b2078122fc 100644 GIT binary patch delta 267 zcmaFCKVN8q2qVWvQC21kMh2Bs14BzQ6SG8JlT;%UT@y0{3tdZ7lT_W5M3dx1GjlV; zq$D#25a15U_e{^rFG^J~F`m4TNtlsi@&Xq1%}z`;j4V|Q3@nrPGW$$^z``%1DJ(4Ik5$!-Gux6b- i%fU2L>NPOU5^@PlgNez~tfG_kS$UZmBcg!LGX?;lH9c_v delta 61 zcmbO)^n!na2qXJOQC22K_Q{Ft>YIC+Y8WR!U@@BPz#_?7#lXOPYjPw@EK`NV~F;9NaECp1-4FDXQ5@!Ga diff --git a/main/watchMain.cpp b/main/watchMain.cpp index 6fd3d97..80fc1d1 100644 --- a/main/watchMain.cpp +++ b/main/watchMain.cpp @@ -591,7 +591,10 @@ void MovementTask() { StepperMotor stepper(stepperCfg, stepperDriver, initSens); - WatchMotor watch(stepper, motorSleep); + WatchMotor watch(stepper, [](uint8_t newPos) { + pictoIllumQue.enqueue(std::make_unique(newPos)); + responseQueue.enqueue(std::make_unique(ResponseType::StepAt, newPos)); + }); ESP_LOGI("Stepper", "Find Home"); stepper.findRef(); @@ -627,23 +630,15 @@ void MovementTask() { continue; } - int jumps = newPos - watch.getIndex(); - if (jumps <= 0) { - jumps += 6; - } - jumps = jumps + (activeState.minJumps % 6) * 6; - if (jumps < activeState.minJumps) { - jumps += 6; - } Syslog::logv(Syslog::Severity::Notice, - "Running Stepper by %i steps with prof=%i a=%.2f w=%.2f", - jumps, activeState.profile, activeState.accel, activeState.speed); + "Running Stepper by min%i steps with prof=%i a=%.2f w=%.2f", + activeState.minJumps, activeState.profile, activeState.accel, activeState.speed); pictoIllumQue.enqueue(std::make_unique(0)); responseQueue.enqueue(std::make_unique(ResponseType::StartMoving, 0)); - watch.moveTo(newPos, activeState.profile); - - pictoIllumQue.enqueue(std::make_unique(newPos)); - responseQueue.enqueue(std::make_unique(ResponseType::StepAt, newPos)); + auto &as = activeState; + watch.moveTo(newPos, as.profile, as.minJumps, as.accel, as.speed); + // pictoIllumQue.enqueue(std::make_unique(newPos)); + // responseQueue.enqueue(std::make_unique(ResponseType::StepAt, newPos)); } } else if (cmd->type == MoveType::Demo) { ESP_LOGI(TAG, "Running Demo"); @@ -652,7 +647,7 @@ void MovementTask() { fos::Task::delayMs(1000); int steps[3]{4, 2, 0}; for (size_t j = 0; j < 3; j++) { - watch.moveTo(steps[j], i); + watch.moveTo(steps[j], i, 1, 1, 1); fos::Task::delayMs(1000); } } @@ -735,11 +730,11 @@ bool onCheckSpitTypeVeto(bool knownType, bool createdByClient) { } bool onCheckSpitObjectVeto(bool knownType) { - return true; // Bypass veto + return true; // Bypass veto if (!knownType) { // Don't allow objects of unregistered SPITTypes return false; } - + return true; } @@ -988,8 +983,8 @@ void app_main(void) { // ToDo send Syslog::logv(Syslog::Severity::Notice, "Health state"); // ESP_LOGI(TAG, "Min heap size: %" PRIu32 " / FreeHeap %" PRIu32 "\n", - ESP_LOGI(TAG, "Min heap size: %u / FreeHeap %lu", - heap_caps_get_minimum_free_size(MALLOC_CAP_DEFAULT), - esp_get_free_heap_size()); + // ESP_LOGI(TAG, "Min heap size: %u / FreeHeap %lu", + // heap_caps_get_minimum_free_size(MALLOC_CAP_DEFAULT), + // esp_get_free_heap_size()); } } diff --git a/main/watchMain.hpp b/main/watchMain.hpp index dba95a0..87b53ed 100644 --- a/main/watchMain.hpp +++ b/main/watchMain.hpp @@ -24,7 +24,7 @@ // Component header #include "Task.hpp" #include "PwmExpanderPca9685.hpp" -#include "StepperDrv8833.hpp" +#include "stepperDrv.hpp" #include "stepperMotor.hpp" #include "cliWrapper.hpp" #include "udpSockets.hpp" diff --git a/startCode.sh b/startCode.sh new file mode 100644 index 0000000..4442e30 --- /dev/null +++ b/startCode.sh @@ -0,0 +1,3 @@ +#!/bin/bash +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +code --profile Embed-Esp ${SCRIPT_DIR} diff --git a/test/integration/main/movementTests.cpp b/test/integration/main/movementTests.cpp index 9fc745e..5f91e34 100644 --- a/test/integration/main/movementTests.cpp +++ b/test/integration/main/movementTests.cpp @@ -11,11 +11,11 @@ #include "Processor.hpp" #include "PwmExpanderPca9685.hpp" -#include "StepperDrv8833.hpp" #include "Task.hpp" #include "esp_event.h" #include "esp_log.h" #include "sdkconfig.h" +#include "stepperDrv.hpp" #include "stepperMotor.hpp" #include "watchFace.hpp" #include @@ -181,6 +181,10 @@ constexpr bool DoFullTurns = false; constexpr bool DoTurnSteps = false; constexpr bool DoTurnProfiles = true; +void AllmostDone(uint8_t newIdx) { + ESP_LOGW(TAG, "Done callback"); +} + void testMovementTask() { esp_log_level_set(TAG, ESP_LOG_DEBUG); esp_log_level_set("STP", ESP_LOG_DEBUG); @@ -207,7 +211,7 @@ void testMovementTask() { OutputPort motorSleep(GPIO_NUM_15, GpioPort::Logic::Inverted); StepperMotor stepper(stepperCfg, stepperDriver, initSens); - WatchMotor watch(stepper, motorSleep); + WatchMotor watch(stepper, motorSleep, AllmostDone); /// /// Full Turns with full steps @@ -273,14 +277,14 @@ void testMovementTask() { ESP_LOGI(TAG, "Move to each index multiple times"); illum.flashAll(BLUE); for (size_t i = 1; i <= 2 * 3; i++) { - watch.moveTo(3 * i); + watch.moveTo(3 * i, 0, 0, 1, 1); ESP_LOGD(TAG, "Position is %3d / %.2f", stepper.getQuanted(), stepper.getScaledPos() * 6); } ESP_LOGI(TAG, "Move to each index multiple times"); illum.flashAll(BLUE); for (size_t i = 1; i <= 6 * 3; i++) { - watch.moveTo(i); + watch.moveTo(i, 0, 0, 1, 1); ESP_LOGD(TAG, "Position is %3d / %.2f", stepper.getQuanted(), stepper.getScaledPos() * 6); } } @@ -290,14 +294,28 @@ void testMovementTask() { /// if constexpr (DoTurnProfiles) { for (size_t i = ProfileGenerator::Smooth; i < ProfileGenerator::NumProfiles; i++) { - // for (size_t i = ProfileGenerator::JumpIn; i < ProfileGenerator::NumProfiles; i++) { // If only part is needed + // for (size_t i = ProfileGenerator::JumpIn; i < ProfileGenerator::NumProfiles; i++) { // If only part is needed ESP_LOGI(TAG, "Running Profile %d ", i); ESP_LOGD(TAG, "Fist Position is %3d / %.2f / Micro %d", stepper.getQuanted(), stepper.getScaledPos() * 6, stepper.getSubPos()); fos::Task::delayMs(1000); illum.flashAll(BLUE); int steps[3]{4, 2, 0}; for (size_t j = 0; j < 3; j++) { - watch.moveTo(steps[j], i); + watch.moveTo(steps[j], i, 0, 1, 1); + ESP_LOGI(TAG, "Last position is %3d / %.2f", stepper.getQuanted(), stepper.getScaledPos() * 6); + fos::Task::delayMs(1000); + } + } + + for (size_t i = ProfileGenerator::Smooth; i < ProfileGenerator::NumProfiles; i++) { + // for (size_t i = ProfileGenerator::JumpIn; i < ProfileGenerator::NumProfiles; i++) { // If only part is needed + ESP_LOGI(TAG, "Running Profile %d ", i); + ESP_LOGD(TAG, "Fist Position is %3d / %.2f / Micro %d", stepper.getQuanted(), stepper.getScaledPos() * 6, stepper.getSubPos()); + fos::Task::delayMs(1000); + illum.flashAll(BLUE); + int steps[3]{4, 2, 0}; + for (size_t j = 0; j < 3; j++) { + watch.moveTo(steps[j], i, 0, 3, 3); ESP_LOGI(TAG, "Last position is %3d / %.2f", stepper.getQuanted(), stepper.getScaledPos() * 6); fos::Task::delayMs(1000); } diff --git a/test/unitOnHost/CMakeLists.txt b/test/unitOnHost/CMakeLists.txt index 197f034..7efdcf8 100644 --- a/test/unitOnHost/CMakeLists.txt +++ b/test/unitOnHost/CMakeLists.txt @@ -1,26 +1,11 @@ cmake_minimum_required(VERSION 3.16) +include(../../core/test/unitOnHost/test_core.cmake) -set(DEF_UTESTDIR "uTest") -set(DEF_SRCDIR "src") -set(DEF_INCLUDEDIR "include") - -# use just host compilers for this one -set(CMAKE_C_COMPILER "gcc") -set(CMAKE_CXX_COMPILER "g++") -set(CMAKE_GENERATOR "Ninja") -set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE) -set(CMAKE_VERBOSE_MAKEFILE TRUE) - -include(test_core.cmake) +UnitTestSetup() enable_testing() project(UnitTests) - -find_package(doctest REQUIRED PATHS "/mingw64/lib/cmake") -# target_link_libraries(${PROJECT_NAME} PRIVATE doctest::doctest) - addSubDirs_ofRoot("${CMAKE_CURRENT_LIST_DIR}/../../components") - - - +addSubDirs_ofRoot("${CMAKE_CURRENT_LIST_DIR}/../../core/components") +add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/../../core/test/unitOnHost/hwMock" hwMock) diff --git a/test/unitOnHost/ReadMe.md b/test/unitOnHost/ReadMe.md deleted file mode 100644 index 540055c..0000000 --- a/test/unitOnHost/ReadMe.md +++ /dev/null @@ -1,28 +0,0 @@ -# Unit Testing - Software - -In contrast to *test*-directory this module demonstrates how unit tests can also be run on host. -These unit tests aim to test freestanding software modules with more convenient methods and tools - -## Setup - -make sure you have following packages installed on your host syste -- gnu compiler -- cmake -- generator -- doctest-dev - -## Build and test code - -* Start some terminal in *uTest*-directory that has access to all needed tools (i.e. on windows a mingw environment or WSL) - -Run following commands -```sh -# run cmake configuration -cmake -S . -B build -# run cmake build -cmake --build build -# run tests -./build/ -# run all tests with -cd build && ctest -``` diff --git a/test/unitOnHost/test_core.cmake b/test/unitOnHost/test_core.cmake deleted file mode 100644 index 3c442cb..0000000 --- a/test/unitOnHost/test_core.cmake +++ /dev/null @@ -1,43 +0,0 @@ -function(addSubDirs_ofRoot anchorPath) - message("scanning: ${anchorPath}") - file(GLOB targetModules RELATIVE "${anchorPath}" "${anchorPath}/*") - foreach(module ${targetModules}) - message("checking: ${module}") - get_filename_component(moduleName ${module} NAME) - set(modulePath "${anchorPath}/${moduleName}") - if (NOT IS_DIRECTORY "${modulePath}") - # skip files - continue() - endif() - if (${moduleName} MATCHES "^_.*") - # skip ignored component - continue() - endif() - - if(EXISTS "${modulePath}/${DEF_UTESTDIR}") - message("Found unit-test: ${moduleName}") - add_subdirectory("${modulePath}/${DEF_UTESTDIR}" ${moduleName}) - endif() - endforeach() -endfunction() - -macro(unitTestsFrame) - if (CMAKE_TESTING_ENABLED) - # get_filename_component(moduleName "${CMAKE_CURRENT_LIST_DIR}/.." NAME) - file(GLOB_RECURSE targetSources "../${DEF_SRCDIR}/*.cpp" "../${DEF_SRCDIR}/*.c") - add_library(${moduleName} ${targetSources}) - target_include_directories(${moduleName} PUBLIC "../${DEF_INCLUDEDIR}") - - set(moduleTestName "${moduleName}Test") - file(GLOB_RECURSE testSource "*.cpp") - add_executable(${moduleTestName} ${testSource}) - target_link_libraries(${moduleTestName} PRIVATE ${moduleName} doctest::doctest) - target_include_directories(${moduleTestName} PRIVATE "../${DEF_SRCDIR}") - - add_test (TEST-${moduleName} ${moduleTestName}) - - # gtest_discover_tests(${moduleTestName} - # PROPERTIES TIMEOUT 30 LABELS ${moduleName} LABELS "all" - # ) - endif() -endmacro()