confidential

Dependencies:   Chainable_RGB_LED mbed mbedConnectorInterface mbedEndpointNetwork

Committer:
cjwu15
Date:
Sat May 09 17:32:02 2015 +0000
Revision:
0:02b8d440ded3
Child:
1:73f962479f1a
initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cjwu15 0:02b8d440ded3 1 /**
cjwu15 0:02b8d440ded3 2 * @file LightResource.h
cjwu15 0:02b8d440ded3 3 * @brief mbed CoAP Endpoint Light resource supporting CoAP GET and PUT
cjwu15 0:02b8d440ded3 4 * @author Doug Anson, Michael Koster
cjwu15 0:02b8d440ded3 5 * @version 1.0
cjwu15 0:02b8d440ded3 6 * @see
cjwu15 0:02b8d440ded3 7 *
cjwu15 0:02b8d440ded3 8 * Copyright (c) 2014
cjwu15 0:02b8d440ded3 9 *
cjwu15 0:02b8d440ded3 10 * Licensed under the Apache License, Version 2.0 (the "License");
cjwu15 0:02b8d440ded3 11 * you may not use this file except in compliance with the License.
cjwu15 0:02b8d440ded3 12 * You may obtain a copy of the License at
cjwu15 0:02b8d440ded3 13 *
cjwu15 0:02b8d440ded3 14 * http://www.apache.org/licenses/LICENSE-2.0
cjwu15 0:02b8d440ded3 15 *
cjwu15 0:02b8d440ded3 16 * Unless required by applicable law or agreed to in writing, software
cjwu15 0:02b8d440ded3 17 * distributed under the License is distributed on an "AS IS" BASIS,
cjwu15 0:02b8d440ded3 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
cjwu15 0:02b8d440ded3 19 * See the License for the specific language governing permissions and
cjwu15 0:02b8d440ded3 20 * limitations under the License.
cjwu15 0:02b8d440ded3 21 */
cjwu15 0:02b8d440ded3 22
cjwu15 0:02b8d440ded3 23 #ifndef __TOUCH_RESOURCE_H__
cjwu15 0:02b8d440ded3 24 #define __TOUCH_RESOURCE_H__
cjwu15 0:02b8d440ded3 25
cjwu15 0:02b8d440ded3 26 #include <stdio.h>
cjwu15 0:02b8d440ded3 27
cjwu15 0:02b8d440ded3 28 // Base class
cjwu15 0:02b8d440ded3 29 #include "DynamicResource.h"
cjwu15 0:02b8d440ded3 30 #include "mbed.h"
cjwu15 0:02b8d440ded3 31
cjwu15 0:02b8d440ded3 32 DigitalIn button(D2);
cjwu15 0:02b8d440ded3 33
cjwu15 0:02b8d440ded3 34
cjwu15 0:02b8d440ded3 35 int count = 0;
cjwu15 0:02b8d440ded3 36
cjwu15 0:02b8d440ded3 37
cjwu15 0:02b8d440ded3 38 void touch_thread(void const *args) {
cjwu15 0:02b8d440ded3 39 while(1) {
cjwu15 0:02b8d440ded3 40 if (button) {
cjwu15 0:02b8d440ded3 41 printf("touch detected\n");
cjwu15 0:02b8d440ded3 42 count++;
cjwu15 0:02b8d440ded3 43 LED_set_color("0000FF00");
cjwu15 0:02b8d440ded3 44 wait(1.0);
cjwu15 0:02b8d440ded3 45 LED_set_color("00000000");
cjwu15 0:02b8d440ded3 46 while(button);
cjwu15 0:02b8d440ded3 47 }
cjwu15 0:02b8d440ded3 48
cjwu15 0:02b8d440ded3 49 Thread::wait(500);
cjwu15 0:02b8d440ded3 50 }
cjwu15 0:02b8d440ded3 51 }
cjwu15 0:02b8d440ded3 52
cjwu15 0:02b8d440ded3 53 /** LightResource class
cjwu15 0:02b8d440ded3 54 */
cjwu15 0:02b8d440ded3 55 class TouchResource : public DynamicResource
cjwu15 0:02b8d440ded3 56 {
cjwu15 0:02b8d440ded3 57
cjwu15 0:02b8d440ded3 58 public:
cjwu15 0:02b8d440ded3 59 /**
cjwu15 0:02b8d440ded3 60 Default constructor
cjwu15 0:02b8d440ded3 61 @param logger input logger instance for this resource
cjwu15 0:02b8d440ded3 62 @param name input the Light resource name
cjwu15 0:02b8d440ded3 63 @param observable input the resource is Observable (default: FALSE)
cjwu15 0:02b8d440ded3 64 */
cjwu15 0:02b8d440ded3 65 TouchResource(const Logger *logger,const char *name,const bool observable = false) : DynamicResource(logger,name,"Touch",SN_GRS_GET_ALLOWED,observable) {
cjwu15 0:02b8d440ded3 66 }
cjwu15 0:02b8d440ded3 67
cjwu15 0:02b8d440ded3 68 /**
cjwu15 0:02b8d440ded3 69 Get the value of the LED
cjwu15 0:02b8d440ded3 70 @returns string containing the last setting
cjwu15 0:02b8d440ded3 71 */
cjwu15 0:02b8d440ded3 72 virtual string get() {
cjwu15 0:02b8d440ded3 73 char result[10];
cjwu15 0:02b8d440ded3 74 sprintf(result, "%d", count);
cjwu15 0:02b8d440ded3 75 count = 0;
cjwu15 0:02b8d440ded3 76 return(result);
cjwu15 0:02b8d440ded3 77 }
cjwu15 0:02b8d440ded3 78 };
cjwu15 0:02b8d440ded3 79
cjwu15 0:02b8d440ded3 80 #endif // __TOUCH_RESOURCE_H__
cjwu15 0:02b8d440ded3 81