From 4e3b547657b6a74bc87ec7671f4cf49c13783e64 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Thu, 18 Jun 2020 14:24:15 +0200 Subject: [PATCH] BLM certify part 1 --- tasmota/xsns_54_ina226.ino | 62 +++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/tasmota/xsns_54_ina226.ino b/tasmota/xsns_54_ina226.ino index 725a63bb3..81c4bafc3 100644 --- a/tasmota/xsns_54_ina226.ino +++ b/tasmota/xsns_54_ina226.ino @@ -26,7 +26,7 @@ * 2. Configure the module to use I2C on the correct pins. * 3. Connect your ina226 module(s) to the I2C pins. * 4. Use the i2cscan console command to probe the modules and check they are present. -* 5. Enable the first device at I2C slave address 0x40 using the following console commands: +* 5. Enable the first device at I2C address 0x40 using the following console commands: * a. Sensor54 11 [shunt resistance in ohms] e.g. Sensor54 11 0.1 * b. Sensor54 12 [full scale current in amperes] e.g. Sensor54 12 3.0 * c. Sensor54 2 saves the settings and restarts Tasmota. The device should show up after the system boots again. @@ -35,7 +35,7 @@ * This driver will not probe I2C bus for INA226 devices unless the full scale current is set for a device number. * It will map device numbers as follows: * -* Device number to I2C slave address mapping +* Device number to I2C address mapping * * 1 - 0x40 * 2 - 0x41 @@ -59,7 +59,7 @@ * * Other commands * -* Sensor54 1 Rescan for devices and return the number of slaves found. +* Sensor54 1 Rescan for devices and return the number of INA226 found. * Sensor54 2 Save the configuration and restart * * @@ -88,13 +88,13 @@ #define INA226_REG_CALIBRATION (0x05) -typedef struct Ina226SlaveInfo_tag { +typedef struct Ina226Info_tag { uint8_t address; uint16_t calibrationValue; uint16_t config; uint8_t present : 1; float i_lsb; -} Ina226SlaveInfo_t; +} Ina226Info_t; /* * Program memory constants @@ -108,9 +108,9 @@ static const uint8_t PROGMEM probeAddresses[INA226_MAX_ADDRESSES] = {INA226_ADDR static char Ina226Str[] = "INA226"; -static uint8_t slavesFound = 0; +static uint8_t Ina226sFound = 0; static uint8_t schedule_reinit = 0; -static Ina226SlaveInfo_t slaveInfo[4] = {0}; +static Ina226Info_t Ina226Info[4] = {0}; //static uint16_t reinit_count[4]; static float voltages[4]; static float currents[4]; @@ -148,10 +148,10 @@ static uint32_t _expand_r_shunt(uint16_t compact_r_shunt) * Set calibration value for Ina226 */ -void Ina226SetCalibration(uint8_t slaveIndex) +void Ina226SetCalibration(uint8_t Ina226Index) { -Ina226SlaveInfo_t *si = slaveInfo + slaveIndex; +Ina226Info_t *si = Ina226Info + Ina226Index; I2cWrite16( si->address, INA226_REG_CALIBRATION, si->calibrationValue); @@ -167,10 +167,10 @@ bool Ina226TestPresence(uint8_t device) // Read config - uint16_t config = I2cRead16( slaveInfo[device].address, INA226_REG_CONFIG ); + uint16_t config = I2cRead16( Ina226Info[device].address, INA226_REG_CONFIG ); //AddLog_P2( LOG_LEVEL_NONE, PSTR("Config register %04x" ), config); - if (config != slaveInfo[device].config) + if (config != Ina226Info[device].config) return false; return true; @@ -179,10 +179,10 @@ bool Ina226TestPresence(uint8_t device) void Ina226ResetActive(void) { - Ina226SlaveInfo_t *p = slaveInfo; + Ina226Info_t *p = Ina226Info; for (uint32_t i = 0; i < INA226_MAX_ADDRESSES; i++) { - p = &slaveInfo[i]; + p = &Ina226Info[i]; // Address uint8_t addr = p->address; if (addr) { @@ -199,9 +199,9 @@ void Ina226Init() { uint32_t i; - slavesFound = 0; + Ina226sFound = 0; - Ina226SlaveInfo_t *p = slaveInfo; + Ina226Info_t *p = Ina226Info; //AddLog_P2( LOG_LEVEL_NONE, "Ina226Init"); // AddLog_P2( LOG_LEVEL_NONE, "Size of Settings: %d bytes", sizeof(Settings)); @@ -210,7 +210,7 @@ void Ina226Init() // AddLog_P2(LOG_LEVEL_DEBUG, "INA226: Initialization failed: No I2C support"); - // Clear slave info data + // Clear Ina226 info data for (i = 0; i < 4; i++){ *p = {0}; @@ -232,7 +232,7 @@ void Ina226Init() continue; - //AddLog_P2( LOG_LEVEL_NONE, PSTR("INA226 trying slave address %02x" ), addr ); + //AddLog_P2( LOG_LEVEL_NONE, PSTR("INA226 trying address %02x" ), addr ); // Try Resetting the device @@ -257,8 +257,8 @@ void Ina226Init() if (!I2cWrite16( addr, INA226_REG_CONFIG, config)) continue; // No device - // store data in slave info struct. - p = &slaveInfo[i]; + // store data in info struct. + p = &Ina226Info[i]; // Address p->address = addr; // Configuration @@ -282,7 +282,7 @@ void Ina226Init() I2cSetActiveFound(addr, Ina226Str); - slavesFound++; + Ina226sFound++; } } @@ -292,7 +292,7 @@ void Ina226Init() float Ina226ReadBus_v(uint8_t device) { - uint8_t addr = slaveInfo[device].address; + uint8_t addr = Ina226Info[device].address; int16_t reg_bus_v = I2cReadS16( addr, INA226_REG_BUSVOLTAGE); float result = ((float) reg_bus_v) * 0.00125f; @@ -307,10 +307,10 @@ float Ina226ReadBus_v(uint8_t device) float Ina226ReadShunt_i(uint8_t device) { - uint8_t addr = slaveInfo[device].address; + uint8_t addr = Ina226Info[device].address; int16_t reg_shunt_i = I2cReadS16( addr, INA226_REG_CURRENT); - float result = ((float) reg_shunt_i) * slaveInfo[device].i_lsb; + float result = ((float) reg_shunt_i) * Ina226Info[device].i_lsb; return result; } @@ -321,10 +321,10 @@ float Ina226ReadShunt_i(uint8_t device) float Ina226ReadPower_w(uint8_t device) { - uint8_t addr = slaveInfo[device].address; + uint8_t addr = Ina226Info[device].address; int16_t reg_shunt_i = I2cReadS16( addr, INA226_REG_POWER); - float result = ((float) reg_shunt_i) * (slaveInfo[device].i_lsb * 25.0); + float result = ((float) reg_shunt_i) * (Ina226Info[device].i_lsb * 25.0); return result; } @@ -354,19 +354,19 @@ void Ina226EverySecond() { //AddLog_P2( LOG_LEVEL_NONE, "Ina226EverySecond"); for (uint8_t device = 0; device < INA226_MAX_ADDRESSES; device++){ - // If there are slaves, and the device was present, and the device still is present, read its registers - if (slavesFound && slaveInfo[device].present && Ina226TestPresence(device)){ + // If there are Ina226s, and the device was present, and the device still is present, read its registers + if (Ina226sFound && Ina226Info[device].present && Ina226TestPresence(device)){ Ina226Read(device); } else { powers[device] = currents[device] = voltages[device] = 0.0f; // If device was present, note that it dropped off here - //if(slaveInfo[device].present){ + //if(Ina226Info[device].present){ //reinit_count[device]++; //AddLog_P2( LOG_LEVEL_DEBUG, "INA226 Device %d dropped off, count: %d", device, reinit_count[device]); //} // Device no longer present - slaveInfo[device].present = false; + Ina226Info[device].present = false; } } } @@ -413,7 +413,7 @@ bool Ina226CommandSensor() case 1: // Rerun init Ina226ResetActive(); Ina226Init(); - Response_P(PSTR("{\"Sensor54-Command-Result\":{\"SlavesFound\":%d}}"),slavesFound); + Response_P(PSTR("{\"Sensor54-Command-Result\":{\"Ina226sFound\":%d}}"),Ina226sFound); break; case 2: // Save and restart @@ -497,7 +497,7 @@ void Ina226Show(bool json) int i, num_found; for (num_found = 0, i = 0; i < INA226_MAX_ADDRESSES; i++) { // Skip uninstalled sensors - if (!slaveInfo[i].present) + if (!Ina226Info[i].present) continue; num_found++;