diff --git a/vibrator/common/utils.h b/vibrator/common/utils.h index 86dd37e..b5005a6 100644 --- a/vibrator/common/utils.h +++ b/vibrator/common/utils.h @@ -103,6 +103,19 @@ inline Enable_If_Unsigned getProperty(const std::string &key, const T def) return ::android::base::GetUintProperty(key, def); } +template +inline std::array getProperty(const std::string &key, const std::array &def) { + std::string value = ::android::base::GetProperty(key, ""); + if (!value.empty()) { + std::array result{0}; + std::stringstream stream{value}; + utils::unpack(stream, &result); + if (stream && stream.eof()) + return result; + } + return def; +} + template <> inline bool getProperty(const std::string &key, const bool def) { return ::android::base::GetBoolProperty(key, def); diff --git a/vibrator/cs40l26/Hardware.h b/vibrator/cs40l26/Hardware.h index e2c2d36..e4dd344 100644 --- a/vibrator/cs40l26/Hardware.h +++ b/vibrator/cs40l26/Hardware.h @@ -318,9 +318,9 @@ class HwCal : public Vibrator::HwCal, private HwCalBase { static constexpr uint32_t VERSION_DEFAULT = 2; static constexpr int32_t DEFAULT_FREQUENCY_SHIFT = 0; - static constexpr std::array V_TICK_DEFAULT = {1, 100}; - static constexpr std::array V_CLICK_DEFAULT = {1, 100}; - static constexpr std::array V_LONG_DEFAULT = {1, 100}; + static constexpr std::array V_TICK_DEFAULT = {5, 95}; + static constexpr std::array V_CLICK_DEFAULT = {5, 95}; + static constexpr std::array V_LONG_DEFAULT = {5, 95}; public: HwCal() {} @@ -370,22 +370,19 @@ class HwCal : public Vibrator::HwCal, private HwCalBase { if (getPersist(TICK_VOLTAGES_CONFIG, value)) { return true; } - *value = V_TICK_DEFAULT; - return true; + return getProperty(TICK_VOLTAGES_CONFIG, value, V_TICK_DEFAULT); } bool getClickVolLevels(std::array *value) override { if (getPersist(CLICK_VOLTAGES_CONFIG, value)) { return true; } - *value = V_CLICK_DEFAULT; - return true; + return getProperty(CLICK_VOLTAGES_CONFIG, value, V_CLICK_DEFAULT); } bool getLongVolLevels(std::array *value) override { if (getPersist(LONG_VOLTAGES_CONFIG, value)) { return true; } - *value = V_LONG_DEFAULT; - return true; + return getProperty(LONG_VOLTAGES_CONFIG, value, V_LONG_DEFAULT); } bool isChirpEnabled() override { return utils::getProperty("persist.vendor.vibrator.hal.chirp.enabled", false); diff --git a/vibrator/cs40l26/tests/test-hwcal.cpp b/vibrator/cs40l26/tests/test-hwcal.cpp index e482b6c..5223c85 100644 --- a/vibrator/cs40l26/tests/test-hwcal.cpp +++ b/vibrator/cs40l26/tests/test-hwcal.cpp @@ -30,9 +30,9 @@ using ::testing::Test; class HwCalTest : public Test { protected: - static constexpr std::array V_TICK_DEFAULT = {1, 100}; - static constexpr std::array V_CLICK_DEFAULT = {1, 100}; - static constexpr std::array V_LONG_DEFAULT = {1, 100}; + static constexpr std::array V_TICK_DEFAULT = {5, 95}; + static constexpr std::array V_CLICK_DEFAULT = {5, 95}; + static constexpr std::array V_LONG_DEFAULT = {5, 95}; public: void SetUp() override { setenv("CALIBRATION_FILEPATH", mCalFile.path, true); }