From c74a9849c0cf4e5c9a8894f5f61f34c121211e19 Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Sun, 7 Nov 2021 14:14:24 -0600 Subject: [PATCH] Properly detect I2C initialization fail on Linux and fix dialog always being displayed even when I2C initialization was successful --- ResourceManager.cpp | 17 ++++++++++------- i2c_smbus/i2c_smbus_linux.cpp | 15 +++++++++++++-- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/ResourceManager.cpp b/ResourceManager.cpp index 80b20193..d45ec267 100644 --- a/ResourceManager.cpp +++ b/ResourceManager.cpp @@ -1108,17 +1108,20 @@ void ResourceManager::DetectDevicesThreadFunction() | If any i2c interfaces failed to detect due to an | | error condition, show a dialog | \*-------------------------------------------------*/ - LOG_DIALOG("One or more I2C/SMBus interfaces failed to initialize.\r" + if(i2c_interface_fail) + { + LOG_DIALOG("One or more I2C/SMBus interfaces failed to initialize.\r" #ifdef _WIN32 - "On Windows, this is usually caused by a failure to load the inpout32 driver.\r" - "You must run OpenRGB as administrator at least once to allow inpout32 to set up.\r" + "On Windows, this is usually caused by a failure to load the inpout32 driver.\r" + "You must run OpenRGB as administrator at least once to allow inpout32 to set up.\r" #endif #ifdef __linux__ - "On Linux, this is usually because the i2c-dev module is not loaded.\r" - "You must load the i2c-dev module along with the correct i2c driver for your motherboard.\r" - "This is usually i2c-piix4 for AMD systems and i2c-i801 for Intel systems.\r" + "On Linux, this is usually because the i2c-dev module is not loaded.\r" + "You must load the i2c-dev module along with the correct i2c driver for your motherboard.\r" + "This is usually i2c-piix4 for AMD systems and i2c-i801 for Intel systems.\r" #endif - "See https://help.openrgb.org for additional troubleshooting."); + "See https://help.openrgb.org for additional troubleshooting."); + } } void ResourceManager::StopDeviceDetection() diff --git a/i2c_smbus/i2c_smbus_linux.cpp b/i2c_smbus/i2c_smbus_linux.cpp index fc4a8390..4e55c9ef 100644 --- a/i2c_smbus/i2c_smbus_linux.cpp +++ b/i2c_smbus/i2c_smbus_linux.cpp @@ -42,6 +42,7 @@ bool i2c_smbus_linux_detect() char driver_path[512]; struct dirent * ent; int test_fd; + int ret = true; char path[1024]; char buff[100]; unsigned short pci_device, pci_vendor, pci_subsystem_device, pci_subsystem_vendor; @@ -58,6 +59,12 @@ bool i2c_smbus_linux_detect() // Loop through all entries in i2c-adapter list ent = readdir(dir); + + if(ent == NULL) + { + return(false); + } + while(ent != NULL) { if(ent->d_type == DT_DIR || ent->d_type == DT_LNK) @@ -142,7 +149,7 @@ bool i2c_smbus_linux_detect() if (test_fd < 0) { ent = readdir(dir); - continue; + ret = false; } bus = new i2c_smbus_linux(); @@ -155,13 +162,17 @@ bool i2c_smbus_linux_detect() bus->port_id = port_id; ResourceManager::get()->RegisterI2CBus(bus); } + else + { + ret = false; + } } } ent = readdir(dir); } closedir(dir); - return(true); + return(ret); } REGISTER_I2C_BUS_DETECTOR(i2c_smbus_linux_detect);