Skip to content

Commit

Permalink
Add support for mixing sensors and vsensors as source for VSENSOR. (#78)
Browse files Browse the repository at this point in the history
* Add support for mixing SENSORS/VSENSORS as source for VSENSOR.
* Update pico-lfs library.
  • Loading branch information
tjko committed Feb 27, 2024
1 parent 095bc60 commit a05ebad
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
10 changes: 7 additions & 3 deletions commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,10 @@ DELTA|Temperature delta between to source sensors|2|sensor_a, sensor_b
Note, in "manual" mode if timeout_ms is set to zero, then sensor's temperature reading
will never revert back to default value (if no updates are being received).

Sensor numbering:
- SENSORS: 1, 2, ...
- VSENSORS: 101, 102, ...


Defaults:

Expand All @@ -1003,14 +1007,14 @@ Example: Set VSENSOR1 to report temperature that is updated by external program.
CONF:VSENSOR2:SOURCE manual,99,5
```

Example: Set VSENSOR2 to follow report temperature delta between SENSOR1 and SENSOR2.
Example: Set VSENSOR2 to follow report temperature delta between SENSOR1 and SENSOR2.
```
CONF:VSENSOR2:SOURCE delta,1,2
```

Example: Set VSENSOR3 to report average temperature between SENSOR1 through SENSOR3.
Example: Set VSENSOR3 to report average temperature between SENSOR1, SENSOR2, and VSENSOR1
```
CONF:VSENSOR3:SOURCE avg,1,2,3
CONF:VSENSOR3:SOURCE avg,1,2,101
```

#### CONFigure:VSENSORx:SOUrce?
Expand Down
2 changes: 1 addition & 1 deletion libs/pico-lfs
Submodule pico-lfs updated 1 files
+4 −1 README.md
11 changes: 6 additions & 5 deletions src/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -1510,7 +1510,7 @@ int cmd_vsensor_name(const char *cmd, const char *args, int query, char *prev_cm
int cmd_vsensor_source(const char *cmd, const char *args, int query, char *prev_cmd)
{
int sensor, val, i;
uint8_t vsmode, selected[SENSOR_MAX_COUNT];
uint8_t vsmode, selected[VSENSOR_SOURCE_MAX_COUNT];
float default_temp;
int timeout;
char *tok, *saveptr, *param, temp_str[32], tmp[8];
Expand All @@ -1529,7 +1529,7 @@ int cmd_vsensor_source(const char *cmd, const char *args, int query, char *prev_
conf->vsensors[sensor].default_temp,
conf->vsensors[sensor].timeout);
} else {
for(i = 0; i < SENSOR_COUNT; i++) {
for(i = 0; i < VSENSOR_SOURCE_MAX_COUNT; i++) {
if (conf->vsensors[sensor].sensors[i]) {
printf(",%d", conf->vsensors[sensor].sensors[i]);
}
Expand Down Expand Up @@ -1563,11 +1563,12 @@ int cmd_vsensor_source(const char *cmd, const char *args, int query, char *prev_
}
} else {
temp_str[0] = 0;
for(i = 0; i < SENSOR_MAX_COUNT; i++)
for(i = 0; i < VSENSOR_SOURCE_MAX_COUNT; i++)
selected[i] = 0;
while((tok = strtok_r(NULL, ",", &saveptr)) != NULL) {
if (count < SENSOR_MAX_COUNT && str_to_int(tok, &val, 10)) {
if (val >= 1 && val <= SENSOR_COUNT) {
if (count < VSENSOR_SOURCE_MAX_COUNT && str_to_int(tok, &val, 10)) {
if ((val >= 1 && val <= SENSOR_COUNT)
|| (val >= 101 && val <= 100 + VSENSOR_COUNT)) {
selected[count++] = val;
snprintf(tmp, sizeof(tmp), ",%d", val);
strncatenate(temp_str, tmp, sizeof(temp_str));
Expand Down
3 changes: 2 additions & 1 deletion src/fanpico.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#define SENSOR_MAX_COUNT 3 /* Max number of sensor inputs on the board */
#define VSENSOR_MAX_COUNT 8 /* Max number of virtual sensors */

#define VSENSOR_SOURCE_MAX_COUNT 8
#define VSENSOR_COUNT 8

#define SENSOR_SERIES_RESISTANCE 10000.0
Expand Down Expand Up @@ -178,7 +179,7 @@ struct vsensor_input {
uint8_t mode;
float default_temp;
int32_t timeout;
uint8_t sensors[SENSOR_MAX_COUNT];
uint8_t sensors[VSENSOR_SOURCE_MAX_COUNT];
struct temp_map map;
enum signal_filter_types filter;
void *filter_ctx;
Expand Down
9 changes: 7 additions & 2 deletions src/sensors.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,13 @@ double get_vsensor(uint8_t i, struct fanpico_config *config,
int count = 0;
t = 0.0;

for (int j = 0; j < SENSOR_COUNT && s->sensors[j]; j++) {
float val = state->temp[s->sensors[j] - 1];
for (int j = 0; j < VSENSOR_SOURCE_MAX_COUNT && s->sensors[j]; j++) {
float val;

if (s->sensors[j] > 100)
val = state->vtemp[s->sensors[j] - 101];
else
val = state->temp[s->sensors[j] - 1];
count++;

if (s->mode == VSMODE_MAX) {
Expand Down

0 comments on commit a05ebad

Please sign in to comment.