2022-01-09 20:51:16 +01:00
|
|
|
#ifndef _CONFIG_H_
|
|
|
|
#define _CONFIG_H_
|
|
|
|
|
|
|
|
#include <Arduino.h>
|
2022-01-31 09:26:10 +01:00
|
|
|
#include <Wire.h>
|
|
|
|
#include <I2C_eeprom.h>
|
2022-02-04 21:24:15 +01:00
|
|
|
#include "globals.h"
|
2022-03-09 23:05:17 +01:00
|
|
|
#include "dtc.h"
|
2022-08-24 23:10:11 +02:00
|
|
|
#include "common.h"
|
2022-01-31 09:26:10 +01:00
|
|
|
|
2023-02-28 10:12:18 +01:00
|
|
|
#if PCB_REV == 1 || PCB_REV == 2 || PCB_REV == 3
|
|
|
|
#define EEPROM_SIZE_BYTES I2C_DEVICESIZE_24LC64
|
|
|
|
#elif PCB_REV == 4
|
2022-01-31 09:26:10 +01:00
|
|
|
#define EEPROM_SIZE_BYTES I2C_DEVICESIZE_24LC256
|
2023-02-28 10:12:18 +01:00
|
|
|
#endif
|
2022-01-09 20:51:16 +01:00
|
|
|
|
2022-01-19 22:23:36 +01:00
|
|
|
typedef enum SpeedSource_e
|
|
|
|
{
|
2023-03-02 17:40:25 +01:00
|
|
|
#ifdef FEATURE_ENABLE_TIMER
|
2022-01-19 22:23:36 +01:00
|
|
|
SOURCE_TIME,
|
2023-03-02 17:40:25 +01:00
|
|
|
#endif
|
2022-01-19 22:23:36 +01:00
|
|
|
SOURCE_IMPULSE,
|
|
|
|
SOURCE_GPS,
|
|
|
|
SOURCE_CAN
|
|
|
|
} SpeedSource_t;
|
|
|
|
|
2022-02-04 21:28:49 +01:00
|
|
|
const char SpeedSourceString[][8] = {
|
2023-03-02 17:40:25 +01:00
|
|
|
#ifdef FEATURE_ENABLE_TIMER
|
2022-02-04 21:28:49 +01:00
|
|
|
"Timer",
|
2023-03-02 17:40:25 +01:00
|
|
|
#endif
|
2022-02-04 21:28:49 +01:00
|
|
|
"Impuls",
|
|
|
|
"GPS",
|
|
|
|
"CAN-Bus"
|
|
|
|
};
|
|
|
|
|
2022-01-19 22:23:36 +01:00
|
|
|
typedef enum GPSBaudRate_e
|
|
|
|
{
|
|
|
|
BAUD_9600,
|
|
|
|
BAUD_115200
|
|
|
|
} GPSBaudRate_t;
|
|
|
|
|
|
|
|
const char GPSBaudRateString[][7] = {
|
|
|
|
"9600",
|
|
|
|
"115200"};
|
|
|
|
|
|
|
|
const size_t GPSBaudRateString_Elements = sizeof(GPSBaudRateString) / sizeof(GPSBaudRateString[0]);
|
|
|
|
|
|
|
|
typedef enum CANSource_e
|
|
|
|
{
|
2023-12-03 23:49:41 +01:00
|
|
|
KTM_890_ADV_R_2021,
|
|
|
|
KTM_1290_SD_R_2023
|
2022-01-19 22:23:36 +01:00
|
|
|
} CANSource_t;
|
|
|
|
|
2023-12-03 23:49:41 +01:00
|
|
|
const char CANSourceString[][30] = {
|
|
|
|
"KTM 890 Adventure R (2021)",
|
|
|
|
"KTM 1290 Superduke R (2023)"};
|
2022-01-19 22:23:36 +01:00
|
|
|
|
2023-09-25 07:19:17 +02:00
|
|
|
const size_t CANSourceString_Elements = sizeof(CANSourceString) / sizeof(CANSourceString[0]);
|
2022-01-19 22:23:36 +01:00
|
|
|
|
|
|
|
const size_t SpeedSourceString_Elements = sizeof(SpeedSourceString) / sizeof(SpeedSourceString[0]);
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
uint16_t writeCycleCounter = 0;
|
2023-02-19 14:29:38 +01:00
|
|
|
uint32_t tankRemain_microL = 0;
|
2022-05-05 21:07:24 +02:00
|
|
|
uint32_t TravelDistance_highRes_mm = 0;
|
|
|
|
uint32_t odometer_mm = 0;
|
|
|
|
uint32_t odometer = 0;
|
2022-01-19 22:23:36 +01:00
|
|
|
uint32_t checksum = 0;
|
|
|
|
} persistenceData_t;
|
|
|
|
|
2022-01-09 20:51:16 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
2022-05-02 20:29:17 +02:00
|
|
|
uint8_t EEPROM_Version = 0;
|
2022-02-04 21:28:49 +01:00
|
|
|
uint32_t DistancePerLube_Default = 8000;
|
|
|
|
uint32_t DistancePerLube_Rain = 4000;
|
2022-01-09 20:51:16 +01:00
|
|
|
uint32_t tankCapacity_ml = 320;
|
2023-02-19 14:29:38 +01:00
|
|
|
uint32_t amountPerDose_microL = DEFAULT_PUMP_DOSE;
|
2022-01-09 20:51:16 +01:00
|
|
|
uint8_t TankRemindAtPercentage = 30;
|
|
|
|
uint8_t PulsePerRevolution = 1;
|
|
|
|
uint32_t TireWidth_mm = 150;
|
|
|
|
uint32_t TireWidthHeight_Ratio = 70;
|
|
|
|
uint32_t RimDiameter_Inch = 18;
|
|
|
|
uint32_t DistancePerRevolution_mm = 2000;
|
2022-08-21 15:47:22 +02:00
|
|
|
uint16_t BleedingPulses = 25;
|
2022-01-19 22:23:36 +01:00
|
|
|
SpeedSource_t SpeedSource = SOURCE_IMPULSE;
|
2022-02-27 22:23:58 +01:00
|
|
|
GPSBaudRate_t GPSBaudRate = BAUD_115200;
|
2022-01-19 22:23:36 +01:00
|
|
|
CANSource_t CANSource = KTM_890_ADV_R_2021;
|
2023-03-02 22:30:42 +01:00
|
|
|
bool LED_Mode_Flash = false;
|
|
|
|
uint8_t LED_Max_Brightness = 255;
|
|
|
|
uint8_t LED_Min_Brightness = 5;
|
2022-01-09 20:51:16 +01:00
|
|
|
uint32_t checksum = 0;
|
|
|
|
} LubeConfig_t;
|
|
|
|
|
2023-02-19 14:42:40 +01:00
|
|
|
const LubeConfig_t LubeConfig_defaults = {
|
2022-08-24 23:08:29 +02:00
|
|
|
0, 8000, 4000, 320, DEFAULT_PUMP_DOSE, 30, 1, 150, 70, 18, 2000, 25, SOURCE_IMPULSE,
|
2022-08-24 20:59:00 +02:00
|
|
|
BAUD_115200,
|
|
|
|
KTM_890_ADV_R_2021,
|
2023-03-02 22:30:42 +01:00
|
|
|
false,
|
|
|
|
255,
|
|
|
|
5,
|
2022-08-24 20:59:00 +02:00
|
|
|
0};
|
|
|
|
|
2022-01-31 09:26:10 +01:00
|
|
|
void InitEEPROM();
|
2022-02-04 21:24:15 +01:00
|
|
|
void EEPROM_Process();
|
2022-01-09 20:51:16 +01:00
|
|
|
void StoreConfig_EEPROM();
|
|
|
|
void GetConfig_EEPROM();
|
2022-01-19 22:23:36 +01:00
|
|
|
void StorePersistence_EEPROM();
|
|
|
|
void GetPersistence_EEPROM();
|
|
|
|
void FormatConfig_EEPROM();
|
|
|
|
void FormatPersistence_EEPROM();
|
2022-01-09 20:51:16 +01:00
|
|
|
uint32_t Checksum_EEPROM(uint8_t const *data, size_t len);
|
2022-01-31 09:26:10 +01:00
|
|
|
void dumpEEPROM(uint16_t memoryAddress, uint16_t length);
|
|
|
|
void MovePersistencePage_EEPROM(boolean reset);
|
2022-09-01 22:46:00 +02:00
|
|
|
uint32_t ConfigSanityCheck(bool autocorrect = false);
|
2022-01-09 20:51:16 +01:00
|
|
|
|
|
|
|
extern LubeConfig_t LubeConfig;
|
2022-01-19 22:23:36 +01:00
|
|
|
extern persistenceData_t PersistenceData;
|
|
|
|
extern uint16_t eePersistenceMarker;
|
2022-01-09 20:51:16 +01:00
|
|
|
#endif // _CONFIG_H_
|