Beispiel #1
0
/** Starts a temperature conversion.
 *
 * @param wait True if function should block until temperature is converted
 * @return 0 if temperature has been converted; -1 if otherwise
 */
int DS18B20::startConversion(bool wait)
{
  int result = 0;

  if (TemperatureSensor::Unknown == _temperatureSensor)
  {
    // no conversion started before (first start)

    // identify chip (DS18B20 or DS18S20)
    result = readROM();

    if (0 != result)
    {
      // could not identify chip
      return result;
    }
    else
    {
      if (_romCode[0] == 0x28)
      {
        _temperatureSensor = TemperatureSensor::DS18B20Type;
      }
      else if (_romCode[0] == 0x10)
      {
        _temperatureSensor = TemperatureSensor::DS18S20Type;
      }
    }
  }

  result = reset();

  if (0 == result)
  {
    writeByte(0xCC); // Skip ROM
    writeByte(0x44); // Convert T

    if (true == wait)
    {
      // wait until conversion is completed
      result = busyWait();
    }

    _conversionStarted = true;
  }

  return result;
}
Beispiel #2
0
int main(int argc, char **argv) {
  init_port();
  init_state();
  readROM("microwriter.rom");
  return 0;
}