Add needy finetuner
This commit is contained in:
parent
40647eb204
commit
30d3c253b5
3 changed files with 343 additions and 0 deletions
209
src/modules/needy_finetuner/doc/face.svg
Normal file
209
src/modules/needy_finetuner/doc/face.svg
Normal file
|
@ -0,0 +1,209 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
|
||||||
|
<svg
|
||||||
|
width="40mm"
|
||||||
|
height="32mm"
|
||||||
|
viewBox="0 0 40 32"
|
||||||
|
version="1.1"
|
||||||
|
id="svg5"
|
||||||
|
inkscape:version="1.1 (c68e22c387, 2021-05-23)"
|
||||||
|
sodipodi:docname="face.svg"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg">
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="namedview7"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1.0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:pageopacity="0.0"
|
||||||
|
inkscape:pagecheckerboard="0"
|
||||||
|
inkscape:document-units="mm"
|
||||||
|
showgrid="false"
|
||||||
|
width="4mm"
|
||||||
|
showguides="true"
|
||||||
|
inkscape:guide-bbox="true"
|
||||||
|
inkscape:zoom="4.6884835"
|
||||||
|
inkscape:cx="43.724159"
|
||||||
|
inkscape:cy="50.336105"
|
||||||
|
inkscape:window-width="1920"
|
||||||
|
inkscape:window-height="1054"
|
||||||
|
inkscape:window-x="0"
|
||||||
|
inkscape:window-y="0"
|
||||||
|
inkscape:window-maximized="1"
|
||||||
|
inkscape:current-layer="layer1"
|
||||||
|
inkscape:snap-global="true">
|
||||||
|
<sodipodi:guide
|
||||||
|
position="19.999999,31.999999"
|
||||||
|
orientation="-1,0"
|
||||||
|
id="guide9"
|
||||||
|
inkscape:label=""
|
||||||
|
inkscape:locked="false"
|
||||||
|
inkscape:color="rgb(0,0,255)" />
|
||||||
|
<sodipodi:guide
|
||||||
|
position="0,2.9999999"
|
||||||
|
orientation="0,1"
|
||||||
|
id="guide11"
|
||||||
|
inkscape:label=""
|
||||||
|
inkscape:locked="false"
|
||||||
|
inkscape:color="rgb(0,0,255)" />
|
||||||
|
<sodipodi:guide
|
||||||
|
position="28.336657,20.053439"
|
||||||
|
orientation="0,-1"
|
||||||
|
id="guide1042" />
|
||||||
|
<sodipodi:guide
|
||||||
|
position="0,31.999999"
|
||||||
|
orientation="0,151.1811"
|
||||||
|
id="guide8477" />
|
||||||
|
<sodipodi:guide
|
||||||
|
position="39.999999,31.999999"
|
||||||
|
orientation="120.94488,0"
|
||||||
|
id="guide8479" />
|
||||||
|
<sodipodi:guide
|
||||||
|
position="39.999999,0"
|
||||||
|
orientation="0,-151.1811"
|
||||||
|
id="guide8481" />
|
||||||
|
<sodipodi:guide
|
||||||
|
position="0,0"
|
||||||
|
orientation="-120.94488,0"
|
||||||
|
id="guide8483" />
|
||||||
|
</sodipodi:namedview>
|
||||||
|
<defs
|
||||||
|
id="defs2" />
|
||||||
|
<g
|
||||||
|
inkscape:label="Layer 1"
|
||||||
|
inkscape:groupmode="layer"
|
||||||
|
id="layer1">
|
||||||
|
<path
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:0.2;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
id="path35"
|
||||||
|
sodipodi:type="arc"
|
||||||
|
sodipodi:cx="20.000002"
|
||||||
|
sodipodi:cy="29.000002"
|
||||||
|
sodipodi:rx="22.397001"
|
||||||
|
sodipodi:ry="22.397001"
|
||||||
|
sodipodi:start="4.0101511"
|
||||||
|
sodipodi:end="5.4155569"
|
||||||
|
sodipodi:open="true"
|
||||||
|
sodipodi:arc-type="arc"
|
||||||
|
d="m 5.5331584,11.902163 a 22.397001,22.397001 0 0 1 28.9495826,0.01346" />
|
||||||
|
<rect
|
||||||
|
style="fill:#000000;stroke:none;stroke-width:0.2;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
id="rect3123"
|
||||||
|
width="1.3620886"
|
||||||
|
height="0.27241772"
|
||||||
|
x="-2.1316838"
|
||||||
|
y="11.505157"
|
||||||
|
transform="rotate(-37)" />
|
||||||
|
<path
|
||||||
|
id="rect3249"
|
||||||
|
style="fill:#000000;stroke:none;stroke-width:0.2;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
d="m 34.722067,9.7419343 -0.327791,0.4349927 -0.435404,-0.3281014 -0.163896,0.2174964 0.435405,0.328101 -0.328101,0.435405 0.217496,0.163896 0.328102,-0.435405 0.434992,0.32779 0.163896,-0.217496 -0.434993,-0.327791 0.32779,-0.4349924 z" />
|
||||||
|
<path
|
||||||
|
style="fill:#000000;stroke:none;stroke-width:0.2;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
d="m 19.075418,6.4278353 c -0.01451,-0.214218 -0.10023,-2.2205407 -0.0951,-2.2255612 0.01288,-0.01259 0.666146,-0.035518 1.01135,-0.035499 0.341166,1.92e-5 1.016579,0.02285 1.028786,0.034775 0.0052,0.00509 -0.09888,2.3530119 -0.104416,2.35529 -0.0022,9.087e-4 -0.19718,-0.0024 -0.433284,-0.00732 -0.407494,-0.00851 -1.128692,-0.00443 -1.312912,0.00743 l -0.08532,0.00549 z"
|
||||||
|
id="path3531" />
|
||||||
|
<path
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:0.2;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
id="path4396"
|
||||||
|
sodipodi:type="arc"
|
||||||
|
sodipodi:cx="20.000002"
|
||||||
|
sodipodi:cy="29.000002"
|
||||||
|
sodipodi:rx="24.793976"
|
||||||
|
sodipodi:ry="24.793976"
|
||||||
|
sodipodi:start="4.0101511"
|
||||||
|
sodipodi:end="5.4155569"
|
||||||
|
sodipodi:open="true"
|
||||||
|
sodipodi:arc-type="arc"
|
||||||
|
d="m 3.9848862,10.072316 a 24.793976,24.793976 0 0 1 32.0478278,0.0149" />
|
||||||
|
<path
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:0.2;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
id="path4500"
|
||||||
|
sodipodi:type="arc"
|
||||||
|
sodipodi:cx="20.000002"
|
||||||
|
sodipodi:cy="29.000002"
|
||||||
|
sodipodi:rx="24.793976"
|
||||||
|
sodipodi:ry="24.793976"
|
||||||
|
sodipodi:start="4.0101511"
|
||||||
|
sodipodi:end="5.4155569"
|
||||||
|
sodipodi:open="true"
|
||||||
|
sodipodi:arc-type="arc"
|
||||||
|
d="m 3.9848862,10.072316 a 24.793976,24.793976 0 0 1 32.0478278,0.0149" />
|
||||||
|
<rect
|
||||||
|
style="fill:#ffffff;stroke:none;stroke-width:0.2;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
id="rect6530"
|
||||||
|
width="0.99619198"
|
||||||
|
height="0.23809774"
|
||||||
|
x="19.501904"
|
||||||
|
y="5.0292072" />
|
||||||
|
<rect
|
||||||
|
style="fill:#ffffff;stroke:none;stroke-width:0.2;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
id="rect6612"
|
||||||
|
width="0.99619198"
|
||||||
|
height="0.23809774"
|
||||||
|
x="19.501904"
|
||||||
|
y="5.5685601" />
|
||||||
|
<path
|
||||||
|
id="path6805"
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:0.75590552;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
d="M 70.351232 25.14266 L 69.799861 16.253941 "
|
||||||
|
transform="scale(0.26458333)" />
|
||||||
|
<path
|
||||||
|
id="path6887"
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:0.75590552;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
d="M 66.60051 25.453369 L 65.643829 16.498172 "
|
||||||
|
transform="scale(0.26458333)" />
|
||||||
|
<path
|
||||||
|
id="path6946"
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:0.75590552;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
d="M 60.721603 26.288978 L 59.161092 17.544741 "
|
||||||
|
transform="scale(0.26458333)" />
|
||||||
|
<path
|
||||||
|
id="path7024"
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:0.75590552;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
d="M 51.194923 28.560264 L 48.68332 20.216329 "
|
||||||
|
transform="scale(0.26458333)" />
|
||||||
|
<path
|
||||||
|
id="path7102"
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:0.75590552;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
d="M 39.932224 32.847187 L 36.165998 24.739902 "
|
||||||
|
transform="scale(0.26458333)" />
|
||||||
|
<path
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:0.2;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
d="M 5.5331584,11.902163 3.9848862,10.072316"
|
||||||
|
id="path7412"
|
||||||
|
sodipodi:nodetypes="cc" />
|
||||||
|
<path
|
||||||
|
id="path8133"
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:0.2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||||
|
d="M 21.403837,6.6672313 21.54972,4.3154244" />
|
||||||
|
<path
|
||||||
|
id="path8135"
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:0.2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||||
|
d="M 22.396215,6.7494397 22.649337,4.3800439" />
|
||||||
|
<path
|
||||||
|
id="path8137"
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:0.2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||||
|
d="M 23.951676,6.9705279 24.364561,4.6569486" />
|
||||||
|
<path
|
||||||
|
id="path8139"
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:0.2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||||
|
d="M 26.472277,7.5714724 27.136805,5.3638062" />
|
||||||
|
<path
|
||||||
|
id="path8141"
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:0.2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||||
|
d="M 29.452199,8.7057207 30.44868,6.5606683" />
|
||||||
|
<path
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:0.2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||||
|
d="m 34.484441,11.917066 1.548273,-1.829847"
|
||||||
|
id="path8143"
|
||||||
|
sodipodi:nodetypes="cc" />
|
||||||
|
<path
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:0.2;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
d="M 0,1.0990401e-7 V 31.999999 H 39.999999 V 1.0990401e-7 Z"
|
||||||
|
id="path8485" />
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 8.8 KiB |
20
src/modules/needy_finetuner/doc/index.md
Normal file
20
src/modules/needy_finetuner/doc/index.md
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
# Finetuner
|
||||||
|
|
||||||
|
Schrijf de handleiding voor je module hier. Kijk gerust naar de handleiding
|
||||||
|
voor de "Doolhof"-module (`src/modules/puzzle_maze/doc/index.md`)
|
||||||
|
|
||||||
|
|
||||||
|
Hieronder wat voorbeelden van markup die je kan gebruiken. Daarnaast kan je ook LaTeX
|
||||||
|
gebruiken (zie bijvoorbeeld de "Doolhof"-module)
|
||||||
|
|
||||||
|
Use drawings! Create the docs/images/your_module directory, put your image there and include them like this:
|
||||||
|
|
||||||
|
![](./your_module/filename.png)
|
||||||
|
|
||||||
|
Use tables! Write them like this:
|
||||||
|
|
||||||
|
| Symbol | Action to take |
|
||||||
|
|--------------------------------|----------------|
|
||||||
|
| ![](./your_module/symbol1.png) | Do nothing |
|
||||||
|
| ![](./your_module/symbol2.png) | Press the red button |
|
||||||
|
| ![](./your_module/symbol3.png) | Press the yellow button |
|
114
src/modules/needy_finetuner/needy_finetuner.ino
Normal file
114
src/modules/needy_finetuner/needy_finetuner.ino
Normal file
|
@ -0,0 +1,114 @@
|
||||||
|
// (c) 2022, Midgard
|
||||||
|
// See the LICENSE file for conditions for copying
|
||||||
|
|
||||||
|
#include <obus_module.h>
|
||||||
|
|
||||||
|
#define PIN_GAUGE 3
|
||||||
|
#define PIN_SLIDER A7
|
||||||
|
|
||||||
|
#define ADJUSTMENT_PERIOD_MS 15000
|
||||||
|
#define SLEEP_PERIOD_MS 5000
|
||||||
|
|
||||||
|
#define ARRAY_LENGTH(array) ((sizeof array)/(sizeof (array[0])))
|
||||||
|
|
||||||
|
uint32_t deadline = 0;
|
||||||
|
int16_t target = 0;
|
||||||
|
int16_t previousTarget = 0;
|
||||||
|
uint8_t moved = 0;
|
||||||
|
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
|
||||||
|
obus_module::setup(OBUS_TYPE_NEEDY, OBUS_NEEDY_ID_DEVELOPMENT);
|
||||||
|
|
||||||
|
pinMode(PIN_GAUGE, OUTPUT);
|
||||||
|
pinMode(PIN_SLIDER, INPUT);
|
||||||
|
|
||||||
|
target = getSliderValue();
|
||||||
|
previousTarget = target;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t stops[] { 0, 18, 147, 526, 900, 1008, 1024 };
|
||||||
|
uint16_t getSliderValue() {
|
||||||
|
uint16_t value = analogRead(PIN_SLIDER) + 1;
|
||||||
|
for (int i = 1; i < ARRAY_LENGTH(stops); i++) {
|
||||||
|
if (value <= stops[i]) return (value - stops[i - 1]) * 170 / (stops[i] - stops[i-1]) + (i-1)*170 - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void gauge(unsigned char value) {
|
||||||
|
// analogWrite accepts values from 0 to 255
|
||||||
|
analogWrite(PIN_GAUGE, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
obus_can::message message;
|
||||||
|
|
||||||
|
bool is_in_tune(int16_t target, int16_t sliderValue) {
|
||||||
|
return abs(target - sliderValue) <= 20;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
int amountOfLedsToLight(timeLeft, target, sliderValue) {
|
||||||
|
if (is_in_tune(target, sliderValue)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (timeLeft <= ADJUSTMENT_PERIOD_MS * 2 / 4) return 3;
|
||||||
|
if (timeLeft <= ADJUSTMENT_PERIOD_MS * 3 / 4) return 2;
|
||||||
|
if (timeLeft <= ADJUSTMENT_PERIOD_MS * 4 / 4) return 1;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
bool is_message_valid = obus_module::loopNeedy(&message, callback_game_start, callback_game_stop);
|
||||||
|
|
||||||
|
int16_t sliderValue = getSliderValue();
|
||||||
|
int16_t gaugeValue = previousTarget - sliderValue;
|
||||||
|
|
||||||
|
int32_t timeLeft = deadline - millis();
|
||||||
|
if (timeLeft <= ADJUSTMENT_PERIOD_MS) {
|
||||||
|
// Require a movement being detected for at least 2 successive loops, to combat jitter
|
||||||
|
if (moved >= 2) {
|
||||||
|
gaugeValue = target - sliderValue;
|
||||||
|
} else {
|
||||||
|
if (abs(sliderValue - previousTarget) > 2) moved++;
|
||||||
|
else moved = 0;
|
||||||
|
|
||||||
|
gaugeValue = (ADJUSTMENT_PERIOD_MS - timeLeft) * 127 / ADJUSTMENT_PERIOD_MS;
|
||||||
|
if (target > previousTarget) {
|
||||||
|
gaugeValue *= -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*amountLeds = amountOfLedsToLight(timeLeft, target, sliderValue);*/
|
||||||
|
|
||||||
|
if (timeLeft < 0) {
|
||||||
|
deadline = millis() + ADJUSTMENT_PERIOD_MS + SLEEP_PERIOD_MS;
|
||||||
|
previousTarget = sliderValue;
|
||||||
|
do {
|
||||||
|
target = random(1023 - 2*30) + 30;
|
||||||
|
} while(abs(target - previousTarget) < 50);
|
||||||
|
moved = 0;
|
||||||
|
|
||||||
|
if (!is_in_tune(target, sliderValue)) {
|
||||||
|
obus_module::strike();
|
||||||
|
target = sliderValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gaugeValue > 127) gaugeValue = 127;
|
||||||
|
else if (gaugeValue < -127) gaugeValue = -127;
|
||||||
|
gauge(gaugeValue + 127);
|
||||||
|
|
||||||
|
delay(50);
|
||||||
|
}
|
||||||
|
|
||||||
|
void callback_game_start(uint8_t puzzle_modules) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void callback_game_stop() {
|
||||||
|
((void (*)(void))0)();
|
||||||
|
}
|
Loading…
Reference in a new issue