mirror of
https://github.com/eclipse/upm.git
synced 2025-07-01 09:21:12 +03:00
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:
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* 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
|
||||
@ -49,9 +49,6 @@ int main(int argc, char **argv)
|
||||
// Instantiate an DS18B20 instance using the default values (uart 0)
|
||||
upm::DS18B20 sensor;
|
||||
|
||||
// locate and setup our devices
|
||||
sensor.init();
|
||||
|
||||
cout << "Found " << sensor.devicesFound() << " device(s)" << endl;
|
||||
cout << endl;
|
||||
|
||||
@ -59,18 +56,26 @@ int main(int argc, char **argv)
|
||||
if (!sensor.devicesFound())
|
||||
return 1;
|
||||
|
||||
// update and print available values every second
|
||||
// update and print available values every 2 seconds
|
||||
while (shouldRun)
|
||||
{
|
||||
// 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
|
||||
cout << "Temperature: " << sensor.getTemperature(0)
|
||||
<< " C / " << sensor.getTemperature(0, true) << " F"
|
||||
<< endl;
|
||||
// we show both C and F for temperature for the sensors
|
||||
int i;
|
||||
for (i=0; i<sensor.devicesFound(); i++)
|
||||
{
|
||||
cout << "Device "
|
||||
<< i
|
||||
<< ": Temperature: "
|
||||
<< sensor.getTemperature(i)
|
||||
<< " C / " << sensor.getTemperature(i, true) << " F"
|
||||
<< endl;
|
||||
}
|
||||
cout << endl;
|
||||
|
||||
sleep(1);
|
||||
sleep(2);
|
||||
}
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
@ -56,7 +56,7 @@ int main(int argc, char **argv)
|
||||
|
||||
printf("Found %d device(s)\n\n", ds18b20_devices_found(sensor));
|
||||
|
||||
// update and print available values every second
|
||||
// update and print available values every 2 seconds
|
||||
while (shouldRun)
|
||||
{
|
||||
// update our values for all sensors
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* 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
|
||||
@ -33,9 +33,6 @@ console.log("Initializing...");
|
||||
// Instantiate an DS18B20 instance using the default values (uart 0)
|
||||
var sensor = new sensorObj.DS18B20(0);
|
||||
|
||||
// locate and setup our devices
|
||||
sensor.init();
|
||||
|
||||
console.log("Found", sensor.devicesFound(), "device(s)");
|
||||
console.log("");
|
||||
|
||||
@ -44,17 +41,21 @@ if (!sensor.devicesFound())
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// update and print available values every second
|
||||
// update and print available values every 2 seconds
|
||||
setInterval(function()
|
||||
{
|
||||
// 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
|
||||
console.log("Temperature:", sensor.getTemperature(0),
|
||||
"C /", sensor.getTemperature(0, true), "F");
|
||||
// we show both C and F for temperature for the sensors
|
||||
for (var i=0; i<sensor.devicesFound(); i++)
|
||||
{
|
||||
console.log("Device:", i, "Temperature:", sensor.getTemperature(i),
|
||||
"C /", sensor.getTemperature(i, true), "F");
|
||||
}
|
||||
|
||||
}, 1000);
|
||||
console.log();
|
||||
}, 2000);
|
||||
|
||||
|
||||
process.on('SIGINT', function()
|
||||
|
@ -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()
|
||||
|
Reference in New Issue
Block a user