12 #include <X11/extensions/shape.h>
13 #include <sensors/sensors.h>
14 #include <sensors/error.h>
15 #include <libdockapp/wmgeneral.h>
16 #include <libdockapp/misc.h>
17 #include "wmgtemp-interface.xpm"
18 #include "wmgtemp-interface-mask.xbm"
24 #define BitOff(a,x) ((void)((a) &= ~(1 << (x))))
25 #define BitOn(a,x) ((void)((a) |= (1 << (x))))
26 #define BitFlip(a,x) ((void)((a) ^= (1 << (x))))
27 #define IsOn(a,x) ((a) & (1 << (x)))
35 #define TSCALE_CELCIUS 5
36 #define TSCALE_FAHRENHEIT 6
37 #define TSCALE_KELVIN 7
52 #define DEBUG 0 /* 0 disable 1 enable */
54 #define OPT_STRING "g:sS:hH:w:m:M:a:e:u:1:2:c:tq"
56 #define TEMPTOFAHRENHEIT(t) ((int)((t * (1.8) + 32)))
57 #define TEMPTOKELVIN(t) ((int)(t + 273))
58 #define TEMPTOCELCIUS(t) (t)
59 #define TEMPTODISPLAYSCALE(temp, display_flags) (IsOn((display_flags), TSCALE_CELCIUS) ? TEMPTOCELCIUS((temp)) : (IsOn((display_flags), TSCALE_KELVIN) ? TEMPTOKELVIN((temp)) : TEMPTOFAHRENHEIT((temp))))
63 int process_config(int argc
, char **argv
);
64 int recompute_range(double cpu_high
, double cpu_low
, double sys_high
, double sys_low
);
66 void process_xevents();
67 void draw_scale_indicator();
68 void add_to_graph(double temp
, int type
, short blank
, double range
, int pos
);
69 void draw_range_line(double temp
, double range
, short type
);
70 void update_display();
71 void update_sensor_data();
72 void do_sensors(int val
);
73 double highest_temp(double *temp_array
);
74 double lowest_temp(double *temp_array
);
75 void draw_temp(short value
, int type
);
76 void draw_warning_lights(double current_temp
);
77 void draw_max(int type
);
78 void blank_max(int type
);
79 void draw_type(int type
);
80 void blank_type(int type
);
81 void cycle_temptype();
85 const sensors_chip_name
*name
;
86 char *exec_app
= NULL
;
87 char *rc_config
= NULL
;
89 short SENSOR_DISP
= 0;
90 int SUBFEAT_NUM_CPU
= 0;
91 int SUBFEAT_NUM_SYS
= 0;
93 double cpu_history
[59];
94 double sys_history
[59];
96 double display_min
= 20;
97 double display_max
= 35;
99 double range_upper
= 35;
100 double range_lower
= 20;
101 double range_step
= 5.0;
103 double warn_temp
= 45;
104 double high_temp
= 50;
106 double run_cpu_high
= 0;
107 double run_sys_high
= 0;
111 short swap_types
= 0;
113 char *sensor_feature1
= "temp1";
114 char *sensor_feature2
= "temp2";
115 char *sensor_chip
= NULL
;
119 int main(int argc
, char **argv
) {
124 const sensors_feature
* feature
= NULL
;
125 const sensors_subfeature
* subfeature_cpu
= NULL
;
126 const sensors_subfeature
* subfeature_sys
= NULL
;
127 short chip_found
= -1;
129 BitOn(SENSOR_DISP
, WARN_NONE
);
130 BitOn(SENSOR_DISP
, TSCALE_CELCIUS
);
131 BitOn(SENSOR_DISP
, GRAPH_LINE
);
133 /* *conffname = "/etc/sensors3.conf"; */
135 if(!process_config(argc
, argv
)) {
139 if(!init_sensors()) {
143 /* Get the chip name */
144 name
= sensors_get_detected_chips(NULL
, &chip_nr
);
145 while(name
!= NULL
&& chip_found
== -1) {
146 if (!sensor_chip
|| strcmp(name
->prefix
, (const char *)sensor_chip
) == 0) {
148 while ((feature
= sensors_get_features(name
, &i
))) {
149 if(strcmp(feature
->name
, (const char *)sensor_feature1
) == 0) {
150 subfeature_cpu
= sensors_get_subfeature(name
, feature
, SENSORS_SUBFEATURE_TEMP_INPUT
);
151 SUBFEAT_NUM_CPU
= subfeature_cpu
->number
;
152 BitOn(SENSOR_DISP
, CPU
);
155 if(strcmp(feature
->name
, (const char *)sensor_feature2
) == 0) {
156 subfeature_sys
= sensors_get_subfeature(name
, feature
, SENSORS_SUBFEATURE_TEMP_INPUT
);
157 SUBFEAT_NUM_SYS
= subfeature_sys
->number
;
158 BitOn(SENSOR_DISP
, SYS
);
164 if(chip_found
== -1) {
165 name
= sensors_get_detected_chips(NULL
, &chip_nr
);
168 if(chip_found
== -1) {
169 fprintf(stderr
,"wmgtemp: Unable to find temperature sensing feature.\n");
173 /* output the name of the sensor if found. */
175 printf("wmgtemp: Primary Sensor - %s on %s\n", name
->prefix
, sensors_get_adapter_name(&name
->bus
));
179 printf("wmgtemp: swapping temps\n");
180 tmp_swap
= SUBFEAT_NUM_SYS
;
181 SUBFEAT_NUM_SYS
= SUBFEAT_NUM_CPU
;
182 SUBFEAT_NUM_CPU
= tmp_swap
;
183 tmp_swap
= SENSOR_DISP
;
184 if(IsOn(tmp_swap
, CPU
)) {
185 BitOn(SENSOR_DISP
, SYS
);
187 BitOff(SENSOR_DISP
, SYS
);
189 if(IsOn(tmp_swap
, SYS
)) {
190 BitOn(SENSOR_DISP
, CPU
);
192 BitOff(SENSOR_DISP
, CPU
);
198 openXwindow(argc
, argv
, wmgtemp_interface_xpm
, wmgtemp_interface_mask_bits
,
199 wmgtemp_interface_mask_width
, wmgtemp_interface_mask_height
);
201 AddMouseRegion(0, 2, 12, 61, 51); /* Graph area */
202 AddMouseRegion(1, 34, 2, 51, 11); /* CPU temp area */
203 AddMouseRegion(2, 34, 52, 51, 61); /* SYS temp area */
204 AddMouseRegion(3, 10, CPU_YPOS
, 28, CPU_YPOS
+ 7); /* CPU label area */
205 AddMouseRegion(4, 10, SYS_YPOS
, 28, SYS_YPOS
+ 7); /* SYS label area */
206 AddMouseRegion(5, 55, CPU_YPOS
, 60, CPU_YPOS
+ 7); /* CPU C/K/F scale indicator */
207 AddMouseRegion(6, 55, SYS_YPOS
, 60, SYS_YPOS
+ 7); /* SYS C/K/F scale indicator */
209 // Add blanking of SYS and CPU for chip type.
211 if(!IsOn(SENSOR_DISP
, CPU
)) {
214 if(!IsOn(SENSOR_DISP
, SYS
)) {
218 draw_scale_indicator();
220 // Initialise the temperature arrays.
221 for(i
= 0; i
< 59; i
++) {
234 void draw_scale_indicator() {
235 if(IsOn(SENSOR_DISP
, TSCALE_CELCIUS
)) {
236 if(IsOn(SENSOR_DISP
, CPU
)) {
237 copyXPMArea(61, 65, 5, 7, 55, CPU_YPOS
);
238 copyXPMArea(70, 2, 2, 2, 52, CPU_YPOS
);
240 if(IsOn(SENSOR_DISP
, SYS
)) {
241 copyXPMArea(61, 65, 5, 7, 55, SYS_YPOS
);
242 copyXPMArea(70, 2, 2, 2, 52, SYS_YPOS
);
245 else if(IsOn(SENSOR_DISP
, TSCALE_FAHRENHEIT
)) {
246 if(IsOn(SENSOR_DISP
, CPU
)) {
247 copyXPMArea(67, 65, 5, 7, 55, CPU_YPOS
);
248 copyXPMArea(70, 2, 2, 2, 52, CPU_YPOS
);
250 if(IsOn(SENSOR_DISP
, SYS
)) {
251 copyXPMArea(67, 65, 5, 7, 55, SYS_YPOS
);
252 copyXPMArea(70, 2, 2, 2, 52, SYS_YPOS
);
255 else if(IsOn(SENSOR_DISP
, TSCALE_KELVIN
)) {
256 if(IsOn(SENSOR_DISP
, CPU
)) {
257 copyXPMArea(73, 65, 5, 7, 55, CPU_YPOS
);
258 copyXPMArea(70, 0, 2, 2, 52, CPU_YPOS
);
260 if(IsOn(SENSOR_DISP
, SYS
)) {
261 copyXPMArea(73, 65, 5, 7, 55, SYS_YPOS
);
262 copyXPMArea(70, 0, 2, 2, 52, SYS_YPOS
);
267 void process_xevents() {
271 struct pollfd
* pfds
= NULL
;
274 time_t lastupdate
= 0;
276 ret
= XInternalConnectionNumbers(display
, &xfds
, &fdcount
);
286 pfds
= (struct pollfd
*)malloc((fdcount
+1)*sizeof(struct pollfd
));
292 for(i
=0; i
< fdcount
; ++i
) {
293 pfds
[i
].fd
= xfds
[i
];
294 pfds
[i
].events
= POLLIN
| POLLPRI
;
301 pfds
[fdcount
].fd
= ConnectionNumber(display
);
302 pfds
[fdcount
].events
= POLLIN
| POLLPRI
;
305 poll(pfds
, fdcount
+ 1, delay
* 1000);
307 if(time(NULL
) - lastupdate
>= delay
) {
308 lastupdate
= time(NULL
);
312 while(XPending(display
)) {
313 XNextEvent(display
, &Event
);
319 XCloseDisplay(display
);
323 button_area
= CheckMouseRegion(Event
.xbutton
.x
, Event
.xbutton
.y
);
324 switch(button_area
) {
326 if(IsOn(SENSOR_DISP
, GRAPH_LINE
)) {
327 BitOff(SENSOR_DISP
, GRAPH_LINE
);
328 BitOn(SENSOR_DISP
, GRAPH_BLOCK
);
330 else if(IsOn(SENSOR_DISP
, GRAPH_BLOCK
)) {
331 BitOff(SENSOR_DISP
, GRAPH_BLOCK
);
332 BitOn(SENSOR_DISP
, GRAPH_LINE
);
338 if(IsOn(SENSOR_DISP
, HIGH_CPU
)) {
339 BitOff(SENSOR_DISP
, HIGH_CPU
);
343 BitOn(SENSOR_DISP
, HIGH_CPU
);
350 if(IsOn(SENSOR_DISP
, HIGH_SYS
)) {
351 BitOff(SENSOR_DISP
, HIGH_SYS
);
355 BitOn(SENSOR_DISP
, HIGH_SYS
);
362 if(SUBFEAT_NUM_CPU
) {
363 if(IsOn(SENSOR_DISP
, CPU
)) {
364 BitOff(SENSOR_DISP
, CPU
);
368 BitOn(SENSOR_DISP
, CPU
);
370 draw_scale_indicator();
377 if(SUBFEAT_NUM_SYS
) {
378 if(IsOn(SENSOR_DISP
, SYS
)) {
379 BitOff(SENSOR_DISP
, SYS
);
383 BitOn(SENSOR_DISP
, SYS
);
385 draw_scale_indicator();
394 draw_scale_indicator();
405 void do_sensors(int val
) {
407 update_sensor_data();
411 if(execat
!= 0 && cpu_history
[58] >= execat
&& !execed
) {
413 execCommand(exec_app
);
415 if(execat
!= 0 && cpu_history
[58] < execat
&& execed
) {
421 void update_sensor_data() {
423 double cpu_high
= highest_temp(cpu_history
);
424 double sys_high
= highest_temp(sys_history
);
426 /* Shift the arrays */
427 for(i
= 0; i
< 58; i
++) {
428 cpu_history
[i
] = cpu_history
[i
+ 1];
429 sys_history
[i
] = sys_history
[i
+ 1];
432 // Read the new values from the sensors into the temperature arrays.
433 if(IsOn(SENSOR_DISP
, SYS
)) sensors_get_value(name
, SUBFEAT_NUM_SYS
, &sys_history
[58]);
434 if(IsOn(SENSOR_DISP
, CPU
)) sensors_get_value(name
, SUBFEAT_NUM_CPU
, &cpu_history
[58]);
436 // Update the run high/low values.
437 if(cpu_high
> run_cpu_high
)
438 run_cpu_high
= cpu_high
;
439 if(sys_high
> run_sys_high
)
440 run_sys_high
= sys_high
;
444 void update_display() {
448 // Rescale the display if needed.
449 while(recompute_range(highest_temp(cpu_history
), lowest_temp(cpu_history
),
450 highest_temp(sys_history
), lowest_temp(sys_history
)));
453 draw_warning_lights(cpu_history
[58]);
455 // ReDraw temperature numbers
456 if(IsOn(SENSOR_DISP
, CPU
)) {
457 copyXPMArea(78, 65, 5, 7, 34, CPU_YPOS
);
458 copyXPMArea(78, 65, 5, 7, 40, CPU_YPOS
);
459 copyXPMArea(78, 65, 5, 7, 46, CPU_YPOS
);
460 draw_temp(TEMPTODISPLAYSCALE(IsOn(SENSOR_DISP
, HIGH_CPU
) == 0 ? cpu_history
[58] : run_cpu_high
, SENSOR_DISP
), CPU
);
462 if(IsOn(SENSOR_DISP
, SYS
)) {
463 copyXPMArea(78, 65, 5, 7, 34, SYS_YPOS
);
464 copyXPMArea(78, 65, 5, 7, 40, SYS_YPOS
);
465 copyXPMArea(78, 65, 5, 7, 46, SYS_YPOS
);
466 draw_temp(TEMPTODISPLAYSCALE(IsOn(SENSOR_DISP
, HIGH_SYS
) == 0 ? sys_history
[58] : run_sys_high
, SENSOR_DISP
), SYS
);
471 for(j
= 0; j
< 59; j
++) {
473 copyXPMArea(65, 0, 1, 39, j
+ 2, 12);
475 if(sys_history
[j
] < cpu_history
[j
]) {
476 // Draw the temperatures on the graph.
477 if(IsOn(SENSOR_DISP
, CPU
)) {
478 add_to_graph(cpu_history
[j
], CPU
, 1, range_upper
- range_lower
, j
+ 2);
480 if(IsOn(SENSOR_DISP
, SYS
)) {
481 add_to_graph(sys_history
[j
], SYS
, 0, range_upper
- range_lower
, j
+ 2);
485 if(IsOn(SENSOR_DISP
, SYS
)) {
486 add_to_graph(sys_history
[j
], SYS
, 0, range_upper
- range_lower
, j
+ 2);
488 if(IsOn(SENSOR_DISP
, CPU
)) {
489 add_to_graph(cpu_history
[j
], CPU
, 1, range_upper
- range_lower
, j
+ 2);
494 // Draw range lines if needed
495 if(range_upper
> display_max
) {
496 draw_range_line(display_max
, range_upper
- range_lower
, D_MAX
);
498 if(range_lower
< display_min
) {
499 draw_range_line(display_min
, range_upper
- range_lower
, D_MIN
);
503 int recompute_range(double cpu_high
, double cpu_low
, double sys_high
, double sys_low
)
507 if(IsOn(SENSOR_DISP
, CPU
)) {
508 if(cpu_high
> range_upper
) {
509 range_upper
+= range_step
;
512 if(cpu_low
< range_lower
) {
513 range_lower
-= range_step
;
517 if(IsOn(SENSOR_DISP
, SYS
)) {
518 if(sys_high
> range_upper
) {
519 range_upper
+= range_step
;
522 if(sys_low
< range_lower
) {
523 range_lower
-= range_step
;
529 if(IsOn(SENSOR_DISP
, CPU
) && IsOn(SENSOR_DISP
, SYS
)) {
530 if((cpu_high
< (range_upper
- range_step
) &&
531 sys_high
< (range_upper
- range_step
)) &&
532 (range_upper
- range_step
) >= display_max
) {
533 range_upper
-= range_step
;
536 if((cpu_low
> (range_lower
+ range_step
) &&
537 sys_low
> (range_lower
+ range_step
)) &&
538 (range_lower
+ range_step
) <= display_min
) {
539 range_lower
+= range_step
;
543 else if(IsOn(SENSOR_DISP
, CPU
) && !IsOn(SENSOR_DISP
, SYS
)) {
544 if(cpu_high
< (range_upper
- range_step
) &&
545 (range_upper
- range_step
) >= display_max
) {
546 range_upper
-= range_step
;
549 if(cpu_low
> (range_lower
+ range_step
) &&
550 (range_lower
+ range_step
) <= display_min
) {
551 range_lower
+= range_step
;
555 else if(!IsOn(SENSOR_DISP
, CPU
) && IsOn(SENSOR_DISP
, SYS
)) {
556 if(sys_high
< (range_upper
- range_step
) &&
557 (range_upper
- range_step
) >= display_max
) {
558 range_upper
-= range_step
;
561 if(sys_low
> (range_lower
+ range_step
) &&
562 (range_lower
+ range_step
) <= display_min
) {
563 range_lower
+= range_step
;
571 double highest_temp(double *temp_array
) {
574 for(i
= 0; i
< 59; i
++) {
575 if(temp_array
[i
] > high
)
576 high
= temp_array
[i
];
581 double lowest_temp(double *temp_array
) {
584 for(i
= 0; i
< 59; i
++) {
585 if((temp_array
[i
] < low
) && (temp_array
[i
] != -1))
591 void add_to_graph(double temp
, int type
, short blank
, double range
, int pos
) {
592 double each
= (double)39 / range
;
593 short length
= each
* (temp
- range_lower
);
596 // if(IsOn(SENSOR_DISP, GRAPH_BLOCK)) {
597 // copyXPMArea(type == CPU ? 67 : 68, 0, 1, length, pos, 51 - length);
599 // else if(IsOn(SENSOR_DISP, GRAPH_LINE)) {
600 // copyXPMArea(type == CPU ? 67 : 68, 0, 1, 1, pos, 51 - length);
603 // Do not draw the graphs if the temperature data does not make sense
604 // Orginially used the code above but change supplied to fix issues seen by Ben Spencer.
605 // Couldn't be arsed to find the real cause as I don't use the app myself anymore.
606 // Doesn't seem to break anything though
607 if ((temp
>= range_lower
) && (temp
<= range_upper
)) {
609 if(IsOn(SENSOR_DISP
, GRAPH_BLOCK
)) {
610 copyXPMArea(type
== CPU
? 67 : 68, 0, 1, length
, pos
, 51 - length
);
612 else if(IsOn(SENSOR_DISP
, GRAPH_LINE
)) {
613 copyXPMArea(type
== CPU
? 67 : 68, 0, 1, 1, pos
, 51 - length
);
619 void draw_temp(short value
, int type
) {
624 copyXPMArea((digit
* 6) + 1, 65, 5, 7, 46, type
== CPU
? CPU_YPOS
: SYS_YPOS
);
626 digit
= ((value
% 100) - digit
) / 10;
627 copyXPMArea((digit
* 6) + 1, 65, 5, 7, 40, type
== CPU
? CPU_YPOS
: SYS_YPOS
);
629 digit
= (value
- (value
% 100)) / 100;
630 copyXPMArea((digit
* 6) + 1, 65, 5, 7, 34, type
== CPU
? CPU_YPOS
: SYS_YPOS
);
637 void draw_clear_temps() {
638 if(IsOn(SENSOR_DISP
, CPU
)) {
639 copyXPMArea(78, 65, 5, 7, 34, CPU_YPOS
);
640 copyXPMArea(78, 65, 5, 7, 40, CPU_YPOS
);
641 copyXPMArea(78, 65, 5, 7, 46, CPU_YPOS
);
643 if(IsOn(SENSOR_DISP
, SYS
)) {
644 copyXPMArea(78, 65, 5, 7, 34, SYS_YPOS
);
645 copyXPMArea(78, 65, 5, 7, 40, SYS_YPOS
);
646 copyXPMArea(78, 65, 5, 7, 46, SYS_YPOS
);
650 void draw_range_line(double temp
, double range
, short type
) {
651 double each
= (double)39 / range
;
652 short length
= each
* (temp
- range_lower
);
654 copyXPMArea(0, type
== D_MAX
? 73 : 74, 59, 1, 2, 51 - length
);
663 config_file
= fopen(rc_config
, "r");
665 if(config_file
== NULL
) {
666 fprintf(stderr
, "Error opening %s\n", rc_config
);
670 config_file
= NULL
; /* Use libsensors default */
673 res
= sensors_init(config_file
);
676 fprintf(stderr
,"Error initializing sensors: %s\n", sensors_strerror(res
));
680 if(config_file
&& fclose(config_file
))
681 perror("Error closing sensors config");
686 void display_usage() {
687 printf("wmgtemp v"PACKAGE_VERSION
"\n" \
688 "Usage: wmgtemp [options]\n" \
690 " -S, --sensorconf=PATH Specify sensors config file PATH\n" \
691 " [Default: autodetect]\n" \
692 " -s, --scale=SCALE Display temperatures in SCALE\n" \
693 " SCALE=kelvin, fahrenheit\n" \
694 " [Default: celcius]\n" \
695 " -g, --graph=STYLE Display graph as STYLE\n" \
696 " STYLE=line, block\n" \
697 " [Default: line]\n" \
698 " -H, --high=TEMP Display red warning light at TEMP degrees celcius\n" \
700 " -w, --warn=TEMP Display amber warning light at TEMP degrees celcius\n" \
702 " -u, --update=SEC Update the display every SEC seconds\n" \
704 " -m, --min=TEMP Set lower bound of the graph to TEMP degrees celcius\n" \
706 " -M, --max=TEMP Set upper bound of the graph to TEMP degrees celcius\n" \
708 " -1, --feature1=F1 Set the feature for CPU\n" \
709 " [Default: temp1]\n" \
710 " -2, --feature2=F2 Set the feature for SYS\n" \
711 " [Default: temp2]\n" \
712 " -c, --chip=NAME Use sensor chip matching NAME\n" \
713 " [Default: use any]\n" \
714 " -a, --execat=TEMP Execute a command at TEMP degrees celcius\n" \
715 " -e, --exec=COMMAND Execute COMMAND when 'execat' temperature is reached\n" \
716 " -t, --swap Swap CPU and SYS temps\n" \
717 " -q, --quiet Don't display any messages\n" \
718 " -h, --help Displays this help screen\n");
721 void draw_warning_lights(double current_temp
) {
722 if(current_temp
>= warn_temp
&& IsOn(SENSOR_DISP
, WARN_NONE
)) {
723 // Switch from ok to warning.
724 BitOff(SENSOR_DISP
, WARN_NONE
);
725 BitOn(SENSOR_DISP
, WARN_WARN
);
726 copyXPMArea(10, 75, 5, 5, 4, 4);
728 if(current_temp
< warn_temp
&& IsOn(SENSOR_DISP
, WARN_WARN
)) {
729 // Switch from warning to ok.
730 BitOff(SENSOR_DISP
, WARN_WARN
);
731 BitOn(SENSOR_DISP
, WARN_NONE
);
732 copyXPMArea(0, 75, 5, 5, 4, 4);
734 if(current_temp
>= high_temp
&& IsOn(SENSOR_DISP
, WARN_WARN
)) {
735 // Switch from warning to high.
736 BitOff(SENSOR_DISP
, WARN_WARN
);
737 BitOn(SENSOR_DISP
, WARN_HIGH
);
738 copyXPMArea(15, 75, 5, 5, 4, 4);
740 if(current_temp
< high_temp
&& IsOn(SENSOR_DISP
, WARN_HIGH
)) {
741 // Switch from high to warning.
742 BitOff(SENSOR_DISP
, WARN_HIGH
);
743 BitOn(SENSOR_DISP
, WARN_WARN
);
744 copyXPMArea(10, 75, 5, 5, 4, 4);
748 void blank_type(int type
) {
751 copyXPMArea(78, 65, 5, 7, 11, CPU_YPOS
);
752 copyXPMArea(78, 65, 5, 7, 17, CPU_YPOS
);
753 copyXPMArea(78, 65, 5, 7, 23, CPU_YPOS
);
755 copyXPMArea(70, 0, 2, 2, 52, CPU_YPOS
);
757 copyXPMArea(78, 65, 5, 7, 34, CPU_YPOS
);
758 copyXPMArea(78, 65, 5, 7, 40, CPU_YPOS
);
759 copyXPMArea(78, 65, 5, 7, 46, CPU_YPOS
);
761 copyXPMArea(78, 65, 5, 7, 55, CPU_YPOS
);
764 copyXPMArea(78, 65, 5, 7, 11, SYS_YPOS
);
765 copyXPMArea(78, 65, 5, 7, 17, SYS_YPOS
);
766 copyXPMArea(78, 65, 5, 7, 23, SYS_YPOS
);
768 copyXPMArea(70, 0, 2, 2, 52, SYS_YPOS
);
770 copyXPMArea(78, 65, 5, 7, 34, SYS_YPOS
);
771 copyXPMArea(78, 65, 5, 7, 40, SYS_YPOS
);
772 copyXPMArea(78, 65, 5, 7, 46, SYS_YPOS
);
774 copyXPMArea(78, 65, 5, 7, 55, SYS_YPOS
);
779 void draw_max(int type
) {
780 // copyXPMArea(1, 81, 17, 7, 11, type == CPU ? CPU_YPOS : SYS_YPOS);
781 copyXPMArea(24, 75, 4, 3, 29, type
== CPU
? CPU_YPOS
: SYS_YPOS
);
784 void blank_max(int type
) {
785 // copyXPMArea(1, 81, 17, 7, 11, type == CPU ? CPU_YPOS : SYS_YPOS);
786 copyXPMArea(20, 75, 4, 3, 29, type
== CPU
? CPU_YPOS
: SYS_YPOS
);
789 void draw_type(int type
) {
792 copyXPMArea(65, 40, 17, 7, 11, CPU_YPOS
);
795 copyXPMArea(65, 47, 17, 7, 11, SYS_YPOS
);
800 void cycle_temptype() {
801 if(IsOn(SENSOR_DISP
, TSCALE_CELCIUS
)) {
802 BitOff(SENSOR_DISP
, TSCALE_CELCIUS
);
803 BitOn(SENSOR_DISP
, TSCALE_KELVIN
);
805 else if(IsOn(SENSOR_DISP
, TSCALE_KELVIN
)) {
806 BitOff(SENSOR_DISP
, TSCALE_KELVIN
);
807 BitOn(SENSOR_DISP
, TSCALE_FAHRENHEIT
);
809 else if(IsOn(SENSOR_DISP
, TSCALE_FAHRENHEIT
)) {
810 BitOff(SENSOR_DISP
, TSCALE_FAHRENHEIT
);
811 BitOn(SENSOR_DISP
, TSCALE_CELCIUS
);
816 int process_config(int argc
, char **argv
) {
817 char *rc_graph
= NULL
;
818 char *rc_scale
= NULL
;
819 char *rc_high
= NULL
;
820 char *rc_warn
= NULL
;
823 char *rc_execat
= NULL
;
824 char *rc_exec
= NULL
;
825 char *rc_delay
= NULL
;
826 char *rc_swap
= NULL
;
827 char *rc_feature1
= NULL
;
828 char *rc_feature2
= NULL
;
829 char *rc_quiet
= NULL
;
830 char *rc_chip
= NULL
;
837 rckeys wmgtemp_keys
[] = {
838 { "graph", &rc_graph
},
839 { "scale", &rc_scale
},
840 { "high", &rc_high
},
841 { "warn", &rc_warn
},
844 { "execat", &rc_execat
},
845 { "exec", &rc_exec
},
846 { "update", &rc_delay
},
847 { "swap", &rc_swap
},
848 { "quiet", &rc_quiet
},
849 { "feature1", &rc_feature1
},
850 { "feature2", &rc_feature2
},
851 { "chip", &rc_chip
},
852 { "sensorconf", &rc_config
},
856 static struct option long_options
[] = {
857 {"graph", required_argument
, 0, 'g'},
858 {"scale", required_argument
, 0, 's'},
859 {"high", required_argument
, 0, 'H'},
860 {"warn", required_argument
, 0, 'w'},
861 {"min", required_argument
, 0, 'm'},
862 {"max", required_argument
, 0, 'M'},
863 {"execat", required_argument
, 0, 'a'},
864 {"exec", required_argument
, 0, 'e'},
865 {"update", required_argument
, 0, 'u'},
866 {"feature1", required_argument
, 0, '1'},
867 {"feature2", required_argument
, 0, '2'},
868 {"chip", required_argument
, 0, 'c'},
869 {"sensorconf", required_argument
, 0, 'S'},
870 {"swap", no_argument
, 0, 't'},
871 {"quiet", no_argument
, 0, 'q'},
872 {"help", no_argument
, 0, 'h'},
878 strcat(temp
, "/.wmgtemprc");
879 parse_rcfile(temp
, wmgtemp_keys
);
882 while ((opt
= getopt_long(argc
, argv
, OPT_STRING
, long_options
, &opt_index
)) != -1) {
885 rc_graph
= strdup(optarg
);
888 rc_scale
= strdup(optarg
);
891 rc_high
= strdup(optarg
);
894 rc_warn
= strdup(optarg
);
897 rc_min
= strdup(optarg
);
900 rc_max
= strdup(optarg
);
903 rc_execat
= strdup(optarg
);
906 rc_exec
= strdup(optarg
);
909 rc_delay
= strdup(optarg
);
912 rc_feature1
= strdup(optarg
);
915 rc_feature2
= strdup(optarg
);
918 rc_chip
= strdup(optarg
);
921 rc_config
= strdup(optarg
);
938 if(rc_quiet
!= NULL
) {
939 if(!strncmp(rc_quiet
, "y", 1)) {
944 if(rc_feature1
!= NULL
) {
945 sensor_feature1
= strdup(rc_feature1
);
947 if(rc_feature2
!= NULL
) {
948 sensor_feature2
= strdup(rc_feature2
);
950 if(rc_chip
!= NULL
) {
951 sensor_chip
= strdup(rc_chip
);
954 if(rc_graph
!= NULL
) {
955 if(!strncmp(rc_graph
, "l", 1)) {
956 BitOff(SENSOR_DISP
, GRAPH_BLOCK
);
957 BitOn(SENSOR_DISP
, GRAPH_LINE
);
959 else if(!strncmp(rc_graph
, "b", 1)) {
960 BitOff(SENSOR_DISP
, GRAPH_LINE
);
961 BitOn(SENSOR_DISP
, GRAPH_BLOCK
);
964 printf("Invalid graph type: %s\n", rc_graph
);
968 if(rc_scale
!= NULL
) {
969 if(!strncmp(rc_scale
, "c", 1)) {
971 else if(!strncmp(rc_scale
, "f", 1)) {
972 BitOff(SENSOR_DISP
, TSCALE_KELVIN
);
973 BitOff(SENSOR_DISP
, TSCALE_CELCIUS
);
974 BitOn(SENSOR_DISP
, TSCALE_FAHRENHEIT
);
976 else if(!strncmp(rc_scale
, "k", 1)) {
977 BitOff(SENSOR_DISP
, TSCALE_CELCIUS
);
978 BitOff(SENSOR_DISP
, TSCALE_FAHRENHEIT
);
979 BitOn(SENSOR_DISP
, TSCALE_KELVIN
);
982 printf("Invalid scale type: %s\n", rc_scale
);
987 if(rc_high
!= NULL
) {
988 high_temp
= (double)atoi(rc_high
);
990 printf("Invalid temperature\n");
995 printf("wmgtemp: high temp set to %d degrees celcius.\n", (int)high_temp
);
998 if(rc_warn
!= NULL
) {
999 warn_temp
= (double)atoi(rc_warn
);
1001 printf("Invalid temperature\n");
1006 printf("wmgtemp: warning temp set to %d degrees celcius.\n", (int)warn_temp
);
1009 if(rc_max
!= NULL
) {
1010 display_max
= range_upper
= (double)atoi(rc_max
);
1012 printf("Invalid temperature\n");
1017 printf("wmgtemp: Upper range set to %d degrees celcius.\n", (int)range_upper
);
1020 if(rc_min
!= NULL
) {
1021 display_min
= range_lower
= (double)atoi(rc_min
);
1023 printf("Invalid temperature\n");
1028 printf("wmgtemp: Lower range set to %d degrees celcius.\n", (int)range_lower
);
1031 if(rc_delay
!= NULL
) {
1032 delay
= atoi(rc_delay
);
1034 printf("Invalid delay\n");
1039 printf("wmgtemp: update delay set to %d seconds.\n", delay
);
1042 if(rc_execat
!= NULL
) {
1043 execat
= (double)atoi(rc_execat
);
1045 printf("Invalid temperature\n");
1049 if(rc_exec
!= NULL
) {
1050 if(strcmp(rc_exec
, "")) {
1051 exec_app
= strdup(rc_exec
);
1052 printf("wmgtemp: Executing \"%s\" at %d degrees celcius.\n", exec_app
, (int)execat
);
1055 printf("You must supply an command to execute\n");
1060 printf("You must supply an command to execute\n");
1065 if(rc_swap
!= NULL
) {
1066 if(!strncmp(rc_swap
, "y", 1)) {
1069 else if(!strncmp(rc_swap
, "n", 1)) {
1073 printf("Supply 'y' or 'n' for swap temps\n");