summaryrefslogtreecommitdiff
path: root/sensors/2.1/default/SensorsV2_1.cpp
blob: 06446a262bfeb2da175769d99603ce57ac9d57de (plain)
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
/*
 * Copyright (C) 2020 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.
 */

#include "SensorsV2_1.h"

#include "Sensor.h"

namespace android {
namespace hardware {
namespace sensors {
namespace V2_1 {
namespace implementation {

using V2_X::implementation::ISensorsEventCallback;
using V2_X::implementation::OnChangeSensor;

class HingeAngleSensor : public OnChangeSensor {
  public:
    HingeAngleSensor(int32_t sensorHandle, ISensorsEventCallback* callback)
        : OnChangeSensor(callback) {
        mSensorInfo.sensorHandle = sensorHandle;
        mSensorInfo.name = "Hinge Angle Sensor";
        mSensorInfo.vendor = "Vendor String";
        mSensorInfo.version = 1;
        mSensorInfo.type = SensorType::HINGE_ANGLE;
        mSensorInfo.typeAsString = "";
        mSensorInfo.maxRange = 360.0f;
        mSensorInfo.resolution = 1.0f;
        mSensorInfo.power = 0.001f;
        mSensorInfo.minDelay = 40 * 1000;  // microseconds
        mSensorInfo.maxDelay = V2_X::implementation::kDefaultMaxDelayUs;
        mSensorInfo.fifoReservedEventCount = 0;
        mSensorInfo.fifoMaxEventCount = 0;
        mSensorInfo.requiredPermission = "";
        mSensorInfo.flags = static_cast<uint32_t>(V1_0::SensorFlagBits::ON_CHANGE_MODE |
                                                  V1_0::SensorFlagBits::WAKE_UP |
                                                  V1_0::SensorFlagBits::DATA_INJECTION);
    }
};

SensorsV2_1::SensorsV2_1() {
    AddSensor<HingeAngleSensor>();
}

// Methods from ::android::hardware::sensors::V2_1::ISensors follow.
Return<void> SensorsV2_1::getSensorsList_2_1(ISensors::getSensorsList_2_1_cb _hidl_cb) {
    std::vector<SensorInfo> sensors;
    for (const auto& sensor : mSensors) {
        sensors.push_back(sensor.second->getSensorInfo());
    }

    // Call the HIDL callback with the SensorInfo
    _hidl_cb(sensors);

    return Void();
}

Return<Result> SensorsV2_1::initialize_2_1(
        const ::android::hardware::MQDescriptorSync<V2_1::Event>& eventQueueDescriptor,
        const ::android::hardware::MQDescriptorSync<uint32_t>& wakeLockDescriptor,
        const sp<V2_1::ISensorsCallback>& sensorsCallback) {
    auto eventQueue = std::make_unique<MessageQueue<V2_1::Event, kSynchronizedReadWrite>>(
            eventQueueDescriptor, true /* resetPointers */);
    std::unique_ptr<EventMessageQueueWrapperBase> wrapper =
            std::make_unique<EventMessageQueueWrapperV2_1>(eventQueue);
    mCallbackWrapper = new ISensorsCallbackWrapper(sensorsCallback);
    return initializeBase(wrapper, wakeLockDescriptor, mCallbackWrapper);
}

Return<Result> SensorsV2_1::injectSensorData_2_1(const V2_1::Event& event) {
    return injectSensorData(convertToOldEvent(event));
}

}  // namespace implementation
}  // namespace V2_1
}  // namespace sensors
}  // namespace hardware
}  // namespace android