164 syslog(LOG_NOTICE, "ds2413 %s", dev_w1->address); |
164 syslog(LOG_NOTICE, "ds2413 %s", dev_w1->address); |
165 for (i = 0; i < 2; i++) { |
165 for (i = 0; i < 2; i++) { |
166 for (device = Config.devices; device; device = device->next) { |
166 for (device = Config.devices; device; device = device->next) { |
167 if ((strcmp(dev_w1->address, device->address) == 0) && (device->subdevice == i) && (device->direction == DEVDIR_IN_BIN)) { |
167 if ((strcmp(dev_w1->address, device->address) == 0) && (device->subdevice == i) && (device->direction == DEVDIR_IN_BIN)) { |
168 /* |
168 /* |
169 * First make sure that if this device is configured as input |
169 * First make sure that this device is configured as input |
170 * to drive the output high. |
170 * to drive the output high. Fix if programmed as output. |
171 * TODO: This must be made different. Check state and fix only if wrong. |
|
172 */ |
171 */ |
173 if ((rc = read_w1(device->address, (char *)"state")) >= 0) { |
172 if ((rc = read_w1(device->address, (char *)"state")) >= 0) { |
174 state = (unsigned int)rc; |
173 state = (unsigned int)rc; |
175 output = ((state & 0x02) >> 1) + ((state & 0x08) >> 2); /* Both latch states */ |
174 output = ((state & 0x02) >> 1) + ((state & 0x08) >> 2); /* Both latch states */ |
176 if (i == 0) { |
175 if ((i == 0) && ((state & 0x02) == 0)) { /* Fix A side */ |
177 output = (output & 0xfe); |
176 syslog(LOG_NOTICE, "One-wire device %s-%d out %04x -> %04x", dev_w1->address, i, output, output | 0x01); |
178 output |= 0x01; |
177 output |= 0x01; |
179 } else if (i == 1) { |
178 write_w1(device->address, (char *)"output", output); |
180 output = (output & 0xfd); |
179 mDelay(10); |
|
180 if ((rc = read_w1(device->address, (char *)"state")) >= 0) /* Read PIO again */ |
|
181 state = (unsigned int)rc; |
|
182 } |
|
183 if ((i == 1) && ((state & 0x08) == 0)) { /* Fix B side */ |
|
184 syslog(LOG_NOTICE, "One-wire device %s-%d out %04x -> %04x", dev_w1->address, i, output, output | 0x02); |
181 output |= 0x02; |
185 output |= 0x02; |
182 } else { |
186 write_w1(device->address, (char *)"output", output); |
183 output = 0xff; |
187 mDelay(10); |
|
188 if ((rc = read_w1(device->address, (char *)"state")) >= 0) /* Read PIO again */ |
|
189 state = (unsigned int)rc; |
184 } |
190 } |
185 write_w1(device->address, (char *)"output", output); |
191 |
186 } |
|
187 if ((rc = read_w1(device->address, (char *)"state")) >= 0) { |
|
188 pthread_mutex_lock(&mutexes[LOCK_DEVICES]); |
192 pthread_mutex_lock(&mutexes[LOCK_DEVICES]); |
189 /* |
193 /* |
190 * Read PIOA or PIOB pin state bits |
194 * Read PIOA or PIOB pin state bits |
191 */ |
195 */ |
192 if (device->subdevice == 0) |
196 if (device->subdevice == 0) |