25 Commits

Author SHA1 Message Date
Emanuele Trabattoni
bea29dc8f5 ADC ok with interrupt or drdy 2026-04-17 12:21:35 +02:00
Emanuele Trabattoni
1b8ba88b05 ADC working ok in sync with system 2026-04-17 11:01:41 +02:00
5aa5aaa07a ADC Testing 2026-04-17 09:13:05 +02:00
1b7a531d54 Updated test instrument with cli commands 2026-04-17 09:11:41 +02:00
8171cab9cb adc ok 2026-04-14 14:16:11 +02:00
Emanuele Trabattoni
899c8cffbc io expander class ok , adc not working 2026-04-14 11:02:33 +02:00
Emanuele Trabattoni
782aa95ee6 Merge branch 'task-refactor' 2026-04-13 10:28:24 +02:00
Emanuele Trabattoni
212b37c95f updated and fixed charts 2026-04-13 10:26:55 +02:00
Emanuele Trabattoni
f8c3c69e80 fix graph 2026-04-12 14:42:40 +02:00
Emanuele Trabattoni
7da58c8a49 Set time from browser 2026-04-12 14:40:58 +02:00
a153402d28 webpage chats 2026-04-12 02:38:27 +02:00
095aa59f36 task refactoring working, sometimes misses events, check priorities 2026-04-12 01:45:32 +02:00
Emanuele Trabattoni
fdba6d5ad5 refactor continued, at least it compiles 2026-04-11 16:39:59 +02:00
Emanuele Trabattoni
d1b96e932c task refactoring work in progress 2026-04-11 15:49:40 +02:00
684c34e209 adding pins and task class 2026-04-11 12:27:19 +02:00
37fa6a686f Merge branch 'datasave' 2026-04-11 11:40:20 +02:00
9c012efef1 refactor led class 2026-04-11 11:37:40 +02:00
d41a99ee88 rgb led 2026-04-11 00:40:33 +02:00
eaeb515074 Modified Task display to order based on task number or arbitraruy function 2026-04-10 23:33:22 +02:00
246ba7eeb2 Task A+B concurrency <check ok without ADC 2026-04-10 22:03:09 +02:00
Emanuele Trabattoni
736a8d8bd5 modified to also read channel B 2026-04-10 12:12:28 +02:00
Emanuele Trabattoni
2083119d79 Updated interface to show Box A+B 2026-04-10 09:27:41 +02:00
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
38 changed files with 3488 additions and 1536 deletions

View File

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

File diff suppressed because one or more lines are too long

View File

@@ -1,88 +1,212 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ESP32 Dashboard</title>
<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>
<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>
<!-- TAB BUTTONS -->
<div class="tabs">
<button class="tab-button active" onclick="openTab('tab1')">Monitor</button>
<button class="tab-button" onclick="openTab('tab2')">Grafico</button>
</div>
<!-- TAB 1 (contenuto attuale) -->
<div id="tab1" class="tab-content active">
<div id="loadingIndicator" class="loading-indicator">
<span class="spinner"></span> Waiting for data...
</div>
<div class="tables-container">
<div class="box">
<h2>Box_A</h2>
<div class="box-data">
<p><strong>Timestamp:</strong> <span id="a_timestamp">-</span></p>
<p><strong>Data Valid:</strong> <span id="a_datavalid">-</span></p>
<p><strong>Generator voltage:</strong> <span id="a_volts_gen">-</span></p>
<p><strong>ADC read time:</strong> <span id="a_adc_read_time">-</span></p>
<p><strong>Queue errors:</strong> <span id="a_n_queue_errors">-</span></p>
</div>
<div class="rpm-highlight">
<strong>Engine RPM:</strong> <span id="a_eng_rpm">-</span>
</div>
<table>
<thead>
<tr>
<th>Property</th>
<th>Pickup 12</th>
<th>Pickup 34</th>
</tr>
</thead>
<tbody>
<tr>
<td>Spark delay</td>
<td id="a_coils12_spark_delay">-</td>
<td id="a_coils34_spark_delay">-</td>
</tr>
<tr>
<td>Spark status</td>
<td id="a_coils12_spark_status">-</td>
<td id="a_coils34_spark_status">-</td>
</tr>
<tr>
<td>Soft start status</td>
<td id="a_coils12_sstart_status">-</td>
<td id="a_coils34_sstart_status">-</td>
</tr>
<tr>
<td>Peak P in</td>
<td id="a_coils12_peak_p_in">-</td>
<td id="a_coils34_peak_p_in">-</td>
</tr>
<tr>
<td>Peak N in</td>
<td id="a_coils12_peak_n_in">-</td>
<td id="a_coils34_peak_n_in">-</td>
</tr>
<tr>
<td>Peak P out</td>
<td id="a_coils12_peak_p_out">-</td>
<td id="a_coils34_peak_p_out">-</td>
</tr>
<tr>
<td>Peak N out</td>
<td id="a_coils12_peak_n_out">-</td>
<td id="a_coils34_peak_n_out">-</td>
</tr>
<tr>
<td>Level spark</td>
<td id="a_coils12_level_spark">-</td>
<td id="a_coils34_level_spark">-</td>
</tr>
<tr>
<td>Spark Events</td>
<td id="a_coils12_n_events">-</td>
<td id="a_coils34_n_events">-</td>
</tr>
<tr>
<td>Missed Events</td>
<td id="a_coils12_n_missed_firing">-</td>
<td id="a_coils34_n_missed_firing">-</td>
</tr>
</tbody>
</table>
</div>
<div class="box">
<h2>Box_B</h2>
<div class="box-data">
<p><strong>Timestamp:</strong> <span id="b_timestamp">-</span></p>
<p><strong>Data Valid:</strong> <span id="b_datavalid">-</span></p>
<p><strong>Generator voltage:</strong> <span id="b_volts_gen">-</span></p>
<p><strong>ADC read time:</strong> <span id="b_adc_read_time">-</span></p>
<p><strong>Queue errors:</strong> <span id="b_n_queue_errors">-</span></p>
</div>
<div class="rpm-highlight">
<strong>Engine RPM:</strong> <span id="b_eng_rpm">-</span>
</div>
<table>
<thead>
<tr>
<th>Property</th>
<th>Pickup 12</th>
<th>Pickup 34</th>
</tr>
</thead>
<tbody>
<tr>
<td>Spark delay</td>
<td id="b_coils12_spark_delay">-</td>
<td id="b_coils34_spark_delay">-</td>
</tr>
<tr>
<td>Spark status</td>
<td id="b_coils12_spark_status">-</td>
<td id="b_coils34_spark_status">-</td>
</tr>
<tr>
<td>Soft start status</td>
<td id="b_coils12_sstart_status">-</td>
<td id="b_coils34_sstart_status">-</td>
</tr>
<tr>
<td>Peak P in</td>
<td id="b_coils12_peak_p_in">-</td>
<td id="b_coils34_peak_p_in">-</td>
</tr>
<tr>
<td>Peak N in</td>
<td id="b_coils12_peak_n_in">-</td>
<td id="b_coils34_peak_n_in">-</td>
</tr>
<tr>
<td>Peak P out</td>
<td id="b_coils12_peak_p_out">-</td>
<td id="b_coils34_peak_p_out">-</td>
</tr>
<tr>
<td>Peak N out</td>
<td id="b_coils12_peak_n_out">-</td>
<td id="b_coils34_peak_n_out">-</td>
</tr>
<tr>
<td>Level spark</td>
<td id="b_coils12_level_spark">-</td>
<td id="b_coils34_level_spark">-</td>
</tr>
<tr>
<td>Spark Events</td>
<td id="b_coils12_n_events">-</td>
<td id="b_coils34_n_events">-</td>
</tr>
<tr>
<td>Missed Events</td>
<td id="b_coils12_n_missed_firing">-</td>
<td id="b_coils34_n_missed_firing">-</td>
</tr>
</tbody>
</table>
</div>
</div>
</div> <!-- END TAB1 -->
<!-- TAB 2 (grafico) -->
<div id="tab2" class="tab-content">
<div class="chart-container">
<h3>Box A</h3>
<canvas id="chartA" height="100"></canvas>
</div>
<div class="chart-container">
<h3>Box B</h3>
<canvas id="chartB" height="100"></canvas>
</div>
</div>
<script src="script.js"></script>
</body>
<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="chart.js"></script>
<script src="script.js"></script>
</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.2,37.6 53.9,37.6 "/>
<rect x="61.5" y="37.1" class="st0" width="1.4" height="8.9"/>
<path class="st0" d="M70.3,41.8c-0.1-0.4-0.2-0.8-0.4-1.2c-0.2-0.3-0.5-0.6-0.9-0.8c-0.4-0.2-0.8-0.3-1.3-0.3c-0.5,0-1,0.1-1.5,0.4
c-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.2,0.4,1.7c0.3,0.5,0.6,0.9,1.1,1.2c0.4,0.3,0.9,0.4,1.5,0.4
c0.5,0,0.9-0.1,1.3-0.3c0.4-0.2,0.7-0.4,0.9-0.7c0.2-0.3,0.4-0.7,0.5-1.1h-1.4c-0.1,0.3-0.2,0.5-0.4,0.7c-0.2,0.2-0.5,0.2-0.8,0.2
c-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.2C70.4,42.6,70.4,42.2,70.3,41.8z M66.2,42.3
c0-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.3c0.3,0,0.5,0.1,0.7,0.2c0.2,0.1,0.3,0.3,0.4,0.4
c0.1,0.2,0.2,0.4,0.2,0.6c0,0.2,0,0.3,0,0.5H66.2z"/>
<path class="st0" d="M73.8,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.4,0.3-0.8,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2,1,0.4,1.5,0.4c0.6,0,1.1-0.1,1.5-0.4c0.5-0.2,0.8-0.6,1.1-1.1
c0.3-0.5,0.4-1.1,0.4-1.8c0-0.7-0.1-1.4-0.4-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.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0.4,0.2,0.8,0.3,1.3,0.3c0.5,0,0.9-0.1,1.2-0.3
c0.3-0.2,0.6-0.5,0.7-0.9l0.1,1h1.2v-4c0-0.6-0.1-1-0.3-1.4C223.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-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,0.6-1.5,0.9-2.8,0.9h-3.2V10.6z"/>
<path class="st0" d="M123.7,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,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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,0.7,0.3,0.7,0.7C38.1,18.4,37.7,18.8,37.3,18.8z"/>
<path class="st0" d="M360.9,50.7v0.7c0.3,0,0.6-0.1,0.9-0.3v4.6h0.7v-5.3h-0.5C361.6,50.5,361.3,50.7,360.9,50.7z"/>
<rect x="341" y="52.9" class="st0" width="2.3" height="0.6"/>
<path class="st0" d="M332.1,50.4c-0.3-0.1-0.5-0.2-0.8-0.2c-0.6,0-1,0.1-1.3,0.4c-0.3,0.3-0.5,0.7-0.5,1.2c0,0.5,0.2,0.9,0.5,1.2
c0.3,0.3,0.7,0.5,1.1,0.5c0.4,0,0.8-0.1,1.1-0.3c0.3-0.2,0.4-0.6,0.5-1c0,0.2,0,0.4,0,0.6c0,1.1-0.3,1.9-0.8,2.2
c-0.2,0.1-0.4,0.2-0.7,0.2c-0.3,0-0.5-0.1-0.7-0.3c-0.2-0.2-0.3-0.4-0.3-0.8h-0.7c0,0.5,0.2,0.9,0.5,1.2c0.3,0.3,0.8,0.5,1.4,0.5
c0.3,0,0.6-0.1,0.9-0.2c0.8-0.4,1.2-1.3,1.2-2.7c0-0.8-0.2-1.4-0.6-1.9C332.6,50.7,332.3,50.5,332.1,50.4z M332,52.6
c-0.2,0.2-0.5,0.3-0.8,0.3s-0.6-0.1-0.8-0.3c-0.2-0.2-0.3-0.4-0.3-0.8c0-0.3,0.1-0.6,0.3-0.8c0.2-0.2,0.5-0.3,0.8-0.3
c0.3,0,0.6,0.1,0.8,0.3c0.2,0.2,0.3,0.4,0.3,0.7C332.3,52.2,332.2,52.4,332,52.6z"/>
<path class="st0" d="M347,54.2c0.1-0.1,0.3-0.3,0.6-0.4l1.1-0.4c0.4-0.2,0.7-0.4,0.9-0.6c0.2-0.3,0.3-0.6,0.3-1
c0-0.4-0.2-0.8-0.5-1.1c-0.3-0.3-0.8-0.4-1.3-0.4c-0.5,0-1,0.1-1.3,0.4c-0.3,0.2-0.5,0.6-0.6,1.1h0.7c0-0.3,0.2-0.5,0.4-0.6
c0.2-0.1,0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.3,0.4c-0.3,0.2-0.5,0.6-0.6,1.1h0.7c0-0.3,0.2-0.5,0.4-0.6
c0.2-0.1,0.5-0.2,0.8-0.2c0.3,0,0.6,0.1,0.8,0.3c0.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.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,1.8-0.4c1.1,0,2.1,0.4,2.9,1.3c0.8,0.9,1.2,1.9,1.2,3.3c0,1.4-0.4,2.5-1.3,3.4
c-0.8,0.9-1.9,1.3-3.1,1.3c-0.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

View File

