diff --git a/main/accessors/settingsaccessors.h b/main/accessors/settingsaccessors.h index 7026c24..a85579c 100644 --- a/main/accessors/settingsaccessors.h +++ b/main/accessors/settingsaccessors.h @@ -213,7 +213,7 @@ struct BatteryApplyCalibrationAccessor : public NewSettingsAccessor { Conf // Lockscreen struct LockscreenAllowPresetSwitchAccessor : public NewSettingsAccessor { ConfigWrapper &getConfig() const override { return configs.lockscreen.allowPresetSwitch; } }; template -struct LockscreenPinDigitAccessor : public NewSettingsAccessor { ConfigWrapper &getConfig() const override { return configs.lockscreen.pin[index].digit; } }; +struct LockscreenPinDigitAccessor : public NewSettingsAccessor { ConfigWrapper &getConfig() const override { return configs.lockscreen.pin[index]; } }; struct LockscreenKeepLockedAccessor : public NewSettingsAccessor { ConfigWrapper &getConfig() const override { return configs.lockscreen.keepLockedAfterReboot; } }; // Handbremse diff --git a/main/can.cpp b/main/can.cpp index 98adb1f..6831a72 100644 --- a/main/can.cpp +++ b/main/can.cpp @@ -272,21 +272,25 @@ void sendCanCommands() const auto timestamp_before = espchrono::millis_clock::now(); const auto result = twai_transmit(&message, timeout); + const auto timestamp_after = espchrono::millis_clock::now(); - if (result != ESP_OK && result != ESP_ERR_TIMEOUT) - { - ESP_LOGE(TAG, "ERROR: twai_transmit() failed with %s", esp_err_to_name(result)); - } - else if (result == ESP_ERR_TIMEOUT) + if (result == ESP_ERR_TIMEOUT) { ++can_sequential_error_cnt; ++can_total_error_cnt; - ESP_LOGW(TAG, "twai_transmit() took %lld ms, seq err: %d, total err: %d", - espchrono::ago(timestamp_before).count(), + ESP_LOGW(TAG, "twai_transmit() failed after %lldms with %s, seq err: %d, total err: %d", + (timestamp_after - timestamp_before).count(), + esp_err_to_name(result), can_sequential_error_cnt, can_total_error_cnt); } + else if (result != ESP_OK) + { + ESP_LOGE(TAG, "ERROR: twai_transmit() failed after %lldms with %s", + (timestamp_after - timestamp_before).count(), + esp_err_to_name(result)); + } else { can_sequential_error_cnt = 0; diff --git a/main/displays/lockscreen.cpp b/main/displays/lockscreen.cpp index fcfa03e..8fff86e 100644 --- a/main/displays/lockscreen.cpp +++ b/main/displays/lockscreen.cpp @@ -1,5 +1,8 @@ #include "lockscreen.h" +// system includes +#include + // 3rdparty lib includes #include #include @@ -11,17 +14,16 @@ #include "displays/potiscalibratedisplay.h" #include "bobbybuttons.h" -bool isValidPin(std::array enteredPin) +namespace { +bool isValidPin(std::array enteredPin) { - for (int i = 0; i < 4; i++) - { - if (enteredPin[i] != configs.lockscreen.pin[i].digit.value) - { - return false; - } - } - return true; + return std::equal(std::cbegin(enteredPin), std::cend(enteredPin), + std::cbegin(configs.lockscreen.pin), std::cend(configs.lockscreen.pin), + [](const int8_t digit, const auto &configuredDigit){ + return digit == configuredDigit.value; + }); } +} // namespace void Lockscreen::start() { diff --git a/main/newsettings.h b/main/newsettings.h index 2d53889..9cc02f7 100644 --- a/main/newsettings.h +++ b/main/newsettings.h @@ -86,15 +86,6 @@ public: ConfigWrapper url; }; -class ConfiguredLockscreenDigit -{ -public: - ConfiguredLockscreenDigit(const char *digitKey) : - digit{0, DoReset, MinMaxOrZeroValue, digitKey } - {} - ConfigWrapper digit; -}; - class ConfigContainer { using mac_t = wifi_stack::mac_t; @@ -265,11 +256,11 @@ public: ConfigWrapper allowPresetSwitch {true, DoReset, {}, "lockAlwPresetSw" }; ConfigWrapper keepLockedAfterReboot {false, DoReset, {}, "keepLocked" }; ConfigWrapper locked {false, DoReset, {}, "currentlyLocked" }; - std::array pin { - ConfiguredLockscreenDigit {"lockscreenPin0"}, - ConfiguredLockscreenDigit {"lockscreenPin1"}, - ConfiguredLockscreenDigit {"lockscreenPin2"}, - ConfiguredLockscreenDigit {"lockscreenPin3"} + std::array, 4> pin { + ConfigWrapper {1, DoReset, MinMaxValue, "lockscreenPin0" }, + ConfigWrapper {2, DoReset, MinMaxValue, "lockscreenPin1" }, + ConfigWrapper {3, DoReset, MinMaxValue, "lockscreenPin2" }, + ConfigWrapper {4, DoReset, MinMaxValue, "lockscreenPin3" }, }; } lockscreen; @@ -542,10 +533,10 @@ public: x(lockscreen.allowPresetSwitch) \ x(lockscreen.keepLockedAfterReboot) \ x(lockscreen.locked) \ - x(lockscreen.pin[0].digit) \ - x(lockscreen.pin[1].digit) \ - x(lockscreen.pin[2].digit) \ - x(lockscreen.pin[3].digit) \ + x(lockscreen.pin[0]) \ + x(lockscreen.pin[1]) \ + x(lockscreen.pin[2]) \ + x(lockscreen.pin[3]) \ \ x(savedStatistics.totalCentimeters) \ \