1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include "HardwareBase.h"
#include "Vibrator.h"
namespace aidl {
namespace android {
namespace hardware {
namespace vibrator {
class HwApi : public Vibrator::HwApi, private HwApiBase {
public:
static std::unique_ptr<HwApi> Create() {
auto hwapi = std::unique_ptr<HwApi>(new HwApi());
// the following streams are required
if (!hwapi->mActivate.is_open() || !hwapi->mDuration.is_open() ||
!hwapi->mState.is_open()) {
return nullptr;
}
return hwapi;
}
bool setAutocal(std::string value) override { return set(value, &mAutocal); }
bool setOlLraPeriod(uint32_t value) override { return set(value, &mOlLraPeriod); }
bool setActivate(bool value) override { return set(value, &mActivate); }
bool setDuration(uint32_t value) override { return set(value, &mDuration); }
bool setState(bool value) override { return set(value, &mState); }
bool hasRtpInput() override { return has(mRtpInput); }
bool setRtpInput(int8_t value) override { return set(value, &mRtpInput); }
bool setMode(std::string value) override { return set(value, &mMode); }
bool setSequencer(std::string value) override { return set(value, &mSequencer); }
bool setScale(uint8_t value) override { return set(value, &mScale); }
bool setCtrlLoop(bool value) override { return set(value, &mCtrlLoop); }
bool setLpTriggerEffect(uint32_t value) override { return set(value, &mLpTriggerEffect); }
bool setLpTriggerScale(uint8_t value) override { return set(value, &mLpTriggerScale); }
bool setLraWaveShape(uint32_t value) override { return set(value, &mLraWaveShape); }
bool setOdClamp(uint32_t value) override { return set(value, &mOdClamp); }
void debug(int fd) override { HwApiBase::debug(fd); }
private:
HwApi() {
open("device/autocal", &mAutocal);
open("device/ol_lra_period", &mOlLraPeriod);
open("activate", &mActivate);
open("duration", &mDuration);
open("state", &mState);
open("device/rtp_input", &mRtpInput);
open("device/mode", &mMode);
open("device/set_sequencer", &mSequencer);
open("device/scale", &mScale);
open("device/ctrl_loop", &mCtrlLoop);
open("device/lp_trigger_effect", &mLpTriggerEffect);
open("device/lp_trigger_scale", &mLpTriggerScale);
open("device/lra_wave_shape", &mLraWaveShape);
open("device/od_clamp", &mOdClamp);
}
private:
std::ofstream mAutocal;
std::ofstream mOlLraPeriod;
std::ofstream mActivate;
std::ofstream mDuration;
std::ofstream mState;
std::ofstream mRtpInput;
std::ofstream mMode;
std::ofstream mSequencer;
std::ofstream mScale;
std::ofstream mCtrlLoop;
std::ofstream mLpTriggerEffect;
std::ofstream mLpTriggerScale;
std::ofstream mLraWaveShape;
std::ofstream mOdClamp;
};
class HwCal : public Vibrator::HwCal, private HwCalBase {
private:
static constexpr char AUTOCAL_CONFIG[] = "autocal";
static constexpr char LRA_PERIOD_CONFIG[] = "lra_period";
static constexpr uint32_t WAVEFORM_CLICK_EFFECT_MS = 6;
static constexpr uint32_t WAVEFORM_TICK_EFFECT_MS = 2;
static constexpr uint32_t WAVEFORM_DOUBLE_CLICK_EFFECT_MS = 135;
static constexpr uint32_t WAVEFORM_HEAVY_CLICK_EFFECT_MS = 8;
static constexpr uint32_t DEFAULT_LRA_PERIOD = 262;
static constexpr uint32_t DEFAULT_FREQUENCY_SHIFT = 10;
static constexpr uint32_t DEFAULT_VOLTAGE_MAX = 107; // 2.15V;
public:
HwCal() {}
bool getAutocal(std::string *value) override { return getPersist(AUTOCAL_CONFIG, value); }
bool getLraPeriod(uint32_t *value) override {
if (getPersist(LRA_PERIOD_CONFIG, value)) {
return true;
}
*value = DEFAULT_LRA_PERIOD;
return true;
}
bool getCloseLoopThreshold(uint32_t *value) override {
return getProperty("closeloop.threshold", value, UINT32_MAX);
return true;
}
bool getDynamicConfig(bool *value) override {
return getProperty("config.dynamic", value, false);
}
bool getLongFrequencyShift(uint32_t *value) override {
return getProperty("long.frequency.shift", value, DEFAULT_FREQUENCY_SHIFT);
}
bool getShortVoltageMax(uint32_t *value) override {
return getProperty("short.voltage", value, DEFAULT_VOLTAGE_MAX);
}
bool getLongVoltageMax(uint32_t *value) override {
return getProperty("long.voltage", value, DEFAULT_VOLTAGE_MAX);
}
bool getClickDuration(uint32_t *value) override {
return getProperty("click.duration", value, WAVEFORM_CLICK_EFFECT_MS);
}
bool getTickDuration(uint32_t *value) override {
return getProperty("tick.duration", value, WAVEFORM_TICK_EFFECT_MS);
}
bool getDoubleClickDuration(uint32_t *value) override {
return getProperty("double_click.duration", value, WAVEFORM_DOUBLE_CLICK_EFFECT_MS);
}
bool getHeavyClickDuration(uint32_t *value) override {
return getProperty("heavyclick.duration", value, WAVEFORM_HEAVY_CLICK_EFFECT_MS);
}
void debug(int fd) override { HwCalBase::debug(fd); }
};
} // namespace vibrator
} // namespace hardware
} // namespace android
} // namespace aidl
|