@@ -1,14 +1,60 @@
let ws;
let lastMessageTimestamp = 0;
const IDLE_THRESHOLD_MS = 1000;
const loadingIndicator = document.getElementById("loadingIndicator");
let chartA, chartB;
let dataA = {
labels: [],
datasets: [
{ label: "RPM", data: [] },
{ label: "Coils12 Delay", data: [] },
{ label: "Coils34 Delay", data: [] }
]
};
let dataB = {
labels: [],
datasets: [
{ label: "RPM", data: [] },
{ label: "Coils12 Delay", data: [] },
{ label: "Coils34 Delay", data: [] }
]
};
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.send(JSON.stringify({
cmd: "setTime",
time: Math.floor(Date.now() / 1000)
}));
};
ws.onclose = () => {
console.log("WebSocket disconnesso, retry...");
setLoadingIndicator(false);
setTimeout(connectWS, 5000);
};
@@ -22,39 +68,128 @@ function connectWS() {
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 ?? "-";
lastMessageTimestamp = Date.now();
setLoadingIndicator(false);
const coils12 = data.coils12 || {};
const coils34 = data.coils34 || {};
updateCharts(data)
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 ?? "-";
// Update Box_A
if (data.box_a) {
const boxA = data.box_a;
document.getElementById("a_datavalid").textContent = boxA.datavalid ?? "-";
document.getElementById("a_timestamp").textContent = boxA.timestamp ?? "-";
document.getElementById("a_volts_gen").textContent = boxA.volts_gen ?? "-";
document.getElementById("a_eng_rpm").textContent = boxA.eng_rpm ?? "-";
document.getElementById("a_adc_read_time").textContent = boxA.adc_read_time ?? "-";
document.getElementById("a_n_queue_errors").textContent = boxA.n_queue_errors ?? "-";
const coils12A = boxA.coils12 || {};
const coils34A = boxA.coils34 || {};
document.getElementById("a_coils12_spark_delay").textContent = coils12A.spark_delay ?? "-";
document.getElementById("a_coils34_spark_delay").textContent = coils34A.spark_delay ?? "-";
document.getElementById("a_coils12_spark_status").textContent = coils12A.spark_status ?? "-";
document.getElementById("a_coils34_spark_status").textContent = coils34A.spark_status ?? "-";
document.getElementById("a_coils12_sstart_status").textContent = coils12A.sstart_status ?? "-";
document.getElementById("a_coils34_sstart_status").textContent = coils34A.sstart_status ?? "-";
document.getElementById("a_coils12_peak_p_in").textContent = coils12A.peak_p_in ?? "-";
document.getElementById("a_coils34_peak_p_in").textContent = coils34A.peak_p_in ?? "-";
document.getElementById("a_coils12_peak_n_in").textContent = coils12A.peak_n_in ?? "-";
document.getElementById("a_coils34_peak_n_in").textContent = coils34A.peak_n_in ?? "-";
document.getElementById("a_coils12_peak_p_out").textContent = coils12A.peak_p_out ?? "-";
document.getElementById("a_coils34_peak_p_out").textContent = coils34A.peak_p_out ?? "-";
document.getElementById("a_coils12_peak_n_out").textContent = coils12A.peak_n_out ?? "-";
document.getElementById("a_coils34_peak_n_out").textContent = coils34A.peak_n_out ?? "-";
document.getElementById("a_coils12_level_spark").textContent = coils12A.level_spark ?? "-";
document.getElementById("a_coils34_level_spark").textContent = coils34A.level_spark ?? "-";
document.getElementById("a_coils12_n_events").textContent = coils12A.n_events ?? "-";
document.getElementById("a_coils34_n_events").textContent = coils34A.n_events ?? "-";
document.getElementById("a_coils12_n_missed_firing").textContent = coils12A.n_missed_firing ?? "-";
document.getElementById("a_coils34_n_missed_firing").textContent = coils34A.n_missed_firing ?? "-";
}
// Update Box_B
if (data.box_b) {
const boxB = data.box_b;
document.getElementById("b_datavalid").textContent = boxB.datavalid ?? "-";
document.getElementById("b_timestamp").textContent = boxB.timestamp ?? "-";
document.getElementById("b_volts_gen").textContent = boxB.volts_gen ?? "-";
document.getElementById("b_eng_rpm").textContent = boxB.eng_rpm ?? "-";
document.getElementById("b_adc_read_time").textContent = boxB.adc_read_time ?? "-";
document.getElementById("b_n_queue_errors").textContent = boxB.n_queue_errors ?? "-";
const coils12B = boxB.coils12 || {};
const coils34B = boxB.coils34 || {};
document.getElementById("b_coils12_spark_delay").textContent = coils12B.spark_delay ?? "-";
document.getElementById("b_coils34_spark_delay").textContent = coils34B.spark_delay ?? "-";
document.getElementById("b_coils12_spark_status").textContent = coils12B.spark_status ?? "-";
document.getElementById("b_coils34_spark_status").textContent = coils34B.spark_status ?? "-";
document.getElementById("b_coils12_sstart_status").textContent = coils12B.sstart_status ?? "-";
document.getElementById("b_coils34_sstart_status").textContent = coils34B.sstart_status ?? "-";
document.getElementById("b_coils12_peak_p_in").textContent = coils12B.peak_p_in ?? "-";
document.getElementById("b_coils34_peak_p_in").textContent = coils34B.peak_p_in ?? "-";
document.getElementById("b_coils12_peak_n_in").textContent = coils12B.peak_n_in ?? "-";
document.getElementById("b_coils34_peak_n_in").textContent = coils34B.peak_n_in ?? "-";
document.getElementById("b_coils12_peak_p_out").textContent = coils12B.peak_p_out ?? "-";
document.getElementById("b_coils34_peak_p_out").textContent = coils34B.peak_p_out ?? "-";
document.getElementById("b_coils12_peak_n_out").textContent = coils12B.peak_n_out ?? "-";
document.getElementById("b_coils34_peak_n_out").textContent = coils34B.peak_n_out ?? "-";
document.getElementById("b_coils12_level_spark").textContent = coils12B.level_spark ?? "-";
document.getElementById("b_coils34_level_spark").textContent = coils34B.level_spark ?? "-";
document.getElementById("b_coils12_n_events").textContent = coils12B.n_events ?? "-";
document.getElementById("b_coils34_n_events").textContent = coils34B.n_events ?? "-";
document.getElementById("b_coils12_n_missed_firing").textContent = coils12B.n_missed_firing ?? "-";
document.getElementById("b_coils34_n_missed_firing").textContent = coils34B.n_missed_firing ?? "-";
}
};
}
function updateCharts(data) {
const t = new Date().toLocaleTimeString();
// ===== BOX A =====
dataA.labels.push(t);
if (data.box_a) {
dataA.datasets[0].data.push(data.box_a.eng_rpm / 10);
dataA.datasets[1].data.push(data.box_a.coils12.spark_delay);
dataA.datasets[2].data.push(data.box_a.coils34.spark_delay);
} else {
dataA.datasets[0].data.push(undefined);
dataA.datasets[1].data.push(undefined);
dataA.datasets[2].data.push(undefined);
}
// ===== BOX B =====
dataB.labels.push(t);
if (data.box_b) {
dataB.datasets[0].data.push(data.box_b.eng_rpm / 10);
dataB.datasets[1].data.push(data.box_b.coils12.spark_delay);
dataB.datasets[2].data.push(data.box_b.coils34.spark_delay);
} else {
dataB.datasets[0].data.push(undefined);
dataB.datasets[1].data.push(undefined);
dataB.datasets[2].data.push(undefined);
}
// limite buffer
const maxPoints = 100;
if (dataA.labels.length > maxPoints) {
dataA.labels.shift();
dataA.datasets.forEach(d => d.data.shift());
}
if (dataB.labels.length > maxPoints) {
dataB.labels.shift();
dataB.datasets.forEach(d => d.data.shift());
}
chartA.update();
chartB.update();
}
function start() {
fetch("/start");
}
@@ -63,4 +198,95 @@ 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;
});
}
function openTab(tabId) {
document.querySelectorAll('.tab-content').forEach(tab => {
tab.classList.remove('active');
});
document.querySelectorAll('.tab-button').forEach(btn => {
btn.classList.remove('active');
});
document.getElementById(tabId).classList.add('active');
event.target.classList.add('active');
}
function initCharts() {
const ctxA = document.getElementById('chartA').getContext('2d');
const ctxB = document.getElementById('chartB').getContext('2d');
chartA = new Chart(ctxA, {
type: 'line',
data: dataA,
options: {
animation: false,
responsive: true,
scales: {
x: {
display: true
},
y: {
beginAtZero: true
}
}
}
});
chartB = new Chart(ctxB, {
type: 'line',
data: dataB,
options: {
animation: false,
responsive: true,
scales: {
x: {
display: true
},
y: {
beginAtZero: true
}
}
}
});
}
window.onload = () => {
initCharts();
};
setInterval(updateLoadingState, 200);
connectWS();

View File

