Merge "vibrator/cs40l26: update default scales of click, tick and long vib" into main

This commit is contained in:
Treehugger Robot 2024-10-25 10:59:08 +00:00 committed by Android (Google) Code Review
commit ce15d2389d
3 changed files with 22 additions and 12 deletions

View file

@ -103,6 +103,19 @@ inline Enable_If_Unsigned<T, T> getProperty(const std::string &key, const T def)
return ::android::base::GetUintProperty(key, def);
}
template <typename T, size_t N>
inline std::array<T, N> getProperty(const std::string &key, const std::array<T, N> &def) {
std::string value = ::android::base::GetProperty(key, "");
if (!value.empty()) {
std::array<T, N> result{0};
std::stringstream stream{value};
utils::unpack(stream, &result);
if (stream && stream.eof())
return result;
}
return def;
}
template <>
inline bool getProperty<bool>(const std::string &key, const bool def) {
return ::android::base::GetBoolProperty(key, def);

View file

@ -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<uint32_t, 2> V_TICK_DEFAULT = {1, 100};
static constexpr std::array<uint32_t, 2> V_CLICK_DEFAULT = {1, 100};
static constexpr std::array<uint32_t, 2> V_LONG_DEFAULT = {1, 100};
static constexpr std::array<uint32_t, 2> V_TICK_DEFAULT = {5, 95};
static constexpr std::array<uint32_t, 2> V_CLICK_DEFAULT = {5, 95};
static constexpr std::array<uint32_t, 2> 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<uint32_t, 2> *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<uint32_t, 2> *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);

View file

@ -30,9 +30,9 @@ using ::testing::Test;
class HwCalTest : public Test {
protected:
static constexpr std::array<uint32_t, 2> V_TICK_DEFAULT = {1, 100};
static constexpr std::array<uint32_t, 2> V_CLICK_DEFAULT = {1, 100};
static constexpr std::array<uint32_t, 2> V_LONG_DEFAULT = {1, 100};
static constexpr std::array<uint32_t, 2> V_TICK_DEFAULT = {5, 95};
static constexpr std::array<uint32_t, 2> V_CLICK_DEFAULT = {5, 95};
static constexpr std::array<uint32_t, 2> V_LONG_DEFAULT = {5, 95};
public:
void SetUp() override { setenv("CALIBRATION_FILEPATH", mCalFile.path, true); }