Added watch function

This commit is contained in:
moosecrap 2025-02-01 08:22:52 -08:00
parent 34bbcf7883
commit 4cb9ef42a6
2 changed files with 17 additions and 2 deletions

View File

@ -39,6 +39,7 @@ Available options:
--reset : Reset all fans to their default mode --reset : Reset all fans to their default mode
--sensors : Print sensor readings even if setting a fan speed --sensors : Print sensor readings even if setting a fan speed
--compact : Print sensor reading in a compact one-line per card format --compact : Print sensor reading in a compact one-line per card format
--watch N : Keep printing output every N seconds
``` ```
### Examples: ### Examples:

View File

@ -20,7 +20,8 @@ static const char helpstring[] = "Available options:\n"
" [+/-]N to set that fan to an RPM offset from the GPU-controlled speed\n" " [+/-]N to set that fan to an RPM offset from the GPU-controlled speed\n"
"--reset : Reset all fans to their default mode\n" "--reset : Reset all fans to their default mode\n"
"--sensors : Print sensor readings even if setting a fan speed \n" "--sensors : Print sensor readings even if setting a fan speed \n"
"--compact : Print sensor reading in a compact one-line per card format\n"; "--compact : Print sensor reading in a compact one-line per card format\n"
"--watch N : Keep printing output every N seconds\n";
void print_gpu_info(int gpu_num, struct card_info gpus[], int compact); void print_gpu_info(int gpu_num, struct card_info gpus[], int compact);
@ -31,6 +32,7 @@ int main (int argc, char **argv)
int print_info = 0; int print_info = 0;
int compact = 0; int compact = 0;
int gpu_num = -1; /* Card to control */ int gpu_num = -1; /* Card to control */
int watch = -1;
char *fan_speed[ICX3_MAX_FANS] = {NULL}; char *fan_speed[ICX3_MAX_FANS] = {NULL};
/* Input parsing */ /* Input parsing */
@ -69,6 +71,14 @@ int main (int argc, char **argv)
print_info = 1; print_info = 1;
} else if (strcmp(argv[i], "--compact") == 0) { } else if (strcmp(argv[i], "--compact") == 0) {
compact = 1; compact = 1;
} else if (strcmp(argv[i], "--watch") == 0) {
i++;
if (i < argc) {
watch = atoi(argv[i]);
} else {
printf(helpstring);
return -1;
}
} else { } else {
printf(helpstring); printf(helpstring);
return 0; return 0;
@ -116,6 +126,7 @@ int main (int argc, char **argv)
} }
/* print sensor info */ /* print sensor info */
print:
if (print_info) { if (print_info) {
if (gpu_num == -1) { if (gpu_num == -1) {
for (int i = 0; i < gpu_count; i++){ for (int i = 0; i < gpu_count; i++){
@ -125,7 +136,10 @@ int main (int argc, char **argv)
print_gpu_info(gpu_num, gpus, compact); print_gpu_info(gpu_num, gpus, compact);
} }
} }
if (watch > 0) {
sleep(watch);
goto print;
}
} }
void print_gpu_info(int gpu_num, struct card_info gpus[], int compact) { void print_gpu_info(int gpu_num, struct card_info gpus[], int compact) {