Compare commits

37 Commits

Author SHA1 Message Date
Emanuele Trabattoni
575730a340 Finalized PINMAP 2026-04-09 15:54:59 +02:00
Emanuele Trabattoni
155f58a347 refactored webserver code 2026-04-09 14:42:13 +02:00
Emanuele Trabattoni
1e068476af LittleFS mount OK, updated interface, upload to littlefs from browser 2026-04-09 13:41:50 +02:00
Emanuele Trabattoni
de9ffe40e5 refactor variables and LittleFS mount 2026-04-09 10:23:57 +02:00
Emanuele Trabattoni
97bce90ba6 changed partition to littlefs, not working yet 2026-04-08 17:10:30 +02:00
Emanuele Trabattoni
12e1e8e7a4 Fixed Filters, split file in html, script and css 2026-04-08 16:55:03 +02:00
Emanuele Trabattoni
4dc45954e9 Webpage is OK, html in memory since SPIFFS is to slow.
Moving average to be fixed
2026-04-08 15:23:21 +02:00
Emanuele Trabattoni
07eb06f67b Save History Sync on flash, still some issues in deleting previous file 2026-04-08 10:27:18 +02:00
Emanuele Trabattoni
481f12f526 Enable/Disable pickup simulation 2026-04-08 10:26:44 +02:00
Emanuele Trabattoni
7c96101cdd SPIFFS mount sometimes fail 2026-04-07 17:33:08 +02:00
Emanuele Trabattoni
877236ee4e Save files appending on same session and new file on new session 2026-04-07 15:53:52 +02:00
Emanuele Trabattoni
668b590d7c CSV file save on SPIFF filesystem, 10MB on internal flash 2026-04-07 13:21:27 +02:00
Emanuele Trabattoni
f36cb96f21 Improved task code 2026-04-07 10:51:53 +02:00
Emanuele Trabattoni
dc44decd64 Moved files in libraries 2026-04-07 10:19:28 +02:00
Emanuele Trabattoni
0d0db29bba Merge branch 'adc' 2026-04-07 10:12:50 +02:00
5c9ef7e93b Fast ADC readings ok, to verify timing and settling time 2026-04-05 17:05:10 +02:00
a2d0afa0c9 adc read ok, very slow 2026-04-05 11:16:10 +02:00
1109681eb5 Merge branch 'debug' 2026-04-05 10:32:08 +02:00
c5d80052e5 Thans to copilot, microsecond resolution to wait for spark.
no missing firings detected
2026-04-04 22:12:53 +02:00
38c595fd7b revert on double task wait, normal and soft start working 2026-04-04 20:00:30 +02:00
b0842aadef Sync 12 and 34 working 2026-04-04 16:27:52 +02:00
0dc5d1ce79 Debug Config OK, ready to realtime debugging 2026-04-04 03:25:33 +02:00
Emanuele Trabattoni
941a2b4eaa debug testing commit 2026-04-04 03:11:44 +02:00
Emanuele Trabattoni
48df6a509d Test OK Channel A 2026-04-01 12:31:29 +02:00
Emanuele Trabattoni
ebff6281af Test Softs start working 2026-04-01 12:00:07 +02:00
Emanuele Trabattoni
d7e0990e36 Test working at 100Khz 2026-04-01 11:43:44 +02:00
Emanuele Trabattoni
21e50bdca8 Tester first iteration 2026-03-31 17:44:00 +02:00
Emanuele Trabattoni
6072a603df First Attempt to print data async, fields not working 2026-03-31 13:07:02 +02:00
Emanuele Trabattoni
27ad612844 Mod to ISR and Tasks ok working 2026-03-31 09:19:11 +02:00
Emanuele Trabattoni
ec138553ad Separate code from headers 2026-03-30 16:29:40 +02:00
Emanuele Trabattoni
1adbf7fdb9 Tasks, ISR, Pin refactoring and renaming 2026-03-30 15:50:17 +02:00
Emanuele Trabattoni
e0af350b89 refactored real time task to general with configuration structure 2026-03-30 12:36:31 +02:00
Emanuele Trabattoni
b75014854d Working trigger + Spark recognition!!! 2026-03-27 17:53:05 +01:00
Emanuele Trabattoni
a210d808da First Test env 2026-03-27 12:49:20 +01:00
Emanuele Trabattoni
a0710f7ee7 Pins and devices refactoring in progress 2026-03-26 18:22:22 +01:00
Emanuele Trabattoni
68ed8a2282 Fixed spark timing compute 2026-03-26 14:09:55 +01:00
Emanuele Trabattoni
b573f64a39 Added datasheets 2026-03-25 20:17:45 +01:00
51 changed files with 2991 additions and 499 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 141 KiB

BIN
Datasheet/PCA9555.pdf Normal file

Binary file not shown.

BIN
Datasheet/ad5291_5292.pdf Normal file

Binary file not shown.

BIN
Datasheet/ads1255.pdf Normal file

Binary file not shown.

View File

Before

Width:  |  Height:  |  Size: 193 KiB

After

Width:  |  Height:  |  Size: 193 KiB

View File

@@ -3,3 +3,4 @@
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
unpacked_fs

View File

@@ -1,7 +1,7 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"Jason2866.esp-decoder",
"pioarduino.pioarduino-ide",
"platformio.platformio-ide"
],
"unwantedRecommendations": [

View File

@@ -11,8 +11,8 @@
"-DARDUINO_RUNNING_CORE=1",
"-DARDUINO_EVENT_RUNNING_CORE=1",
"-DBOARD_HAS_PSRAM",
"-DARDUINO_USB_MODE=1",
"-DARDUINO_USB_CDC_ON_BOOT=0"
"-DARDUINO_USB_MODE=0",
"-DARDUINO_USB_CDC_ON_BOOT=1"
],
"f_cpu": "240000000L",
"f_flash": "80000000L",

View File

@@ -0,0 +1,3 @@
{
}

View File

@@ -0,0 +1,106 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Astro Rotax Monitor</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header class="page-header">
<div class="header-content">
<img src="logo_astro_dev.svg" alt="Astro Tecnologie" class="logo">
</div>
<div>
<h1>Rotax Ignition Box Monitor</h1>
</div>
</header>
<div id="loadingIndicator" class="loading-indicator">
<span class="spinner"></span> Waiting for data...
</div>
<div style="max-width: 900px; margin: 0 auto; text-align: left;">
<p><strong>Timestamp:</strong> <span id="timestamp">-</span></p>
<p><strong>Data Valid:</strong> <span id="datavalid">-</span></p>
<p><strong>Generator voltage:</strong> <span id="volts_gen">-</span></p>
<p><strong>Engine RPM:</strong> <span id="eng_rpm">-</span></p>
<p><strong>ADC read time:</strong> <span id="adc_read_time">-</span></p>
<p><strong>Queue errors:</strong> <span id="n_queue_errors">-</span></p>
<table>
<thead>
<tr>
<th>Property</th>
<th>Pickup 12</th>
<th>Pickup 34</th>
</tr>
</thead>
<tbody>
<tr>
<td>Spark delay</td>
<td id="coils12_spark_delay">-</td>
<td id="coils34_spark_delay">-</td>
</tr>
<tr>
<td>Spark status</td>
<td id="coils12_spark_status">-</td>
<td id="coils34_spark_status">-</td>
</tr>
<tr>
<td>Soft start status</td>
<td id="coils12_sstart_status">-</td>
<td id="coils34_sstart_status">-</td>
</tr>
<tr>
<td>Peak P in</td>
<td id="coils12_peak_p_in">-</td>
<td id="coils34_peak_p_in">-</td>
</tr>
<tr>
<td>Peak N in</td>
<td id="coils12_peak_n_in">-</td>
<td id="coils34_peak_n_in">-</td>
</tr>
<tr>
<td>Peak P out</td>
<td id="coils12_peak_p_out">-</td>
<td id="coils34_peak_p_out">-</td>
</tr>
<tr>
<td>Peak N out</td>
<td id="coils12_peak_n_out">-</td>
<td id="coils34_peak_n_out">-</td>
</tr>
<tr>
<td>Level spark</td>
<td id="coils12_level_spark">-</td>
<td id="coils34_level_spark">-</td>
</tr>
<tr>
<td>Spark Events</td>
<td id="coils12_n_events">-</td>
<td id="coils34_n_events">-</td>
</tr>
<tr>
<td>Missed Events</td>
<td id="coils12_n_missed_firing">-</td>
<td id="coils34_n_missed_firing">-</td>
</tr>
</tbody>
</table>
</div>
<div class="upload-section">
<h3>Upload file to Flash</h3>
<p>Select a file and upload it to Flash.</p>
<input type="file" id="littlefsFile">
<button onclick="uploadLittleFS()">Upload</button>
<div id="uploadStatus" class="upload-status">No file uploaded yet.</div>
</div>
<script src="script.js"></script>
</body>
</html>

View File

