コード例 #1
0
ファイル: sensors.c プロジェクト: SteveJones/j4status
static void
_j4status_sensors_add_sensors(J4statusPluginContext *context, const sensors_chip_name *match)
{
    const sensors_chip_name *chip;
    const sensors_feature *feature;
    int chip_nr = 0;
    while ( ( chip = sensors_get_detected_chips(match, &chip_nr) ) != NULL )
    {
        int feature_nr = 0;
        while ( ( feature = sensors_get_features(chip, &feature_nr) ) != NULL )
        {
            switch (feature->type)
            {
            case SENSORS_FEATURE_TEMP:
                _j4status_sensors_add_feature_temp(context, chip, feature);
            break;
            case SENSORS_FEATURE_FAN:
                _j4status_sensors_add_feature_fan(context, chip, feature);
            break;
            default:
                continue;
            }
        }
    }
}
コード例 #2
0
ファイル: chips.c プロジェクト: AlisonSchofield/lm-sensors
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);
		}
	}
}
コード例 #3
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));
		}
	}
}
コード例 #4
0
ファイル: chips.c プロジェクト: AlisonSchofield/lm-sensors
static FeatureDescriptor * generateChipFeatures(const sensors_chip_name *chip)
{
	int nr, count = 1;
	const sensors_feature *sensor;
	FeatureDescriptor *features;

	/* How many main features do we have? */
	nr = 0;
	while ((sensor = sensors_get_features(chip, &nr)))
		count++;

	/* Allocate the memory we need */
	features = calloc(count, sizeof(FeatureDescriptor));
	if (!features)
		return NULL;

	/* Fill in the data structures */
	count = 0;
	nr = 0;
	while ((sensor = sensors_get_features(chip, &nr))) {
		switch (sensor->type) {
		case SENSORS_FEATURE_TEMP:
			fillChipTemperature(&features[count], chip, sensor);
			break;
		case SENSORS_FEATURE_IN:
			fillChipVoltage(&features[count], chip, sensor);
			break;
		case SENSORS_FEATURE_FAN:
			fillChipFan(&features[count], chip, sensor);
			break;
		case SENSORS_FEATURE_VID:
			fillChipVid(&features[count], chip, sensor);
			break;
		case SENSORS_FEATURE_BEEP_ENABLE:
			fillChipBeepEnable(&features[count], chip, sensor);
			break;
		default:
			continue;
		}

		features[count].feature = sensor;
		count++;
	}

	return features;
}
コード例 #5
0
ファイル: lm_sensors4.c プロジェクト: 08opt/istatd
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;
}
コード例 #6
0
   Chip(const sensors_chip_name * c) : chip(c) {
      // populate name
      if(sensors_snprintf_chip_name(name, NAME_SZ, c) < 0) {
         // error: bad chip name
         snprintf(name, NAME_SZ, "Unknown chip");
      }

      // populate features
      int i = 0;
      const sensors_feature * feature;
      while( (feature = sensors_get_features(chip, &i)) ) {
         features.push_back(Feature(c, feature));
      }
   }
