void SRF02::update() { if (interval == 0) { return; } if (rangingTriggered && millis() > nextRead) { for (SRF02 *i = first; i != 0; i = i->next) { Wire.beginTransmission(i->deviceId); WIRE_WRITE(2); Wire.endTransmission(); Wire.requestFrom(i->deviceId, (uint8_t) 2); i->value = ((unsigned long) WIRE_READ()) << 8; i->value += (unsigned long) WIRE_READ(); } rangingTriggered = false; } if (millis() > nextRequest) { for (SRF02 *i = first; i != 0; i = i->next) { Wire.beginTransmission(i->deviceId); WIRE_WRITE((uint8_t) 0); WIRE_WRITE(i->mode); Wire.endTransmission(); } nextRead = millis() + READ_DURATION; nextRequest = millis() + interval; rangingTriggered = true; } }
unsigned int CMPS03::read () { Wire.beginTransmission(deviceId); WIRE_WRITE((uint8_t) 2); Wire.endTransmission(); delay(1); Wire.requestFrom(deviceId, (uint8_t) 2); unsigned int value = ((unsigned int) WIRE_READ()) << 8; value = value + ((unsigned int) WIRE_READ()); return value; }