mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-29 13:46:37 +00:00
BLM certify part 1
This commit is contained in:
parent
2af506e48b
commit
4e3b547657
@ -26,7 +26,7 @@
|
|||||||
* 2. Configure the module to use I2C on the correct pins.
|
* 2. Configure the module to use I2C on the correct pins.
|
||||||
* 3. Connect your ina226 module(s) to the I2C 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.
|
* 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
|
* 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
|
* 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.
|
* 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.
|
* 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:
|
* It will map device numbers as follows:
|
||||||
*
|
*
|
||||||
* Device number to I2C slave address mapping
|
* Device number to I2C address mapping
|
||||||
*
|
*
|
||||||
* 1 - 0x40
|
* 1 - 0x40
|
||||||
* 2 - 0x41
|
* 2 - 0x41
|
||||||
@ -59,7 +59,7 @@
|
|||||||
*
|
*
|
||||||
* Other commands
|
* 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
|
* Sensor54 2 Save the configuration and restart
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
@ -88,13 +88,13 @@
|
|||||||
#define INA226_REG_CALIBRATION (0x05)
|
#define INA226_REG_CALIBRATION (0x05)
|
||||||
|
|
||||||
|
|
||||||
typedef struct Ina226SlaveInfo_tag {
|
typedef struct Ina226Info_tag {
|
||||||
uint8_t address;
|
uint8_t address;
|
||||||
uint16_t calibrationValue;
|
uint16_t calibrationValue;
|
||||||
uint16_t config;
|
uint16_t config;
|
||||||
uint8_t present : 1;
|
uint8_t present : 1;
|
||||||
float i_lsb;
|
float i_lsb;
|
||||||
} Ina226SlaveInfo_t;
|
} Ina226Info_t;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Program memory constants
|
* Program memory constants
|
||||||
@ -108,9 +108,9 @@ static const uint8_t PROGMEM probeAddresses[INA226_MAX_ADDRESSES] = {INA226_ADDR
|
|||||||
|
|
||||||
|
|
||||||
static char Ina226Str[] = "INA226";
|
static char Ina226Str[] = "INA226";
|
||||||
static uint8_t slavesFound = 0;
|
static uint8_t Ina226sFound = 0;
|
||||||
static uint8_t schedule_reinit = 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 uint16_t reinit_count[4];
|
||||||
static float voltages[4];
|
static float voltages[4];
|
||||||
static float currents[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
|
* 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);
|
I2cWrite16( si->address, INA226_REG_CALIBRATION, si->calibrationValue);
|
||||||
|
|
||||||
@ -167,10 +167,10 @@ bool Ina226TestPresence(uint8_t device)
|
|||||||
|
|
||||||
// Read config
|
// 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);
|
//AddLog_P2( LOG_LEVEL_NONE, PSTR("Config register %04x" ), config);
|
||||||
|
|
||||||
if (config != slaveInfo[device].config)
|
if (config != Ina226Info[device].config)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -179,10 +179,10 @@ bool Ina226TestPresence(uint8_t device)
|
|||||||
|
|
||||||
void Ina226ResetActive(void)
|
void Ina226ResetActive(void)
|
||||||
{
|
{
|
||||||
Ina226SlaveInfo_t *p = slaveInfo;
|
Ina226Info_t *p = Ina226Info;
|
||||||
|
|
||||||
for (uint32_t i = 0; i < INA226_MAX_ADDRESSES; i++) {
|
for (uint32_t i = 0; i < INA226_MAX_ADDRESSES; i++) {
|
||||||
p = &slaveInfo[i];
|
p = &Ina226Info[i];
|
||||||
// Address
|
// Address
|
||||||
uint8_t addr = p->address;
|
uint8_t addr = p->address;
|
||||||
if (addr) {
|
if (addr) {
|
||||||
@ -199,9 +199,9 @@ void Ina226Init()
|
|||||||
{
|
{
|
||||||
uint32_t i;
|
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, "Ina226Init");
|
||||||
// AddLog_P2( LOG_LEVEL_NONE, "Size of Settings: %d bytes", sizeof(Settings));
|
// 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");
|
// 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++){
|
for (i = 0; i < 4; i++){
|
||||||
*p = {0};
|
*p = {0};
|
||||||
@ -232,7 +232,7 @@ void Ina226Init()
|
|||||||
continue;
|
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
|
// Try Resetting the device
|
||||||
|
|
||||||
@ -257,8 +257,8 @@ void Ina226Init()
|
|||||||
if (!I2cWrite16( addr, INA226_REG_CONFIG, config))
|
if (!I2cWrite16( addr, INA226_REG_CONFIG, config))
|
||||||
continue; // No device
|
continue; // No device
|
||||||
|
|
||||||
// store data in slave info struct.
|
// store data in info struct.
|
||||||
p = &slaveInfo[i];
|
p = &Ina226Info[i];
|
||||||
// Address
|
// Address
|
||||||
p->address = addr;
|
p->address = addr;
|
||||||
// Configuration
|
// Configuration
|
||||||
@ -282,7 +282,7 @@ void Ina226Init()
|
|||||||
|
|
||||||
I2cSetActiveFound(addr, Ina226Str);
|
I2cSetActiveFound(addr, Ina226Str);
|
||||||
|
|
||||||
slavesFound++;
|
Ina226sFound++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -292,7 +292,7 @@ void Ina226Init()
|
|||||||
|
|
||||||
float Ina226ReadBus_v(uint8_t device)
|
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);
|
int16_t reg_bus_v = I2cReadS16( addr, INA226_REG_BUSVOLTAGE);
|
||||||
|
|
||||||
float result = ((float) reg_bus_v) * 0.00125f;
|
float result = ((float) reg_bus_v) * 0.00125f;
|
||||||
@ -307,10 +307,10 @@ float Ina226ReadBus_v(uint8_t device)
|
|||||||
|
|
||||||
float Ina226ReadShunt_i(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);
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
@ -321,10 +321,10 @@ float Ina226ReadShunt_i(uint8_t device)
|
|||||||
|
|
||||||
float Ina226ReadPower_w(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);
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
@ -354,19 +354,19 @@ void Ina226EverySecond()
|
|||||||
{
|
{
|
||||||
//AddLog_P2( LOG_LEVEL_NONE, "Ina226EverySecond");
|
//AddLog_P2( LOG_LEVEL_NONE, "Ina226EverySecond");
|
||||||
for (uint8_t device = 0; device < INA226_MAX_ADDRESSES; device++){
|
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 there are Ina226s, and the device was present, and the device still is present, read its registers
|
||||||
if (slavesFound && slaveInfo[device].present && Ina226TestPresence(device)){
|
if (Ina226sFound && Ina226Info[device].present && Ina226TestPresence(device)){
|
||||||
Ina226Read(device);
|
Ina226Read(device);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
powers[device] = currents[device] = voltages[device] = 0.0f;
|
powers[device] = currents[device] = voltages[device] = 0.0f;
|
||||||
// If device was present, note that it dropped off here
|
// If device was present, note that it dropped off here
|
||||||
//if(slaveInfo[device].present){
|
//if(Ina226Info[device].present){
|
||||||
//reinit_count[device]++;
|
//reinit_count[device]++;
|
||||||
//AddLog_P2( LOG_LEVEL_DEBUG, "INA226 Device %d dropped off, count: %d", device, reinit_count[device]);
|
//AddLog_P2( LOG_LEVEL_DEBUG, "INA226 Device %d dropped off, count: %d", device, reinit_count[device]);
|
||||||
//}
|
//}
|
||||||
// Device no longer present
|
// Device no longer present
|
||||||
slaveInfo[device].present = false;
|
Ina226Info[device].present = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -413,7 +413,7 @@ bool Ina226CommandSensor()
|
|||||||
case 1: // Rerun init
|
case 1: // Rerun init
|
||||||
Ina226ResetActive();
|
Ina226ResetActive();
|
||||||
Ina226Init();
|
Ina226Init();
|
||||||
Response_P(PSTR("{\"Sensor54-Command-Result\":{\"SlavesFound\":%d}}"),slavesFound);
|
Response_P(PSTR("{\"Sensor54-Command-Result\":{\"Ina226sFound\":%d}}"),Ina226sFound);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2: // Save and restart
|
case 2: // Save and restart
|
||||||
@ -497,7 +497,7 @@ void Ina226Show(bool json)
|
|||||||
int i, num_found;
|
int i, num_found;
|
||||||
for (num_found = 0, i = 0; i < INA226_MAX_ADDRESSES; i++) {
|
for (num_found = 0, i = 0; i < INA226_MAX_ADDRESSES; i++) {
|
||||||
// Skip uninstalled sensors
|
// Skip uninstalled sensors
|
||||||
if (!slaveInfo[i].present)
|
if (!Ina226Info[i].present)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
num_found++;
|
num_found++;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user