@@ -1,7 +1,49 @@
: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: Arial;
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;
margin: auto;
}
.page-header h1 {
margin: auto;
margin-top: 20px;
text-align: center;
margin-top: 40px;
font-size: 28px;
font-weight: 600;
}
table {
@@ -9,21 +51,209 @@ table {
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 #ccc;
padding: 10px;
font-size: 16px;
text-align: left;
border: 1px solid var(--border-color);
padding: 12px;
font-size: 14px;
text-align: center;
}
th {
background-color: #f4f4f4;
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);
}
}
.tables-container {
display: flex;
gap: 20px;
max-width: 1800px;
margin: 0 auto;
padding: 0 20px;
}
.box {
flex: 1;
background: white;
padding: 20px;
border-radius: 6px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
.box h2 {
margin-top: 0;
margin-bottom: 16px;
color: var(--primary-blue);
font-size: 18px;
font-weight: 700;
text-align: center;
}
.box-data {
margin-bottom: 20px;
}
.box-data p {
margin: 8px 0;
font-size: 14px;
}
.box-data strong {
color: var(--primary-blue);
}
.rpm-highlight {
background: #c6e4fa;
border: 3px double var(--primary-blue);
border-radius: 8px;
padding: 12px 16px;
margin-bottom: 20px;
text-align: center;
font-size: 18px;
font-weight: bold;
color: var(--text-dark);
}
.rpm-highlight strong {
color: var(--primary-blue);
}
span {
color: var(--text-dark);
}
/* TABS */
.tabs {
display: flex;
justify-content: center;
margin: 20px;
}
.tab-button {
padding: 10px 20px;
margin: 0 5px;
border: none;
cursor: pointer;
background: var(--border-color);
border-radius: 4px;
}
.tab-button.active {
background: var(--primary-blue);
color: white;
}
.tab-content {
display: none;
}
.tab-content.active {
display: block;
}
.chart-container {
max-width: 1000px;
margin: 20px auto;
background: white;
padding: 20px;
border-radius: 6px;
box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,11 +1,11 @@
//ADS1256 header file
// ADS1256 header file
/*
Name: ADS1256.h
Created: 2022/07/14
Author: Curious Scientist
Editor: Notepad++
Comment: Visit https://curiousscientist.tech/blog/ADS1256-custom-library
Special thanks to
Special thanks to
Abraão Queiroz for spending time on the code and suggesting corrections for ESP32 microcontrollers
Benjamin Pelletier for pointing out and fixing an issue around the handling of the DRDY signal
*/
@@ -14,51 +14,55 @@
#define _ADS1256_h
#include <SPI.h>
#include <Arduino.h>
//Differential inputs
#define DIFF_0_1 0b00000001 //A0 + A1 as differential input
#define DIFF_2_3 0b00100011 //A2 + A3 as differential input
#define DIFF_4_5 0b01000101 //A4 + A5 as differential input
#define DIFF_6_7 0b01100111 //A6 + A7 as differential input
// SPI Frequency
#define SPI_FREQ 1920000
//Single-ended inputs
#define SING_0 0b00001111 //A0 + GND (common) as single-ended input
#define SING_1 0b00011111 //A1 + GND (common) as single-ended input
#define SING_2 0b00101111 //A2 + GND (common) as single-ended input
#define SING_3 0b00111111 //A3 + GND (common) as single-ended input
#define SING_4 0b01001111 //A4 + GND (common) as single-ended input
#define SING_5 0b01011111 //A5 + GND (common) as single-ended input
#define SING_6 0b01101111 //A6 + GND (common) as single-ended input
#define SING_7 0b01111111 //A7 + GND (common) as single-ended input
// Differential inputs
#define DIFF_0_1 0b00000001 // A0 + A1 as differential input
#define DIFF_2_3 0b00100011 // A2 + A3 as differential input
#define DIFF_4_5 0b01000101 // A4 + A5 as differential input
#define DIFF_6_7 0b01100111 // A6 + A7 as differential input
//PGA settings //Input voltage range
#define PGA_1 0b00000000 //± 5 V
#define PGA_2 0b00000001 //± 2.5 V
#define PGA_4 0b00000010 //± 1.25 V
#define PGA_8 0b00000011 //± 625 mV
#define PGA_16 0b00000100 //± 312.5 mV
// Single-ended inputs
#define SING_0 0b00001111 // A0 + GND (common) as single-ended input
#define SING_1 0b00011111 // A1 + GND (common) as single-ended input
#define SING_2 0b00101111 // A2 + GND (common) as single-ended input
#define SING_3 0b00111111 // A3 + GND (common) as single-ended input
#define SING_4 0b01001111 // A4 + GND (common) as single-ended input
#define SING_5 0b01011111 // A5 + GND (common) as single-ended input
#define SING_6 0b01101111 // A6 + GND (common) as single-ended input
#define SING_7 0b01111111 // A7 + GND (common) as single-ended input
// PGA settings //Input voltage range
#define PGA_1 0b00000000 // ± 5 V
#define PGA_2 0b00000001 // ± 2.5 V
#define PGA_4 0b00000010 // ± 1.25 V
#define PGA_8 0b00000011 // ± 625 mV
#define PGA_16 0b00000100 // ± 312.5 mV
#define PGA_32 0b00000101 //+ 156.25 mV
#define PGA_64 0b00000110 //± 78.125 mV
#define PGA_64 0b00000110 // ± 78.125 mV
//Datarate //DEC
#define DRATE_30000SPS 0b11110000 //240
#define DRATE_15000SPS 0b11100000 //224
#define DRATE_7500SPS 0b11010000 //208
#define DRATE_3750SPS 0b11000000 //192
#define DRATE_2000SPS 0b10110000 //176
#define DRATE_1000SPS 0b10100001 //161
#define DRATE_500SPS 0b10010010 //146
#define DRATE_100SPS 0b10000010 //130
#define DRATE_60SPS 0b01110010 //114
#define DRATE_50SPS 0b01100011 //99
#define DRATE_30SPS 0b01010011 //83
#define DRATE_25SPS 0b01000011 //67
#define DRATE_15SPS 0b00110011 //51
#define DRATE_10SPS 0b00100011 //35
#define DRATE_5SPS 0b00010011 //19
#define DRATE_2SPS 0b00000011 //3
// Datarate //DEC
#define DRATE_30000SPS 0b11110000 // 240
#define DRATE_15000SPS 0b11100000 // 224
#define DRATE_7500SPS 0b11010000 // 208
#define DRATE_3750SPS 0b11000000 // 192
#define DRATE_2000SPS 0b10110000 // 176
#define DRATE_1000SPS 0b10100001 // 161
#define DRATE_500SPS 0b10010010 // 146
#define DRATE_100SPS 0b10000010 // 130
#define DRATE_60SPS 0b01110010 // 114
#define DRATE_50SPS 0b01100011 // 99
#define DRATE_30SPS 0b01010011 // 83
#define DRATE_25SPS 0b01000011 // 67
#define DRATE_15SPS 0b00110011 // 51
#define DRATE_10SPS 0b00100011 // 35
#define DRATE_5SPS 0b00010011 // 19
#define DRATE_2SPS 0b00000011 // 3
//Status register
// Status register
#define BITORDER_MSB 0
#define BITORDER_LSB 1
#define ACAL_DISABLED 0
@@ -66,7 +70,7 @@
#define BUFFER_DISABLED 0
#define BUFFER_ENABLED 1
//Register addresses
// Register addresses
#define STATUS_REG 0x00
#define MUX_REG 0x01
#define ADCON_REG 0x02
@@ -79,7 +83,7 @@
#define FSC1_REG 0x09
#define FSC2_REG 0x0A
//Command definitions
// Command definitions
#define WAKEUP 0b00000000
#define RDATA 0b00000001
#define RDATAC 0b00000011
@@ -96,26 +100,30 @@
#define RESET 0b11111110
//----------------------------------------------------------------
class ADS1256
{
{
public:
static constexpr int8_t PIN_UNUSED = -1;
static constexpr int8_t PIN_UNUSED = -1;
//Constructor
ADS1256(const int8_t DRDY_pin, const int8_t RESET_pin, const int8_t SYNC_pin, const int8_t CS_pin, float VREF, SPIClass* spi = &SPI);
//Initializing function
void InitializeADC();
//ADS1256(int drate, int pga, int byteOrder, bool bufen);
//Read a register
// Constructor
ADS1256(const int8_t DRDY_pin, const int8_t RESET_pin, const int8_t SYNC_pin, const int8_t CS_pin, float VREF, SPIClass *spi = &SPI);
~ADS1256()
{
vSemaphoreDelete(m_drdyHigh);
vSemaphoreDelete(m_drdyLow);
}
// Initializing function
void InitializeADC();
// ADS1256(int drate, int pga, int byteOrder, bool bufen);
// Read a register
long readRegister(uint8_t registerAddress);
//Write a register
void writeRegister(uint8_t registerAddress, uint8_t registerValueToWrite);
//Individual methods
// Write a register
void writeRegister(uint8_t registerAddress, uint8_t registerValueToWrite);
// Individual methods
void setDRATE(uint8_t drate);
void setPGA(uint8_t pga);
uint8_t getPGA();
@@ -128,62 +136,80 @@ static constexpr int8_t PIN_UNUSED = -1;
uint8_t getAutoCal();
void setGPIO(uint8_t dir0, uint8_t dir1, uint8_t dir2, uint8_t dir3);
void writeGPIO(uint8_t dir0value, uint8_t dir1value, uint8_t dir2value, uint8_t dir3value);
uint8_t readGPIO(uint8_t gpioPin);
uint8_t readGPIO(uint8_t gpioPin);
void setCLKOUT(uint8_t clkout);
void setSDCS(uint8_t sdcs);
void sendDirectCommand(uint8_t directCommand);
void setSDCS(uint8_t sdcs);
void sendDirectCommand(uint8_t directCommand);
//Get a single conversion
// Get a single conversion
long readSingle();
//Single input continuous reading
// Single input continuous reading
long readSingleContinuous();
//Cycling through the single-ended inputs
long cycleSingle(); //Ax + COM
//Cycling through the differential inputs
long cycleDifferential(); //Ax + Ay
//Converts the reading into a voltage value
// Cycling through the single-ended inputs
long cycleSingle(); // Ax + COM
// Cycling through the differential inputs
long cycleDifferential(); // Ax + Ay
// Converts the reading into a voltage value
float convertToVoltage(int32_t rawData);
//Stop AD
// Stop AD
void stopConversion();
// functions for callback
inline uint8_t getDRDYpin()
{
return m_DRDY_pin;
}
SemaphoreHandle_t getDRDYsemaphoreHigh()
{
return m_drdyHigh;
}
SemaphoreHandle_t getDRDYsemaphoreLow()
{
return m_drdyLow;
}
private:
SPIClass* _spi; //Pointer to an SPIClass object
SPIClass *_spi; // Pointer to an SPIClass object
void waitForLowDRDY(); // Block until DRDY is low
void waitForHighDRDY(); // Block until DRDY is high
void updateMUX(uint8_t muxValue);
inline void CS_LOW();
inline void CS_HIGH();
void waitForLowDRDY(); // Block until DRDY is low
void waitForHighDRDY(); // Block until DRDY is high
void updateMUX(uint8_t muxValue);
inline void CS_LOW();
inline void CS_HIGH();
void updateConversionParameter(); //Refresh the conversion parameter based on the PGA
void updateConversionParameter(); // Refresh the conversion parameter based on the PGA
float _VREF = 0; //Value of the reference voltage
float conversionParameter = 0; //PGA-dependent multiplier
//Pins
int8_t _DRDY_pin; //Pin assigned for DRDY
int8_t _RESET_pin; //Pin assigned for RESET
int8_t _SYNC_pin; //Pin assigned for SYNC
int8_t _CS_pin; //Pin assigned for CS
float m_VREF = 0; // Value of the reference voltage
float m_conversionParameter = 0; // PGA-dependent multiplier
// Pins
int8_t m_DRDY_pin; // Pin assigned for DRDY
int8_t m_RESET_pin; // Pin assigned for RESET
int8_t m_SYNC_pin; // Pin assigned for SYNC
int8_t m_CS_pin; // Pin assigned for CS
//Register values
byte _DRATE; //Value of the DRATE register
byte _ADCON; //Value of the ADCON register
byte _MUX; //Value of the MUX register
byte _PGA; //Value of the PGA (within ADCON)
byte _GPIO; //Value of the GPIO register
byte _STATUS; //Value of the status register
byte _GPIOvalue; //GPIO value
byte _ByteOrder; //Byte order
// Register values
uint8_t m_DRATE; // Value of the DRATE register
uint8_t m_ADCON; // Value of the ADCON register
uint8_t m_MUX; // Value of the MUX register
uint8_t m_PGA; // Value of the PGA (within ADCON)
uint8_t m_GPIO; // Value of the GPIO register
uint8_t m_STATUS; // Value of the status register
uint8_t m_GPIOvalue; // GPIO value
uint8_t m_ByteOrder; // Byte order
byte _outputBuffer[3]; //3-byte (24-bit) buffer for the fast acquisition - Single-channel, continuous
long _outputValue; //Combined value of the _outputBuffer[3]
bool _isAcquisitionRunning; //bool that keeps track of the acquisition (running or not)
uint8_t _cycle; //Tracks the cycles as the MUX is cycling through the input channels
uint8_t m_outputBuffer[3]; // 3-byte (24-bit) buffer for the fast acquisition - Single-channel, continuous
int32_t m_outputValue; // Combined value of the m_outputBuffer[3]
bool m_isAcquisitionRunning; // bool that keeps track of the acquisition (running or not)
uint8_t m_cycle; // Tracks the cycles as the MUX is cycling through the input channels
SemaphoreHandle_t m_drdyHigh;
SemaphoreHandle_t m_drdyLow;
};
#endif

View File

@@ -0,0 +1,38 @@
#include <led.h>
RGBled::RGBled(const uint8_t pin) : m_led(pin)
{
pinMode(m_led, OUTPUT);
writeStatus(RGBled::ERROR);
m_brightness = 1.0f;
}
RGBled::~RGBled()
{
pinMode(m_led, INPUT);
}
void RGBled::setBrightness(const float b)
{
m_brightness = b;
}
void RGBled::setStatus(const LedStatus s)
{
if (m_status == s)
return;
std::lock_guard<std::mutex> lock(m_mutex);
m_status = s;
writeStatus(m_status);
}
const RGBled::LedStatus RGBled::getSatus(void)
{
return m_status;
}
void RGBled::writeStatus(const RGBled::LedStatus s)
{
const RGBled::color_u u{.status = s};
rgbLedWrite(m_led, (uint8_t)(m_brightness*u.color.r), (uint8_t)(m_brightness*u.color.g), (uint8_t)(m_brightness*u.color.b));
}

View File

@@ -0,0 +1,65 @@
#pragma once
// System Inlcudes
#include <Arduino.h>
#include <mutex>
#define RED 0x00FF00
#define GREEN 0xFF0000
#define BLUE 0x0000FF
#define WHITE 0xFFFFFF
#define YELLOW 0xFFFF00
#define CYAN 0xFF00FF
#define MAGENTA 0x00FFFF
#define ORANGE 0xA5FF00
#define PURPLE 0x008080
#define PINK 0x69FFB4
#define LIME 0xCD3232
#define SKY_BLUE 0xCE87EB
#define GOLD 0xD7FF00
#define TURQUOISE 0xE040D0
#define INDIGO 0x004B82
#define GRAY 0x808080
class RGBled
{
public:
enum LedStatus
{
OK = GREEN,
ERROR = RED,
INIT = YELLOW,
DATA_A = CYAN,
DATA_B = MAGENTA,
DATA_ALL = ORANGE,
IDLE = GRAY
};
struct color_t
{
uint8_t a, r, g, b;
};
union color_u
{
uint32_t status;
color_t color;
};
public:
RGBled(const uint8_t pin = 48);
~RGBled();
void setBrightness(const float b);
void setStatus(const LedStatus s);
const LedStatus getSatus(void);
private:
void writeStatus(const LedStatus s);
private:
LedStatus m_status = LedStatus::IDLE;
std::mutex m_mutex;
float m_brightness;
const uint8_t m_led;
};

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

@@ -20,23 +20,22 @@ lib_deps =
hideakitai/PCA95x5@^0.1.3
me-no-dev/AsyncTCP@^3.3.2
me-no-dev/ESPAsyncWebServer@^3.6.0
adafruit/Adafruit NeoPixel@^1.15.4
upload_protocol = esptool
upload_port = COM4
upload_port = /dev/ttyACM1
upload_speed = 921600
monitor_port = COM4
monitor_port = /dev/ttyACM0
monitor_speed = 921600
build_type = release
build_flags =
-DCORE_DEBUG_LEVEL=5
-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_PRIORITY=21
-DCONFIG_ASYNC_TCP_QUEUE_SIZE=64
-DCONFIG_ASYNC_TCP_RUNNING_CORE=1
-DCONFIG_ASYNC_TCP_STACK_SIZE=8192
-DCONFIG_ASYNC_TCP_STACK_SIZE=4096
-fstack-protector-all
[env:esp32-s3-devkitc1-n16r8-debug]
@@ -47,10 +46,11 @@ platform = ${env:esp32-s3-devkitc1-n16r8.platform}
framework = ${env:esp32-s3-devkitc1-n16r8.framework}
lib_deps =
${env:esp32-s3-devkitc1-n16r8.lib_deps}
adafruit/Adafruit NeoPixel@^1.15.4
upload_protocol = esptool
upload_port = COM8
upload_port = /dev/ttyACM1
upload_speed = 921600
monitor_port = COM4
monitor_port = /dev/ttyACM0
monitor_speed = 921600
debug_tool = esp-builtin
debug_speed = 15000
@@ -62,10 +62,8 @@ build_flags =
-DCORE_DEBUG_LEVEL=5
-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_PRIORITY=21
-DCONFIG_ASYNC_TCP_QUEUE_SIZE=128
-DCONFIG_ASYNC_TCP_RUNNING_CORE=1
-DCONFIG_ASYNC_TCP_STACK_SIZE=8192

View File

@@ -1,28 +1,45 @@
#include "datasave.h"
#include <math.h>
static const size_t min_free = 1024 * 1024; // minimum free space in SPIFFS 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);
}
}
void ignitionBoxStatusAverage::filter(int32_t &old, const int32_t value, const uint32_t k)
LITTLEFSGuard::~LITTLEFSGuard()
{
LittleFS.end();
LOG_INFO("LittleFS unmounted successfully");
}
void ignitionBoxStatusFiltered::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)
void ignitionBoxStatusFiltered::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()
void ignitionBoxStatusFiltered::reset()
{
m_last = ignitionBoxStatus();
m_count = 0;
m_data_valid = false;
}
void ignitionBoxStatusAverage::update(const ignitionBoxStatus &new_status)
void ignitionBoxStatusFiltered::update(const ignitionBoxStatus &new_status)
{
if (m_count == 0 && !m_data_valid)
{
@@ -30,8 +47,7 @@ void ignitionBoxStatusAverage::update(const ignitionBoxStatus &new_status)
}
m_count++;
// simple moving average calculation
m_last.timestamp = new_status.timestamp; // keep timestamp of latest status
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
@@ -42,18 +58,18 @@ void ignitionBoxStatusAverage::update(const ignitionBoxStatus &new_status)
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
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
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;
if (m_count >= m_max_count)
{
@@ -62,7 +78,7 @@ void ignitionBoxStatusAverage::update(const ignitionBoxStatus &new_status)
}
}
const bool ignitionBoxStatusAverage::get(ignitionBoxStatus &status) const
const bool ignitionBoxStatusFiltered::get(ignitionBoxStatus &status) const
{
if (m_data_valid)
{
@@ -71,7 +87,7 @@ const bool ignitionBoxStatusAverage::get(ignitionBoxStatus &status) const
return m_data_valid;
}
const ArduinoJson::JsonDocument ignitionBoxStatusAverage::toJson() const
const ArduinoJson::JsonDocument ignitionBoxStatusFiltered::toJson() const
{
ArduinoJson::JsonDocument doc;
if (m_data_valid)
@@ -105,97 +121,3 @@ const ArduinoJson::JsonDocument ignitionBoxStatusAverage::toJson() const
}
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 spiffs_guard = LITTLEFSGuard(); // use RAII guard to ensure SPIFFS 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

@@ -4,46 +4,26 @@
// System Includes
#include <Arduino.h>
#include <DebugLog.h>
#include <LittleFS.h>
#include <string>
#include <fstream>
#include <filesystem>
#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 SPIFFS, 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()
{
if (!LittleFS.begin(true))
{
LOG_ERROR("Failed to mount LittleFS");
}
LOG_INFO("SPIFFS mounted successfully");
}
~LITTLEFSGuard()
{
LittleFS.end();
LOG_INFO("LittleFS unmounted successfully");
}
LITTLEFSGuard();
~LITTLEFSGuard();
};
class ignitionBoxStatusAverage
class ignitionBoxStatusFiltered
{
private:
ignitionBoxStatus m_last;
@@ -52,8 +32,9 @@ private:
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) {
ignitionBoxStatusFiltered() = default;
ignitionBoxStatusFiltered(const uint32_t max_count) : m_max_count(max_count)
{
m_data_valid = false;
m_count = 0;
}
@@ -67,7 +48,3 @@ 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

@@ -1,6 +1,7 @@
#pragma once
#include <Arduino.h>
#include <map>
#include <psvector.h>
// =====================
// Event Flags (bitmask)
@@ -88,3 +89,7 @@ struct ignitionBoxStatus
uint32_t n_queue_errors = 0;
int32_t adc_read_time = 0;
};
template <typename T>
using PSRAMVector = std::vector<T, PSRAMAllocator<T>>;

View File

