changed PreProcessor-Stuff for Feature-Handling

This commit is contained in:
Marcel Peterkau 2022-05-04 23:06:15 +02:00
parent 2b5039b8ab
commit 1c0ab060ff
9 changed files with 76 additions and 52 deletions

View File

@ -26,14 +26,15 @@ upload_speed = 921600
build_flags =
!python git_rev_macro.py
;-DWIFI_CLIENT
-DREMOTE_DEBUG
-DWIFI_SSID=${wifi_cred.wifi_ssid}
-DWIFI_PASSWORD=${wifi_cred.wifi_password}
-DADMIN_PASSWORD=${wifi_cred.admin_password}
-DWIFI_AP_PASSWORD=${wifi_cred.wifi_ap_password}
-DWIFI_AP_IP_GW=10,0,0,1
-DPCB_REVISION=13
;-DFEATURE_ENABLE_WIFI_CLIENT
-DFEATURE_ENABLE_REMOTE_DEBUG
-DFEATURE_ENABLE_CAN
-DFEATURE_ENABLE_GPS
board_build.filesystem = littlefs

View File

@ -1,3 +1,4 @@
#ifdef FEATURE_ENABLE_CAN
#include "can.h"
MCP_CAN CAN0(GPIO_CS_CAN);
@ -42,3 +43,4 @@ uint32_t Process_CAN_WheelSpeed()
return 0;
}
#endif

View File

@ -31,16 +31,4 @@
#error "You must define an WIFI_AP_PASSWORD for Standalone AP-Mode"
#endif
#ifndef PCB_REVISION
#error "You must define PCB_REVISION"
#else
#if PCB_REVISION == 13
#elif PCB_REVISION == 12
#elif PCB_REVISION == 10
#else
#error "Unknown PCB_REVISION defined"
#endif
#endif
#endif

View File

@ -2,12 +2,8 @@
#define _CONFIG_H_
#include <Arduino.h>
#if PCB_REVISION >= 12
#include <Wire.h>
#include <I2C_eeprom.h>
#else
#include <EEPROM.h>
#endif
#include "globals.h"
#include "dtc.h"
@ -17,8 +13,10 @@ typedef enum SpeedSource_e
{
SOURCE_TIME,
SOURCE_IMPULSE,
#ifdef FEATURE_ENABLE_GPS
SOURCE_GPS,
#if PCB_REVISION == 13
#endif
#if FEATURE_ENABLE_CAN
SOURCE_CAN
#endif
} SpeedSource_t;
@ -26,12 +24,15 @@ typedef enum SpeedSource_e
const char SpeedSourceString[][8] = {
"Timer",
"Impuls",
#ifdef FEATURE_ENABLE_GPS
"GPS",
#if PCB_REVISION >= 13
#endif
#if FEATURE_ENABLE_CAN
"CAN-Bus"
#endif
};
#ifdef FEATURE_ENABLE_GPS
typedef enum GPSBaudRate_e
{
BAUD_9600,
@ -43,9 +44,9 @@ const char GPSBaudRateString[][7] = {
"115200"};
const size_t GPSBaudRateString_Elements = sizeof(GPSBaudRateString) / sizeof(GPSBaudRateString[0]);
#endif
#if PCB_REVISION >= 13
#ifdef FEATURE_ENABLE_CAN
typedef enum CANSource_e
{
KTM_890_ADV_R_2021
@ -82,8 +83,10 @@ typedef struct
uint32_t DistancePerRevolution_mm = 2000;
uint8_t BleedingPulses = 25;
SpeedSource_t SpeedSource = SOURCE_IMPULSE;
#ifdef FEATURE_ENABLE_GPS
GPSBaudRate_t GPSBaudRate = BAUD_115200;
#if PCB_REVISION == 13
#endif
#ifdef FEATURE_ENABLE_CAN
CANSource_t CANSource = KTM_890_ADV_R_2021;
#endif
uint32_t checksum = 0;

View File

@ -10,13 +10,13 @@ void MaintainDTC(DTCNums_t DTC_no, boolean active)
{
if (active && DTCStorage[i].active != DTC_ACTIVE)
{
Serial.printf("DTC gone active: %d", DTC_no);
Serial.printf("DTC gone active: %d\n", DTC_no);
DTCStorage[i].timestamp = millis();
DTCStorage[i].active = DTC_ACTIVE;
}
if (!active && DTCStorage[i].active == DTC_ACTIVE)
{
Serial.printf("DTC gone previous: %d", DTC_no);
Serial.printf("DTC gone previous: %d\n", DTC_no);
DTCStorage[i].active = DTC_PREVIOUS;
}
return;
@ -31,7 +31,7 @@ void MaintainDTC(DTCNums_t DTC_no, boolean active)
{
if (DTCStorage[i].Number == DTC_LAST_DTC)
{
Serial.printf("new DTC registered: %d", DTC_no);
Serial.printf("new DTC registered: %d\n", DTC_no);
DTCStorage[i].Number = DTC_no;
DTCStorage[i].timestamp = millis();
DTCStorage[i].active = DTC_ACTIVE;

View File

@ -7,14 +7,18 @@
typedef enum DTCNums_e
{
DTC_NO_GPS_SERIAL = 1,
DTC_TANK_EMPTY,
DTC_TANK_EMPTY = 1,
DTC_NO_EEPROM_FOUND,
DTC_EEPROM_CFG_BAD,
DTC_EEPROM_PDS_BAD,
DTC_EEPROM_VERSION_BAD,
#ifdef FEATURE_ENABLE_GPS
DTC_NO_GPS_SERIAL,
#endif
#ifdef FEATURE_ENABLE_CAN
DTC_CAN_TRANSCEIVER_FAILED,
DTC_NO_CAN_SIGNAL,
#endif
DTC_LAST_DTC
} DTCNums_t;

View File

@ -1,3 +1,4 @@
#ifdef FEATURE_ENABLE_GPS
#include "gps.h"
TinyGPSPlus gps;
@ -54,3 +55,5 @@ uint32_t Process_GPS_WheelSpeed()
return 0;
}
#endif

View File

@ -14,11 +14,15 @@
#include "webui.h"
#include "config.h"
#include "globals.h"
#ifdef FEATURE_ENABLE_CAN
#include "can.h"
#endif
#ifdef FEATURE_ENABLE_GPS
#include "gps.h"
#endif
#include "dtc.h"
#ifdef REMOTE_DEBUG
#ifdef FEATURE_ENABLE_REMOTE_DEBUG
#include <RemoteDebug.h>
#include "rmtdbghelp.h"
#else
@ -26,7 +30,7 @@
#define debugE Serial.println
#endif
#ifdef WIFI_CLIENT
#ifdef FEATURE_ENABLE_WIFI_CLIENT
#include <ESP8266WiFiMulti.h>
const char *ssid = QUOTE(WIFI_SSID);
@ -56,7 +60,7 @@ void SystemShutdown();
uint32_t Process_Impulse_WheelSpeed();
void EEPROMCyclicPDS_callback();
#ifdef REMOTE_DEBUG
#ifdef FEATURE_ENABLE_REMOTE_DEBUG
RemoteDebug Debug;
String IpAddress2String(const IPAddress &ipAddress);
void processCmdRemoteDebug();
@ -70,7 +74,7 @@ void RemoteDebug_dumpPersistance();
void RemoteDebug_ShowDTCs();
#endif
#ifdef WIFI_CLIENT
#ifdef FEATURE_ENABLE_WIFI_CLIENT
void wifiMaintainConnectionTicker_callback();
Ticker WiFiMaintainConnectionTicker(wifiMaintainConnectionTicker_callback, 1000, 0, MILLIS);
#endif
@ -82,9 +86,9 @@ void setup()
snprintf(DeviceName, 32, HOST_NAME, ESP.getChipId());
WiFi.persistent(false);
ClearAllDTC(); // Init DTC-Storage
ClearAllDTC(); // Init DTC-Storage
#ifdef WIFI_CLIENT
#ifdef FEATURE_ENABLE_WIFI_CLIENT
WiFi.mode(WIFI_STA);
WiFi.setHostname(DeviceName);
wifiMulti.addAP(QUOTE(WIFI_SSID), QUOTE(WIFI_PASSWORD));
@ -99,9 +103,7 @@ void setup()
Serial.println("Souko's ChainLube Mk1");
Serial.println(DeviceName);
#if PCB_REVISION >= 12
InitEEPROM();
#endif
GetConfig_EEPROM();
GetPersistence_EEPROM();
@ -116,14 +118,15 @@ void setup()
pinMode(GPIO_TRIGGER, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(GPIO_TRIGGER), trigger_ISR, FALLING);
break;
#ifdef FEATURE_ENABLE_GPS
case SOURCE_GPS:
Init_GPS();
break;
#endif
case SOURCE_TIME:
break;
#if PCB_REVISION >= 13
#ifdef FEATURE_ENABLE_CAN
case SOURCE_CAN:
Init_CAN();
break;
@ -136,7 +139,7 @@ void setup()
pinMode(GPIO_BUTTON, INPUT_PULLUP);
pinMode(GPIO_PUMP, OUTPUT);
#ifdef REMOTE_DEBUG
#ifdef FEATURE_ENABLE_REMOTE_DEBUG
if (MDNS.begin(DeviceName))
MDNS.addService("telnet", "tcp", 23);
@ -202,14 +205,18 @@ void loop()
case SOURCE_IMPULSE:
wheelDistance = Process_Impulse_WheelSpeed();
break;
#ifdef FEATURE_ENABLE_CAN
case SOURCE_CAN:
wheelDistance = Process_CAN_WheelSpeed();
break;
#endif
case SOURCE_TIME:
break;
#ifdef FEATURE_ENABLE_GPS
case SOURCE_GPS:
wheelDistance = Process_GPS_WheelSpeed();
break;
#endif
}
RunLubeApp(wheelDistance);
@ -220,10 +227,10 @@ void loop()
EEPROM_Process();
ArduinoOTA.handle();
#ifdef REMOTE_DEBUG
#ifdef FEATURE_ENABLE_REMOTE_DEBUG
Debug.handle();
#endif
#ifdef WIFI_CLIENT
#ifdef FEATURE_ENABLE_WIFI_CLIENT
WiFiMaintainConnectionTicker.update();
#endif
if (globals.systemStatus == sysStat_Shutdown)
@ -239,7 +246,7 @@ String IpAddress2String(const IPAddress &ipAddress)
String(ipAddress[3]);
}
#ifdef REMOTE_DEBUG
#ifdef FEATURE_ENABLE_REMOTE_DEBUG
void processCmdRemoteDebug()
{
String lastCmd = Debug.getLastCommand();
@ -266,7 +273,7 @@ void processCmdRemoteDebug()
RemoteDebug_dumpPersistance();
else if (lastCmd == "saveEE")
StoreConfig_EEPROM();
else if (lastCmd == "showdtc")
else if (lastCmd == "showdtc")
RemoteDebug_ShowDTCs();
}
@ -318,8 +325,10 @@ void RemoteDebug_dumpConfig()
debugA("DistancePerRevolution_mm: %d", LubeConfig.DistancePerRevolution_mm);
debugA("BleedingPulses: %d", LubeConfig.BleedingPulses);
debugA("SpeedSource: %d", LubeConfig.SpeedSource);
#ifdef FEATURE_ENABLE_GPS
debugA("GPSBaudRate: %d", LubeConfig.GPSBaudRate);
#if PCB_REVISION == 13
#endif
#ifdef FEATURE_ENABLE_CAN
debugA("CANSource: %d", LubeConfig.CANSource);
#endif
debugA("checksum: 0x%08X", LubeConfig.checksum);
@ -369,7 +378,7 @@ void RemoteDebug_CheckEEPOM()
}
#endif
#ifdef WIFI_CLIENT
#ifdef FEATURE_ENABLE_WIFI_CLIENT
void wifiMaintainConnectionTicker_callback()
{
static uint32_t WiFiFailCount = 0;
@ -692,7 +701,7 @@ void toggleWiFiAP(boolean shutdown)
{
WiFi.mode(WIFI_OFF);
debugV("WiFi turned off");
#ifdef WIFI_CLIENT
#ifdef FEATURE_ENABLE_WIFI_CLIENT
WiFiMaintainConnectionTicker.stop();
#endif
}
@ -701,7 +710,7 @@ void toggleWiFiAP(boolean shutdown)
WiFi.mode(WIFI_AP);
WiFi.softAPConfig(IPAddress(WIFI_AP_IP_GW), IPAddress(WIFI_AP_IP_GW), IPAddress(255, 255, 255, 0));
WiFi.softAP(DeviceName, QUOTE(WIFI_AP_PASSWORD));
#ifdef WIFI_CLIENT
#ifdef FEATURE_ENABLE_WIFI_CLIENT
WiFiMaintainConnectionTicker.stop();
debugV("WiFi AP started, stopped Maintain-Timer");
#else

View File

@ -55,9 +55,11 @@ String processor(const String &var)
return String(LubeConfig.BleedingPulses);
if (var == "SPEED_SOURCE")
return String(SpeedSourceString[LubeConfig.SpeedSource]);
#ifdef FEATURE_ENABLE_GPS
if (var == "GPS_BAUD")
return String(GPSBaudRateString[LubeConfig.GPSBaudRate]);
#if PCB_REVISION == 13
#endif
#ifdef FEATURE_ENABLE_CAN
if (var == "CAN_SOURCE")
return String(CANSourceString[LubeConfig.CANSource]);
#endif
@ -81,10 +83,14 @@ String processor(const String &var)
}
if (var == "SHOW_IMPULSE_SETTINGS")
return LubeConfig.SpeedSource == SOURCE_IMPULSE ? "" : "hidden";
#ifdef FEATURE_ENABLE_CAN
if (var == "SHOW_CAN_SETTINGS")
return LubeConfig.SpeedSource == SOURCE_CAN ? "" : "hidden";
#endif
#ifdef FEATURE_ENABLE_GPS
if (var == "SHOW_GPS_SETTINGS")
return LubeConfig.SpeedSource == SOURCE_GPS ? "" : "hidden";
#endif
if (var == "SHOW_DTC_TABLE")
return globals.systemStatus == sysStat_Error ? "" : "hidden";
@ -131,6 +137,7 @@ String processor(const String &var)
return temp;
}
#ifdef FEATURE_ENABLE_CAN
if (var == "CANSOURCE_SELECT_OPTIONS")
{
String temp;
@ -141,6 +148,8 @@ String processor(const String &var)
}
return temp;
}
#endif
#ifdef FEATURE_EABLE_GPS
if (var == "GPSBAUD_SELECT_OPTIONS")
{
String temp;
@ -151,6 +160,7 @@ String processor(const String &var)
}
return temp;
}
#endif
if (var == "SYSTEM_STATUS")
return String(globals.systemStatustxt);
@ -201,19 +211,23 @@ void WebserverPOST_Callback(AsyncWebServerRequest *request)
LubeConfig.PulsePerRevolution = p->value().toInt();
if (p->name() == "pulsesave")
globals.requestEEAction = EE_CFG_SAVE;
// end: POST Form Source Pulse Settings
// end: POST Form Source Pulse Settings
#ifdef FEATURE_EABLE_GPS
// 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
// end: POST Form Source GPS Settings
#endif
#ifdef FEATURE_EABLE_CAN
// 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
// end: POST Form Source CAN Settings
#endif
// begin: POST Form Lubrication
if (p->name() == "lubedistancenormal")
LubeConfig.DistancePerLube_Default = p->value().toInt();