sm8150-common: vibrator: Simplify everything

Change-Id: Iceb0c087eb2983f5e5ce81e27c0bf87677b13422
This commit is contained in:
LuK1337 2019-08-07 16:22:37 +02:00
parent 18e343d27f
commit d34eb44fe3
2 changed files with 8 additions and 58 deletions

View File

@ -35,62 +35,49 @@ static constexpr char DURATION_PATH[] = "/sys/class/leds/vibrator/duration";
static constexpr char GAIN_PATH[] = "/sys/class/leds/vibrator/gain"; static constexpr char GAIN_PATH[] = "/sys/class/leds/vibrator/gain";
static constexpr char IGNORE_STORE_PATH[] = "/sys/class/leds/vibrator/ignore_store"; static constexpr char IGNORE_STORE_PATH[] = "/sys/class/leds/vibrator/ignore_store";
static constexpr char LP_TRIGGER_PATH[] = "/sys/class/leds/vibrator/haptic_audio"; static constexpr char LP_TRIGGER_PATH[] = "/sys/class/leds/vibrator/haptic_audio";
static constexpr char LRA_WAVE_SHAPE_PATH[] = "/sys/class/leds/vibrator/lra_resistance";
static constexpr char MODE_PATH[] = "/sys/class/leds/vibrator/activate_mode";
static constexpr char SCALE_PATH[] = "/sys/class/leds/vibrator/gain"; static constexpr char SCALE_PATH[] = "/sys/class/leds/vibrator/gain";
static constexpr char SEQ_PATH[] = "/sys/class/leds/vibrator/seq"; static constexpr char SEQ_PATH[] = "/sys/class/leds/vibrator/seq";
static constexpr char VMAX_PATH[] = "/sys/class/leds/vibrator/vmax"; static constexpr char VMAX_PATH[] = "/sys/class/leds/vibrator/vmax";
// RTP mode
static constexpr char RTP_MODE[] = "rtp";
// Waveform mode
static constexpr char WAVEFORM_MODE[] = "waveform";
static constexpr uint8_t SQUARE_WAVE = 0;
static constexpr uint8_t SINE_WAVE = 1;
// General constants // General constants
static constexpr uint8_t GAIN = 128; static constexpr uint8_t GAIN = 128;
static constexpr uint8_t LOOP_MODE_OPEN = 1;
static constexpr uint8_t VMAX = 9; static constexpr uint8_t VMAX = 9;
// Effects // Effects
static const AwEffect WAVEFORM_CLICK_EFFECT { static const AwEffect WAVEFORM_CLICK_EFFECT {
.sequences = std::vector<std::string>({ "0x0 0x1", "0x1 0x0" }), .sequences = std::vector<std::string>({ "0x0 0x1", "0x1 0x0" }),
.loops = std::vector<std::string>({ "0x0 0x0" }), .loops = std::vector<std::string>({ "0x0 0x0", "0x1 0x0" }),
.vmax = VMAX, .vmax = VMAX,
.gain = GAIN, .gain = GAIN,
.timeMS = 0 .timeMS = 0
}; };
static const AwEffect WAVEFORM_TICK_EFFECT { static const AwEffect WAVEFORM_TICK_EFFECT {
.sequences = std::vector<std::string>({ "0x0 0x1", "0x1 0x0" }), .sequences = std::vector<std::string>({ "0x0 0x1", "0x1 0x0" }),
.loops = std::vector<std::string>({ "0x1 0x0", "0x0 0x0" }), .loops = std::vector<std::string>({ "0x0 0x0", "0x1 0x0" }),
.vmax = VMAX, .vmax = VMAX,
.gain = GAIN, .gain = GAIN,
.timeMS = 0 .timeMS = 0
}; };
static const AwEffect WAVEFORM_DOUBLE_CLICK_EFFECT { static const AwEffect WAVEFORM_DOUBLE_CLICK_EFFECT {
.sequences = std::vector<std::string>({ "0x0 0x1" }), .sequences = std::vector<std::string>({ "0x0 0x1" }),
.loops = std::vector<std::string>({ "0 0x0", "0x1 0x0", "0x0 0x0" }), .loops = std::vector<std::string>({ "0x0 0x0" }),
.vmax = VMAX, .vmax = VMAX,
.gain = GAIN, .gain = GAIN,
.timeMS = 10 .timeMS = 10
}; };
static const AwEffect WAVEFORM_HEAVY_CLICK_EFFECT { static const AwEffect WAVEFORM_HEAVY_CLICK_EFFECT {
.sequences = std::vector<std::string>({ "0x0 0x1", "0x1 0x0" }), .sequences = std::vector<std::string>({ "0x0 0x1", "0x1 0x0" }),
.loops = std::vector<std::string>({ "0x1 0x1", "0x0 0x0" }), .loops = std::vector<std::string>({ "0x0 0x0", "0x1 0x0" }),
.vmax = VMAX, .vmax = VMAX,
.gain = GAIN, .gain = GAIN,
.timeMS = 10 .timeMS = 10
}; };
static const AwEffect WAVEFORM_POP_EFFECT { static const AwEffect WAVEFORM_POP_EFFECT {
.duration = 0,
.vmax = VMAX, .vmax = VMAX,
.gain = GAIN, .gain = GAIN,
.timeMS = 5 .timeMS = 5
}; };
static const AwEffect WAVEFORM_THUD_EFFECT { static const AwEffect WAVEFORM_THUD_EFFECT {
.duration = 0,
.vmax = VMAX, .vmax = VMAX,
.gain = GAIN, .gain = GAIN,
.timeMS = 10 .timeMS = 10
@ -123,31 +110,10 @@ Vibrator::Vibrator() {
set(LP_TRIGGER_PATH, 1); set(LP_TRIGGER_PATH, 1);
} }
Return<Status> Vibrator::on(uint32_t timeoutMs, bool isWaveform) {
set(LOOP_PATH, LOOP_MODE_OPEN);
set(DURATION_PATH, timeoutMs);
if (isWaveform) {
set(MODE_PATH, WAVEFORM_MODE);
set(LRA_WAVE_SHAPE_PATH, SINE_WAVE);
} else {
set(MODE_PATH, RTP_MODE);
set(LRA_WAVE_SHAPE_PATH, SQUARE_WAVE);
}
if (mShouldSetBrightness) {
set(BRIGHTNESS_PATH, 1);
} else {
set(BRIGHTNESS_PATH, 0);
set(ACTIVATE_PATH, 1);
}
return Status::OK;
}
Return<Status> Vibrator::on(uint32_t timeoutMs) { Return<Status> Vibrator::on(uint32_t timeoutMs) {
mShouldSetBrightness = false; set(DURATION_PATH, timeoutMs);
return on(timeoutMs, false /* isWaveform */); set(BRIGHTNESS_PATH, 1);
return Status::OK;
} }
Return<Status> Vibrator::off() { Return<Status> Vibrator::off() {
@ -196,10 +162,6 @@ Return<void> Vibrator::performEffect(Effect effect, EffectStrength strength, per
set(ACTIVATE_PATH, 0); set(ACTIVATE_PATH, 0);
set(IGNORE_STORE_PATH, 0); set(IGNORE_STORE_PATH, 0);
if (effect.duration.has_value()) {
set(DURATION_PATH, *effect.duration);
}
if (effect.vmax.has_value()) { if (effect.vmax.has_value()) {
set(VMAX_PATH, *effect.vmax); set(VMAX_PATH, *effect.vmax);
} }
@ -229,37 +191,29 @@ Return<void> Vibrator::performEffect(Effect effect, EffectStrength strength, per
switch (effect) { switch (effect) {
case Effect::CLICK: case Effect::CLICK:
setEffect(WAVEFORM_CLICK_EFFECT, timeMS); setEffect(WAVEFORM_CLICK_EFFECT, timeMS);
mShouldSetBrightness = true;
break; break;
case Effect::DOUBLE_CLICK: case Effect::DOUBLE_CLICK:
setEffect(WAVEFORM_DOUBLE_CLICK_EFFECT, timeMS); setEffect(WAVEFORM_DOUBLE_CLICK_EFFECT, timeMS);
mShouldSetBrightness = true;
break; break;
case Effect::TICK: case Effect::TICK:
setEffect(WAVEFORM_TICK_EFFECT, timeMS); setEffect(WAVEFORM_TICK_EFFECT, timeMS);
mShouldSetBrightness = true;
break; break;
case Effect::HEAVY_CLICK: case Effect::HEAVY_CLICK:
setEffect(WAVEFORM_HEAVY_CLICK_EFFECT, timeMS); setEffect(WAVEFORM_HEAVY_CLICK_EFFECT, timeMS);
mShouldSetBrightness = true;
break; break;
case Effect::POP: case Effect::POP:
setEffect(WAVEFORM_POP_EFFECT, timeMS); setEffect(WAVEFORM_POP_EFFECT, timeMS);
mShouldSetBrightness = true;
break; break;
case Effect::THUD: case Effect::THUD:
setEffect(WAVEFORM_THUD_EFFECT, timeMS); setEffect(WAVEFORM_THUD_EFFECT, timeMS);
mShouldSetBrightness = true;
break; break;
default: default:
_hidl_cb(Status::UNSUPPORTED_OPERATION, 0); _hidl_cb(Status::UNSUPPORTED_OPERATION, 0);
mShouldSetBrightness = false;
return Void(); return Void();
} }
set(SCALE_PATH, convertEffectStrength(strength)); set(SCALE_PATH, convertEffectStrength(strength));
on(timeMS);
on(timeMS, true /* isWaveform */);
_hidl_cb(status, timeMS); _hidl_cb(status, timeMS);
return Void(); return Void();

View File

@ -25,7 +25,6 @@ namespace {
typedef struct { typedef struct {
std::optional<std::vector<std::string>> sequences; std::optional<std::vector<std::string>> sequences;
std::optional<std::vector<std::string>> loops; std::optional<std::vector<std::string>> loops;
std::optional<int> duration;
std::optional<uint8_t> vmax; std::optional<uint8_t> vmax;
std::optional<uint8_t> gain; std::optional<uint8_t> gain;
int timeMS{}; int timeMS{};
@ -61,10 +60,7 @@ class Vibrator : public IVibrator {
Return<void> perform_1_2(Effect effect, EffectStrength strength, perform_cb _hidl_cb) override; Return<void> perform_1_2(Effect effect, EffectStrength strength, perform_cb _hidl_cb) override;
private: private:
Return<Status> on(uint32_t timeoutMs, bool isWaveform);
Return<void> performEffect(Effect effect, EffectStrength strength, perform_cb _hidl_cb); Return<void> performEffect(Effect effect, EffectStrength strength, perform_cb _hidl_cb);
bool mShouldSetBrightness{};
}; };
} // namespace implementation } // namespace implementation