@@ -3,35 +3,53 @@
// Library defines
#define ADS1256_SPI_ALREADY_STARTED
// System Includes
#include <memory>
// Device Libraries
#include <ADS1256.h>
#include <AD5292.h>
#include <PCA95x5.h>
#include <extio.h>
#include <Wire.h>
// ADC Channel mapping
#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
#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_a = NULL, *pot_b = NULL;
ADS1256 *adc_a = NULL, *adc_b = NULL;
PCA9555* io = NULL;
struct Devices
{
// Busses
std::unique_ptr<TwoWire> m_i2c = nullptr;
std::unique_ptr<SPIClass> m_spi_a = nullptr;
std::unique_ptr<SPIClass> m_spi_b = nullptr;
// Bus Mutextes
std::mutex m_spi_a_mutex;
std::mutex m_spi_b_mutex;
std::mutex m_i2c_mutex;
// Device Pointers
std::unique_ptr<AD5292> m_pot_a = nullptr;
std::unique_ptr<AD5292> m_pot_b = nullptr;
std::unique_ptr<ADS1256> m_adc_a = nullptr;
std::unique_ptr<ADS1256> m_adc_b = nullptr;
std::unique_ptr<ExternalIO> m_ext_io = nullptr;
};
// Adc read channel wrapper to selet mux before reading
inline float adcReadChannel(ADS1256* adc, const uint8_t ch){
inline float adcReadChannel(ADS1256 *adc, const uint8_t ch)
{
adc->setMUX(ch);
// scarta 3 conversioni
for (int i = 0; i < 3; i++) {
adc->readSingle();
}
adc->readSingle();
// ora lettura valida a 30kSPS → ~100 µs di settling
return adc->convertToVoltage(adc->readSingle());
}

129
RotaxMonitor/src/extio.cpp Normal file
View File

@@ -0,0 +1,129 @@
#include <extio.h>
// Static interrupt callback
static void onExpanderInterrupt(void *arg)
{
auto cls = (ExternalIO *)(arg);
if (!cls) // invalid args
return;
cls->extReadInterrupt();
}
ExternalIO::ExternalIO(TwoWire &i2c, std::mutex &i2c_mutex, const uint8_t int_pin) : m_i2cMutex(i2c_mutex), m_i2c(i2c), m_intPin(int_pin)
{
std::lock_guard<std::mutex> lock(m_i2cMutex);
// Attach OUT expanders on BUS
m_outMap[EXPANDER_A_OUT_ADDR] = std::make_unique<PCA9555>();
m_outMap[EXPANDER_A_OUT_ADDR]->attach(m_i2c, EXPANDER_A_OUT_ADDR);
m_outMap[EXPANDER_B_OUT_ADDR] = std::make_unique<PCA9555>();
m_outMap[EXPANDER_B_OUT_ADDR]->attach(m_i2c, EXPANDER_B_OUT_ADDR);
for (auto &[a, e] : m_outMap)
{
e->direction(PCA95x5::Direction::OUT_ALL);
e->polarity(PCA95x5::Polarity::ORIGINAL_ALL);
};
// Attach IN Expanders on Bus
m_inMap[EXPANDER_A_IN_ADDR] = std::make_unique<PCA9555>();
m_inMap[EXPANDER_A_IN_ADDR]->attach(m_i2c, EXPANDER_A_IN_ADDR);
m_inMap[EXPANDER_B_IN_ADDR] = std::make_unique<PCA9555>();
m_inMap[EXPANDER_B_IN_ADDR]->attach(m_i2c, EXPANDER_B_IN_ADDR);
for (auto &[a, e] : m_inMap)
{
e->direction(PCA95x5::Direction::IN_ALL);
e->polarity(PCA95x5::Polarity::ORIGINAL_ALL);
m_lastInputState[a] = e->read(); /// initialize input state to collect interrupts
};
}
ExternalIO::~ExternalIO() {
}
void ExternalIO::extDigitalWrite(const uint32_t mappedPin, const bool val)
{
std::lock_guard<std::mutex> lock(m_i2cMutex);
const io_t pa = map2pin(mappedPin);
if (!m_outMap.contains(pa.addr))
{
LOG_ERROR("Undefined IO Expander addr: [", pa.addr, "]");
return;
}
auto &io = m_outMap.at(pa.addr);
if (!io->write(static_cast<PCA95x5::Port::Port>(pa.pin), val ? PCA95x5::Level::H : PCA95x5::Level::L))
{
LOG_ERROR("IO Expander [", pa.addr, "] Unable to WRITE Port [", pa.pin, "] to [", val ? "HIGH" : "LOW");
LOG_ERROR("IO Expander Error [", io->i2c_error(), "]");
}
}
const bool ExternalIO::extDigitalRead(const uint32_t mappedPin)
{
std::lock_guard<std::mutex> lock(m_i2cMutex);
const io_t pa = map2pin(mappedPin);
if (!m_inMap.contains(pa.addr))
{
LOG_ERROR("Undefined IO Expander addr: [", pa.addr, "]");
return false;
}
auto &io = m_inMap.at(pa.addr);
const bool rv = io->read(static_cast<PCA95x5::Port::Port>(pa.pin)) == PCA95x5::Level::H ? true : false; // read value
const uint8_t err = io->i2c_error();
if (err)
{
LOG_ERROR("IO Expander [", pa.addr, "] Unable to READ Port [", pa.pin, "]");
LOG_ERROR("IO Expander Error [", err, "]");
}
return rv;
}
void ExternalIO::extAttachInterrupt(ExtInterruptCb cb)
{
attachInterruptArg(EXPANDER_ALL_INTERRUPT, onExpanderInterrupt, (void *)(this), FALLING);
m_extInterruptCb = cb;
}
void ExternalIO::extDetachInterrupt()
{
detachInterrupt(EXPANDER_ALL_INTERRUPT);
}
void ExternalIO::extReadInterrupt()
{
std::lock_guard<std::mutex> lock(m_i2cMutex);
disableInterrupt(EXPANDER_ALL_INTERRUPT);
// read all registers and collect
IOstate interruptState;
for (auto &[a, e] : m_inMap)
{
interruptState[a] = e->read();
}
m_lastInputState = interruptState; // restore to current values
// compare to last state to see the difference
if (m_extInterruptCb)
{
for (auto &[a, v] : interruptState)
{
if (v)
m_extInterruptCb(stat2map(a, v));
}
}
enableInterrupt(EXPANDER_ALL_INTERRUPT);
}
const ExternalIO::io_t ExternalIO::map2pin(const uint32_t mappedIO)
{
return io_t{
.addr = (uint8_t)((mappedIO >> 16) & (uint8_t)0xFF),
.pin = (uint8_t)(mappedIO && (uint32_t)0xFF),
};
}
const uint32_t ExternalIO::stat2map(const uint8_t addr, const uint16_t stat)
{
if (!stat)
return 0;
return (uint32_t)(addr << 16) | (1UL << __builtin_ctz(stat));
}

49
RotaxMonitor/src/extio.h Normal file
View File

@@ -0,0 +1,49 @@
#pragma once
#define DEBUGLOG_DEFAULT_LOG_LEVEL_DEBUG
#include <Arduino.h>
#include <DebugLog.h>
#include <PCA95x5.h>
#include <pins.h>
#include <memory>
#include <map>
class ExternalIO
{
using IOptr = std::unique_ptr<PCA9555>;
using IOmap = std::map<const uint8_t, IOptr>;
using IOstate = std::map<const uint8_t, uint16_t>;
using ExtInterruptCb = std::function<void(const uint32_t)>;
struct io_t
{
uint8_t addr;
uint8_t pin;
};
public:
ExternalIO(TwoWire &i2c, std::mutex &i2c_mutex, const uint8_t int_pin);
~ExternalIO();
void extDigitalWrite(const uint32_t mappedPin, const bool val);
const bool extDigitalRead(const uint32_t mappedPin);
void extAttachInterrupt(ExtInterruptCb cb = nullptr);
void extDetachInterrupt();
void extReadInterrupt();
private:
const io_t map2pin(const uint32_t mappedIO);
const uint32_t stat2map(const uint8_t addr, const uint16_t stat);
private:
const uint8_t m_intPin;
IOmap m_inMap;
IOmap m_outMap;
uint8_t m_intPinChanged;
IOstate m_lastInputState;
ExtInterruptCb m_extInterruptCb = nullptr;
std::mutex &m_i2cMutex;
TwoWire &m_i2c;
};

View File

@@ -4,7 +4,7 @@
// ISR (Pass return bitmask to ISR management function)
// one function for each wake up pin conncted to a trigger
// =====================
void trig_isr(void *arg)
void trig_isr_A(void *arg)
{
const int64_t time_us = esp_timer_get_time();
@@ -50,4 +50,53 @@ void trig_isr(void *arg)
if (xHigherPriorityTaskWoken)
portYIELD_FROM_ISR();
}
}
void trig_isr_B(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

@@ -16,8 +16,8 @@
#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 RT_TASK_STACK 2048 // in words
#define RT_TASK_PRIORITY (configMAX_PRIORITIES - 5) // highest priority after wifi tasks
struct isrParams
{
@@ -26,4 +26,5 @@ struct isrParams
TaskHandle_t rt_handle_ptr;
};
void IRAM_ATTR trig_isr(void *arg);
void IRAM_ATTR trig_isr_A(void *arg);
void IRAM_ATTR trig_isr_B(void *arg);

View File

@@ -1,4 +1,4 @@
#define DEBUGLOG_DEFAULT_LOG_LEVEL_INFO
#define DEBUGLOG_DEFAULT_LOG_LEVEL_DEBUG
// Arduino Libraries
#include <Arduino.h>
@@ -7,38 +7,23 @@
#include <SPI.h>
#include <WiFi.h>
#include <ArduinoJson.h>
#include <ESPAsyncWebServer.h>
#include <AsyncTCP.h>
// Definitions
#include <tasks.h>
#include <devices.h>
#include <datasave.h>
#include <webserver.h>
#include <ui.h>
#include <led.h>
// FreeRTOS directives
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
// Defines to enable channel B
// #define CH_B_ENABLE
#define TEST
// Debug Defines
#define WIFI_SSID "AstroRotaxMonitor"
#define WIFI_PASSWORD "maledettirotax"
void 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;
}
}
#define PSRAM_MAX 4096
#define QUEUE_MAX 256
void setup()
{
@@ -61,11 +46,6 @@ void setup()
LOG_DEBUG("ESP32 Heap:", ESP.getHeapSize());
LOG_DEBUG("ESP32 Sketch:", ESP.getFreeSketchSpace());
// Initialize Interrupt pins on PICKUP detectors
initTriggerPinsInputs();
// Initialize Interrupt pins on SPARK detectors
initSparkPinInputs();
// Init Wifi station
LOG_INFO("Initializing WiFi...");
WiFi.mode(WIFI_AP);
@@ -73,6 +53,7 @@ void setup()
IPAddress gateway(10, 11, 12, 1);
IPAddress subnet(255, 255, 255, 0);
WiFi.softAPConfig(local_IP, gateway, subnet);
WiFi.setTxPower(WIFI_POWER_5dBm); // reduce wifi power
if (WiFi.softAP(WIFI_SSID, WIFI_PASSWORD))
{
LOG_INFO("WiFi AP Mode Started");
@@ -87,74 +68,42 @@ void setup()
vTaskDelay(pdMS_TO_TICKS(5000));
esp_restart();
}
// Initialize Interrupt pins on PICKUP detectors
initTriggerPinsInputs();
// Initialize Interrupt pins on SPARK detectors
initSparkPinInputs();
}
////////////////////// MAIN LOOP //////////////////////
void loop()
{
// global variables
RGBled led;
led.setBrightness(0.025f);
led.setStatus(RGBled::LedStatus::INIT);
std::shared_ptr<Devices> dev = std::make_shared<Devices>();
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;
std::mutex fs_mutex;
LITTLEFSGuard fsGuard;
// 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_12p = RST_EXT_A12P, .rst_io_12n = RST_EXT_A12N, .rst_io_34p = RST_EXT_A34P, .rst_io_34n = RST_EXT_A34N}};
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
//////// INIT SPI INTERFACES ////////
bool spiA_ok = true;
bool spiB_ok = true;
// Init 2 SPI interfaces
LOG_DEBUG("Init 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
#ifndef TEST
LOG_DEBUG("Init SPI A ok");
#ifdef CH_B_ENABLE
delay(50);
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
LOG_DEBUG("Init SPI B ok");
#endif
if (!spiA_ok || !spiB_ok)
{
LOG_ERROR("Unable to Initialize SPI Busses");
@@ -162,126 +111,170 @@ void loop()
vTaskDelay(pdMS_TO_TICKS(5000));
esp_restart();
}
dev->m_spi_a.reset(&SPI_A);
#ifdef CH_B_ENABLE
dev->m_spi_b.reset(&SPI_B);
#endif
// Init ADCs
dev->m_adc_a = std::make_unique<ADS1256>(ADC_A_DRDY, ADS1256::PIN_UNUSED, ADS1256::PIN_UNUSED, ADC_A_CS, 2.5, &SPI_A);
#ifdef CH_B_ENABLE
dev->m_adc_b = std::make_unique<ADS1256>(ADC_B_DRDY, ADS1256::PIN_UNUSED, ADS1256::PIN_UNUSED, ADC_B_CS, 2.5, &SPI_B);
#endif
// Configure ADCs
dev->m_adc_a->InitializeADC();
dev->m_adc_a->setPGA(PGA_1);
dev->m_adc_a->setDRATE(DRATE_7500SPS);
#ifdef CH_B_ENABLE
dev->m_adc_b->InitializeADC();
dev->m_adc_b->setPGA(PGA_1);
dev->m_adc_b->setDRATE(DRATE_30000SPS);
#endif
LOG_DEBUG("Init SPI OK");
// Init ADC_A
dev.adc_a = new ADS1256(ADC_A_DRDY, ADS1256::PIN_UNUSED, ADC_A_SYNC, ADC_A_CS, 2.5, &SPI_A);
dev.adc_a->InitializeADC();
dev.adc_a->setPGA(PGA_1);
dev.adc_a->setDRATE(DRATE_7500SPS);
#ifndef TEST
// 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);
// 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);
#endif
if ((ignA_task_success && ignB_task_success) != pdPASS)
//////// INIT I2C INTERFACES ////////
LOG_DEBUG("Init I2C Interfaces");
bool i2c_ok = true;
i2c_ok = Wire.begin(SDA, SCL, 100000);
if (!i2c_ok)
{
LOG_ERROR("Una ble to initialize ISR task");
LOG_ERROR("Unable to Initialize I2C Bus");
LOG_ERROR("5 seconds to restart...");
vTaskDelay(pdMS_TO_TICKS(5000));
esp_restart();
}
LOG_DEBUG("Real Time Tasks A & B initialized");
// Init IO Expanders
// dev->m_ext_io = std::make_unique<ExternalIO>(Wire, dev->m_i2c_mutex, EXPANDER_ALL_INTERRUPT);
////////////////////// MAIN LOOP //////////////////////
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);
//////// INIT REALTIME TASKS PARAMETERS ////////
const rtIgnitionTask::rtTaskParams taskA_params{
.rt_running = true,
.name = "rtIgnTask_A",
.rt_stack_size = RT_TASK_STACK,
.rt_priority = RT_TASK_PRIORITY,
.rt_int = rtIgnitionTask::rtTaskInterruptParams{
.isr_ptr = &trig_isr_A,
.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_io = rtIgnitionTask::rtTaskIOParams{
.pot_cs_12 = POT_CS_A12,
.pot_cs_34 = POT_CS_A34,
.ss_force = SS_FORCE_A,
.ss_inhibit_12 = SS_INIBHIT_A12,
.ss_inhibit_34 = SS_INHIBIT_A34,
.sh_disch_12 = SH_DISCH_A12,
.sh_disch_34 = SH_DISCH_A34,
.sh_arm_12 = SH_ARM_A12,
.sh_arm_34 = SH_ARM_A34,
.relay_in_12 = RELAY_IN_A12,
.relay_in_34 = RELAY_OUT_A12,
.relay_out_12 = RELAY_IN_A34,
.relay_out_34 = RELAY_OUT_A34,
},
.rt_queue = nullptr,
.dev = dev};
// Initialize Web page
AsyncWebServer server(80);
AsyncWebSocket ws("/ws");
ws.onEvent(onWsEvent);
server.addHandler(&ws);
server.serveStatic("/", LittleFS, "/").setDefaultFile("index.html");
server.begin();
const rtIgnitionTask::rtTaskParams taskB_params{
.rt_running = true,
.name = "rtIgnTask_B",
.rt_stack_size = RT_TASK_STACK,
.rt_priority = RT_TASK_PRIORITY,
.rt_int = rtIgnitionTask::rtTaskInterruptParams{
.isr_ptr = &trig_isr_B,
.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_io = rtIgnitionTask::rtTaskIOParams{
.pot_cs_12 = POT_CS_B12,
.pot_cs_34 = POT_CS_B34,
.ss_force = SS_FORCE_B,
.ss_inhibit_12 = SS_INIBHIT_B12,
.ss_inhibit_34 = SS_INHIBIT_B34,
.sh_disch_12 = SH_DISCH_B12,
.sh_disch_34 = SH_DISCH_B34,
.sh_arm_12 = SH_ARM_B12,
.sh_arm_34 = SH_ARM_B34,
.relay_in_12 = RELAY_IN_B12,
.relay_in_34 = RELAY_OUT_B12,
.relay_out_12 = RELAY_IN_B34,
.relay_out_34 = RELAY_OUT_B34,
},
.rt_queue = nullptr,
.dev = dev};
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request)
{ request->send(200, "text/plain", "OK"); });
//////// SPAWN REALTIME TASKS ////////
auto task_A = rtIgnitionTask(taskA_params, PSRAM_MAX, QUEUE_MAX, CORE_0, fs_mutex);
delay(50);
auto task_B = rtIgnitionTask(taskB_params, PSRAM_MAX, QUEUE_MAX, CORE_1, fs_mutex);
while (running)
// Ignition A on Core 0
auto ignA_task_success = task_A.getStatus() == rtIgnitionTask::OK ? pdPASS : pdFAIL;
auto ignB_task_success = task_B.getStatus() == rtIgnitionTask::OK ? pdPASS : pdFAIL;
if (ignA_task_success != pdPASS || ignB_task_success != pdPASS)
{
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.print("Data Received: " + String(counter) + "/" + String(hist.size()) + '\r');
if (ws.count() > 0 && counter % 10 == 0) // send data every 10 samples
{
Serial.println();
LOG_INFO("Sending average ignition status to websocket clients...");
auto msg = ign_info_avg.toJson().as<String>();
ws.textAll(msg);
}
}
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);
}
LOG_ERROR("Unable to initialize ISR task");
LOG_ERROR("5 seconds to restart...");
vTaskDelay(pdMS_TO_TICKS(5000));
esp_restart();
}
if (trigA_TaskHandle)
vTaskDelete(trigA_TaskHandle);
if (trigB_TaskHandle)
vTaskDelete(trigB_TaskHandle);
////////////////////// MAIN LOOP //////////////////////
}
const bool tasK_A_rt = task_A.start();
delay(50);
const bool task_B_rt = task_B.start();
if (tasK_A_rt != true || task_B_rt != true)
{
led.setStatus(RGBled::LedStatus::ERROR);
LOG_ERROR("Unable to start realtime tasks");
}
else
{
LOG_DEBUG("Real Time Tasks A & B initialized");
led.setStatus(RGBled::LedStatus::OK);
}
//////// SPAWN WEBSERVER and WEBSOCKET ////////
AstroWebServer webPage(80, LittleFS);
ArduinoJson::JsonDocument json_data;
bool data_a, data_b;
task_A.onMessage([&webPage, &json_data, &data_a](ignitionBoxStatusFiltered sts)
{
json_data["box_a"] = sts.toJson();
data_a = true; });
task_B.onMessage([&webPage, &json_data, &data_b](ignitionBoxStatusFiltered sts)
{
json_data["box_b"] = sts.toJson();
data_b = true; });
// task_A.enableSave(true, "ignitionA_test.csv");
// task_B.enableSave(true, "ignitionB_test.csv");
uint32_t monitor_loop = millis();
uint32_t data_loop = monitor_loop;
//////////////// INNER LOOP /////////////////////
while (running)
{
uint32_t this_loop = millis();
if (this_loop - monitor_loop > 2000)
{
clearScreen();
printRunningTasksMod(Serial);
monitor_loop = millis();
}
if ((data_a && data_b) || (this_loop - data_loop > 500))
{
webPage.sendWsData(json_data.as<String>());
json_data.clear();
data_a = data_b = false;
data_loop = millis();
}
} //////////////// INNER LOOP /////////////////////
} ////////////////////// MAIN LOOP //////////////////////

