Skip to content

Commit

Permalink
Add CONFigure:FANx:HYSteresis command (#2)
Browse files Browse the repository at this point in the history
Allows user to change the hysteresis of a given fan to limit the
amount of INFO lines sent to LOG and/or SYSLOG.
  • Loading branch information
Zitt authored Aug 10, 2024
1 parent 10327bd commit 87b1d5e
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 1 deletion.
19 changes: 19 additions & 0 deletions commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Fanpico supports following commands:
* [CONFigure:DELete](#configuredelete)
* [CONFigure:FANx:NAME](#configurefanxname)
* [CONFigure:FANx:NAME?](#configurefanxname-1)
* [CONFigure:FANx:HYSteresis](#CONFigure:FANx:HYSteresis)
* [CONFigure:FANx:HYSteresis?](#CONFigure:FANx:HYSteresis-1)
* [CONFigure:FANx:MINpwm](#configurefanxminpwm)
* [CONFigure:FANx:MINpwm?](#configurefanxminpwm-1)
* [CONFigure:FANx:MAXpwm](#configurefanxmaxpwm)
Expand Down Expand Up @@ -324,6 +326,23 @@ CONF:FAN1:NAME?
CPU Fan 1
```

#### CONFigure:FANx:HYSteresis
Set the hysteresis threshold for a given fan (output) port.

For example:
```
CONF:FAN1:HYSteresis 2.0
```

#### CONFigure:FANx:HYSteresis?
Query the hysteresis threshold for a given fan (output) port.

For example:
```
CONF:FAN8:HYSteresis?
CONF:FAN8:HYS=1.000000
```

#### CONFigure:FANx:MINpwm
Set absolute minimum PWM duty cycle (%) for given fan port.
This can be used to make sure that fan always sees a minimum
Expand Down
26 changes: 26 additions & 0 deletions src/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,31 @@ int cmd_fan_source(const char *cmd, const char *args, int query, char *prev_cmd)
return ret;
}

int cmd_fan_info_hys(const char *cmd, const char *args, int query, char *prev_cmd)
{
int fan;
float val;

fan = atoi(&prev_cmd[3]) - 1;
if (fan >= 0 && fan < FAN_COUNT) {
if (query) {
printf("CONF:FAN%d:HYS=%f\n", fan+1, conf->fans[fan].info_hyst);
} else if (str_to_float(args, &val)) {
if (val >= 0.0) {
log_msg(LOG_NOTICE, "fan%d: change Hysteresis %f --> %f",
fan + 1, conf->fans[fan].info_hyst, val);
conf->fans[fan].info_hyst = val;
} else {
log_msg(LOG_WARNING, "fan%d: invalid new value for Hysteresis: %f",
fan + 1, val);
return 2;
}
}
return 0;
}
return 1;
}

int cmd_fan_rpm(const char *cmd, const char *args, int query, char *prev_cmd)
{
int fan;
Expand Down Expand Up @@ -2692,6 +2717,7 @@ const struct cmd_t fan_c_commands[] = {
{ "RPMFactor", 4, NULL, cmd_fan_rpm_factor },
{ "RPMMOde", 5, NULL, cmd_fan_rpm_mode },
{ "SOUrce", 3, NULL, cmd_fan_source },
{ "HYSteresis",3, NULL, cmd_fan_info_hys },
{ 0, 0, 0, 0 }
};

Expand Down
4 changes: 4 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ void clear_config(struct fanpico_config *cfg)
f->rpm_factor = 2;
f->filter = FILTER_NONE;
f->filter_ctx = NULL;
f->info_hyst = FAN_INFO_HYSTERESIS;
}

for (i = 0; i < MBFAN_MAX_COUNT; i++) {
Expand Down Expand Up @@ -744,6 +745,7 @@ cJSON *config_to_json(const struct fanpico_config *cfg)
cJSON_AddItemToObject(o, "rpm_factor", cJSON_CreateNumber(f->rpm_factor));
cJSON_AddItemToObject(o, "lra_low", cJSON_CreateNumber(f->lra_low));
cJSON_AddItemToObject(o, "lra_high", cJSON_CreateNumber(f->lra_high));
cJSON_AddItemToObject(o, "hysteresis", cJSON_CreateNumber(f->info_hyst));
cJSON_AddItemToArray(fans, o);
}
cJSON_AddItemToObject(config, "fans", fans);
Expand Down Expand Up @@ -1092,6 +1094,8 @@ int json_to_config(cJSON *config, struct fanpico_config *cfg)
f->lra_high = cJSON_GetNumberValue(r);
if ((r = cJSON_GetObjectItem(item, "filter")))
json2filter(r, &f->filter, &f->filter_ctx);
if ((r = cJSON_GetObjectItem(item, "hysteresis")))
f->info_hyst = cJSON_GetNumberValue(r);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/fanpico.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#define SENSOR_SERIES_RESISTANCE 10000.0

#define ADC_REF_VOLTAGE 3.0
#define FAN_INFO_HYSTERESIS 1.0
#define ADC_MAX_VALUE (1 << 12)
#define ADC_AVG_WINDOW 10

Expand Down Expand Up @@ -138,6 +139,7 @@ struct temp_map {

struct fan_output {
char name[MAX_NAME_LEN];
float info_hyst;

/* output PWM signal settings */
uint8_t min_pwm;
Expand Down
3 changes: 2 additions & 1 deletion src/tacho.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,9 @@ void read_tacho_inputs()
void update_tacho_input_freq(struct fanpico_state *st)
{
for (int i = 0; i < FAN_COUNT; i++) {
float hyst = cfg->fans[i].info_hyst;
st->fan_freq[i] = roundf(fan_tacho_freq[i]*100)/100.0;
if (check_for_change(st->fan_freq_prev[i], st->fan_freq[i], 1.0)) {
if (check_for_change(st->fan_freq_prev[i], st->fan_freq[i], hyst)) {
log_msg(LOG_INFO, "fan%d: Input Tacho change %.2fHz --> %.2fHz",
i+1,
st->fan_freq_prev[i],
Expand Down

0 comments on commit 87b1d5e

Please # to comment.