コード例 #7
0
SensorChip::SensorChip(sensors_chip_name const *chip_name,
    const std::vector<std::string> &ignore) :
  internal_name_(chip_name)
{
  char name_buffer[NAME_BUFFER_SIZE];
  sensors_snprintf_chip_name(name_buffer, NAME_BUFFER_SIZE, internal_name_);
  name_ = name_buffer;

  ROS_DEBUG("Found Sensor: %s", getName().c_str());

  // enumerate the features of this sensor
  sensors_feature const *feature;
  int number = 0;

  while ((feature = sensors_get_features(internal_name_, &number)) != NULL) {
    sensors_feature_type type = feature->type;
    SensorChipFeaturePtr feature_ptr;
    switch(type){
    case SENSORS_FEATURE_FAN:
      feature_ptr.reset(new FanSensor(*this, feature));
      break;
    case SENSORS_FEATURE_TEMP:
      feature_ptr.reset(new TempSensor(*this, feature));
      break;
    case SENSORS_FEATURE_IN:
      feature_ptr.reset(new VoltageSensor(*this, feature));
      break;
    default:
      feature_ptr.reset(new OtherSensor(*this, feature));
      break;
    }

    if( std::count(ignore.begin(), ignore.end(),
          feature_ptr->getFullName()) > 0 ) {
      ROS_INFO_STREAM("Ignoring sensor " << feature_ptr->getFullName());
    } else {
      features_.push_back(feature_ptr);
    }
  }

  std::stringstream info_msg;
  info_msg << "Found sensor " << getName();
  if( features_.size() > 0 ) {
    info_msg << " with features: ";
    size_t remain = features_.size();
    BOOST_FOREACH(const SensorChipFeaturePtr & feature, features_) {
      remain--;
      info_msg << feature->getFeatureName();
      if( remain > 0 ) info_msg << ", ";
    }
コード例 #8
0
ファイル: hud_sensors_temp.c プロジェクト: etnaviv/mesa
static void
build_sensor_list(void)
{
   const sensors_chip_name *chip;
   const sensors_chip_name *match = 0;
   const sensors_feature *feature;
   int chip_nr = 0;

   char name[256];
   while ((chip = sensors_get_detected_chips(match, &chip_nr))) {
      sensors_snprintf_chip_name(name, sizeof(name), chip);

      /* Get all features and filter accordingly. */
      int fnr = 0;
      while ((feature = sensors_get_features(chip, &fnr))) {
         char *featurename = sensors_get_label(chip, feature);
         if (!featurename)
            continue;

         /* Create a 'current' and 'critical' object pair.
          * Ignore sensor if its not temperature based.
          */
         switch(feature->type) {
         case SENSORS_FEATURE_TEMP:
            create_object(name, featurename, chip, feature,
                          SENSORS_TEMP_CURRENT);
            create_object(name, featurename, chip, feature,
                          SENSORS_TEMP_CRITICAL);
            break;
         case SENSORS_FEATURE_IN:
            create_object(name, featurename, chip, feature,
                          SENSORS_VOLTAGE_CURRENT);
            break;
         case SENSORS_FEATURE_CURR:
            create_object(name, featurename, chip, feature,
                          SENSORS_CURRENT_CURRENT);
            break;
         case SENSORS_FEATURE_POWER:
            create_object(name, featurename, chip, feature,
                          SENSORS_POWER_CURRENT);
            break;
         default:
            break;
         }
         free(featurename);
      }
   }
}
コード例 #9
0
LMSensorList::LMSensorList()
{
    sensors_init(NULL);
    int sensor_i = 0;
    const sensors_chip_name *sc;

    while ((sc = sensors_get_detected_chips(NULL, &sensor_i))) {
        int feature_i = 0;
        const sensors_feature *sf;
        while ((sf = sensors_get_features(sc, &feature_i)))
        {
            LMSensor *lms = new LMSensor(sc, sf);
            m_sensors.push_back(lms);
        }
    }
}
コード例 #10
0
ファイル: chipname.c プロジェクト: sophiekovalevsky/pysensors
static PyObject*
get_features(ChipName *self, PyObject *args)
{
    PyObject *list = PyList_New(0);
    int n = 0;

    (void)args;

    while (1)
    {
        const sensors_feature *feature = sensors_get_features(&self->chip_name,
                                                              &n);
        if (feature == NULL)
        {
            break;
        }
        else
        {
            /* Some internal fields are not accessible with
             * __init__(), so we need to copy them ourselves.  We
             * bypass __init__() altogether. */
            Feature *py_feature = PyObject_New(Feature,
                                               &FeatureType);

            if (py_feature == NULL)
            {
                goto error;
            }

            py_feature->feature = *feature;

            /* Duplicate the name string, so that destructors won't
             * end up freeing the same string pointer multiple
             * times. */
            py_feature->feature.name = strdup(feature->name);
            py_feature->py_name = PyString_FromString(feature->name);
            PyList_Append(list, (PyObject*)py_feature);
            Py_DECREF(py_feature);
        }
    }

    return list;

error:
    Py_DECREF(list);
    return NULL;
}
コード例 #11
0
ファイル: main.c プロジェクト: Biolunar/dstatus
static struct temperature* temperature_init(void)
{
	int chip_nr = 0;
	struct temperature* temp = 0;

	if (sensors_init(0))
	{
		fprintf(stderr, u8"Could not initialize libsensors.\n");
		return 0;
	}

	temp = calloc(1, sizeof(struct temperature));
	if (!temp)
	{
		fprintf(stderr, u8"Could not allocate memory for temperature struct.\n");
		return 0;
	}

	while ((temp->chip = sensors_get_detected_chips(0, &chip_nr)))
	{
		if (!strcmp(chip_name, temp->chip->prefix))
		{
			int feature_nr = 0;
			sensors_feature const* feat = 0;
			while ((feat = sensors_get_features(temp->chip, &feature_nr)))
			{
				if (feat->type == SENSORS_FEATURE_TEMP)
				{
					sensors_subfeature const* sub = sensors_get_subfeature(temp->chip, feat, SENSORS_SUBFEATURE_TEMP_INPUT);
					if (!sub)
					{
						fprintf(stderr, u8"Could not get chip subfeature.\n");
						return 0;
					}

					++temp->count;
					temp->numbers = realloc(temp->numbers, temp->count * sizeof(int));
					temp->numbers[temp->count - 1] = sub->number;
				}
			}

			return temp;
		}
	}

	return 0;
}
コード例 #12
0
ファイル: chips.c プロジェクト: AlisonSchofield/lm-sensors
void print_chip(const sensors_chip_name *name)
{
	const sensors_feature *feature;
	int i, label_size;

	label_size = get_label_size(name);

	i = 0;
	while ((feature = sensors_get_features(name, &i))) {
		switch (feature->type) {
		case SENSORS_FEATURE_TEMP:
			print_chip_temp(name, feature, label_size);
			break;
		case SENSORS_FEATURE_IN:
			print_chip_in(name, feature, label_size);
			break;
		case SENSORS_FEATURE_FAN:
			print_chip_fan(name, feature, label_size);
			break;
		case SENSORS_FEATURE_VID:
			print_chip_vid(name, feature, label_size);
			break;
		case SENSORS_FEATURE_BEEP_ENABLE:
			print_chip_beep_enable(name, feature, label_size);
			break;
		case SENSORS_FEATURE_POWER:
			print_chip_power(name, feature, label_size);
			break;
		case SENSORS_FEATURE_ENERGY:
			print_chip_energy(name, feature, label_size);
			break;
		case SENSORS_FEATURE_CURR:
			print_chip_curr(name, feature, label_size);
			break;
		case SENSORS_FEATURE_INTRUSION:
			print_chip_intrusion(name, feature, label_size);
			break;
		case SENSORS_FEATURE_HUMIDITY:
			print_chip_humidity(name, feature, label_size);
			break;
		default:
			continue;
		}
	}
}
コード例 #13
0
ファイル: chips.c プロジェクト: AlisonSchofield/lm-sensors
static int get_label_size(const sensors_chip_name *name)
{
	int i;
	const sensors_feature *iter;
	char *label;
	unsigned int max_size = 11;	/* 11 as minimum label width */

	i = 0;
	while ((iter = sensors_get_features(name, &i))) {
		if ((label = sensors_get_label(name, iter)) &&
		    strlen(label) > max_size)
			max_size = strlen(label);
		free(label);
	}

	/* One more for the colon, and one more to guarantee at least one
	   space between that colon and the value */
	return max_size + 2;
}
コード例 #14
0
ファイル: sensors.c プロジェクト: max1220/lua-sensor
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);
}
コード例 #15
0
ファイル: eeepc-fanctld.c プロジェクト: poliva/eeepc-fanctld
int init_sensor_data() {

	const sensors_chip_name *chip_name;
	const sensors_feature *feature;
	const sensors_subfeature *subfeature;
	char *label;
	int fan_enabled=FALSE, temperature_enabled=FALSE;
	int a,b,c;

	a=0;
	while ( (chip_name = sensors_get_detected_chips(NULL, &a)) ) {

		b=0;
		while ( (feature = sensors_get_features(chip_name, &b)) ) {

			c=0;
			while ( (subfeature = sensors_get_all_subfeatures(chip_name, feature, &c)) ) {
				label = sensors_get_label(chip_name, feature);
				if ( strcmp(CPU_TEMP, label)==0 ) {
					printf ("Found sensor: %s (cpu temperature)\n", CPU_TEMP);
					sd.chip_name_temp=chip_name;
					sd.number_temp=subfeature->number;
					temperature_enabled=TRUE;
					break;
				}
				if (subfeature->type == SENSORS_SUBFEATURE_FAN_INPUT) {
					printf ("Found FAN sensor\n");
					sd.chip_name_fan=chip_name;
					sd.number_fan=subfeature->number;
					fan_enabled=TRUE;
					break;
				}
			}
		}
	}

	if (fan_enabled==TRUE && temperature_enabled==TRUE)
		return TRUE;
	return FALSE;
}
コード例 #16
0
ファイル: Hwmon.cpp プロジェクト: mreyna1216/gator
void Hwmon::setup() {
	// hwmon does not currently work with perf
	if (gSessionData->perf.isSetup()) {
		return;
	}

	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))) {
			counters = new HwmonCounter(counters, chip, feature);
		}
	}
}
コード例 #17
0
ファイル: lm_sensors4.c プロジェクト: mikedamage/istatd
unsigned int get_sensor_num(void)
{
	int a, b, c, num;
	const sensors_chip_name * chip;
	const sensors_feature * features;
	const sensors_subfeature * subfeatures;
	
	a = num = 0;

	sensors_init(NULL);

	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)
				{
					// chip = chip->addr
					// sensor = features->number
					num++; break;
				}
					
				if (subfeatures->type != SENSORS_SUBFEATURE_TEMP_INPUT)
				{
					num++; break;
				}
			}
		}
	}
	
	return num;
}
コード例 #18
0
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;
}
コード例 #19
0
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;
}
コード例 #20
0
ファイル: sensors.c プロジェクト: Whissi/collectd
static int sensors_load_conf (void)
{
	static int call_once = 0;

	FILE *fh = NULL;
	featurelist_t *last_feature = NULL;

	const sensors_chip_name *chip;
	int chip_num;

	int status;

	if (call_once)
		return 0;

	call_once = 1;

	if (conffile != NULL)
	{
		fh = fopen (conffile, "r");
		if (fh == NULL)
		{
			char errbuf[1024];
			ERROR ("sensors plugin: fopen(%s) failed: %s", conffile,
					sstrerror (errno, errbuf, sizeof (errbuf)));
			return (-1);
		}
	}

	status = sensors_init (fh);
	if (fh)
		fclose (fh);

	if (status != 0)
	{
		ERROR ("sensors plugin: Cannot initialize sensors. "
				"Data will not be collected.");
		return (-1);
	}

#if SENSORS_API_VERSION < 0x400
	chip_num = 0;
	while ((chip = sensors_get_detected_chips (&chip_num)) != NULL)
	{
		int feature_num0 = 0;
		int feature_num1 = 0;

		while (42)
		{
			const sensors_feature_data *feature;
			int feature_type;
			featurelist_t *fl;

			feature = sensors_get_all_features (*chip,
					&feature_num0, &feature_num1);

			/* Check if all features have been read. */
			if (feature == NULL)
				break;

			/* "master features" only */
			if (feature->mapping != SENSORS_NO_MAPPING)
			{
				DEBUG ("sensors plugin: sensors_load_conf: "
						"Ignoring subfeature `%s', "
						"because (feature->mapping "
						"!= SENSORS_NO_MAPPING).",
						feature->name);
				continue;
			}

			/* skip ignored in sensors.conf */
			if (sensors_get_ignored (*chip, feature->number) == 0)
			{
				DEBUG ("sensors plugin: sensors_load_conf: "
						"Ignoring subfeature `%s', "
						"because "
						"`sensors_get_ignored' told "
						"me so.",
						feature->name);
				continue;
			}

			feature_type = sensors_feature_name_to_type (
					feature->name);
			if (feature_type == SENSOR_TYPE_UNKNOWN)
			{
				DEBUG ("sensors plugin: sensors_load_conf: "
						"Ignoring subfeature `%s', "
						"because its type is "
						"unknown.",
						feature->name);
				continue;
			}

			fl = calloc (1, sizeof (*fl));
			if (fl == NULL)
			{
				ERROR ("sensors plugin: calloc failed.");
				continue;
			}

			fl->chip = chip;
			fl->data = feature;
			fl->type = feature_type;

			if (first_feature == NULL)
				first_feature = fl;
			else
				last_feature->next = fl;
			last_feature = fl;
		} /* while sensors_get_all_features */
	} /* while sensors_get_detected_chips */
/* #endif SENSORS_API_VERSION < 0x400 */

#elif (SENSORS_API_VERSION >= 0x400) && (SENSORS_API_VERSION < 0x500)
	chip_num = 0;
	while ((chip = sensors_get_detected_chips (NULL, &chip_num)) != NULL)
	{
		const sensors_feature *feature;
		int feature_num = 0;

		while ((feature = sensors_get_features (chip, &feature_num)) != NULL)
		{
			const sensors_subfeature *subfeature;
			int subfeature_num = 0;

			/* Only handle voltage, fanspeeds and temperatures */
			if ((feature->type != SENSORS_FEATURE_IN)
					&& (feature->type != SENSORS_FEATURE_FAN)
					&& (feature->type != SENSORS_FEATURE_TEMP)
					&& (feature->type != SENSORS_FEATURE_POWER))
			{
				DEBUG ("sensors plugin: sensors_load_conf: "
						"Ignoring feature `%s', "
						"because its type is not "
						"supported.", feature->name);
				continue;
			}

			while ((subfeature = sensors_get_all_subfeatures (chip,
							feature, &subfeature_num)) != NULL)
			{
				featurelist_t *fl;

				if ((subfeature->type != SENSORS_SUBFEATURE_IN_INPUT)
						&& (subfeature->type != SENSORS_SUBFEATURE_FAN_INPUT)
						&& (subfeature->type != SENSORS_SUBFEATURE_TEMP_INPUT)
						&& (subfeature->type != SENSORS_SUBFEATURE_POWER_INPUT))
					continue;

				fl = calloc (1, sizeof (*fl));
				if (fl == NULL)
				{
					ERROR ("sensors plugin: calloc failed.");
					continue;
				}

				fl->chip = chip;
				fl->feature = feature;
				fl->subfeature = subfeature;

				if (first_feature == NULL)
					first_feature = fl;
				else
					last_feature->next = fl;
				last_feature  = fl;
			} /* while (subfeature) */
		} /* while (feature) */
	} /* while (chip) */
#endif /* (SENSORS_API_VERSION >= 0x400) && (SENSORS_API_VERSION < 0x500) */

	if (first_feature == NULL)
	{
		sensors_cleanup ();
		INFO ("sensors plugin: lm_sensors reports no "
				"features. Data will not be collected.");
		return (-1);
	}

	return (0);
} /* int sensors_load_conf */
コード例 #21
0
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;
}