blob: 763e09a157e3e508aac34df22bdbcd36e9a5e48d [file] [log] [blame]
Connor O'Brienac9430e2016-12-02 16:22:51 -08001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "ConsumerIrService"
18#include <android/log.h>
19
20#include <hardware/hardware.h>
21#include <hardware/consumerir.h>
22#include "ConsumerIr.h"
23
24namespace android {
25namespace hardware {
26namespace ir {
27namespace V1_0 {
28namespace implementation {
29
30ConsumerIr::ConsumerIr(consumerir_device_t *device) {
31 mDevice = device;
32}
33
34// Methods from ::android::hardware::consumerir::V1_0::IConsumerIr follow.
35Return<bool> ConsumerIr::transmit(int32_t carrierFreq, const hidl_vec<int32_t>& pattern, int32_t patternLen) {
36 return mDevice->transmit(mDevice, carrierFreq, pattern.data(), patternLen) == 0;
37}
38
39Return<void> ConsumerIr::getCarrierFreqs(getCarrierFreqs_cb _hidl_cb) {
40 int32_t len = mDevice->get_num_carrier_freqs(mDevice);
41 if (len < 0) {
42 _hidl_cb(false, {});
43 return Void();
44 }
45
46 consumerir_freq_range_t *rangeAr = new consumerir_freq_range_t[len];
47 bool success = (mDevice->get_carrier_freqs(mDevice, len, rangeAr) >= 0);
48 if (!success) {
49 _hidl_cb(false, {});
50 return Void();
51 }
52
53 hidl_vec<ConsumerIrFreqRange> rangeVec;
54 rangeVec.resize(len);
55 for (int32_t i = 0; i < len; i++) {
56 rangeVec[i].min = static_cast<uint32_t>(rangeAr[i].min);
57 rangeVec[i].max = static_cast<uint32_t>(rangeAr[i].max);
58 }
59 _hidl_cb(true, rangeVec);
60 return Void();
61}
62
63
64IConsumerIr* HIDL_FETCH_IConsumerIr(const char *name) {
65 consumerir_device_t *dev;
66 const hw_module_t *hw_module = NULL;
67
68 int ret = hw_get_module(name, &hw_module);
69 if (ret != 0) {
70 ALOGE("hw_get_module %s failed: %d", name, ret);
71 return nullptr;
72 }
73 ret = hw_module->methods->open(hw_module, CONSUMERIR_TRANSMITTER, (hw_device_t **) &dev);
74 if (ret < 0) {
75 ALOGE("Can't open consumer IR transmitter, error: %d", ret);
76 return nullptr;
77 }
78 return new ConsumerIr(dev);
79}
80
81} // namespace implementation
82} // namespace V1_0
83} // namespace ir
84} // namespace hardware
85} // namespace android