diff --git a/i2c_tools/i2c_tools.cpp b/i2c_tools/i2c_tools.cpp index f89e296b..c775335b 100644 --- a/i2c_tools/i2c_tools.cpp +++ b/i2c_tools/i2c_tools.cpp @@ -121,3 +121,35 @@ std::string i2c_dump(i2c_smbus_interface * bus, unsigned char address) return text; } /* i2c_dump() */ + +/******************************************************************************************\ +* * +* i2c_read * +* * +* Prints values read from register address regaddr of a given SMBus device * +* * +* bus - pointer to i2c_smbus_interface to scan * +* address - SMBus device address to scan * +* regaddr - register address to read from * +* size - number of bytes to read * +* * +\******************************************************************************************/ + +std::string i2c_read(i2c_smbus_interface * bus, unsigned char address, unsigned char regaddr, unsigned char size) +{ + int i; + + bus->i2c_smbus_write_byte(address, regaddr); + + char line[128]; + std::string text; + + for(i = 0; i < size; i++) + { + sprintf(line, "%02x ", (unsigned char)bus->i2c_smbus_read_byte(address)); + text.append(line); + } + + return text; + +} /* i2c_read() */ diff --git a/i2c_tools/i2c_tools.h b/i2c_tools/i2c_tools.h index 7353f6d0..ea4bc6f4 100644 --- a/i2c_tools/i2c_tools.h +++ b/i2c_tools/i2c_tools.h @@ -9,3 +9,5 @@ std::string i2c_detect(i2c_smbus_interface * bus, int mode); std::string i2c_dump(i2c_smbus_interface * bus, unsigned char address); + +std::string i2c_read(i2c_smbus_interface * bus, unsigned char address, unsigned char regaddr, unsigned char size); diff --git a/qt/OpenRGBSystemInfoPage.cpp b/qt/OpenRGBSystemInfoPage.cpp index 45f80572..b05a8f86 100644 --- a/qt/OpenRGBSystemInfoPage.cpp +++ b/qt/OpenRGBSystemInfoPage.cpp @@ -88,3 +88,23 @@ void Ui::OpenRGBSystemInfoPage::on_DumpButton_clicked() ui->SMBusDataText->setPlainText(i2c_dump(bus, address).c_str()); } } + +void Ui::OpenRGBSystemInfoPage::on_ReadButton_clicked() +{ + int current_index = ui->SMBusAdaptersBox->currentIndex(); + + if(current_index < 0) + { + current_index = 0; + } + + if(busses.size() > current_index) + { + i2c_smbus_interface* bus = busses[current_index]; + unsigned char address = ui->ReadAddressBox->value(); + unsigned char regaddr = ui->ReadRegisterBox->value(); + unsigned char size = ui->ReadSizeBox->value(); + + ui->SMBusDataText->setPlainText(i2c_read(bus, address, regaddr, size).c_str()); + } +} diff --git a/qt/OpenRGBSystemInfoPage.h b/qt/OpenRGBSystemInfoPage.h index 887897bc..a3494679 100644 --- a/qt/OpenRGBSystemInfoPage.h +++ b/qt/OpenRGBSystemInfoPage.h @@ -22,6 +22,8 @@ private slots: void on_DumpButton_clicked(); + void on_ReadButton_clicked(); + private: Ui::OpenRGBSystemInfoPageUi *ui; std::vector& busses; diff --git a/qt/OpenRGBSystemInfoPage.ui b/qt/OpenRGBSystemInfoPage.ui index b1a3f77b..6142b61c 100644 --- a/qt/OpenRGBSystemInfoPage.ui +++ b/qt/OpenRGBSystemInfoPage.ui @@ -14,9 +14,37 @@ Frame - + + + + SMBus Adapters: + + + + + + + Address: + + + + + + + Read Device + + + + + + + + SMBus Dumper: + + + @@ -33,44 +61,6 @@ - - - - Dump Device - - - - - - - Address: - - - - - - - SMBus Dumper: - - - - - - - SMBus Adapters: - - - - - - - Detect Devices - - - - - - @@ -78,6 +68,9 @@ + + + @@ -88,6 +81,81 @@ + + + + Detect Devices + + + + + + + Dump Device + + + + + + + SMBus Reader: + + + + + + + + + Addr: + + + + + + + 0x + + + 255 + + + 16 + + + + + + + Reg: + + + + + + + 0x + + + 255 + + + 16 + + + + + + + Size: + + + + + + + +