thermferm/one-wire.c

changeset 690
3a5b019e9acc
parent 674
6cabc02f4c8d
child 692
6d97eb820cc1
equal deleted inserted replaced
689:f94b525f7563 690:3a5b019e9acc
293 /* 293 /*
294 * cur_w1 points to the next not handled device. 294 * cur_w1 points to the next not handled device.
295 */ 295 */
296 if (cur_w1 != NULL) { 296 if (cur_w1 != NULL) {
297 297
298 if ((strcmp(cur_w1->family, (char *)"10") == 0) || (strcmp(cur_w1->family, (char *)"22") == 0) || (strcmp(cur_w1->family, (char *)"28") == 0) || 298 if (((strcmp(cur_w1->family, (char *)"10") == 0) || (strcmp(cur_w1->family, (char *)"22") == 0) || (strcmp(cur_w1->family, (char *)"28") == 0) ||
299 (strcmp(cur_w1->family, (char *)"3b") == 0) || (strcmp(cur_w1->family, (char *)"42") == 0)) { 299 (strcmp(cur_w1->family, (char *)"3b") == 0) || (strcmp(cur_w1->family, (char *)"42") == 0)) &&
300 (cur_w1->present == DEVPRESENT_YES)) {
300 devfile = xstrcpy((char *)"/sys/bus/w1/devices/"); 301 devfile = xstrcpy((char *)"/sys/bus/w1/devices/");
301 devfile = xstrcat(devfile, cur_w1->address); 302 devfile = xstrcat(devfile, cur_w1->address);
302 devfile = xstrcat(devfile, (char *)"/resolution"); 303 devfile = xstrcat(devfile, (char *)"/resolution");
303 if ((fp = fopen(devfile, "r+"))) { 304 if ((fp = fopen(devfile, "r+"))) {
304 if ((fgets(buffer, 25, fp))) { 305 if ((fgets(buffer, 25, fp))) {
305 sscanf(buffer, "%d", &value); 306 sscanf(buffer, "%d", &value);
306 if (value != W1_TEMP_RESOLUTION) { 307 /* If device is removed, value is negative (errno?) */
308 if ((value > 0) && (value != W1_TEMP_RESOLUTION)) {
307 syslog(LOG_NOTICE, "One-wire device %s set resolution from %d to %d", cur_w1->address, value, W1_TEMP_RESOLUTION); 309 syslog(LOG_NOTICE, "One-wire device %s set resolution from %d to %d", cur_w1->address, value, W1_TEMP_RESOLUTION);
308 fseek(fp, 0L, SEEK_SET); 310 fseek(fp, 0L, SEEK_SET);
309 sprintf(buffer, "%d", W1_TEMP_RESOLUTION); 311 sprintf(buffer, "%d", W1_TEMP_RESOLUTION);
310 fputs(buffer, fp); 312 fputs(buffer, fp);
311 } 313 }
345 } else { 347 } else {
346 syslog(LOG_NOTICE, "One-wire device %s open: %s", cur_w1->address, strerror(errno)); 348 syslog(LOG_NOTICE, "One-wire device %s open: %s", cur_w1->address, strerror(errno));
347 } 349 }
348 free(devfile); 350 free(devfile);
349 devfile = NULL; 351 devfile = NULL;
350 } 352 } /* if temperature sensor and present */
351 353
352 for (;;) { 354 for (;;) {
353 if (cur_w1->next != NULL) { 355 if (cur_w1->next != NULL) {
354 cur_w1 = cur_w1->next; 356 cur_w1 = cur_w1->next;
355 } else { 357 } else {

mercurial