static void _j4status_sensors_feature_fan_update(J4statusPluginContext *context, J4statusSensorsFeature *feature) { double curr; sensors_get_value(feature->chip, feature->input->number, &curr); double high = -1; if ( feature->max != NULL ) sensors_get_value(feature->chip, feature->max->number, &high); J4statusState state; if ( ( high > 0 ) && ( curr > high ) ) state = J4STATUS_STATE_BAD; else state = J4STATUS_STATE_GOOD; j4status_section_set_state(feature->section, state); if ( ! context->config.show_details ) high = -1; gchar *value; if ( high > 0 ) value = g_strdup_printf("%.0frpm (high = %.0frpm)", curr, high); else value = g_strdup_printf("%.0frpm", curr); j4status_section_set_value(feature->section, value); }
unsigned int get_sensor_data(unsigned int _id, struct sensor_data *_data) { int a, b, c, num; const sensors_chip_name * chip; const sensors_feature * features; const sensors_subfeature * subfeatures; a = num = 0; _data->kind = -1; while ((chip = sensors_get_detected_chips(NULL, &a))) { b = 0; while ((features = sensors_get_features(chip, &b))) { c = 0; while ((subfeatures = sensors_get_all_subfeatures(chip, features, &c))) { if (subfeatures->type == SENSORS_SUBFEATURE_FAN_INPUT) { if (_id == num) { _data->id = _id; _data->chip = chip->addr; _data->sensor = features->number; char *label = sensors_get_label(chip, features); memcpy(_data->label, label, strlen(label)+1); free(label); _data->kind = SENSOR_FAN; sensors_get_value(chip, subfeatures->number, &_data->data); return 1; } num++; } if (subfeatures->type == SENSORS_SUBFEATURE_TEMP_INPUT) { if (_id == num) { _data->id = _id; _data->chip = chip->addr; _data->sensor = features->number; char *label = sensors_get_label(chip, features); memcpy(_data->label, label, strlen(label)+1); free(label); _data->kind = SENSOR_TEMP; sensors_get_value(chip, subfeatures->number, &_data->data); return 1; } num++; } } } } return 0; }
void HwmonDriver::readEvents(mxml_node_t *const) { int err = sensors_init(NULL); if (err) { logg->logMessage("Failed to initialize libsensors! (%d)", err); return; } sensors_sysfs_no_scaling = 1; int chip_nr = 0; const sensors_chip_name *chip; while ((chip = sensors_get_detected_chips(NULL, &chip_nr))) { int feature_nr = 0; const sensors_feature *feature; while ((feature = sensors_get_features(chip, &feature_nr))) { // Keep in sync with HwmonCounter::read // Can this counter be read? double value; const sensors_subfeature *const subfeature = sensors_get_subfeature(chip, feature, getInput(feature->type)); if ((subfeature == NULL) || (sensors_get_value(chip, subfeature->number, &value) != 0)) { continue; } // Get the name of the counter int len = sensors_snprintf_chip_name(NULL, 0, chip) + 1; char *chip_name = new char[len]; sensors_snprintf_chip_name(chip_name, len, chip); len = snprintf(NULL, 0, "hwmon_%s_%d_%d", chip_name, chip_nr, feature->number) + 1; char *const name = new char[len]; snprintf(name, len, "hwmon_%s_%d_%d", chip_name, chip_nr, feature->number); delete [] chip_name; setCounters(new HwmonCounter(getCounters(), name, chip, feature)); } } }
void print_chip_raw(const sensors_chip_name *name) { int a, b, err; const sensors_feature *feature; const sensors_subfeature *sub; char *label; double val; a = 0; while ((feature = sensors_get_features(name, &a))) { if (!(label = sensors_get_label(name, feature))) { fprintf(stderr, "ERROR: Can't get label of feature " "%s!\n", feature->name); continue; } printf("%s:\n", label); free(label); b = 0; while ((sub = sensors_get_all_subfeatures(name, feature, &b))) { if (sub->flags & SENSORS_MODE_R) { if ((err = sensors_get_value(name, sub->number, &val))) fprintf(stderr, "ERROR: Can't get " "value of subfeature %s: %s\n", sub->name, sensors_strerror(err)); else printf(" %s: %.3f\n", sub->name, val); } else printf("(%s)\n", label); } } }
static int get_input_value(const sensors_chip_name * name, const sensors_subfeature * sf, double * val) { int err; err = sensors_get_value(name, sf->number, val); if(err) { // TODO: error-handling here } return err; }
static void _j4status_sensors_feature_temp_update(J4statusPluginContext *context, J4statusSensorsFeature *feature) { double curr; sensors_get_value(feature->chip, feature->input->number, &curr); double high = -1; if ( feature->max != NULL ) sensors_get_value(feature->chip, feature->max->number, &high); double crit = -1; if ( feature->crit != NULL ) sensors_get_value(feature->chip, feature->crit->number, &crit); J4statusState state; if ( ( high > 0 ) && ( curr > high ) ) state = J4STATUS_STATE_BAD; else state = J4STATUS_STATE_GOOD; if ( ( crit > 0 ) && ( curr > crit ) ) state |= J4STATUS_STATE_URGENT; if ( ( ! context->started ) && ( ( state & J4STATUS_STATE_URGENT ) == 0 ) ) return; j4status_section_set_state(feature->section, state); if ( ! context->config.show_details ) high = crit = -1; gchar *value; if ( ( high > 0 ) && ( crit > 0 ) ) value = g_strdup_printf("%+.1f°C (high = %+.1f°C, crit = %+.1f°C)", curr, high, crit); else if ( high > 0 ) value = g_strdup_printf("%+.1f°C (high = %+.1f°C)", curr, high); else if ( crit > 0 ) value = g_strdup_printf("%+.1f°C (crit = %+.1f°C)", curr, crit); else value = g_strdup_printf("%+.1f°C", curr); j4status_section_set_value(feature->section, value); }
static double get_value(const sensors_chip_name * name, const sensors_subfeature * sf) { double val; int err; err = sensors_get_value(name, sf->number, &val); if(err) { // TODO: error-handling here val = 0; } return val; }
static double get_value(const sensors_chip_name *name, const sensors_subfeature *sub) { double val; int err; err = sensors_get_value(name, sub->number, &val); if (err) { fprintf(stderr, "ERROR: Can't get value of subfeature %s\n", sub->name); val = 0; } return val; }
/* A variant for input values, where we want to handle errors gracefully */ static int get_input_value(const sensors_chip_name *name, const sensors_subfeature *sub, double *val) { int err; err = sensors_get_value(name, sub->number, val); if (err && err != -SENSORS_ERR_ACCESS_R) { fprintf(stderr, "ERROR: Can't get value of subfeature %s: %s\n", sub->name, sensors_strerror(err)); } return err; }
double Feature::getValue(sensors_subfeature_type subfeature_type) const { double result = 0; const sensors_subfeature *subfeature; // Find feature subfeature = sensors_get_subfeature(mSensorsChipName, mSensorsFeature, subfeature_type); if (subfeature) { sensors_get_value(mSensorsChipName, subfeature->number, &result); } return result; }
static int get_flag(const sensors_chip_name *chip, int num) { double val; int ret; if (num == -1) return 0; ret = sensors_get_value(chip, num, &val); if (ret) { sensorLog(LOG_ERR, "Error getting sensor data: %s/#%d: %s", chip->prefix, num, sensors_strerror(ret)); return -1; } return (int) (val + 0.5); }
static int l_readAll(lua_State *L) { sensors_init(NULL); const sensors_chip_name *scn; const sensors_feature *sf; const sensors_subfeature *ss; int n, n1, n2, err; double r; char scns[80]; lua_newtable(L); //Push new table on to stack. Index -1 for(n = 0; (scn = sensors_get_detected_chips(NULL, &n)) != NULL; ) { // Iterate over detected chips for(n1 = 0; (sf = sensors_get_features(scn, &n1)) != NULL; ) // Iterate over features of chip for(n2 = 0; (ss = sensors_get_all_subfeatures(scn, sf, &n2)) != NULL; ) { // Iterate over subfeatures of features from chip sprintf(scns, "%s-%x-%x__%s", scn->prefix, scn->bus.nr, scn->addr, ss->name); // Set scns to (chip.prefix - chip.bus.nr - chip.addr __ subfeature.name ) err = sensors_get_value(scn, ss->number, &r); // Get value from chip using subfeature.number, store result in r. If err != 0 then an error occured. if (err == 0) { // Sensor data. Addres in char* scns, name in ss->name, result in r lua_pushnumber(L, r); //Push table value on stack. Table is now at -2 lua_setfield(L, -2, scns); //Set 3rd argument as key in table at stack index -2 to stack index -1 } else { return(luaL_error(L, "Can't read sensors!")); } } } sensors_cleanup(); return(1); }
static void print_chip_vid(const sensors_chip_name *name, const sensors_feature *feature, int label_size) { char *label; const sensors_subfeature *subfeature; double vid; subfeature = sensors_get_subfeature(name, feature, SENSORS_SUBFEATURE_VID); if (!subfeature) return; if ((label = sensors_get_label(name, feature)) && !sensors_get_value(name, subfeature->number, &vid)) { print_label(label, label_size); printf("%+6.3f V\n", vid); } free(label); }
static void print_chip_humidity(const sensors_chip_name *name, const sensors_feature *feature, int label_size) { char *label; const sensors_subfeature *subfeature; double humidity; subfeature = sensors_get_subfeature(name, feature, SENSORS_SUBFEATURE_HUMIDITY_INPUT); if (!subfeature) return; if ((label = sensors_get_label(name, feature)) && !sensors_get_value(name, subfeature->number, &humidity)) { print_label(label, label_size); printf("%6.1f %%RH\n", humidity); } free(label); }
static double get_temperature(struct temperature* temp) { assert(temp); double value = 0.0; for (size_t i = 0; i < temp->count; ++i) { double dummy = 0.0; int const ret = sensors_get_value(temp->chip, temp->numbers[i], &dummy); if (ret < 0) { fprintf(stderr, u8"Could not get temperature value from subfeature %d.\n", temp->numbers[i]); } value = value >= dummy ? value : dummy; } return value; }
static void print_chip_beep_enable(const sensors_chip_name *name, const sensors_feature *feature, int label_size) { char *label; const sensors_subfeature *subfeature; double beep_enable; subfeature = sensors_get_subfeature(name, feature, SENSORS_SUBFEATURE_BEEP_ENABLE); if (!subfeature) return; if ((label = sensors_get_label(name, feature)) && !sensors_get_value(name, subfeature->number, &beep_enable)) { print_label(label, label_size); printf("%s\n", beep_enable ? "enabled" : "disabled"); } free(label); }
static void print_chip_intrusion(const sensors_chip_name *name, const sensors_feature *feature, int label_size) { char *label; const sensors_subfeature *subfeature; double alarm; subfeature = sensors_get_subfeature(name, feature, SENSORS_SUBFEATURE_INTRUSION_ALARM); if (!subfeature) return; if ((label = sensors_get_label(name, feature)) && !sensors_get_value(name, subfeature->number, &alarm)) { print_label(label, label_size); printf("%s\n", alarm ? "ALARM" : "OK"); } free(label); }
bool HwmonCounter::canRead() { if (!polled) { double value; const sensors_subfeature *subfeature; bool result = true; subfeature = sensors_get_subfeature(chip, feature, input); if (!subfeature) { result = false; } else { result = sensors_get_value(chip, subfeature->number, &value) == 0; } polled = true; readable = result; } enabled &= readable; return readable; }
static gdouble libsensors_plugin_get_sensor_value(const gchar *path, const gchar *id, SensorType type, GError **error) { gdouble result = 0; regmatch_t m[3]; /* parse the uri into a (chip, feature) tuplet */ if (regexec (&uri_re, path, 3, m, 0) == 0) { const sensors_chip_name *found_chip; int feature; int i; if ((found_chip = g_hash_table_lookup(hash_table, path)) != NULL) { gdouble value; feature = atoi(path + m[2].rm_so); #if SENSORS_API_VERSION < 0x400 /* retrieve the value of the feature */ if (sensors_get_feature (*found_chip, feature, &value) == 0) { result = value; } else { g_set_error (error, SENSORS_APPLET_PLUGIN_ERROR, LIBSENSORS_MISSING_FEATURE_ERROR, "Error retrieving sensor value"); } #else if (sensors_get_value(found_chip, feature, &value) >= 0) { result = value; } else { g_set_error (error, SENSORS_APPLET_PLUGIN_ERROR, LIBSENSORS_MISSING_FEATURE_ERROR, "Error retrieving sensor value"); } #endif } else { g_set_error (error, SENSORS_APPLET_PLUGIN_ERROR, LIBSENSORS_CHIP_NOT_FOUND_ERROR, "Chip not found"); } } else { g_set_error (error, SENSORS_APPLET_PLUGIN_ERROR, LIBSENSORS_REGEX_URL_COMPILE_ERROR, "Error compiling URL regex"); } return result; }
static PyObject* get_value(ChipName *self, PyObject *args, PyObject *kwargs) { char *kwlist[] = {"subfeat_nr", NULL}; int subfeat_nr = -1; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i", kwlist, &subfeat_nr)) { return NULL; } double value = 0.0; int status = sensors_get_value(&self->chip_name, subfeat_nr, &value); if (status < 0) { PyErr_SetString(SensorsException, sensors_strerror(status)); return NULL; } return PyFloat_FromDouble(value); }
int64_t HwmonCounter::read() { double value; double result; const sensors_subfeature *subfeature; // Keep in sync with the read check in HwmonDriver::readEvents subfeature = sensors_get_subfeature(chip, feature, getInput(feature->type)); if (!subfeature) { logg->logError(__FILE__, __LINE__, "No input value for hwmon sensor %s", label); handleException(); } if (sensors_get_value(chip, subfeature->number, &value) != 0) { logg->logError(__FILE__, __LINE__, "Can't get input value for hwmon sensor %s", label); handleException(); } result = (monotonic ? value - previous_value : value); previous_value = value; return result; }
int64_t HwmonCounter::read() { double value; double result; const sensors_subfeature *subfeature; // Keep in sync with the read check in HwmonDriver::readEvents subfeature = sensors_get_subfeature(mChip, mFeature, getInput(mFeature->type)); if (!subfeature) { logg.logError("No input value for hwmon sensor %s", mLabel); handleException(); } if (sensors_get_value(mChip, subfeature->number, &value) != 0) { logg.logError("Can't get input value for hwmon sensor %s", mLabel); handleException(); } result = (mMonotonic ? value - mPreviousValue : value); mPreviousValue = value; return result; }
int main(int argc, char* argv[]) { unsigned char r, g, b; struct timespec tms; const sensors_chip_name *chip; const sensors_feature *feature; int nr, subfeat_nr; double temp, used_temp, cpu_percent, ram_free_percent; FILE *cpufile; // Open the sensors if(sensors_init(NULL) != 0) { printf("Error initializing the sensors\n"); return 1; } atexit(sensors_cleanup); // Ready to open lights // Open the device using the VID, PID handle = hid_open(0x1770, 0xff00, NULL); if (!handle) { printf("Unable to open MSI Led device.\n"); return 1; } signal(SIGINT, signal_callback_handler); while(1) { nr = 0; used_temp = 0; while((chip = sensors_get_detected_chips(NULL, &nr)) != NULL) { subfeat_nr = 0; while((feature = sensors_get_features(chip, &subfeat_nr)) != NULL) { // Uncomment the next printfs to get your device and subdevice ID //printf("%s [%d,%d] ", sensors_get_label(chip, feature), nr-1, subfeat_nr-1); if(sensors_get_value(chip, subfeat_nr-1, &temp) == 0) { //printf(" = %.2fºC\n", temp); } else { //printf(" = NO DATA\n"); } if(nr-1 == DEVICE_ID && subfeat_nr-1 == SUBDEV_ID) used_temp = temp; } } if(used_temp <= 0) r = 0; // No data. Make it full green (zero red) else r = CLAMP(0, 0xFF*(used_temp - TEMP_LOW)/(TEMP_HIGH - TEMP_LOW), 0xFF); g = 0xFF - r; // Fade from red to green b = 0; commit(handle, MODE_NORMAL); // You have to commit first in GE60 (?) sendActivateArea(handle, AREA_LEFT, r, g, b); // Get CPU info cpu_percent = 0.0; cpufile = fopen("/proc/loadavg", "r"); if(cpufile) { fscanf(cpufile, "%lf", &cpu_percent); fclose(cpufile); } cpu_percent /= NUMBER_CPUS; r = 0; g = 0xFF; b = CLAMP(0, 0xFF * cpu_percent, 0xFF); //printf("CPU: %.2f\n", cpu_percent * 100.0); sendActivateArea(handle, AREA_MIDDLE, r, g, b); // Get RAM info ram_free_percent = get_ram_free(); //printf("RAM: %.2lf\n", ram_used_percent); b = CLAMP(0, 0xFF * ram_free_percent, 0xFF); r = 0xFF - b; g = 0; sendActivateArea(handle, AREA_RIGHT, r, g, b); tms.tv_sec = REFRESH_INTERVAL; tms.tv_nsec = 0; nanosleep(&tms, NULL); } // This should never be executed tho... hid_close(handle); handle = NULL; hid_exit(); return 0; }
int get_temp() { double val; sensors_get_value(sd.chip_name_temp, sd.number_temp, &val); return (int)val; }
int netsnmp_sensor_arch_load(netsnmp_cache *cache, void *vp) { netsnmp_sensor_info *sp; const sensors_chip_name *chip; const sensors_feature *data; const sensors_subfeature *data2; int chip_nr = 0; DEBUGMSGTL(("sensors:arch", "Reload v3 LM Sensors module\n")); while ((chip = sensors_get_detected_chips( NULL, &chip_nr))) { int a = 0; while ((data = sensors_get_features( chip, &a))) { DEBUGMSGTL(("sensors:arch:detail", "get_features (%s, %d)\n", data->name, data->number)); int b = 0; while ((data2 = sensors_get_all_subfeatures( chip, data, &b))) { char *label = NULL; double val; int type = NETSNMP_SENSOR_TYPE_OTHER; DEBUGMSGTL(("sensors:arch:detail", " get_subfeatures (%s, %d)\n", data2->name, data2->number)); /* * Check the type of this subfeature, * concentrating on the main "input" measurements. */ switch ( data2->type ) { case SENSORS_SUBFEATURE_IN_INPUT: type = NETSNMP_SENSOR_TYPE_VOLTAGE_DC; break; case SENSORS_SUBFEATURE_FAN_INPUT: type = NETSNMP_SENSOR_TYPE_RPM; break; case SENSORS_SUBFEATURE_TEMP_INPUT: type = NETSNMP_SENSOR_TYPE_TEMPERATURE; break; case SENSORS_SUBFEATURE_VID: type = NETSNMP_SENSOR_TYPE_VOLTAGE_DC; break; default: /* Skip everything other than these basic sensor features - ??? */ DEBUGMSGTL(("sensors:arch:detail", " Skip type %x\n", data2->type)); continue; } /* * Get the name and value of this subfeature */ /* if (!(label = sensors_get_label(chip, data))) { DEBUGMSGTL(("sensors:arch:detail", " Can't get name (%s)\n", label)); continue; } if (sensors_get_value(chip, data2->number, &val) < 0) { DEBUGMSGTL(("sensors:arch:detail", " Can't get value (%f)\n", val)); continue; } */ if (!(label = sensors_get_label(chip, data)) || (sensors_get_value(chip, data2->number, &val) < 0)) { DEBUGMSGTL(("sensors:arch:detail", " Can't get name/value (%s, %f)\n", label, val)); free(label); label = NULL; continue; } DEBUGMSGTL(("sensors:arch:detail", "%s = %f\n", label, val)); /* * Use this type to create a new sensor entry * (inserting it in the appropriate sub-containers) */ sp = sensor_by_name( label, type ); if ( sp ) { sp->value = val; sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE; } if (label) { free(label); label = NULL; } } /* end while data2 */ } /* end while data */ } /* end while chip */ return 0; }
static int do_features(const sensors_chip_name *chip, const FeatureDescriptor *feature, int action) { char *label; const char *formatted; int i, alrm, beep, ret; double val[MAX_DATA]; /* If only scanning, take a quick exit if alarm is off */ alrm = get_flag(chip, feature->alarmNumber); if (alrm == -1) return -1; if (action == DO_SCAN && !alrm) return 0; for (i = 0; feature->dataNumbers[i] >= 0; i++) { ret = sensors_get_value(chip, feature->dataNumbers[i], val + i); if (ret) { sensorLog(LOG_ERR, "Error getting sensor data: %s/#%d: %s", chip->prefix, feature->dataNumbers[i], sensors_strerror(ret)); return -1; } } /* For RRD, we don't need anything else */ if (action == DO_RRD) { if (feature->rrd) { const char *rrded = feature->rrd(val); sprintf(rrdBuff + strlen(rrdBuff), ":%s", rrded ? rrded : "U"); } return 0; } /* For scanning and logging, we need extra information */ beep = get_flag(chip, feature->beepNumber); if (beep == -1) return -1; formatted = feature->format(val, alrm, beep); if (!formatted) { sensorLog(LOG_ERR, "Error formatting sensor data"); return -1; } /* FIXME: It would be more efficient to store the label at * initialization time. */ label = sensors_get_label(chip, feature->feature); if (!label) { sensorLog(LOG_ERR, "Error getting sensor label: %s/%s", chip->prefix, feature->feature->name); return -1; } if (action == DO_READ) sensorLog(LOG_INFO, " %s: %s", label, formatted); else sensorLog(LOG_ALERT, "Sensor alarm: Chip %s: %s: %s", chipName(chip), label, formatted); free(label); return 0; }
static int sensors_read (void) { if (sensors_load_conf () != 0) return (-1); #if SENSORS_API_VERSION < 0x400 for (featurelist_t *fl = first_feature; fl != NULL; fl = fl->next) { double value; int status; char plugin_instance[DATA_MAX_NAME_LEN]; char type_instance[DATA_MAX_NAME_LEN]; status = sensors_get_feature (*fl->chip, fl->data->number, &value); if (status < 0) continue; status = sensors_snprintf_chip_name (plugin_instance, sizeof (plugin_instance), fl->chip); if (status < 0) continue; sstrncpy (type_instance, fl->data->name, sizeof (type_instance)); sensors_submit (plugin_instance, sensor_type_name_map[fl->type], type_instance, value); } /* for fl = first_feature .. NULL */ /* #endif SENSORS_API_VERSION < 0x400 */ #elif (SENSORS_API_VERSION >= 0x400) && (SENSORS_API_VERSION < 0x500) for (featurelist_t *fl = first_feature; fl != NULL; fl = fl->next) { double value; int status; char plugin_instance[DATA_MAX_NAME_LEN]; char type_instance[DATA_MAX_NAME_LEN]; char *sensor_label; const char *type; status = sensors_get_value (fl->chip, fl->subfeature->number, &value); if (status < 0) continue; status = sensors_snprintf_chip_name (plugin_instance, sizeof (plugin_instance), fl->chip); if (status < 0) continue; if (use_labels) { sensor_label = sensors_get_label (fl->chip, fl->feature); sstrncpy (type_instance, sensor_label, sizeof (type_instance)); free (sensor_label); } else { sstrncpy (type_instance, fl->feature->name, sizeof (type_instance)); } if (fl->feature->type == SENSORS_FEATURE_IN) type = "voltage"; else if (fl->feature->type == SENSORS_FEATURE_FAN) type = "fanspeed"; else if (fl->feature->type == SENSORS_FEATURE_TEMP) type = "temperature"; else if (fl->feature->type == SENSORS_FEATURE_POWER) type = "power"; else continue; sensors_submit (plugin_instance, type, type_instance, value); } /* for fl = first_feature .. NULL */ #endif /* (SENSORS_API_VERSION >= 0x400) && (SENSORS_API_VERSION < 0x500) */ return (0); } /* int sensors_read */
static GList *libsensors_plugin_get_sensors(void) { const sensors_chip_name *chip_name; int i; GList *sensors = NULL; #if SENSORS_API_VERSION < 0x400 FILE *file; g_debug("%s: using libsensors version < 4", __FUNCTION__); /* try to open config file, otherwise try alternate config * file - if neither succeed, exit */ if ((file = fopen (LIBSENSORS_CONFIG_FILE, "r")) == NULL) { if ((file = fopen (LIBSENSORS_ALTERNATIVE_CONFIG_FILE, "r")) == NULL) { g_debug("%s: error opening libsensors config file... ", __FUNCTION__); return sensors; } } /* at this point should have an open config file, if is not * valid, close file and return */ if (sensors_init(file) != 0) { fclose(file); g_debug("%s: error initing libsensors from config file...", __FUNCTION__); return sensors; } fclose(file); /* libsensors exposes a number of chips - ... */ i = 0; while ((chip_name = sensors_get_detected_chips (&i)) != NULL) { char *chip_name_string; const sensors_feature_data *data; int n1 = 0, n2 = 0; chip_name_string = get_chip_name_string(chip_name); /* ... each of which has one or more 'features' ... */ while ((data = sensors_get_all_features (*chip_name, &n1, &n2)) != NULL) { // error // fill in list for us check_sensor_with_data(&sensors, chip_name_string, chip_name, &n1, &n2, data); } g_free (chip_name_string); } #else g_debug("%s: using libsensors version >= 4", __FUNCTION__); int nr = 0; if (sensors_init(NULL) != 0) { g_debug("%s: error initing libsensors", __FUNCTION__); return sensors; } i = 0; while ((chip_name = sensors_get_detected_chips(NULL, &nr))) { char *chip_name_string, *label; const sensors_subfeature *input_feature; const sensors_subfeature *low_feature; const sensors_subfeature *high_feature; const sensors_feature *main_feature; SensorType type; gint nr1 = 0; gdouble value, low, high; gchar *path; gboolean visible; IconType icon; chip_name_string = get_chip_name_string(chip_name); if (chip_name_string == NULL) { g_debug("%s: %d: error getting name string for sensor: %s\n", __FILE__, __LINE__, chip_name->path); continue; } while ((main_feature = sensors_get_features(chip_name, &nr1))) { switch (main_feature->type) { case SENSORS_FEATURE_IN: type = VOLTAGE_SENSOR; input_feature = sensors_get_subfeature(chip_name, main_feature, SENSORS_SUBFEATURE_IN_INPUT); low_feature = sensors_get_subfeature(chip_name, main_feature, SENSORS_SUBFEATURE_IN_MIN); high_feature = sensors_get_subfeature(chip_name, main_feature, SENSORS_SUBFEATURE_IN_MAX); break; case SENSORS_FEATURE_FAN: type = FAN_SENSOR; input_feature = sensors_get_subfeature(chip_name, main_feature, SENSORS_SUBFEATURE_FAN_INPUT); low_feature = sensors_get_subfeature(chip_name, main_feature, SENSORS_SUBFEATURE_FAN_MIN); // no fan max feature high_feature = NULL; break; case SENSORS_FEATURE_TEMP: type = TEMP_SENSOR; input_feature = sensors_get_subfeature(chip_name, main_feature, SENSORS_SUBFEATURE_TEMP_INPUT); low_feature = sensors_get_subfeature(chip_name, main_feature, SENSORS_SUBFEATURE_TEMP_MIN); high_feature = sensors_get_subfeature(chip_name, main_feature, SENSORS_SUBFEATURE_TEMP_MAX); if (!high_feature) high_feature = sensors_get_subfeature(chip_name, main_feature, SENSORS_SUBFEATURE_TEMP_CRIT); break; default: g_debug("%s: %d: error determining type for: %s\n", __FILE__, __LINE__, chip_name_string); continue; } if (!input_feature) { g_debug("%s: %d: could not get input subfeature for: %s\n", __FILE__, __LINE__, chip_name_string); continue; } // if still here we got input feature so get label label = sensors_get_label(chip_name, main_feature); if (!label) { g_debug("%s: %d: error: could not get label for: %s\n", __FILE__, __LINE__, chip_name_string); continue; } g_assert(chip_name_string && label); icon = get_sensor_icon(type); visible = (type == TEMP_SENSOR ? TRUE : FALSE); sensors_applet_plugin_default_sensor_limits(type, &low, &high); if (low_feature) { sensors_get_value(chip_name, low_feature->number, &low); } if (high_feature) { sensors_get_value(chip_name, high_feature->number, &high); } if (sensors_get_value(chip_name, input_feature->number, &value) < 0) { g_debug("%s: %d: error: could not get value for input feature of sensor: %s\n", __FILE__, __LINE__, chip_name_string); free(label); continue; } g_debug("for chip %s (type %s) got label %s and value %f", chip_name_string, (type == TEMP_SENSOR ? "temp" : (type == FAN_SENSOR ? "fan" : (type == VOLTAGE_SENSOR ? "voltage" : "error"))), label, value); path = g_strdup_printf ("sensor://%s/%d", chip_name_string, input_feature->number); g_hash_table_insert(hash_table, g_strdup(path), (void *)chip_name); sensors_applet_plugin_add_sensor_with_limits(&sensors, path, label, label, type, visible, low, high, icon, DEFAULT_GRAPH_COLOR); } g_free(chip_name_string); } #endif return sensors; }
int get_fan() { double val; sensors_get_value(sd.chip_name_fan, sd.number_fan, &val); return (int)val; }