thermferm/one-wire.c

changeset 674
6cabc02f4c8d
parent 672
0c2c66920d79
child 690
3a5b019e9acc
equal deleted inserted replaced
673:0c084b876a2c 674:6cabc02f4c8d
140 n_w1->address = xstrcpy(buffer); 140 n_w1->address = xstrcpy(buffer);
141 strncpy(n_w1->family, buffer, 2); 141 strncpy(n_w1->family, buffer, 2);
142 n_w1->family[2] = '\0'; 142 n_w1->family[2] = '\0';
143 n_w1->present = DEVPRESENT_YES; 143 n_w1->present = DEVPRESENT_YES;
144 n_w1->value = (strcmp(w1type, (char *)"3a") == 0) ? 3:-1; 144 n_w1->value = (strcmp(w1type, (char *)"3a") == 0) ? 3:-1;
145 // n_w1->subdevices = (strcmp(w1type, (char *)"3a") == 0) ? 2:1;
146 n_w1->timestamp = time(NULL); 145 n_w1->timestamp = time(NULL);
147 146
148 pthread_mutex_lock(&mutexes[LOCK_ONE_WIRE]); 147 pthread_mutex_lock(&mutexes[LOCK_ONE_WIRE]);
149 if (w1_devices == NULL) { 148 if (w1_devices == NULL) {
150 w1_devices = n_w1; 149 w1_devices = n_w1;
207 SM_SUCCESS; 206 SM_SUCCESS;
208 } 207 }
209 208
210 for (dev_w1 = w1_devices; dev_w1; dev_w1 = dev_w1->next) { 209 for (dev_w1 = w1_devices; dev_w1; dev_w1 = dev_w1->next) {
211 if (strcmp(dev_w1->family, "3a") == 0) { 210 if (strcmp(dev_w1->family, "3a") == 0) {
212 // syslog(LOG_NOTICE, "ds2413 %s", dev_w1->address);
213 for (i = 0; i < 2; i++) { 211 for (i = 0; i < 2; i++) {
214 for (device = Config.devices; device; device = device->next) { 212 for (device = Config.devices; device; device = device->next) {
215 if ((strcmp(dev_w1->address, device->address) == 0) && (device->subdevice == i) && (device->direction == DEVDIR_IN_BIN)) { 213 if ((strcmp(dev_w1->address, device->address) == 0) && (device->subdevice == i) && (device->direction == DEVDIR_IN_BIN)) {
216 /* 214 /*
217 * First make sure that this device is configured as input 215 * First make sure that this device is configured as input
270 newval = (newval & 0xfd); 268 newval = (newval & 0xfd);
271 newval |= (device->value) ? 0x00 : 0x02; 269 newval |= (device->value) ? 0x00 : 0x02;
272 } 270 }
273 271
274 if (output != newval) { 272 if (output != newval) {
275 if ((rc = write_w1(dev_w1->address, (char *)"output", newval)) == 0) { 273 if ((write_w1(dev_w1->address, (char *)"output", newval)) == 0) {
276 syslog(LOG_NOTICE, "One-wire device %s-%d out %02x -> %02x", dev_w1->address, i, output, newval); 274 syslog(LOG_NOTICE, "One-wire device %s-%d out %02x -> %02x", dev_w1->address, i, output, newval);
277 dev_w1->value = newval; 275 dev_w1->value = newval;
278 } else {
279 syslog(LOG_NOTICE, "One-wire device %s-%d write output rc=%d", dev_w1->address, i, rc);
280 } 276 }
281 } 277 }
282 } else {
283 syslog(LOG_NOTICE, "One-wire device %s-%d read state rc=%d", dev_w1->address, i, rc);
284 } 278 }
285 } 279 }
286 } /* for (device = Config.devices; ... */ 280 } /* for (device = Config.devices; ... */
287 } 281 }
288 } 282 }
301 */ 295 */
302 if (cur_w1 != NULL) { 296 if (cur_w1 != NULL) {
303 297
304 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) ||
305 (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)) {
306 // syslog(LOG_NOTICE, "Reading %s", cur_w1->address);
307 devfile = xstrcpy((char *)"/sys/bus/w1/devices/"); 300 devfile = xstrcpy((char *)"/sys/bus/w1/devices/");
308 devfile = xstrcat(devfile, cur_w1->address); 301 devfile = xstrcat(devfile, cur_w1->address);
309 devfile = xstrcat(devfile, (char *)"/resolution"); 302 devfile = xstrcat(devfile, (char *)"/resolution");
310 if ((fp = fopen(devfile, "r+"))) { 303 if ((fp = fopen(devfile, "r+"))) {
311 if ((fgets(buffer, 25, fp))) { 304 if ((fgets(buffer, 25, fp))) {
364 } 357 }
365 if ((strcmp(cur_w1->family, (char *)"10") == 0) || (strcmp(cur_w1->family, (char *)"22") == 0) || (strcmp(cur_w1->family, (char *)"28") == 0) || 358 if ((strcmp(cur_w1->family, (char *)"10") == 0) || (strcmp(cur_w1->family, (char *)"22") == 0) || (strcmp(cur_w1->family, (char *)"28") == 0) ||
366 (strcmp(cur_w1->family, (char *)"3b") == 0) || (strcmp(cur_w1->family, (char *)"42") == 0)) 359 (strcmp(cur_w1->family, (char *)"3b") == 0) || (strcmp(cur_w1->family, (char *)"42") == 0))
367 break; 360 break;
368 } 361 }
369 // syslog(LOG_NOTICE, "One-wire device %s next sensor %s", cur_w1->address, cur_w1->family);
370 362
371 } else { 363 } else {
372 // syslog(LOG_NOTICE, "cur_w1 == NULL");
373 mDelay(750); 364 mDelay(750);
374 } 365 }
375 366
376 SM_PROCEED(Missing); 367 SM_PROCEED(Missing);
377 368

mercurial