sdm660-common: ir: Wire up lirc/spi logic
* Before loading the HAL, make sure the device exists Change-Id: Ice2a1322ef8d7a3a7d7371a3bdd86547dec20bf1 Signed-off-by: clarencelol <clarencekuiek@icloud.com> Signed-off-by: OdSazib <odsazib@gmail.com>
This commit is contained in:
parent
fa7fa65ffb
commit
47b8b542c7
1 changed files with 38 additions and 8 deletions
|
@ -19,16 +19,46 @@ namespace ir {
|
|||
namespace V1_0 {
|
||||
namespace implementation {
|
||||
|
||||
ConsumerIr::ConsumerIr() : mDevice(nullptr) {
|
||||
const hw_module_t *hw_module = NULL;
|
||||
typedef struct ir_device {
|
||||
const std::string name;
|
||||
const std::string device_path;
|
||||
} ir_device_t;
|
||||
|
||||
int ret = hw_get_module(CONSUMERIR_HARDWARE_MODULE_ID, &hw_module);
|
||||
const static ir_device_t devices[] = {
|
||||
{"lirc", "/dev/lirc0"},
|
||||
{"spi", "/dev/spidev7.1"},
|
||||
};
|
||||
|
||||
ConsumerIr::ConsumerIr() : mDevice(nullptr) {
|
||||
const hw_module_t *hw_module;
|
||||
int ret;
|
||||
|
||||
for (auto& [name, device_path] : devices) {
|
||||
hw_module = NULL;
|
||||
ret = 0;
|
||||
|
||||
if (access(device_path.c_str(), F_OK) == -1)
|
||||
continue;
|
||||
|
||||
ret = hw_get_module_by_class(CONSUMERIR_HARDWARE_MODULE_ID, name.c_str(), &hw_module);
|
||||
if (ret != 0) {
|
||||
LOG(FATAL) << "hw_get_module " CONSUMERIR_HARDWARE_MODULE_ID " failed: " << ret;
|
||||
LOG(ERROR) << "hw_get_module " CONSUMERIR_HARDWARE_MODULE_ID " (class "
|
||||
<< name << ") failed: " << ret;
|
||||
continue;
|
||||
}
|
||||
ret = hw_module->methods->open(hw_module, CONSUMERIR_TRANSMITTER, (hw_device_t **) &mDevice);
|
||||
ret = hw_module->methods->open(hw_module, CONSUMERIR_TRANSMITTER,
|
||||
(hw_device_t **) &mDevice);
|
||||
if (ret < 0) {
|
||||
LOG(FATAL) << "Can't open consumer IR transmitter, error: " << ret;
|
||||
LOG(ERROR) << "Can't open consumer IR transmitter (class " << name
|
||||
<< "), error: " << ret;
|
||||
mDevice = nullptr;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (mDevice == nullptr) {
|
||||
LOG(FATAL) << "Could not find a working ConsumerIR HAL";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue