TrailTraffic
Dependencies: Chainable_RGB_LED mbed mbedConnectorInterface mbedEndpointNetwork
Fork of IoT_LED_demo by
mbedEndpointResources/Motion.h@1:b96a11b680dc, 2015-05-22 (annotated)
- Committer:
- cjwu15
- Date:
- Fri May 22 00:39:20 2015 +0000
- Revision:
- 1:b96a11b680dc
Share;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cjwu15 | 1:b96a11b680dc | 1 | /** |
cjwu15 | 1:b96a11b680dc | 2 | * @file LightResource.h |
cjwu15 | 1:b96a11b680dc | 3 | * @brief mbed CoAP Endpoint Light resource supporting CoAP GET and PUT |
cjwu15 | 1:b96a11b680dc | 4 | * @author Doug Anson, Michael Koster |
cjwu15 | 1:b96a11b680dc | 5 | * @version 1.0 |
cjwu15 | 1:b96a11b680dc | 6 | * @see |
cjwu15 | 1:b96a11b680dc | 7 | * |
cjwu15 | 1:b96a11b680dc | 8 | * Copyright (c) 2014 |
cjwu15 | 1:b96a11b680dc | 9 | * |
cjwu15 | 1:b96a11b680dc | 10 | * Licensed under the Apache License, Version 2.0 (the "License"); |
cjwu15 | 1:b96a11b680dc | 11 | * you may not use this file except in compliance with the License. |
cjwu15 | 1:b96a11b680dc | 12 | * You may obtain a copy of the License at |
cjwu15 | 1:b96a11b680dc | 13 | * |
cjwu15 | 1:b96a11b680dc | 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
cjwu15 | 1:b96a11b680dc | 15 | * |
cjwu15 | 1:b96a11b680dc | 16 | * Unless required by applicable law or agreed to in writing, software |
cjwu15 | 1:b96a11b680dc | 17 | * distributed under the License is distributed on an "AS IS" BASIS, |
cjwu15 | 1:b96a11b680dc | 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
cjwu15 | 1:b96a11b680dc | 19 | * See the License for the specific language governing permissions and |
cjwu15 | 1:b96a11b680dc | 20 | * limitations under the License. |
cjwu15 | 1:b96a11b680dc | 21 | */ |
cjwu15 | 1:b96a11b680dc | 22 | |
cjwu15 | 1:b96a11b680dc | 23 | #ifndef __MOTION_RESOURCE_H__ |
cjwu15 | 1:b96a11b680dc | 24 | #define __MOTION_RESOURCE_H__ |
cjwu15 | 1:b96a11b680dc | 25 | |
cjwu15 | 1:b96a11b680dc | 26 | |
cjwu15 | 1:b96a11b680dc | 27 | // Base class |
cjwu15 | 1:b96a11b680dc | 28 | #include "DynamicResource.h" |
cjwu15 | 1:b96a11b680dc | 29 | #include "mbed.h" |
cjwu15 | 1:b96a11b680dc | 30 | |
cjwu15 | 1:b96a11b680dc | 31 | |
cjwu15 | 1:b96a11b680dc | 32 | InterruptIn sensorMotion(D2); |
cjwu15 | 1:b96a11b680dc | 33 | int motions = 0; |
cjwu15 | 1:b96a11b680dc | 34 | |
cjwu15 | 1:b96a11b680dc | 35 | void irq_handler(void) |
cjwu15 | 1:b96a11b680dc | 36 | { |
cjwu15 | 1:b96a11b680dc | 37 | motions++; |
cjwu15 | 1:b96a11b680dc | 38 | } |
cjwu15 | 1:b96a11b680dc | 39 | |
cjwu15 | 1:b96a11b680dc | 40 | /** LightResource class |
cjwu15 | 1:b96a11b680dc | 41 | */ |
cjwu15 | 1:b96a11b680dc | 42 | class MotionResource : public DynamicResource |
cjwu15 | 1:b96a11b680dc | 43 | { |
cjwu15 | 1:b96a11b680dc | 44 | |
cjwu15 | 1:b96a11b680dc | 45 | public: |
cjwu15 | 1:b96a11b680dc | 46 | /** |
cjwu15 | 1:b96a11b680dc | 47 | Default constructor |
cjwu15 | 1:b96a11b680dc | 48 | @param logger input logger instance for this resource |
cjwu15 | 1:b96a11b680dc | 49 | @param name input the Light resource name |
cjwu15 | 1:b96a11b680dc | 50 | @param observable input the resource is Observable (default: FALSE) |
cjwu15 | 1:b96a11b680dc | 51 | */ |
cjwu15 | 1:b96a11b680dc | 52 | MotionResource(const Logger *logger,const char *name,const bool observable = false) : DynamicResource(logger,name,"Motion",SN_GRS_GET_ALLOWED,observable) { |
cjwu15 | 1:b96a11b680dc | 53 | sensorMotion.rise(&irq_handler); |
cjwu15 | 1:b96a11b680dc | 54 | } |
cjwu15 | 1:b96a11b680dc | 55 | |
cjwu15 | 1:b96a11b680dc | 56 | /** |
cjwu15 | 1:b96a11b680dc | 57 | Get the value of the LED |
cjwu15 | 1:b96a11b680dc | 58 | @returns string containing the last setting |
cjwu15 | 1:b96a11b680dc | 59 | */ |
cjwu15 | 1:b96a11b680dc | 60 | virtual string get() { |
cjwu15 | 1:b96a11b680dc | 61 | char result[4]; |
cjwu15 | 1:b96a11b680dc | 62 | sprintf(result, "%d", motions); |
cjwu15 | 1:b96a11b680dc | 63 | motions = 0; |
cjwu15 | 1:b96a11b680dc | 64 | return(result); |
cjwu15 | 1:b96a11b680dc | 65 | }; |
cjwu15 | 1:b96a11b680dc | 66 | }; |
cjwu15 | 1:b96a11b680dc | 67 | |
cjwu15 | 1:b96a11b680dc | 68 | #endif // __TEMP_RESOURCE_H__ |