fork of chris cause ide is stupid

Dependencies:   Chainable_RGB_LED mbed mbedConnectorInterface mbedEndpointNetwork

Fork of Trail by Christopher Wu

mbedEndpointResources/Temp.h

Committer:
jowil
Date:
2015-05-28
Revision:
2:f72204758515
Parent:
1:b96a11b680dc

File content as of revision 2:f72204758515:

/**
 * @file    LightResource.h
 * @brief   mbed CoAP Endpoint Light resource supporting CoAP GET and PUT
 * @author  Doug Anson, Michael Koster
 * @version 1.0
 * @see
 *
 * Copyright (c) 2014
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef __TEMP_RESOURCE_H__
#define __TEMP_RESOURCE_H__


// Base class
#include "DynamicResource.h"
#include "mbed.h"


AnalogIn sensorTemp(A0);


/** LightResource class
 */
class TempResource : public DynamicResource
{

public:
    /**
    Default constructor
    @param logger input logger instance for this resource
    @param name input the Light resource name
    @param observable input the resource is Observable (default: FALSE)
    */
    TempResource(const Logger *logger,const char *name,const bool observable = false) : DynamicResource(logger,name,"Temp",SN_GRS_GET_ALLOWED,observable) {
    }

    /**
    Get the value of the LED
    @returns string containing the last setting
    */
    virtual string get() {
        int B=3975;
        float a = sensorTemp * 1000;
        float resistance = (float) (1023-a) * 10000/a; //get the resistance of the sensor;
        float temperature= 1.0f / (logf(resistance/10000)/B + 1/298.15) - 273.15;//convert to temperature via datasheet ;
        char result[8];
        sprintf(result, "%f", temperature);
        return(result);
    };
};

#endif // __TEMP_RESOURCE_H__