Skip to content

Commit

Permalink
cli: Add verbose mode for 'temp' command
Browse files Browse the repository at this point in the history
to show individual die temperature sensor readings.
  • Loading branch information
kelvin-cao committed Dec 2, 2023
1 parent 98626c9 commit 27dbfd7
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions cli/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1284,26 +1284,48 @@ static int test(int argc, char **argv)
static int temp(int argc, char **argv)
{
float ret;
int nr_reading;
float temps[4];

static struct {
struct switchtec_dev *dev;
int verbose;
} cfg = {};
const struct argconfig_options opts[] = {
DEVICE_OPTION,
{"verbose", 'v', "", CFG_NONE, &cfg.verbose, no_argument,
"print individual die temperature sensor reading"},
{NULL}};

argconfig_parse(argc, argv, CMD_DESC_TEMP, opts, &cfg, sizeof(cfg));

ret = switchtec_die_temp(cfg.dev);
if (ret < 0) {
switchtec_perror("die_temp");
return 1;
if (!cfg.verbose) {
ret = switchtec_die_temp(cfg.dev);
if (ret < 0) {
switchtec_perror("die_temp");
return 1;
}

if (have_decent_term())
printf("%.3g °C\n", ret);
else
printf("%.3g degC\n", ret);
} else {
int i;
nr_reading = switchtec_die_temps(cfg.dev, 4, temps);
if (nr_reading < 0) {
switchtec_perror("die_temp");
return 1;
}

for (i = 0; i < nr_reading; i++) {
if (have_decent_term())
printf("Sensor %d: %.3g °C\n", i, temps[i]);
else
printf("Sensor %d: %.3g degC\n", i, temps[i]);
}
}

if (have_decent_term())
printf("%.3g °C\n", ret);
else
printf("%.3g degC\n", ret);
return 0;
}

Expand Down

0 comments on commit 27dbfd7

Please sign in to comment.