diff --git a/lib/Domain/TargetHost.cpp b/lib/Domain/TargetHost.cpp index be60b90..e985059 100644 --- a/lib/Domain/TargetHost.cpp +++ b/lib/Domain/TargetHost.cpp @@ -28,9 +28,11 @@ const uint8_t TargetHost::TARGET_R_PIN = A3; const uint8_t TargetHost::TARGET_T_PIN = A4; uint16_t TargetHost::getStoredThreshold() { - uint16_t result = EEPROM.read(TRESHOLD_LSB_ADDRESS); - result |= EEPROM.read(TRESHOLD_MSB_ADDRESS) << 8; - return result; + if (thresholdCache == 0) { + thresholdCache = EEPROM.read(TRESHOLD_LSB_ADDRESS); + thresholdCache |= EEPROM.read(TRESHOLD_MSB_ADDRESS) << 8; + } + return thresholdCache; } void TargetHost::storeThreshold(uint16_t threshold) { diff --git a/lib/Domain/TargetHost.hpp b/lib/Domain/TargetHost.hpp index 37ceb7e..b3fedf3 100644 --- a/lib/Domain/TargetHost.hpp +++ b/lib/Domain/TargetHost.hpp @@ -30,9 +30,11 @@ class Target { class TargetHost { /** - * Minimum light value to validate a hit + * Minimum light value to validate a hit. + * Shall be stored in EEPROM */ - uint16_t lightTreshold; + uint16_t thresholdCache; + Game &game; static const uint8_t LED_PIN; @@ -53,6 +55,7 @@ class TargetHost { targets[2].pin = TARGET_E_PIN; targets[3].pin = TARGET_R_PIN; targets[4].pin = TARGET_T_PIN; + thresholdCache = 0; } uint16_t getTargetLightValue(const Target &target);