Compare commits

...

6 Commits

11 changed files with 339 additions and 357 deletions

View File

@ -102,37 +102,33 @@
<hr />
<p>
<h4>&Ouml;lvorrat</h4>
<form action="post.htm" method="POST" class="form-horizontal">
<div class="form-group row">
<label for="tankremain_maint" class="control-label col-4">Tankinhalt verbleibend</label>
<div class="col-8">
<div class="progress">
<div id="tankremain_maint" class="data-tankremain progress-bar text-light" role="progressbar"
aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"
style="width: 0%">
%TANK_REMAIN_CAPACITY%&#37;
style="width: 0%">0%
</div>
</div>
</div>
</div>
<div class="form-group row">
<div class="col text-center">
<button name="resettank" type="submit" class="btn btn-outline-primary ml-2">Tank zurücksetzen</button>
<button id="resettank" class="btn-wsevent btn btn-outline-primary ml-2">Tank zurücksetzen</button>
</div>
</div>
</form>
</p>
<!-- Div Group Tank remain -->
<!-- Div Group Purging -->
<hr />
<p>
<h4>Entl&uuml;ftung</h4>
<form action="post.htm" method="POST" class="form-horizontal">
<div class="form-group row">
<label for="bleedingpulses" class="control-label col-4">Entl&uuml;ftung Dosierung</label>
<div class="col-8">
<div class="input-group">
<input id="bleedingpulses" name="bleedingpulses" value="0" type="text" class="data-bleedingpulses form-control">
<input id="bleedingpulses" value="0" type="text" class="set-wsevent data-bleedingpulses form-control">
<div class="input-group-append">
<span class="input-group-text">Pulse</span>
</div>
@ -141,11 +137,9 @@
</div>
<div class="form-group row">
<div class="col text-center">
<button name="maintsave" type="submit" class="btn btn-outline-primary">Speichern</button>
<button name="purgenow" type="submit" class="btn btn-outline-primary ml-2">Entlüftung starten</button>
<button id="purgenow" class="btn-wsevent btn btn-outline-primary ml-2">Entlüftung starten</button>
</div>
</div>
</form>
</p>
<!-- Div Group Purging -->
<!-- Div Group Measure -->
@ -153,13 +147,11 @@
<hr />
<p>
<h4>Einmessen</h4>
<form action="post.htm" method="POST" class="form-horizontal">
<div class="form-group row">
<label for="measuredpulses" class="control-label col-4">erfasste Pulse</label>
<div class="col-8">
<div class="input-group">
<input id="measuredpulses" name="measuredpulses" value="0" type="text" readonly
class="form-control">
<input id="measuredpulses" name="measuredpulses" value="0" type="text" readonly class="form-control">
<div class="input-group-append">
<span class="input-group-text">Pulse</span>
</div>
@ -168,54 +160,13 @@
</div>
<div class="form-group row">
<div class="col text-center">
<button name="measurestartstop" type="submit" class="btn btn-outline-primary">Start</button>
<button name="measurereset" type="submit" class="btn btn-outline-primary ml-2">Reset</button>
<button id="measurestartstop" class="btn-wsevent btn btn-outline-primary">Start</button>
<button id="measurereset" class="btn-wsevent btn btn-outline-primary ml-2">Reset</button>
</div>
</div>
</form>
</p>
</div>
<!-- Div Group Purging -->
<!-- Div Group EEPROM formatting -->
<hr />
<p>
<h4>EEPROM formatieren</h4>
<div class="alert alert-primary alert-dismissable show fade" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<strong>Achtung!</strong><br>
Das Formatieren der EEPROM-Bereiche sollte nur ausgeführt werden wenn es unbedingt erforderlich ist!
Hierdurch werden alle Einstellungen zurück gesetzt bzw. alle Betriebsdaten gehen verloren.
Folgende Situationen erfordern unter anderem eine Formatierung:
- Erstinitialisierung (bei neu aufgebautem Gerät)
- Firmware-Update (nur wenn es die Release-Notes fordern)
</div>
<form action="post.htm" method="POST" class="form-horizontal">
<div class="form-group row">
<div class="offset-4 col-8">
<div class="form-check">
<input class="form-check-input" type="checkbox" name="reset_ee_cfg" id="reset_ee_cfg">
<label class="form-check-label" for="reset_ee_cfg">
Bereich "CFG"
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" name="reset_ee_pds" id="reset_ee_pds">
<label class="form-check-label" for="reset_ee_pds">
Bereich "PDS"
</label>
</div>
</div>
</div>
<div class="form-group row">
<div class="col text-center">
<button name="reset_ee_btn" type="submit" class="btn btn-outline-primary">EEPROM formatieren</button>
</div>
</div>
</form>
</p>
<!-- Div Group EEPROM formatting -->
<!-- Div Group LiveDebug -->
<hr />
<p>
@ -225,8 +176,8 @@
</div>
<div class="form-group row">
<div class="col text-center">
<button id="btn-debugstart" class="btn-wsevent btn btn-outline-primary ml-2">Start</button>
<button id="btn-debugstop" class="btn-wsevent btn btn-outline-primary ml-2">Stop</button>
<button id="debugstart" class="btn-wsevent btn btn-outline-primary ml-2">Start</button>
<button id="debugstop" class="btn-wsevent btn btn-outline-primary ml-2">Stop</button>
</div>
</div>
</p>
@ -237,7 +188,7 @@
<h4>Ger&auml;t neustarten</h4>
<div class="form-group row">
<div class="col text-center">
<button id="btn-reboot" class="btn-wsevent btn btn-outline-primary">Reboot</button>
<button id="reboot" class="btn-wsevent btn btn-outline-primary">Reboot</button>
</div>
</div>
</p>
@ -252,11 +203,10 @@
<hr />
<p>
<h4>Signalquelle</h4>
<form action="post.htm" method="POST" class="form-horizontal">
<div class="form-group row">
<label for="sourceselect" class="control-label col-4">Schnittstelle</label>
<label for="speedsource" class="control-label col-4">Schnittstelle</label>
<div class="col-8">
<select id="sourceselect" name="sourceselect" class="data-sourceselect select form-control">
<select id="speedsource" class="set-wsevent data-speedsource select form-control">
<option value="Impuls">Impuls</option>
<option value="GPS">GPS</option>
<option value="CAN-Bus">CAN-Bus</option>
@ -273,24 +223,21 @@
</div>
<div class="form-group row">
<div class="col text-center">
<button name="sourcesave" type="submit" class="btn btn-outline-primary">&Uuml;bernehmen</button>
<button id="sourcesave" class="btn-wsevent btn btn-outline-primary">&Uuml;bernehmen</button>
</div>
</div>
</form>
</p>
<!-- Div Group Signal Source -->
<!-- Div Group Source:Impulse Settings-->
<div id="showimpulse" class="data-showimpulse removeable">
<div id="showimpulse" class="data-showimpulse hideable">
<hr />
<p>
<h4>Einstellungen Impulseingang</h4>
<form action="post.htm" method="POST" class="form-horizontal">
<div class="form-group row">
<label for="tirewidth" class="control-label col-4">Reifenbreite</label>
<div class="col-8">
<div class="input-group">
<input id="tirewidth" name="tirewidth" type="text" required="required" class="data-tirewidth form-control">
<input id="tirewidth" type="text" required="required" class="set-wsevent data-tirewidth form-control">
<div class="input-group-append">
<span class="input-group-text">mm</span>
</div>
@ -302,7 +249,7 @@
<label for="tireratio" class="control-label col-4">Höhe/Breite-Verhältniss</label>
<div class="col-8">
<div class="input-group">
<input id="tireratio" name="tireratio" type="text" required="required" class="data-tireratio form-control">
<input id="tireratio" type="text" required="required" class="set-wsevent data-tireratio form-control">
<div class="input-group-append">
<span class="input-group-text">mm</span>
</div>
@ -313,7 +260,7 @@
<label for="tiredia" class="control-label col-4">Felgendurchmesser</label>
<div class="col-8">
<div class="input-group">
<input id="tiredia" name="tiredia" type="text" required="required" class="data-tiredia form-control">
<input id="tiredia" type="text" required="required" class="set-wsevent data-tiredia form-control">
<div class="input-group-append">
<span class="input-group-text">"</span>
</div>
@ -324,63 +271,48 @@
<label for="pulserev" class="control-label col-4">Pulse pro Umdrehung</label>
<div class="col-8">
<div class="input-group">
<input id="pulserev" name="pulserev" type="text" required="required" class="data-pulserev form-control">
<input id="pulserev" type="text" required="required" class="set-wsevent data-pulserev form-control">
<div class="input-group-addon"></div>
</div>
</div>
</div>
<div class="form-group row">
<div class="col text-center">
<button name="pulsesave" type="submit" class="btn btn-outline-primary">Speichern</button>
</div>
</div>
</form>
</p>
</div>
<!-- Div Group Source:Impulse Settings-->
<!-- Div Group Source:CAN Settings-->
<div id="showcan" class="data-showcan removeable">
<div id="showcan" class="data-showcan hideable">
<hr />
<p>
<h4>Einstellungen CAN-Bus</h4>
<form action="post.htm" method="POST" class="form-horizontal">
<div class="form-group row">
<label for="cansource" class="control-label col-4">Model</label>
<div class="col-8">
<select id="cansource" name="cansource" class="data-cansource select form-control">
<select id="cansource" class="set-wsevent data-cansource select form-control">
<option value="KTM 890 Adventure R (2021)">KTM 890 Adventure R (2021)</option>
<option value="KTM 1290 Superduke R (2023)">KTM 1290 Superduke R (2023)</option>
</select>
</div>
</div>
<div class="form-group row">
<div class="col text-center">
<button name="cansave" type="submit" class="btn btn-outline-primary">Speichern</button>
</div>
</div>
</form>
</p>
</div>
<!-- Div Group Source:CAN Settings-->
<!-- Div Group Source:GPS Settings-->
<div id="showgps" class="data-showgps removeable">
<div id="showgps" class="data-showgps hideable">
<hr />
<p>
<h4>Einstellungen GPS</h4>
<form action="post.htm" method="POST" class="form-horizontal">
<div class="form-group row">
<label for="gpsbaud" class="control-label col-4">Baudrate</label>
<div class="col-8">
<select id="gpsbaud" name="gpsbaud" class="data-gpsbaud select form-control">
<select id="gpsbaud" class="set-wsevent data-gpsbaud select form-control">
</select>
</div>
</div>
<div class="form-group row">
<div class="col text-center">
<button name="gpssave" type="submit" class="btn btn-outline-primary">Speichern</button>
<button id="gpssave" class="btn-wsevent btn btn-outline-primary">Speichern</button>
</div>
</div>
</form>
</p>
</div>
<!-- Div Group Source:GPS Settings-->
@ -388,13 +320,12 @@
<hr />
<p>
<h4>Dosierung</h4>
<form action="post.htm" method="POST" class="form-horizontal">
<div class="form-group row">
<label for="lubedistancenormal" class="control-label col-4">Normal (gr&uuml;n)</label>
<div class="col-8">
<div class="input-group">
<input id="lubedistancenormal" name="lubedistancenormal" type="text"
class="data-lubedistancenormal form-control" required="required">
<input id="lubedistancenormal" type="text"
class="set-wsevent data-lubedistancenormal form-control" required="required">
<div class="input-group-append">
<span class="input-group-text">m</span>
</div>
@ -405,32 +336,25 @@
<label for="lubedistancerain" class="control-label col-4">Regen (blau)</label>
<div class="col-8">
<div class="input-group">
<input id="lubedistancerain" name="lubedistancerain" type="text"
class="data-lubedistancerain form-control" required="required">
<input id="lubedistancerain" type="text"
class="set-wsevent data-lubedistancerain form-control" required="required">
<div class="input-group-append">
<span class="input-group-text">m</span>
</div>
</div>
</div>
</div>
<div class="form-group row">
<div class="col text-center">
<button name="oilsave" type="submit" class="btn btn-outline-primary">Speichern</button>
</div>
</div>
</form>
</p>
<!-- Div Group Lube Settings-->
<!-- Div Group Oiltank Settings -->
<hr />
<p>
<h4>&Ouml;ltank</h4>
<form action="post.htm" method="POST" class="form-horizontal">
<div class="form-group row">
<label for="tankcap" class="control-label col-4">Tankkapazität</label>
<div class="col-8">
<div class="input-group">
<input id="tankcap" name="tankcap" type="text" class="data-tankcap form-control"
<input id="tankcap" type="text" class="set-wsevent data-tankcap form-control"
required="required">
<div class="input-group-append">
<span class="input-group-text">ml</span>
@ -442,7 +366,7 @@
<label for="tankwarn" class="control-label col-4">Leer-Warnung</label>
<div class="col-8">
<div class="input-group">
<input id="tankwarn" name="tankwarn" type="text" class="data-tankwarn form-control"
<input id="tankwarn" type="text" class="set-wsevent data-tankwarn form-control"
required="required">
<div class="input-group-append">
<span class="input-group-text">&#37;</span>
@ -454,7 +378,7 @@
<label for="pumppulse" class="control-label col-4">Menge pro Puls</label>
<div class="col-8">
<div class="input-group">
<input id="pumppulse" name="pumppulse" type="text" class="data-pumppulse form-control"
<input id="pumppulse" type="text" class="set-wsevent data-pumppulse form-control"
required="required">
<div class="input-group-append">
<span class="input-group-text">µl</span>
@ -462,24 +386,17 @@
</div>
</div>
</div>
<div class="form-group row">
<div class="col text-center">
<button name="oilsave" type="submit" class="btn btn-outline-primary">Speichern</button>
</div>
</div>
</form>
</p>
<!-- Div Group Oiltank Settings -->
<!-- Div Group LED Settings-->
<hr />
<p>
<h4>LED Einstellungen</h4>
<form action="post.htm" method="POST" class="form-horizontal">
<div class="form-group row">
<label for="ledmodeflash" class="control-label col-4">LED Modus blinken</label>
<div class="col-8">
<div class="form-check">
<input class="data-ledmodeflash form-check-input" type="checkbox" name="ledmodeflash" id="ledmodeflash">
<input class="set-wsevent data-ledmodeflash form-check-input" type="checkbox" id="ledmodeflash">
<label class="form-check-label" for="ledmodeflash">
LED blinken
</label>
@ -490,8 +407,7 @@
<label for="ledmaxbrightness" class="control-label col-4">Max Helligkeit</label>
<div class="col-8">
<div class="input-group">
<input id="ledmaxbrightness" name="ledmaxbrightness" type="text"
class="data-ledmaxbrightness form-control" required="required">
<input id="ledmaxbrightness" type="text" class="set-wsevent data-ledmaxbrightness form-control" required="required">
</div>
</div>
</div>
@ -499,19 +415,21 @@
<label for="ledminbrightness" class="control-label col-4">Min Helligkeit</label>
<div class="col-8">
<div class="input-group">
<input id="ledminbrightness" name="ledminbrightness" type="text"
class="data-ledminbrightness form-control" required="required">
<input id="ledminbrightness" type="text" class="set-wsevent data-ledminbrightness form-control" required="required">
</div>
</div>
</div>
<div class="form-group row">
<div class="col text-center">
<button name="ledsave" type="submit" class="btn btn-outline-primary">Speichern</button>
</div>
</div>
</form>
</p>
<!-- Div Group Lube Settings-->
<!-- Div Group Save Button-->
<hr />
<p>
<div class="form-group row">
<div class="col text-center">
<button id="settingssave" class="btn-wsevent btn btn-outline-primary">Speichern</button>
</div>
</div>
</p>
</div>
<!-- Div Tab Settings -->