View File

@@ -4,19 +4,19 @@
// =====================
// USB (RISERVATA)
// =====================
#define USB_DM 19
#define USB_DP 20
#define USB_DM 19
#define USB_DP 20
// =====================
// UART DEBUG (RISERVATA)
// =====================
#define UART_TX 43
#define UART_RX 44
#define UART_TX 43
#define UART_RX 44
// =====================
// RGB Led
// =====================
#define LED 48
#define LED 48
// =====================
// STRAPPING CRITICI (NON USARE)
@@ -26,85 +26,134 @@
// =====================
// SPI BUS ADC1 (VSPI)
// =====================
#define SPI_A_MOSI 11
#define SPI_A_MISO 13
#define SPI_A_SCK 12
#define SPI_A_MOSI 10
#define SPI_A_SCK 11
#define SPI_A_MISO 12
// =====================
// SPI BUS ADC2 (HSPI)
// =====================
#define SPI_B_MOSI 35
#define SPI_B_MISO 37
#define SPI_B_SCK 36
#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 SDA 8
#define SCL 9
#define I2C_INT 17
// =====================
// ADC CONTROL
// =====================
#define ADC_A_CS 4
#define ADC_A_DRDY 5
#define ADC_A_SYNC 6
#define ADC_A_CS 14
#define ADC_A_DRDY 13
#define ADC_B_CS 14
#define ADC_B_DRDY 15
#define ADC_B_SYNC 16
// =====================
// DIGITAL POT
// =====================
#define POT_A_CS 7
#define POT_B_CS 17
#define ADC_B_CS 21
#define ADC_B_DRDY 47
// =====================
// TRIGGER INPUT INTERRUPTS
// =====================
#define TRIG_PIN_A12P 18
#define TRIG_PIN_A12N 21
#define TRIG_PIN_A34P 1
#define TRIG_PIN_A34N 2
#define TRIG_PIN_B12P 38
#define TRIG_PIN_B12N 39
#define TRIG_PIN_B34P 40
#define TRIG_PIN_B34N 41
#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_PIN_A12 42
#define SPARK_PIN_A34 45 // OK (strapping ma consentito) 45
#define SPARK_PIN_B12 46 // OK (strapping ma consentito) 46
#define SPARK_PIN_B34 47
#define SPARK_PIN_A12 4
#define SPARK_PIN_A34 5
#define SPARK_PIN_B12 1
#define SPARK_PIN_B34 2
// +++++++++++++++++++++
// MACRO TO COMBINE PIN NUMBER AND ADDRESS
#define PIN2ADDR(p, a) ((1UL << p) | ((uint32_t)(a) << 16))
// +++++++++++++++++++++
// =====================
// PCA9555 (I2C EXPANDER)
// PCA9555 I/O EXPANDER INTERRUPT (Common)
// =====================
#define EXPANDER_ALL_INTERRUPT 17
// --- RESET LINES ---
#define RST_EXT_A12P 0
#define RST_EXT_A12N 1
#define RST_EXT_A34P 2
#define RST_EXT_A34N 3
#define RST_EXT_B12P 4
#define RST_EXT_B12N 5
#define RST_EXT_B34P 6
#define RST_EXT_B34N 7
// =====================
// PCA9555 I/O EXPANDER BOX_A (OUT)
// =====================
#define EXPANDER_A_OUT_ADDR 0xFF
// --- DIGITAL POT CHIP SELECT LINES ---
#define POT_CS_A12 PIN2ADDR(0, EXPANDER_A_OUT_ADDR)
#define POT_CS_A34 PIN2ADDR(1, EXPANDER_A_OUT_ADDR)
// --- SOFT START FORCE LINES ---
#define SS_FORCE_A PIN2ADDR(2, EXPANDER_A_OUT_ADDR)
#define SS_INIBHIT_A12 PIN2ADDR(3, EXPANDER_A_OUT_ADDR)
#define SS_INHIBIT_A34 PIN2ADDR(4, EXPANDER_A_OUT_ADDR)
// --- SAMPLE AND HOLD ARM AND DISCHARGE ---
#define SH_DISCH_A12 PIN2ADDR(5, EXPANDER_A_OUT_ADDR)
#define SH_DISCH_A34 PIN2ADDR(6, EXPANDER_A_OUT_ADDR)
#define SH_ARM_A12 PIN2ADDR(7, EXPANDER_A_OUT_ADDR)
#define SH_ARM_A34 PIN2ADDR(8, EXPANDER_A_OUT_ADDR)
// --- RELAY ---
#define A_EXT_RELAY 8
#define B_EXT_RELAY 9
#define RELAY_IN_A12 PIN2ADDR(9, EXPANDER_A_OUT_ADDR)
#define RELAY_OUT_A12 PIN2ADDR(10, EXPANDER_A_OUT_ADDR)
#define RELAY_IN_A34 PIN2ADDR(11, EXPANDER_A_OUT_ADDR)
#define RELAY_OUT_A34 PIN2ADDR(12, EXPANDER_A_OUT_ADDR)
// --- STATUS / BUTTON ---
#define BTN_3 10
#define BTN_4 11
#define STA_1 12
#define STA_2 13
#define STA_3 14
#define STA_4 15
// =====================
// PCA9555 I/O EXPANDER BOX_A (IN)
// =====================
#define EXPANDER_A_IN_ADDR 0xFF
#define SS_A12_ON PIN2ADDR(0, EXPANDER_A_IN_ADDR)
#define SS_A12_OFF PIN2ADDR(1, EXPANDER_A_IN_ADDR)
#define SS_A34_ON PIN2ADDR(2, EXPANDER_A_IN_ADDR)
#define SS_A34_OFF PIN2ADDR(3, EXPANDER_A_IN_ADDR)
// =====================
// PCA9555 I/O EXPANDER BOX_B (OUT)
// =====================
#define EXPANDER_B_OUT_ADDR 0xFF
// --- DIGITAL POT CHIP SELECT LINES ---
#define POT_CS_B12 PIN2ADDR(0, EXPANDER_B_OUT_ADDR)
#define POT_CS_B34 PIN2ADDR(1, EXPANDER_B_OUT_ADDR)
// --- SOFT START FORCE LINES ---
#define SS_FORCE_B PIN2ADDR(2, EXPANDER_B_OUT_ADDR)
#define SS_INIBHIT_B12 PIN2ADDR(3, EXPANDER_B_OUT_ADDR)
#define SS_INHIBIT_B34 PIN2ADDR(4, EXPANDER_B_OUT_ADDR)
// --- SAMPLE AND HOLD ARM AND DISCHARGE ---
#define SH_DISCH_B12 PIN2ADDR(5, EXPANDER_B_OUT_ADDR)
#define SH_DISCH_B34 PIN2ADDR(6, EXPANDER_B_OUT_ADDR)
#define SH_ARM_B12 PIN2ADDR(7, EXPANDER_B_OUT_ADDR)
#define SH_ARM_B34 PIN2ADDR(8, EXPANDER_B_OUT_ADDR)
// --- RELAY ---
#define RELAY_IN_B12 PIN2ADDR(9, EXPANDER_B_OUT_ADDR)
#define RELAY_OUT_B12 PIN2ADDR(10, EXPANDER_B_OUT_ADDR)
#define RELAY_IN_B34 PIN2ADDR(11, EXPANDER_B_OUT_ADDR)
#define RELAY_OUT_B34 PIN2ADDR(12, EXPANDER_B_OUT_ADDR)
// =====================
// PCA9555 I/O EXPANDER BOX_B (IN)
// =====================
#define EXPANDER_B_IN_ADDR 0xFF
#define SS_B12_ON PIN2ADDR(0, EXPANDER_B_IN_ADDR)
#define SS_B12_OFF PIN2ADDR(1, EXPANDER_B_IN_ADDR)
#define SS_B34_ON PIN2ADDR(2, EXPANDER_B_IN_ADDR)
#define SS_B34_OFF PIN2ADDR(3, EXPANDER_B_IN_ADDR)
// Init Pin Functions
inline void initTriggerPinsInputs()

View File

@@ -65,7 +65,7 @@
#define RST_EXT_A34N 3
// --- RELAY ---
#define A_EXT_RELAY 8
#define SH_ARM_A34 8
// Init Pin Functions

View File

@@ -25,6 +25,3 @@ struct PSRAMAllocator {
heap_caps_free(p);
}
};
template <typename T>
using PSRAMVector = std::vector<T, PSRAMAllocator<T>>;

View File

