updated Project with elementes From ChainLube-Project
This commit is contained in:
@@ -1,38 +1,63 @@
|
||||
/**
|
||||
* @file eeprom.h
|
||||
*
|
||||
* @brief Header file for configuration settings and EEPROM operations in the DE-Timer application.
|
||||
*
|
||||
* This file defines configuration settings for the DE-Timer project, including default values,
|
||||
* EEPROM structures, and functions for EEPROM operations. It also defines enums for different sources
|
||||
* of speed input, GPS baud rates, and CAN bus sources. Additionally, it includes functions for EEPROM handling
|
||||
* such as storing, retrieving, and formatting configuration data.
|
||||
*
|
||||
* @author Marcel Peterkau
|
||||
* @date 09.01.2024
|
||||
*/
|
||||
|
||||
#ifndef _EEPROM_H_
|
||||
#define _EEPROM_H_
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
#include <I2C_eeprom.h>
|
||||
|
||||
#include "globals.h"
|
||||
#include "dtc.h"
|
||||
#include "common.h"
|
||||
#include "debugger.h"
|
||||
|
||||
#define I2C_EE_ADDRESS 0x50
|
||||
#define EEPROM_SIZE_BYTES I2C_DEVICESIZE_24LC64
|
||||
#define EEPROM_ENDURANCE 1000000
|
||||
#define EEPROM_STRUCTURE_REVISION 3 // Increment this version when changing EEPROM structures
|
||||
#define EEPROM_SIZE_BYTES I2C_DEVICESIZE_24LC256
|
||||
|
||||
typedef enum
|
||||
typedef enum Factions_e
|
||||
{
|
||||
NONE,
|
||||
FACTION_1,
|
||||
FACTION_2,
|
||||
FACTION_3
|
||||
} factions_t;
|
||||
} Factions_t;
|
||||
|
||||
typedef enum EERequest_e
|
||||
{
|
||||
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
|
||||
|
||||
} EERequest_t;
|
||||
|
||||
// Structure for persistence data stored in EEPROM
|
||||
typedef struct
|
||||
{
|
||||
uint32_t writeCycleCounter = 0;
|
||||
uint32_t faction_1_timer = 0;
|
||||
uint32_t faction_2_timer = 0;
|
||||
uint32_t faction_3_timer = 0;
|
||||
factions_t activeFaction = NONE;
|
||||
uint32_t checksum = 0;
|
||||
uint32_t writeCycleCounter;
|
||||
uint32_t faction_1_timer;
|
||||
uint32_t faction_2_timer;
|
||||
uint32_t faction_3_timer;
|
||||
Factions_t activeFaction;
|
||||
uint32_t checksum;
|
||||
} persistenceData_t;
|
||||
|
||||
extern persistenceData_t PersistenceData;
|
||||
typedef enum
|
||||
{
|
||||
BATTERY_UNDEFINED,
|
||||
@@ -47,6 +72,7 @@ const char BatteryString[][10]{
|
||||
|
||||
const size_t BatteryString_Elements = sizeof(BatteryString) / sizeof(BatteryString[0]);
|
||||
|
||||
// Structure for configuration settings stored in EEPROM
|
||||
typedef struct
|
||||
{
|
||||
uint8_t EEPROM_Version;
|
||||
@@ -55,24 +81,30 @@ typedef struct
|
||||
char Faction_1_Name[33];
|
||||
char Faction_2_Name[33];
|
||||
char Faction_3_Name[33];
|
||||
char wifi_ap_ssid[33];
|
||||
char wifi_ap_password[64];
|
||||
char wifi_client_ssid[33];
|
||||
char wifi_client_password[64];
|
||||
bool wifi_autoconnect;
|
||||
uint32_t checksum;
|
||||
} configData_t;
|
||||
|
||||
extern configData_t ConfigData;
|
||||
|
||||
// Default configuration settings
|
||||
const configData_t ConfigData_defaults = {
|
||||
2, // EEPROM_Version (incerease this if anything on Layout changes!)
|
||||
BATTERY_LIPO_3S, // batteryType
|
||||
false, // active_faction_on_reboot
|
||||
"FACTION 1", // Faction_1_Name
|
||||
"FACTION 2", // Faction_2_Name
|
||||
"FACTION 3", // Faction_3_Name
|
||||
0 // checksum
|
||||
2, // EEPROM_Version (incerease this if anything on Layout changes!)
|
||||
BATTERY_LIPO_3S, // batteryType
|
||||
false, // active_faction_on_reboot
|
||||
"FACTION 1", // Faction_1_Name
|
||||
"FACTION 2", // Faction_2_Name
|
||||
"FACTION 3", // Faction_3_Name
|
||||
"ChainLube",
|
||||
QUOTE(WIFI_AP_PASSWORD),
|
||||
QUOTE(WIFI_SSID_CLIENT),
|
||||
QUOTE(WIFI_PASSWORD_CLIENT),
|
||||
true,
|
||||
0 // checksum
|
||||
};
|
||||
|
||||
const uint16_t startofConfigData = 16;
|
||||
const uint16_t startofPersistence = 16 + sizeof(ConfigData) + (sizeof(ConfigData) % 16);
|
||||
|
||||
void InitEEPROM();
|
||||
void EEPROM_Process();
|
||||
void StoreConfig_EEPROM();
|
||||
@@ -85,5 +117,9 @@ uint32_t Checksum_EEPROM(uint8_t const *data, size_t len);
|
||||
void dumpEEPROM(uint16_t memoryAddress, uint16_t length);
|
||||
void MovePersistencePage_EEPROM(boolean reset);
|
||||
uint32_t ConfigSanityCheck(bool autocorrect = false);
|
||||
bool validateWiFiString(char *string, size_t size);
|
||||
|
||||
#endif // _EEPROM_H_
|
||||
extern configData_t ConfigData;
|
||||
extern persistenceData_t PersistenceData;
|
||||
extern uint16_t eePersistenceMarker;
|
||||
#endif // _CONFIG_H_
|
||||
|
Reference in New Issue
Block a user