diff options
author | Sebastiano Barezzi <barezzisebastiano@gmail.com> | 2021-09-13 12:23:27 +0200 |
---|---|---|
committer | Sebastiano Barezzi <barezzisebastiano@gmail.com> | 2021-09-20 14:20:46 +0200 |
commit | 2a2f1278ae24ce00eeca767e5ebc53d616b0a767 (patch) | |
tree | 4f63a75dccadca12791dcb83480e44ad5904d5d0 /ir | |
parent | 91c106c2951ed596750e8f431dcba8b3abcc73b1 (diff) |
sdm660-common: ir: Wire up lirc/spi logic
* Before loading the HAL, make sure the device exists
Change-Id: Ice2a1322ef8d7a3a7d7371a3bdd86547dec20bf1
Diffstat (limited to 'ir')
-rw-r--r-- | ir/ConsumerIr.cpp | 44 |
1 files changed, 37 insertions, 7 deletions
diff --git a/ir/ConsumerIr.cpp b/ir/ConsumerIr.cpp index d632d25..795855b 100644 --- a/ir/ConsumerIr.cpp +++ b/ir/ConsumerIr.cpp @@ -19,16 +19,46 @@ namespace ir { namespace V1_0 { namespace implementation { +typedef struct ir_device { + const std::string name; + const std::string device_path; +} ir_device_t; + +const static ir_device_t devices[] = { + {"lirc", "/dev/lirc0"}, + {"spi", "/dev/spidev7.1"}, +}; + ConsumerIr::ConsumerIr() : mDevice(nullptr) { - const hw_module_t *hw_module = NULL; + const hw_module_t *hw_module; + int ret; + + for (auto& [name, device_path] : devices) { + hw_module = NULL; + ret = 0; - int ret = hw_get_module(CONSUMERIR_HARDWARE_MODULE_ID, &hw_module); - if (ret != 0) { - LOG(FATAL) << "hw_get_module " CONSUMERIR_HARDWARE_MODULE_ID " failed: " << ret; + 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(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); + if (ret < 0) { + LOG(ERROR) << "Can't open consumer IR transmitter (class " << name + << "), error: " << ret; + mDevice = nullptr; + continue; + } + break; } - 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; + + if (mDevice == nullptr) { + LOG(FATAL) << "Could not find a working ConsumerIR HAL"; } } |