diff --git a/Software/include/common.h b/Software/include/common.h index 864e8d0..f609d2c 100644 --- a/Software/include/common.h +++ b/Software/include/common.h @@ -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,53 @@ // -> 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_9600, + 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 diff --git a/Software/include/config.h b/Software/include/config.h index c77e016..8d7c4ee 100644 --- a/Software/include/config.h +++ b/Software/include/config.h @@ -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 diff --git a/Software/include/globals.h b/Software/include/globals.h index 9bd5681..7ff65fe 100644 --- a/Software/include/globals.h +++ b/Software/include/globals.h @@ -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 */ diff --git a/Software/src/common.cpp b/Software/src/common.cpp new file mode 100644 index 0000000..52b4cf4 --- /dev/null +++ b/Software/src/common.cpp @@ -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]); \ No newline at end of file diff --git a/Software/src/config.cpp b/Software/src/config.cpp index a4f9733..73a641e 100644 --- a/Software/src/config.cpp +++ b/Software/src/config.cpp @@ -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);