sensor lib

Dependents:   gather_sensor_data

Committer:
readysteadygo2006
Date:
Thu Sep 08 14:05:15 2016 +0000
Revision:
0:cbe8cd32b8d9
test;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
readysteadygo2006 0:cbe8cd32b8d9 1 #include "DS1820Sensor.h"
readysteadygo2006 0:cbe8cd32b8d9 2
readysteadygo2006 0:cbe8cd32b8d9 3 DS1820Sensor::DS1820Sensor(PinName one_wire_pinname): DS1820_sensor(one_wire_pinname) {
readysteadygo2006 0:cbe8cd32b8d9 4 reading_type = DS1820_ALL;
readysteadygo2006 0:cbe8cd32b8d9 5 }
readysteadygo2006 0:cbe8cd32b8d9 6
readysteadygo2006 0:cbe8cd32b8d9 7
readysteadygo2006 0:cbe8cd32b8d9 8 sensorStatus DS1820Sensor::readSensor(string &sensor_reading) {
readysteadygo2006 0:cbe8cd32b8d9 9
readysteadygo2006 0:cbe8cd32b8d9 10 //add start to reading
readysteadygo2006 0:cbe8cd32b8d9 11 sensor_reading = "{";
readysteadygo2006 0:cbe8cd32b8d9 12
readysteadygo2006 0:cbe8cd32b8d9 13 //Read Temp
readysteadygo2006 0:cbe8cd32b8d9 14 if ((reading_type & DS1820_TEMP) == DS1820_TEMP) {
readysteadygo2006 0:cbe8cd32b8d9 15 float temp = DS1820_sensor.read();
readysteadygo2006 0:cbe8cd32b8d9 16 //check required here
readysteadygo2006 0:cbe8cd32b8d9 17
readysteadygo2006 0:cbe8cd32b8d9 18 char reading_type_string[10];
readysteadygo2006 0:cbe8cd32b8d9 19 sprintf(reading_type_string, "%05X", DS1820_TEMP);
readysteadygo2006 0:cbe8cd32b8d9 20 char temp_string[10];
readysteadygo2006 0:cbe8cd32b8d9 21 sprintf(temp_string, "%2.2f", temp);
readysteadygo2006 0:cbe8cd32b8d9 22 sensor_reading = sensor_reading + reading_type_string + ":" + temp_string;
readysteadygo2006 0:cbe8cd32b8d9 23 }
readysteadygo2006 0:cbe8cd32b8d9 24
readysteadygo2006 0:cbe8cd32b8d9 25 //add end to reading
readysteadygo2006 0:cbe8cd32b8d9 26 sensor_reading = sensor_reading + "}";
readysteadygo2006 0:cbe8cd32b8d9 27
readysteadygo2006 0:cbe8cd32b8d9 28 return SENSOR_SUCCESS;
readysteadygo2006 0:cbe8cd32b8d9 29 }
readysteadygo2006 0:cbe8cd32b8d9 30
readysteadygo2006 0:cbe8cd32b8d9 31
readysteadygo2006 0:cbe8cd32b8d9 32 sensorStatus DS1820Sensor::setReadingType(sensorReadingType sensor_reading_types) {
readysteadygo2006 0:cbe8cd32b8d9 33 if ((sensor_reading_types > DS1820_FIRST) && (sensor_reading_types <= DS1820_ALL)) {
readysteadygo2006 0:cbe8cd32b8d9 34 reading_type = sensor_reading_types;
readysteadygo2006 0:cbe8cd32b8d9 35 return SENSOR_SUCCESS;
readysteadygo2006 0:cbe8cd32b8d9 36 } else {
readysteadygo2006 0:cbe8cd32b8d9 37 return SENSOR_PARAM_OUT_RANGE;
readysteadygo2006 0:cbe8cd32b8d9 38 }
readysteadygo2006 0:cbe8cd32b8d9 39 }
readysteadygo2006 0:cbe8cd32b8d9 40
readysteadygo2006 0:cbe8cd32b8d9 41 sensorReadingType DS1820Sensor::getReadingType() {
readysteadygo2006 0:cbe8cd32b8d9 42 return reading_type;
readysteadygo2006 0:cbe8cd32b8d9 43 }
readysteadygo2006 0:cbe8cd32b8d9 44