View File

@ -81,7 +81,8 @@ function getDescriptionForDTCNumber(number, callback) {
fetch(jsonFilePath)
.then((response) => response.json())
.then((data) => {
const foundEntry = data.find((entry) => entry.num === number);
const dtcList = data.dtc_table_data;
const foundEntry = dtcList.find((entry) => entry.num === number);
if (foundEntry) {
const description = foundEntry.description;
@ -102,6 +103,32 @@ function getDescriptionForDTCNumber(number, callback) {
});
}
function showDTCModal(event) {
var dtc = parseInt(event.currentTarget.getAttribute("data-dtc"));
var debugval = event.currentTarget.getAttribute("data-debugval");
var modal = $("#dtcModal");
getDescriptionForDTCNumber(dtc, function (error, title, description) {
if (error) {
console.error("Fehler beim Abrufen der Beschreibung:", error);
modal.find(".modal-title").text("Fehler");
modal
.find(".dtc-desc")
.text("DTC-Beschreibung konnte nicht geladen werden");
} else {
modal.find(".modal-title").text(title);
modal.find(".dtc-desc").text(description);
if (debugval > 0) {
modal.find(".dtc-debugval").text("Debugvalue: " + debugval);
} else {
modal.find(".dtc-debugval").remove();
}
}
});
// Modal anzeigen
modal.modal("show");
}
function fillDTCTable(dtcArray) {
// Referenz auf das Tabellen-Element
var table = document.getElementById("dtc_table");
@ -176,6 +203,7 @@ function fillDTCTable(dtcArray) {
row.setAttribute("data-dtc", dtcInfo[1]);
row.setAttribute("data-debugval", dtcInfo[4]);
row.addEventListener("click", showDTCModal);
// Aktivität
var activityCell = row.insertCell(3);

View File

@ -1,5 +1,7 @@
$(".navbar-nav>li>a").on("click", function () {
$(".navbar-collapse").collapse("hide");
$(document).ready(function(){
$('.navbar-nav a').on('click', function(){
$('.navbar-collapse').collapse('hide');
});
});
document
@ -10,28 +12,5 @@ document
nextSibling.innerText = fileName;
});
$("table").on("click", "tr[data-dtc]", function () {
var dtc = $(this).data("dtc");
var debugval = $(this).data("debugval");
var modal = $("#dtcModal");
getDescriptionForDTCNumber(dtc, function (error, title, description) {
if (error) {
console.error("Fehler beim Abrufen der Beschreibung:", error);
modal.find(".modal-title").text("Fehler");
modal
.find(".dtc-desc")
.text("DTC-Beschreibung konnte nicht geladen werden");
} else {
modal.find(".modal-title").text(title);
modal.find(".dtc-desc").text(description);
if (debugval > 0) {
modal.find(".dtc-debugval").text("Debugvalue: " + debugval);
} else {
modal.find(".dtc-debugval").remove();
}
}
});
// Modal anzeigen
modal.modal("show");
});

View File

@ -15,12 +15,11 @@ function initWebSocket() {
}
function initButtons() {
var elements = document.getElementsByClassName("btn-wsevent");
if (elements.length > 0) {
for (var i = 0; i < elements.length; i++) {
var element = elements[i];
let element = elements[i];
element.addEventListener("click", function () {
websocket_sendevent("btn-" + element.id, 0);
});
@ -29,12 +28,11 @@ function initButtons() {
}
function initSettingInputs() {
var elements = document.getElementsByClassName("btn-wssetting");
var elements = document.getElementsByClassName("set-wsevent");
if (elements.length > 0) {
for (var i = 0; i < elements.length; i++) {
var element = elements[i];
let element = elements[i];
element.addEventListener("change", function () {
websocket_sendevent("set-" + element.id, element.value);
});
@ -173,9 +171,10 @@ function fillValuesToHTML(dataset) {
} else if (element.classList.contains("progress-bar")) {
// Wenn das Element eine Fortschrittsleiste ist
updateProgressBar(element, dataset[key]);
} else if (element.classList.contains("removeable")) {
} else if (element.classList.contains("hideable")) {
// Wenn das Element ein Settingsabschnitt-div ist
if (dataset[key] == 0) element.remove();
if (dataset[key] == 0) element.style.display = "none";
else element.style.display = "";
} else {
// Standardmäßig für Textfelder und andere Elemente
element.value = dataset[key];

View File

@ -14,6 +14,8 @@
#ifndef _COMMON_H_
#define _COMMON_H_
#include <stddef.h>
#define Q(x) #x
#define QUOTE(x) Q(x)
#define SET_BIT(value, bitPosition) ((value) |= (1U << (bitPosition)))
@ -64,6 +66,57 @@
// -> 6.90µl / Pulse
#define DEFAULT_PUMP_DOSE 7
typedef enum eSystem_Status
{
sysStat_Startup,
sysStat_Normal,
sysStat_Rain,
sysStat_Purge,
sysStat_Error,
sysStat_Shutdown
} tSystem_Status;
// Enum for different sources of speed input
typedef enum SpeedSource_e
{
#ifdef FEATURE_ENABLE_TIMER
SOURCE_TIME,
#endif
SOURCE_IMPULSE,
SOURCE_GPS,
SOURCE_CAN
} SpeedSource_t;
// String representation of SpeedSource enum
extern const char *SpeedSourceString[];
extern const size_t SpeedSourceString_Elements;
// Enum for GPS baud rates
typedef enum GPSBaudRate_e
{
BAUD_4800,
BAUD_9600,
BAUD_19200,
BAUD_38400,
BAUD_57600,
BAUD_115200
} GPSBaudRate_t;
// String representation of GPSBaudRate enum
extern const char *GPSBaudRateString[];
extern const size_t GPSBaudRateString_Elements;
// Enum for CAN bus sources
typedef enum CANSource_e
{
KTM_890_ADV_R_2021,
KTM_1290_SD_R_2023
} CANSource_t;
// String representation of CANSource enum
extern const char *CANSourceString[];
extern const size_t CANSourceString_Elements;
#define STARTUP_DELAY 5000
#define SHUTDOWN_DELAY_MS 5000

View File

@ -18,7 +18,6 @@
#include <Arduino.h>
#include <Wire.h>
#include <I2C_eeprom.h>
#include "globals.h"
#include "dtc.h"
#include "common.h"
@ -28,56 +27,19 @@
#define EEPROM_SIZE_BYTES I2C_DEVICESIZE_24LC256
#endif
// Enum for different sources of speed input
typedef enum SpeedSource_e
typedef enum EERequest_e
{
#ifdef FEATURE_ENABLE_TIMER
SOURCE_TIME,
#endif
SOURCE_IMPULSE,
SOURCE_GPS,
SOURCE_CAN
} SpeedSource_t;
EE_IDLE,
EE_CFG_SAVE,
EE_CFG_LOAD,
EE_CFG_FORMAT,
EE_PDS_SAVE,
EE_PDS_LOAD,
EE_PDS_FORMAT,
EE_FORMAT_ALL,
EE_ALL_SAVE
// String representation of SpeedSource enum
const char SpeedSourceString[][8] = {
#ifdef FEATURE_ENABLE_TIMER
"Timer",
#endif
"Impuls",
"GPS",
"CAN-Bus"
};
const size_t SpeedSourceString_Elements = sizeof(SpeedSourceString) / sizeof(SpeedSourceString[0]);
// Enum for GPS baud rates
typedef enum GPSBaudRate_e
{
BAUD_9600,
BAUD_115200
} GPSBaudRate_t;
// String representation of GPSBaudRate enum
const char GPSBaudRateString[][7] = {
"9600",
"115200"};
const size_t GPSBaudRateString_Elements = sizeof(GPSBaudRateString) / sizeof(GPSBaudRateString[0]);
// Enum for CAN bus sources
typedef enum CANSource_e
{
KTM_890_ADV_R_2021,
KTM_1290_SD_R_2023
} CANSource_t;
// String representation of CANSource enum
const char CANSourceString[][30] = {
"KTM 890 Adventure R (2021)",
"KTM 1290 Superduke R (2023)"};
const size_t CANSourceString_Elements = sizeof(CANSourceString) / sizeof(CANSourceString[0]);
} EERequest_t;
// Structure for persistence data stored in EEPROM
typedef struct

View File

@ -15,30 +15,8 @@
#define _GLOBALS_H_
#include <Arduino.h>
typedef enum eSystem_Status
{
sysStat_Startup,
sysStat_Normal,
sysStat_Rain,
sysStat_Purge,
sysStat_Error,
sysStat_Shutdown
} tSystem_Status;
typedef enum eEERequest
{
EE_IDLE,
EE_CFG_SAVE,
EE_CFG_LOAD,
EE_CFG_FORMAT,
EE_PDS_SAVE,
EE_PDS_LOAD,
EE_PDS_FORMAT,
EE_FORMAT_ALL,
EE_ALL_SAVE
} tEERequest;
#include "config.h"
#include "common.h"
typedef struct Globals_s
{
@ -46,7 +24,7 @@ typedef struct Globals_s
tSystem_Status resumeStatus = sysStat_Startup; /**< Status to resume after rain mode */
char systemStatustxt[16] = ""; /**< Text representation of system status */
uint16_t purgePulses = 0; /**< Number of purge pulses */
eEERequest requestEEAction = EE_IDLE;; /**< EEPROM-related request */
EERequest_t requestEEAction = EE_IDLE;; /**< EEPROM-related request */
char DeviceName[33]; /**< Device name */
char FlashVersion[10]; /**< Flash version */
uint16_t eePersistanceAdress; /**< EEPROM persistence address */

32
Software/src/common.cpp Normal file
View File

@ -0,0 +1,32 @@
#include "common.h"
// String representation of SpeedSource enum
const char *SpeedSourceString[] = {
#ifdef FEATURE_ENABLE_TIMER
"Timer",
#endif
"Impuls",
"GPS",
"CAN-Bus"
};
const size_t SpeedSourceString_Elements = sizeof(SpeedSourceString) / sizeof(SpeedSourceString[0]);
// String representation of GPSBaudRate enum
const char *GPSBaudRateString[] = {
"4800",
"9600",
"19200",
"38400",
"57600",
"115200"
};
const size_t GPSBaudRateString_Elements = sizeof(GPSBaudRateString) / sizeof(GPSBaudRateString[0]);
// String representation of CANSource enum
const char *CANSourceString[] = {
"KTM 890 Adventure R (2021)",
"KTM 1290 Superduke R (2023)"};
const size_t CANSourceString_Elements = sizeof(CANSourceString) / sizeof(CANSourceString[0]);

View File

@ -8,6 +8,7 @@
#include "config.h"
#include "debugger.h"
#include "globals.h"
// Instance of I2C_eeprom for EEPROM access
I2C_eeprom ee(0x50, EEPROM_SIZE_BYTES);

View File

@ -151,7 +151,7 @@ void Debug_pushMessage(const char *format, ...)
// Check if either the Serial or WebUI debug port is enabled
if ((DebuggerStatus[dbg_Serial] == enabled) || (DebuggerStatus[dbg_Webui] == enabled))
{
char buff[64]; // Buffer to hold the formatted message
char buff[128]; // Buffer to hold the formatted message
va_list arg; // Variable argument list for vsnprintf
va_start(arg, format);

View File

@ -17,8 +17,9 @@ AsyncWebServer webServer(80);
const char *PARAM_MESSAGE = "message";
SpeedSource_t speedsourcePreselect; /**< Preselect Memory for change SourceAdress */
String processor(const String &var);
void WebserverPOST_Callback(AsyncWebServerRequest *request);
void WebserverNotFound_Callback(AsyncWebServerRequest *request);
void WebserverFirmwareUpdate_Callback(AsyncWebServerRequest *request, const String &filename, size_t index, uint8_t *data, size_t len, bool final);
void WebserverEERestore_Callback(AsyncWebServerRequest *request, const String &filename, size_t index, uint8_t *data, size_t len, bool final);
@ -34,6 +35,8 @@ void Websocket_RefreshClientData_Status(uint32_t client_id, bool send_mapping =
void Websocket_RefreshClientData_Static(uint32_t client_id, bool send_mapping = false);
void Websocket_HandleButtons(uint8_t *data);
void Websocket_HandleSettings(uint8_t *data);
void parseWebsocketString(char *data, char *identifierBuffer, size_t identifierBufferSize, char *valueBuffer, size_t valueBufferSize);
int findIndexByString(const char *searchString, const char *const *array, int arraySize);
/**
* @brief Initializes the web-based user interface (WebUI) for the ChainLube application.
@ -115,119 +118,6 @@ void Webserver_Process()
}
}
void WebserverPOST_Callback(AsyncWebServerRequest *request)
{
request->send(LittleFS, "/post.htm", "text/html", false, processor);
Debug_pushMessage("POST:\n");
int paramsNr = request->params();
for (int i = 0; i < paramsNr; i++)
{
AsyncWebParameter *p = request->getParam(i);
Debug_pushMessage("%s : %s\n", p->name().c_str(), p->value().c_str());
// begin: POST Form Source Changed
if (p->name() == "sourceselect")
{
SpeedSource_t temp = (SpeedSource_t)p->value().toInt();
Debug_pushMessage("temp: %d", temp);
Debug_pushMessage("SpeedSource: %d", LubeConfig.SpeedSource);
if (LubeConfig.SpeedSource != temp)
{
LubeConfig.SpeedSource = temp;
globals.systemStatus = sysStat_Shutdown;
}
}
// end: POST Form Source Changed
// begin: POST Form Source Pulse Settings
if (p->name() == "tirewidth")
LubeConfig.TireWidth_mm = p->value().toInt();
if (p->name() == "tireratio")
LubeConfig.TireWidthHeight_Ratio = p->value().toInt();
if (p->name() == "tiredia")
LubeConfig.RimDiameter_Inch = p->value().toInt();
if (p->name() == "pulserev")
LubeConfig.PulsePerRevolution = p->value().toInt();
if (p->name() == "pulsesave")
globals.requestEEAction = EE_CFG_SAVE;
// end: POST Form Source Pulse Settings
// begin: POST Form Source GPS Settings
if (p->name() == "gpsbaud")
LubeConfig.GPSBaudRate = (GPSBaudRate_t)p->value().toInt();
if (p->name() == "gpssave")
globals.requestEEAction = EE_CFG_SAVE;
// end: POST Form Source GPS Settings
// begin: POST Form Source CAN Settings
if (p->name() == "cansource")
LubeConfig.CANSource = (CANSource_t)p->value().toInt();
if (p->name() == "cansave")
globals.requestEEAction = EE_CFG_SAVE;
// end: POST Form Source CAN Settings
// begin: POST Form Lubrication
if (p->name() == "lubedistancenormal")
LubeConfig.DistancePerLube_Default = p->value().toInt();
if (p->name() == "lubedistancerain")
LubeConfig.DistancePerLube_Rain = p->value().toInt();
if (p->name() == "lubesave")
globals.requestEEAction = EE_CFG_SAVE;
// end: POST Form Lubrication
// begin: POST Form Oiltank
if (p->name() == "tankcap")
LubeConfig.tankCapacity_ml = p->value().toInt();
if (p->name() == "tankwarn")
LubeConfig.TankRemindAtPercentage = p->value().toInt();
if (p->name() == "pumppulse")
LubeConfig.amountPerDose_microL = p->value().toInt();
if (p->name() == "oilsave")
globals.requestEEAction = EE_CFG_SAVE;
// end: POST Form Oiltank
// begin: POST Form Maintenance
if (p->name() == "maintsave")
globals.requestEEAction = EE_CFG_SAVE;
if (p->name() == "resettank")
{
PersistenceData.tankRemain_microL = LubeConfig.tankCapacity_ml * 1000;
globals.requestEEAction = EE_PDS_SAVE;
}
if (p->name() == "reset_ee_btn")
{
if (request->hasParam("reset_ee_pds", true))
{
AsyncWebParameter *param = request->getParam("reset_ee_pds", true);
if (param->value() == "on")
globals.requestEEAction = globals.requestEEAction == EE_CFG_FORMAT ? EE_FORMAT_ALL : EE_PDS_FORMAT;
}
if (request->hasParam("reset_ee_cfg", true))
{
AsyncWebParameter *param = request->getParam("reset_ee_cfg", true);
if (param->value() == "on")
globals.requestEEAction = globals.requestEEAction == EE_PDS_FORMAT ? EE_FORMAT_ALL : EE_CFG_FORMAT;
}
}
// end: POST Form Maintenance
// begin: POST Form LED Settings
if (p->name() == "ledmaxbrightness")
LubeConfig.LED_Max_Brightness = p->value().toInt();
if (p->name() == "ledminbrightness")
LubeConfig.LED_Min_Brightness = p->value().toInt();
if (p->name() == "ledsave")
{
if (request->hasParam("ledmodeflash", true))
{
AsyncWebParameter *param = request->getParam("ledmodeflash", true);
if (param->value() == "on")
LubeConfig.LED_Mode_Flash = true;
}
else
{
LubeConfig.LED_Mode_Flash = false;
}
globals.requestEEAction = EE_CFG_SAVE;
}
// end: POST Form LED SEttings
}
}
/**
* @brief Callback function for handling HTTP 404 (Not Found) errors on the web server.
*
@ -514,12 +404,13 @@ void Websocket_HandleMessage(void *arg, uint8_t *data, size_t len)
if (info->final && info->index == 0 && info->len == len && info->opcode == WS_TEXT)
{
data[len] = 0;
Debug_pushMessage("Websocket-Message (len: %d): %s\n", len, (char *)data);
if (strncmp((char *)data, "btn-", strlen("btn-")) == 0)
{
Websocket_HandleButtons(data + strlen("btn-"));
}
if (strncmp((char *)data, "set-", strlen("set-")) == 0)
else if (strncmp((char *)data, "set-", strlen("set-")) == 0)
{
Websocket_HandleSettings(data + strlen("set-"));
}
@ -530,42 +421,101 @@ void Websocket_HandleMessage(void *arg, uint8_t *data, size_t len)
}
}
/**
* @brief Handle button commands received via WebSocket.
*
* This function parses a WebSocket string representing button commands, extracts
* the identifier and value components, and performs corresponding actions based on
* the received commands.
*
* @param data The WebSocket data containing button commands.
*/
void Websocket_HandleButtons(uint8_t *data)
{
if (strcmp((char *)data, "debugstart") == 0)
char identifier[32];
char value[32];
parseWebsocketString((char *)data, identifier, sizeof(identifier), value, sizeof(value));
if (strcmp(identifier, "debugstart") == 0)
{
SetDebugportStatus(dbg_Webui, enabled);
}
else if (strcmp((char *)data, "debugstop") == 0)
else if (strcmp(identifier, "debugstop") == 0)
{
SetDebugportStatus(dbg_Webui, disabled);
}
else if (strcmp((char *)data, "measurereset") == 0)
else if (strcmp(identifier, "measurereset") == 0)
{
globals.measuredPulses = 0;
}
else if (strcmp((char *)data, "measurestartstop") == 0)
else if (strcmp(identifier, "measurestartstop") == 0)
{
globals.measurementActive = !globals.measurementActive;
}
else if (strcmp((char *)data, "purgenow") == 0)
else if (strcmp(identifier, "purgenow") == 0)
{
globals.systemStatus = sysStat_Purge;
globals.purgePulses = LubeConfig.BleedingPulses;
}
else if (strcmp((char *)data, "reboot") == 0)
else if (strcmp(identifier, "sourcesave") == 0)
{
LubeConfig.SpeedSource = speedsourcePreselect;
globals.requestEEAction = EE_CFG_SAVE;
globals.systemStatus = sysStat_Shutdown;
}
else if (strcmp(identifier, "settingssave") == 0)
{
globals.requestEEAction = EE_CFG_SAVE;
}
else if (strcmp(identifier, "reboot") == 0)
{
globals.systemStatus = sysStat_Shutdown;
}
else
{
Debug_pushMessage("Got unknown Button-id '%s' from ws-client\n", (char *)data);
Debug_pushMessage("Got unknown Button-id '%s' from ws-client\n", identifier);
}
}
/**
* @brief Handle settings commands received via WebSocket.
*
* This function parses a WebSocket string representing settings commands, extracts
* the identifier and value components, and updates the system settings accordingly.
*
* @param data The WebSocket data containing settings commands.
*/
void Websocket_HandleSettings(uint8_t *data)
{
Debug_pushMessage("Got Settings-id and value '%s' from ws-client\n", (char *)data);
char identifier[32];
char value[32];
parseWebsocketString((char *)data, identifier, sizeof(identifier), value, sizeof(value));
if (strcmp(identifier, "bleedingpulses") == 0)
{
LubeConfig.BleedingPulses = atoi(value);
}
else if (strcmp(identifier, "speedsource") == 0)
{
int index = findIndexByString(value, SpeedSourceString, SpeedSourceString_Elements);
speedsourcePreselect = (SpeedSource_t)index;
}
else if (strcmp(identifier, "cansource") == 0)
{
int index = findIndexByString(value, CANSourceString, CANSourceString_Elements);
LubeConfig.CANSource = (CANSource_t)index;
}
else if (strcmp(identifier, "gpsbaud") == 0)
{
int index = findIndexByString(value, GPSBaudRateString, GPSBaudRateString_Elements);
LubeConfig.GPSBaudRate = (GPSBaudRate_t)index;
}
else
{
Debug_pushMessage("Got unknown Settings-id and value '%s' from ws-client\n", identifier);
}
}
/**
@ -689,7 +639,7 @@ void Websocket_RefreshClientData_Static(uint32_t client_id, bool send_mapping)
"tirewidth;"
"tireratio;"
"tiredia;"
"sourceselect;"
"speedsource;"
"gpsbaud;"
"cansource;"
"ledmodeflash;"
@ -742,4 +692,86 @@ void Websocket_RefreshClientData_Static(uint32_t client_id, bool send_mapping)
{
webSocket.textAll(temp);
}
}
/**
* @brief Parse a WebSocket string into identifier and value components.
*
* This function takes a WebSocket string, separates it into identifier and value
* components using the ":" delimiter, and stores them in the specified buffers.
* If no ":" is found, the entire string is considered as the value, and the
* identifier buffer is set to an empty string.
*
* @param data The WebSocket string to parse.
* @param identifierBuffer The buffer to store the identifier component.
* @param identifierBufferSize The size of the identifier buffer.
* @param valueBuffer The buffer to store the value component.
* @param valueBufferSize The size of the value buffer.
*/
void parseWebsocketString(char *data, char *identifierBuffer, size_t identifierBufferSize,
char *valueBuffer, size_t valueBufferSize)
{
// Zerlegen des Strings anhand des Trennzeichens ":"
char *token = strtok(data, ":");
// Falls der erste Teil des Strings vorhanden ist
if (token != NULL)
{
// Kopieren des ersten Teils in den Buffer für Identifier
strncpy(identifierBuffer, token, identifierBufferSize - 1);
identifierBuffer[identifierBufferSize - 1] = '\0'; // Null-Terminierung sicherstellen
// Weitere Aufrufe von strtok, um den nächsten Teil zu erhalten
token = strtok(NULL, ":");
// Falls der zweite Teil des Strings vorhanden ist
if (token != NULL)
{
// Kopieren des zweiten Teils in den Buffer für Value
strncpy(valueBuffer, token, valueBufferSize - 1);
valueBuffer[valueBufferSize - 1] = '\0'; // Null-Terminierung sicherstellen
}
else
{
// Kein zweiter Teil vorhanden, setzen Sie den Buffer für Value auf leer
valueBuffer[0] = '\0';
}
}
else
{
// Der erste Teil des Strings fehlt, setzen Sie den Buffer für Identifier auf leer
identifierBuffer[0] = '\0';
// Der gesamte String wird als Value betrachtet
strncpy(valueBuffer, data, valueBufferSize - 1);
valueBuffer[valueBufferSize - 1] = '\0'; // Null-Terminierung sicherstellen
}
}
/**
* @brief Find the index of a string in an array.
*
* This function searches for the given string in the provided array and returns
* the index of the first occurrence. If the string is not found, it returns -1.
*
* @param searchString The string to search for in the array.
* @param array The array of strings to search within.
* @param arraySize The size of the array.
*
* @return The index of the first occurrence of the string in the array,
* or -1 if the string is not found.
*/
int findIndexByString(const char *searchString, const char *const *array, int arraySize)
{
// Durchlaufe das Array und vergleiche jeden String
for (int i = 0; i < arraySize; ++i)
{
if (strcmp(array[i], searchString) == 0)
{
// String gefunden, gib den Index zurück
return i;
}
}
// String nicht gefunden, gib -1 zurück
return -1;
}