endpoint including temperature and distance sensors

Dependencies:   mbed mbedConnectorInterface mbedEndpointNetwork TrashSensors

Fork of TempAndDistTest by Tim Ambrose

Files at this revision

API Documentation at this revision

Comitter:
coyotebush
Date:
Mon May 25 03:21:11 2015 +0000
Parent:
10:338191178cbf
Commit message:
Move sensor code into library

Changed in this revision

GroveTemp.cpp Show diff for this revision Revisions of this file
GroveTemp.h Show diff for this revision Revisions of this file
hcsr04.cpp Show diff for this revision Revisions of this file
hcsr04.h Show diff for this revision Revisions of this file
sensor.lib Show annotated file Show diff for this revision Revisions of this file
--- a/GroveTemp.cpp	Mon May 18 00:44:59 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,50 +0,0 @@
-#include "mbed.h"
-#include <math.h>
-#include "GroveTemp.h"
-//
-AnalogIn thermistor(A0);   /* Temperature sensor connected to Analog Grove connector */
-
-GroveTempSensor::GroveTempSensor() {
-   resetMinMax();
-}
-
-float GroveTempSensor::getTemp() {
-   unsigned int analogRead;
-//                units, 
-//                tens;
-    
-   analogRead = thermistor.read_u16(); /* Read analog value */
-   
-   /* Calculate the resistance of the thermistor from analog votage read. */
-   resistance = (float) 10000.0 * ((65536.0 / analogRead) - 1.0);
-
-   /* Convert the resistance to temperature using Steinhart's Hart equation */
-   temperature = (1/((log(resistance/10000.0)/TEMP_BETA) + (1.0/298.15)))-273.15; 
-
-//   units = (int) temperature % 10;
-//   tens  = (int) temperature / 10;
-   if (temperature > maxTemp)
-      maxTemp = temperature;
-   if (temperature < minTemp)
-      minTemp = temperature;
-   
-   return temperature;
-}
-
-void GroveTempSensor::resetMinMax() {
-   maxTemp = -999.9;
-   minTemp = 999.9;
-   minMaxDefined = false;
-}
-
-float GroveTempSensor::getMin() {
-   if (!minMaxDefined)
-      getTemp();
-   return minTemp;
-}
-
-float GroveTempSensor::getMax() {
-   if (!minMaxDefined)
-      getTemp();
-   return maxTemp;
-}
\ No newline at end of file
--- a/GroveTemp.h	Mon May 18 00:44:59 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,30 +0,0 @@
-/*
-GroveTemp.h
-IoT GarbageCollectors
-
-Created by Timothy Ambrose on 4/29/15.
-*/
-
-#ifndef GROVE_TEMP_H
-#define GROVE_TEMP_H
-
-#include "mbed.h"
-#define TEMP_BETA 3975
-
-class GroveTempSensor {
-private:
-   float temperature,
-         resistance,
-         minTemp,
-         maxTemp;
-   bool minMaxDefined;
-   
-public:
-   GroveTempSensor();
-   float getTemp();
-   void resetMinMax();
-   float getMin();
-   float getMax();
-};
-
-#endif
\ No newline at end of file
--- a/hcsr04.cpp	Mon May 18 00:44:59 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,105 +0,0 @@
-/* Copyright (c) 2013 Prabhu Desai
- * pdtechworld@gmail.com
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
- * and associated documentation files (the "Software"), to deal in the Software without restriction,
- * including without limitation the rights to use, copy, modify, merge, publish, distribute,
- * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all copies or
- * substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
- * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-#include "hcsr04.h"
-
-
-HCSR04::HCSR04(PinName TrigPin,PinName EchoPin):
-    trigger(TrigPin), echo(EchoPin), maxpulse(-1)
-{
-    pulsetime.stop();
-    pulsetime.reset();
-    echo.rise(this,&HCSR04::isr_rise);
-    echo.fall(this,&HCSR04::isr_fall);
-    trigger=0;
-}
-
-HCSR04::~HCSR04()
-{
-}
-
-void HCSR04::isr_rise(void)
-{
-    pulsetime.start();
-    pulsetime.reset();
-}
-void HCSR04::start(void)
-{
-    pulsedur = -1;
-    
-    trigger=1;
-    wait_us(10);
-    trigger=0;
-}
-
-void HCSR04::isr_fall(void)
-{
-    pulsetime.stop();
-    pulsedur = pulsetime.read_us();
-    if (pulsedur > maxpulse && pulsedur < kBogusPulse)
-        maxpulse = pulsedur;
-}
-
-void HCSR04::rise (void (*fptr)(void))
-{
-    echo.rise(fptr);
-}
-void HCSR04::fall (void (*fptr)(void))
-{
-    echo.fall(fptr);
-}
-
-double HCSR04::get_dist_cm()
-{
-    return pulsedur * kMicrosecondsToCentimeters;
-}
-double HCSR04::get_max_dist_cm()
-{
-    return maxpulse * kMicrosecondsToCentimeters;
-}
-int HCSR04::get_pulse_us()
-{
-    return pulsedur;
-}
-
-
-
-/*******************************************************
-   Here is a sample code usage
-********************************************************* 
-#include "hcsr04.h"
-HCSR04  usensor(p25,p6);
-int main()
-{
-    unsigned char count=0;
-    while(1) {
-        usensor.start();
-        wait_ms(500); 
-        dist=usensor.get_dist_cm();
-        lcd.cls();
-        lcd.locate(0,0);
-        lcd.printf("cm:%ld",dist );
- 
-        count++;
-        lcd.locate(0,1);
-        lcd.printf("Distance =%d",count);
-        
-    }
-*/
\ No newline at end of file
--- a/hcsr04.h	Mon May 18 00:44:59 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,74 +0,0 @@
-/* Copyright (c) 2013 Prabhu Desai
- * pdtechworld@gmail.com
- *
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
- * and associated documentation files (the "Software"), to deal in the Software without restriction,
- * including without limitation the rights to use, copy, modify, merge, publish, distribute,
- * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all copies or
- * substantial portions of the Software.
- *
- * For more details on the sensor :
- * http://www.elecfreaks.com/store/hcsr04-ultrasonic-sensor-distance-measuring-module-p-91.html?zenid=pgm8pgnvaodbe36dibq5s1soi3
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
- * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#ifndef MBED_HCSR04_H
-#define MBED_HCSR04_H
-
-#include "mbed.h"
-
-/** HCSR04 Class(es)
- */
-
-// TODO(CJF): steal clever logic from https://code.google.com/p/arduino-new-ping/ ?
-
-class HCSR04
-{
-public:
-    static const double kMicrosecondsToCentimeters = 343.0 / 20000;
-    static const double kBogusPulse = 500 / kMicrosecondsToCentimeters;
-    
-    /** Create a HCSR04 object connected to the specified pin
-    * @param pin i/o pin to connect to
-    */
-    HCSR04(PinName TrigPin,PinName EchoPin);
-    ~HCSR04();
-
-    /** Return the distance from obstacle in cm
-    * @param distance in cms and returns -1, in case of failure
-    */
-    double get_dist_cm(void);
-    double get_max_dist_cm(void);
-    /** Return the pulse duration equal to sonic waves travelling to obstacle and back to receiver.
-    * @param pulse duration in microseconds.
-    */
-    int get_pulse_us(void);
-    /** Generates the trigger pulse of 10us on the trigger PIN.
-    */
-    void start(void );
-    void isr_rise(void);
-    void isr_fall(void);
-    void fall (void (*fptr)(void));
-    void rise (void (*fptr)(void));
-
-
-
-private:
-
-    Timer pulsetime;
-    DigitalOut  trigger;
-    InterruptIn echo;
-    int pulsedur;
-    int maxpulse;
-};
-
-#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sensor.lib	Mon May 25 03:21:11 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/coyotebush/code/TrashSensors/#3f335fc50cef