Example #1
0
bool OwRelay::rawWrite(uint64_t addr, bool value) {
  OneWire ds = os->getOneWire();
  uint8_t *a = (uint8_t *)&addr;
  ds.reset();
  ds.write(0x55, 1); // ROM select
  for(int i = 0; i < 8; i++) ds.write(a[i], 1);
  uint8_t bit = ds.read_bit();
  ds.reset();

  bool oops = false;
  value ^= 1;
  if ((bit&1) ^ value) {
    oops = true;
    // toggled the wrong way, toggle again...
    ds.write(0x55, 1); // ROM select
    for(int i = 0; i < 8; i++) ds.write(a[i], 1);
    bit = ds.read_bit();
    ds.reset();
  }
#if DEBUG
  Serial.print(F("OWR: Write "));
  printAddr(&Serial, addr);
  Serial.print("<-");
  Serial.print(value);
  if (oops) Serial.print(" 2xtoggle");
  Serial.print(" bit=");
  Serial.print(bit);
  Serial.println();
#endif

  return !((bit&1) ^ value);
}
Example #2
0
// Read the state, returns -1 on failure
int8_t OwRelay::rawRead(uint64_t addr) {
  OneWire ds = os->getOneWire();
  byte data[12];
  ds.reset();
  ds.select((uint8_t *)&addr);
  uint8_t value = ds.read_bit() ^ 1; // read the switch value

#if DEBUG
  Serial.print(F("OWR: Good data for "));
  printAddr(&Serial, addr);
  Serial.print("->");
  Serial.print(value);
  Serial.println();
#endif

  return value;
}