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 OHOS_HDI_VIBRATOR_V1_1_VIBRATORTYPES_H
17#define OHOS_HDI_VIBRATOR_V1_1_VIBRATORTYPES_H
18
19#include <cstdbool>
20#include <cstdint>
21#include <vector>
22
23#ifndef HDI_BUFF_MAX_SIZE
24#define HDI_BUFF_MAX_SIZE (1024 * 200)
25#endif
26
27#ifndef HDI_CHECK_VALUE_RETURN
28#define HDI_CHECK_VALUE_RETURN(lv, compare, rv, ret) do { \
29    if ((lv) compare (rv)) { \
30        return ret; \
31    } \
32} while (false)
33#endif
34
35#ifndef HDI_CHECK_VALUE_RET_GOTO
36#define HDI_CHECK_VALUE_RET_GOTO(lv, compare, rv, ret, value, table) do { \
37    if ((lv) compare (rv)) { \
38        ret = value; \
39        goto table; \
40    } \
41} while (false)
42#endif
43
44namespace OHOS {
45class MessageParcel;
46}
47
48namespace OHOS {
49namespace HDI {
50namespace Vibrator {
51namespace V1_1 {
52
53using namespace OHOS;
54
55enum HdfVibratorMode : int32_t {
56    HDF_VIBRATOR_MODE_ONCE,
57    HDF_VIBRATOR_MODE_PRESET,
58    HDF_VIBRATOR_MODE_BUTT,
59};
60
61enum HdfEffectType : int32_t {
62    HDF_EFFECT_TYPE_TIME,
63    HDF_EFFECT_TYPE_PRIMITIVE,
64    HDF_EFFECT_TYPE_BUTT,
65};
66
67struct HdfVibratorInfo {
68    bool isSupportIntensity;
69    bool isSupportFrequency;
70    uint16_t intensityMaxValue;
71    uint16_t intensityMinValue;
72    int16_t frequencyMaxValue;
73    int16_t frequencyMinValue;
74} __attribute__ ((aligned(8)));
75
76struct TimeEffect {
77    int32_t delay;
78    int32_t time;
79    uint16_t intensity;
80    int16_t frequency;
81} __attribute__ ((aligned(8)));
82
83struct PrimitiveEffect {
84    int32_t delay;
85    int32_t effectId;
86    uint16_t intensity;
87} __attribute__ ((aligned(8)));
88
89union CompositeEffect {
90    OHOS::HDI::Vibrator::V1_1::TimeEffect timeEffect;
91    OHOS::HDI::Vibrator::V1_1::PrimitiveEffect primitiveEffect;
92}  __attribute__ ((aligned(8)));
93
94struct HdfCompositeEffect {
95    int32_t type;
96    std::vector<OHOS::HDI::Vibrator::V1_1::CompositeEffect> compositeEffects;
97};
98
99struct HdfEffectInfo {
100    int32_t duration;
101    bool isSupportEffect;
102} __attribute__ ((aligned(8)));
103
104bool HdfVibratorInfoBlockMarshalling(OHOS::MessageParcel &data, const OHOS::HDI::Vibrator::V1_1::HdfVibratorInfo& dataBlock);
105
106bool HdfVibratorInfoBlockUnmarshalling(OHOS::MessageParcel &data, OHOS::HDI::Vibrator::V1_1::HdfVibratorInfo& dataBlock);
107
108bool TimeEffectBlockMarshalling(OHOS::MessageParcel &data, const OHOS::HDI::Vibrator::V1_1::TimeEffect& dataBlock);
109
110bool TimeEffectBlockUnmarshalling(OHOS::MessageParcel &data, OHOS::HDI::Vibrator::V1_1::TimeEffect& dataBlock);
111
112bool PrimitiveEffectBlockMarshalling(OHOS::MessageParcel &data, const OHOS::HDI::Vibrator::V1_1::PrimitiveEffect& dataBlock);
113
114bool PrimitiveEffectBlockUnmarshalling(OHOS::MessageParcel &data, OHOS::HDI::Vibrator::V1_1::PrimitiveEffect& dataBlock);
115
116bool HdfCompositeEffectBlockMarshalling(OHOS::MessageParcel &data, const OHOS::HDI::Vibrator::V1_1::HdfCompositeEffect& dataBlock);
117
118bool HdfCompositeEffectBlockUnmarshalling(OHOS::MessageParcel &data, OHOS::HDI::Vibrator::V1_1::HdfCompositeEffect& dataBlock);
119
120bool HdfEffectInfoBlockMarshalling(OHOS::MessageParcel &data, const OHOS::HDI::Vibrator::V1_1::HdfEffectInfo& dataBlock);
121
122bool HdfEffectInfoBlockUnmarshalling(OHOS::MessageParcel &data, OHOS::HDI::Vibrator::V1_1::HdfEffectInfo& dataBlock);
123
124} // V1_1
125} // Vibrator
126} // HDI
127} // OHOS
128
129#endif // OHOS_HDI_VIBRATOR_V1_1_VIBRATORTYPES_H
130
131