Skip to content

Commit 2212448

Browse files
committed
auterion pm: set max current based on eeprom
1 parent e2e8b12 commit 2212448

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/drivers/power_monitor/pm_selector_auterion/PowerMonitorSelectorAuterion.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ void PowerMonitorSelectorAuterion::try_eeprom_start()
9696
EepromBlockPm eeprom_block_pm = _eeprom_blocks_pm[ii];
9797

9898
uint16_t dev_type = eeprom_block_pm.dev_type;
99+
set_max_current(dev_type, eeprom_block_pm.max_current);
99100
set_shunt_value(dev_type, eeprom_block_pm.shunt_value);
100101
int ret_val = start_pm(_buses[i].bus_number, dev_type, eeprom_block_pm.i2c_addr, _buses[i].id);
101102

@@ -368,6 +369,19 @@ bool PowerMonitorSelectorAuterion::is_user_configured(const uint16_t dev_type) c
368369
return sens_en != 0;
369370
}
370371

372+
void PowerMonitorSelectorAuterion::set_max_current(const uint16_t dev_type, const float max_current) const
373+
{
374+
const char *ina_type = get_ina_type(dev_type);
375+
376+
if (ina_type == nullptr) {
377+
return;
378+
}
379+
380+
char param_name[PARAM_MAX_LEN];
381+
snprintf(param_name, sizeof(param_name), "INA%s_CURRENT", ina_type);
382+
set_float_param(param_name, max_current);
383+
}
384+
371385
void PowerMonitorSelectorAuterion::set_shunt_value(const uint16_t dev_type, const float shunt_value) const
372386
{
373387
const char *ina_type = get_ina_type(dev_type);
@@ -378,12 +392,16 @@ void PowerMonitorSelectorAuterion::set_shunt_value(const uint16_t dev_type, cons
378392

379393
char param_name[PARAM_MAX_LEN];
380394
snprintf(param_name, sizeof(param_name), "INA%s_SHUNT", ina_type);
395+
set_float_param(param_name, shunt_value);
396+
}
381397

382-
float current_shunt_value = 0;
383-
param_get(param_find(param_name), &current_shunt_value);
398+
void PowerMonitorSelectorAuterion::set_float_param(const char *param_name, const float param_val) const
399+
{
400+
float current_param_value = 0;
401+
param_get(param_find(param_name), &current_param_value);
384402

385-
if (fabsf(current_shunt_value - shunt_value) > FLT_EPSILON) {
386-
param_set(param_find(param_name), &(shunt_value));
403+
if (fabsf(current_param_value - param_val) > FLT_EPSILON) {
404+
param_set(param_find(param_name), &(param_val));
387405
}
388406
}
389407

src/drivers/power_monitor/pm_selector_auterion/PowerMonitorSelectorAuterion.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ class PowerMonitorSelectorAuterion : public ModuleBase<PowerMonitorSelectorAuter
160160
const char *get_start_command(const uint16_t dev_type) const;
161161

162162
bool is_user_configured(const uint16_t dev_type) const;
163+
void set_max_current(const uint16_t dev_type, const float max_current) const;
163164
void set_shunt_value(const uint16_t dev_type, const float shunt_value) const;
165+
void set_float_param(const char *param_name, const float param_val) const;
164166
const char *get_ina_type(const uint16_t dev_type) const;
165167
uint16_t crc16_update(const uint16_t current_crc, const uint8_t *data_p, size_t length) const;
166168

0 commit comments

Comments
 (0)