mirror of
https://github.com/lm-sensors/lm-sensors.git
synced 2026-11-23 20:11:42 +00:00
Expanded expressions, slightly new syntax
An expression can now refer to the value it has to compute (@), but also to other values. This is now perfectly valid as an expression: vid + in_min - in_max * 2 / @ Not that this is very sensible, but you get the idea. Please install the new example config file, or replace all old 'val' occurences with '@'. git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@107 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
1 parent
657798a79c
commit
1c12665831
7 files changed
+40
-18
No files matched your search
+10
-9
@@ -46,7 +46,8 @@ chip "lm78-*" "lm78-j-*" "lm79-*"
|
||||
# A compute line describes how to scale a certain feature. There are
|
||||
# two expressions in it: the first describes how the /proc value must
|
||||
# be translated to a user value, the second how a user value must be
|
||||
# translated to a /proc value. 'val' is the value to operate on.
|
||||
# translated to a /proc value. '@' is the value to operate on. You may
|
||||
# refer to other readable features (like '2 * vid').
|
||||
|
||||
# Like for the label statement, there are logical groups here. They are
|
||||
# sometimes a bit different, though. For example, fan1_div is in the
|
||||
@@ -69,10 +70,10 @@ chip "lm78-*" "lm78-j-*" "lm79-*"
|
||||
# in6 -5.0 100 60 +3.00
|
||||
|
||||
# These would lead to these declarations:
|
||||
# compute in3 ((6.8/10)+1)*val , val/((6.8/10)+1)
|
||||
# compute in4 ((30/10)+1)*val , val/((30/10)+1)
|
||||
# compute in5 -(240/60)*val , -val/(240/60)
|
||||
# compute in6 -(100/60)*val , -val/(100/60)
|
||||
# compute in3 ((6.8/10)+1)*@ , @/((6.8/10)+1)
|
||||
# compute in4 ((30/10)+1)*@ , @/((30/10)+1)
|
||||
# compute in5 -(240/60)*@ , -@/(240/60)
|
||||
# compute in6 -(100/60)*@ , -@/(100/60)
|
||||
|
||||
# On almost any mainboard we have seen, the Winbond compute values lead to
|
||||
# much better results, though.
|
||||
@@ -83,10 +84,10 @@ chip "lm78-*" "lm78-j-*" "lm79-*"
|
||||
# in6 -5.0 90.9 60.4 +3.00
|
||||
|
||||
# These leads to these declarations:
|
||||
compute in3 ((6.8/10)+1)*val , val/((6.8/10)+1)
|
||||
compute in4 ((28/10)+1)*val , val/((28/10)+1)
|
||||
compute in5 -(210/60.4)*val , -val/(210/60.4)
|
||||
compute in6 -(90.9/60.4)*val , -val/(90.9/60.4)
|
||||
compute in3 ((6.8/10)+1)*@ , @/((6.8/10)+1)
|
||||
compute in4 ((28/10)+1)*@ , @/((28/10)+1)
|
||||
compute in5 -(210/60.4)*@ , -@/(210/60.4)
|
||||
compute in6 -(90.9/60.4)*@ , -@/(90.9/60.4)
|
||||
|
||||
# Set statements set things like limits. Complete expressions can be
|
||||
# used. Not everything can sensibly be set: setting 'in0', for example,
|
||||
|
||||
+2
-2
@@ -187,7 +187,7 @@ int sensors_get_feature(sensors_chip_name name, int feature, double *result)
|
||||
return -SENSORS_ERR_PROC;
|
||||
if (! expr)
|
||||
*result = val;
|
||||
else if ((res = sensors_eval_expr(expr,val,result)))
|
||||
else if ((res = sensors_eval_expr(name,expr,val,result)))
|
||||
return res;
|
||||
return 0;
|
||||
}
|
||||
@@ -213,7 +213,7 @@ int sensors_set_feature(sensors_chip_name name, int feature, double value)
|
||||
if (!strcmp(featureptr->name,chip->computes->name))
|
||||
expr = chip->computes->to_proc;
|
||||
if (expr)
|
||||
if ((res = sensors_eval_expr(expr,value,&value)))
|
||||
if ((res = sensors_eval_expr(name,expr,value,&value)))
|
||||
return res;
|
||||
if (sensors_write_proc(name,feature,value))
|
||||
return -SENSORS_ERR_PROC;
|
||||
|
||||
@@ -170,6 +170,9 @@ OCTESC (1[0-7]{0,2})|([2-7][0-7]?)|(0[1-7][0-7]?)|(00[1-7])
|
||||
<MIDDLE>"," {
|
||||
return ',';
|
||||
}
|
||||
<MIDDLE>"@" {
|
||||
return '@';
|
||||
}
|
||||
|
||||
/* Quoted string */
|
||||
<MIDDLE>\" {
|
||||
|
||||
@@ -211,6 +211,10 @@ expression: FLOAT
|
||||
$$->data.var = $1;
|
||||
$$->kind = sensors_kind_var;
|
||||
}
|
||||
| '@'
|
||||
{ $$ = malloc_expr();
|
||||
$$->kind = sensors_kind_source;
|
||||
}
|
||||
| expression '+' expression
|
||||
{ $$ = malloc_expr();
|
||||
$$->kind = sensors_kind_sub;
|
||||
|
||||
+16
-5
@@ -23,6 +23,7 @@
|
||||
#include "error.h"
|
||||
#include "data.h"
|
||||
#include "sensors.h"
|
||||
#include "access.h"
|
||||
|
||||
sensors_chip *sensors_config_chips = NULL;
|
||||
int sensors_config_chips_count = 0;
|
||||
@@ -200,24 +201,34 @@ int sensors_parse_i2cbus_name(const char *name, int *res)
|
||||
}
|
||||
|
||||
|
||||
int sensors_eval_expr(sensors_expr *expr, double val, double *result)
|
||||
int sensors_eval_expr(sensors_chip_name chipname, sensors_expr *expr,
|
||||
double val, double *result)
|
||||
{
|
||||
double res1,res2;
|
||||
int res;
|
||||
sensors_chip_feature *feature;
|
||||
|
||||
if (expr->kind == sensors_kind_val) {
|
||||
*result = expr->data.val;
|
||||
return 0;
|
||||
}
|
||||
if (expr->kind == sensors_kind_var) {
|
||||
/* We should check the kind of variable here! */
|
||||
if (expr->kind == sensors_kind_source) {
|
||||
*result = val;
|
||||
return 0;
|
||||
}
|
||||
if ((res = sensors_eval_expr(expr->data.subexpr.sub1,val,&res1)))
|
||||
if (expr->kind == sensors_kind_var) {
|
||||
/* We should check the kind of variable here! */
|
||||
if (! (feature = sensors_lookup_feature_name(chipname.prefix,
|
||||
expr->data.var)))
|
||||
return SENSORS_ERR_NO_ENTRY;
|
||||
if (! (res = sensors_get_feature(chipname,feature->number,result)))
|
||||
return res;
|
||||
return 0;
|
||||
}
|
||||
if ((res = sensors_eval_expr(chipname,expr->data.subexpr.sub1,val,&res1)))
|
||||
return res;
|
||||
if (expr->data.subexpr.sub2 &&
|
||||
(res = sensors_eval_expr(expr->data.subexpr.sub2,val,&res2)))
|
||||
(res = sensors_eval_expr(chipname,expr->data.subexpr.sub2,val,&res2)))
|
||||
return res;
|
||||
switch(expr->data.subexpr.op) {
|
||||
case sensors_add:
|
||||
|
||||
+4
-2
@@ -31,7 +31,8 @@ typedef enum sensors_operation {
|
||||
sensors_negate } sensors_operation;
|
||||
|
||||
typedef enum sensors_expr_kind {
|
||||
sensors_kind_val, sensors_kind_var, sensors_kind_sub } sensors_expr_kind;
|
||||
sensors_kind_val, sensors_kind_source, sensors_kind_var,
|
||||
sensors_kind_sub } sensors_expr_kind;
|
||||
|
||||
struct sensors_expr;
|
||||
|
||||
@@ -126,7 +127,8 @@ extern int sensors_proc_bus_max;
|
||||
error.h on failure. */
|
||||
extern int sensors_parse_i2cbus_name(const char *name, int *res);
|
||||
|
||||
extern int sensors_eval_expr(sensors_expr *expr, double val, double *result);
|
||||
extern int sensors_eval_expr(sensors_chip_name chipname, sensors_expr *expr,
|
||||
double val, double *result);
|
||||
|
||||
|
||||
#endif /* def LIB_SENSORS_DATA_H */
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "data.h"
|
||||
#include "proc.h"
|
||||
#include "error.h"
|
||||
#include "access.h"
|
||||
|
||||
extern int sensors_yyparse(void);
|
||||
extern FILE *sensors_yyin;
|
||||
|
||||
Reference in new issue
Block a user