Skip to content

Commit

Permalink
sns: shorter cfg keys for hlw8012
Browse files Browse the repository at this point in the history
Also allow flashstringhelper -> settingskey conversion
  • Loading branch information
mcspr committed Aug 2, 2021
1 parent 5c0d188 commit fa5e4f7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
2 changes: 1 addition & 1 deletion code/espurna/config/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
#endif

#ifndef CFG_VERSION
#define CFG_VERSION 8
#define CFG_VERSION 9
#endif
14 changes: 11 additions & 3 deletions code/espurna/sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2017,9 +2017,9 @@ void _sensorLoad() {
#if HLW8012_SUPPORT
{
HLW8012Sensor * sensor = new HLW8012Sensor();
sensor->setSEL(getSetting("snsHlw8012SelGPIO", HLW8012_SEL_PIN));
sensor->setCF(getSetting("snsHlw8012CfGPIO", HLW8012_CF_PIN));
sensor->setCF1(getSetting("snsHlw8012Cf1GPIO", HLW8012_CF1_PIN));
sensor->setSEL(getSetting(F("hlw8012SEL"), HLW8012_SEL_PIN));
sensor->setCF(getSetting(F("hlw8012CF"), HLW8012_CF_PIN));
sensor->setCF1(getSetting(F("hlw8012CF1"), HLW8012_CF1_PIN));
sensor->setSELCurrent(HLW8012_SEL_CURRENT);
_sensors.push_back(sensor);
}
Expand Down Expand Up @@ -2757,6 +2757,14 @@ void _sensorBackwards(int version) {
moveSetting(F("pwrRatioP"), _magnitudeSettingsRatioKey(MAGNITUDE_POWER_ACTIVE, 0).value());
moveSetting(F("pwrRatioE"), _magnitudeSettingsRatioKey(MAGNITUDE_ENERGY, 0).value());
}

#if HLW8012_SUPPORT
if (version < 9) {
moveSetting(F("snsHlw8012SelGPIO"), F("hlw8012SEL"));
moveSetting(F("snsHlw8012CfGPIO"), F("hlw8012CF"));
moveSetting(F("snsHlw8012Cf1GPIO"), F("hlw8012CF1"));
}
#endif
}

void sensorSetup() {
Expand Down
27 changes: 13 additions & 14 deletions code/espurna/settings_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,18 @@ Copyright (C) 2020-2021 by Maxim Prokhorov <prokhorov dot max at outlook dot com

class SettingsKey {
public:
SettingsKey() = default;
SettingsKey(const SettingsKey&) = default;
SettingsKey(SettingsKey&&) = default;

SettingsKey(const char* key) :
_key(key)
{}

SettingsKey(const __FlashStringHelper* key) :
_key(key)
{}

SettingsKey(const String& key) :
_key(key)
{}
Expand All @@ -29,9 +37,9 @@ class SettingsKey {
_key(std::move(key))
{}

SettingsKey(const String& prefix, size_t index) {
_key.reserve(prefix.length() + 4);
_key += prefix;
SettingsKey(const String& prefix, size_t index) :
_key(prefix)
{
_key += index;
}

Expand All @@ -41,12 +49,6 @@ class SettingsKey {
_key += index;
}

SettingsKey(const char* prefix, size_t index) :
_key(prefix)
{
_key += index;
}

const char* c_str() const {
return _key.c_str();
}
Expand All @@ -55,11 +57,8 @@ class SettingsKey {
return _key.length();
}

bool operator==(const char* other) const {
return _key == other;
}

bool operator==(const String& other) const {
template <typename T>
bool operator==(T&& other) const {
return _key == other;
}

Expand Down

0 comments on commit fa5e4f7

Please sign in to comment.