• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef VIBRATOR_INFOS_H
17 #define VIBRATOR_INFOS_H
18 
19 #include <string>
20 #include <unordered_map>
21 #include <vector>
22 
23 #include "parcel.h"
24 namespace OHOS {
25 namespace Sensors {
26 const std::string VIBRATE_BUTT = "butt";
27 const std::string VIBRATE_TIME = "time";
28 const std::string VIBRATE_PRESET = "preset";
29 const std::string VIBRATE_CUSTOM_HD = "custom.hd";
30 const std::string VIBRATE_CUSTOM_COMPOSITE_EFFECT = "custom.composite.effect";
31 const std::string VIBRATE_CUSTOM_COMPOSITE_TIME = "custom.composite.time";
32 
33 enum VibrateUsage {
34     USAGE_UNKNOWN = 0,
35     USAGE_ALARM = 1,
36     USAGE_RING = 2,
37     USAGE_NOTIFICATION = 3,
38     USAGE_COMMUNICATION = 4,
39     USAGE_TOUCH = 5,
40     USAGE_MEDIA = 6,
41     USAGE_PHYSICAL_FEEDBACK = 7,
42     USAGE_SIMULATE_REALITY = 8,
43     USAGE_MAX = 9,
44 };
45 
46 enum VibrateTag {
47     EVENT_TAG_UNKNOWN = -1,
48     EVENT_TAG_CONTINUOUS = 0,
49     EVENT_TAG_TRANSIENT = 1,
50 };
51 
52 enum VibrateCustomMode {
53     VIBRATE_MODE_HD = 0,
54     VIBRATE_MODE_MAPPING = 1,
55     VIBRATE_MODE_TIMES = 2,
56 };
57 
58 struct VibrateCurvePoint {
59     bool operator<(const VibrateCurvePoint &rhs) const
60     {
61         return time < rhs.time;
62     }
63     int32_t time = 0;
64     int32_t intensity = 0;
65     int32_t frequency = 0;
66 };
67 
68 struct VibrateEvent {
69     bool operator<(const VibrateEvent &rhs) const
70     {
71         return time < rhs.time;
72     }
73 
74     VibrateTag tag;
75     int32_t time = 0;
76     int32_t duration = 0;
77     int32_t intensity = 0;
78     int32_t frequency = 0;
79     int32_t index = 0;
80     std::vector<VibrateCurvePoint> points;
81 };
82 
83 struct VibratePattern {
84     bool operator<(const VibratePattern &rhs) const
85     {
86         return startTime < rhs.startTime;
87     }
88     int32_t startTime = 0;
89     std::vector<VibrateEvent> events;
90     void Dump() const;
91     bool Marshalling(Parcel &parcel) const;
92     std::optional<VibratePattern> Unmarshalling(Parcel &data);
93 };
94 
95 struct VibratePackage {
96     std::vector<VibratePattern> patterns;
97     void Dump() const;
98 };
99 
100 struct VibratorCapacity {
101     bool isSupportHdHaptic = false;
102     bool isSupportPresetMapping = false;
103     bool isSupportTimeDelay = false;
104     void Dump() const;
105     int32_t GetVibrateMode();
106 };
107 
108 struct VibrateSlice {
109     int32_t time = 0;
110     int32_t duration = 0;
111     int32_t intensity = 0;
112     int32_t frequency = 0;
113 };
114 
115 struct VibrateInfo {
116     std::string mode;
117     std::string packageName;
118     int32_t pid = -1;
119     int32_t uid = -1;
120     int32_t usage = 0;
121     int32_t duration = 0;
122     std::string effect;
123     int32_t count = 0;
124     VibratePackage package;
125 };
126 
127 struct VibrateParameter {
128     int32_t intensity = 100;  // from 0 to 100
129     int32_t frequency = 0;    // from -100 to 100
130     int32_t reserved = 0;
131     void Dump() const;
132     bool Marshalling(Parcel &parcel) const;
133     std::optional<VibrateParameter> Unmarshalling(Parcel &data);
134 };
135 }  // namespace Sensors
136 }  // namespace OHOS
137 #endif  // VIBRATOR_INFOS_H
138