diff --git a/etc/sensors.conf.eg b/etc/sensors.conf.eg index 598517f7..d7b5152c 100644 --- a/etc/sensors.conf.eg +++ b/etc/sensors.conf.eg @@ -93,6 +93,10 @@ # translated to a /proc value. '@' is the value to operate on. You may # refer to other readable features (like '2 * vid'). # +# The following operators are valid: + - * / ( ) ^ ` +# ^ is e**x and ` is ln(x) (valid in library version 1.4.0 / +# lm_sensors 2.7.1 or higher) +# # Like for the label statement, there are logical groups here. They are # sometimes a bit different, though. For example, fan1_div is in the # logical label group of fan1 (it gets the same label if none is declared @@ -1374,7 +1378,6 @@ chip "adm1021-*" "adm1023-*" "max1617-*" "max1617a-*" "thmc10-*" "lm84-*" "gl523 chip "vt1211-*" "vt8231-*" # # temp1 and in6 are not implemented in vt1211 / vt8231 -# temp4-7 (thermistor) cacluations unimplemented here - requires logarithms :( # # 1 for temp, 0 for volt. # Sensor Voltage Mode Temp Mode config bit @@ -1451,15 +1454,33 @@ chip "vt1211-*" "vt8231-*" # compute temp1 (@ - 65) / 0.9686, (@ * 0.9686) + 65 compute temp3 (@ - 65) / 0.9686, (@ * 0.9686) + 65 +# +# thermistor calculations. +# 3435 is the thermistor beta. +# '^' is the e**x operator; '`' is the ln(x) operator +# (valid in library version 1.4.0 / lm_sensors 2.7.1 or higher) +# This assumes that the thermistor forms a resistor divider with a resistor +# equal to its nominal value @ 25C. If not, the math gets even harder. +# + compute temp2 (1 / (((1 / 3435) * (` ((253 - @) / (@ - 43)))) + (1 / 298.15))) - 273.15, \ + 253 - (210 / (1 + (1 / (^ (((3435 * (25 - @)) / ((@ + 273.15) * 298.15))))))) + compute temp4 (1 / (((1 / 3435) * (` ((253 - @) / (@ - 43)))) + (1 / 298.15))) - 273.15, \ + 253 - (210 / (1 + (1 / (^ (((3435 * (25 - @)) / ((@ + 273.15) * 298.15))))))) + compute temp5 (1 / (((1 / 3435) * (` ((253 - @) / (@ - 43)))) + (1 / 298.15))) - 273.15, \ + 253 - (210 / (1 + (1 / (^ (((3435 * (25 - @)) / ((@ + 273.15) * 298.15))))))) + compute temp6 (1 / (((1 / 3435) * (` ((253 - @) / (@ - 43)))) + (1 / 298.15))) - 273.15, \ + 253 - (210 / (1 + (1 / (^ (((3435 * (25 - @)) / ((@ + 273.15) * 298.15))))))) + compute temp7 (1 / (((1 / 3435) * (` ((253 - @) / (@ - 43)))) + (1 / 298.15))) - 273.15, \ + 253 - (210 / (1 + (1 / (^ (((3435 * (25 - @)) / ((@ + 273.15) * 298.15))))))) # set temp1_hyst 40 # set temp1_over 45 - set temp2_hyst 55 - set temp2_over 60 + set temp2_hyst 40 + set temp2_over 45 set temp3_hyst 60 set temp3_over 65 - set temp4_hyst 60 - set temp4_over 65 + set temp4_hyst 40 + set temp4_over 45 set fan1_min 3000 set fan2_min 3000 diff --git a/lib/Module.mk b/lib/Module.mk index 260337f6..624b9c7d 100644 --- a/lib/Module.mk +++ b/lib/Module.mk @@ -29,7 +29,7 @@ LIBMAN5FILES := $(MODULE_DIR)/sensors.conf.5 # The main and minor version of the library LIBMAINVER := 1 -LIBMINORVER := 3.0 +LIBMINORVER := 4.0 LIBVER := $(LIBMAINVER).$(LIBMINORVER) # The static lib name, the shared lib name, and the internal ('so') name of diff --git a/lib/access.c b/lib/access.c index c51dd468..0de4ac2f 100644 --- a/lib/access.c +++ b/lib/access.c @@ -19,6 +19,7 @@ #include #include +#include #include "access.h" #include "sensors.h" #include "data.h" @@ -395,6 +396,14 @@ int sensors_eval_expr(sensors_chip_name chipname, const sensors_expr *expr, case sensors_negate: *result = -res1; return 0; + case sensors_exp: + *result = exp(res1); + return 0; + case sensors_log: + if (res1 < 0.0) + return -SENSORS_ERR_DIV_ZERO; + *result = log(res1); + return 0; } return 0; } diff --git a/lib/conf-lex.l b/lib/conf-lex.l index 5b6e89a3..f32451a1 100644 --- a/lib/conf-lex.l +++ b/lib/conf-lex.l @@ -178,6 +178,12 @@ OCTESC (1[0-7]{0,2})|([2-7][0-7]?)|(0[1-7][0-7]?)|(00[1-7]) "@" { return '@'; } +"^" { + return '^'; + } +"`" { + return '`'; + } /* Quoted string */ \" { diff --git a/lib/conf-parse.y b/lib/conf-parse.y index 13888f47..0e35e6d1 100644 --- a/lib/conf-parse.y +++ b/lib/conf-parse.y @@ -102,6 +102,7 @@ static sensors_chip *current_chip = NULL; %left '-' '+' %left '*' '/' %left NEG +%right '^' '`' %token ',' %token EOL @@ -272,6 +273,20 @@ expression: FLOAT } | '(' expression ')' { $$ = $2; } + | '^' expression + { $$ = malloc_expr(); + $$->kind = sensors_kind_sub; + $$->data.subexpr.op = sensors_exp; + $$->data.subexpr.sub1 = $2; + $$->data.subexpr.sub2 = NULL; + } + | '`' expression + { $$ = malloc_expr(); + $$->kind = sensors_kind_sub; + $$->data.subexpr.op = sensors_log; + $$->data.subexpr.sub1 = $2; + $$->data.subexpr.sub2 = NULL; + } ; i2cbus_name: NAME diff --git a/lib/data.h b/lib/data.h index a220ed37..65aeb6eb 100644 --- a/lib/data.h +++ b/lib/data.h @@ -29,7 +29,7 @@ /* Kinds of expression operators recognized */ typedef enum sensors_operation { sensors_add, sensors_sub, sensors_multiply, sensors_divide, - sensors_negate } sensors_operation; + sensors_negate, sensors_exp, sensors_log } sensors_operation; /* An expression can have several forms */ typedef enum sensors_expr_kind {