Added compact sensor display option
This commit is contained in:
@@ -33,72 +33,59 @@ enum icx3_product_id check_for_icx3(char *i2c_dev_path)
|
||||
|
||||
void print_icx3_fans(char *i2c_dev_path)
|
||||
{
|
||||
char data[I2C_SMBUS_BLOCK_MAX] = {};
|
||||
int fd, read_result;
|
||||
struct icx3_fan_control fans[ICX3_MAX_FANS];
|
||||
get_fan_status(fans, i2c_dev_path);
|
||||
|
||||
struct icx3_fan_control *fan_status;
|
||||
|
||||
/* First thing is to check for the product ID to figure out how many fans we have */
|
||||
char fans_avail[ICX3_MAX_FANS] = {0};
|
||||
get_available_fans(i2c_dev_path, fans_avail);
|
||||
|
||||
fd = open_i2c_dev(i2c_dev_path);
|
||||
if (fd == -1)
|
||||
return;
|
||||
|
||||
for (int i=0; i < ICX3_MAX_FANS; i++) {
|
||||
if (!fans_avail[i])
|
||||
continue;
|
||||
|
||||
read_result = i2c_smbus_read_i2c_block_data(fd, ICX3_REG_FANCONTROL + i, ICX3_FANCONTROL_SIZE, data);
|
||||
if (read_result != ICX3_FANCONTROL_SIZE) {
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
fan_status = (struct icx3_fan_control*) &data;
|
||||
for (int i=0; i < ICX3_MAX_FANS; i++) {
|
||||
printf("%s: %d RPM (%d/%d%%, %s)\n",
|
||||
icx3_fan_names[i],
|
||||
fan_status->rpm_status,
|
||||
fan_status->duty_status,
|
||||
fan_status->duty,
|
||||
icx3_fan_mode_names[fan_status->fanmode]
|
||||
fans[i].rpm_status,
|
||||
fans[i].duty_status,
|
||||
fans[i].duty,
|
||||
icx3_fan_mode_names[fans[i].fanmode]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void print_icx3_fans_oneline(char *i2c_dev_path)
|
||||
{
|
||||
struct icx3_fan_control fans[ICX3_MAX_FANS];
|
||||
get_fan_status(fans, i2c_dev_path);
|
||||
|
||||
close(fd);
|
||||
printf("FAN");
|
||||
for (int i=0; i < ICX3_MAX_FANS; i++) {
|
||||
printf(" %3d", fans[i].duty_status);
|
||||
}
|
||||
printf("%%");
|
||||
}
|
||||
|
||||
void print_icx3_temps(char *i2c_dev_path)
|
||||
{
|
||||
char data[I2C_SMBUS_BLOCK_MAX] = {};
|
||||
int fd, read_result;
|
||||
struct icx3_temp_sensors *temp_sensors;
|
||||
float temps[ICX3_NUM_TEMP_SENSORS];
|
||||
|
||||
fd = open_i2c_dev(i2c_dev_path);
|
||||
if (fd == -1)
|
||||
return;
|
||||
|
||||
read_result = i2c_smbus_read_i2c_block_data(fd, ICX3_REG_TEMPSENSOR, ICX3_TEMPSENSOR_SIZE, data);
|
||||
if (read_result != ICX3_TEMPSENSOR_SIZE) {
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
temp_sensors = (struct icx3_temp_sensors*) &data;
|
||||
|
||||
float cur_temp;
|
||||
short cur_data;
|
||||
get_temp_sensors(temps, i2c_dev_path);
|
||||
|
||||
for (int i=0; i<ICX3_NUM_TEMP_SENSORS; i++) {
|
||||
/* endian swap */
|
||||
cur_data = (short)(temp_sensors->data[2*i+1] << 8) | (short)(temp_sensors->data[2*i]);
|
||||
/* temp is reported in tenths of deg C */
|
||||
cur_temp = (float)cur_data/10;
|
||||
printf("%s: %+.1f°C\n",
|
||||
icx3_temp_sensor_names[i],
|
||||
cur_temp);
|
||||
temps[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void print_icx3_temps_oneline(char *i2c_dev_path)
|
||||
{
|
||||
float temps[ICX3_NUM_TEMP_SENSORS];
|
||||
|
||||
get_temp_sensors(temps, i2c_dev_path);
|
||||
|
||||
for (int i=0; i<ICX3_NUM_TEMP_SENSORS; i++) {
|
||||
if (i == 0 || strncmp(icx3_temp_sensor_names[i], icx3_temp_sensor_names[i-1], 3))
|
||||
printf(" %.3s", icx3_temp_sensor_names[i]);
|
||||
printf(" %3.0f", temps[i]);
|
||||
}
|
||||
printf("°C");
|
||||
}
|
||||
|
||||
void get_available_fans(char *i2c_dev_path, char *fans_avail)
|
||||
{
|
||||
int product_id = check_for_icx3(i2c_dev_path);
|
||||
@@ -155,6 +142,62 @@ void get_available_fans(char *i2c_dev_path, char *fans_avail)
|
||||
}
|
||||
}
|
||||
|
||||
void get_fan_status(struct icx3_fan_control *fans, char *i2c_dev_path)
|
||||
{
|
||||
char data[I2C_SMBUS_BLOCK_MAX] = {};
|
||||
int fd, read_result;
|
||||
|
||||
/* First thing is to check for the product ID to figure out how many fans we have */
|
||||
char fans_avail[ICX3_MAX_FANS] = {0};
|
||||
get_available_fans(i2c_dev_path, fans_avail);
|
||||
|
||||
fd = open_i2c_dev(i2c_dev_path);
|
||||
if (fd == -1)
|
||||
return;
|
||||
|
||||
for (int i=0; i < ICX3_MAX_FANS; i++) {
|
||||
if (!fans_avail[i]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
read_result = i2c_smbus_read_i2c_block_data(fd, ICX3_REG_FANCONTROL + i, ICX3_FANCONTROL_SIZE, data);
|
||||
if (read_result != ICX3_FANCONTROL_SIZE) {
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
memcpy(&fans[i], &data, sizeof(struct icx3_fan_control));
|
||||
}
|
||||
|
||||
close(fd);
|
||||
}
|
||||
|
||||
void get_temp_sensors(float *temps, char *i2c_dev_path)
|
||||
{
|
||||
char data[I2C_SMBUS_BLOCK_MAX] = {};
|
||||
int fd, read_result;
|
||||
struct icx3_temp_sensors *temp_sensors;
|
||||
|
||||
fd = open_i2c_dev(i2c_dev_path);
|
||||
if (fd == -1)
|
||||
return;
|
||||
|
||||
read_result = i2c_smbus_read_i2c_block_data(fd, ICX3_REG_TEMPSENSOR, ICX3_TEMPSENSOR_SIZE, data);
|
||||
close(fd);
|
||||
if (read_result != ICX3_TEMPSENSOR_SIZE)
|
||||
return;
|
||||
temp_sensors = (struct icx3_temp_sensors*) &data;
|
||||
|
||||
float cur_temp;
|
||||
short cur_data;
|
||||
|
||||
for (int i=0; i<ICX3_NUM_TEMP_SENSORS; i++) {
|
||||
/* endian swap */
|
||||
cur_data = (short)(temp_sensors->data[2*i+1] << 8) | (short)(temp_sensors->data[2*i]);
|
||||
/* temp is reported in tenths of deg C */
|
||||
temps[i] = (float)cur_data/10;
|
||||
}
|
||||
}
|
||||
|
||||
int open_i2c_dev(char *i2c_dev_path)
|
||||
{
|
||||
int fd = open(i2c_dev_path, O_RDONLY);
|
||||
|
||||
Reference in New Issue
Block a user