blob: 6a032a75e08ee1a7f91eac4fd369c506d30adfd5 [file] [log] [blame]
Alex Ray09875a22013-09-04 23:32:55 -07001/*
2 * Copyright (C) 2013 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#define LOG_TAG "ConsumerIrHal"
17
18#include <errno.h>
19#include <string.h>
20#include <cutils/log.h>
21#include <hardware/hardware.h>
22#include <hardware/consumerir.h>
23
24#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
25
26static const consumerir_freq_range_t consumerir_freqs[] = {
27 {.min = 30000, .max = 30000},
28 {.min = 33000, .max = 33000},
29 {.min = 36000, .max = 36000},
30 {.min = 38000, .max = 38000},
31 {.min = 40000, .max = 40000},
32 {.min = 56000, .max = 56000},
33};
34
35static int consumerir_transmit(struct consumerir_device *dev,
36 int carrier_freq, int pattern[], int pattern_len)
37{
38 int total_time = 0;
39 long i;
40
41 for (i = 0; i < pattern_len; i++)
42 total_time += pattern[i];
43
44 /* simulate the time spent transmitting by sleeping */
45 ALOGD("transmit for %d uS at %d Hz", total_time, carrier_freq);
46 usleep(total_time);
47
48 return 0;
49}
50
51static int consumerir_get_num_carrier_freqs(struct consumerir_device *dev)
52{
53 return ARRAY_SIZE(consumerir_freqs);
54}
55
56static int consumerir_get_carrier_freqs(struct consumerir_device *dev,
57 consumerir_freq_range_t *ranges)
58{
59 memcpy(ranges, consumerir_freqs, sizeof(consumerir_freqs));
60 return ARRAY_SIZE(consumerir_freqs);
61}
62
63static int consumerir_close(hw_device_t *dev)
64{
65 free(dev);
66 return 0;
67}
68
69/*
70 * Generic device handling
71 */
72static int consumerir_open(const hw_module_t* module, const char* name,
73 hw_device_t** device)
74{
75 if (strcmp(name, CONSUMERIR_TRANSMITTER) != 0) {
76 return -EINVAL;
77 }
78 if (device == NULL) {
79 ALOGE("NULL device on open");
80 return -EINVAL;
81 }
82
83 consumerir_device_t *dev = malloc(sizeof(consumerir_device_t));
84 memset(dev, 0, sizeof(consumerir_device_t));
85
86 dev->common.tag = HARDWARE_DEVICE_TAG;
87 dev->common.version = 0;
88 dev->common.module = (struct hw_module_t*) module;
89 dev->common.close = consumerir_close;
90
91 dev->transmit = consumerir_transmit;
92 dev->get_num_carrier_freqs = consumerir_get_num_carrier_freqs;
93 dev->get_carrier_freqs = consumerir_get_carrier_freqs;
94
95 *device = (hw_device_t*) dev;
96 return 0;
97}
98
99static struct hw_module_methods_t consumerir_module_methods = {
100 .open = consumerir_open,
101};
102
103consumerir_module_t HAL_MODULE_INFO_SYM = {
104 .common = {
105 .tag = HARDWARE_MODULE_TAG,
106 .module_api_version = CONSUMERIR_MODULE_API_VERSION_1_0,
107 .hal_api_version = HARDWARE_HAL_API_VERSION,
108 .id = CONSUMERIR_HARDWARE_MODULE_ID,
109 .name = "Demo IR HAL",
110 .author = "The Android Open Source Project",
111 .methods = &consumerir_module_methods,
112 },
113};