1/*
2 * Copyright (c) 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_2_VIBRATORTYPES_H
17#define OHOS_HDI_VIBRATOR_V1_2_VIBRATORTYPES_H
18
19#include <cstdbool>
20#include <cstdint>
21#include <vector>
22#include "vibrator/v1_1/vibrator_types.h"
23
24#ifndef HDI_BUFF_MAX_SIZE
25#define HDI_BUFF_MAX_SIZE (1024 * 200)
26#endif
27
28#ifndef HDI_CHECK_VALUE_RETURN
29#define HDI_CHECK_VALUE_RETURN(lv, compare, rv, ret) do { \
30    if ((lv) compare (rv)) { \
31        return ret; \
32    } \
33} while (false)
34#endif
35
36#ifndef HDI_CHECK_VALUE_RET_GOTO
37#define HDI_CHECK_VALUE_RET_GOTO(lv, compare, rv, ret, value, table) do { \
38    if ((lv) compare (rv)) { \
39        ret = value; \
40        goto table; \
41    } \
42} while (false)
43#endif
44
45namespace OHOS {
46class MessageParcel;
47}
48
49namespace OHOS {
50namespace HDI {
51namespace Vibrator {
52namespace V1_2 {
53
54using namespace OHOS;
55using namespace OHOS::HDI::Vibrator::V1_1;
56
57enum EVENT_TYPE : int32_t {
58    CONTINUOUS = 0,
59    TRANSIENT = 1,
60};
61
62enum HdfVibratorModeV1_2 : int32_t {
63    HDF_VIBRATOR_MODE_ONCE,
64    HDF_VIBRATOR_MODE_PRESET,
65    HDF_VIBRATOR_MODE_HDHAPTIC,
66    HDF_VIBRATOR_MODE_BUTT,
67};
68
69struct CurvePoint {
70    int32_t time;
71    int32_t intensity;
72    int32_t frequency;
73} __attribute__ ((aligned(8)));
74
75struct HapticEvent {
76    OHOS::HDI::Vibrator::V1_2::EVENT_TYPE type;
77    int32_t time;
78    int32_t duration;
79    int32_t intensity;
80    int32_t frequency;
81    int32_t index;
82    int32_t pointNum;
83    std::vector<OHOS::HDI::Vibrator::V1_2::CurvePoint> points;
84};
85
86struct HapticPaket {
87    int32_t time;
88    int32_t eventNum;
89    std::vector<OHOS::HDI::Vibrator::V1_2::HapticEvent> events;
90};
91
92struct HapticCapacity {
93    bool isSupportHdHaptic;
94    bool isSupportPresetMapping;
95    bool isSupportTimeDelay;
96    bool reserved0;
97    int32_t reserved1;
98} __attribute__ ((aligned(8)));
99
100bool CurvePointBlockMarshalling(OHOS::MessageParcel &data, const OHOS::HDI::Vibrator::V1_2::CurvePoint& dataBlock);
101
102bool CurvePointBlockUnmarshalling(OHOS::MessageParcel &data, OHOS::HDI::Vibrator::V1_2::CurvePoint& dataBlock);
103
104bool HapticEventBlockMarshalling(OHOS::MessageParcel &data, const OHOS::HDI::Vibrator::V1_2::HapticEvent& dataBlock);
105
106bool HapticEventBlockUnmarshalling(OHOS::MessageParcel &data, OHOS::HDI::Vibrator::V1_2::HapticEvent& dataBlock);
107
108bool HapticPaketBlockMarshalling(OHOS::MessageParcel &data, const OHOS::HDI::Vibrator::V1_2::HapticPaket& dataBlock);
109
110bool HapticPaketBlockUnmarshalling(OHOS::MessageParcel &data, OHOS::HDI::Vibrator::V1_2::HapticPaket& dataBlock);
111
112bool HapticCapacityBlockMarshalling(OHOS::MessageParcel &data, const OHOS::HDI::Vibrator::V1_2::HapticCapacity& dataBlock);
113
114bool HapticCapacityBlockUnmarshalling(OHOS::MessageParcel &data, OHOS::HDI::Vibrator::V1_2::HapticCapacity& dataBlock);
115
116} // V1_2
117} // Vibrator
118} // HDI
119} // OHOS
120
121#endif // OHOS_HDI_VIBRATOR_V1_2_VIBRATORTYPES_H
122
123