1
0
mirror of https://github.com/gryf/wmtemp.git synced 2026-05-10 16:33:03 +02:00

4 Commits

Author SHA1 Message Date
gryf ac503a1ee5 Using NVCtrlLib library instead of nvidia-settings program. Refactoring and
code cleanup. Changed version to 0.4.0
2012-05-30 11:21:27 +02:00
gryf 4e92b6f5ca Added tag help for changeset 1ebdda9bbf87 2012-05-30 11:18:59 +02:00
gryf 0c442e8e90 Reverted code to nvidia-settings approach since nvclock stopped working with
nvidia drivers 295.40. To conserve resources there is delay in running
nvidia-settings utility in contrast to CPU temp readings.
2012-05-30 11:04:50 +02:00
gryf 28d2a7fd2e Attempt to use nvclock code for reading GPU temperature, since running
nvidia-settings couple of times for a second is highly inefficient.
2012-05-30 11:01:21 +02:00
5 changed files with 90 additions and 82 deletions
+1 -1
View File
@@ -366,7 +366,7 @@ void setMaskXY(int x, int y) {
/*******************************************************************************\ /*******************************************************************************\
|* openXwindow *| |* openXwindow *|
\*******************************************************************************/ \*******************************************************************************/
void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bits, int pixmask_width, int pixmask_height) { void openXwindow(int argc, char *argv[], char *pixmap_bytes[], const char *pixmask_bits, int pixmask_width, int pixmask_height) {
unsigned int borderwidth = 1; unsigned int borderwidth = 1;
XClassHint classHint; XClassHint classHint;
+1 -1
View File
@@ -45,7 +45,7 @@ Display *display;
void AddMouseRegion(int index, int left, int top, int right, int bottom); void AddMouseRegion(int index, int left, int top, int right, int bottom);
int CheckMouseRegion(int x, int y); int CheckMouseRegion(int x, int y);
void openXwindow(int argc, char *argv[], char **, char *, int, int); void openXwindow(int argc, char *argv[], char **, const char *, int, int);
void RedrawWindow(void); void RedrawWindow(void);
void RedrawWindowXY(int x, int y); void RedrawWindowXY(int x, int y);
+2 -2
View File
@@ -9,14 +9,14 @@ OBJ = $(SRC:.c=.o)
CFLAGS = -Wall -O3 CFLAGS = -Wall -O3
LIB = -L/usr/X11R6/lib -lXpm -lXext -lX11 -lsensors LIB = -I/usr/include/NVCtrl/ -L/usr/X11R6/lib -lXpm -lXext -lX11 -lsensors -lXNVCtrl
INSTALL = /usr/bin/install INSTALL = /usr/bin/install
CC = gcc CC = gcc
all: $(OBJ) all: $(OBJ)
$(CC) -o $(EXE) $(OBJ) $(LIB) $(CC) $(CFLAGS) -o $(EXE) $(OBJ) $(LIB)
strip $(EXE) strip $(EXE)
$(OBJ): %.o : %.c $(OBJ): %.o : %.c
+85 -77
View File
@@ -2,11 +2,10 @@
* wmtempnv: a sensor monitor for WindowMaker. this little app is mainly based * wmtempnv: a sensor monitor for WindowMaker. this little app is mainly based
* on wmsensormon and other simple dockapps. * on wmsensormon and other simple dockapps.
* *
* version = 0.1 * version = 0.4
* date: Fri Oct 31 20:41:14 CET 2008 @861 /Internet Time/ *
* author: Roman 'gryf' Dobosz * requirements: configured lm_sensors, sensor program and
* requirements: configured lm_sensors and sensor program, nvidia-settings, cut, * nvidia-settings package
* grep.
* licence: gpl * licence: gpl
*/ */
@@ -19,78 +18,82 @@
#include <string.h> #include <string.h>
#include "../wmgeneral/wmgeneral.h" #include "../wmgeneral/wmgeneral.h"
#include "../wmgeneral/misc.h" #include "../wmgeneral/misc.h"
#include "../wmgeneral/misc.h"
#include "wmtempnv_master2.xpm" #include "wmtempnv_master2.xpm"
#include "wmtempnv_mask.xbm" #include "wmtempnv_mask.xbm"
#include <NVCtrl/NVCtrl.h>
#include <NVCtrl/NVCtrlLib.h>
#define MAXSTRLEN 8 #define MAXSTRLEN 8
#define TEMP 40 #define TEMP 40
#define TEMP_OVER 47 #define TEMP_OVER 47
#define GPU_T 70 #define GPU_T 70
#define GPU_T_OVER 85 #define GPU_T_OVER 85
#define MAXFNAME 50
void display_values(int, int, int); void display_values(int, int, int);
int get_temp(int core_number); int get_temp(int core_number, Display*);
int get_offset(int temp, int cpu); int get_offset(int temp, int cpu);
Display *display;
int main(int argc, char **argv){ int main(int argc, char **argv){
int temp1=0, temp2=0, temp3=0; int temp1=0, temp2=0, temp3=0;
/* offset is one of 0 (normal), 7 (alert), 14 (warning) */ /* offset is one of 0 (normal), 7 (alert), 14 (warning) */
int offset1=0, offset2=0, offset3=0; int offset1=0, offset2=0, offset3=0;
int counter = 0; int counter = 0;
display = XOpenDisplay(NULL);
openXwindow(argc, argv, wmtempnv_master2_xpm, wmtempnv_mask_bits, wmtempnv_mask_width, wmtempnv_mask_height); openXwindow(argc, argv, wmtempnv_master2_xpm, wmtempnv_mask_bits,
wmtempnv_mask_width, wmtempnv_mask_height);
while(TRUE){ while(TRUE){
if(counter==0){ temp1 = get_temp(0, display);
temp1 = get_temp(0); offset1 = get_offset(temp1, 1);
offset1 = get_offset(temp1, 1); temp2 = get_temp(1, display);
temp2 = get_temp(1); offset2 = get_offset(temp2, 1);
offset2 = get_offset(temp2, 1); temp3 = get_temp(2, display);
temp3 = get_temp(2); offset3 = get_offset(temp3, 0);
offset3 = get_offset(temp3, 0);
counter = 200;
}
// core 1
copyXPMArea(0, 87 + offset1, 23, 7, 4, 7); // LCD: "CPU"
copyXPMArea(69, 87 + offset1, 5, 7, 22, 7); // LCD: number of cpu
copyXPMArea(66, 65 + offset1, 9, 7, 51, 7); // LCD: "°C"
display_values(temp1, 0, offset1);
// core 2 // core 1
copyXPMArea(0, 87 + offset2, 23, 7, 4, 21); copyXPMArea(0, 87 + offset1, 23, 7, 4, 7); // LCD: "CPU"
copyXPMArea(75, 87 + offset2, 5, 7, 22, 21); copyXPMArea(69, 87 + offset1, 5, 7, 22, 7); // LCD: number of cpu
copyXPMArea(66, 65 + offset2, 9, 7, 51, 21); copyXPMArea(66, 65 + offset1, 9, 7, 51, 7); // LCD: "°C"
display_values(temp2, 14, offset2); display_values(temp1, 0, offset1);
// gpu // core 2
copyXPMArea(23, 87 + offset3, 23, 7, 4, 35); copyXPMArea(0, 87 + offset2, 23, 7, 4, 21);
copyXPMArea(66, 65 + offset3, 9, 7, 51, 35); copyXPMArea(75, 87 + offset2, 5, 7, 22, 21);
display_values(temp3, 28, offset3); copyXPMArea(66, 65 + offset2, 9, 7, 51, 21);
RedrawWindow(); display_values(temp2, 14, offset2);
counter--;
usleep(5000); // gpu
} copyXPMArea(23, 87 + offset3, 23, 7, 4, 35);
copyXPMArea(66, 65 + offset3, 9, 7, 51, 35);
display_values(temp3, 28, offset3);
RedrawWindow();
counter--;
sleep(1);
}
} }
int get_offset(int temp, int cpu){ int get_offset(int temp, int cpu){
int alt, wrn; int alt, wrn;
if(cpu == 1){ if(cpu == 1){
wrn = TEMP; wrn = TEMP;
alt = TEMP_OVER; alt = TEMP_OVER;
}else{ }else{
wrn = GPU_T; wrn = GPU_T;
alt = GPU_T_OVER; alt = GPU_T_OVER;
} }
if(temp >= alt){ if(temp >= alt){
return 7; // Alert return 7; // Alert
}else if(temp >= wrn){ }else if(temp >= wrn){
return 14; // Warning return 14; // Warning
}else{ }else{
return 0; // Normal return 0; // Normal
} }
} }
void display_values(int temp, int offset, int offset2){ void display_values(int temp, int offset, int offset2){
char text[5], num1, num2, num3, num4; char text[5], num1, num2, num3, num4;
@@ -101,34 +104,39 @@ void display_values(int temp, int offset, int offset2){
num3 = (text[2] - '0'); num3 = (text[2] - '0');
num4 = (text[3] - '0'); num4 = (text[3] - '0');
if(num1) if(num1)
copyXPMArea(5 * num1, 65 + offset2, 5, 7, 31, 7 + offset); copyXPMArea(5 * num1, 65 + offset2, 5, 7, 31, 7 + offset);
else else
copyXPMArea(60, 65 + offset2, 5, 7, 31, 7 + offset); copyXPMArea(60, 65 + offset2, 5, 7, 31, 7 + offset);
copyXPMArea(5 * num2, 65 + offset2, 5, 7, 38, 7 + offset); copyXPMArea(5 * num2, 65 + offset2, 5, 7, 38, 7 + offset);
copyXPMArea(5 * num3, 65 + offset2, 5, 7, 45, 7 + offset); copyXPMArea(5 * num3, 65 + offset2, 5, 7, 45, 7 + offset);
copyXPMArea(5 * num4, 65 + offset2, 5, 7, 51, 7 + offset); copyXPMArea(5 * num4, 65 + offset2, 5, 7, 51, 7 + offset);
} }
int get_temp(int core_number){ int get_temp(int core_number, Display *disp){
// Core temperature. argument is core number. core no.2 is GPU // Core temperature. argument is core number. core no.2 is GPU
FILE *file; FILE *file;
int core=0; char filename[MAXFNAME];
char cmd[] = " "; int core_temp = 0;
if(core_number==2){ Bool res;
sprintf(cmd, "echo `nvidia-settings -q 'GPUCoreTemp'|grep Attribute|cut -d ':' -f 3|cut -d '.' -f 1`");
}else{ if(core_number == 2){
sprintf(cmd, "echo `sensors |grep 'Core %d'|cut -d ':' -f 2|cut -d '.' -f 1`", core_number);
} res = XNVCTRLQueryTargetAttribute(disp,
file = popen(cmd, "r"); NV_CTRL_TARGET_TYPE_GPU, 0, 0,
while (! feof(file)) { NV_CTRL_GPU_CORE_TEMPERATURE, &core_temp);
char line[MAXSTRLEN + 1];
bzero(line, MAXSTRLEN + 1); if (res == False) core_temp = 0;
fgets(line, MAXSTRLEN, file); }else{
if(line[0] != 0){ snprintf(filename, MAXFNAME,
sscanf(line, "%d", &core); "/sys/bus/platform/devices/coretemp.0/temp%d_input",
core_number + 2);
if((file = fopen(filename, "r")) != NULL){
if(fscanf(file, "%d", &core_temp) != EOF){
core_temp = core_temp / 1000;
fclose(file);
}
} }
} }
pclose(file); return core_temp;
return core;
} }
+1 -1
View File
@@ -1,6 +1,6 @@
#define wmtempnv_mask_width 64 #define wmtempnv_mask_width 64
#define wmtempnv_mask_height 64 #define wmtempnv_mask_height 64
static unsigned char wmtempnv_mask_bits[] = { static const char wmtempnv_mask_bits[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,