@@ -1,5 +1,9 @@
#include "tasks.h"
#include <esp_timer.h>
#include <datasave.h>
#include <mutex>
//// GLOBAL STATIC FUNCTIONS
// Timeout callback for microsecond precision
void spark_timeout_callback(void *arg)
@@ -8,7 +12,18 @@ void spark_timeout_callback(void *arg)
xTaskNotify(handle, SPARK_FLAG_TIMEOUT, eSetValueWithOverwrite);
}
void rtIgnitionTask(void *pvParameters)
// Manages queue receive, save data and callback to external tasks for communication
void rtIgnitionTask::rtIgnitionTask_manager(void *pvParameters)
{
rtIgnitionTask *cls = (rtIgnitionTask *)pvParameters;
while (cls->m_running)
{
cls->run();
}
}
// Static task function
void rtIgnitionTask::rtIgnitionTask_realtime(void *pvParameters)
{
// Invalid real time rt_task_ptr parameters, exit immediate
@@ -17,53 +32,59 @@ void rtIgnitionTask(void *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
const rtTaskInterruptParams rt_int = params->rt_int; // copy to avoid external override
const rtTaskIOParams rt_rst = params->rt_io; // 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;
Devices *dev = params->dev.get();
ADS1256 *adc = params->name == "rtIgnTask_A" ? dev->m_adc_a.get() : dev->m_adc_b.get();
std::mutex &spi_mutex = params->name == "rtIgnTask_A" ? dev->m_spi_a_mutex : dev->m_spi_b_mutex;
ExternalIO *io = dev->m_ext_io.get();
TaskStatus_t rt_task_info;
vTaskGetInfo(NULL, &rt_task_info, pdFALSE, eInvalid);
LOG_INFO("rtTask Params OK [", params->name.c_str(), "]");
ignitionBoxStatus ign_box_sts;
// Variables for ISR, static to be fixed in memory locations
static isrParams isr_params_t12p{
isrParams isr_params_t12p{
.flag = TRIG_FLAG_12P,
.ign_stat = &ign_box_sts,
.rt_handle_ptr = rt_handle_ptr};
static isrParams isr_params_t12n{
.rt_handle_ptr = rt_task_info.xHandle};
isrParams isr_params_t12n{
.flag = TRIG_FLAG_12N,
.ign_stat = &ign_box_sts,
.rt_handle_ptr = rt_handle_ptr};
static isrParams isr_params_t34p{
.rt_handle_ptr = rt_task_info.xHandle};
isrParams isr_params_t34p{
.flag = TRIG_FLAG_34P,
.ign_stat = &ign_box_sts,
.rt_handle_ptr = rt_handle_ptr};
static isrParams isr_params_t34n{
.rt_handle_ptr = rt_task_info.xHandle};
isrParams isr_params_t34n{
.flag = TRIG_FLAG_34N,
.ign_stat = &ign_box_sts,
.rt_handle_ptr = rt_handle_ptr};
static isrParams isr_params_sp12{
.rt_handle_ptr = rt_task_info.xHandle};
isrParams isr_params_sp12{
.flag = SPARK_FLAG_12,
.ign_stat = &ign_box_sts,
.rt_handle_ptr = rt_handle_ptr};
static isrParams isr_params_sp34{
.rt_handle_ptr = rt_task_info.xHandle};
isrParams isr_params_sp34{
.flag = SPARK_FLAG_34,
.ign_stat = &ign_box_sts,
.rt_handle_ptr = rt_handle_ptr};
.rt_handle_ptr = rt_task_info.xHandle};
LOG_INFO("rtTask ISR Params OK");
LOG_DEBUG("rtTask HDL Params OK, HDL* [", (uint32_t)rt_task_info.xHandle, "]");
LOG_DEBUG("rtTask ISR Params OK, ISR* [", (uint32_t)rt_int.isr_ptr, "]");
LOG_DEBUG("rtTask QUE Params OK, QUE* [", (uint32_t)rt_queue, "]");
// 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,
.arg = (void *)rt_task_info.xHandle,
.dispatch_method = ESP_TIMER_TASK,
.name = "spark_timeout"};
esp_timer_create(&timer_args, &timeout_timer);
@@ -76,15 +97,8 @@ void rtIgnitionTask(void *pvParameters)
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");
LOG_INFO("rtTask ISR Attach OK [", params->name.c_str(), "]");
// Compute Reset Pin Bitmask
const uint16_t rst_bitmask = (1 << rt_rst.rst_io_12p) |
(1 << rt_rst.rst_io_12n) |
(1 << rt_rst.rst_io_34p) |
(1 << rt_rst.rst_io_34n);
LOG_WARN("rtTask Init Correct");
// Global rt_task_ptr variables
bool first_cycle = true;
bool cycle12 = false;
@@ -107,23 +121,6 @@ void rtIgnitionTask(void *pvParameters)
if (first_cycle && pickup_flag != TRIG_FLAG_12P) // skip first cycle because of possible initial noise on pickup signals at startu
continue;
#ifdef DEBUG
Serial.print("\033[2J"); // clear screen
Serial.print("\033[H"); // cursor home
LOG_INFO("Iteration [", it++, "]");
if (!names.contains(pickup_flag))
{
LOG_ERROR("Wrong Pickup Flag");
LOG_ERROR("Pickup Flags: ", printBits(pickup_flag).c_str());
continue;
}
else
{
LOG_INFO("Pickup Trigger: ", names.at(pickup_flag));
}
#endif
// 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);
@@ -238,43 +235,57 @@ void rtIgnitionTask(void *pvParameters)
// read adc channels: pickup12, out12 [ pos + neg ]
if (adc) // read only if adc initialized
{
std::lock_guard<std::mutex> lock(spi_mutex);
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.coils12.peak_p_in = adc->convertToVoltage(adc->cycleSingle());
ign_box_sts.coils12.peak_n_in = adc->convertToVoltage(adc->cycleSingle());
ign_box_sts.coils34.peak_p_in = adc->convertToVoltage(adc->cycleSingle());
ign_box_sts.coils34.peak_n_in = adc->convertToVoltage(adc->cycleSingle());
ign_box_sts.coils12.peak_p_out =adc->convertToVoltage(adc->cycleSingle());
ign_box_sts.coils12.peak_n_out =adc->convertToVoltage(adc->cycleSingle());
ign_box_sts.coils34.peak_p_out =adc->convertToVoltage(adc->cycleSingle());
ign_box_sts.coils34.peak_n_out =adc->convertToVoltage(adc->cycleSingle());
ign_box_sts.adc_read_time = (int32_t)(esp_timer_get_time() - start_adc_read);
adc->stopConversion();
}
else // simulate adc read timig
vTaskDelay(pdMS_TO_TICKS(1));
vTaskDelay(pdMS_TO_TICKS(c_adc_time));
// reset peak detectors + sample and hold
// outputs on io expander
if (io)
{
const uint16_t iostat = io->read();
io->write(iostat | rst_bitmask);
vTaskDelay(pdMS_TO_TICKS(1));
io->write(iostat & ~rst_bitmask);
// Discharge Pulse
io->extDigitalWrite(rt_rst.sh_disch_12, true);
io->extDigitalWrite(rt_rst.sh_disch_34, true);
delayMicroseconds(250);
io->extDigitalWrite(rt_rst.sh_disch_12, false);
io->extDigitalWrite(rt_rst.sh_disch_34, false);
// Safety delay
delayMicroseconds(500);
// Re-Arm Pulse
io->extDigitalWrite(rt_rst.sh_arm_12, true);
io->extDigitalWrite(rt_rst.sh_arm_34, true);
delayMicroseconds(250);
io->extDigitalWrite(rt_rst.sh_arm_12, false);
io->extDigitalWrite(rt_rst.sh_arm_34, false);
}
else
vTaskDelay(pdMS_TO_TICKS(1));
vTaskDelay(pdMS_TO_TICKS(c_io_time));
// 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;
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");
LOG_WARN("rtTask Ending [", params->name.c_str(), "]");
// Ignition A Interrupts DETACH
detachInterrupt(rt_int.trig_pin_12p);
detachInterrupt(rt_int.trig_pin_12n);
@@ -285,3 +296,253 @@ void rtIgnitionTask(void *pvParameters)
// delete present task
vTaskDelete(NULL);
}
///////////// CLASS MEMBER DEFINITIONS /////////////
rtIgnitionTask::rtIgnitionTask(const rtTaskParams params, const uint32_t history_size, const uint32_t queue_size, const uint8_t core, std::mutex &fs_mutex, fs::FS &filesystem) : m_params(params), m_filesystem(filesystem), m_fs_mutex(fs_mutex), m_core(core), m_max_history(history_size)
{
// create queue buffers
m_queue = xQueueCreate(queue_size, sizeof(ignitionBoxStatus));
if (!m_queue)
{
LOG_ERROR("Unable To Create Task [", params.name.c_str(), "] queues");
m_manager_status = rtTaskStatus::ERROR;
return;
}
else
m_params.rt_queue = m_queue;
// create PSram history vectors
m_history_0 = PSHistory(history_size);
m_history_1 = PSHistory(history_size);
// assing active and writable history
m_active_history = std::unique_ptr<PSHistory>(&m_history_0);
m_save_history = std::unique_ptr<PSHistory>(&m_history_1);
LOG_WARN("Starting Manager for [", m_params.name.c_str(), "]");
// auto task_success = pdPASS;
auto task_success = xTaskCreatePinnedToCore(
rtIgnitionTask_manager,
(std::string("man_") + m_params.name).c_str(),
8192,
(void *)this,
m_params.rt_priority >> 2,
&m_manager_handle,
m_core);
if (task_success != pdPASS)
{
LOG_ERROR("Unable To Create Manager for [", params.name.c_str(), "]");
m_manager_status = rtTaskStatus::ERROR;
return;
}
// average every 10 samples
m_info_filtered = ignitionBoxStatusFiltered(10);
m_last_data = millis();
m_manager_status = rtTaskStatus::OK;
}
rtIgnitionTask::~rtIgnitionTask()
{
if (m_rt_handle)
vTaskDelete(m_rt_handle);
if (m_manager_handle)
vTaskDelete(m_manager_handle);
if (m_queue)
vQueueDelete(m_queue);
}
void rtIgnitionTask::run()
{
// receive new data from the queue
auto new_data = xQueueReceive(m_queue, &m_last_status, 0); // non blocking receive
if (new_data == pdPASS)
{
m_last_data = millis();
m_manager_status = rtTaskStatus::RUNNING;
// if history buffer is full swap buffers and if enabled save history buffer
if (m_counter_status >= m_active_history->size())
{
LOG_DEBUG("Save for Buffer Full: ", m_counter_status);
m_counter_status = 0;
m_partial_save = false; // reset partial save flag on new data cycle
std::swap(m_active_history, m_save_history);
if (m_enable_save)
saveHistory(*m_save_history, m_history_path); // directly call the save task function to save without delay
}
// update filtered data
m_info_filtered.update(m_last_status);
(*m_active_history)[m_counter_status] = m_last_status;
if (m_on_message_cb && m_counter_status % 10 == 0)
{
m_on_message_cb(m_info_filtered);
}
// update data counter
m_counter_status++;
}
else
{
if (millis() - m_last_data > c_idle_time)
{
if (m_counter_status > 0 && !m_partial_save)
{
LOG_DEBUG("Save Partial: ", m_counter_status);
m_active_history->resize(m_counter_status);
saveHistory(*m_active_history, m_history_path);
m_active_history->resize(m_max_history);
m_counter_status = 0;
m_partial_save = true;
}
m_manager_status = rtTaskStatus::IDLE;
}
delay(5); // yeld to another task
}
}
const bool rtIgnitionTask::start()
{
LOG_WARN("Starting rtTask [", m_params.name.c_str(), "]");
auto task_success = xTaskCreatePinnedToCore(
rtIgnitionTask_realtime,
m_params.name.c_str(),
m_params.rt_stack_size,
(void *)&m_params,
m_params.rt_priority,
&m_rt_handle,
m_core);
const bool success = task_success == pdPASS && m_rt_handle != nullptr;
if (success)
m_manager_status = rtTaskStatus::IDLE;
return success;
}
const bool rtIgnitionTask::stop()
{
LOG_WARN("Ending Task [", m_params.name.c_str(), "]");
if (m_rt_handle)
{
m_params.rt_running = false;
m_rt_handle = nullptr;
m_manager_status = rtTaskStatus::STOPPED;
return true;
}
return false;
}
const ignitionBoxStatus rtIgnitionTask::getLast() const
{
return m_last_status;
}
const ignitionBoxStatusFiltered rtIgnitionTask::getFiltered() const
{
return m_info_filtered;
}
const rtIgnitionTask::rtTaskStatus rtIgnitionTask::getStatus() const
{
return m_manager_status;
}
void rtIgnitionTask::enableSave(const bool enable, const std::filesystem::path filename)
{
m_enable_save = enable;
if (enable && !filename.empty())
{
LOG_WARN("Save History Enabled Task [", m_params.name.c_str(), "]");
m_history_path = m_filesystem.mountpoint() / filename;
}
else
{
LOG_WARN("Save History Disabled Task [", m_params.name.c_str(), "]");
}
}
void rtIgnitionTask::onMessage(std::function<void(ignitionBoxStatusFiltered)> callaback)
{
m_on_message_cb = callaback;
}
void rtIgnitionTask::saveHistory(const rtIgnitionTask::PSHistory &history, const std::filesystem::path &file_name)
{
// Lock filesystem mutex to avoid concurrent access
std::lock_guard<std::mutex> fs_lock(m_fs_mutex);
// Check for free space
if (LittleFS.totalBytes() - LittleFS.usedBytes() < history.size() * sizeof(ignitionBoxStatus)) // check if at least 1MB is free for saving history
{
LOG_ERROR("Not enough space in SPIFFS to save history");
return;
}
// create complete file path
const std::filesystem::path mount_point = std::filesystem::path(m_filesystem.mountpoint());
std::filesystem::path file_path = file_name;
if (file_name.root_path() != mount_point)
file_path = mount_point / file_name;
// if firt save remove old file and create new
auto save_flags = std::ios::out;
if (m_first_save)
{
save_flags |= std::ios::trunc; // overwrite existing file
m_filesystem.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 Flash, new file:", file_path.c_str());
}
else // else append to existing file
{
save_flags |= std::ios::app; // append to new file
LOG_INFO("Saving history to Flash, 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 (m_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();
m_first_save = false;
}
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 Box history saved to Flash, records written: ", history.size());
}

View File

@@ -2,12 +2,19 @@
#define DEBUGLOG_DEFAULT_LOG_LEVEL_DEBUG
// Serial debug flag
//#define DEBUG
// #define DEBUG
// Arduino Libraries
#include <Arduino.h>
#include <DebugLog.h>
#include "utils.h"
#include <memory>
#include <mutex>
#include <filesystem>
#include <FS.h>
#include <LittleFS.h>
#include <datasave.h>
#include <functional>
// ISR
#include "isr.h"
@@ -31,36 +38,122 @@ static const std::map<const uint32_t, const char *> names = {
};
#endif
// RT task Interrupt parameters
struct rtTaskInterrupts
class rtIgnitionTask
{
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;
};
using PSHistory = PSRAMVector<ignitionBoxStatus>;
// RT Task Peak Detector Reset pins
struct rtTaskResets
{
const uint8_t rst_io_12p;
const uint8_t rst_io_12n;
const uint8_t rst_io_34p;
const uint8_t rst_io_34n;
};
public:
// RT task Interrupt parameters
struct rtTaskInterruptParams
{
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;
};
// 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
};
// RT Task Peak Detector Reset pins
struct rtTaskIOParams
{
const uint32_t expander_addr;
const uint32_t pot_cs_12;
const uint32_t pot_cs_34;
const uint32_t ss_force;
const uint32_t ss_inhibit_12;
const uint32_t ss_inhibit_34;
const uint32_t sh_disch_12;
const uint32_t sh_disch_34;
const uint32_t sh_arm_12;
const uint32_t sh_arm_34;
const uint32_t relay_in_12;
const uint32_t relay_in_34;
const uint32_t relay_out_12;
const uint32_t relay_out_34;
};
void rtIgnitionTask(void *pvParameters);
// RT task parameters
struct rtTaskParams
{
bool rt_running; // run flag, false to terminate
const std::string name;
const uint32_t rt_stack_size;
const uint32_t rt_priority;
const rtTaskInterruptParams rt_int; // interrupt pins to attach
const rtTaskIOParams rt_io; // reset ping for peak detectors
QueueHandle_t rt_queue; // queue for task io
const std::shared_ptr<Devices> dev;
};
enum rtTaskStatus
{
INIT,
OK,
ERROR,
RUNNING,
IDLE,
STOPPED
};
public:
rtIgnitionTask(const rtTaskParams params, const uint32_t history_size, const uint32_t queue_size, const uint8_t core, std::mutex &fs_mutex, fs::FS &filesystem = LittleFS);
~rtIgnitionTask();
void run();
const bool start();
const bool stop();
const ignitionBoxStatus getLast() const;
const ignitionBoxStatusFiltered getFiltered() const;
const rtTaskStatus getStatus() const;
void enableSave(const bool enable, const std::filesystem::path filename);
void onMessage(std::function<void(ignitionBoxStatusFiltered)> callaback);
private:
void saveHistory(const rtIgnitionTask::PSHistory &history, const std::filesystem::path &file_name);
private: // static functions for FreeRTOS
static void rtIgnitionTask_manager(void *pvParameters);
static void rtIgnitionTask_realtime(void *pvParameters);
private:
bool m_running = true;
rtTaskStatus m_manager_status = INIT;
rtTaskParams m_params;
const uint8_t m_core;
TaskHandle_t m_rt_handle = nullptr;
TaskHandle_t m_manager_handle = nullptr;
QueueHandle_t m_queue = nullptr;
bool m_enable_save = false;
std::filesystem::path m_history_path;
const uint32_t m_max_history;
PSHistory m_history_0;
PSHistory m_history_1;
std::unique_ptr<PSHistory> m_active_history;
std::unique_ptr<PSHistory> m_save_history;
fs::FS &m_filesystem;
std::mutex &m_fs_mutex;
bool m_partial_save = false;
bool m_first_save = true;
uint32_t m_counter_status = 0;
uint32_t m_last_data = 0;
ignitionBoxStatus m_last_status;
ignitionBoxStatusFiltered m_info_filtered;
std::function<void(ignitionBoxStatusFiltered)> m_on_message_cb = nullptr;
static const uint32_t c_idle_time = 10000; // in mS
static const uint32_t c_spark_timeout_max = 500; // uS
static const uint8_t c_adc_time = 4; // in mS
static const uint8_t c_io_time = 2; // in mS
};

