Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9c012efef1 | |||
| d41a99ee88 | |||
| eaeb515074 | |||
| 246ba7eeb2 | |||
| 736a8d8bd5 | |||
| 2083119d79 |
Vendored
+1
-2
@@ -1,8 +1,7 @@
|
|||||||
{
|
{
|
||||||
"recommendations": [
|
"recommendations": [
|
||||||
"Jason2866.esp-decoder",
|
"Jason2866.esp-decoder",
|
||||||
"pioarduino.pioarduino-ide",
|
"pioarduino.pioarduino-ide"
|
||||||
"platformio.platformio-ide"
|
|
||||||
],
|
],
|
||||||
"unwantedRecommendations": [
|
"unwantedRecommendations": [
|
||||||
"ms-vscode.cpptools-extension-pack"
|
"ms-vscode.cpptools-extension-pack"
|
||||||
|
|||||||
+110
-28
@@ -13,6 +13,7 @@
|
|||||||
<img src="logo_astro_dev.svg" alt="Astro Tecnologie" class="logo">
|
<img src="logo_astro_dev.svg" alt="Astro Tecnologie" class="logo">
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
|
|
||||||
<h1>Rotax Ignition Box Monitor</h1>
|
<h1>Rotax Ignition Box Monitor</h1>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
@@ -21,14 +22,19 @@
|
|||||||
<span class="spinner"></span> Waiting for data...
|
<span class="spinner"></span> Waiting for data...
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div style="max-width: 900px; margin: 0 auto; text-align: left;">
|
<div class="tables-container">
|
||||||
<p><strong>Timestamp:</strong> <span id="timestamp">-</span></p>
|
<div class="box">
|
||||||
<p><strong>Data Valid:</strong> <span id="datavalid">-</span></p>
|
<h2>Box_A</h2>
|
||||||
<p><strong>Generator voltage:</strong> <span id="volts_gen">-</span></p>
|
<div class="box-data">
|
||||||
<p><strong>Engine RPM:</strong> <span id="eng_rpm">-</span></p>
|
<p><strong>Timestamp:</strong> <span id="a_timestamp">-</span></p>
|
||||||
<p><strong>ADC read time:</strong> <span id="adc_read_time">-</span></p>
|
<p><strong>Data Valid:</strong> <span id="a_datavalid">-</span></p>
|
||||||
<p><strong>Queue errors:</strong> <span id="n_queue_errors">-</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>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -40,58 +46,134 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Spark delay</td>
|
<td>Spark delay</td>
|
||||||
<td id="coils12_spark_delay">-</td>
|
<td id="a_coils12_spark_delay">-</td>
|
||||||
<td id="coils34_spark_delay">-</td>
|
<td id="a_coils34_spark_delay">-</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Spark status</td>
|
<td>Spark status</td>
|
||||||
<td id="coils12_spark_status">-</td>
|
<td id="a_coils12_spark_status">-</td>
|
||||||
<td id="coils34_spark_status">-</td>
|
<td id="a_coils34_spark_status">-</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Soft start status</td>
|
<td>Soft start status</td>
|
||||||
<td id="coils12_sstart_status">-</td>
|
<td id="a_coils12_sstart_status">-</td>
|
||||||
<td id="coils34_sstart_status">-</td>
|
<td id="a_coils34_sstart_status">-</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Peak P in</td>
|
<td>Peak P in</td>
|
||||||
<td id="coils12_peak_p_in">-</td>
|
<td id="a_coils12_peak_p_in">-</td>
|
||||||
<td id="coils34_peak_p_in">-</td>
|
<td id="a_coils34_peak_p_in">-</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Peak N in</td>
|
<td>Peak N in</td>
|
||||||
<td id="coils12_peak_n_in">-</td>
|
<td id="a_coils12_peak_n_in">-</td>
|
||||||
<td id="coils34_peak_n_in">-</td>
|
<td id="a_coils34_peak_n_in">-</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Peak P out</td>
|
<td>Peak P out</td>
|
||||||
<td id="coils12_peak_p_out">-</td>
|
<td id="a_coils12_peak_p_out">-</td>
|
||||||
<td id="coils34_peak_p_out">-</td>
|
<td id="a_coils34_peak_p_out">-</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Peak N out</td>
|
<td>Peak N out</td>
|
||||||
<td id="coils12_peak_n_out">-</td>
|
<td id="a_coils12_peak_n_out">-</td>
|
||||||
<td id="coils34_peak_n_out">-</td>
|
<td id="a_coils34_peak_n_out">-</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Level spark</td>
|
<td>Level spark</td>
|
||||||
<td id="coils12_level_spark">-</td>
|
<td id="a_coils12_level_spark">-</td>
|
||||||
<td id="coils34_level_spark">-</td>
|
<td id="a_coils34_level_spark">-</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Spark Events</td>
|
<td>Spark Events</td>
|
||||||
<td id="coils12_n_events">-</td>
|
<td id="a_coils12_n_events">-</td>
|
||||||
<td id="coils34_n_events">-</td>
|
<td id="a_coils34_n_events">-</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Missed Events</td>
|
<td>Missed Events</td>
|
||||||
<td id="coils12_n_missed_firing">-</td>
|
<td id="a_coils12_n_missed_firing">-</td>
|
||||||
<td id="coils34_n_missed_firing">-</td>
|
<td id="a_coils34_n_missed_firing">-</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</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 class="upload-section">
|
<div class="upload-section">
|
||||||
<h3>Upload file to Flash</h3>
|
<h3>Upload file to Flash</h3>
|
||||||
<p>Select a file and upload it to Flash.</p>
|
<p>Select a file and upload it to Flash.</p>
|
||||||
|
|||||||
+67
-28
@@ -46,36 +46,75 @@ function connectWS() {
|
|||||||
lastMessageTimestamp = Date.now();
|
lastMessageTimestamp = Date.now();
|
||||||
setLoadingIndicator(false);
|
setLoadingIndicator(false);
|
||||||
|
|
||||||
document.getElementById("datavalid").textContent = data.datavalid ?? "-";
|
// Update Box_A
|
||||||
document.getElementById("timestamp").textContent = data.timestamp ?? "-";
|
if (data.box_a) {
|
||||||
document.getElementById("volts_gen").textContent = data.volts_gen ?? "-";
|
const boxA = data.box_a;
|
||||||
document.getElementById("eng_rpm").textContent = data.eng_rpm ?? "-";
|
document.getElementById("a_datavalid").textContent = boxA.datavalid ?? "-";
|
||||||
document.getElementById("adc_read_time").textContent = data.adc_read_time ?? "-";
|
document.getElementById("a_timestamp").textContent = boxA.timestamp ?? "-";
|
||||||
document.getElementById("n_queue_errors").textContent = data.n_queue_errors ?? "-";
|
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 coils12 = data.coils12 || {};
|
const coils12A = boxA.coils12 || {};
|
||||||
const coils34 = data.coils34 || {};
|
const coils34A = boxA.coils34 || {};
|
||||||
|
|
||||||
document.getElementById("coils12_spark_delay").textContent = coils12.spark_delay ?? "-";
|
document.getElementById("a_coils12_spark_delay").textContent = coils12A.spark_delay ?? "-";
|
||||||
document.getElementById("coils34_spark_delay").textContent = coils34.spark_delay ?? "-";
|
document.getElementById("a_coils34_spark_delay").textContent = coils34A.spark_delay ?? "-";
|
||||||
document.getElementById("coils12_spark_status").textContent = coils12.spark_status ?? "-";
|
document.getElementById("a_coils12_spark_status").textContent = coils12A.spark_status ?? "-";
|
||||||
document.getElementById("coils34_spark_status").textContent = coils34.spark_status ?? "-";
|
document.getElementById("a_coils34_spark_status").textContent = coils34A.spark_status ?? "-";
|
||||||
document.getElementById("coils12_sstart_status").textContent = coils12.sstart_status ?? "-";
|
document.getElementById("a_coils12_sstart_status").textContent = coils12A.sstart_status ?? "-";
|
||||||
document.getElementById("coils34_sstart_status").textContent = coils34.sstart_status ?? "-";
|
document.getElementById("a_coils34_sstart_status").textContent = coils34A.sstart_status ?? "-";
|
||||||
document.getElementById("coils12_peak_p_in").textContent = coils12.peak_p_in ?? "-";
|
document.getElementById("a_coils12_peak_p_in").textContent = coils12A.peak_p_in ?? "-";
|
||||||
document.getElementById("coils34_peak_p_in").textContent = coils34.peak_p_in ?? "-";
|
document.getElementById("a_coils34_peak_p_in").textContent = coils34A.peak_p_in ?? "-";
|
||||||
document.getElementById("coils12_peak_n_in").textContent = coils12.peak_n_in ?? "-";
|
document.getElementById("a_coils12_peak_n_in").textContent = coils12A.peak_n_in ?? "-";
|
||||||
document.getElementById("coils34_peak_n_in").textContent = coils34.peak_n_in ?? "-";
|
document.getElementById("a_coils34_peak_n_in").textContent = coils34A.peak_n_in ?? "-";
|
||||||
document.getElementById("coils12_peak_p_out").textContent = coils12.peak_p_out ?? "-";
|
document.getElementById("a_coils12_peak_p_out").textContent = coils12A.peak_p_out ?? "-";
|
||||||
document.getElementById("coils34_peak_p_out").textContent = coils34.peak_p_out ?? "-";
|
document.getElementById("a_coils34_peak_p_out").textContent = coils34A.peak_p_out ?? "-";
|
||||||
document.getElementById("coils12_peak_n_out").textContent = coils12.peak_n_out ?? "-";
|
document.getElementById("a_coils12_peak_n_out").textContent = coils12A.peak_n_out ?? "-";
|
||||||
document.getElementById("coils34_peak_n_out").textContent = coils34.peak_n_out ?? "-";
|
document.getElementById("a_coils34_peak_n_out").textContent = coils34A.peak_n_out ?? "-";
|
||||||
document.getElementById("coils12_level_spark").textContent = coils12.level_spark ?? "-";
|
document.getElementById("a_coils12_level_spark").textContent = coils12A.level_spark ?? "-";
|
||||||
document.getElementById("coils34_level_spark").textContent = coils34.level_spark ?? "-";
|
document.getElementById("a_coils34_level_spark").textContent = coils34A.level_spark ?? "-";
|
||||||
document.getElementById("coils12_n_events").textContent = coils12.n_events ?? "-";
|
document.getElementById("a_coils12_n_events").textContent = coils12A.n_events ?? "-";
|
||||||
document.getElementById("coils34_n_events").textContent = coils34.n_events ?? "-";
|
document.getElementById("a_coils34_n_events").textContent = coils34A.n_events ?? "-";
|
||||||
document.getElementById("coils12_n_missed_firing").textContent = coils12.n_missed_firing ?? "-";
|
document.getElementById("a_coils12_n_missed_firing").textContent = coils12A.n_missed_firing ?? "-";
|
||||||
document.getElementById("coils34_n_missed_firing").textContent = coils34.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 ?? "-";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,10 +35,13 @@ body {
|
|||||||
.logo {
|
.logo {
|
||||||
height: 50px;
|
height: 50px;
|
||||||
width: auto;
|
width: auto;
|
||||||
|
margin: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.page-header h1 {
|
.page-header h1 {
|
||||||
margin: 5px;
|
margin: auto;
|
||||||
|
margin-top: 20px;
|
||||||
|
text-align: center;
|
||||||
font-size: 28px;
|
font-size: 28px;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
}
|
}
|
||||||
@@ -159,21 +162,57 @@ button:hover {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Data section */
|
.tables-container {
|
||||||
div[style*="max-width: 900px"] {
|
display: flex;
|
||||||
|
gap: 20px;
|
||||||
|
max-width: 1800px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 0 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.box {
|
||||||
|
flex: 1;
|
||||||
background: white;
|
background: white;
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
|
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;
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
div[style*="max-width: 900px"] p {
|
.box-data p {
|
||||||
margin: 8px 0;
|
margin: 8px 0;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
div[style*="max-width: 900px"] strong {
|
.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);
|
color: var(--primary-blue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
#include <led.h>
|
||||||
|
|
||||||
|
RGBled::RGBled(const uint8_t pin) : m_led(pin)
|
||||||
|
{
|
||||||
|
pinMode(m_led, OUTPUT);
|
||||||
|
writeStatus(RGBled::ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
RGBled::~RGBled()
|
||||||
|
{
|
||||||
|
pinMode(m_led, INPUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
RGBled::color_u u{.status = s};
|
||||||
|
rgbLedWrite(m_led, u.color.r, u.color.g, u.color.b);
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
#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, g, r, b;
|
||||||
|
};
|
||||||
|
|
||||||
|
union color_u
|
||||||
|
{
|
||||||
|
uint32_t status;
|
||||||
|
color_t color;
|
||||||
|
};
|
||||||
|
|
||||||
|
public:
|
||||||
|
RGBled(const uint8_t pin = 48);
|
||||||
|
~RGBled();
|
||||||
|
|
||||||
|
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;
|
||||||
|
const uint8_t m_led;
|
||||||
|
};
|
||||||
+12
-14
@@ -20,23 +20,22 @@ lib_deps =
|
|||||||
hideakitai/PCA95x5@^0.1.3
|
hideakitai/PCA95x5@^0.1.3
|
||||||
me-no-dev/AsyncTCP@^3.3.2
|
me-no-dev/AsyncTCP@^3.3.2
|
||||||
me-no-dev/ESPAsyncWebServer@^3.6.0
|
me-no-dev/ESPAsyncWebServer@^3.6.0
|
||||||
|
adafruit/Adafruit NeoPixel@^1.15.4
|
||||||
upload_protocol = esptool
|
upload_protocol = esptool
|
||||||
upload_port = COM8
|
upload_port = /dev/ttyACM1
|
||||||
upload_speed = 921600
|
upload_speed = 921600
|
||||||
monitor_port = COM4
|
monitor_port = /dev/ttyACM0
|
||||||
monitor_speed = 921600
|
monitor_speed = 921600
|
||||||
build_type = release
|
build_type = release
|
||||||
build_flags =
|
build_flags =
|
||||||
-DCORE_DEBUG_LEVEL=1
|
-DCORE_DEBUG_LEVEL=1
|
||||||
-DARDUINO_USB_CDC_ON_BOOT=0
|
-DARDUINO_USB_CDC_ON_BOOT=0
|
||||||
-DARDUINO_USB_MODE=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_MAX_ACK_TIME=5000
|
||||||
-DCONFIG_ASYNC_TCP_PRIORITY=20
|
-DCONFIG_ASYNC_TCP_PRIORITY=21
|
||||||
-DCONFIG_ASYNC_TCP_QUEUE_SIZE=128
|
-DCONFIG_ASYNC_TCP_QUEUE_SIZE=64
|
||||||
-DCONFIG_ASYNC_TCP_RUNNING_CORE=1
|
-DCONFIG_ASYNC_TCP_RUNNING_CORE=1
|
||||||
-DCONFIG_ASYNC_TCP_STACK_SIZE=8192
|
-DCONFIG_ASYNC_TCP_STACK_SIZE=4096
|
||||||
-fstack-protector-all
|
-fstack-protector-all
|
||||||
|
|
||||||
[env:esp32-s3-devkitc1-n16r8-debug]
|
[env:esp32-s3-devkitc1-n16r8-debug]
|
||||||
@@ -47,10 +46,11 @@ platform = ${env:esp32-s3-devkitc1-n16r8.platform}
|
|||||||
framework = ${env:esp32-s3-devkitc1-n16r8.framework}
|
framework = ${env:esp32-s3-devkitc1-n16r8.framework}
|
||||||
lib_deps =
|
lib_deps =
|
||||||
${env:esp32-s3-devkitc1-n16r8.lib_deps}
|
${env:esp32-s3-devkitc1-n16r8.lib_deps}
|
||||||
|
adafruit/Adafruit NeoPixel@^1.15.4
|
||||||
upload_protocol = esptool
|
upload_protocol = esptool
|
||||||
upload_port = COM8
|
upload_port = /dev/ttyACM1
|
||||||
upload_speed = 921600
|
upload_speed = 921600
|
||||||
monitor_port = COM4
|
monitor_port = /dev/ttyACM0
|
||||||
monitor_speed = 921600
|
monitor_speed = 921600
|
||||||
debug_tool = esp-builtin
|
debug_tool = esp-builtin
|
||||||
debug_speed = 15000
|
debug_speed = 15000
|
||||||
@@ -62,11 +62,9 @@ build_flags =
|
|||||||
-DCORE_DEBUG_LEVEL=3
|
-DCORE_DEBUG_LEVEL=3
|
||||||
-DARDUINO_USB_CDC_ON_BOOT=0
|
-DARDUINO_USB_CDC_ON_BOOT=0
|
||||||
-DARDUINO_USB_MODE=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_MAX_ACK_TIME=5000
|
||||||
-DCONFIG_ASYNC_TCP_PRIORITY=20
|
-DCONFIG_ASYNC_TCP_PRIORITY=21
|
||||||
-DCONFIG_ASYNC_TCP_QUEUE_SIZE=128
|
-DCONFIG_ASYNC_TCP_QUEUE_SIZE=64
|
||||||
-DCONFIG_ASYNC_TCP_RUNNING_CORE=1
|
-DCONFIG_ASYNC_TCP_RUNNING_CORE=1
|
||||||
-DCONFIG_ASYNC_TCP_STACK_SIZE=8192
|
-DCONFIG_ASYNC_TCP_STACK_SIZE=4096
|
||||||
-fstack-protector-all
|
-fstack-protector-all
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <psvector.h>
|
||||||
|
|
||||||
// =====================
|
// =====================
|
||||||
// Event Flags (bitmask)
|
// Event Flags (bitmask)
|
||||||
@@ -88,3 +89,7 @@ struct ignitionBoxStatus
|
|||||||
uint32_t n_queue_errors = 0;
|
uint32_t n_queue_errors = 0;
|
||||||
int32_t adc_read_time = 0;
|
int32_t adc_read_time = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
using PSRAMVector = std::vector<T, PSRAMAllocator<T>>;
|
||||||
|
|||||||
@@ -4,7 +4,56 @@
|
|||||||
// ISR (Pass return bitmask to ISR management function)
|
// ISR (Pass return bitmask to ISR management function)
|
||||||
// one function for each wake up pin conncted to a trigger
|
// 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();
|
||||||
|
|
||||||
|
// 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void trig_isr_B(void *arg)
|
||||||
{
|
{
|
||||||
const int64_t time_us = esp_timer_get_time();
|
const int64_t time_us = esp_timer_get_time();
|
||||||
|
|
||||||
|
|||||||
@@ -16,8 +16,8 @@
|
|||||||
|
|
||||||
#define CORE_0 0
|
#define CORE_0 0
|
||||||
#define CORE_1 1
|
#define CORE_1 1
|
||||||
#define RT_TASK_STACK 4096 // in words
|
#define RT_TASK_STACK 2048 // in words
|
||||||
#define RT_TASK_PRIORITY (configMAX_PRIORITIES - 4) // highest priority after wifi tasks
|
#define RT_TASK_PRIORITY (configMAX_PRIORITIES - 6) // highest priority after wifi tasks
|
||||||
|
|
||||||
struct isrParams
|
struct isrParams
|
||||||
{
|
{
|
||||||
@@ -26,4 +26,5 @@ struct isrParams
|
|||||||
TaskHandle_t rt_handle_ptr;
|
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);
|
||||||
|
|||||||
+140
-66
@@ -14,12 +14,10 @@
|
|||||||
#include <datasave.h>
|
#include <datasave.h>
|
||||||
#include <webserver.h>
|
#include <webserver.h>
|
||||||
#include <ui.h>
|
#include <ui.h>
|
||||||
|
#include <led.h>
|
||||||
|
|
||||||
// FreeRTOS directives
|
// Defines to enable channel B
|
||||||
#include "freertos/FreeRTOS.h"
|
#define CH_B_ENABLE
|
||||||
#include "freertos/task.h"
|
|
||||||
|
|
||||||
// #define CH_B_ENABLE
|
|
||||||
#define TEST
|
#define TEST
|
||||||
|
|
||||||
// Debug Defines
|
// Debug Defines
|
||||||
@@ -75,16 +73,27 @@ void setup()
|
|||||||
initSparkPinInputs();
|
initSparkPinInputs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////// MAIN LOOP //////////////////////
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
// global variables
|
// global variables
|
||||||
|
RGBled led;
|
||||||
|
led.setStatus(RGBled::LedStatus::INIT);
|
||||||
bool running = true;
|
bool running = true;
|
||||||
const uint32_t max_queue = 128;
|
const uint32_t max_queue = 128;
|
||||||
const uint32_t filter_k = 10;
|
const uint32_t filter_k = 10;
|
||||||
|
|
||||||
PSRAMVector<ignitionBoxStatus> ignA_history_0(max_history);
|
PSRAMVector<ignitionBoxStatus> ignA_history_0(max_history);
|
||||||
PSRAMVector<ignitionBoxStatus> ignA_history_1(max_history);
|
PSRAMVector<ignitionBoxStatus> ignA_history_1(max_history);
|
||||||
auto *active_history = &ignA_history_0;
|
auto *active_history_A = &ignA_history_0;
|
||||||
auto *writable_history = &ignA_history_1;
|
auto *writable_history_A = &ignA_history_1;
|
||||||
|
|
||||||
|
#ifdef CH_B_ENABLE
|
||||||
|
PSRAMVector<ignitionBoxStatus> ignB_history_0(max_history);
|
||||||
|
PSRAMVector<ignitionBoxStatus> ignB_history_1(max_history);
|
||||||
|
auto *active_history_B = &ignB_history_0;
|
||||||
|
auto *writable_history_B = &ignB_history_1;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Resources Initialization
|
// Resources Initialization
|
||||||
Devices dev;
|
Devices dev;
|
||||||
@@ -94,20 +103,36 @@ void loop()
|
|||||||
// Data Queue for real time task to main loop communication
|
// Data Queue for real time task to main loop communication
|
||||||
QueueHandle_t rt_taskA_queue = xQueueCreate(max_queue, sizeof(ignitionBoxStatus));
|
QueueHandle_t rt_taskA_queue = xQueueCreate(max_queue, sizeof(ignitionBoxStatus));
|
||||||
QueueHandle_t rt_taskB_queue = xQueueCreate(max_queue, sizeof(ignitionBoxStatus));
|
QueueHandle_t rt_taskB_queue = xQueueCreate(max_queue, sizeof(ignitionBoxStatus));
|
||||||
|
|
||||||
rtTaskParams taskA_params{
|
rtTaskParams taskA_params{
|
||||||
.rt_running = true,
|
.rt_running = true,
|
||||||
.dev = &dev,
|
.dev = &dev,
|
||||||
.rt_handle_ptr = &trigA_TaskHandle,
|
|
||||||
.rt_queue = rt_taskA_queue,
|
.rt_queue = rt_taskA_queue,
|
||||||
.rt_int = rtTaskInterrupts{
|
.rt_int = rtTaskInterrupts{
|
||||||
.isr_ptr = trig_isr,
|
.isr_ptr = &trig_isr_A,
|
||||||
.trig_pin_12p = TRIG_PIN_A12P,
|
.trig_pin_12p = TRIG_PIN_A12P,
|
||||||
.trig_pin_12n = TRIG_PIN_A12N,
|
.trig_pin_12n = TRIG_PIN_A12N,
|
||||||
.trig_pin_34p = TRIG_PIN_A34P,
|
.trig_pin_34p = TRIG_PIN_A34P,
|
||||||
.trig_pin_34n = TRIG_PIN_A34N,
|
.trig_pin_34n = TRIG_PIN_A34N,
|
||||||
.spark_pin_12 = SPARK_PIN_A12,
|
.spark_pin_12 = SPARK_PIN_A12,
|
||||||
.spark_pin_34 = SPARK_PIN_A34},
|
.spark_pin_34 = SPARK_PIN_A34},
|
||||||
.rt_resets = rtTaskResets{.rst_io_peak= RST_EXT_PEAK_DETECT, .rst_io_sh = RST_EXT_SAMPLE_HOLD}};
|
.rt_resets = rtTaskResets{.rst_io_peak = RST_EXT_PEAK_DETECT_A, .rst_io_sh = RST_EXT_SAMPLE_HOLD_A}};
|
||||||
|
|
||||||
|
#ifdef CH_B_ENABLE
|
||||||
|
rtTaskParams taskB_params{
|
||||||
|
.rt_running = true,
|
||||||
|
.dev = &dev,
|
||||||
|
.rt_queue = rt_taskB_queue,
|
||||||
|
.rt_int = rtTaskInterrupts{
|
||||||
|
.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_resets = rtTaskResets{.rst_io_peak = RST_EXT_PEAK_DETECT_B, .rst_io_sh = RST_EXT_SAMPLE_HOLD_B}};
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!rt_taskA_queue || !rt_taskB_queue)
|
if (!rt_taskA_queue || !rt_taskB_queue)
|
||||||
{
|
{
|
||||||
@@ -119,24 +144,6 @@ void loop()
|
|||||||
else
|
else
|
||||||
LOG_DEBUG("Task Variables OK");
|
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
|
// Spi ok flags
|
||||||
bool spiA_ok = true;
|
bool spiA_ok = true;
|
||||||
bool spiB_ok = true;
|
bool spiB_ok = true;
|
||||||
@@ -145,9 +152,11 @@ void loop()
|
|||||||
spiA_ok = SPI_A.begin(SPI_A_SCK, SPI_A_MISO, SPI_A_MOSI);
|
spiA_ok = SPI_A.begin(SPI_A_SCK, SPI_A_MISO, SPI_A_MOSI);
|
||||||
SPI_A.setDataMode(SPI_MODE1); // ADS1256 requires SPI mode 1
|
SPI_A.setDataMode(SPI_MODE1); // ADS1256 requires SPI mode 1
|
||||||
#ifdef CH_B_ENABLE
|
#ifdef CH_B_ENABLE
|
||||||
|
#ifndef TEST
|
||||||
SPIClass SPI_B(HSPI);
|
SPIClass SPI_B(HSPI);
|
||||||
spiB_ok = SPI_B.begin(SPI_B_SCK, SPI_B_MISO, SPI_B_MOSI);
|
spiB_ok = SPI_B.begin(SPI_B_SCK, SPI_B_MISO, SPI_B_MOSI);
|
||||||
SPI_B.setDataMode(SPI_MODE1); // ADS1256 requires SPI mode 1
|
SPI_B.setDataMode(SPI_MODE1); // ADS1256 requires SPI mode 1
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
if (!spiA_ok || !spiB_ok)
|
if (!spiA_ok || !spiB_ok)
|
||||||
{
|
{
|
||||||
@@ -158,18 +167,21 @@ void loop()
|
|||||||
}
|
}
|
||||||
LOG_DEBUG("Init SPI OK");
|
LOG_DEBUG("Init SPI OK");
|
||||||
|
|
||||||
|
#ifndef TEST
|
||||||
// Init ADC_A
|
// Init ADC_A
|
||||||
dev.adc_a = new ADS1256(ADC_A_DRDY, ADS1256::PIN_UNUSED, ADS1256::PIN_UNUSED, ADC_A_CS, 2.5, &SPI_A);
|
dev.adc_a = new ADS1256(ADC_A_DRDY, ADS1256::PIN_UNUSED, ADS1256::PIN_UNUSED, ADC_A_CS, 2.5, &SPI_A);
|
||||||
dev.adc_a->InitializeADC();
|
dev.adc_a->InitializeADC();
|
||||||
dev.adc_a->setPGA(PGA_1);
|
dev.adc_a->setPGA(PGA_1);
|
||||||
dev.adc_a->setDRATE(DRATE_7500SPS);
|
dev.adc_a->setDRATE(DRATE_7500SPS);
|
||||||
|
#endif
|
||||||
#ifdef CH_B_ENABLE
|
#ifdef CH_B_ENABLE
|
||||||
|
#ifndef TEST
|
||||||
// Init ADC_B
|
// 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 = new ADS1256(ADC_B_DRDY, ADS1256::PIN_UNUSED, ADS1256::PIN_UNUSED, ADC_B_CS, 2.5, &SPI_B);
|
||||||
dev.adc_a->InitializeADC();
|
dev.adc_a->InitializeADC();
|
||||||
dev.adc_a->setPGA(PGA_1);
|
dev.adc_a->setPGA(PGA_1);
|
||||||
dev.adc_a->setDRATE(DRATE_1000SPS);
|
dev.adc_a->setDRATE(DRATE_1000SPS);
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
LOG_DEBUG("Init ADC OK");
|
LOG_DEBUG("Init ADC OK");
|
||||||
@@ -178,7 +190,7 @@ void loop()
|
|||||||
auto ignA_task_success = pdPASS;
|
auto ignA_task_success = pdPASS;
|
||||||
ignA_task_success = xTaskCreatePinnedToCore(
|
ignA_task_success = xTaskCreatePinnedToCore(
|
||||||
rtIgnitionTask,
|
rtIgnitionTask,
|
||||||
"rtIgnitionTask_boxA",
|
"rtTask_A",
|
||||||
RT_TASK_STACK,
|
RT_TASK_STACK,
|
||||||
(void *)&taskA_params,
|
(void *)&taskA_params,
|
||||||
RT_TASK_PRIORITY,
|
RT_TASK_PRIORITY,
|
||||||
@@ -188,10 +200,11 @@ void loop()
|
|||||||
|
|
||||||
// Ignition B on Core 1
|
// Ignition B on Core 1
|
||||||
auto ignB_task_success = pdPASS;
|
auto ignB_task_success = pdPASS;
|
||||||
|
|
||||||
#ifdef CH_B_ENABLE
|
#ifdef CH_B_ENABLE
|
||||||
ignB_task_success = xTaskCreatePinnedToCore(
|
ignB_task_success = xTaskCreatePinnedToCore(
|
||||||
rtIgnitionTask,
|
rtIgnitionTask,
|
||||||
"rtIgnitionTask_boxB",
|
"rtTask_B",
|
||||||
RT_TASK_STACK,
|
RT_TASK_STACK,
|
||||||
(void *)&taskB_params,
|
(void *)&taskB_params,
|
||||||
RT_TASK_PRIORITY, // priorità leggermente più alta
|
RT_TASK_PRIORITY, // priorità leggermente più alta
|
||||||
@@ -209,64 +222,125 @@ void loop()
|
|||||||
}
|
}
|
||||||
|
|
||||||
LOG_DEBUG("Real Time Tasks A & B initialized");
|
LOG_DEBUG("Real Time Tasks A & B initialized");
|
||||||
|
led.setStatus(RGBled::LedStatus::OK);
|
||||||
|
|
||||||
////////////////////// MAIN LOOP //////////////////////
|
|
||||||
bool partial_save = false; // flag to indicate if a partial save has been done after a timeout
|
bool partial_save = false; // flag to indicate if a partial save has been done after a timeout
|
||||||
uint32_t counter = 0;
|
auto last_data = millis();
|
||||||
|
auto last_info = millis();
|
||||||
|
|
||||||
|
uint32_t counter_a = 0;
|
||||||
|
uint32_t counter_b = 0;
|
||||||
uint32_t wait_count = 0;
|
uint32_t wait_count = 0;
|
||||||
ignitionBoxStatus ign_info;
|
|
||||||
ignitionBoxStatusAverage ign_info_avg(filter_k);
|
ignitionBoxStatus ign_info_A;
|
||||||
|
ignitionBoxStatus ign_info_B;
|
||||||
|
|
||||||
|
ignitionBoxStatusAverage ign_info_avg_A(filter_k);
|
||||||
|
ignitionBoxStatusAverage ign_info_avg_B(filter_k);
|
||||||
|
|
||||||
LITTLEFSGuard fsGuard;
|
LITTLEFSGuard fsGuard;
|
||||||
WebPage webPage(80, LittleFS); // Initialize webserver and Websocket
|
WebPage webPage(80, LittleFS); // Initialize webserver and Websocket
|
||||||
|
|
||||||
|
//////////////// INNER LOOP /////////////////////
|
||||||
while (running)
|
while (running)
|
||||||
{
|
{
|
||||||
if (counter >= active_history->size()) // not concurrent with write task
|
auto dataA = pdFALSE;
|
||||||
|
auto dataB = pdFALSE;
|
||||||
|
|
||||||
|
dataA = xQueueReceive(rt_taskA_queue, &ign_info_A, 0);
|
||||||
|
if (counter_a >= active_history_A->size()) // not concurrent with write task
|
||||||
{
|
{
|
||||||
counter = 0;
|
counter_a = 0;
|
||||||
partial_save = false; // reset partial save flag on new data cycle
|
partial_save = false; // reset partial save flag on new data cycle
|
||||||
auto *temp = active_history;
|
swapHistory(active_history_A, writable_history_A);
|
||||||
active_history = writable_history; // switch active and writable buffers
|
save_history(*writable_history_A, "ignition_historyA.csv"); // directly call the save task function to save without delay
|
||||||
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)
|
#ifdef CH_B_ENABLE
|
||||||
|
dataB = xQueueReceive(rt_taskB_queue, &ign_info_B, 0);
|
||||||
|
if (counter_b >= active_history_B->size()) // not concurrent with write task
|
||||||
{
|
{
|
||||||
// printInfo(ign_info);
|
counter_b = 0;
|
||||||
auto &hist = *active_history;
|
partial_save = false; // reset partial save flag on new data cycle
|
||||||
hist[counter++ % active_history->size()] = ign_info;
|
swapHistory(active_history_B, writable_history_B);
|
||||||
ign_info_avg.update(ign_info); // update moving average with latest ignition status
|
save_history(*writable_history_B, "ignition_historyB.csv"); // directly call the save task function to save without delay
|
||||||
Serial.printf("\033[2K Data Received: %d/%d\r", counter, hist.size());
|
|
||||||
if ( counter % filter_k == 0) // send data every 10 samples
|
|
||||||
{
|
|
||||||
Serial.println();
|
|
||||||
LOG_DEBUG("Sending average ignition status to websocket clients...");
|
|
||||||
webPage.sendWsData(ign_info_avg.toJson().as<String>());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
// Update last data
|
||||||
|
if (dataA == pdTRUE || dataB == pdTRUE)
|
||||||
|
last_data = millis();
|
||||||
|
|
||||||
|
// Update Led color
|
||||||
|
if (dataA == pdTRUE && dataB == pdFALSE)
|
||||||
|
led.setStatus(RGBled::DATA_A);
|
||||||
|
else if (dataB == pdTRUE && dataA == pdFALSE)
|
||||||
|
led.setStatus(RGBled::DATA_B);
|
||||||
else
|
else
|
||||||
|
led.setStatus(RGBled::DATA_ALL);
|
||||||
|
|
||||||
|
if (dataA == pdTRUE)
|
||||||
{
|
{
|
||||||
Serial.printf("[%d] Waiting for data...\r", wait_count++);
|
(*active_history_A)[counter_a++ % active_history_A->size()] = ign_info_A;
|
||||||
if (!partial_save && counter > 0) // if timeout occurs but we have unsaved data, save it before next timeout
|
ign_info_avg_A.update(ign_info_A); // update moving average with latest ignition status
|
||||||
|
// Serial.printf("Data Received A: %d/%d\n\r", counter_a, (*active_history_A).size());
|
||||||
|
if (counter_a % filter_k == 0) // send data every 10 samples
|
||||||
{
|
{
|
||||||
active_history->resize(counter); // resize active history to actual number of records received to avoid saving empty records
|
ArduinoJson::JsonDocument wsData;
|
||||||
save_history(*active_history, "ignition_history.csv");
|
wsData["box_a"] = ign_info_avg_A.toJson();
|
||||||
active_history->resize(max_history); // resize back to max history size for next data cycle
|
wsData["box_b"] = JsonObject();
|
||||||
counter = 0; // reset counter after saving
|
webPage.sendWsData(wsData.as<String>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#ifdef CH_B_ENABLE
|
||||||
|
if (dataB == pdTRUE)
|
||||||
|
{
|
||||||
|
(*active_history_B)[counter_b++ % active_history_B->size()] = ign_info_B;
|
||||||
|
ign_info_avg_B.update(ign_info_B); // update moving average with latest ignition status
|
||||||
|
// Serial.printf("Data Received B: %d/%d\n\r", counter_b, (*active_history_B).size());
|
||||||
|
if (counter_b % filter_k == 0) // send data every 10 samples
|
||||||
|
{
|
||||||
|
ArduinoJson::JsonDocument wsData;
|
||||||
|
wsData["box_a"] = JsonObject();
|
||||||
|
wsData["box_b"] = ign_info_avg_B.toJson();
|
||||||
|
webPage.sendWsData(wsData.as<String>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (dataA == pdFALSE && dataB == pdFALSE && (millis() - last_data) > 2000)
|
||||||
|
{
|
||||||
|
if (!partial_save && counter_a > 0) // if timeout occurs but we have unsaved data, save it before next timeout
|
||||||
|
{
|
||||||
|
active_history_A->resize(counter_a); // resize active history to actual number of records received to avoid saving empty records
|
||||||
|
save_history(*active_history_A, "ignition_history_A.csv");
|
||||||
|
active_history_A->resize(max_history); // resize back to max history size for next data cycle
|
||||||
|
#ifdef CH_B_ENABLE
|
||||||
|
active_history_B->resize(counter_a); // resize active history to actual number of records received to avoid saving empty records
|
||||||
|
save_history(*active_history_B, "ignition_history_B.csv");
|
||||||
|
active_history_B->resize(max_history); // resize back to max history size for next data cycle
|
||||||
|
#endif
|
||||||
|
counter_a = 0; // reset counter after saving
|
||||||
|
counter_b = 0; // reset counter after saving
|
||||||
|
|
||||||
partial_save = true;
|
partial_save = true;
|
||||||
first_save = true;
|
first_save = true;
|
||||||
}
|
}
|
||||||
delay(500);
|
// Serial.printf("[%d] Waiting for data...\r", wait_count++);
|
||||||
|
led.setStatus(RGBled::LedStatus::IDLE);
|
||||||
|
delay(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((millis() - last_info) > 1000)
|
||||||
|
{
|
||||||
|
clearScreen();
|
||||||
|
Serial.println();
|
||||||
|
printRunningTasksMod(Serial);
|
||||||
|
last_info = millis();
|
||||||
}
|
}
|
||||||
|
} //////////////// INNER LOOP /////////////////////
|
||||||
|
|
||||||
if (trigA_TaskHandle)
|
if (trigA_TaskHandle)
|
||||||
vTaskDelete(trigA_TaskHandle);
|
vTaskDelete(trigA_TaskHandle);
|
||||||
if (trigB_TaskHandle)
|
if (trigB_TaskHandle)
|
||||||
vTaskDelete(trigB_TaskHandle);
|
vTaskDelete(trigB_TaskHandle);
|
||||||
////////////////////// MAIN LOOP //////////////////////
|
|
||||||
}
|
} ////////////////////// MAIN LOOP //////////////////////
|
||||||
|
|||||||
@@ -84,18 +84,18 @@
|
|||||||
// =====================
|
// =====================
|
||||||
|
|
||||||
// --- RESET LINES ---
|
// --- RESET LINES ---
|
||||||
#define RST_EXT_PEAK_DETECT 0
|
#define RST_EXT_PEAK_DETECT_A 0
|
||||||
#define RST_EXT_SAMPLE_HOLD 1
|
#define RST_EXT_SAMPLE_HOLD_A 1
|
||||||
#define BTN_1 2
|
#define RST_EXT_PEAK_DETECT_B 2
|
||||||
#define BTN_2 3
|
#define RST_EXT_SAMPLE_HOLD_B 3
|
||||||
#define BTN_3 4
|
#define BTN_3 4
|
||||||
#define BTN_4 5
|
#define BTN_4 5
|
||||||
#define BTN_5 6
|
#define BTN_5 6
|
||||||
#define BTN_6 7
|
#define BTN_6 7
|
||||||
|
|
||||||
// --- RELAY ---
|
// --- RELAY ---
|
||||||
#define A_EXT_RELAY 8
|
#define EXT_RELAY_A 8
|
||||||
#define B_EXT_RELAY 9
|
#define EXT_RELAY_B 9
|
||||||
|
|
||||||
// --- STATUS / BUTTON ---
|
// --- STATUS / BUTTON ---
|
||||||
#define BTN_7 10
|
#define BTN_7 10
|
||||||
|
|||||||
@@ -65,7 +65,7 @@
|
|||||||
#define RST_EXT_A34N 3
|
#define RST_EXT_A34N 3
|
||||||
|
|
||||||
// --- RELAY ---
|
// --- RELAY ---
|
||||||
#define A_EXT_RELAY 8
|
#define EXT_RELAY_A 8
|
||||||
|
|
||||||
|
|
||||||
// Init Pin Functions
|
// Init Pin Functions
|
||||||
|
|||||||
@@ -25,6 +25,3 @@ struct PSRAMAllocator {
|
|||||||
heap_caps_free(p);
|
heap_caps_free(p);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
using PSRAMVector = std::vector<T, PSRAMAllocator<T>>;
|
|
||||||
|
|||||||
+25
-17
@@ -17,57 +17,65 @@ void rtIgnitionTask(void *pvParameters)
|
|||||||
LOG_ERROR("Null rt_task_ptr parameters");
|
LOG_ERROR("Null rt_task_ptr parameters");
|
||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
}
|
}
|
||||||
LOG_INFO("rtTask Params OK");
|
|
||||||
|
|
||||||
// Task Parameters and Devices
|
// Task Parameters and Devices
|
||||||
rtTaskParams *params = (rtTaskParams *)pvParameters;
|
rtTaskParams *params = (rtTaskParams *)pvParameters;
|
||||||
const rtTaskInterrupts rt_int = params->rt_int; // copy to avoid external override
|
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 rtTaskResets rt_rst = params->rt_resets; // copy to avoid external override
|
||||||
QueueHandle_t rt_queue = params->rt_queue;
|
QueueHandle_t rt_queue = params->rt_queue;
|
||||||
TaskHandle_t rt_handle_ptr = *params->rt_handle_ptr;
|
|
||||||
Devices *dev = params->dev;
|
Devices *dev = params->dev;
|
||||||
ADS1256 *adc = dev->adc_a;
|
ADS1256 *adc = dev->adc_a;
|
||||||
PCA9555 *io = dev->io;
|
PCA9555 *io = dev->io;
|
||||||
|
|
||||||
|
TaskStatus_t rt_task_info;
|
||||||
|
vTaskGetInfo(NULL, &rt_task_info, pdFALSE, eInvalid);
|
||||||
|
|
||||||
|
const auto rt_task_name = pcTaskGetName(rt_task_info.xHandle);
|
||||||
|
LOG_INFO("rtTask Params OK [", rt_task_name, "]");
|
||||||
|
|
||||||
ignitionBoxStatus ign_box_sts;
|
ignitionBoxStatus ign_box_sts;
|
||||||
|
|
||||||
// Variables for ISR, static to be fixed in memory locations
|
// Variables for ISR, static to be fixed in memory locations
|
||||||
static isrParams isr_params_t12p{
|
isrParams isr_params_t12p{
|
||||||
.flag = TRIG_FLAG_12P,
|
.flag = TRIG_FLAG_12P,
|
||||||
.ign_stat = &ign_box_sts,
|
.ign_stat = &ign_box_sts,
|
||||||
.rt_handle_ptr = rt_handle_ptr};
|
.rt_handle_ptr = rt_task_info.xHandle};
|
||||||
static isrParams isr_params_t12n{
|
isrParams isr_params_t12n{
|
||||||
.flag = TRIG_FLAG_12N,
|
.flag = TRIG_FLAG_12N,
|
||||||
.ign_stat = &ign_box_sts,
|
.ign_stat = &ign_box_sts,
|
||||||
.rt_handle_ptr = rt_handle_ptr};
|
.rt_handle_ptr = rt_task_info.xHandle};
|
||||||
static isrParams isr_params_t34p{
|
isrParams isr_params_t34p{
|
||||||
.flag = TRIG_FLAG_34P,
|
.flag = TRIG_FLAG_34P,
|
||||||
.ign_stat = &ign_box_sts,
|
.ign_stat = &ign_box_sts,
|
||||||
.rt_handle_ptr = rt_handle_ptr};
|
.rt_handle_ptr = rt_task_info.xHandle};
|
||||||
static isrParams isr_params_t34n{
|
isrParams isr_params_t34n{
|
||||||
.flag = TRIG_FLAG_34N,
|
.flag = TRIG_FLAG_34N,
|
||||||
.ign_stat = &ign_box_sts,
|
.ign_stat = &ign_box_sts,
|
||||||
.rt_handle_ptr = rt_handle_ptr};
|
.rt_handle_ptr = rt_task_info.xHandle};
|
||||||
static isrParams isr_params_sp12{
|
isrParams isr_params_sp12{
|
||||||
.flag = SPARK_FLAG_12,
|
.flag = SPARK_FLAG_12,
|
||||||
.ign_stat = &ign_box_sts,
|
.ign_stat = &ign_box_sts,
|
||||||
.rt_handle_ptr = rt_handle_ptr};
|
.rt_handle_ptr = rt_task_info.xHandle};
|
||||||
static isrParams isr_params_sp34{
|
isrParams isr_params_sp34{
|
||||||
.flag = SPARK_FLAG_34,
|
.flag = SPARK_FLAG_34,
|
||||||
.ign_stat = &ign_box_sts,
|
.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
|
// Create esp_timer for microsecond precision timeout
|
||||||
esp_timer_handle_t timeout_timer;
|
esp_timer_handle_t timeout_timer;
|
||||||
esp_timer_create_args_t timer_args = {
|
esp_timer_create_args_t timer_args = {
|
||||||
.callback = spark_timeout_callback,
|
.callback = spark_timeout_callback,
|
||||||
.arg = (void *)rt_handle_ptr,
|
.arg = (void *)rt_task_info.xHandle,
|
||||||
.dispatch_method = ESP_TIMER_TASK,
|
.dispatch_method = ESP_TIMER_TASK,
|
||||||
.name = "spark_timeout"};
|
.name = "spark_timeout"};
|
||||||
esp_timer_create(&timer_args, &timeout_timer);
|
esp_timer_create(&timer_args, &timeout_timer);
|
||||||
|
|
||||||
|
|
||||||
// Attach Pin Interrupts
|
// Attach Pin Interrupts
|
||||||
attachInterruptArg(digitalPinToInterrupt(rt_int.trig_pin_12p), rt_int.isr_ptr, (void *)&isr_params_t12p, RISING);
|
attachInterruptArg(digitalPinToInterrupt(rt_int.trig_pin_12p), rt_int.isr_ptr, (void *)&isr_params_t12p, RISING);
|
||||||
attachInterruptArg(digitalPinToInterrupt(rt_int.trig_pin_12n), rt_int.isr_ptr, (void *)&isr_params_t12n, RISING);
|
attachInterruptArg(digitalPinToInterrupt(rt_int.trig_pin_12n), rt_int.isr_ptr, (void *)&isr_params_t12n, RISING);
|
||||||
@@ -76,7 +84,7 @@ 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_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);
|
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 [", rt_task_name, "]");
|
||||||
|
|
||||||
// Global rt_task_ptr variables
|
// Global rt_task_ptr variables
|
||||||
bool first_cycle = true;
|
bool first_cycle = true;
|
||||||
|
|||||||
@@ -55,7 +55,6 @@ struct rtTaskParams
|
|||||||
{
|
{
|
||||||
bool rt_running; // run flag, false to terminate
|
bool rt_running; // run flag, false to terminate
|
||||||
Devices *dev;
|
Devices *dev;
|
||||||
TaskHandle_t* rt_handle_ptr;
|
|
||||||
const QueueHandle_t rt_queue;
|
const QueueHandle_t rt_queue;
|
||||||
const rtTaskInterrupts rt_int; // interrupt pins to attach
|
const rtTaskInterrupts rt_int; // interrupt pins to attach
|
||||||
const rtTaskResets rt_resets; // reset ping for peak detectors
|
const rtTaskResets rt_resets; // reset ping for peak detectors
|
||||||
|
|||||||
@@ -14,191 +14,3 @@ void printField(const char name[], const char *val);
|
|||||||
|
|
||||||
void printInfo(const ignitionBoxStatus &info);
|
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";
|
|
||||||
@@ -1,4 +1,15 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "freertos_stats.h"
|
||||||
|
#include "sdkconfig.h"
|
||||||
|
|
||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "freertos/portable.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 printBits(uint32_t value) {
|
||||||
std::string result;
|
std::string result;
|
||||||
@@ -12,3 +23,60 @@ std::string printBits(uint32_t value) {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,5 +2,14 @@
|
|||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <datastruct.h>
|
||||||
|
|
||||||
std::string printBits(uint32_t value);
|
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
|
||||||
|
}
|
||||||
|
|||||||
+1
-2
@@ -1,8 +1,7 @@
|
|||||||
{
|
{
|
||||||
"recommendations": [
|
"recommendations": [
|
||||||
"Jason2866.esp-decoder",
|
"Jason2866.esp-decoder",
|
||||||
"pioarduino.pioarduino-ide",
|
"pioarduino.pioarduino-ide"
|
||||||
"platformio.platformio-ide"
|
|
||||||
],
|
],
|
||||||
"unwantedRecommendations": [
|
"unwantedRecommendations": [
|
||||||
"ms-vscode.cpptools-extension-pack"
|
"ms-vscode.cpptools-extension-pack"
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#define DEBUGLOG_DEFAULT_LOG_LEVEL_DEBUG
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <DebugLog.h>
|
#include <DebugLog.h>
|
||||||
|
|
||||||
@@ -18,10 +20,11 @@ static uint32_t count = 0;
|
|||||||
#define PAUSE_LONG_MIN 5000
|
#define PAUSE_LONG_MIN 5000
|
||||||
#define PAUSE_LONG_MAX PAUSE_LONG_MIN * 100
|
#define PAUSE_LONG_MAX PAUSE_LONG_MIN * 100
|
||||||
|
|
||||||
#define RPM_MIN 800
|
#define RPM_MIN 250
|
||||||
#define RPM_MAX 5500
|
#define RPM_MAX 5500
|
||||||
|
|
||||||
void clearScreen(){
|
void clearScreen()
|
||||||
|
{
|
||||||
Serial.print("\033[2J"); // clear screen
|
Serial.print("\033[2J"); // clear screen
|
||||||
Serial.print("\033[H"); // cursor home
|
Serial.print("\033[H"); // cursor home
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
@@ -52,14 +55,38 @@ static timerStatus stsA = {
|
|||||||
.coil_pulse_us = 1000,
|
.coil_pulse_us = 1000,
|
||||||
.spark_pulse_us = 100,
|
.spark_pulse_us = 100,
|
||||||
.spark_delay_us = 50,
|
.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};
|
.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 = 1000,
|
||||||
|
.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;
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
|
|
||||||
Serial.begin(921600);
|
Serial.begin(115200);
|
||||||
delay(1000);
|
delay(1000);
|
||||||
LOG_ATTACH_SERIAL(Serial);
|
LOG_ATTACH_SERIAL(Serial);
|
||||||
|
|
||||||
@@ -80,14 +107,26 @@ void setup()
|
|||||||
pinMode(SPARK_DELAY_POT, ANALOG);
|
pinMode(SPARK_DELAY_POT, ANALOG);
|
||||||
pinMode(FREQ_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);
|
stsA.main_task = xTaskGetCurrentTaskHandleForCore(1);
|
||||||
|
stsB.main_task = xTaskGetCurrentTaskHandleForCore(1);
|
||||||
|
|
||||||
|
// Begin timer with preset fixed frequency
|
||||||
timerA = timerBegin(FREQUENCY);
|
timerA = timerBegin(FREQUENCY);
|
||||||
|
timerB = timerBegin(FREQUENCY);
|
||||||
|
|
||||||
|
// Stop timers because of autostart
|
||||||
timerStop(timerA);
|
timerStop(timerA);
|
||||||
|
timerStop(timerB);
|
||||||
|
|
||||||
|
// Attach interrupts and call callback every timer expiry
|
||||||
timerAttachInterruptArg(timerA, &onTimer, (void *)&stsA);
|
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");
|
LOG_INFO("Setup Complete");
|
||||||
}
|
}
|
||||||
@@ -97,34 +136,58 @@ void loop()
|
|||||||
LOG_INFO("Loop: ", count++);
|
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);
|
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;
|
stsA.spark_delay_us = spark_delay * PERIOD_US;
|
||||||
if (stsA.spark_delay_us > (SPARK_DLY_MIN + SPARK_DLY_MAX) / 2) {
|
if (stsA.spark_delay_us > (SPARK_DLY_MIN + SPARK_DLY_MAX) / 2)
|
||||||
|
{
|
||||||
stsA.soft_start = true;
|
stsA.soft_start = true;
|
||||||
stsA.spark_delay_us -= (SPARK_DLY_MIN + SPARK_DLY_MAX) / 2;
|
stsA.spark_delay_us -= (SPARK_DLY_MIN + SPARK_DLY_MAX) / 2;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
stsA.soft_start = false;
|
stsA.soft_start = false;
|
||||||
}
|
}
|
||||||
|
stsB.soft_start = stsA.soft_start;
|
||||||
|
stsB.spark_delay_us = stsA.spark_delay_us;
|
||||||
|
|
||||||
double new_rpm = (double)(map(analogRead(FREQ_POT), 0, 4096, RPM_MIN, RPM_MAX));
|
double new_rpm = (double)(map(analogRead(FREQ_POT), 0, 4096, RPM_MIN, RPM_MAX));
|
||||||
filtered_rpm = filtered_rpm + 0.1 * (new_rpm - filtered_rpm);
|
filtered_rpm = filtered_rpm + 0.1 * (new_rpm - filtered_rpm);
|
||||||
stsA.pause_long_us = (uint32_t)(60000000.0f / filtered_rpm / 2.0f);
|
stsA.pause_long_us = (uint32_t)(60000000.0f / filtered_rpm / 2.0f);
|
||||||
|
stsB.pause_long_us = stsA.pause_long_us;
|
||||||
|
|
||||||
if (isEnabled) {
|
if (isEnabled_A)
|
||||||
LOG_INFO("==== System is ENABLED ====");
|
LOG_INFO("==== System A is ENABLED ====");
|
||||||
} else {
|
else
|
||||||
LOG_INFO("==== System is DISABLED ====");
|
LOG_INFO("==== System A is DISABLED ====");
|
||||||
}
|
|
||||||
|
if (isEnabled_B)
|
||||||
|
LOG_INFO("==== System B is ENABLED ====");
|
||||||
|
else
|
||||||
|
LOG_INFO("==== System B is DISABLED ====");
|
||||||
|
|
||||||
LOG_INFO("Spark Delay uS: ", stsA.spark_delay_us, "\tSoft Start: ", stsA.soft_start ? "TRUE" : "FALSE");
|
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("Engine Rpm: ", (uint32_t)(filtered_rpm));
|
||||||
LOG_INFO("Coil Pulse: ", stsA.coil_pulse_us, "us");
|
LOG_INFO("Coil Pulse: ", stsA.coil_pulse_us, "us");
|
||||||
LOG_INFO("Spark Pulse: ", stsA.spark_pulse_us, "us");
|
LOG_INFO("Spark Pulse: ", stsA.spark_pulse_us, "us");
|
||||||
|
|
||||||
if (digitalRead(ENABLE_PIN) == LOW && !isEnabled) {
|
if (digitalRead(ENABLE_PIN_A) == LOW && !isEnabled_A)
|
||||||
|
{
|
||||||
timerStart(timerA);
|
timerStart(timerA);
|
||||||
isEnabled = true;
|
isEnabled_A = true;
|
||||||
} else if (digitalRead(ENABLE_PIN) == HIGH && isEnabled) {
|
}
|
||||||
|
else if (digitalRead(ENABLE_PIN_A) == HIGH && isEnabled_A)
|
||||||
|
{
|
||||||
timerStop(timerA);
|
timerStop(timerA);
|
||||||
isEnabled = false;
|
isEnabled_A = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (digitalRead(ENABLE_PIN_B) == LOW && !isEnabled_B)
|
||||||
|
{
|
||||||
|
timerStart(timerB);
|
||||||
|
isEnabled_B = true;
|
||||||
|
}
|
||||||
|
else if (digitalRead(ENABLE_PIN_B) == HIGH && isEnabled_B)
|
||||||
|
{
|
||||||
|
timerStop(timerB);
|
||||||
|
isEnabled_B = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
delay(100);
|
delay(100);
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// Enable Pin
|
// Enable Pin
|
||||||
#define ENABLE_PIN 16
|
#define ENABLE_PIN_A 16
|
||||||
|
#define ENABLE_PIN_B 15
|
||||||
|
|
||||||
///// Ignition Box A /////
|
///// Ignition Box A /////
|
||||||
#define PIN_TRIG_A12P 18
|
#define PIN_TRIG_A12P 18
|
||||||
|
|||||||
@@ -7,20 +7,18 @@ void onTimer(void *arg)
|
|||||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||||
timerStatus *params = (timerStatus *)(arg);
|
timerStatus *params = (timerStatus *)(arg);
|
||||||
TaskHandle_t task = params->main_task;
|
TaskHandle_t task = params->main_task;
|
||||||
|
const timerPins pins = params->pins;
|
||||||
|
|
||||||
// increment state time
|
// increment state time
|
||||||
params->state_time += params->clock_period_us;
|
params->state_time += params->clock_period_us;
|
||||||
|
|
||||||
digitalWrite(PIN_TRIG_B12P, HIGH);
|
|
||||||
|
|
||||||
switch (params->state)
|
switch (params->state)
|
||||||
{
|
{
|
||||||
|
|
||||||
case S_12P:
|
case S_12P:
|
||||||
if (params->state_time == params->clock_period_us && !params->coil12p_high)
|
if (params->state_time == params->clock_period_us && !params->coil12p_high)
|
||||||
{
|
{
|
||||||
// xTaskNotifyFromISR(task, PIN_TRIG_A12P, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
digitalWrite(pins.pin_trig_12p, HIGH);
|
||||||
digitalWrite(PIN_TRIG_A12P, HIGH);
|
|
||||||
params->coil12p_high = true;
|
params->coil12p_high = true;
|
||||||
wait_sent = false;
|
wait_sent = false;
|
||||||
}
|
}
|
||||||
@@ -29,21 +27,18 @@ void onTimer(void *arg)
|
|||||||
{
|
{
|
||||||
if (params->state_time == params->spark_delay_us)
|
if (params->state_time == params->spark_delay_us)
|
||||||
{
|
{
|
||||||
// xTaskNotifyFromISR(task, SPARK_A12, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
digitalWrite(pins.pin_spark_12, HIGH);
|
||||||
digitalWrite(SPARK_A12, HIGH);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params->state_time == (params->spark_delay_us + params->spark_pulse_us))
|
if (params->state_time == (params->spark_delay_us + params->spark_pulse_us))
|
||||||
{
|
{
|
||||||
// xTaskNotifyFromISR(task, ~SPARK_A12, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
digitalWrite(pins.pin_spark_12, LOW);
|
||||||
digitalWrite(SPARK_A12, LOW);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params->state_time >= params->coil_pulse_us && params->coil12p_high)
|
if (params->state_time >= params->coil_pulse_us && params->coil12p_high)
|
||||||
{
|
{
|
||||||
// xTaskNotifyFromISR(task, ~PIN_TRIG_A12P, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
digitalWrite(pins.pin_trig_12p, LOW);
|
||||||
digitalWrite(PIN_TRIG_A12P, LOW);
|
|
||||||
params->coil12p_high = false;
|
params->coil12p_high = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,8 +52,7 @@ void onTimer(void *arg)
|
|||||||
case S_12N:
|
case S_12N:
|
||||||
if (params->state_time == params->clock_period_us && !params->coil12n_high)
|
if (params->state_time == params->clock_period_us && !params->coil12n_high)
|
||||||
{
|
{
|
||||||
// xTaskNotifyFromISR(task, PIN_TRIG_A12N, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
digitalWrite(pins.pin_trig_12n, HIGH);
|
||||||
digitalWrite(PIN_TRIG_A12N, HIGH);
|
|
||||||
params->coil12n_high = true;
|
params->coil12n_high = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,21 +60,18 @@ void onTimer(void *arg)
|
|||||||
{
|
{
|
||||||
if (params->state_time == params->spark_delay_us)
|
if (params->state_time == params->spark_delay_us)
|
||||||
{
|
{
|
||||||
// xTaskNotifyFromISR(task, SPARK_A12, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
digitalWrite(pins.pin_spark_12, HIGH);
|
||||||
digitalWrite(SPARK_A12, HIGH);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params->state_time == (params->spark_delay_us + params->spark_pulse_us))
|
if (params->state_time == (params->spark_delay_us + params->spark_pulse_us))
|
||||||
{
|
{
|
||||||
// xTaskNotifyFromISR(task, ~SPARK_A12, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
digitalWrite(pins.pin_spark_12, LOW);
|
||||||
digitalWrite(SPARK_A12, LOW);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params->state_time >= params->coil_pulse_us && params->coil12n_high)
|
if (params->state_time >= params->coil_pulse_us && params->coil12n_high)
|
||||||
{
|
{
|
||||||
// xTaskNotifyFromISR(task, ~PIN_TRIG_A12N, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
digitalWrite(pins.pin_trig_12n, LOW);
|
||||||
digitalWrite(PIN_TRIG_A12N, LOW);
|
|
||||||
params->coil12n_high = false;
|
params->coil12n_high = false;
|
||||||
params->state = S_WAIT_10MS;
|
params->state = S_WAIT_10MS;
|
||||||
params->state_time = 0;
|
params->state_time = 0;
|
||||||
@@ -90,7 +81,6 @@ void onTimer(void *arg)
|
|||||||
case S_WAIT_10MS:
|
case S_WAIT_10MS:
|
||||||
if (!wait_sent)
|
if (!wait_sent)
|
||||||
{
|
{
|
||||||
// xTaskNotifyFromISR(task, S_WAIT_10MS, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
|
||||||
wait_sent = true;
|
wait_sent = true;
|
||||||
}
|
}
|
||||||
if (params->state_time >= params->pause_long_us)
|
if (params->state_time >= params->pause_long_us)
|
||||||
@@ -103,8 +93,7 @@ void onTimer(void *arg)
|
|||||||
case S_34P:
|
case S_34P:
|
||||||
if (params->state_time == params->clock_period_us && !params->coil34p_high)
|
if (params->state_time == params->clock_period_us && !params->coil34p_high)
|
||||||
{
|
{
|
||||||
// xTaskNotifyFromISR(task, PIN_TRIG_A34P, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
digitalWrite(pins.pin_trig_34p, HIGH);
|
||||||
digitalWrite(PIN_TRIG_A34P, HIGH);
|
|
||||||
params->coil34p_high = true;;
|
params->coil34p_high = true;;
|
||||||
wait_sent = false;
|
wait_sent = false;
|
||||||
}
|
}
|
||||||
@@ -113,21 +102,18 @@ void onTimer(void *arg)
|
|||||||
{
|
{
|
||||||
if (params->state_time == params->spark_delay_us)
|
if (params->state_time == params->spark_delay_us)
|
||||||
{
|
{
|
||||||
// xTaskNotifyFromISR(task, SPARK_A34, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
digitalWrite(pins.pin_spark_34, HIGH);
|
||||||
digitalWrite(SPARK_A34, HIGH);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params->state_time == params->spark_delay_us + params->spark_pulse_us)
|
if (params->state_time == params->spark_delay_us + params->spark_pulse_us)
|
||||||
{
|
{
|
||||||
// xTaskNotifyFromISR(task, ~SPARK_A34, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
digitalWrite(pins.pin_spark_34, LOW);
|
||||||
digitalWrite(SPARK_A34, LOW);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params->state_time >= params->coil_pulse_us && params->coil34p_high)
|
if (params->state_time >= params->coil_pulse_us && params->coil34p_high)
|
||||||
{
|
{
|
||||||
// xTaskNotifyFromISR(task, ~PIN_TRIG_A34P, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
digitalWrite(pins.pin_trig_34p, LOW);
|
||||||
digitalWrite(PIN_TRIG_A34P, LOW);
|
|
||||||
params->coil34p_high = false;
|
params->coil34p_high = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,8 +127,7 @@ void onTimer(void *arg)
|
|||||||
case S_34N:
|
case S_34N:
|
||||||
if (params->state_time == params->clock_period_us && !params->coil34n_high)
|
if (params->state_time == params->clock_period_us && !params->coil34n_high)
|
||||||
{
|
{
|
||||||
// xTaskNotifyFromISR(task, PIN_TRIG_A34N, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
digitalWrite(pins.pin_trig_34n, HIGH);
|
||||||
digitalWrite(PIN_TRIG_A34N, HIGH);
|
|
||||||
params->coil34n_high = true;
|
params->coil34n_high = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,21 +135,18 @@ void onTimer(void *arg)
|
|||||||
{
|
{
|
||||||
if (params->state_time == params->spark_delay_us)
|
if (params->state_time == params->spark_delay_us)
|
||||||
{
|
{
|
||||||
// xTaskNotifyFromISR(task, SPARK_A34, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
digitalWrite(pins.pin_spark_34, HIGH);
|
||||||
digitalWrite(SPARK_A34, HIGH);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params->state_time == params->spark_delay_us + params->spark_pulse_us)
|
if (params->state_time == params->spark_delay_us + params->spark_pulse_us)
|
||||||
{
|
{
|
||||||
// xTaskNotifyFromISR(task, ~SPARK_A34, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
digitalWrite(pins.pin_spark_34, LOW);
|
||||||
digitalWrite(SPARK_A34, LOW);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params->state_time >= params->coil_pulse_us && params->coil34n_high)
|
if (params->state_time >= params->coil_pulse_us && params->coil34n_high)
|
||||||
{
|
{
|
||||||
// xTaskNotifyFromISR(task, ~PIN_TRIG_A34N, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
digitalWrite(pins.pin_trig_34n, LOW);
|
||||||
digitalWrite(PIN_TRIG_A34N, LOW);
|
|
||||||
params->coil34n_high = false;
|
params->coil34n_high = false;
|
||||||
params->state = S_WAIT_10MS_END;
|
params->state = S_WAIT_10MS_END;
|
||||||
params->state_time = 0;
|
params->state_time = 0;
|
||||||
@@ -174,7 +156,6 @@ void onTimer(void *arg)
|
|||||||
case S_WAIT_10MS_END:
|
case S_WAIT_10MS_END:
|
||||||
if (!wait_sent)
|
if (!wait_sent)
|
||||||
{
|
{
|
||||||
// xTaskNotifyFromISR(task, S_WAIT_10MS_END, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
|
||||||
wait_sent = true;
|
wait_sent = true;
|
||||||
}
|
}
|
||||||
if (params->state_time >= params->pause_long_us)
|
if (params->state_time >= params->pause_long_us)
|
||||||
@@ -185,8 +166,6 @@ void onTimer(void *arg)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
digitalWrite(PIN_TRIG_B12P, LOW);
|
|
||||||
|
|
||||||
if (xHigherPriorityTaskWoken)
|
if (xHigherPriorityTaskWoken)
|
||||||
portYIELD_FROM_ISR();
|
portYIELD_FROM_ISR();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#define DEBUGLOG_DEFAULT_LOG_LEVEL_DEBUG
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <DebugLog.h>
|
#include <DebugLog.h>
|
||||||
#include "pins.h"
|
#include "pins.h"
|
||||||
@@ -19,6 +21,15 @@ enum State
|
|||||||
S_WAIT_10MS_END
|
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
|
struct timerStatus
|
||||||
{
|
{
|
||||||
State state = State::S_12P;
|
State state = State::S_12P;
|
||||||
@@ -34,6 +45,7 @@ struct timerStatus
|
|||||||
bool coil34p_high = false;
|
bool coil34p_high = false;
|
||||||
bool coil12n_high = false;
|
bool coil12n_high = false;
|
||||||
bool coil34n_high = false;
|
bool coil34n_high = false;
|
||||||
|
timerPins pins;
|
||||||
TaskHandle_t main_task;
|
TaskHandle_t main_task;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user