forked from ExpressLRS/ExpressLRS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.cpp
More file actions
112 lines (97 loc) · 1.67 KB
/
config.cpp
File metadata and controls
112 lines (97 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "config.h"
#include "common.h"
#include "POWERMGNT.h"
void
Config::Load()
{
// Populate the struct from eeprom
m_eeprom->Get(0, m_config);
// Check if version number matches
if (m_config.version != CONFIG_VERSION)
{
// If not, revert to defaults for this version
Serial.println("EEPROM version mismatch! Resetting to defaults...");
SetDefaults();
}
m_modified = false;
}
void
Config::Commit()
{
if (!m_modified)
{
// No changes
return;
}
// Write the struct to eeprom
m_eeprom->Put(0, m_config);
m_eeprom->Commit();
m_modified = false;
}
// Getters
uint32_t
Config::GetRate()
{
return m_config.rate;
}
uint32_t
Config::GetTlm()
{
return m_config.tlm;
}
uint32_t
Config::GetPower()
{
return m_config.power;
}
bool
Config::IsModified()
{
return m_modified;
}
// Setters
void
Config::SetRate(uint32_t rate)
{
if (m_config.rate != rate)
{
m_config.rate = rate;
m_modified = true;
}
}
void
Config::SetTlm(uint32_t tlm)
{
if (m_config.tlm != tlm)
{
m_config.tlm = tlm;
m_modified = true;
}
}
void
Config::SetPower(uint32_t power)
{
if (m_config.power != power)
{
m_config.power = power;
m_modified = true;
}
}
void
Config::SetDefaults()
{
expresslrs_mod_settings_s *const modParams = get_elrs_airRateConfig(RATE_DEFAULT);
m_config.version = CONFIG_VERSION;
SetRate(modParams->index);
SetTlm(modParams->TLMinterval);
SetPower(DefaultPowerEnum);
Commit();
}
void
Config::SetStorageProvider(ELRS_EEPROM *eeprom)
{
if (eeprom)
{
m_eeprom = eeprom;
}
}