@@ -0,0 +1,306 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 26.0.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="e_astro_logo_negativo" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
x="0px" y="0px" viewBox="0 0 374 56" style="enable-background:new 0 0 374 56;" xml:space="preserve">
<style type="text/css">
.st0{fill:#FFFFFF;}
</style>
<g>
<polygon class="st0" points="53.9,46 59.2,46 59.2,44.8 55.3,44.8 55.3,42.4 59,42.4 59,41.2 55.3,41.2 55.3,38.8 59.2,38.8
59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1.9C94,40.5,93.6,40.1,93.1,39.9z M93,44c-0.1,0.3-0.3,0.6-0.6,0.7
c-0.3,0.2-0.5,0.2-0.9,0.2c-0.5,0-0.9-0.2-1.2-0.5C90.1,44,90,43.5,90,42.9c0-0.5,0.1-0.9,0.2-1.2c0.1-0.3,0.3-0.6,0.6-0.7
c0.3-0.2,0.5-0.2,0.9-0.2c0.5,0,0.9,0.2,1.2,0.5c0.3,0.4,0.4,0.9,0.4,1.6C93.2,43.3,93.2,43.7,93,44z"/>
<path class="st0" d="M101.2,39.9c-0.4-0.2-0.8-0.3-1.3-0.3c-0.5,0-1,0.1-1.3,0.4c-0.3,0.2-0.5,0.5-0.7,0.9l-0.2-1.1h-1.2V46h1.4
v-2.9c0-0.5,0.1-0.9,0.2-1.3c0.1-0.4,0.3-0.6,0.6-0.8c0.2-0.2,0.5-0.3,0.9-0.3c0.4,0,0.7,0.1,1,0.4c0.2,0.3,0.4,0.6,0.4,1.2V46h1.4
v-3.7c0-0.6-0.1-1.1-0.3-1.5C101.8,40.4,101.5,40.1,101.2,39.9z"/>
<rect x="104.7" y="39.7" class="st0" width="1.4" height="6.3"/>
<path class="st0" d="M105.4,36.8c-0.3,0-0.5,0.1-0.6,0.2c-0.2,0.1-0.2,0.3-0.2,0.6c0,0.3,0.1,0.5,0.2,0.6c0.2,0.1,0.4,0.2,0.6,0.2
c0.3,0,0.5-0.1,0.6-0.2c0.2-0.1,0.2-0.4,0.2-0.6c0-0.2-0.1-0.4-0.2-0.6C105.9,36.9,105.6,36.8,105.4,36.8z"/>
<path class="st0" d="M110.3,41c0.2-0.1,0.5-0.2,0.7-0.2c0.3,0,0.6,0.1,0.8,0.3c0.2,0.2,0.4,0.4,0.4,0.7l1.4-0.1
c0-0.3-0.1-0.5-0.3-0.8c-0.1-0.3-0.3-0.5-0.5-0.7c-0.2-0.2-0.5-0.4-0.8-0.5c-0.3-0.1-0.7-0.2-1.1-0.2c-0.5,0-1,0.1-1.5,0.4
c-0.5,0.3-0.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.3,40.2,223,39.9,222.6,39.8z M222.5,43.7c0,0.2-0.1,0.4-0.2,0.7
c-0.1,0.2-0.3,0.4-0.5,0.5c-0.2,0.1-0.5,0.2-0.8,0.2c-0.4,0-0.8-0.1-1-0.3c-0.2-0.2-0.3-0.4-0.3-0.7c0-0.3,0.1-0.6,0.4-0.7
c0.2-0.1,0.6-0.2,0.9-0.2c0.3,0,0.5,0,0.8,0.1c0.2,0,0.5,0.1,0.7,0.2V43.7z"/>
<rect x="226.2" y="37.1" class="st0" width="1.4" height="8.9"/>
<polygon class="st0" points="233.3,46 238.7,46 238.7,44.8 234.7,44.8 234.7,42.4 238.4,42.4 238.4,41.2 234.7,41.2 234.7,38.8
238.7,38.8 238.7,37.6 233.3,37.6 "/>
<path class="st0" d="M246.4,47.6c-0.1-0.2-0.1-0.4-0.1-0.6v-7.3h-0.9l-0.3,1c-0.2-0.4-0.5-0.7-0.8-0.9c-0.3-0.2-0.7-0.3-1.1-0.3
c-0.5,0-1,0.1-1.4,0.4c-0.4,0.3-0.8,0.6-1.1,1.1c-0.3,0.5-0.4,1.1-0.4,1.8c0,0.7,0.1,1.3,0.4,1.8c0.3,0.5,0.6,0.9,1.1,1.1
c0.4,0.3,0.9,0.4,1.4,0.4c0.5,0,0.8-0.1,1.1-0.3c0.2-0.2,0.4-0.4,0.5-0.8v1.8c0,0.7,0.1,1.2,0.4,1.5c0.3,0.4,0.8,0.6,1.4,0.8l0.4-1
c-0.2-0.1-0.4-0.2-0.5-0.2C246.5,47.9,246.4,47.8,246.4,47.6z M244.9,43.4c0,0.3-0.1,0.6-0.2,0.8c-0.1,0.2-0.3,0.4-0.6,0.5
c-0.2,0.1-0.5,0.2-0.7,0.2c-0.3,0-0.5-0.1-0.8-0.2c-0.3-0.2-0.5-0.4-0.6-0.7c-0.2-0.3-0.3-0.7-0.3-1.2c0-0.4,0.1-0.8,0.2-1.1
c0.1-0.3,0.3-0.6,0.6-0.7c0.3-0.2,0.5-0.2,0.9-0.2c0.3,0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0.2,0.2-0.5,0.2-0.8,0.2c-0.3,0-0.6-0.1-0.9-0.3c-0.2-0.2-0.4-0.4-0.5-0.7c-0.1-0.3-0.2-0.6-0.2-1h4.2
C286.3,42.6,286.2,42.2,286.2,41.8z M282,42.3c0-0.3,0.1-0.5,0.2-0.8c0.1-0.3,0.3-0.5,0.5-0.7c0.2-0.2,0.5-0.3,0.9-0.3
c0.3,0,0.5,0.1,0.7,0.2c0.2,0.1,0.3,0.3,0.4,0.4c0.1,0.2,0.2,0.4,0.2,0.6c0,0.2,0,0.3,0,0.5H282z"/>
<path class="st0" d="M292.8,39.9c-0.3-0.2-0.8-0.3-1.3-0.3c-0.5,0-1,0.1-1.3,0.4c-0.3,0.2-0.5,0.5-0.7,0.9l-0.2-1.1h-1.2V46h1.4
v-2.9c0-0.5,0.1-0.9,0.2-1.3c0.1-0.4,0.3-0.6,0.6-0.8c0.2-0.2,0.5-0.3,0.9-0.3c0.4,0,0.7,0.1,1,0.4c0.2,0.3,0.4,0.6,0.4,1.2V46h1.4
v-3.7c0-0.6-0.1-1.1-0.3-1.5C293.4,40.4,293.2,40.1,292.8,39.9z"/>
<path class="st0" d="M298.9,45c-0.2,0-0.3,0.1-0.5,0.1c-0.5,0-0.8-0.3-0.8-0.8v-3.6h1.8v-0.9h-1.8V38h-1.4v1.7h-0.9v0.9h0.9v3.7
c0,0.4,0.1,0.8,0.3,1.1c0.2,0.3,0.4,0.5,0.7,0.6c0.3,0.1,0.6,0.2,1,0.2c0.2,0,0.5,0,0.7-0.1c0.2-0.1,0.5-0.1,0.7-0.2l-0.2-1
C299.3,44.9,299.1,45,298.9,45z"/>
<path class="st0" d="M58.3,21.7H65l1.3,4h3.1L63.5,8.1h-3.6l-6,17.5H57L58.3,21.7z M61.7,11.6l2.6,7.9h-5.2L61.7,11.6z"/>
<path class="st0" d="M80.4,23.1c-0.5,0.2-1.2,0.3-1.9,0.3c-0.7,0-1.3-0.1-1.9-0.3c-0.6-0.2-1.1-0.6-1.4-1c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,2.8-3c0.7-1.4,1-3.1,1-5.1
c0-2-0.3-3.7-1-5c-0.7-1.3-1.6-2.4-2.8-3c-1.2-0.7-2.5-1-4.1-1c-1.5,0-2.9,0.3-4.1,1c-1.2,0.7-2.1,1.7-2.8,3s-1,3-1,5.1
c0,2,0.3,3.7,1,5.1C121.6,23.3,122.5,24.3,123.7,25z M124.2,12.1c0.9-1.1,2-1.7,3.5-1.7c1.5,0,2.7,0.6,3.5,1.7s1.3,2.7,1.3,4.8
c0,2.1-0.4,3.7-1.3,4.8c-0.9,1.1-2.1,1.7-3.5,1.7c-1.5,0-2.6-0.6-3.5-1.7c-0.9-1.1-1.3-2.7-1.3-4.8
C122.9,14.8,123.4,13.2,124.2,12.1z"/>
<polygon class="st0" points="149.4,25.6 152.3,25.6 152.3,10.6 157.8,10.6 157.8,8.1 143.9,8.1 143.9,10.6 149.4,10.6 "/>
<polygon class="st0" points="171.6,23.1 163.4,23.1 163.4,18.1 171.1,18.1 171.1,15.6 163.4,15.6 163.4,10.6 171.6,10.6 171.6,8.1
160.5,8.1 160.5,25.6 171.6,25.6 "/>
<path class="st0" d="M178.6,24.9c1.1,0.7,2.5,1.1,4,1.1c1.4,0,2.7-0.2,3.7-0.7c1-0.5,1.8-1.2,2.4-2.1c0.6-0.9,0.8-2,0.8-3.3h-3.1
c0,1-0.3,1.8-1,2.5c-0.7,0.6-1.6,1-2.8,1c-1,0-1.8-0.3-2.4-0.8c-0.7-0.5-1.2-1.3-1.5-2.3c-0.3-1-0.5-2.1-0.5-3.4
c0-1.4,0.2-2.6,0.6-3.6c0.4-1,0.9-1.7,1.6-2.1c0.7-0.5,1.4-0.7,2.2-0.7c0.9,0,1.7,0.3,2.4,0.9c0.7,0.6,1.1,1.4,1.5,2.3l3.1-0.6
c-0.4-1.6-1.1-2.8-2.2-3.8c-1.1-1-2.7-1.5-4.7-1.5c-1.5,0-2.8,0.3-3.9,1c-1.1,0.7-2,1.7-2.7,3c-0.7,1.3-1,3-1,5
c0,1.9,0.3,3.5,0.9,4.9C176.6,23.1,177.5,24.1,178.6,24.9z"/>
<polygon class="st0" points="196.3,12.7 204.5,25.6 207.5,25.6 207.5,8.1 204.6,8.1 204.6,20.8 196.6,8.1 193.4,8.1 193.4,25.6
196.3,25.6 "/>
<path class="st0" d="M215.2,25c1.2,0.7,2.5,1,4.1,1c1.5,0,2.9-0.3,4.1-1c1.2-0.7,2.1-1.7,2.8-3c0.7-1.4,1-3.1,1-5.1
c0-2-0.3-3.7-1-5c-0.7-1.3-1.6-2.4-2.8-3c-1.2-0.7-2.5-1-4.1-1c-1.5,0-2.9,0.3-4.1,1c-1.2,0.7-2.1,1.7-2.8,3c-0.7,1.3-1,3-1,5.1
c0,2,0.3,3.7,1,5.1C213.1,23.3,214,24.3,215.2,25z M215.7,12.1c0.9-1.1,2-1.7,3.5-1.7c1.5,0,2.7,0.6,3.5,1.7
c0.9,1.1,1.3,2.7,1.3,4.8c0,2.1-0.4,3.7-1.3,4.8c-0.9,1.1-2.1,1.7-3.5,1.7c-1.5,0-2.6-0.6-3.5-1.7c-0.9-1.1-1.3-2.7-1.3-4.8
C214.4,14.8,214.9,13.2,215.7,12.1z"/>
<polygon class="st0" points="241.3,23.1 233.9,23.1 233.9,8.1 231,8.1 231,25.6 241.3,25.6 "/>
<path class="st0" d="M246.8,25c1.2,0.7,2.5,1,4.1,1c1.5,0,2.9-0.3,4.1-1c1.2-0.7,2.1-1.7,2.8-3c0.7-1.4,1-3.1,1-5.1
c0-2-0.3-3.7-1-5c-0.7-1.3-1.6-2.4-2.8-3c-1.2-0.7-2.5-1-4.1-1c-1.5,0-2.9,0.3-4.1,1c-1.2,0.7-2.1,1.7-2.8,3c-0.7,1.3-1,3-1,5.1
c0,2,0.3,3.7,1,5.1C244.7,23.3,245.6,24.3,246.8,25z M247.3,12.1c0.9-1.1,2-1.7,3.5-1.7c1.5,0,2.7,0.6,3.5,1.7
c0.9,1.1,1.3,2.7,1.3,4.8c0,2.1-0.4,3.7-1.3,4.8c-0.9,1.1-2.1,1.7-3.5,1.7c-1.5,0-2.6-0.6-3.5-1.7c-0.9-1.1-1.3-2.7-1.3-4.8
C246,14.8,246.4,13.2,247.3,12.1z"/>
<path class="st0" d="M265.1,24.9c1.2,0.7,2.4,1.1,3.8,1.1c1.2,0,2.1-0.3,2.9-0.9c0.7-0.6,1.2-1.4,1.6-2.4l0.3,2.9h2.4v-8.9h-6.9
v1.9l4.1,0.1v0.1c0,1-0.2,1.8-0.5,2.5c-0.4,0.7-0.8,1.2-1.5,1.5c-0.6,0.4-1.3,0.5-2.1,0.5c-0.9,0-1.8-0.3-2.5-0.8
c-0.7-0.5-1.3-1.3-1.7-2.2c-0.4-1-0.6-2.1-0.6-3.3c0-1.4,0.2-2.5,0.7-3.5c0.5-1,1.1-1.7,1.8-2.3c0.8-0.5,1.6-0.8,2.5-0.8
c0.8,0,1.5,0.2,2.1,0.6c0.6,0.4,1.2,1,1.7,1.7l2.9-0.7c-0.7-1.4-1.5-2.5-2.6-3.2c-1.1-0.7-2.4-1-4-1c-1.2,0-2.2,0.2-3.2,0.6
c-1,0.4-1.9,1-2.6,1.8c-0.8,0.8-1.3,1.8-1.8,2.9c-0.4,1.1-0.6,2.4-0.6,3.9c0,1.8,0.3,3.4,1,4.7C263,23.1,263.9,24.1,265.1,24.9z"/>
<rect x="280.8" y="8.1" class="st0" width="2.9" height="17.5"/>
<polygon class="st0" points="300,23.1 291.8,23.1 291.8,18.1 299.5,18.1 299.5,15.6 291.8,15.6 291.8,10.6 300,10.6 300,8.1
288.9,8.1 288.9,25.6 300,25.6 "/>
<path class="st0" d="M40.6,6.7H0v40.6h40.6V32.2H300v-1.2H40.6V6.7z M7.9,36.7H3.3c-0.4,0-0.7-0.3-0.7-0.7c0-0.4,0.3-0.7,0.7-0.7
h4.7c0.4,0,0.7,0.3,0.7,0.7C8.7,36.4,8.3,36.7,7.9,36.7z M7.9,32.2H3.3c-0.4,0-0.7-0.3-0.7-0.7c0-0.4,0.3-0.7,0.7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0.2,0.2,0.3,0.4,0.3,0.7c0,0.5-0.3,0.8-0.8,1.1l-1.1,0.4c-0.2,0.1-0.4,0.2-0.5,0.3
c-0.5,0.3-0.7,0.8-0.7,1.4v0.8h3.8V55h-3.1v-0.3C356.8,54.5,356.9,54.4,357,54.2z"/>
<rect x="350.4" y="41" class="st0" width="1" height="5.5"/>
<polygon class="st0" points="342.8,46.5 342.8,41 341.8,41 341.8,44.9 339.4,41 338.3,41 338.3,46.5 339.3,46.5 339.3,42.5
341.8,46.5 "/>
<polygon class="st0" points="348.9,46.5 348.9,41 347.9,41 347.9,44.9 345.4,41 344.4,41 344.4,46.5 345.4,46.5 345.4,42.5
347.9,46.5 "/>
<path class="st0" d="M336.3,46.5h1.1l-1.8-5.5h-1.3l-1.9,5.5h1.1l0.4-1.2h2L336.3,46.5z M334.1,44.6l0.8-2.4l0.8,2.4H334.1z"/>
<path class="st0" d="M373.5,33.6c-0.1-0.1-0.2-0.2-0.3-0.3c-0.1-0.1-0.2-0.2-0.3-0.4c-0.1-0.1-0.3-0.3-0.4-0.4c0,0-0.1-0.1-0.1-0.1
c0,0-0.1-0.1-0.1-0.1c-0.1-0.1-0.2-0.2-0.2-0.2c-0.1-0.1-0.2-0.2-0.3-0.2c0,0-0.1-0.1-0.1-0.1c0,0-0.1-0.1-0.1-0.1
c-0.2-0.2-0.4-0.3-0.6-0.5c-0.2-0.2-0.5-0.4-0.7-0.6c-0.1-0.1-0.2-0.2-0.4-0.3c-0.1,0-0.1-0.1-0.2-0.1c-0.1,0-0.1-0.1-0.2-0.1
c-1.1-0.8-2.4-1.5-3.9-2.2c-0.2-0.1-0.4-0.2-0.6-0.3c-0.1,0-0.2-0.1-0.3-0.1c-0.1,0-0.2-0.1-0.3-0.1c-0.2-0.1-0.4-0.2-0.6-0.2
c-0.2-0.1-0.4-0.1-0.6-0.2c-0.1,0-0.2-0.1-0.3-0.1c-0.1,0-0.2-0.1-0.3-0.1c-0.2-0.1-0.4-0.1-0.7-0.2l-0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.9,0-1.7-0.2-2.4-0.7c-0.7-0.5-1.3-1.1-1.7-2h-5.7c0.5,2.4,1.7,4.3,3.5,5.7c0.2,0.1,0.3,0.2,0.5,0.4
c0,0,0,0,0,0c-0.2,0.1-0.3,0.1-0.5,0.2c0,0,0,0,0,0h-9.6L335.8,24.8z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 31 KiB

125
RotaxMonitor/data/script.js Normal file
View File

@@ -0,0 +1,125 @@
let ws;
let lastMessageTimestamp = 0;
const IDLE_THRESHOLD_MS = 1000;
const loadingIndicator = document.getElementById("loadingIndicator");
function setLoadingIndicator(visible) {
if (!loadingIndicator) {
return;
}
loadingIndicator.classList.toggle("hidden", !visible);
}
function updateLoadingState() {
const isConnected = ws && ws.readyState === WebSocket.OPEN;
const idle = Date.now() - lastMessageTimestamp >= IDLE_THRESHOLD_MS;
setLoadingIndicator(isConnected && idle);
}
function connectWS() {
ws = new WebSocket("ws://" + location.host + "/ws");
ws.onopen = () => {
console.log("WebSocket connesso");
lastMessageTimestamp = Date.now();
setLoadingIndicator(false);
};
ws.onclose = () => {
console.log("WebSocket disconnesso, retry...");
setLoadingIndicator(false);
setTimeout(connectWS, 5000);
};
ws.onmessage = (event) => {
let data;
try {
data = JSON.parse(event.data);
} catch (e) {
console.error("Invalid JSON received", e);
return;
}
lastMessageTimestamp = Date.now();
setLoadingIndicator(false);
document.getElementById("datavalid").textContent = data.datavalid ?? "-";
document.getElementById("timestamp").textContent = data.timestamp ?? "-";
document.getElementById("volts_gen").textContent = data.volts_gen ?? "-";
document.getElementById("eng_rpm").textContent = data.eng_rpm ?? "-";
document.getElementById("adc_read_time").textContent = data.adc_read_time ?? "-";
document.getElementById("n_queue_errors").textContent = data.n_queue_errors ?? "-";
const coils12 = data.coils12 || {};
const coils34 = data.coils34 || {};
document.getElementById("coils12_spark_delay").textContent = coils12.spark_delay ?? "-";
document.getElementById("coils34_spark_delay").textContent = coils34.spark_delay ?? "-";
document.getElementById("coils12_spark_status").textContent = coils12.spark_status ?? "-";
document.getElementById("coils34_spark_status").textContent = coils34.spark_status ?? "-";
document.getElementById("coils12_sstart_status").textContent = coils12.sstart_status ?? "-";
document.getElementById("coils34_sstart_status").textContent = coils34.sstart_status ?? "-";
document.getElementById("coils12_peak_p_in").textContent = coils12.peak_p_in ?? "-";
document.getElementById("coils34_peak_p_in").textContent = coils34.peak_p_in ?? "-";
document.getElementById("coils12_peak_n_in").textContent = coils12.peak_n_in ?? "-";
document.getElementById("coils34_peak_n_in").textContent = coils34.peak_n_in ?? "-";
document.getElementById("coils12_peak_p_out").textContent = coils12.peak_p_out ?? "-";
document.getElementById("coils34_peak_p_out").textContent = coils34.peak_p_out ?? "-";
document.getElementById("coils12_peak_n_out").textContent = coils12.peak_n_out ?? "-";
document.getElementById("coils34_peak_n_out").textContent = coils34.peak_n_out ?? "-";
document.getElementById("coils12_level_spark").textContent = coils12.level_spark ?? "-";
document.getElementById("coils34_level_spark").textContent = coils34.level_spark ?? "-";
document.getElementById("coils12_n_events").textContent = coils12.n_events ?? "-";
document.getElementById("coils34_n_events").textContent = coils34.n_events ?? "-";
document.getElementById("coils12_n_missed_firing").textContent = coils12.n_missed_firing ?? "-";
document.getElementById("coils34_n_missed_firing").textContent = coils34.n_missed_firing ?? "-";
};
}
function start() {
fetch("/start");
}
function stop() {
fetch("/stop");
}
function uploadLittleFS() {
const fileInput = document.getElementById("littlefsFile");
const status = document.getElementById("uploadStatus");
if (!fileInput || fileInput.files.length === 0) {
if (status) status.textContent = "Select a file first.";
return;
}
const file = fileInput.files[0];
const formData = new FormData();
formData.append("file", file, file.name);
if (status) status.textContent = "Uploading...";
fetch("/upload", {
method: "POST",
body: formData,
})
.then((resp) => {
if (!resp.ok) {
throw new Error("Upload failed: " + resp.status + " " + resp.statusText);
}
return resp.text();
})
.then(() => {
if (status) status.textContent = "Uploaded: " + file.name;
fileInput.value = "";
})
.catch((err) => {
if (status) status.textContent = err.message;
});
}
setInterval(updateLoadingState, 200);
connectWS();

182
RotaxMonitor/data/style.css Normal file
View File

@@ -0,0 +1,182 @@
:root {
--primary-dark: #0a1929;
--primary-blue: #003585;
--accent-blue: #1e88e5;
--light-bg: #f5f7fa;
--border-color: #d0d6dd;
--text-dark: #1a1a1a;
--text-muted: #666666;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
margin: 0;
padding: 0;
background-color: var(--light-bg);
color: var(--text-dark);
}
.page-header {
background: linear-gradient(135deg, var(--primary-dark) 0%, #1a3a52 100%);
color: white;
padding: 30px 20px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
margin-bottom: 30px;
}
.header-content {
max-width: 900px;
margin: 0 auto;
display: flex;
align-items: center;
gap: 20px;
}
.logo {
height: 50px;
width: auto;
}
.page-header h1 {
margin: 5px;
font-size: 28px;
font-weight: 600;
}
table {
margin: auto;
border-collapse: collapse;
width: 100%;
max-width: 900px;
background: white;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
border-radius: 6px;
overflow: hidden;
}
th, td {
border: 1px solid var(--border-color);
padding: 12px;
font-size: 14px;
text-align: center;
}
th {
background-color: var(--primary-blue);
color: white;
font-weight: 600;
}
tr:hover {
background-color: #f9fbfc;
}
button {
margin: 10px;
padding: 10px 20px;
font-size: 16px;
background-color: var(--primary-blue);
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
transition: background-color 0.2s;
}
button:hover {
background-color: var(--accent-blue);
}
.upload-section {
margin: 30px auto 20px;
max-width: 900px;
text-align: left;
padding: 20px;
border: 1px solid var(--border-color);
border-radius: 6px;
background: white;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
.upload-section h3 {
margin-top: 0;
margin-bottom: 8px;
color: var(--primary-blue);
font-size: 16px;
}
.upload-section p {
margin: 8px 0;
color: var(--text-muted);
font-size: 14px;
}
.upload-section input[type="file"] {
margin-top: 8px;
margin-bottom: 12px;
}
.upload-status {
margin-top: 10px;
font-size: 14px;
color: var(--text-muted);
}
.loading-indicator {
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
margin: 0;
padding: 16px 20px;
font-size: 20px;
color: var(--primary-blue);
border-bottom: 1px solid var(--border-color);
background: white;
width: 100%;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
.loading-indicator.hidden {
display: none;
}
.spinner {
width: 16px;
height: 16px;
border: 2px solid transparent;
border-top-color: var(--primary-blue);
border-radius: 50%;
animation: spin 0.8s linear infinite;
}
@keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
/* Data section */
div[style*="max-width: 900px"] {
background: white;
padding: 20px;
border-radius: 6px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
margin-bottom: 20px;
}
div[style*="max-width: 900px"] p {
margin: 8px 0;
font-size: 14px;
}
div[style*="max-width: 900px"] strong {
color: var(--primary-blue);
}
span {
color: var(--text-dark);
}

View File

@@ -120,14 +120,14 @@ void ADS1256::setDRATE(uint8_t drate) //Setting DRATE (sampling frequency)
{
writeRegister(DRATE_REG, drate);
_DRATE = drate;
delay(200);
delayMicroseconds(500);
}
void ADS1256::setMUX(uint8_t mux) //Setting MUX (input channel)
{
writeRegister(MUX_REG, mux);
_MUX = mux;
delay(200);
//delayMicroseconds(500);
}
void ADS1256::setPGA(uint8_t pga) //Setting PGA (input voltage range)
@@ -138,7 +138,7 @@ void ADS1256::setPGA(uint8_t pga) //Setting PGA (input voltage range)
_ADCON = (_ADCON & 0b11111000) | (_PGA & 0b00000111); // Clearing and then setting bits 2-0 based on pga
writeRegister(ADCON_REG, _ADCON);
delay(200);
delayMicroseconds(1000); //Delay to allow the PGA to settle after changing its value
updateConversionParameter(); //Update the multiplier according top the new PGA value
}
@@ -501,8 +501,6 @@ void ADS1256::writeRegister(uint8_t registerAddress, uint8_t registerValueToWrit
CS_HIGH();
_spi->endTransaction();
delay(100);
}
long ADS1256::readRegister(uint8_t registerAddress) //Reading a register
@@ -524,7 +522,7 @@ long ADS1256::readRegister(uint8_t registerAddress) //Reading a register
CS_HIGH();
_spi->endTransaction();
delay(100);
return regValue;
}

View File

@@ -1,6 +0,0 @@
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 0x5000,
otadata, data, ota, 0xe000, 0x2000,
app0, app, ota_0, 0x10000, 0x700000,
app1, app, ota_1, 0x710000,0x700000,
spiffs, data, spiffs, 0xE10000,0x1F0000,
1 # Name Type SubType Offset Size Flags
2 nvs data nvs 0x9000 0x5000
3 otadata data ota 0xe000 0x2000
4 app0 app ota_0 0x10000 0x700000
5 app1 app ota_1 0x710000 0x700000
6 spiffs data spiffs 0xE10000 0x1F0000

View File

@@ -0,0 +1,6 @@
# ESP32 Partition Table
# Name, Type, SubType, Offset, Size
nvs, data, nvs, 0x9000, 0x4000
phy_init, data, phy, 0xd000, 0x1000
factory, app, factory, 0x10000, 0x300000
littlefs, data, littlefs, 0x310000, 0xCF0000
1 # ESP32 Partition Table
2 # Name, Type, SubType, Offset, Size
3 nvs, data, nvs, 0x9000, 0x4000
4 phy_init, data, phy, 0xd000, 0x1000
5 factory, app, factory, 0x10000, 0x300000
6 littlefs, data, littlefs, 0x310000, 0xCF0000

View File

@@ -0,0 +1,6 @@
# ESP32 Partition Table
# Name, Type, SubType, Offset, Size
nvs, data, nvs, 0x9000, 0x4000
phy_init, data, phy, 0xd000, 0x1000
factory, app, factory, 0x10000, 0x300000
spiffs, data, spiffs, 0x310000, 0xCF0000
1 # ESP32 Partition Table
2 # Name, Type, SubType, Offset, Size
3 nvs, data, nvs, 0x9000, 0x4000
4 phy_init, data, phy, 0xd000, 0x1000
5 factory, app, factory, 0x10000, 0x300000
6 spiffs, data, spiffs, 0x310000, 0xCF0000

View File

@@ -8,39 +8,65 @@
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:esp32-s3-n16r8]
platform = https://github.com/pioarduino/platform-espressif32/releases/download/55.03.37/platform-espressif32.zip
board = esp32-s3-n16r8
[env:esp32-s3-devkitc1-n16r8]
board = esp32-s3-devkitc1-n16r8
board_build.partitions = partitions/no_ota_10mb_littlefs.csv
board_build.filesystem = littlefs
platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip
framework = arduino
lib_deps =
hideakitai/DebugLog@^0.8.4
bblanchon/ArduinoJson@^7.4.2
hideakitai/PCA95x5@^0.1.3
adafruit/Adafruit SSD1306@^2.5.16
board_build.partitions = partitions/default_16MB.csv
board_build.psram = enabled
monitor_speed = 115200
me-no-dev/AsyncTCP@^3.3.2
me-no-dev/ESPAsyncWebServer@^3.6.0
upload_protocol = esptool
upload_port = COM8
upload_speed = 921600
monitor_port = COM4
monitor_speed = 921600
build_type = release
build_flags =
-DCORE_DEBUG_LEVEL=1
-DARDUINO_USB_CDC_ON_BOOT=0
-DARDUINO_USB_MODE=0
-DCONFIG_FREERTOS_GENERATE_RUN_TIME_STATS=1
-DCONFIG_FREERTOS_USE_TRACE_FACILITY=1
-DCONFIG_ASYNC_TCP_MAX_ACK_TIME=5000
-DCONFIG_ASYNC_TCP_PRIORITY=20
-DCONFIG_ASYNC_TCP_QUEUE_SIZE=128
-DCONFIG_ASYNC_TCP_RUNNING_CORE=1
-DCONFIG_ASYNC_TCP_STACK_SIZE=8192
-fstack-protector-all
[env:esp32-s3-n16r8-debug]
platform = ${env:esp32-s3-n16r8.platform}
board = ${env:esp32-s3-n16r8.board}
framework = ${env:esp32-s3-n16r8.framework}
[env:esp32-s3-devkitc1-n16r8-debug]
board = ${env:esp32-s3-devkitc1-n16r8.board}
board_build.partitions = ${env:esp32-s3-devkitc1-n16r8.board_build.partitions}
board_build.filesystem = ${env:esp32-s3-devkitc1-n16r8.board_build.filesystem}
platform = ${env:esp32-s3-devkitc1-n16r8.platform}
framework = ${env:esp32-s3-devkitc1-n16r8.framework}
lib_deps =
${env:esp32-s3-n16r8.lib_deps}
hideakitai/PCA95x5@^0.1.3
adafruit/Adafruit SSD1306@^2.5.16
board_build.partitions = partitions/default_16MB.csv
board_build.psram = enabled
monitor_speed = 115200
${env:esp32-s3-devkitc1-n16r8.lib_deps}
upload_protocol = esptool
upload_port = COM8
upload_speed = 921600
monitor_port = COM4
monitor_speed = 921600
debug_tool = esp-builtin
debug_speed = 15000
build_type = debug
build_flags =
-O0
-g3
-ggdb
-fno-inline
-fno-ipa-sra
-fno-tree-sra
-fno-builtin
-ggdb3
-DCORE_DEBUG_LEVEL=3
-DARDUINO_USB_CDC_ON_BOOT=0
-DARDUINO_USB_MODE=0
-DCONFIG_FREERTOS_GENERATE_RUN_TIME_STATS=1
-DCONFIG_FREERTOS_USE_TRACE_FACILITY=1
-DCONFIG_ASYNC_TCP_MAX_ACK_TIME=5000
-DCONFIG_ASYNC_TCP_PRIORITY=20
-DCONFIG_ASYNC_TCP_QUEUE_SIZE=128
-DCONFIG_ASYNC_TCP_RUNNING_CORE=1
-DCONFIG_ASYNC_TCP_STACK_SIZE=8192
-fstack-protector-all

View File

@@ -1,11 +0,0 @@
// ADC Channels
#define A1_RAW 0
#define A2_RAW 1
#define B1_RAW 2
#define B2_RAW 3
#define A1_COND 4
#define A2_COND 5
#define B1_COND 6
#define B2_COND 7

View File

@@ -0,0 +1,221 @@
#include "datasave.h"
#include <math.h>
static const size_t min_free = 1024 * 1024; // minimum free space in LittleFS to allow saving history (1MB)
LITTLEFSGuard::LITTLEFSGuard()
{
if (!LittleFS.begin(true, "/littlefs", 10, "littlefs"))
{
LOG_ERROR("Failed to mount LittleFS");
}
else
{
LOG_INFO("LittleFS mounted successfully");
LOG_INFO("LittleFS Free KBytes:", (LittleFS.totalBytes() - LittleFS.usedBytes()) /1024);
}
}
LITTLEFSGuard::~LITTLEFSGuard()
{
LittleFS.end();
LOG_INFO("LittleFS unmounted successfully");
}
void ignitionBoxStatusAverage::filter(int32_t &old, const int32_t value, const uint32_t k)
{
float alpha = 1.0f / (float)k;
old = old + (int32_t)(alpha * (float)(value - old));
}
void ignitionBoxStatusAverage::filter(float &old, const float value, const uint32_t k)
{
float alpha = 1.0f / (float)k;
old = old + (float)(alpha * (float)(value - old));
}
void ignitionBoxStatusAverage::reset()
{
m_last = ignitionBoxStatus();
m_count = 0;
m_data_valid = false;
}
void ignitionBoxStatusAverage::update(const ignitionBoxStatus &new_status)
{
if (m_count == 0 && !m_data_valid)
{
m_last = new_status;
}
m_count++;
// simple moving average calculation
m_last.timestamp = new_status.timestamp; // keep timestamp of latest status
m_last.coils12.n_events = new_status.coils12.n_events; // sum events instead of averaging
m_last.coils12.n_missed_firing = new_status.coils12.n_missed_firing; // sum missed firings instead of averaging
m_last.coils12.spark_status = new_status.coils12.spark_status; // take latest spark status
m_last.coils12.sstart_status = new_status.coils12.sstart_status; // take latest soft start status
filter(m_last.coils12.spark_delay, new_status.coils12.spark_delay, m_max_count); // incremental average calculation
filter(m_last.coils12.peak_p_in, new_status.coils12.peak_p_in, m_max_count); // incremental average calculation
filter(m_last.coils12.peak_n_in, new_status.coils12.peak_n_in, m_max_count); // incremental average calculation
filter(m_last.coils12.peak_p_out, new_status.coils12.peak_p_out, m_max_count); // incremental average calculation
filter(m_last.coils12.peak_n_out, new_status.coils12.peak_n_out, m_max_count); // incremental average calculation
m_last.coils34.n_events = new_status.coils34.n_events; // sum events instead of averaging
m_last.coils34.n_missed_firing = new_status.coils34.n_missed_firing; // sum missed firings instead of averaging
m_last.coils34.spark_status = new_status.coils34.spark_status; // take latest spark status
m_last.coils34.sstart_status = new_status.coils34.sstart_status; // take latest soft start status
filter(m_last.coils34.spark_delay, new_status.coils34.spark_delay, m_max_count); // incremental average calculation
filter(m_last.coils34.peak_p_in, new_status.coils34.peak_p_in, m_max_count); // incremental average calculation
filter(m_last.coils34.peak_n_in, new_status.coils34.peak_n_in, m_max_count); // incremental average calculation
filter(m_last.coils34.peak_p_out, new_status.coils34.peak_p_out, m_max_count); // incremental average calculation
filter(m_last.coils34.peak_n_out, new_status.coils34.peak_n_out, m_max_count); // incremental average calculation
filter(m_last.eng_rpm, new_status.eng_rpm, m_max_count); // incremental average calculation // incremental average calculation
filter(m_last.adc_read_time, m_last.adc_read_time, m_max_count); // incremental average calculation
m_last.n_queue_errors = new_status.n_queue_errors; // take last of queue errors since it's a cumulative count of errors in the queue, not an average value
if (m_count >= m_max_count)
{
m_count = 0; // reset count after reaching max samples to average
m_data_valid = true; // set data valid flag after first average is calculated
}
}
const bool ignitionBoxStatusAverage::get(ignitionBoxStatus &status) const
{
if (m_data_valid)
{
status = m_last;
}
return m_data_valid;
}
const ArduinoJson::JsonDocument ignitionBoxStatusAverage::toJson() const
{
ArduinoJson::JsonDocument doc;
if (m_data_valid)
{
doc["timestamp"] = m_last.timestamp;
doc["datavalid"] = m_data_valid ? "TRUE" : "FALSE";
doc["coils12"]["n_events"] = m_last.coils12.n_events;
doc["coils12"]["n_missed_firing"] = m_last.coils12.n_missed_firing;
doc["coils12"]["spark_delay"] = m_last.coils12.spark_delay;
doc["coils12"]["spark_status"] = sparkStatusNames.at(m_last.coils12.spark_status);
doc["coils12"]["peak_p_in"] = m_last.coils12.peak_p_in;
doc["coils12"]["peak_n_in"] = m_last.coils12.peak_n_in;
doc["coils12"]["peak_p_out"] = m_last.coils12.peak_p_out;
doc["coils12"]["peak_n_out"] = m_last.coils12.peak_n_out;
doc["coils12"]["sstart_status"] = softStartStatusNames.at(m_last.coils12.sstart_status);
doc["coils34"]["n_events"] = m_last.coils34.n_events;
doc["coils34"]["n_missed_firing"] = m_last.coils34.n_missed_firing;
doc["coils34"]["spark_delay"] = m_last.coils34.spark_delay;
doc["coils34"]["spark_status"] = sparkStatusNames.at(m_last.coils34.spark_status);
doc["coils34"]["peak_p_in"] = m_last.coils34.peak_p_in;
doc["coils34"]["peak_n_in"] = m_last.coils34.peak_n_in;
doc["coils34"]["peak_p_out"] = m_last.coils34.peak_p_out;
doc["coils34"]["peak_n_out"] = m_last.coils34.peak_n_out;
doc["coils34"]["sstart_status"] = softStartStatusNames.at(m_last.coils34.sstart_status);
doc["eng_rpm"] = m_last.eng_rpm;
doc["adc_read_time"] = m_last.adc_read_time;
doc["n_queue_errors"] = m_last.n_queue_errors;
}
return doc;
}
void saveHistoryTask(void *pvParameters)
{
const auto *params = static_cast<dataSaveParams *>(pvParameters);
const auto &history = *params->history;
const auto &file_path = params->file_path;
if (!params)
{
LOG_ERROR("Invalid parameters for saveHistoryTask");
return;
}
LOG_DEBUG("Starting saving: ", file_path.c_str());
save_history(history, file_path);
vTaskDelete(NULL);
}
void save_history(const PSRAMVector<ignitionBoxStatus> &history, const std::filesystem::path &file_name)
{
// Initialize SPIFFS
if (!SAVE_HISTORY_TO_LITTLEFS)
return;
auto littlefs_guard = LITTLEFSGuard(); // use RAII guard to ensure LittleFS is properly mounted and unmounted
if (LittleFS.totalBytes() - LittleFS.usedBytes() < min_free) // check if at least 1MB is free for saving history
{
LOG_ERROR("Not enough space in SPIFFS to save history");
return;
}
std::filesystem::path file_path = file_name;
if (file_name.root_path() != "/littlefs")
file_path = std::filesystem::path("/littlefs") / file_name;
auto save_flags = std::ios::out;
if (first_save && LittleFS.exists(file_path.c_str()))
{
first_save = false;
save_flags |= std::ios::trunc; // overwrite existing file
LittleFS.remove(file_path.c_str()); // ensure file is removed before saving to avoid issues with appending to existing file in SPIFFS
LOG_INFO("Saving history to LittleFS, new file:", file_path.c_str());
}
else
{
save_flags |= std::ios::app; // append to new file
LOG_INFO("Saving history to LittleFS, appending to existing file:", file_path.c_str());
}
std::ofstream ofs(file_path, save_flags);
if (ofs.fail())
{
LOG_ERROR("Failed to open file for writing");
return;
}
// write csv header
if (first_save)
{
ofs << "TS,\
EVENTS_12,DLY_12,STAT_12,V_12_1,V_12_2,V_12_3,V_12_4,IGNITION_MODE_12,\
EVENTS_34,DLY_34,STAT_34,V_34_1,V_34_2,V_34_3,V_34_4,IGNITION_MODE_34,\
ENGINE_RPM,ADC_READTIME,N_QUEUE_ERRORS"
<< std::endl;
ofs.flush();
}
for (const auto &entry : history)
{
ofs << std::to_string(entry.timestamp) << ","
<< std::to_string(entry.coils12.n_events) << ","
<< std::to_string(entry.coils12.spark_delay) << ","
<< std::string(sparkStatusNames.at(entry.coils12.spark_status)) << ","
<< std::to_string(entry.coils12.peak_p_in) << ","
<< std::to_string(entry.coils12.peak_n_in) << ","
<< std::to_string(entry.coils12.peak_p_out) << ","
<< std::to_string(entry.coils12.peak_n_out) << ","
<< std::string(softStartStatusNames.at(entry.coils12.sstart_status)) << ","
<< std::to_string(entry.coils34.n_events) << ","
<< std::to_string(entry.coils34.spark_delay) << ","
<< std::string(sparkStatusNames.at(entry.coils34.spark_status)) << ","
<< std::to_string(entry.coils34.peak_p_in) << ","
<< std::to_string(entry.coils34.peak_n_in) << ","
<< std::to_string(entry.coils34.peak_p_out) << ","
<< std::to_string(entry.coils34.peak_n_out) << ","
<< std::string(softStartStatusNames.at(entry.coils34.sstart_status)) << ","
<< std::to_string(entry.eng_rpm) << ","
<< std::to_string(entry.adc_read_time) << ","
<< std::to_string(entry.n_queue_errors);
ofs << std::endl;
ofs.flush();
}
ofs.close();
LOG_INFO("Ignition A history saved to LittleFS, records written: ", history.size());
}

View File

@@ -0,0 +1,62 @@
#pragma once
#define DEBUGLOG_DEFAULT_LOG_LEVEL_INFO
// System Includes
#include <Arduino.h>
#include <DebugLog.h>
#include <string>
#include <fstream>
#include <ArduinoJson.h>
#include <filesystem>
#include <LittleFS.h>
// Project Includes
#include "isr.h"
#include "psvector.h"
const uint32_t max_history = 256;
const bool SAVE_HISTORY_TO_LITTLEFS = false; // Set to true to enable saving history to LittleFS, false to disable
static bool first_save = true; // flag to indicate if this is the first save (to write header)
struct dataSaveParams
{
const PSRAMVector<ignitionBoxStatus> *history;
const std::filesystem::path file_path;
};
class LITTLEFSGuard
{
public:
LITTLEFSGuard();
~LITTLEFSGuard();
};
class ignitionBoxStatusAverage
{
private:
ignitionBoxStatus m_last;
uint32_t m_count = 0;
uint32_t m_max_count = 100; // number of samples to average before resetting
bool m_data_valid = false; // flag to indicate if the average data is valid (i.e. at least one sample has been added)
public:
ignitionBoxStatusAverage() = default;
ignitionBoxStatusAverage(const uint32_t max_count) : m_max_count(max_count)
{
m_data_valid = false;
m_count = 0;
}
void reset();
void update(const ignitionBoxStatus &new_status);
const bool get(ignitionBoxStatus &status) const;
const ArduinoJson::JsonDocument toJson() const;
private:
void filter(int32_t &old, const int32_t value, const uint32_t k);
void filter(float &old, const float value, const uint32_t k);
};
// Task and function declarations
void saveHistoryTask(void *pvParameters);
void save_history(const PSRAMVector<ignitionBoxStatus> &history, const std::filesystem::path &file_path);

View File

@@ -0,0 +1,90 @@
#pragma once
#include <Arduino.h>
#include <map>
// =====================
// Event Flags (bitmask)
// =====================
static const uint32_t TRIG_FLAG_12P = (1 << 0);
static const uint32_t TRIG_FLAG_12N = (1 << 1);
static const uint32_t TRIG_FLAG_34P = (1 << 2);
static const uint32_t TRIG_FLAG_34N = (1 << 3);
static const uint32_t SPARK_FLAG_TIMEOUT = (1 << 8);
static const uint32_t SPARK_FLAG_12 = (1 << 9);
static const uint32_t SPARK_FLAG_34 = (1 << 10);
// Spark Status
enum sparkStatus
{
SPARK_POS_OK,
SPARK_NEG_OK,
SPARK_POS_SKIP,
SPARK_NEG_SKIP,
SPARK_POS_WAIT,
SPARK_NEG_WAIT,
SPARK_POS_FAIL,
SPARK_NEG_FAIL,
SPARK_POS_UNEXPECTED,
SPARK_NEG_UNEXPECTED,
SPARK_SYNC_FAIL,
};
static const std::map<const sparkStatus, const char *> sparkStatusNames = {
{SPARK_POS_OK, "SPARK_POS_OK"},
{SPARK_NEG_OK, "SPARK_NEG_OK"},
{SPARK_POS_SKIP, "SPARK_POS_SKIP"},
{SPARK_NEG_SKIP, "SPARK_NEG_SKIP"},
{SPARK_POS_WAIT, "SPARK_POS_WAIT"},
{SPARK_NEG_WAIT, "SPARK_NEG_WAIT"},
{SPARK_POS_FAIL, "SPARK_POS_FAIL"},
{SPARK_NEG_FAIL, "SPARK_NEG_FAIL"},
{SPARK_POS_UNEXPECTED, "SPARK_POS_UNEXPECTED"},
{SPARK_NEG_UNEXPECTED, "SPARK_NEG_UNEXPECTED"},
{SPARK_SYNC_FAIL, "SPARK_SYNC_FAIL"},
};
enum softStartStatus
{
NORMAL,
SOFT_START,
ERROR,
};
const std::map<const softStartStatus, const char *> softStartStatusNames = {
{NORMAL, "NORMAL"},
{SOFT_START, "SOFT_START"},
{ERROR, "ERROR"},
};
struct coilsStatus
{
int64_t trig_time = 0;
int64_t spark_time = 0;
int32_t spark_delay = 0; // in microseconds
sparkStatus spark_status = sparkStatus::SPARK_POS_OK;
softStartStatus sstart_status = softStartStatus::NORMAL;
float peak_p_in = 0.0;
float peak_n_in = 0.0;
float peak_p_out = 0.0;
float peak_n_out = 0.0;
float level_spark = 0.0;
uint32_t n_events = 0;
uint32_t n_missed_firing = 0;
};
// Task internal Status
struct ignitionBoxStatus
{
int64_t timestamp = 0;
// coils pairs for each ignition
coilsStatus coils12;
coilsStatus coils34;
// voltage from generator
float volts_gen = 0.0;
// enine rpm
int32_t eng_rpm = 0;
// debug values
uint32_t n_queue_errors = 0;
int32_t adc_read_time = 0;
};

View File

@@ -1,38 +1,37 @@
#pragma once
// Library defines
#define ADS1256_SPI_ALREADY_STARTED
// Device Libraries
#include <ADS1256.h>
#include <AD5292.h>
#include <Adafruit_SSD1306.h>
#include <PCA95x5.h>
// ADC Channel mapping
#define PICKUP_IN_A12 SING_0
#define PICKUP_IN_A34 SING_1
#define PICKUP_OUT_A12 SING_2
#define PICKUP_OUT_A34 SING_3
#define PICKUP_IN_B12 SING_4
#define PICKUP_IN_B34 SING_5
#define PICKUP_OUT_B12 SING_6
#define PICKUP_OUT_B34 SING_7
#define ADC_CH_PEAK_12P_IN SING_0
#define ADC_CH_PEAK_12N_IN SING_1
#define ADC_CH_PEAK_34P_IN SING_2
#define ADC_CH_PEAK_34N_IN SING_3
#define ADC_CH_PEAK_12P_OUT SING_4
#define ADC_CH_PEAK_12N_OUT SING_5
#define ADC_CH_PEAK_34P_OUT SING_6
#define ADC_CH_PEAK_34N_OUT SING_7
// Device Pointer structs for tasks
struct Devices {
AD5292* pot;
ADS1256* adc;
Adafruit_SSD1306* lcd;
PCA9555* io;
AD5292 *pot_a = NULL, *pot_b = NULL;
ADS1256 *adc_a = NULL, *adc_b = NULL;
PCA9555* io = NULL;
};
float adcReadChannel(ADS1256* adc, const uint32_t ch){
adc->setMUX(PICKUP_IN_A12);
// Adc read channel wrapper to selet mux before reading
inline float adcReadChannel(ADS1256* adc, const uint8_t ch){
adc->setMUX(ch);
// scarta 3 conversioni
for (int i = 0; i < 3; i++) {
while (digitalRead(ADC_DRDY));
adc->readSingle();
}
// ora lettura valida a 30kSPS → ~100 µs di settling
while (digitalRead(ADC_DRDY));
return adc->convertToVoltage(adc->readSingle());
}

53
RotaxMonitor/src/isr.cpp Normal file
View File

@@ -0,0 +1,53 @@
#include "isr.h"
// =====================
// ISR (Pass return bitmask to ISR management function)
// one function for each wake up pin conncted to a trigger
// =====================
void trig_isr(void *arg)
{
const int64_t time_us = esp_timer_get_time();
// exit if invalid args
if (!arg)
return;
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
isrParams *params = (isrParams *)arg;
ignitionBoxStatus *box = params->ign_stat;
TaskHandle_t task_handle = params->rt_handle_ptr;
// exit if task not running
if (!task_handle)
return;
switch (params->flag)
{
case TRIG_FLAG_12P:
case TRIG_FLAG_12N:
// only on first trigger to avoid multiple firing due to noise, to be fixed with hardware debounce
box->coils12.trig_time = time_us;
xTaskNotifyFromISR(task_handle, params->flag, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
break;
case TRIG_FLAG_34P:
case TRIG_FLAG_34N:
// only on first trigger to avoid multiple firing due to noise, to be fixed with hardware debounce
box->coils34.trig_time = time_us;
xTaskNotifyFromISR(task_handle, params->flag, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
break;
case SPARK_FLAG_12:
box->coils12.spark_time = time_us;
xTaskNotifyFromISR(task_handle, params->flag, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
break;
case SPARK_FLAG_34:
box->coils34.spark_time = time_us;
xTaskNotifyFromISR(task_handle, params->flag, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
break;
default:
break;
}
if (xHigherPriorityTaskWoken)
portYIELD_FROM_ISR();
}

View File

@@ -1,168 +1,29 @@
#pragma once
// Test device Flag
// #define TEST
// Arduino Libraries
#include <Arduino.h>
#include "soc/gpio_struct.h"
#include <map>
#ifndef TEST
#include "pins.h"
#else
#include "pins_test.h"
#endif
#include "datastruct.h"
#define CORE_0 0
#define CORE_1 1
#define TASK_STACK 4096 // in words
#define TASK_PRIORITY 2 // priorità leggermente più alta
#define CORE_0 0
#define CORE_1 1
#define RT_TASK_STACK 4096 // in words
#define RT_TASK_PRIORITY (configMAX_PRIORITIES - 4) // highest priority after wifi tasks
#define IGN_BUF_SIZE 128
// =====================
// Event Flags (bitmask)
// =====================
#define TRIG_FLAG_A12P (1 << 0)
#define TRIG_FLAG_A12N (1 << 2)
#define TRIG_FLAG_A34P (1 << 1)
#define TRIG_FLAG_A34N (1 << 3)
#define TRIG_FLAG_B12P (1 << 4)
#define TRIG_FLAG_B12N (1 << 6)
#define TRIG_FLAG_B34P (1 << 5)
#define TRIG_FLAG_B34N (1 << 7)
#define SPARK_FLAG_A12 (1 << 0)
#define SPARK_FLAG_A34 (1 << 2)
#define SPARK_FLAG_B12 (1 << 1)
#define SPARK_FLAG_B34 (1 << 3)
// Task handle
TaskHandle_t trigA_TaskHandle = NULL;
TaskHandle_t trigB_TaskHandle = NULL;
// Spark Status
enum sparkStatus {
SPARK_POS_OK,
SPARK_NEG_OK,
SPARK_POS_SKIP,
SPARK_NEG_SKIP,
SPARK_POS_WAIT,
SPARK_NEG_WAIT,
SPARK_POS_FAIL,
SPARK_NEG_FAIL,
SPARK_POS_UNEXPECTED,
SPARK_NEG_UNEXPECTED,
SPARK_SYNC_FAIL,
struct isrParams
{
const uint32_t flag;
ignitionBoxStatus *ign_stat;
TaskHandle_t rt_handle_ptr;
};
// Task internal Status
struct ignitionBoxStatus {
// start time from ISR
int64_t trig12_start;
int64_t trig34_start;
// time at which spark occours
int64_t trig12_end;
int64_t trig34_end;
// computed delay from pickup to spark
int64_t spark12_delay;
int64_t spark34_delay;
// spark status
sparkStatus spark12_status = sparkStatus::SPARK_POS_OK;
sparkStatus spark34_status = sparkStatus::SPARK_POS_OK;
// soft start status for circuits 12 and 34
bool soft12_engaged = false;
bool soft34_engaged = false;
// peak voltage from circuits 12 and 34
float volts12_pickup;
float volts34_pickup;
// peak voltage from conditioned output 12 and 34
float volts12_out;
float volts34_out;
// voltage from generator
float volts_gen;
};
ignitionBoxStatus ignA_status;
ignitionBoxStatus ignB_status;
ignitionBoxStatus ingA_statusBuffer[IGN_BUF_SIZE];
ignitionBoxStatus ingB_statusBuffer[IGN_BUF_SIZE];
// Pin to flag Map
static uint32_t pin2trig[49];
void initTriggerPinMapping() {
pin2trig[TRIG_A12P] = TRIG_FLAG_A12P;
pin2trig[TRIG_A12N] = TRIG_FLAG_A12N;
pin2trig[TRIG_A34P] = TRIG_FLAG_A34P;
pin2trig[TRIG_A34N] = TRIG_FLAG_A34N;
pin2trig[TRIG_B12P] = TRIG_FLAG_B12P;
pin2trig[TRIG_B12N] = TRIG_FLAG_B12N;
pin2trig[TRIG_B34P] = TRIG_FLAG_B34P;
pin2trig[TRIG_B34N] = TRIG_FLAG_B34N;
};
static uint32_t pin2spark[49];
void initSparkPinMapping() {
pin2spark[SPARK_A12] = SPARK_FLAG_A12;
pin2spark[SPARK_A34] = SPARK_FLAG_A34;
pin2spark[SPARK_B12] = SPARK_FLAG_B12;
pin2spark[SPARK_B34] = SPARK_FLAG_B34;
};
// =====================
// ISR (Pass return bitmask to ISR management function)
// one function for each wake up pin conncted to a trigger
// =====================
void IRAM_ATTR trig_isr_a() {
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
auto startTime = esp_timer_get_time();
uint32_t status = GPIO.status;
uint32_t flags = 0;
while (status) {
uint32_t pin = __builtin_ctz(status); // trova primo bit attivo
status &= ~(1 << pin); // clear bit
flags |= pin2trig[pin];
}
if (flags & (TRIG_FLAG_A12P | TRIG_FLAG_A12N))
ignA_status.trig12_start = startTime;
else
ignA_status.trig12_start = startTime;
if (trigA_TaskHandle) {
xTaskNotifyFromISR(trigA_TaskHandle, flags, eSetBits, &xHigherPriorityTaskWoken);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
}
void IRAM_ATTR spark_a() {
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
uint32_t spark_flag = GPIO.status1.val & SPARK_A12 ? SPARK_FLAG_A12 : SPARK_FLAG_A34 ;
if (trigA_TaskHandle) {
xTaskNotifyFromISR(trigA_TaskHandle, spark_flag, eSetBits, &xHigherPriorityTaskWoken);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
}
void IRAM_ATTR trig_isr_b() {
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
uint32_t status = GPIO.status1.val;
uint32_t flags = 0;
while (status) {
uint32_t pin = __builtin_ctz(status); // trova primo bit attivo
status &= ~(1 << pin); // clear bit
flags |= pin2trig[pin];
}
if (trigB_TaskHandle) {
xTaskNotifyFromISR(trigB_TaskHandle, flags, eSetBits, &xHigherPriorityTaskWoken);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
}
void IRAM_ATTR spark_b() {
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
uint32_t spark_flag = GPIO.status1.val & SPARK_B12 ? SPARK_FLAG_B12 : SPARK_FLAG_B34 ;
if (trigB_TaskHandle) {
xTaskNotifyFromISR(trigB_TaskHandle, spark_flag, eSetBits, &xHigherPriorityTaskWoken);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
}
void IRAM_ATTR trig_isr(void *arg);

View File

@@ -1,119 +1,272 @@
#define DEBUGLOG_DEFAULT_LOG_LEVEL_INFO
#define DEBUGLOG_DEFAULT_LOG_LEVEL_DEBUG
// Arduino Libraries
#include <Arduino.h>
#include <DebugLog.h>
#include <DebugLogEnable.h>
#include <SPI.h>
#include <WiFi.h>
#include <ArduinoJson.h>
// Definitions
#include <pins.h>
#include <channels.h>
#include <tasks.h>
#include <devices.h>
#include <datasave.h>
#include <webserver.h>
#include <ui.h>
// FreeRTOS directives
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
void setup() {
delay(250);
Serial.begin(115200);
// #define CH_B_ENABLE
#define TEST
// Setup Logger
LOG_ATTACH_SERIAL(Serial);
LOG_SET_LEVEL(DebugLogLevel::LVL_INFO);
// Debug Defines
#define WIFI_SSID "AstroRotaxMonitor"
#define WIFI_PASSWORD "maledettirotax"
// Print Processor Info
LOG_INFO("ESP32 Chip:", ESP.getChipModel());
LOG_INFO("ESP32 PSram:", ESP.getPsramSize());
LOG_INFO("ESP32 Flash:", ESP.getFlashChipSize());
LOG_INFO("ESP32 Heap:", ESP.getHeapSize());
LOG_INFO("ESP32 Sketch:", ESP.getFreeSketchSpace());
void setup()
{
Serial.begin(921600);
delay(250);
// Initialize Interrupt pins on coil detectors
pinMode(TRIG_A12P, INPUT_PULLDOWN);
pinMode(TRIG_A12N, INPUT_PULLDOWN);
pinMode(TRIG_A34P, INPUT_PULLDOWN);
pinMode(TRIG_A34N, INPUT_PULLDOWN);
pinMode(TRIG_B12P, INPUT_PULLDOWN);
pinMode(TRIG_B12N, INPUT_PULLDOWN);
pinMode(TRIG_B34P, INPUT_PULLDOWN);
pinMode(TRIG_B34N, INPUT_PULLDOWN);
initTriggerPinMapping();
// Initialize Interrupt pins on spark detectors
pinMode(SPARK_A12, INPUT_PULLDOWN);
pinMode(SPARK_A34, INPUT_PULLDOWN);
pinMode(SPARK_B12, INPUT_PULLDOWN);
pinMode(SPARK_B34, INPUT_PULLDOWN);
initSparkPinMapping();
// Setup Logger
LOG_ATTACH_SERIAL(Serial);
LOG_SET_LEVEL(DebugLogLevel::LVL_INFO);
// Ignition A Interrupts
attachInterrupt(TRIG_A12P, trig_isr_a, RISING);
attachInterrupt(TRIG_A34P, trig_isr_a, RISING);
attachInterrupt(TRIG_A12N, trig_isr_a, RISING);
attachInterrupt(TRIG_A34N, trig_isr_a, RISING);
attachInterrupt(SPARK_A12, spark_a, RISING);
attachInterrupt(SPARK_A34, spark_a, RISING);
// Ignition B Interrupts
attachInterrupt(TRIG_B12P, trig_isr_b, RISING);
attachInterrupt(TRIG_B34P, trig_isr_b, RISING);
attachInterrupt(TRIG_B12N, trig_isr_b, RISING);
attachInterrupt(TRIG_B34N, trig_isr_b, RISING);
attachInterrupt(SPARK_B12, spark_b, RISING);
attachInterrupt(SPARK_B34, spark_b, RISING);
// Print Processor Info
LOG_DEBUG("ESP32 Chip:", ESP.getChipModel());
if (psramFound())
{
LOG_DEBUG("ESP32 PSram Found");
LOG_DEBUG("ESP32 PSram:", ESP.getPsramSize());
psramInit();
}
LOG_DEBUG("ESP32 Flash:", ESP.getFlashChipSize());
LOG_DEBUG("ESP32 Heap:", ESP.getHeapSize());
LOG_DEBUG("ESP32 Sketch:", ESP.getFreeSketchSpace());
// Init SPI interface
SPI.begin();
// Init Wifi station
LOG_INFO("Initializing WiFi...");
WiFi.mode(WIFI_AP);
IPAddress local_IP(10, 11, 12, 1);
IPAddress gateway(10, 11, 12, 1);
IPAddress subnet(255, 255, 255, 0);
WiFi.softAPConfig(local_IP, gateway, subnet);
if (WiFi.softAP(WIFI_SSID, WIFI_PASSWORD))
{
LOG_INFO("WiFi AP Mode Started");
LOG_INFO("Wifi SSID:", WIFI_SSID);
LOG_INFO("Wifi Password:", WIFI_PASSWORD);
LOG_INFO("WiFi IP:" + WiFi.softAPIP().toString());
}
else
{
LOG_ERROR("Failed to start WiFi AP Mode");
LOG_ERROR("5 seconds to restart...");
vTaskDelay(pdMS_TO_TICKS(5000));
esp_restart();
}
// Initialize Interrupt pins on PICKUP detectors
initTriggerPinsInputs();
// Initialize Interrupt pins on SPARK detectors
initSparkPinInputs();
}
void loop() {
// global variables
bool running = true;
Devices dev;
void loop()
{
// global variables
bool running = true;
const uint32_t max_queue = 128;
const uint32_t filter_k = 10;
PSRAMVector<ignitionBoxStatus> ignA_history_0(max_history);
PSRAMVector<ignitionBoxStatus> ignA_history_1(max_history);
auto *active_history = &ignA_history_0;
auto *writable_history = &ignA_history_1;
// Init devices
dev.adc = new ADS1256(ADC_DRDY, ADC_RST, ADC_SYNC, ADC_CS, 2.5, &SPI);
dev.adc->InitializeADC();
dev.adc->setPGA(PGA_1);
dev.adc->setDRATE(DRATE_1000SPS);
// Resources Initialization
Devices dev;
// Task handle
TaskHandle_t trigA_TaskHandle = NULL;
TaskHandle_t trigB_TaskHandle = NULL;
// Data Queue for real time task to main loop communication
QueueHandle_t rt_taskA_queue = xQueueCreate(max_queue, sizeof(ignitionBoxStatus));
QueueHandle_t rt_taskB_queue = xQueueCreate(max_queue, sizeof(ignitionBoxStatus));
rtTaskParams taskA_params{
.rt_running = true,
.dev = &dev,
.rt_handle_ptr = &trigA_TaskHandle,
.rt_queue = rt_taskA_queue,
.rt_int = rtTaskInterrupts{
.isr_ptr = trig_isr,
.trig_pin_12p = TRIG_PIN_A12P,
.trig_pin_12n = TRIG_PIN_A12N,
.trig_pin_34p = TRIG_PIN_A34P,
.trig_pin_34n = TRIG_PIN_A34N,
.spark_pin_12 = SPARK_PIN_A12,
.spark_pin_34 = SPARK_PIN_A34},
.rt_resets = rtTaskResets{.rst_io_peak= RST_EXT_PEAK_DETECT, .rst_io_sh = RST_EXT_SAMPLE_HOLD}};
// Ignition A on Core 0
auto ignA_task_success = xTaskCreatePinnedToCore(
ignitionA_task,
"ignitionA_task",
TASK_STACK,
(void*) &dev,
TASK_PRIORITY,
&trigA_TaskHandle,
CORE_0
);
// Ignition A on Core 1
auto ignB_task_success = xTaskCreatePinnedToCore(
ignitionB_task,
"ignitionB_task",
TASK_STACK,
(void*) &dev,
TASK_PRIORITY, // priorità leggermente più alta
&trigA_TaskHandle,
CORE_1
);
if ((ignA_task_success && ignB_task_success) != pdPASS){
LOG_ERROR("Unble to initialize ISR task");
if (!rt_taskA_queue || !rt_taskB_queue)
{
LOG_ERROR("Unable To Create task queues");
LOG_ERROR("5 seconds to restart...");
vTaskDelay(pdMS_TO_TICKS(5000));
esp_restart();
}
LOG_INFO("Real Time Tasks A&B initialized");
else
LOG_DEBUG("Task Variables OK");
#ifdef CH_B_ENABLE
QueueHandle_t rt_taskB_queue = xQueueCreate(max_queue, sizeof(ignitionBoxStatus));
rtTaskParams taskB_params{
.rt_running = true,
.dev = &dev,
.rt_handle_ptr = &trigB_TaskHandle,
.rt_queue = rt_taskB_queue,
.rt_int = rtTaskInterrupts{
.isr_ptr = trig_isr,
.trig_pin_12p = TRIG_PIN_B12P,
.trig_pin_12n = TRIG_PIN_B12N,
.trig_pin_34p = TRIG_PIN_B34P,
.trig_pin_34n = TRIG_PIN_B34N,
.spark_pin_12 = SPARK_PIN_B12,
.spark_pin_34 = SPARK_PIN_B34},
.rt_resets = rtTaskResets{.rst_io_12p = RST_EXT_B12P, .rst_io_12n = RST_EXT_B12N, .rst_io_34p = RST_EXT_B34P, .rst_io_34n = RST_EXT_B34N}};
#endif
// Spi ok flags
bool spiA_ok = true;
bool spiB_ok = true;
// Init 2 SPI interfaces
SPIClass SPI_A(FSPI);
spiA_ok = SPI_A.begin(SPI_A_SCK, SPI_A_MISO, SPI_A_MOSI);
SPI_A.setDataMode(SPI_MODE1); // ADS1256 requires SPI mode 1
#ifdef CH_B_ENABLE
SPIClass SPI_B(HSPI);
spiB_ok = SPI_B.begin(SPI_B_SCK, SPI_B_MISO, SPI_B_MOSI);
SPI_B.setDataMode(SPI_MODE1); // ADS1256 requires SPI mode 1
#endif
if (!spiA_ok || !spiB_ok)
{
LOG_ERROR("Unable to Initialize SPI Busses");
LOG_ERROR("5 seconds to restart...");
vTaskDelay(pdMS_TO_TICKS(5000));
esp_restart();
}
LOG_DEBUG("Init SPI OK");
// Init ADC_A
dev.adc_a = new ADS1256(ADC_A_DRDY, ADS1256::PIN_UNUSED, ADS1256::PIN_UNUSED, ADC_A_CS, 2.5, &SPI_A);
dev.adc_a->InitializeADC();
dev.adc_a->setPGA(PGA_1);
dev.adc_a->setDRATE(DRATE_7500SPS);
#ifdef CH_B_ENABLE
// Init ADC_B
dev.adc_a = new ADS1256(ADC_B_DRDY, ADC_B_RST, ADC_B_SYNC, ADC_B_CS, 2.5, &SPI_B);
dev.adc_a->InitializeADC();
dev.adc_a->setPGA(PGA_1);
dev.adc_a->setDRATE(DRATE_1000SPS);
#endif
LOG_DEBUG("Init ADC OK");
// Ignition A on Core 0
auto ignA_task_success = pdPASS;
ignA_task_success = xTaskCreatePinnedToCore(
rtIgnitionTask,
"rtIgnitionTask_boxA",
RT_TASK_STACK,
(void *)&taskA_params,
RT_TASK_PRIORITY,
&trigA_TaskHandle,
CORE_0);
delay(100); // give some time to the thread to start
// Ignition B on Core 1
auto ignB_task_success = pdPASS;
#ifdef CH_B_ENABLE
ignB_task_success = xTaskCreatePinnedToCore(
rtIgnitionTask,
"rtIgnitionTask_boxB",
RT_TASK_STACK,
(void *)&taskB_params,
RT_TASK_PRIORITY, // priorità leggermente più alta
&trigB_TaskHandle,
CORE_1);
delay(100); // give some time to the thread to start
#endif
if (ignA_task_success != pdPASS || ignB_task_success != pdPASS)
{
LOG_ERROR("Unable to initialize ISR task");
LOG_ERROR("5 seconds to restart...");
vTaskDelay(pdMS_TO_TICKS(5000));
esp_restart();
}
LOG_DEBUG("Real Time Tasks A & B initialized");
////////////////////// MAIN LOOP //////////////////////
while (running) {
bool partial_save = false; // flag to indicate if a partial save has been done after a timeout
uint32_t counter = 0;
uint32_t wait_count = 0;
ignitionBoxStatus ign_info;
ignitionBoxStatusAverage ign_info_avg(filter_k);
LITTLEFSGuard fsGuard;
WebPage webPage(80, LittleFS); // Initialize webserver and Websocket
while (running)
{
if (counter >= active_history->size()) // not concurrent with write task
{
counter = 0;
partial_save = false; // reset partial save flag on new data cycle
auto *temp = active_history;
active_history = writable_history; // switch active and writable buffers
writable_history = temp; // ensure writable_history points to the buffer we just filled
dataSaveParams save_params{
.history = writable_history,
.file_path = "ignition_history.csv"};
save_history(*writable_history, "ignition_history.csv"); // directly call the save task function to save without delay
}
if (xQueueReceive(rt_taskA_queue, &ign_info, pdMS_TO_TICKS(1000)) == pdTRUE)
{
// printInfo(ign_info);
auto &hist = *active_history;
hist[counter++ % active_history->size()] = ign_info;
ign_info_avg.update(ign_info); // update moving average with latest ignition status
Serial.printf("\033[2K Data Received: %d/%d\r", counter, hist.size());
if ( counter % filter_k == 0) // send data every 10 samples
{
Serial.println();
LOG_DEBUG("Sending average ignition status to websocket clients...");
webPage.sendWsData(ign_info_avg.toJson().as<String>());
}
}
else
{
Serial.printf("[%d] Waiting for data...\r", wait_count++);
if (!partial_save && counter > 0) // if timeout occurs but we have unsaved data, save it before next timeout
{
active_history->resize(counter); // resize active history to actual number of records received to avoid saving empty records
save_history(*active_history, "ignition_history.csv");
active_history->resize(max_history); // resize back to max history size for next data cycle
counter = 0; // reset counter after saving
partial_save = true;
first_save = true;
}
delay(500);
}
}
if (trigA_TaskHandle)
vTaskDelete(trigA_TaskHandle);
vTaskDelete(trigA_TaskHandle);
if (trigB_TaskHandle)
vTaskDelete(trigB_TaskHandle);
vTaskDelete(trigB_TaskHandle);
////////////////////// MAIN LOOP //////////////////////
}

View File

@@ -1,86 +1,127 @@
#pragma once
#include <Arduino.h>
// =====================
// SPI BUS
// USB (RISERVATA)
// =====================
#define SPI_MOSI 11
#define SPI_MISO 13
#define SPI_SCK 12
#define USB_DM 19
#define USB_DP 20
// =====================
// I2C BUS
// UART DEBUG (RISERVATA)
// =====================
#define UART_TX 43
#define UART_RX 44
// =====================
// RGB Led
// =====================
#define LED 48
// =====================
// STRAPPING CRITICI (NON USARE)
// =====================
// 0, 3
// =====================
// SPI BUS ADC1 (VSPI)
// =====================
#define SPI_A_MOSI 10
#define SPI_A_SCK 11
#define SPI_A_MISO 12
// =====================
// SPI BUS ADC2 (HSPI)
// =====================
#define SPI_B_MOSI 36
#define SPI_B_SCK 37
#define SPI_B_MISO 38
// =====================
// I2C BUS (PCA9555)
// =====================
#define SDA 8
#define SCL 9
#define I2C_INT 17
// =====================
// ADC CONTROL
// =====================
#define ADC_CS 10
#define ADC_DRDY 4
#define ADC_RST 5
#define ADC_SYNC 6
#define ADC_A_CS 14
#define ADC_A_DRDY 13
#define ADC_B_CS 21
#define ADC_B_DRDY 47
// =====================
// DIGITAL POT
// =====================
#define POT_CS 7
#define POT_DRDY 18
// =====================
// RELAY OUT
// =====================
#define PICK_RELAY 21
#define POT_A_CS 18
#define POT_B_CS 35
// =====================
// TRIGGER INPUT INTERRUPTS
// =====================
#define TRIG_A12P 1
#define TRIG_A12N 2
#define TRIG_A34P 3
#define TRIG_A34N 14
#define TRIG_B12P 15
#define TRIG_B12N 16
#define TRIG_B34P 17
#define TRIG_B34N 18
// =====================
// PEAK DETECTOR RESET OUTPUTS
// =====================
#define RST_A12P 39
#define RST_A12N 40
#define RST_A34P 41
#define RST_A34N 42
#define RST_B12P 35
#define RST_B12N 36
#define RST_B34P 37
#define RST_B34N 38
#define TRIG_PIN_A12P 6
#define TRIG_PIN_A12N 7
#define TRIG_PIN_A34P 15
#define TRIG_PIN_A34N 16
#define TRIG_PIN_B12P 42
#define TRIG_PIN_B12N 41
#define TRIG_PIN_B34P 40
#define TRIG_PIN_B34N 39
// =====================
// SPARK DETECT INPUTS
// =====================
#define SPARK_A12 45 // input only
#define SPARK_A34 46 // input only
#define SPARK_B12 47
#define SPARK_B34 48
#define SPARK_PIN_A12 4
#define SPARK_PIN_A34 5
#define SPARK_PIN_B12 1
#define SPARK_PIN_B34 2
// =====================
// STATUS & BUTTON su PCA9555 (I2C)
// PCA9555 (I2C EXPANDER)
// =====================
#define STA_1 0
#define STA_2 1
#define STA_3 2
#define STA_4 3
#define STA_5 4
#define STA_6 5
#define STA_7 6
#define STA_8 7
#define BTN_1 8
#define BTN_2 9
#define BTN_3 10
#define BTN_4 11
#define BTN_5 12
#define BTN_6 13
#define BTN_7 14
#define BTN_8 15
// --- RESET LINES ---
#define RST_EXT_PEAK_DETECT 0
#define RST_EXT_SAMPLE_HOLD 1
#define BTN_1 2
#define BTN_2 3
#define BTN_3 4
#define BTN_4 5
#define BTN_5 6
#define BTN_6 7
// --- RELAY ---
#define A_EXT_RELAY 8
#define B_EXT_RELAY 9
// --- STATUS / BUTTON ---
#define BTN_7 10
#define BTN_8 11
#define STA_1 12
#define STA_2 13
#define STA_3 14
#define STA_4 15
// Init Pin Functions
inline void initTriggerPinsInputs()
{
pinMode(TRIG_PIN_A12P, INPUT_PULLDOWN);
pinMode(TRIG_PIN_A12N, INPUT_PULLDOWN);
pinMode(TRIG_PIN_A34P, INPUT_PULLDOWN);
pinMode(TRIG_PIN_A34N, INPUT_PULLDOWN);
pinMode(TRIG_PIN_B12P, INPUT_PULLDOWN);
pinMode(TRIG_PIN_B12N, INPUT_PULLDOWN);
pinMode(TRIG_PIN_B34P, INPUT_PULLDOWN);
pinMode(TRIG_PIN_B34N, INPUT_PULLDOWN);
}
inline void initSparkPinInputs()
{
pinMode(SPARK_PIN_A12, INPUT_PULLDOWN);
pinMode(SPARK_PIN_A34, INPUT_PULLDOWN);
pinMode(SPARK_PIN_B12, INPUT_PULLDOWN);
pinMode(SPARK_PIN_B34, INPUT_PULLDOWN);
}

View File

@@ -0,0 +1,84 @@
#pragma once
#include <Arduino.h>
// =====================
// UART DEBUG
// =====================
#define UART_TX 1 // TX0 (USB seriale)
#define UART_RX 3 // RX0
// =====================
// SPI BUS
// =====================
#define SPI_A_MOSI 23
#define SPI_A_MISO 19
#define SPI_A_SCK 18
// =====================
// I2C BUS
// =====================
#define SDA 21
#define SCL 22
// =====================
// ADC CONTROL (SPI + interrupt safe)
// =====================
#define ADC_A_CS 5 // chip select
#define ADC_A_DRDY 34 // input only + interrupt perfetto
#define ADC_A_RST 27 // output
#define ADC_A_SYNC 26 // output
// =====================
// DIGITAL OUT
// =====================
#define POT_A_CS 25
#define POT_B_CS 33
// =====================
// TRIGGER INPUT INTERRUPTS
// =====================
#define TRIG_PIN_A12P 35
#define TRIG_PIN_A12N 32
#define TRIG_PIN_A34P 39
#define TRIG_PIN_A34N 36
// =====================
// SPARK DETECT INTERRUPTS
// =====================
#define SPARK_PIN_A12 4
#define SPARK_PIN_A34 2
// =====================
// PCA9555 (I2C EXPANDER)
// =====================
// --- RESET LINES ---
#define RST_EXT_A12P 0
#define RST_EXT_A12N 1
#define RST_EXT_A34P 2
#define RST_EXT_A34N 3
// --- RELAY ---
#define A_EXT_RELAY 8
// Init Pin Functions
inline void initTriggerPinsInputs()
{
pinMode(TRIG_PIN_A12P, INPUT_PULLDOWN);
pinMode(TRIG_PIN_A12N, INPUT_PULLDOWN);
pinMode(TRIG_PIN_A34P, INPUT_PULLDOWN);
pinMode(TRIG_PIN_A34N, INPUT_PULLDOWN);
}
inline void initSparkPinInputs()
{
pinMode(SPARK_PIN_A12, INPUT_PULLDOWN);
pinMode(SPARK_PIN_A34, INPUT_PULLDOWN);
}

View File

@@ -0,0 +1,30 @@
#pragma once
#include <vector>
#include "esp_heap_caps.h"
// Allocator custom per PSRAM
template <typename T>
struct PSRAMAllocator {
using value_type = T;
PSRAMAllocator() noexcept {}
template <typename U>
PSRAMAllocator(const PSRAMAllocator<U>&) noexcept {}
T* allocate(std::size_t n) {
void* ptr = heap_caps_malloc(n * sizeof(T), MALLOC_CAP_SPIRAM);
if (!ptr) {
throw std::bad_alloc();
}
return static_cast<T*>(ptr);
}
void deallocate(T* p, std::size_t) noexcept {
heap_caps_free(p);
}
};
template <typename T>
using PSRAMVector = std::vector<T, PSRAMAllocator<T>>;

266
RotaxMonitor/src/tasks.cpp Normal file
View File

@@ -0,0 +1,266 @@
#include "tasks.h"
#include <esp_timer.h>
// Timeout callback for microsecond precision
void spark_timeout_callback(void *arg)
{
TaskHandle_t handle = (TaskHandle_t)arg;
xTaskNotify(handle, SPARK_FLAG_TIMEOUT, eSetValueWithOverwrite);
}
void rtIgnitionTask(void *pvParameters)
{
// Invalid real time rt_task_ptr parameters, exit immediate
if (!pvParameters)
{
LOG_ERROR("Null rt_task_ptr parameters");
vTaskDelete(NULL);
}
LOG_INFO("rtTask Params OK");
// Task Parameters and Devices
rtTaskParams *params = (rtTaskParams *)pvParameters;
const rtTaskInterrupts rt_int = params->rt_int; // copy to avoid external override
const rtTaskResets rt_rst = params->rt_resets; // copy to avoid external override
QueueHandle_t rt_queue = params->rt_queue;
TaskHandle_t rt_handle_ptr = *params->rt_handle_ptr;
Devices *dev = params->dev;
ADS1256 *adc = dev->adc_a;
PCA9555 *io = dev->io;
ignitionBoxStatus ign_box_sts;
// Variables for ISR, static to be fixed in memory locations
static isrParams isr_params_t12p{
.flag = TRIG_FLAG_12P,
.ign_stat = &ign_box_sts,
.rt_handle_ptr = rt_handle_ptr};
static isrParams isr_params_t12n{
.flag = TRIG_FLAG_12N,
.ign_stat = &ign_box_sts,
.rt_handle_ptr = rt_handle_ptr};
static isrParams isr_params_t34p{
.flag = TRIG_FLAG_34P,
.ign_stat = &ign_box_sts,
.rt_handle_ptr = rt_handle_ptr};
static isrParams isr_params_t34n{
.flag = TRIG_FLAG_34N,
.ign_stat = &ign_box_sts,
.rt_handle_ptr = rt_handle_ptr};
static isrParams isr_params_sp12{
.flag = SPARK_FLAG_12,
.ign_stat = &ign_box_sts,
.rt_handle_ptr = rt_handle_ptr};
static isrParams isr_params_sp34{
.flag = SPARK_FLAG_34,
.ign_stat = &ign_box_sts,
.rt_handle_ptr = rt_handle_ptr};
LOG_INFO("rtTask ISR Params OK");
// Create esp_timer for microsecond precision timeout
esp_timer_handle_t timeout_timer;
esp_timer_create_args_t timer_args = {
.callback = spark_timeout_callback,
.arg = (void *)rt_handle_ptr,
.dispatch_method = ESP_TIMER_TASK,
.name = "spark_timeout"};
esp_timer_create(&timer_args, &timeout_timer);
// Attach Pin Interrupts
attachInterruptArg(digitalPinToInterrupt(rt_int.trig_pin_12p), rt_int.isr_ptr, (void *)&isr_params_t12p, RISING);
attachInterruptArg(digitalPinToInterrupt(rt_int.trig_pin_12n), rt_int.isr_ptr, (void *)&isr_params_t12n, RISING);
attachInterruptArg(digitalPinToInterrupt(rt_int.trig_pin_34p), rt_int.isr_ptr, (void *)&isr_params_t34p, RISING);
attachInterruptArg(digitalPinToInterrupt(rt_int.trig_pin_34n), rt_int.isr_ptr, (void *)&isr_params_t34n, RISING);
attachInterruptArg(digitalPinToInterrupt(rt_int.spark_pin_12), rt_int.isr_ptr, (void *)&isr_params_sp12, RISING);
attachInterruptArg(digitalPinToInterrupt(rt_int.spark_pin_34), rt_int.isr_ptr, (void *)&isr_params_sp34, RISING);
LOG_INFO("rtTask ISR Attach OK");
// Global rt_task_ptr variables
bool first_cycle = true;
bool cycle12 = false;
bool cycle34 = false;
int64_t last_cycle_time = 0;
uint32_t n_errors = 0;
while (params->rt_running)
{
uint32_t pickup_flag = 0;
uint32_t spark_flag = 0;
// WAIT FOR PICKUP SIGNAL
xTaskNotifyWait(
0x00, // non pulire all'ingresso
ULONG_MAX, // pulisci i primi 8 bit
&pickup_flag, // valore ricevuto
portMAX_DELAY);
if (first_cycle && pickup_flag != TRIG_FLAG_12P) // skip first cycle because of possible initial noise on pickup signals at startu
continue;
// Start microsecond precision timeout timer
esp_timer_stop(timeout_timer); // stop timer in case it was running from previous cycle
esp_timer_start_once(timeout_timer, spark_timeout_max);
// WAIT FOR SPARK TO HAPPEN OR TIMEOUT
xTaskNotifyWait(
0x00, // non pulire all'ingresso
ULONG_MAX, // pulisci i primi 8 bit
&spark_flag, // valore ricevuto
portMAX_DELAY); // wait indefinitely, timeout handled by esp_timer
// Handle timeout or spark event
if (spark_flag != SPARK_FLAG_TIMEOUT)
esp_timer_stop(timeout_timer);
// A trigger from pickup 12 is followed by a spark event on 34 or vice versa pickup 34 triggers spark on 12
if ((pickup_flag == TRIG_FLAG_12P || pickup_flag == TRIG_FLAG_12N) && (spark_flag != SPARK_FLAG_12 && spark_flag != SPARK_FLAG_TIMEOUT))
{
ign_box_sts.coils12.spark_status = ign_box_sts.coils34.spark_status = sparkStatus::SPARK_SYNC_FAIL;
continue;
}
// Select coil status reference based on pickup_flag
coilsStatus *coils;
switch (pickup_flag)
{
case TRIG_FLAG_12P:
{
first_cycle = false;
// compute engine rpm from cycle time
auto current_time = esp_timer_get_time();
auto cycle_time = current_time - last_cycle_time;
last_cycle_time = current_time;
ign_box_sts.eng_rpm = (int32_t)(60.0f / (cycle_time / 1000000.0f));
}
case TRIG_FLAG_12N:
coils = &ign_box_sts.coils12;
break;
case TRIG_FLAG_34P:
case TRIG_FLAG_34N:
coils = &ign_box_sts.coils34;
break;
}
// Select logic based on pickup and spark flags
switch (pickup_flag)
{
case TRIG_FLAG_12P:
case TRIG_FLAG_34P:
{
// Timeout not occourred, expected POSITIVE edge spark OCCOURRED
if (spark_flag != SPARK_FLAG_TIMEOUT)
{
coils->spark_delay = (int32_t)(coils->spark_time - coils->trig_time);
coils->sstart_status = softStartStatus::NORMAL; // because spark on positive edge
coils->spark_status = sparkStatus::SPARK_POS_OK; // do not wait for spark on negative edge
}
// Timeout occourred, expected POSITIVE edge spark NOT OCCOURRED
else if (spark_flag == SPARK_FLAG_TIMEOUT)
{
coils->spark_status = sparkStatus::SPARK_NEG_WAIT;
coils->sstart_status = softStartStatus::NORMAL;
}
continue; // Do nothing more on positive pulse
}
// CASES for NEGATIVE cycle triggering of pickup and sparks 12 & 34
case TRIG_FLAG_12N:
case TRIG_FLAG_34N:
{
const bool expected_negative = coils->spark_status == sparkStatus::SPARK_NEG_WAIT;
// Timeout not occourred, expected NEGATIVE edge spark OCCOURRED
if (spark_flag != SPARK_FLAG_TIMEOUT && expected_negative)
{
coils->spark_delay = (int32_t)(coils->spark_time - coils->trig_time);
coils->sstart_status = softStartStatus::SOFT_START;
coils->spark_status = sparkStatus::SPARK_NEG_OK;
}
// Timeout occourred, expected POSITIVE edge spark NOT OCCOURRED
else if (spark_flag == SPARK_FLAG_TIMEOUT && expected_negative)
{
coils->sstart_status = softStartStatus::ERROR;
coils->spark_status = sparkStatus::SPARK_NEG_FAIL;
}
// Timeout not occouured, unexpected negative edge spark
else if (spark_flag != SPARK_FLAG_TIMEOUT && !expected_negative)
{
coils->sstart_status = softStartStatus::SOFT_START;
coils->spark_status = sparkStatus::SPARK_NEG_UNEXPECTED;
}
// Wait for finish of negative pulse to save data to buffer
coils->n_events++;
if (pickup_flag == TRIG_FLAG_12N)
cycle12 = true;
else
cycle34 = true;
break;
}
default:
break;
}
if (cycle12 && cycle34) // wait for both 12 and 34 cycles to complete before sending data to main loop and resetting peak detectors
{
cycle12 = false;
cycle34 = false;
if (ign_box_sts.coils12.spark_status == sparkStatus::SPARK_POS_FAIL || ign_box_sts.coils12.spark_status == sparkStatus::SPARK_NEG_FAIL)
ign_box_sts.coils12.n_missed_firing++;
if (ign_box_sts.coils34.spark_status == sparkStatus::SPARK_POS_FAIL || ign_box_sts.coils34.spark_status == sparkStatus::SPARK_NEG_FAIL)
ign_box_sts.coils34.n_missed_firing++;
// read adc channels: pickup12, out12 [ pos + neg ]
if (adc) // read only if adc initialized
{
uint32_t start_adc_read = esp_timer_get_time();
// from peak detector circuits
ign_box_sts.coils12.peak_p_in = adcReadChannel(adc, ADC_CH_PEAK_12P_IN);
ign_box_sts.coils12.peak_n_in = adcReadChannel(adc, ADC_CH_PEAK_12N_IN);
ign_box_sts.coils34.peak_p_in = adcReadChannel(adc, ADC_CH_PEAK_34P_IN);
ign_box_sts.coils34.peak_n_in = adcReadChannel(adc, ADC_CH_PEAK_34N_IN);
ign_box_sts.coils12.peak_p_out = adcReadChannel(adc, ADC_CH_PEAK_12P_OUT);
ign_box_sts.coils12.peak_n_out = adcReadChannel(adc, ADC_CH_PEAK_12N_OUT);
ign_box_sts.coils34.peak_p_out = adcReadChannel(adc, ADC_CH_PEAK_34P_OUT);
ign_box_sts.coils34.peak_n_out = adcReadChannel(adc, ADC_CH_PEAK_34N_OUT);
ign_box_sts.adc_read_time = (int32_t)(esp_timer_get_time() - start_adc_read);
}
else // simulate adc read timig
vTaskDelay(pdMS_TO_TICKS(1));
// reset peak detectors + sample and hold
// outputs on io expander
if (io)
{
const uint16_t iostat = io->read();
const uint16_t rst_bitmask = (0x0001 << rt_rst.rst_io_peak);
io->write(iostat | rst_bitmask);
vTaskDelay(pdMS_TO_TICKS(1));
io->write(iostat & ~rst_bitmask);
}
else
vTaskDelay(pdMS_TO_TICKS(1));
// send essage to main loop with ignition info, by copy so local static variable is ok
if (rt_queue)
{
ign_box_sts.timestamp = esp_timer_get_time(); // update data timestamp
if (xQueueSendToBack(rt_queue, (void *)&ign_box_sts, 0) != pdPASS)
ign_box_sts.n_queue_errors = ++n_errors;
}
}
}
// Delete the timeout timer
esp_timer_delete(timeout_timer);
LOG_WARN("Ending realTime Task");
// Ignition A Interrupts DETACH
detachInterrupt(rt_int.trig_pin_12p);
detachInterrupt(rt_int.trig_pin_12n);
detachInterrupt(rt_int.trig_pin_34p);
detachInterrupt(rt_int.trig_pin_34n);
detachInterrupt(rt_int.spark_pin_12);
detachInterrupt(rt_int.spark_pin_34);
// delete present task
vTaskDelete(NULL);
}

View File

@@ -1,8 +1,13 @@
#pragma once
#define DEBUGLOG_DEFAULT_LOG_LEVEL_DEBUG
// Serial debug flag
//#define DEBUG
// Arduino Libraries
#include <Arduino.h>
#include <DebugLog.h>
#include "utils.h"
// ISR
#include "isr.h"
@@ -10,136 +15,50 @@
// DEVICES
#include "devices.h"
const auto spark_timeout_max = 1;
// Global Variables and Flags
const uint32_t spark_timeout_max = 500; // in microseconds
void ignitionA_task(void *pvParameters) {
Devices* dev = (Devices*) pvParameters;
ADS1256* adc = dev->adc;
// Debug Variables
#ifdef DEBUG
static const std::map<const uint32_t, const char *> names = {
{TRIG_FLAG_12P, "TRIG_FLAG_12P"},
{TRIG_FLAG_12N, "TRIG_FLAG_12N"},
{TRIG_FLAG_34P, "TRIG_FLAG_34P"},
{TRIG_FLAG_34N, "TRIG_FLAG_34N"},
{SPARK_FLAG_12, "SPARK_FLAG_12"},
{SPARK_FLAG_34, "SPARK_FLAG_34"},
{SPARK_FLAG_TIMEOUT, "SPARK_FLAG_TIMEOUT"},
};
#endif
uint32_t pickup_flag;
uint32_t spark_flag;
// RT task Interrupt parameters
struct rtTaskInterrupts
{
void (*isr_ptr)(void *);
const uint8_t trig_pin_12p;
const uint8_t trig_pin_12n;
const uint8_t trig_pin_34p;
const uint8_t trig_pin_34n;
const uint8_t spark_pin_12;
const uint8_t spark_pin_34;
};
while (true) {
// WAIT FOR PICKUP SIGNAL
xTaskNotifyWait(
0x00, // non pulire all'ingresso
ULONG_MAX, // pulisci tutti i bit all'uscita
&pickup_flag, // valore ricevuto
portMAX_DELAY
);
// WAIT FOR SPARK TO HAPPEN
auto spark_timeout = xTaskNotifyWait(
0x00, // non pulire all'ingresso
ULONG_MAX, // pulisci tutti i bit all'uscita
&spark_flag, // valore ricevuto
spark_timeout_max
);
// Save current time to compute delay from pickup to spark
auto curr_time = esp_timer_get_time();
// A trigger from pickup 12 is followed by a spark event on 34 or vice versa pickup 34 triggers spark on 12
if ((pickup_flag == TRIG_FLAG_A12P || pickup_flag == TRIG_FLAG_A12N) && spark_flag != SPARK_A12) {
ignA_status.trig12_start = ignA_status.trig34_start = -1;
ignA_status.trig12_end = ignA_status.trig34_end = -1;
ignA_status.spark12_delay = ignA_status.spark34_delay = -1;
ignA_status.soft12_engaged = ignA_status.soft34_engaged = false;
ignA_status.spark12_status = ignA_status.spark12_status = sparkStatus::SPARK_SYNC_FAIL;
// Save error on circular buffer and skip to next cycle //
// [TODO]
continue;
}
bool new_data12 = false;
bool new_data34 = false;
// RT Task Peak Detector Reset pins
struct rtTaskResets
{
const uint8_t rst_io_peak;
const uint8_t rst_io_sh;
};
switch (pickup_flag) {
case TRIG_FLAG_A12P: {
// Timeout not occourred, expected POSITIVE edge spark OCCOURRED
if (spark_timeout == pdPASS) {
ignA_status.trig12_end = curr_time;
ignA_status.spark12_delay = ignA_status.trig12_end - ignA_status.trig12_end;
ignA_status.soft12_engaged = false; // because spark on positive edge
ignA_status.spark12_status = sparkStatus::SPARK_POS_OK; // do not wait for spark on negative edge
}
// Timeout occourred, expected POSITIVE edge spark NOT OCCOURRED
else if (spark_timeout == pdFAIL) {
ignA_status.spark12_status = sparkStatus::SPARK_NEG_WAIT;
ignA_status.soft12_engaged = false;
}
// Do nothing more on positive pulse
break;
}
case TRIG_FLAG_A12N: {
bool expected_negative12 = ignA_status.spark12_status == sparkStatus::SPARK_NEG_WAIT;
// Timeout not occourred, expected NEGATIVE edge spark OCCOURRED
if (spark_timeout == pdPASS && expected_negative12) {
ignA_status.trig12_end = curr_time;
ignA_status.spark12_delay = ignA_status.trig12_end - ignA_status.trig12_end;
ignA_status.soft12_engaged = true;
ignA_status.spark12_status == sparkStatus::SPARK_NEG_OK;
}
// Timeout occourred, expected POSITIVE edge spark NOT OCCOURRED
else if (spark_timeout == pdFAIL && expected_negative12) {
ignA_status.soft12_engaged = false;
ignA_status.spark12_status = sparkStatus::SPARK_NEG_FAIL;
}
// Timeout not occouured, unexpected negative edge spark
else if (spark_timeout == pdPASS && !expected_negative12) {
ignA_status.soft12_engaged = true;
ignA_status.spark12_status = sparkStatus::SPARK_NEG_UNEXPECTED;
}
// Save status on circular buffer
new_data12 = true;
break;
}
case TRIG_FLAG_A34P:
case TRIG_FLAG_A34N:
break;
default:
LOG_ERROR("Invalid A Interrupt");
}
// RT task parameters
struct rtTaskParams
{
bool rt_running; // run flag, false to terminate
Devices *dev;
TaskHandle_t* rt_handle_ptr;
const QueueHandle_t rt_queue;
const rtTaskInterrupts rt_int; // interrupt pins to attach
const rtTaskResets rt_resets; // reset ping for peak detectors
};
vTaskDelay(pdMS_TO_TICKS(1)); // delay 1ms to allow peak detectors to charge
if (new_data12) {
// read adc channels: pickup12, out12 [ pos + neg ]
ignA_status.volts12_pickup = adcReadChannel(adc, PICKUP_IN_A12);
ignA_status.volts12_out = adcReadChannel(adc, PICKUP_OUT_A12);
// reset peak detectors
digitalWrite(RST_A12P, HIGH);
digitalWrite(RST_A12N, HIGH);
vTaskDelay(pdMS_TO_TICKS(1));
digitalWrite(RST_A12P, HIGH);
digitalWrite(RST_A12N, HIGH);
// save on circluar buffer 12
}
}
}
void ignitionB_task(void *pvParameters) {
uint32_t notifiedValue;
while (true) {
// attende eventi
xTaskNotifyWait(
0x00, // non pulire all'ingresso
0xFFFFFFFF, // pulisci tutti i bit all'uscita
&notifiedValue, // valore ricevuto
portMAX_DELAY
);
switch (notifiedValue) {
case TRIG_FLAG_B12P:
break;
case TRIG_FLAG_B34P:
break;
case TRIG_FLAG_B12N:
break;
case TRIG_FLAG_B34N:
break;
default:
LOG_ERROR("Invalid B Interrupt: ", notifiedValue);
}
}
}
void rtIgnitionTask(void *pvParameters);

73
RotaxMonitor/src/ui.cpp Normal file
View File

@@ -0,0 +1,73 @@
#include <ui.h>
void clearScreen()
{
Serial.print("\033[2J"); // clear screen
Serial.print("\033[H"); // cursor home
Serial.flush();
}
void setCursor(const uint8_t x, const uint8_t y)
{
Serial.printf("\033[%d;%d", y, x + 1);
Serial.flush();
}
void printField(const char name[], const uint32_t val)
{
Serial.printf("%15s: %06u\n", name, val);
}
void printField(const char name[], const int32_t val)
{
Serial.printf("%15s: %06d\n", name, val);
}
void printField(const char name[], const int64_t val)
{
Serial.printf("%15s: %06u\n", name, (uint64_t)val);
}
void printField(const char name[], const float val)
{
Serial.printf("%15s: %4.2f\n", name, val);
}
void printField(const char name[], const char *val)
{
Serial.printf("%15s: %s\n", name, val);
}
void printInfo(const ignitionBoxStatus &info)
{
clearScreen();
setCursor(0, 0);
printField("++ Timestamp ++", (uint32_t)info.timestamp);
Serial.println("========== Coils 12 =============");
printField("Events", info.coils12.n_events);
printField("Events Missed", info.coils12.n_missed_firing);
printField("Spark Dly", (uint32_t)info.coils12.spark_delay);
printField("Spark Sts", sparkStatusNames.at(info.coils12.spark_status));
printField("Peak P_IN", info.coils12.peak_p_in);
printField("Peak N_IN", info.coils12.peak_n_in);
printField("Peak P_OUT", info.coils12.peak_p_out);
printField("Peak N_OUT", info.coils12.peak_n_out);
printField("Soft Start ", softStartStatusNames.at(info.coils12.sstart_status));
Serial.println("========== Coils 34 =============");
printField("Events", info.coils34.n_events);
printField("Events Missed", info.coils34.n_missed_firing);
printField("Spark Dly", (uint32_t)info.coils34.spark_delay);
printField("Spark Sts", sparkStatusNames.at(info.coils34.spark_status));
printField("Peak P_IN", info.coils34.peak_p_in);
printField("Peak N_IN", info.coils34.peak_n_in);
printField("Peak P_OUT", info.coils34.peak_p_out);
printField("Peak N_OUT", info.coils34.peak_n_out);
printField("Soft Start ", softStartStatusNames.at(info.coils34.sstart_status));
Serial.println("============ END ===============");
Serial.println();
printField("Engine RPM", info.eng_rpm);
printField("ADC Read Time", info.adc_read_time);
printField("Queue Errors", info.n_queue_errors);
}

204
RotaxMonitor/src/ui.h Normal file
View File

@@ -0,0 +1,204 @@
#pragma once
#include <Arduino.h>
#include <datastruct.h>
#include <string>
void clearScreen();
void setCursor(const uint8_t x, const uint8_t y);
void printField(const char name[], const uint32_t val);
void printField(const char name[], const int32_t val);
void printField(const char name[], const int64_t val);
void printField(const char name[], const float val);
void printField(const char name[], const char *val);
void printInfo(const ignitionBoxStatus &info);
static const std::string htmlTest = R"rawliteral(
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ESP32 Dashboard</title>
<style>
body {
font-family: Arial;
text-align: center;
margin-top: 40px;
}
table {
margin: auto;
border-collapse: collapse;
width: 100%;
max-width: 900px;
}
th, td {
border: 1px solid #ccc;
padding: 10px;
font-size: 16px;
text-align: left;
}
th {
background-color: #f4f4f4;
}
button {
margin: 10px;
padding: 10px 20px;
font-size: 16px;
}
</style>
</head>
<body>
<h2>RotaxMonitor realtime data</h2>
<button onclick="start()">Start</button>
<button onclick="stop()">Stop</button>
<div style="max-width: 900px; margin: 0 auto; text-align: left;">
<p><strong>Timestamp:</strong> <span id="timestamp">-</span></p>
<p><strong>Data Valid:</strong> <span id="datavalid">-</span></p>
<p><strong>Generator voltage:</strong> <span id="volts_gen">-</span></p>
<p><strong>Engine RPM:</strong> <span id="eng_rpm">-</span></p>
<p><strong>ADC read time:</strong> <span id="adc_read_time">-</span></p>
<p><strong>Queue errors:</strong> <span id="n_queue_errors">-</span></p>
<table>
<thead>
<tr>
<th>Property</th>
<th>Coils 12</th>
<th>Coils 34</th>
</tr>
</thead>
<tbody>
<tr>
<td>Spark delay</td>
<td id="coils12_spark_delay">-</td>
<td id="coils34_spark_delay">-</td>
</tr>
<tr>
<td>Spark status</td>
<td id="coils12_spark_status">-</td>
<td id="coils34_spark_status">-</td>
</tr>
<tr>
<td>Soft start status</td>
<td id="coils12_sstart_status">-</td>
<td id="coils34_sstart_status">-</td>
</tr>
<tr>
<td>Peak P in</td>
<td id="coils12_peak_p_in">-</td>
<td id="coils34_peak_p_in">-</td>
</tr>
<tr>
<td>Peak N in</td>
<td id="coils12_peak_n_in">-</td>
<td id="coils34_peak_n_in">-</td>
</tr>
<tr>
<td>Peak P out</td>
<td id="coils12_peak_p_out">-</td>
<td id="coils34_peak_p_out">-</td>
</tr>
<tr>
<td>Peak N out</td>
<td id="coils12_peak_n_out">-</td>
<td id="coils34_peak_n_out">-</td>
</tr>
<tr>
<td>Level spark</td>
<td id="coils12_level_spark">-</td>
<td id="coils34_level_spark">-</td>
</tr>
<tr>
<td>Events</td>
<td id="coils12_n_events">-</td>
<td id="coils34_n_events">-</td>
</tr>
<tr>
<td>Missed firings</td>
<td id="coils12_n_missed_firing">-</td>
<td id="coils34_n_missed_firing">-</td>
</tr>
</tbody>
</table>
</div>
<script>
let ws;
function connectWS() {
ws = new WebSocket("ws://" + location.host + "/ws");
ws.onopen = () => {
console.log("WebSocket connesso");
};
ws.onclose = () => {
console.log("WebSocket disconnesso, retry...");
setTimeout(connectWS, 5000);
};
ws.onmessage = (event) => {
let data;
try {
data = JSON.parse(event.data);
} catch (e) {
console.error("Invalid JSON received", e);
return;
}
document.getElementById("datavalid").textContent = data.datavalid ?? "-";
document.getElementById("timestamp").textContent = data.timestamp ?? "-";
document.getElementById("volts_gen").textContent = data.volts_gen ?? "-";
document.getElementById("eng_rpm").textContent = data.eng_rpm ?? "-";
document.getElementById("adc_read_time").textContent = data.adc_read_time ?? "-";
document.getElementById("n_queue_errors").textContent = data.n_queue_errors ?? "-";
const coils12 = data.coils12 || {};
const coils34 = data.coils34 || {};
document.getElementById("coils12_spark_delay").textContent = coils12.spark_delay ?? "-";
document.getElementById("coils34_spark_delay").textContent = coils34.spark_delay ?? "-";
document.getElementById("coils12_spark_status").textContent = coils12.spark_status ?? "-";
document.getElementById("coils34_spark_status").textContent = coils34.spark_status ?? "-";
document.getElementById("coils12_sstart_status").textContent = coils12.sstart_status ?? "-";
document.getElementById("coils34_sstart_status").textContent = coils34.sstart_status ?? "-";
document.getElementById("coils12_peak_p_in").textContent = coils12.peak_p_in ?? "-";
document.getElementById("coils34_peak_p_in").textContent = coils34.peak_p_in ?? "-";
document.getElementById("coils12_peak_n_in").textContent = coils12.peak_n_in ?? "-";
document.getElementById("coils34_peak_n_in").textContent = coils34.peak_n_in ?? "-";
document.getElementById("coils12_peak_p_out").textContent = coils12.peak_p_out ?? "-";
document.getElementById("coils34_peak_p_out").textContent = coils34.peak_p_out ?? "-";
document.getElementById("coils12_peak_n_out").textContent = coils12.peak_n_out ?? "-";
document.getElementById("coils34_peak_n_out").textContent = coils34.peak_n_out ?? "-";
document.getElementById("coils12_level_spark").textContent = coils12.level_spark ?? "-";
document.getElementById("coils34_level_spark").textContent = coils34.level_spark ?? "-";
document.getElementById("coils12_n_events").textContent = coils12.n_events ?? "-";
document.getElementById("coils34_n_events").textContent = coils34.n_events ?? "-";
document.getElementById("coils12_n_missed_firing").textContent = coils12.n_missed_firing ?? "-";
document.getElementById("coils34_n_missed_firing").textContent = coils34.n_missed_firing ?? "-";
};
}
function start() {
fetch("/start");
}
function stop() {
fetch("/stop");
}
connectWS();
</script>
</body>
</html>
)rawliteral";

View File

@@ -0,0 +1,14 @@
#include "utils.h"
std::string printBits(uint32_t value) {
std::string result;
for (int i = 31; i >= 0; i--) {
// ottieni il singolo bit
result += ((value >> i) & 1) ? '1' : '0';
// aggiungi uno spazio ogni 8 bit, tranne dopo l'ultimo
if (i % 8 == 0 && i != 0) {
result += ' ';
}
}
return result;
}

6
RotaxMonitor/src/utils.h Normal file
View File

@@ -0,0 +1,6 @@
#pragma once
#include <Arduino.h>
#include <string>
std::string printBits(uint32_t value);

View File

@@ -0,0 +1,98 @@
#include <webserver.h>
WebPage::WebPage(const uint8_t port, fs::FS &filesystem) : m_port(port), m_webserver(AsyncWebServer(port)), m_websocket(AsyncWebSocket("/ws")), m_filesystem(filesystem)
{
m_websocket.onEvent([this](AsyncWebSocket *server, AsyncWebSocketClient *client,
AwsEventType type, void *arg, uint8_t *data, size_t len)
{ onWsEvent(server, client, type, arg, data, len); });
m_webserver.addHandler(&m_websocket);
m_webserver.serveStatic("/", m_filesystem, "/").setDefaultFile("index.html");
m_webserver.on("/upload", HTTP_POST,
[this](AsyncWebServerRequest *request)
{ onUploadRequest(request); },
[this](AsyncWebServerRequest *request, const String &filename, size_t index, uint8_t *data, size_t len, bool final)
{ onUploadHandler(request, filename, index, data, len, final); }
);
m_webserver.begin();
}
WebPage::~WebPage()
{
m_webserver.removeHandler(&m_websocket);
m_webserver.end();
}
void WebPage::sendWsData(const String &data){
if (m_websocket.count()){
m_websocket.textAll(data);
}
}
void WebPage::onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len)
{
switch (type)
{
case WS_EVT_CONNECT:
Serial.printf("WS client IP[%s]-ID[%u] CONNECTED\r\n", client->remoteIP().toString().c_str(), client->id());
break;
case WS_EVT_DISCONNECT:
Serial.printf("WS client ID[%u] DISCONNECTED\r\n", client->remoteIP().toString().c_str(), client->id());
break;
}
}
void WebPage::onUploadRequest(AsyncWebServerRequest *request)
{
if (m_upload_failed)
request->send(500, "text/plain", "Upload failed");
else
request->send(200, "text/plain", "Upload successful");
}
void WebPage::onUploadHandler(AsyncWebServerRequest *request, const String &filename, size_t index, uint8_t *data, size_t len, bool final)
{
if (index == 0) // only on first iteration to open file
{
m_upload_failed = false;
String safeName = filename;
int slashIndex = safeName.lastIndexOf('/');
if (slashIndex >= 0)
safeName = safeName.substring(slashIndex + 1);
if (safeName.length() == 0)
{
m_upload_failed = true;
LOG_ERROR("Invalid file name");
return;
}
const std::filesystem::path filePath = std::filesystem::path(m_filesystem.mountpoint()) / safeName.c_str();
if (m_filesystem.exists(filePath.c_str()))
m_filesystem.remove(filePath.c_str());
m_upload_file = m_filesystem.open(filePath.c_str(), FILE_WRITE);
if (!m_upload_file)
{
m_upload_failed = true;
LOG_ERROR("Failed to open upload file:", filePath.c_str());
return;
}
}
// Actual write of file data
if (!m_upload_failed && m_upload_file)
{
if (m_upload_file.write(data, len) != len)
m_upload_failed = true;
}
// close the file and save on final call
if (final && m_upload_file)
{
m_upload_file.close();
if (!m_upload_failed)
LOG_INFO("Uploaded file to LittleFS:", filename.c_str());
}
}

View File

@@ -0,0 +1,38 @@
#pragma once
#define DEBUGLOG_DEFAULT_LOG_LEVEL_INFO
// System includes
#include <Arduino.h>
#include <DebugLog.h>
#include <ESPAsyncWebServer.h>
#include <AsyncTCP.h>
#include <filesystem>
#include <FS.h>
class WebPage
{
const uint8_t m_port = 80;
fs::FS &m_filesystem;
AsyncWebServer m_webserver;
AsyncWebSocket m_websocket;
bool m_upload_failed = false;
fs::File m_upload_file;
public:
WebPage(const uint8_t port, fs::FS &filesystem);
~WebPage();
void sendWsData(const String &data);
private:
void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client,
AwsEventType type, void *arg, uint8_t *data, size_t len);
void onUploadRequest(AsyncWebServerRequest *request);
void onUploadHandler(AsyncWebServerRequest *request, const String &filename, size_t index, uint8_t *data, size_t len, bool final);
void onStart(AsyncWebServerRequest *request);
void onStop(AsyncWebServerRequest *request);
void onDownload(AsyncWebServerRequest *request);
};

5
RotaxMonitorTester/.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch

View File

@@ -0,0 +1,10 @@
{
"recommendations": [
"Jason2866.esp-decoder",
"pioarduino.pioarduino-ide",
"platformio.platformio-ide"
],
"unwantedRecommendations": [
"ms-vscode.cpptools-extension-pack"
]
}

View File

@@ -0,0 +1,37 @@
This directory is intended for project header files.
A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.
```src/main.c
#include "header.h"
int main (void)
{
...
}
```
Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.
In C, the convention is to give header files names that end with `.h'.
Read more about using header files in official GCC documentation:
* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html

View File

@@ -0,0 +1,46 @@
This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into the executable file.
The source code of each library should be placed in a separate directory
("lib/your_library_name/[Code]").
For example, see the structure of the following example libraries `Foo` and `Bar`:
|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional. for custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- README --> THIS FILE
|
|- platformio.ini
|--src
|- main.c
Example contents of `src/main.c` using Foo and Bar:
```
#include <Foo.h>
#include <Bar.h>
int main (void)
{
...
}
```
The PlatformIO Library Dependency Finder will find automatically dependent
libraries by scanning project source files.
More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html

View File

@@ -0,0 +1,39 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:esp32-devtest-release]
board = esp32dev
platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip
framework = arduino
lib_deps =
hideakitai/DebugLog@^0.8.4
board_build.flash_size = 4MB
board_build.partitions = default.csv
monitor_speed = 921600
build_type = release
[env:esp32-devtest-debug]
board = esp32dev
platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip
lib_deps =
hideakitai/DebugLog@^0.8.4
board_build.flash_size = 4MB
board_build.partitions = default.csv
monitor_speed = 921600
build_type = debug
build_flags =
-O0
-g3
-ggdb
-fno-inline
-fno-ipa-sra
-fno-tree-sra
-fno-builtin

View File

@@ -0,0 +1,132 @@
#include <Arduino.h>
#include <DebugLog.h>
#include "timer.h"
#include <map>
static hw_timer_t *timerA = NULL;
static hw_timer_t *timerB = NULL;
TaskHandle_t main_t = NULL;
static uint32_t count = 0;
#define FREQUENCY 100000 // 100 KHz
#define PERIOD_US 10
#define SPARK_DLY_MIN 10
#define SPARK_DLY_MAX 490
#define PAUSE_LONG_MIN 5000
#define PAUSE_LONG_MAX PAUSE_LONG_MIN*100
#define RPM_MIN 800
#define RPM_MAX 5500
void clearScreen(){
Serial.print("\033[2J"); // clear screen
Serial.print("\033[H"); // cursor home
Serial.flush();
}
static double filtered_rpm = 0;
static const std::map<const uint32_t, const char *> pin2Name = {
{PIN_TRIG_A12P, "HIGH_PIN_TRIG_A12P"},
{~PIN_TRIG_A12P, "LOW_PIN_TRIG_A12P"},
{PIN_TRIG_A12N, "HIGH_PIN_TRIG_A12N"},
{~PIN_TRIG_A12N, "LOW_PIN_TRIG_A12N"},
{PIN_TRIG_A34P, "HIGH_PIN_TRIG_A34P"},
{~PIN_TRIG_A34P, "LOW_PIN_TRIG_A34P"},
{PIN_TRIG_A34N, "HIGH_PIN_TRIG_A34N"},
{~PIN_TRIG_A34N, "LOW_PIN_TRIG_A34N"},
{SPARK_A12, "HIGH_SPARK_A12"},
{~SPARK_A12, "LOW_SPARK_A12"},
{SPARK_A34, "HIGH_SPARK_A34"},
{~SPARK_A34, "LOW_SPARK_A34"},
{State::S_WAIT_10MS_END, "S_WAIT_10MS_END"},
{State::S_WAIT_10MS, "S_WAIT_10MS"}};
static timerStatus stsA = {
.clock_period_us = (uint32_t)PERIOD_US,
.pause_long_us = 10000,
.pause_short_us = 1000,
.coil_pulse_us = 1000,
.spark_pulse_us = 100,
.spark_delay_us = 50,
.main_task = NULL};
static bool isEnabled = false;
void setup()
{
Serial.begin(921600);
delay(1000);
LOG_ATTACH_SERIAL(Serial);
pinMode(PIN_TRIG_A12P, OUTPUT);
pinMode(PIN_TRIG_A12N, OUTPUT);
pinMode(PIN_TRIG_A34P, OUTPUT);
pinMode(PIN_TRIG_A34N, OUTPUT);
pinMode(SPARK_A12, OUTPUT);
pinMode(SPARK_A34, OUTPUT);
pinMode(PIN_TRIG_B12P, OUTPUT);
pinMode(PIN_TRIG_B12N, OUTPUT);
pinMode(PIN_TRIG_B34P, OUTPUT);
pinMode(PIN_TRIG_B34N, OUTPUT);
pinMode(SPARK_B12, OUTPUT);
pinMode(SPARK_B34, OUTPUT);
pinMode(SPARK_DELAY_POT, ANALOG);
pinMode(FREQ_POT, ANALOG);
pinMode(ENABLE_PIN, INPUT_PULLUP);
stsA.main_task = xTaskGetCurrentTaskHandleForCore(1);
timerA = timerBegin(FREQUENCY);
timerStop(timerA);
timerAttachInterruptArg(timerA, &onTimer, (void *)&stsA);
timerAlarm(timerA, 1, true, 0);
LOG_INFO("Setup Complete");
}
void loop()
{
LOG_INFO("Loop: ", count++);
uint32_t spark_delay = (uint32_t)(map(analogRead(SPARK_DELAY_POT), 0, 4096, SPARK_DLY_MIN, SPARK_DLY_MAX) / PERIOD_US);
stsA.spark_delay_us = spark_delay * PERIOD_US;
if (stsA.spark_delay_us > (SPARK_DLY_MIN + SPARK_DLY_MAX) / 2) {
stsA.soft_start = true;
stsA.spark_delay_us -= (SPARK_DLY_MIN + SPARK_DLY_MAX) / 2;
} else {
stsA.soft_start = false;
}
double new_rpm = (double)(map(analogRead(FREQ_POT), 0, 4096, RPM_MIN, RPM_MAX));
filtered_rpm = filtered_rpm + 0.1 * (new_rpm - filtered_rpm);
stsA.pause_long_us = (uint32_t)(60000000.0f / filtered_rpm / 2.0f);
if (isEnabled) {
LOG_INFO("==== System is ENABLED ====");
} else {
LOG_INFO("==== System is DISABLED ====");
}
LOG_INFO("Spark Delay uS: ", stsA.spark_delay_us, "\tSoft Start: ", stsA.soft_start ? "TRUE" : "FALSE");
LOG_INFO("Engine Rpm: ", (uint32_t)(filtered_rpm));
LOG_INFO("Coil Pulse: ", stsA.coil_pulse_us, "us");
LOG_INFO("Spark Pulse: ", stsA.spark_pulse_us, "us");
if (digitalRead(ENABLE_PIN) == LOW && !isEnabled) {
timerStart(timerA);
isEnabled = true;
} else if (digitalRead(ENABLE_PIN) == HIGH && isEnabled) {
timerStop(timerA);
isEnabled = false;
}
delay(100);
clearScreen();
}

View File

@@ -0,0 +1,26 @@
#pragma once
// Enable Pin
#define ENABLE_PIN 16
///// Ignition Box A /////
#define PIN_TRIG_A12P 18
#define PIN_TRIG_A12N 19
#define PIN_TRIG_A34P 21
#define PIN_TRIG_A34N 22
#define SPARK_A12 23
#define SPARK_A34 25
///// Ignition Box /////
#define PIN_TRIG_B12P 26
#define PIN_TRIG_B12N 27
#define PIN_TRIG_B34P 32
#define PIN_TRIG_B34N 33
#define SPARK_B12 4
#define SPARK_B34 5
// Pot
#define SPARK_DELAY_POT 13
#define FREQ_POT 14

View File

@@ -0,0 +1,192 @@
#include "timer.h"
volatile static bool wait_sent = false;
void onTimer(void *arg)
{
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
timerStatus *params = (timerStatus *)(arg);
TaskHandle_t task = params->main_task;
// increment state time
params->state_time += params->clock_period_us;
digitalWrite(PIN_TRIG_B12P, HIGH);
switch (params->state)
{
case S_12P:
if (params->state_time == params->clock_period_us && !params->coil12p_high)
{
// xTaskNotifyFromISR(task, PIN_TRIG_A12P, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
digitalWrite(PIN_TRIG_A12P, HIGH);
params->coil12p_high = true;
wait_sent = false;
}
if (!params->soft_start)
{
if (params->state_time == params->spark_delay_us)
{
// xTaskNotifyFromISR(task, SPARK_A12, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
digitalWrite(SPARK_A12, HIGH);
}
if (params->state_time == (params->spark_delay_us + params->spark_pulse_us))
{
// xTaskNotifyFromISR(task, ~SPARK_A12, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
digitalWrite(SPARK_A12, LOW);
}
}
if (params->state_time >= params->coil_pulse_us && params->coil12p_high)
{
// xTaskNotifyFromISR(task, ~PIN_TRIG_A12P, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
digitalWrite(PIN_TRIG_A12P, LOW);
params->coil12p_high = false;
}
if (params->state_time >= params->pause_short_us)
{
params->state = S_12N;
params->state_time = 0;
}
break;
case S_12N:
if (params->state_time == params->clock_period_us && !params->coil12n_high)
{
// xTaskNotifyFromISR(task, PIN_TRIG_A12N, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
digitalWrite(PIN_TRIG_A12N, HIGH);
params->coil12n_high = true;
}
if (params->soft_start)
{
if (params->state_time == params->spark_delay_us)
{
// xTaskNotifyFromISR(task, SPARK_A12, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
digitalWrite(SPARK_A12, HIGH);
}
if (params->state_time == (params->spark_delay_us + params->spark_pulse_us))
{
// xTaskNotifyFromISR(task, ~SPARK_A12, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
digitalWrite(SPARK_A12, LOW);
}
}
if (params->state_time >= params->coil_pulse_us && params->coil12n_high)
{
// xTaskNotifyFromISR(task, ~PIN_TRIG_A12N, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
digitalWrite(PIN_TRIG_A12N, LOW);
params->coil12n_high = false;
params->state = S_WAIT_10MS;
params->state_time = 0;
}
break;
case S_WAIT_10MS:
if (!wait_sent)
{
// xTaskNotifyFromISR(task, S_WAIT_10MS, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
wait_sent = true;
}
if (params->state_time >= params->pause_long_us)
{
params->state = S_34P;
params->state_time = 0;
}
break;
case S_34P:
if (params->state_time == params->clock_period_us && !params->coil34p_high)
{
// xTaskNotifyFromISR(task, PIN_TRIG_A34P, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
digitalWrite(PIN_TRIG_A34P, HIGH);
params->coil34p_high = true;;
wait_sent = false;
}
if (!params->soft_start)
{
if (params->state_time == params->spark_delay_us)
{
// xTaskNotifyFromISR(task, SPARK_A34, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
digitalWrite(SPARK_A34, HIGH);
}
if (params->state_time == params->spark_delay_us + params->spark_pulse_us)
{
// xTaskNotifyFromISR(task, ~SPARK_A34, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
digitalWrite(SPARK_A34, LOW);
}
}
if (params->state_time >= params->coil_pulse_us && params->coil34p_high)
{
// xTaskNotifyFromISR(task, ~PIN_TRIG_A34P, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
digitalWrite(PIN_TRIG_A34P, LOW);
params->coil34p_high = false;
}
if (params->state_time >= params->pause_short_us)
{
params->state = S_34N;
params->state_time = 0;
}
break;
case S_34N:
if (params->state_time == params->clock_period_us && !params->coil34n_high)
{
// xTaskNotifyFromISR(task, PIN_TRIG_A34N, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
digitalWrite(PIN_TRIG_A34N, HIGH);
params->coil34n_high = true;
}
if (params->soft_start)
{
if (params->state_time == params->spark_delay_us)
{
// xTaskNotifyFromISR(task, SPARK_A34, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
digitalWrite(SPARK_A34, HIGH);
}
if (params->state_time == params->spark_delay_us + params->spark_pulse_us)
{
// xTaskNotifyFromISR(task, ~SPARK_A34, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
digitalWrite(SPARK_A34, LOW);
}
}
if (params->state_time >= params->coil_pulse_us && params->coil34n_high)
{
// xTaskNotifyFromISR(task, ~PIN_TRIG_A34N, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
digitalWrite(PIN_TRIG_A34N, LOW);
params->coil34n_high = false;
params->state = S_WAIT_10MS_END;
params->state_time = 0;
}
break;
case S_WAIT_10MS_END:
if (!wait_sent)
{
// xTaskNotifyFromISR(task, S_WAIT_10MS_END, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
wait_sent = true;
}
if (params->state_time >= params->pause_long_us)
{
params->state = S_12P;
params->state_time = 0;
}
break;
}
digitalWrite(PIN_TRIG_B12P, LOW);
if (xHigherPriorityTaskWoken)
portYIELD_FROM_ISR();
}

View File

@@ -0,0 +1,40 @@
#pragma once
#include <Arduino.h>
#include <DebugLog.h>
#include "pins.h"
#include "driver/gpio.h"
enum State
{
S_12P,
S_12N_DELAY,
S_12N,
S_WAIT_10MS,
S_34P,
S_34N_DELAY,
S_34N,
S_WAIT_1MS,
S_WAIT_10MS_END
};
struct timerStatus
{
State state = State::S_12P;
uint32_t state_time = 0;
uint32_t clock_period_us;
uint32_t pause_long_us;
uint32_t pause_short_us;
uint32_t coil_pulse_us;
uint32_t spark_pulse_us;
uint32_t spark_delay_us;
bool soft_start = false;
bool coil12p_high = false;
bool coil34p_high = false;
bool coil12n_high = false;
bool coil34n_high = false;
TaskHandle_t main_task;
};
void IRAM_ATTR onTimer(void *arg);

View File

@@ -0,0 +1,11 @@
This directory is intended for PlatformIO Test Runner and project tests.
Unit Testing is a software testing method by which individual units of
source code, sets of one or more MCU program modules together with associated
control data, usage procedures, and operating procedures, are tested to
determine whether they are fit for use. Unit testing finds problems early
in the development cycle.
More information about PlatformIO Unit Testing:
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html