diff --git a/wmgtemp/ChangeLog b/wmgtemp/ChangeLog index c5e0490..8ea29e8 100644 --- a/wmgtemp/ChangeLog +++ b/wmgtemp/ChangeLog @@ -1,3 +1,9 @@ +2020-06-13 Snow Flurry + + * ChangeLog, configure.ac, Makefile.am, src/envsys.c, src/envsys.h, + src/wmgtemp.c: Remove everything that makes this work on Linux. + This now works with NetBSD using envsys/proplib. + 2017-02-01 Doug Torrance * CREDITS, ChangeLog, README, configure.ac: Bump to version 1.2. diff --git a/wmgtemp/Makefile.am b/wmgtemp/Makefile.am index a41b44d..71493ed 100644 --- a/wmgtemp/Makefile.am +++ b/wmgtemp/Makefile.am @@ -1,9 +1,9 @@ bin_PROGRAMS = wmgtemp wmgtemp_SOURCES = src/wmgtemp.c src/wmgtemp-interface-mask.xbm \ - src/wmgtemp-interface.xpm + src/wmgtemp-interface.xpm src/envsys.c dist_man_MANS = wmgtemp.1 -AM_CFLAGS = $(X11_CFLAGS) $(dockapp_CFLAGS) -LIBS += $(X11_LIBS) $(dockapp_LIBS) +AM_CFLAGS = $(X11_CFLAGS) $(dockapp_CFLAGS) -I/usr/pkg/include +LIBS += $(X11_LIBS) $(dockapp_LIBS) -lprop -L/usr/pkg/lib -Wl,-R/usr/pkg/lib EXTRA_DIST = Artistic BUGS CREDITS examples/wmgtemprc diff --git a/wmgtemp/configure.ac b/wmgtemp/configure.ac index 01cd1cc..b85629a 100644 --- a/wmgtemp/configure.ac +++ b/wmgtemp/configure.ac @@ -1,9 +1,9 @@ -AC_INIT([wmgtemp], [1.2], [wmaker-dev@googlegroups.com]) +AC_INIT([wmgtemp], [1.4], [wmaker-dev@googlegroups.com]) AM_INIT_AUTOMAKE([foreign subdir-objects]) AC_CONFIG_SRCDIR([configure.ac]) AC_PROG_CC -AC_CHECK_LIB([sensors],[sensors_get_features]) PKG_CHECK_MODULES([X11],[x11]) +AC_CHECK_LIB([prop],[prop_bool_create]) PKG_CHECK_MODULES([dockapp],[dockapp]) AC_CONFIG_FILES([Makefile]) AC_OUTPUT diff --git a/wmgtemp/src/wmgtemp.c b/wmgtemp/src/wmgtemp.c index 379917c..4db594e 100644 --- a/wmgtemp/src/wmgtemp.c +++ b/wmgtemp/src/wmgtemp.c @@ -10,16 +10,16 @@ #include #include #include -#include -#include #include #include -#include "wmgtemp-interface.xpm" -#include "wmgtemp-interface-mask.xbm" #include #include #include +#include "wmgtemp-interface.xpm" +#include "wmgtemp-interface-mask.xbm" +#include "envsys.h" + /* Defines */ #define BitOff(a,x) ((void)((a) &= ~(1 << (x)))) #define BitOn(a,x) ((void)((a) |= (1 << (x)))) @@ -51,15 +51,14 @@ #define DEBUG 0 /* 0 disable 1 enable */ -#define OPT_STRING "g:sS:hH:w:m:M:a:e:u:1:2:c:tq" +#define OPT_STRING "g:sS:hH:w:m:M:a:e:u:1:2:tq" -#define TEMPTOFAHRENHEIT(t) ((int)((t * (1.8) + 32))) -#define TEMPTOKELVIN(t) ((int)(t + 273)) -#define TEMPTOCELCIUS(t) (t) +#define TEMPTOFAHRENHEIT(t) ((int)((t * (9.0 / 5.0) - 459.67))) +#define TEMPTOKELVIN(t) ((int)t) +#define TEMPTOCELCIUS(t) ((int)(t - 273.15)) #define TEMPTODISPLAYSCALE(temp, display_flags) (IsOn((display_flags), TSCALE_CELCIUS) ? TEMPTOCELCIUS((temp)) : (IsOn((display_flags), TSCALE_KELVIN) ? TEMPTOKELVIN((temp)) : TEMPTOFAHRENHEIT((temp)))) /* Prototypes */ -int init_sensors(); int process_config(int argc, char **argv); int recompute_range(double cpu_high, double cpu_low, double sys_high, double sys_low); void display_usage(); @@ -82,7 +81,6 @@ void cycle_temptype(); /* Globals */ int delay = 1; -const sensors_chip_name *name; char *exec_app = NULL; char *rc_config = NULL; @@ -110,8 +108,10 @@ double execat = 0; short execed = 0; short swap_types = 0; -char *sensor_feature1 = "temp1"; -char *sensor_feature2 = "temp2"; +const char *cpu_sensor_name = "coretemp0"; +const char *sys_sensor_name = "thinkpad0"; +char *sys_stat_name = NULL; +char *cpu_stat_name = NULL; char *sensor_chip = NULL; short quiet = 0; @@ -121,58 +121,30 @@ int main(int argc, char **argv) { int i = 0; int tmp_swap; - const sensors_feature* feature = NULL; - const sensors_subfeature* subfeature_cpu = NULL; - const sensors_subfeature* subfeature_sys = NULL; - short chip_found = -1; - BitOn(SENSOR_DISP, WARN_NONE); BitOn(SENSOR_DISP, TSCALE_CELCIUS); BitOn(SENSOR_DISP, GRAPH_LINE); - /* *conffname = "/etc/sensors3.conf"; */ - if(!process_config(argc, argv)) { exit(-1); } - if(!init_sensors()) { - exit(-1); - } + /* get cpu and sys stat names */ + cpu_stat_name = get_temp_stat_name(cpu_sensor_name); + sys_stat_name = get_temp_stat_name(sys_sensor_name); + BitOn(SENSOR_DISP, SYS); + BitOn(SENSOR_DISP, CPU); - /* Get the chip name */ - name = sensors_get_detected_chips(NULL, &chip_nr); - while(name != NULL && chip_found == -1) { - if (!sensor_chip || strcmp(name->prefix, (const char *)sensor_chip) == 0) { - i = 0; - while ((feature = sensors_get_features(name, &i))) { - if(strcmp(feature->name, (const char *)sensor_feature1) == 0) { - subfeature_cpu = sensors_get_subfeature(name, feature, SENSORS_SUBFEATURE_TEMP_INPUT); - SUBFEAT_NUM_CPU = subfeature_cpu->number; - BitOn(SENSOR_DISP, CPU); - chip_found = 1; - } - if(strcmp(feature->name, (const char *)sensor_feature2) == 0) { - subfeature_sys = sensors_get_subfeature(name, feature, SENSORS_SUBFEATURE_TEMP_INPUT); - SUBFEAT_NUM_SYS = subfeature_sys->number; - BitOn(SENSOR_DISP, SYS); - chip_found = 1; - } - } - } - - if(chip_found == -1) { - name = sensors_get_detected_chips(NULL, &chip_nr); - } - } - if(chip_found == -1) { + if(cpu_stat_name == NULL || sys_stat_name == NULL) { fprintf(stderr,"wmgtemp: Unable to find temperature sensing feature.\n"); exit(0); } - /* output the name of the sensor if found. */ - if(quiet == 0) - printf("wmgtemp: Primary Sensor - %s on %s\n", name->prefix, sensors_get_adapter_name(&name->bus)); + if (quiet == 0) + printf("wmgtemp: cputemp is %s.%s, systemp is %s.%s\n", cpu_sensor_name, + cpu_stat_name, + sys_sensor_name, + sys_stat_name); if(swap_types) { if(quiet == 0) @@ -430,8 +402,8 @@ void update_sensor_data() { } // Read the new values from the sensors into the temperature arrays. - if(IsOn(SENSOR_DISP, SYS)) sensors_get_value(name, SUBFEAT_NUM_SYS, &sys_history[58]); - if(IsOn(SENSOR_DISP, CPU)) sensors_get_value(name, SUBFEAT_NUM_CPU, &cpu_history[58]); + if(IsOn(SENSOR_DISP, SYS)) sys_history[58] = get_stat_int(sys_sensor_name, sys_stat_name) / 1000000.0; + if(IsOn(SENSOR_DISP, CPU)) cpu_history[58] = get_stat_int(cpu_sensor_name, cpu_stat_name) / 1000000.0; // Update the run high/low values. if(cpu_high > run_cpu_high) @@ -655,40 +627,10 @@ void draw_range_line(double temp, double range, short type) { } -int init_sensors() { - FILE *config_file; - int res; - - if (rc_config) { - config_file = fopen(rc_config, "r"); - - if(config_file == NULL) { - fprintf(stderr, "Error opening %s\n", rc_config); - return 0; - } - } else { - config_file = NULL; /* Use libsensors default */ - } - - res = sensors_init(config_file); - - if(res != 0) { - fprintf(stderr,"Error initializing sensors: %s\n", sensors_strerror(res)); - return 0; - } - - if(config_file && fclose(config_file)) - perror("Error closing sensors config"); - - return 1; -} - void display_usage() { printf("wmgtemp v"PACKAGE_VERSION"\n" \ "Usage: wmgtemp [options]\n" \ "Options:\n" \ - " -S, --sensorconf=PATH Specify sensors config file PATH\n" \ - " [Default: autodetect]\n" \ " -s, --scale=SCALE Display temperatures in SCALE\n" \ " SCALE=kelvin, fahrenheit\n" \ " [Default: celcius]\n" \ @@ -706,11 +648,9 @@ void display_usage() { " -M, --max=TEMP Set upper bound of the graph to TEMP degrees celcius\n" \ " [Default: 35]\n" \ " -1, --feature1=F1 Set the feature for CPU\n" \ - " [Default: temp1]\n" \ + " [Default: coretemp0]\n" \ " -2, --feature2=F2 Set the feature for SYS\n" \ - " [Default: temp2]\n" \ - " -c, --chip=NAME Use sensor chip matching NAME\n" \ - " [Default: use any]\n" \ + " [Default: thinkpad0]\n" \ " -a, --execat=TEMP Execute a command at TEMP degrees celcius\n" \ " -e, --exec=COMMAND Execute COMMAND when 'execat' temperature is reached\n" \ " -t, --swap Swap CPU and SYS temps\n" \ @@ -827,7 +767,6 @@ int process_config(int argc, char **argv) { char *rc_feature1 = NULL; char *rc_feature2 = NULL; char *rc_quiet = NULL; - char *rc_chip = NULL; short parse_ok = 1; int opt_index; int opt; @@ -848,7 +787,6 @@ int process_config(int argc, char **argv) { { "quiet", &rc_quiet }, { "feature1", &rc_feature1 }, { "feature2", &rc_feature2 }, - { "chip", &rc_chip }, { "sensorconf", &rc_config }, { NULL, NULL } }; @@ -914,9 +852,6 @@ int process_config(int argc, char **argv) { case '2': rc_feature2 = strdup(optarg); break; - case 'c': - rc_chip = strdup(optarg); - break; case 'S': rc_config = strdup(optarg); break; @@ -942,13 +877,10 @@ int process_config(int argc, char **argv) { } if(rc_feature1 != NULL) { - sensor_feature1 = strdup(rc_feature1); + cpu_sensor_name = strdup(rc_feature1); } if(rc_feature2 != NULL) { - sensor_feature2 = strdup(rc_feature2); - } - if(rc_chip != NULL) { - sensor_chip = strdup(rc_chip); + sys_sensor_name = strdup(rc_feature2); } if(rc_graph != NULL) {