View File

@@ -14,191 +14,3 @@ 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

@@ -1,14 +1,194 @@
#include "utils.h"
#include "freertos_stats.h"
#include "sdkconfig.h"
std::string printBits(uint32_t value) {
#include "freertos/FreeRTOS.h"
#include "freertos/portable.h"
#include "esp_heap_caps.h"
#include "esp_system.h"
#include "esp_spi_flash.h"
#include "esp_partition.h"
#include "LittleFS.h"
#include <vector>
#include <algorithm>
#include <functional>
#define FREERTOS_TASK_NUMBER_MAX_NUM 256 // RunTime stats for how many Tasks to be stored
std::string printBits(uint32_t value)
{
std::string result;
for (int i = 31; i >= 0; i--) {
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) {
if (i % 8 == 0 && i != 0)
{
result += ' ';
}
}
return result;
}
// ANSI colors
#define BAR_WIDTH 30
#define COLOR_RESET "\033[0m"
#define COLOR_RED "\033[31m"
#define COLOR_GREEN "\033[32m"
#define COLOR_BLUE "\033[34m"
#define COLOR_MAGENTA "\033[35m"
#define COLOR_CYAN "\033[36m"
#define COLOR_YELLOW "\033[33m"
#define COLOR_WHITE "\033[37m"
#define COLOR_LBLUE "\033[94m"
void printBar(Print &printer, const char *label, size_t used, size_t total, const char *color)
{
float perc = total > 0 ? ((float)used / total) : 0;
int filled = perc * BAR_WIDTH;
printer.printf("%s%-12s [" COLOR_RESET, color, label);
for (int i = 0; i < BAR_WIDTH; i++)
{
if (i < filled)
printer.printf("%s#%s", color, COLOR_RESET);
else
printer.printf("-");
}
printer.printf("] %s%6.2f%%%s (%5.3f/%5.3f)MB\n",
color,
perc * 100.0,
COLOR_RESET,
(used / 1024.0f / 1024.0f),
(total / 1024.0f / 1024.0f));
}
void printRunningTasksMod(Print &printer, std::function<bool(const TaskStatus_t &a, const TaskStatus_t &b)> orderBy)
{
static const char *taskStates[] = {"Running", "Ready", "Blocked", "Suspended", "Deleted", "Invalid"};
static uint32_t ulRunTimeCounters[FREERTOS_TASK_NUMBER_MAX_NUM];
static uint32_t ulLastRunTime = 0;
uint32_t ulCurrentRunTime = 0, ulTaskRunTime = 0;
uint32_t ulTotalRunTime = 0;
std::vector<TaskStatus_t> pxTaskStatusArray;
UBaseType_t uxArraySize = 0;
// Take a snapshot of the number of tasks in case it changes while this function is executing.
uxArraySize = uxTaskGetNumberOfTasks();
pxTaskStatusArray.resize(uxArraySize);
// Generate raw status information about each task.
uxArraySize = uxTaskGetSystemState(pxTaskStatusArray.data(), uxArraySize, &ulTotalRunTime);
if (orderBy == nullptr)
std::sort(pxTaskStatusArray.begin(), pxTaskStatusArray.end(), [](const TaskStatus_t &a, const TaskStatus_t &b)
{ return a.xTaskNumber < b.xTaskNumber; });
else
std::sort(pxTaskStatusArray.begin(), pxTaskStatusArray.end(), orderBy);
// Compute system total runtime
ulCurrentRunTime = ulTotalRunTime - ulLastRunTime;
ulLastRunTime = ulTotalRunTime;
// PRINT MEMORY INFO
printer.printf("\033[H");
printer.printf(COLOR_LBLUE "=================== ESP32 SYSTEM MONITOR ===================\n" COLOR_RESET);
std::string buffer;
time_t now = time(nullptr);
struct tm *t = localtime(&now);
buffer.resize(64);
strftime(buffer.data(), sizeof(buffer), "%Y-%m-%d %H:%M:%S", t);
printer.printf(COLOR_YELLOW "=============== Datetime: %s ===============\n\n" COLOR_RESET, buffer.c_str());
// ===== HEAP =====
size_t freeHeap = esp_get_free_heap_size();
size_t totalHeap = heap_caps_get_total_size(MALLOC_CAP_DEFAULT);
printBar(printer, "HEAP", totalHeap - freeHeap, totalHeap, COLOR_GREEN);
// ===== RAM INTERNA =====
size_t freeInternal = heap_caps_get_free_size(MALLOC_CAP_INTERNAL);
size_t totalInternal = heap_caps_get_total_size(MALLOC_CAP_INTERNAL);
printBar(printer, "INTERNAL", totalInternal - freeInternal, totalInternal, COLOR_BLUE);
// ===== PSRAM =====
size_t totalPsram = heap_caps_get_total_size(MALLOC_CAP_SPIRAM);
if (totalPsram > 0)
{
size_t freePsram = heap_caps_get_free_size(MALLOC_CAP_SPIRAM);
printBar(printer, "PSRAM", totalPsram - freePsram, totalPsram, COLOR_MAGENTA);
}
printer.printf("\n");
// ===== FLASH APP (approssimato) =====
const esp_partition_t *app_partition =
esp_partition_find_first(ESP_PARTITION_TYPE_APP,
ESP_PARTITION_SUBTYPE_APP_FACTORY,
NULL);
if (app_partition)
{
size_t totalAPP = app_partition->size; // dimensione reale partizione
size_t sketchSize = ESP.getSketchSize();
printBar(printer, "FLASH APP", sketchSize, totalAPP, COLOR_CYAN);
}
else
{
printer.printf(COLOR_YELLOW "%-12s [NOT FOUND]\n" COLOR_RESET, "FLASH APP");
}
// ===== LITTLEFS (corretto con partition table) =====
const esp_partition_t *fs_partition =
esp_partition_find_first(ESP_PARTITION_TYPE_DATA,
ESP_PARTITION_SUBTYPE_DATA_LITTLEFS,
"littlefs");
if (fs_partition)
{
size_t totalFS = fs_partition->size; // dimensione reale partizione
size_t usedFS = LittleFS.usedBytes(); // spazio usato reale
printBar(printer, "LITTLEFS", usedFS, totalFS, COLOR_YELLOW);
}
else
{
printer.printf(COLOR_YELLOW "%-12s [NOT FOUND]\n" COLOR_RESET, "LITTLEFS");
}
// ===== MIN HEAP =====
size_t minHeap = esp_get_minimum_free_heap_size();
printer.printf("%s\nMin Heap Ever:%s %u KB\n\n", COLOR_RED, COLOR_RESET, minHeap / 1024);
// Print Runtime Information
printer.printf("Tasks: %u, Runtime: %lus, Period: %luus\r\n", uxArraySize, ulTotalRunTime / 1000000, ulCurrentRunTime);
// Print Task Headers
printer.printf("Num\t Name\tLoad\tPrio\t Free\tCore\tState\r\n");
for (const auto &task : pxTaskStatusArray)
{
ulTaskRunTime = (task.ulRunTimeCounter - ulRunTimeCounters[task.xTaskNumber]);
ulRunTimeCounters[task.xTaskNumber] = task.ulRunTimeCounter;
ulTaskRunTime = (ulTaskRunTime * 100) / ulCurrentRunTime; // in percentage
printer.printf(
"%3u\t%16s"
"\t%3lu%%"
"\t%4u\t%5lu"
"\t%4c"
"\t%s\r\n",
task.xTaskNumber, task.pcTaskName,
ulTaskRunTime,
task.uxCurrentPriority, task.usStackHighWaterMark,
(task.xCoreID == tskNO_AFFINITY) ? '*' : ('0' + task.xCoreID),
taskStates[task.eCurrentState]);
}
printer.println();
}

View File

@@ -2,5 +2,14 @@
#include <Arduino.h>
#include <string>
#include <datastruct.h>
std::string printBits(uint32_t value);
void printRunningTasksMod(Print &printer, std::function<bool(const TaskStatus_t &a, const TaskStatus_t &b)> orderBy = nullptr);
inline void swapHistory(PSRAMVector<ignitionBoxStatus>* active, PSRAMVector<ignitionBoxStatus>* writable) {
auto *temp = active;
active = writable; // switch active and writable buffers
writable = temp; // ensure writable_history points to the buffer we just filled
}

View File

@@ -0,0 +1,166 @@
#include <webserver.h>
#include <ArduinoJson.h>
static std::map<const std::string, AstroWebServer::c_commandEnum> s_webserverCommands = {
{"setTime", AstroWebServer::SET_TIME},
};
void on_ping(TimerHandle_t xTimer)
{
if (!xTimer)
return;
auto ws = (AsyncWebSocket *)pvTimerGetTimerID(xTimer);
ws->pingAll();
ws->cleanupClients();
}
AstroWebServer::AstroWebServer(const uint8_t port, fs::FS &filesystem) : m_port(port), m_webserver(AsyncWebServer(port)), m_websocket(AsyncWebSocket("/ws")), m_filesystem(filesystem)
{
LOG_DEBUG("Initializing Web Server");
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();
m_websocket.enable(true);
m_pingTimer = xTimerCreate("wsPingTimer", pdMS_TO_TICKS(2000), pdTRUE, (void *)&m_websocket, on_ping);
LOG_DEBUG("Webserver Init OK");
}
AstroWebServer::~AstroWebServer()
{
xTimerDelete(m_pingTimer, pdMS_TO_TICKS(10));
m_webserver.removeHandler(&m_websocket);
m_webserver.end();
}
void AstroWebServer::sendWsData(const String &data)
{
if (m_websocket.count())
{
m_websocket.textAll(data);
}
}
void AstroWebServer::onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len)
{
switch (type)
{
case WS_EVT_CONNECT:
LOG_DEBUG("WS client IP[", client->remoteIP().toString().c_str(), "]-ID[", client->id(), "] CONNECTED");
break;
case WS_EVT_DISCONNECT:
LOG_DEBUG("WS client IP[", client->remoteIP().toString().c_str(), "]-ID[", client->id(), "] DISCONNECTED");
break;
case WS_EVT_PONG:
LOG_DEBUG("WS client IP[", client->remoteIP().toString().c_str(), "]-ID[", client->id(), "] PONG");
break;
case WS_EVT_DATA:
{
AwsFrameInfo *info = (AwsFrameInfo *)arg;
if (info->final && info->index == 0 && info->len == len)
{
std::string data_str((char *)data, len);
ArduinoJson::JsonDocument doc;
if (auto rv = ArduinoJson::deserializeJson(doc, data_str) != ArduinoJson::DeserializationError::Ok)
{
LOG_ERROR("WS Client unable to deserialize Json");
return;
}
if (!doc["cmd"].is<std::string>() || !s_webserverCommands.contains(doc["cmd"]))
{
LOG_WARN("WS Client Invalid Json command [", doc["cmd"].as<std::string>().c_str(), "]");
return;
}
std::string buffer;
switch (s_webserverCommands.at(doc["cmd"]))
{
case SET_TIME:
{
auto epoch = doc["time"].as<time_t>();
timeval te{
.tv_sec = epoch,
.tv_usec = 0,
};
timezone tz{
.tz_minuteswest = 0,
.tz_dsttime = DST_MET,
};
settimeofday(&te, &tz);
time_t now = time(nullptr);
struct tm *t = localtime(&now);
buffer.resize(64);
strftime(buffer.data(), sizeof(buffer), "%Y-%m-%d %H:%M:%S", t);
LOG_DEBUG("WS Client set Datetime to: ", buffer.c_str());
break;
}
default:
// call external command callback
break;
}
}
}
}
}
void AstroWebServer::onUploadRequest(AsyncWebServerRequest *request)
{
if (m_uploadFailed)
request->send(500, "text/plain", "Upload failed");
else
request->send(200, "text/plain", "Upload successful");
}
void AstroWebServer::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_uploadFailed = false;
String safeName = filename;
int slashIndex = safeName.lastIndexOf('/');
if (slashIndex >= 0)
safeName = safeName.substring(slashIndex + 1);
if (safeName.length() == 0)
{
m_uploadFailed = 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_uploadFile = m_filesystem.open(filePath.c_str(), FILE_WRITE);
if (!m_uploadFile)
{
m_uploadFailed = true;
LOG_ERROR("Failed to open upload file:", filePath.c_str());
return;
}
}
// Actual write of file data
if (!m_uploadFailed && m_uploadFile)
{
if (m_uploadFile.write(data, len) != len)
m_uploadFailed = true;
}
// close the file and save on final call
if (final && m_uploadFile)
{
m_uploadFile.close();
if (!m_uploadFailed)
LOG_INFO("Uploaded file to LittleFS:", filename.c_str());
}
}

View File

