~ubuntu-branches/ubuntu/natty/ksensors/natty

« back to all changes in this revision

Viewing changes to src/lmsensor.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Morten Kjeldgaard
  • Date: 2008-11-17 15:26:19 UTC
  • mfrom: (2.1.3 lenny)
  • Revision ID: james.westby@ubuntu.com-20081117152619-5430139unvad2lwg
Tags: 0.7.3-16ubuntu1
* Merge from Debian unstable (LP: #254660). Remaining Ubuntu changes:
* debian/rules: update for patch and unpatch, add call to
  dh_icons, make sure config.guess and config.sub are present.
  Check for presence of Makefile before calling make clean.
* debian/patches/01_kubuntu_fix_etc_sensors_conf.diff: have 
  ksensors use /etc/sensors3.conf instead of sensors.conf
* debian/menu: section -> Apps/Tools
* debian/control: versioned build-depends on libsensors-dev, 
  added quilt as a build-depend for patch management. Bumped
  debhelper build-depends to 5.0.51~ due to dh_icons.
* debian/compat: bump to 5.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
LMSensor::~LMSensor(){
31
31
}
32
32
 
33
 
 
 
33
#if SENSORS_API_VERSION < 0x400 /* libsensor 3 code */
34
34
bool LMSensor::init(const sensors_feature_data **data, int *nr1,int *nr2)
 
35
#else
 
36
bool LMSensor::init(const sensors_feature **data, int *nr1, int *nr2)
 
37
#endif
35
38
{
36
39
 double min,max;
37
40
 const sensors_chip_name *chip_name= getChipName();
40
43
 char *label;
41
44
 QString str;
42
45
 
43
 
 bool min_max=false;
 
46
#if SENSORS_API_VERSION < 0x400 /* libsensor 3 code */
 
47
 bool min_found=false;
 
48
 bool max_found=false;
44
49
 while( (*data= sensors_get_all_features(*chip_name, nr1, nr2)) && (*data)->mapping!=SENSORS_NO_MAPPING) {
45
 
   str= (*data)->name;
46
 
   if(str.find("_min")>=0 || str.find("_low")>=0) {
47
 
     sensors_get_feature(*chip_name, (*data)->number, &valMin);
48
 
     min_max=true;
49
 
   } 
50
 
   else if(str.find("_max")>=0 || str.find("_over")>=0  || str.find("_high")>=0) {
51
 
     sensors_get_feature(*chip_name, (*data)->number, &valMax);
52
 
     min_max=true;
 
50
   int len = strlen((*data)->name);
 
51
   const char *postfix = (*data)->name + len - 4;
 
52
 
 
53
   if (len < 5)
 
54
     continue;
 
55
 
 
56
   if((!strcmp(postfix, "_min") || !strcmp(postfix, "_low")) &&
 
57
      !sensors_get_feature(*chip_name, (*data)->number, &valMin))
 
58
     min_found=true;
 
59
   
 
60
   if(!strcmp(postfix, "_max") &&
 
61
      !sensors_get_feature(*chip_name, (*data)->number, &valMax)) {
 
62
     max_found=true;
 
63
     continue;
53
64
   }
 
65
 
 
66
   postfix--;
 
67
 
 
68
   if((!strcmp(postfix, "_over") || !strcmp(postfix, "_high")) &&
 
69
      !sensors_get_feature(*chip_name, (*data)->number, &valMax))
 
70
     max_found=true;
54
71
 }
55
72
 
56
73
 double newVal;
87
104
 sensors_get_label(*chip_name,feature,&label);
88
105
 setDescription(QString(label));
89
106
 
90
 
 if(min_max){
91
 
   if(min>max) {
92
 
     double pivot= valMin;
93
 
     min= max;
94
 
     max= pivot;
95
 
   }
96
 
   setValueMax(max,dgCelsius);
97
 
   setValueMin(min,dgCelsius);
98
 
   setValue((max+min)/2,dgCelsius);
99
 
 }
100
 
 else {
101
 
   setValueMax(70,dgCelsius);
102
 
   setValueMin(0,dgCelsius);
103
 
   setValue(newVal,dgCelsius);
104
 
 }
 
107
 if(min_found)
 
108
   min = valMin;
 
109
   
 
110
 if(max_found)
 
111
   max = valMax;
 
112
 
 
113
#else /* libsensors4 code */
 
114
 
 
115
  const sensors_subfeature *sub_feature;
 
116
  const sensors_feature *feature_data = *data;
 
117
  
 
118
  /* Move to next feature for the loop in LMSensorsChip::createSensors() */
 
119
  *data = sensors_get_features(chip_name, nr1);
 
120
 
 
121
  switch(feature_data->type)
 
122
  {
 
123
    case SENSORS_FEATURE_IN:
 
124
      sub_feature = sensors_get_subfeature(chip_name, feature_data,
 
125
        SENSORS_SUBFEATURE_IN_INPUT);
 
126
 
 
127
      if (!sub_feature)
 
128
        return false;
 
129
 
 
130
      feature = sub_feature->number;
 
131
 
 
132
      if (!(sub_feature = sensors_get_subfeature(chip_name, feature_data,
 
133
            SENSORS_SUBFEATURE_IN_MIN)) ||
 
134
          sensors_get_value(chip_name, sub_feature->number, &min))
 
135
        min = -16;
 
136
 
 
137
      if (!(sub_feature = sensors_get_subfeature(chip_name, feature_data,
 
138
            SENSORS_SUBFEATURE_IN_MAX)) ||
 
139
          sensors_get_value(chip_name, sub_feature->number, &max))
 
140
        max = 16;
 
141
 
 
142
      setType(lmVoltage);
 
143
      break;
 
144
 
 
145
    case SENSORS_FEATURE_FAN:
 
146
      sub_feature = sensors_get_subfeature(chip_name, feature_data,
 
147
        SENSORS_SUBFEATURE_FAN_INPUT);
 
148
 
 
149
      if (!sub_feature)
 
150
        return false;
 
151
 
 
152
      feature = sub_feature->number;
 
153
 
 
154
      if (!(sub_feature = sensors_get_subfeature(chip_name, feature_data,
 
155
            SENSORS_SUBFEATURE_FAN_MIN)) ||
 
156
          sensors_get_value(chip_name, sub_feature->number, &min))
 
157
        min = 3000;
 
158
 
 
159
      max = 10000;
 
160
 
 
161
      setType(lmFan);
 
162
      break;
 
163
 
 
164
    case SENSORS_FEATURE_TEMP:
 
165
      sub_feature = sensors_get_subfeature(chip_name, feature_data,
 
166
        SENSORS_SUBFEATURE_TEMP_INPUT);
 
167
 
 
168
      if (!sub_feature)
 
169
        return false;
 
170
 
 
171
      feature = sub_feature->number;
 
172
 
 
173
      if (!(sub_feature = sensors_get_subfeature(chip_name, feature_data,
 
174
            SENSORS_SUBFEATURE_TEMP_MIN)) ||
 
175
          sensors_get_value(chip_name, sub_feature->number, &min))
 
176
        min = 0;
 
177
 
 
178
      if ((!(sub_feature = sensors_get_subfeature(chip_name, feature_data,
 
179
              SENSORS_SUBFEATURE_TEMP_MAX)) &&
 
180
           !(sub_feature = sensors_get_subfeature(chip_name, feature_data,
 
181
              SENSORS_SUBFEATURE_TEMP_CRIT))) ||
 
182
          sensors_get_value(chip_name, sub_feature->number, &max))
 
183
        max = 65;
 
184
 
 
185
      setType(lmTemp);
 
186
      break;
 
187
    
 
188
    default:
 
189
      return false;
 
190
  }
 
191
 
 
192
  str.sprintf("%s.%s", chip_name->prefix, main_name);
 
193
  setName( str.latin1() );
 
194
 
 
195
  label = sensors_get_label(chip_name, feature_data);
 
196
  if (label)
 
197
    setDescription(QString(label));
 
198
  else
 
199
    setDescription( str.latin1() );
 
200
 
 
201
#endif /* libsensors3 / libsensors4 code */
 
202
 
 
203
 if(min>max) {
 
204
   double pivot= min;
 
205
   min= max;
 
206
   max= pivot;
 
207
 }
 
208
 
 
209
 setValueMax(max,dgCelsius);
 
210
 setValueMin(min,dgCelsius);
105
211
 
106
212
 readConfig();
107
213
 updateValue();
119
225
{
120
226
 double newVal;
121
227
 const sensors_chip_name *chip_name= getChipName();
 
228
#if SENSORS_API_VERSION < 0x400 /* libsensor 3 code */
122
229
 sensors_get_feature(*chip_name, feature, &newVal);
 
230
#else
 
231
 sensors_get_value(chip_name, feature, &newVal);
 
232
#endif
123
233
 return newVal;
124
234
}
125
235