@@ -112,15 +112,15 @@ void INA_Class::readInafromEEPROM(const uint8_t deviceNumber) {
112
112
@param[in] deviceNumber Index to device array */
113
113
if (deviceNumber == _currentINA || deviceNumber > _DeviceCount) return ; // Skip if correct device
114
114
#if defined(__AVR__) || defined(CORE_TEENSY) || defined(ESP32) || defined(ESP8266) || (__STM32F1__)
115
- #ifdef __STM32F1__ // STM32F1 has no built-in EEPROM
116
- uint16_t e = deviceNumber * sizeof (inaEE); // it uses flash memory to emulate
117
- uint16_t *ptr = (uint16_t *)&inaEE; // "EEPROM" calls are uint16_t type
118
- for (uint8_t n = sizeof (inaEE); n; --n) // Implement EEPROM.get template
115
+ #ifdef __STM32F1__ // STM32F1 has no built-in EEPROM
116
+ uint16_t e = deviceNumber * sizeof (inaEE); // it uses flash memory to emulate
117
+ uint16_t *ptr = (uint16_t *)&inaEE; // "EEPROM" calls are uint16_t type
118
+ for (uint8_t n = sizeof (inaEE) + _EEPROM_offset ; n; --n) // Implement EEPROM.get template
119
119
{
120
120
EEPROM.read (e++, ptr++); // for ina (inaDet type)
121
121
} // of for-next each byte
122
122
#else
123
- EEPROM.get (deviceNumber * sizeof (inaEE), inaEE); // Read EEPROM values to structure
123
+ EEPROM.get (_EEPROM_offset + ( deviceNumber * sizeof (inaEE)) , inaEE); // Read EEPROM values
124
124
#endif
125
125
#else
126
126
inaEE = _EEPROMEmulation[deviceNumber];
@@ -135,17 +135,17 @@ void INA_Class::writeInatoEEPROM(const uint8_t deviceNumber) {
135
135
@param[in] deviceNumber Index to device array */
136
136
inaEE = ina; // only save relevant part of ina to EEPROM
137
137
#if defined(__AVR__) || defined(CORE_TEENSY) || defined(ESP32) || defined(ESP8266) || (__STM32F1__)
138
- #ifdef __STM32F1__ // STM32F1 has no built-in EEPROM
139
- uint16_t e = deviceNumber * sizeof (inaEE); // it uses flash memory to emulate
140
- const uint16_t *ptr = (const uint16_t *)&inaEE; // "EEPROM" calls are uint16_t type
141
- for (uint8_t n = sizeof (inaEE); n; --n) // Implement EEPROM.put template
138
+ #ifdef __STM32F1__ // STM32F1 has no built-in EEPROM
139
+ uint16_t e = deviceNumber * sizeof (inaEE); // it uses flash memory to emulate
140
+ const uint16_t *ptr = (const uint16_t *)&inaEE; // "EEPROM" calls are uint16_t type
141
+ for (uint8_t n = sizeof (inaEE) + _EEPROM_offset ; n; --n) // Implement EEPROM.put template
142
142
{
143
143
EEPROM.update (e++, *ptr++); // for ina (inaDet type)
144
144
} // for-next
145
145
#else
146
- EEPROM.put (deviceNumber * sizeof (inaEE), inaEE); // Write the structure
146
+ EEPROM.put (_EEPROM_offset + ( deviceNumber * sizeof (inaEE) ), inaEE); // Write the structure
147
147
#ifdef ESP32
148
- EEPROM.commit (); // Force write to EEPROM when ESP32
148
+ EEPROM.commit (); // Force write to EEPROM when ESP32
149
149
#endif
150
150
#endif
151
151
#else
@@ -189,14 +189,14 @@ uint8_t INA_Class::begin(const uint16_t maxBusAmps, const uint32_t microOhmR,
189
189
** RAM available at runtime to allocate sufficient space for 32 devices. **
190
190
**********************************************************************************************/
191
191
#if defined(ESP32) || defined(ESP8266)
192
- EEPROM.begin (512 ); // If ESP32 then allocate 512 Bytes
193
- maxDevices = 512 / sizeof (inaEE); // and compute number of devices
194
- #elif defined(__STM32F1__) // Emulated EEPROM for STM32F1
195
- maxDevices = EEPROM.maxcount () / sizeof (inaEE); // Compute number devices possible
196
- #elif defined(CORE_TEENSY) // TEENSY doesn't have EEPROM.length
197
- maxDevices = 2048 / sizeof (inaEE); // defined, so use 2Kb as value
192
+ EEPROM.begin (512 ); // If ESP32 then allocate 512 Bytes
193
+ maxDevices = (_EEPROM_offset + 512 ) / sizeof (inaEE); // and compute number of devices
194
+ #elif defined(__STM32F1__) // Emulated EEPROM for STM32F1
195
+ maxDevices = (_EEPROM_offset + EEPROM.maxcount ()) / sizeof (inaEE); // Compute max possible
196
+ #elif defined(CORE_TEENSY) // TEENSY doesn't have EEPROM.length
197
+ maxDevices = (_EEPROM_offset + 2048 ) / sizeof (inaEE); // defined, so use 2Kb as value
198
198
#elif defined(__AVR__)
199
- maxDevices = EEPROM.length () / sizeof (inaEE); // Compute number devices possible
199
+ maxDevices = (_EEPROM_offset + EEPROM.length ()) / sizeof (inaEE); // Compute max possible
200
200
#else
201
201
maxDevices = 32 ;
202
202
#endif
@@ -604,9 +604,11 @@ int32_t INA_Class::getBusMicroAmps(const uint8_t deviceNumber) {
604
604
if (ina.type == INA3221_0 || ina.type == INA3221_1 ||
605
605
ina.type == INA3221_2) // Doesn't compute Amps
606
606
{
607
- microAmps = getShuntMicroVolts (deviceNumber) * ((int32_t )1000000 / (int32_t )ina.microOhmR );
607
+ microAmps =
608
+ (int64_t )getShuntMicroVolts (deviceNumber) * ((int64_t )1000000 / (int64_t )ina.microOhmR );
608
609
} else {
609
- microAmps = (int64_t )readWord (ina.currentRegister , ina.address ) * ina.current_LSB / 1000 ;
610
+ microAmps = (int64_t )readWord (ina.currentRegister , ina.address ) * (int64_t )ina.current_LSB /
611
+ (int64_t )1000 ;
610
612
} // of if-then-else an INA3221
611
613
return (microAmps);
612
614
} // of method getBusMicroAmps()
@@ -623,10 +625,12 @@ int64_t INA_Class::getBusMicroWatts(const uint8_t deviceNumber) {
623
625
if (ina.type == INA3221_0 || ina.type == INA3221_1 ||
624
626
ina.type == INA3221_2) // Doesn't compute Amps
625
627
{
626
- microWatts = (getShuntMicroVolts (deviceNumber) * 1000000 / ina.microOhmR ) *
627
- getBusMilliVolts (deviceNumber) / 1000 ;
628
+ microWatts =
629
+ ((int64_t )getShuntMicroVolts (deviceNumber) * (int64_t )1000000 / (int64_t )ina.microOhmR ) *
630
+ (int64_t )getBusMilliVolts (deviceNumber) / (int64_t )1000 ;
628
631
} else {
629
- microWatts = (int64_t )readWord (INA_POWER_REGISTER, ina.address ) * ina.power_LSB / 1000 ;
632
+ microWatts =
633
+ (int64_t )readWord (INA_POWER_REGISTER, ina.address ) * (int64_t )ina.power_LSB / (int64_t )1000 ;
630
634
} // of if-then-else an INA3221
631
635
return (microWatts);
632
636
} // of method getBusMicroWatts()
0 commit comments