@@ -0,0 +1,48 @@
#pragma once
#define DEBUGLOG_DEFAULT_LOG_LEVEL_DEBUG
// System includes
#include <Arduino.h>
#include <DebugLog.h>
#include <ESPAsyncWebServer.h>
#include <AsyncTCP.h>
#include <filesystem>
#include <map>
#include <FS.h>
class AstroWebServer
{
public:
AstroWebServer(const uint8_t port, fs::FS &filesystem);
~AstroWebServer();
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);
private:
const uint8_t m_port = 80;
fs::FS &m_filesystem;
AsyncWebServer m_webserver;
AsyncWebSocket m_websocket;
bool m_uploadFailed = false;
fs::File m_uploadFile;
TimerHandle_t m_pingTimer = NULL;
public:
enum c_commandEnum
{
SET_TIME
};
};

View File

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

View File

@@ -22,7 +22,7 @@ build_type = release
[env:esp32-devtest-debug]
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

View File

@@ -0,0 +1,12 @@
#pragma once
// ANSI colors
#define COLOR_RESET "\033[0m"
#define COLOR_RED "\033[31m"
#define COLOR_GREEN "\033[32m"
#define COLOR_BLUE "\033[34m"
#define COLOR_MAGENTA "\033[35m"
#define COLOR_CYAN "\033[36m"
#define COLOR_YELLOW "\033[33m"
#define COLOR_WHITE "\033[37m"
#define COLOR_LBLUE "\033[94m"

View File

@@ -1,7 +1,11 @@
#define DEBUGLOG_DEFAULT_LOG_LEVEL_DEBUG
#include <Arduino.h>
#include <DebugLog.h>
#include "timer.h"
#include "colors.h"
#include <map>
static hw_timer_t *timerA = NULL;
@@ -15,19 +19,27 @@ static uint32_t count = 0;
#define SPARK_DLY_MIN 10
#define SPARK_DLY_MAX 490
#define PAUSE_LONG_MIN 5000
#define PAUSE_LONG_MAX PAUSE_LONG_MIN*100
#define COIL_PULSE_MIN 100
#define COIL_PULSE_MAX 1000
#define RPM_MIN 800
#define SPARK_PULSE_MIN 10
#define SPARK_PULSE_MAX 500
#define PAUSE_LONG_MIN 5000
#define PAUSE_LONG_MAX PAUSE_LONG_MIN * 100
#define RPM_MIN 250
#define RPM_MAX 5500
void clearScreen(){
Serial.print("\033[2J"); // clear screen
Serial.print("\033[H"); // cursor home
Serial.flush();
void clearScreen()
{
Serial.print("\033[2J"); // clear screen
Serial.print("\033[H"); // cursor home
Serial.flush();
}
static double filtered_rpm = 0;
static uint32_t set_rpm = 500;
static uint32_t set_delay = 100;
static const std::map<const uint32_t, const char *> pin2Name = {
{PIN_TRIG_A12P, "HIGH_PIN_TRIG_A12P"},
@@ -46,21 +58,48 @@ static const std::map<const uint32_t, const char *> pin2Name = {
{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};
.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,
.pins = {
.pin_trig_12p = PIN_TRIG_A12P,
.pin_trig_12n = PIN_TRIG_A12N,
.pin_trig_34p = PIN_TRIG_A34P,
.pin_trig_34n = PIN_TRIG_A34N,
.pin_spark_12 = SPARK_A12,
.pin_spark_34 = SPARK_A34},
.main_task = NULL};
static bool isEnabled = false;
static timerStatus stsB = {
.clock_period_us = (uint32_t)PERIOD_US,
.pause_long_us = 10000,
.pause_short_us = 1000,
.coil_pulse_us = 500,
.spark_pulse_us = 100,
.spark_delay_us = 50,
.pins = {
.pin_trig_12p = PIN_TRIG_B12P,
.pin_trig_12n = PIN_TRIG_B12N,
.pin_trig_34p = PIN_TRIG_B34P,
.pin_trig_34n = PIN_TRIG_B34N,
.pin_spark_12 = SPARK_B12,
.pin_spark_34 = SPARK_B34},
.main_task = NULL};
static bool isEnabled_A = false;
static bool isEnabled_B = false;
static String last_command;
void setup()
{
Serial.begin(921600);
Serial.begin(115200);
delay(1000);
Serial.setTimeout(100);
LOG_ATTACH_SERIAL(Serial);
pinMode(PIN_TRIG_A12P, OUTPUT);
@@ -80,53 +119,150 @@ void setup()
pinMode(SPARK_DELAY_POT, ANALOG);
pinMode(FREQ_POT, ANALOG);
pinMode(ENABLE_PIN, INPUT_PULLUP);
pinMode(ENABLE_PIN_A, INPUT_PULLUP);
pinMode(ENABLE_PIN_B, INPUT_PULLUP);
// get the task handle for the main loop
stsA.main_task = xTaskGetCurrentTaskHandleForCore(1);
stsB.main_task = xTaskGetCurrentTaskHandleForCore(1);
// Begin timer with preset fixed frequency
timerA = timerBegin(FREQUENCY);
timerB = timerBegin(FREQUENCY);
// Stop timers because of autostart
timerStop(timerA);
timerStop(timerB);
// Attach interrupts and call callback every timer expiry
timerAttachInterruptArg(timerA, &onTimer, (void *)&stsA);
timerAlarm(timerA, 1, true, 0);
timerAttachInterruptArg(timerB, &onTimer, (void *)&stsB);
timerAlarm(timerA, 1, true, 0); // infinite number of reloads
timerAlarm(timerB, 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();
Serial.printf("\t++++ Loop: %u ++++\n", count++);
if (isEnabled_A)
Serial.println("==== System A is" COLOR_GREEN " ENABLED" COLOR_RESET " ====");
else
Serial.println("==== System A is" COLOR_RED " DISABLED" COLOR_RESET " ====");
if (isEnabled_B)
Serial.println("==== System B is" COLOR_GREEN " ENABLED" COLOR_RESET " ====");
else
Serial.println("==== System B is" COLOR_RED " DISABLED" COLOR_RESET " ====");
Serial.printf("Spark Delay uS: %u\n", stsA.spark_delay_us);
Serial.printf("Soft Start: %s\n", stsA.soft_start ? "ENABLED" : "DISABLED");
Serial.printf("Engine Rpm: %u\n", (uint32_t)(set_rpm));
Serial.printf("Coil Pulse: %u uS\n", stsA.coil_pulse_us);
Serial.printf("Spark Pulse: %u uS\n", stsA.spark_pulse_us);
Serial.println(COLOR_CYAN "-------------------------------------");
Serial.println("E[a/b] > Enable Box a/b | D[a/b] > Disable a/b");
Serial.println("S[ddd] > Spark Delay | R[dddd] > Engine RPM");
Serial.println("C[ddd] > Spark Pulse | P[ddd] > Coil Pulse");
Serial.println("-------------------------------------" COLOR_RESET);
Serial.printf("Last Command: %s\n", last_command.c_str());
auto str = Serial.readStringUntil('\n');
if (!str.isEmpty())
{
last_command = str;
const auto cmd = str.charAt(0);
char c;
switch (cmd)
{
case 'E':
{
char box;
sscanf(str.c_str(), "%c%c\n", &c, &box);
if (box == 'a' && !isEnabled_A)
{
timerStart(timerA);
isEnabled_A = true;
}
else if (box == 'b' && !isEnabled_B)
{
timerStart(timerB);
isEnabled_B = true;
}
break;
}
case 'D':
{
char c;
char box;
sscanf(str.c_str(), "%c%c\n", &c, &box);
if (box == 'a' && isEnabled_A)
{
timerStop(timerA);
isEnabled_A = false;
}
else if (box == 'b' && isEnabled_B)
{
timerStop(timerB);
isEnabled_B = false;
}
break;
}
case 'R':
{
int new_rpm;
sscanf(str.c_str(), "%c%d\n", &c, &new_rpm);
new_rpm = min(RPM_MAX, max(RPM_MIN, new_rpm));
stsA.pause_long_us = (uint32_t)(60000000.0f / (float)new_rpm / 2.0f);
stsB.pause_long_us = stsA.pause_long_us;
set_rpm = (uint32_t)new_rpm;
break;
}
case 'S':
{
int new_delay;
sscanf(str.c_str(), "%c%d\n", &c, &new_delay);
new_delay = min(SPARK_DLY_MAX, max(SPARK_DLY_MIN, new_delay));
stsA.spark_delay_us = (uint32_t)(new_delay);
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;
}
stsB.soft_start = stsA.soft_start;
stsB.spark_delay_us = stsA.spark_delay_us;
break;
}
case 'P':
{
int new_pulse;
sscanf(str.c_str(), "%c%d\n", &c, &new_pulse);
new_pulse = min(COIL_PULSE_MAX, max(COIL_PULSE_MIN, new_pulse));
stsA.coil_pulse_us = stsB.coil_pulse_us = (uint32_t)new_pulse;
break;
}
case 'C':
{
int new_pulse;
sscanf(str.c_str(), "%c%d\n", &c, &new_pulse);
new_pulse = min(SPARK_PULSE_MAX, max(SPARK_PULSE_MIN, new_pulse));
stsA.spark_pulse_us = stsB.spark_pulse_us = (uint32_t)new_pulse;
break;
}
default:
break;
}
Serial.read();
}
str.clear();
delay(1000);
}

View File

@@ -1,7 +1,8 @@
#pragma once
// Enable Pin
#define ENABLE_PIN 16
#define ENABLE_PIN_A 16
#define ENABLE_PIN_B 15
///// Ignition Box A /////
#define PIN_TRIG_A12P 18

View File

@@ -7,20 +7,18 @@ void onTimer(void *arg)
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
timerStatus *params = (timerStatus *)(arg);
TaskHandle_t task = params->main_task;
const timerPins pins = params->pins;
// 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);
digitalWrite(pins.pin_trig_12p, HIGH);
params->coil12p_high = true;
wait_sent = false;
}
@@ -29,21 +27,18 @@ void onTimer(void *arg)
{
if (params->state_time == params->spark_delay_us)
{
// xTaskNotifyFromISR(task, SPARK_A12, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
digitalWrite(SPARK_A12, HIGH);
digitalWrite(pins.pin_spark_12, HIGH);
}
if (params->state_time == (params->spark_delay_us + params->spark_pulse_us))
{
// xTaskNotifyFromISR(task, ~SPARK_A12, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
digitalWrite(SPARK_A12, LOW);
digitalWrite(pins.pin_spark_12, LOW);
}
}
if (params->state_time >= params->coil_pulse_us && params->coil12p_high)
{
// xTaskNotifyFromISR(task, ~PIN_TRIG_A12P, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
digitalWrite(PIN_TRIG_A12P, LOW);
digitalWrite(pins.pin_trig_12p, LOW);
params->coil12p_high = false;
}
@@ -57,8 +52,7 @@ void onTimer(void *arg)
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);
digitalWrite(pins.pin_trig_12n, HIGH);
params->coil12n_high = true;
}
@@ -66,21 +60,18 @@ void onTimer(void *arg)
{
if (params->state_time == params->spark_delay_us)
{
// xTaskNotifyFromISR(task, SPARK_A12, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
digitalWrite(SPARK_A12, HIGH);
digitalWrite(pins.pin_spark_12, HIGH);
}
if (params->state_time == (params->spark_delay_us + params->spark_pulse_us))
{
// xTaskNotifyFromISR(task, ~SPARK_A12, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
digitalWrite(SPARK_A12, LOW);
digitalWrite(pins.pin_spark_12, LOW);
}
}
if (params->state_time >= params->coil_pulse_us && params->coil12n_high)
{
// xTaskNotifyFromISR(task, ~PIN_TRIG_A12N, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
digitalWrite(PIN_TRIG_A12N, LOW);
digitalWrite(pins.pin_trig_12n, LOW);
params->coil12n_high = false;
params->state = S_WAIT_10MS;
params->state_time = 0;
@@ -90,7 +81,6 @@ void onTimer(void *arg)
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)
@@ -103,8 +93,7 @@ void onTimer(void *arg)
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);
digitalWrite(pins.pin_trig_34p, HIGH);
params->coil34p_high = true;;
wait_sent = false;
}
@@ -113,21 +102,18 @@ void onTimer(void *arg)
{
if (params->state_time == params->spark_delay_us)
{
// xTaskNotifyFromISR(task, SPARK_A34, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
digitalWrite(SPARK_A34, HIGH);
digitalWrite(pins.pin_spark_34, HIGH);
}
if (params->state_time == params->spark_delay_us + params->spark_pulse_us)
{
// xTaskNotifyFromISR(task, ~SPARK_A34, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
digitalWrite(SPARK_A34, LOW);
digitalWrite(pins.pin_spark_34, LOW);
}
}
if (params->state_time >= params->coil_pulse_us && params->coil34p_high)
{
// xTaskNotifyFromISR(task, ~PIN_TRIG_A34P, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
digitalWrite(PIN_TRIG_A34P, LOW);
digitalWrite(pins.pin_trig_34p, LOW);
params->coil34p_high = false;
}
@@ -141,8 +127,7 @@ void onTimer(void *arg)
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);
digitalWrite(pins.pin_trig_34n, HIGH);
params->coil34n_high = true;
}
@@ -150,21 +135,18 @@ void onTimer(void *arg)
{
if (params->state_time == params->spark_delay_us)
{
// xTaskNotifyFromISR(task, SPARK_A34, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
digitalWrite(SPARK_A34, HIGH);
digitalWrite(pins.pin_spark_34, HIGH);
}
if (params->state_time == params->spark_delay_us + params->spark_pulse_us)
{
// xTaskNotifyFromISR(task, ~SPARK_A34, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
digitalWrite(SPARK_A34, LOW);
digitalWrite(pins.pin_spark_34, LOW);
}
}
if (params->state_time >= params->coil_pulse_us && params->coil34n_high)
{
// xTaskNotifyFromISR(task, ~PIN_TRIG_A34N, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
digitalWrite(PIN_TRIG_A34N, LOW);
digitalWrite(pins.pin_trig_34n, LOW);
params->coil34n_high = false;
params->state = S_WAIT_10MS_END;
params->state_time = 0;
@@ -174,7 +156,6 @@ void onTimer(void *arg)
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)
@@ -184,9 +165,7 @@ void onTimer(void *arg)
}
break;
}
digitalWrite(PIN_TRIG_B12P, LOW);
if (xHigherPriorityTaskWoken)
portYIELD_FROM_ISR();
}

View File

@@ -1,5 +1,7 @@
#pragma once
#define DEBUGLOG_DEFAULT_LOG_LEVEL_DEBUG
#include <Arduino.h>
#include <DebugLog.h>
#include "pins.h"
@@ -19,6 +21,15 @@ enum State
S_WAIT_10MS_END
};
struct timerPins {
const uint8_t pin_trig_12p;
const uint8_t pin_trig_12n;
const uint8_t pin_trig_34p;
const uint8_t pin_trig_34n;
const uint8_t pin_spark_12;
const uint8_t pin_spark_34;
};
struct timerStatus
{
State state = State::S_12P;
@@ -34,6 +45,7 @@ struct timerStatus
bool coil34p_high = false;
bool coil12n_high = false;
bool coil34n_high = false;
timerPins pins;
TaskHandle_t main_task;
};