From 2a2f1278ae24ce00eeca767e5ebc53d616b0a767 Mon Sep 17 00:00:00 2001 From: Sebastiano Barezzi Date: Mon, 13 Sep 2021 12:23:27 +0200 Subject: sdm660-common: ir: Wire up lirc/spi logic * Before loading the HAL, make sure the device exists Change-Id: Ice2a1322ef8d7a3a7d7371a3bdd86547dec20bf1 --- ir/ConsumerIr.cpp | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) (limited to 'ir') 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"; } } -- cgit v1.2.3