Skip to content

Commit

Permalink
markw: add consumerir skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
anomalchik authored and Razziell committed Jun 29, 2018
1 parent 35bb689 commit 5d6ad78
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 0 deletions.
1 change: 1 addition & 0 deletions Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@

subdirs = [
"light",
"consumerir",
]
24 changes: 24 additions & 0 deletions consumerir/Android.bp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (C) 2013 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.

cc_library_shared {
name: "consumerir.msm8953",
relative_install_path: "hw",
proprietary: true,
srcs: ["consumerir.c"],
header_libs: ["libhardware_headers"],
shared_libs: [
"liblog",
],
}
121 changes: 121 additions & 0 deletions consumerir/consumerir.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
* Copyright (C) 2013 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.
*/
#define LOG_TAG "ConsumerIrHal"

#include <errno.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include <log/log.h>

#include <hardware/consumerir.h>
#include <hardware/hardware.h>

#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))

static const consumerir_freq_range_t consumerir_freqs[] = {
{.min = 30000, .max = 30000},
{.min = 33000, .max = 33000},
{.min = 36000, .max = 36000},
{.min = 38000, .max = 38000},
{.min = 40000, .max = 40000},
{.min = 56000, .max = 56000},
};

static int consumerir_transmit(struct consumerir_device *dev __unused,
int carrier_freq, const int pattern[], int pattern_len)
{
int total_time = 0;
long i;

for (i = 0; i < pattern_len; i++)
total_time += pattern[i];

/* simulate the time spent transmitting by sleeping */
ALOGD("transmit for %d uS at %d Hz", total_time, carrier_freq);
usleep(total_time);

return 0;
}

static int consumerir_get_num_carrier_freqs(struct consumerir_device *dev __unused)
{
return ARRAY_SIZE(consumerir_freqs);
}

static int consumerir_get_carrier_freqs(struct consumerir_device *dev __unused,
size_t len, consumerir_freq_range_t *ranges)
{
size_t to_copy = ARRAY_SIZE(consumerir_freqs);

to_copy = len < to_copy ? len : to_copy;
memcpy(ranges, consumerir_freqs, to_copy * sizeof(consumerir_freq_range_t));
return to_copy;
}

static int consumerir_close(hw_device_t *dev)
{
free(dev);
return 0;
}

/*
* Generic device handling
*/
static int consumerir_open(const hw_module_t* module, const char* name,
hw_device_t** device)
{
if (strcmp(name, CONSUMERIR_TRANSMITTER) != 0) {
return -EINVAL;
}
if (device == NULL) {
ALOGE("NULL device on open");
return -EINVAL;
}

consumerir_device_t *dev = malloc(sizeof(consumerir_device_t));
memset(dev, 0, sizeof(consumerir_device_t));

dev->common.tag = HARDWARE_DEVICE_TAG;
dev->common.version = 0;
dev->common.module = (struct hw_module_t*) module;
dev->common.close = consumerir_close;

dev->transmit = consumerir_transmit;
dev->get_num_carrier_freqs = consumerir_get_num_carrier_freqs;
dev->get_carrier_freqs = consumerir_get_carrier_freqs;

*device = (hw_device_t*) dev;
return 0;
}

static struct hw_module_methods_t consumerir_module_methods = {
.open = consumerir_open,
};

consumerir_module_t HAL_MODULE_INFO_SYM = {
.common = {
.tag = HARDWARE_MODULE_TAG,
.module_api_version = CONSUMERIR_MODULE_API_VERSION_1_0,
.hal_api_version = HARDWARE_HAL_API_VERSION,
.id = CONSUMERIR_HARDWARE_MODULE_ID,
.name = "Demo IR HAL",
.author = "The Android Open Source Project",
.methods = &consumerir_module_methods,
},
};

0 comments on commit 5d6ad78

Please sign in to comment.