Christopher Wu / Mbed 2 deprecated Trail

Dependencies:   Chainable_RGB_LED mbed mbedConnectorInterface mbedEndpointNetwork

Fork of IoT_LED_demo by MBED_DEMOS

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Motion.h Source File

Motion.h

00001 /**
00002  * @file    LightResource.h
00003  * @brief   mbed CoAP Endpoint Light resource supporting CoAP GET and PUT
00004  * @author  Doug Anson, Michael Koster
00005  * @version 1.0
00006  * @see
00007  *
00008  * Copyright (c) 2014
00009  *
00010  * Licensed under the Apache License, Version 2.0 (the "License");
00011  * you may not use this file except in compliance with the License.
00012  * You may obtain a copy of the License at
00013  *
00014  *     http://www.apache.org/licenses/LICENSE-2.0
00015  *
00016  * Unless required by applicable law or agreed to in writing, software
00017  * distributed under the License is distributed on an "AS IS" BASIS,
00018  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00019  * See the License for the specific language governing permissions and
00020  * limitations under the License.
00021  */
00022 
00023 #ifndef __MOTION_RESOURCE_H__
00024 #define __MOTION_RESOURCE_H__
00025 
00026 
00027 // Base class
00028 #include "DynamicResource.h"
00029 #include "mbed.h"
00030 
00031 
00032 InterruptIn sensorMotion(D2);
00033 int motions = 0;
00034 
00035 void irq_handler(void)
00036 {
00037     motions++;
00038 }
00039 
00040 /** LightResource class
00041  */
00042 class MotionResource : public DynamicResource
00043 {
00044 
00045 public:
00046     /**
00047     Default constructor
00048     @param logger input logger instance for this resource
00049     @param name input the Light resource name
00050     @param observable input the resource is Observable (default: FALSE)
00051     */
00052     MotionResource(const Logger *logger,const char *name,const bool observable = false) : DynamicResource(logger,name,"Motion",SN_GRS_GET_ALLOWED,observable) {
00053         sensorMotion.rise(&irq_handler);
00054     }
00055 
00056     /**
00057     Get the value of the LED
00058     @returns string containing the last setting
00059     */
00060     virtual string get() {
00061         char result[4];
00062         sprintf(result, "%d", motions);
00063         motions = 0;
00064         return(result);
00065     };
00066 };
00067 
00068 #endif // __TEMP_RESOURCE_H__