ds18b20: rewrite C++ to wrap C, add FTI, update examples

Previously, the C++ and C versions of this driver were separate.  Now
the C++ implementation wraps the C implementation.

In addition, the C++ init() function has been deprecated.  It
currently does nothing, and examples have been modified to remove it's
calls.  This function will be removed in a separate release.

The examples have been further modified to update all detected devices
and print their respective temperatures, instead of only reporting the
on the first device detected.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
This commit is contained in:
Jon Trulson
2017-01-18 13:09:51 -07:00
parent 6769d976a0
commit d3b864362d
15 changed files with 685 additions and 757 deletions

View File

@ -1,6 +1,6 @@
#!/usr/bin/python
# Author: Jon Trulson <jtrulson@ics.com>
# Copyright (c) 2016 Intel Corporation.
# Copyright (c) 2016-2017 Intel Corporation.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
@ -45,25 +45,26 @@ def main():
# Instantiate an DS18B20 instance using the default values (uart 0)
sensor = sensorObj.DS18B20(0)
# locate and setup our devices
sensor.init()
print("Found", sensor.devicesFound(), "device(s)")
print()
if (not sensor.devicesFound()):
sys.exit(1);
# update and print available values every second
# update and print available values every 2 seconds
while (1):
# update our values for the first sensor
sensor.update(0)
# update our values for all of the detected sensors
sensor.update(-1)
# we show both C and F for temperature for the first sensor
print("Temperature:", sensor.getTemperature(0), "C /", end=' ')
print(sensor.getTemperature(0, True), "F")
# we show both C and F for temperature for the sensors
for i in range(sensor.devicesFound()):
print("Device:", i, end=' ')
print("Temperature:", sensor.getTemperature(i), "C /", end=' ')
print(sensor.getTemperature(i, True), "F")
time.sleep(1)
print()
time.sleep(2)
if __name__ == '__main__':
main()