1 /* 2 * Copyright (c) 2022-2024 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 "parcel.h" 20 namespace OHOS { 21 namespace Sensors { 22 constexpr int32_t MAX_EVENT_SIZE = 16; 23 constexpr int32_t MAX_POINT_SIZE = 16; 24 const std::string VIBRATE_BUTT = "butt"; 25 const std::string VIBRATE_TIME = "time"; 26 const std::string VIBRATE_PRESET = "preset"; 27 const std::string VIBRATE_CUSTOM_HD = "custom.hd"; 28 const std::string VIBRATE_CUSTOM_COMPOSITE_EFFECT = "custom.composite.effect"; 29 const std::string VIBRATE_CUSTOM_COMPOSITE_TIME = "custom.composite.time"; 30 31 enum VibrateUsage { 32 USAGE_UNKNOWN = 0, 33 USAGE_ALARM = 1, 34 USAGE_RING = 2, 35 USAGE_NOTIFICATION = 3, 36 USAGE_COMMUNICATION = 4, 37 USAGE_TOUCH = 5, 38 USAGE_MEDIA = 6, 39 USAGE_PHYSICAL_FEEDBACK = 7, 40 USAGE_SIMULATE_REALITY = 8, 41 USAGE_MAX = 9, 42 }; 43 44 enum VibrateTag { 45 EVENT_TAG_UNKNOWN = -1, 46 EVENT_TAG_CONTINUOUS = 0, 47 EVENT_TAG_TRANSIENT = 1, 48 }; 49 50 enum VibrateCustomMode { 51 VIBRATE_MODE_HD = 0, 52 VIBRATE_MODE_MAPPING = 1, 53 VIBRATE_MODE_TIMES = 2, 54 }; 55 56 struct VibrateCurvePoint { 57 bool operator<(const VibrateCurvePoint &rhs) const 58 { 59 return time < rhs.time; 60 } 61 int32_t time = 0; 62 int32_t intensity = 0; 63 int32_t frequency = 0; 64 }; 65 66 struct VibrateEvent { 67 bool operator<(const VibrateEvent &rhs) const 68 { 69 return time < rhs.time; 70 } 71 72 VibrateTag tag; 73 int32_t time = 0; 74 int32_t duration = 0; 75 int32_t intensity = 0; 76 int32_t frequency = 0; 77 int32_t index = 0; 78 std::vector<VibrateCurvePoint> points; 79 }; 80 81 struct VibratePattern : public Parcelable { 82 bool operator<(const VibratePattern &rhs) const 83 { 84 return startTime < rhs.startTime; 85 } 86 int32_t startTime = 0; 87 int32_t patternDuration = 0; 88 std::vector<VibrateEvent> events; 89 void Dump() const; 90 bool Marshalling(Parcel &parcel) const; 91 static VibratePattern* Unmarshalling(Parcel &data); 92 }; 93 94 struct VibratePackage { 95 std::vector<VibratePattern> patterns; 96 int32_t packageDuration = 0; 97 void Dump() const; 98 }; 99 100 struct VibratorCapacity : public Parcelable { 101 bool isSupportHdHaptic = false; 102 bool isSupportPresetMapping = false; 103 bool isSupportTimeDelay = false; 104 void Dump() const; 105 int32_t GetVibrateMode(); 106 bool Marshalling(Parcel &parcel) const; 107 static VibratorCapacity* Unmarshalling(Parcel &data); 108 }; 109 110 struct VibrateSlice { 111 int32_t time = 0; 112 int32_t duration = 0; 113 int32_t intensity = 0; 114 int32_t frequency = 0; 115 }; 116 117 struct VibrateInfo { 118 std::string mode; 119 std::string packageName; 120 int32_t pid = -1; 121 int32_t uid = -1; 122 int32_t usage = 0; 123 bool systemUsage = false; 124 int32_t duration = 0; 125 std::string effect; 126 int32_t count = 0; 127 int32_t intensity = 0; 128 VibratePackage package; 129 }; 130 131 struct VibrateParameter : public Parcelable { 132 int32_t intensity = 100; // from 0 to 100 133 int32_t frequency = 0; // from -100 to 100 134 int32_t reserved = 0; 135 void Dump() const; 136 bool Marshalling(Parcel &parcel) const; 137 static VibrateParameter* Unmarshalling(Parcel &data); 138 }; 139 } // namespace Sensors 140 } // namespace OHOS 141 #endif // VIBRATOR_INFOS_H 142