From dc3009bcaf7c110724cbde7b77f45d0dfb7fc08b Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Mon, 25 Feb 2019 22:06:46 -0600 Subject: [PATCH] Add some sanity checking to Aura device detection. Aura devices appear to read incrementing values at 0xA0 if no register written --- OpenAuraSDK/OpenAuraSDK.cpp | 44 ++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/OpenAuraSDK/OpenAuraSDK.cpp b/OpenAuraSDK/OpenAuraSDK.cpp index 14c8f1b3..8024ca3c 100644 --- a/OpenAuraSDK/OpenAuraSDK.cpp +++ b/OpenAuraSDK/OpenAuraSDK.cpp @@ -197,6 +197,42 @@ void DetectI2CBusses() #endif /* WIN32 */ +/******************************************************************************************\ +* * +* TestForAuraController * +* * +* Tests the given address to see if an Aura controller exists there. First does a * +* quick write to test for a response, and if so does a simple read at 0xA0 to test * +* for incrementing values 0...F which was observed at this location during data dump * +* * +\******************************************************************************************/ + +bool TestForAuraController(i2c_smbus_interface* bus, unsigned char address) +{ + bool pass = false; + + int res = bus->i2c_smbus_write_quick(address, I2C_SMBUS_WRITE); + + if (res >= 0) + { + pass = true; + + for (int i = 0xA0; i < 0xB0; i++) + { + res = bus->i2c_smbus_read_byte_data(address, i); + + if (res != (i - 0xA0)) + { + pass = false; + } + } + } + + return(pass); + +} /* TestForAuraController() */ + + /******************************************************************************************\ * * * DetectAuraControllers * @@ -236,9 +272,7 @@ void DetectAuraControllers() // Add Aura-enabled controllers at their remapped addresses for (unsigned int slot = 0; slot < 8; slot++) { - int res = busses[bus]->i2c_smbus_write_quick(0x70 + slot, I2C_SMBUS_WRITE); - - if (res >= 0) + if (TestForAuraController(busses[bus], 0x70 + slot)) { new_controller = new AuraController(busses[bus], 0x70 + slot); controllers.push_back(new_controller); @@ -246,9 +280,7 @@ void DetectAuraControllers() } // Check for Aura controller at 0x4E - int res = busses[bus]->i2c_smbus_write_quick(0x4E, I2C_SMBUS_WRITE); - - if (res >= 0) + if (TestForAuraController(busses[bus], 0x4E)) { new_controller = new AuraController(busses[bus], 0x4E); controllers.push_back(new_controller);