TrailTraffic
Dependencies: Chainable_RGB_LED mbed mbedConnectorInterface mbedEndpointNetwork
Fork of IoT_LED_demo by
mbedEndpointResources/SliderResource.h@1:b96a11b680dc, 2015-05-22 (annotated)
- Committer:
- cjwu15
- Date:
- Fri May 22 00:39:20 2015 +0000
- Revision:
- 1:b96a11b680dc
- Parent:
- 0:a7458d25d9c9
Share;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
michaeljkoster | 0:a7458d25d9c9 | 1 | /** |
michaeljkoster | 0:a7458d25d9c9 | 2 | * @file SliderResource.h |
michaeljkoster | 0:a7458d25d9c9 | 3 | * @brief mbed CoAP Endpoint |
michaeljkoster | 0:a7458d25d9c9 | 4 | * @author Michael Koster |
michaeljkoster | 0:a7458d25d9c9 | 5 | * @version 1.0 |
michaeljkoster | 0:a7458d25d9c9 | 6 | * @see |
michaeljkoster | 0:a7458d25d9c9 | 7 | * |
michaeljkoster | 0:a7458d25d9c9 | 8 | * Copyright (c) 2015 |
michaeljkoster | 0:a7458d25d9c9 | 9 | * |
michaeljkoster | 0:a7458d25d9c9 | 10 | * Licensed under the Apache License, Version 2.0 (the "License"); |
michaeljkoster | 0:a7458d25d9c9 | 11 | * you may not use this file except in compliance with the License. |
michaeljkoster | 0:a7458d25d9c9 | 12 | * You may obtain a copy of the License at |
michaeljkoster | 0:a7458d25d9c9 | 13 | * |
michaeljkoster | 0:a7458d25d9c9 | 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
michaeljkoster | 0:a7458d25d9c9 | 15 | * |
michaeljkoster | 0:a7458d25d9c9 | 16 | * Unless required by applicable law or agreed to in writing, software |
michaeljkoster | 0:a7458d25d9c9 | 17 | * distributed under the License is distributed on an "AS IS" BASIS, |
michaeljkoster | 0:a7458d25d9c9 | 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
michaeljkoster | 0:a7458d25d9c9 | 19 | * See the License for the specific language governing permissions and |
michaeljkoster | 0:a7458d25d9c9 | 20 | * limitations under the License. |
michaeljkoster | 0:a7458d25d9c9 | 21 | */ |
michaeljkoster | 0:a7458d25d9c9 | 22 | |
michaeljkoster | 0:a7458d25d9c9 | 23 | #ifndef __SLIDER_RESOURCE_H__ |
michaeljkoster | 0:a7458d25d9c9 | 24 | #define __SLIDER_RESOURCE_H__ |
michaeljkoster | 0:a7458d25d9c9 | 25 | |
michaeljkoster | 0:a7458d25d9c9 | 26 | // Base class |
michaeljkoster | 0:a7458d25d9c9 | 27 | #include "DynamicResource.h" |
michaeljkoster | 0:a7458d25d9c9 | 28 | |
michaeljkoster | 0:a7458d25d9c9 | 29 | // Slide Potentiometer connected to A0 |
michaeljkoster | 0:a7458d25d9c9 | 30 | AnalogIn slider_in(A0); |
michaeljkoster | 0:a7458d25d9c9 | 31 | |
michaeljkoster | 0:a7458d25d9c9 | 32 | /** TemperatureResource class |
michaeljkoster | 0:a7458d25d9c9 | 33 | */ |
michaeljkoster | 0:a7458d25d9c9 | 34 | class SliderResource : public DynamicResource |
michaeljkoster | 0:a7458d25d9c9 | 35 | { |
michaeljkoster | 0:a7458d25d9c9 | 36 | public: |
michaeljkoster | 0:a7458d25d9c9 | 37 | /** |
michaeljkoster | 0:a7458d25d9c9 | 38 | Default constructor |
michaeljkoster | 0:a7458d25d9c9 | 39 | @param logger input logger instance for this resource |
michaeljkoster | 0:a7458d25d9c9 | 40 | @param name input the resource name |
michaeljkoster | 0:a7458d25d9c9 | 41 | @param observable input the resource is Observable (default: FALSE) |
michaeljkoster | 0:a7458d25d9c9 | 42 | */ |
michaeljkoster | 0:a7458d25d9c9 | 43 | SliderResource(const Logger *logger,const char *name,const bool observable = false) : DynamicResource(logger,name,"Slider", SN_GRS_GET_ALLOWED,observable) { |
michaeljkoster | 0:a7458d25d9c9 | 44 | } |
michaeljkoster | 0:a7458d25d9c9 | 45 | |
michaeljkoster | 0:a7458d25d9c9 | 46 | /** |
michaeljkoster | 0:a7458d25d9c9 | 47 | Get the value of the slide potentiometer |
michaeljkoster | 0:a7458d25d9c9 | 48 | @returns string containing the slider value from 0-1.00 |
michaeljkoster | 0:a7458d25d9c9 | 49 | */ |
michaeljkoster | 0:a7458d25d9c9 | 50 | virtual string get() { |
michaeljkoster | 0:a7458d25d9c9 | 51 | char slider_pos[7]; |
michaeljkoster | 0:a7458d25d9c9 | 52 | memset(slider_pos,0,7); |
michaeljkoster | 0:a7458d25d9c9 | 53 | sprintf(slider_pos,"%3.2f", slider_in.read()); |
michaeljkoster | 0:a7458d25d9c9 | 54 | return string(slider_pos); |
michaeljkoster | 0:a7458d25d9c9 | 55 | } |
michaeljkoster | 0:a7458d25d9c9 | 56 | }; |
michaeljkoster | 0:a7458d25d9c9 | 57 | |
michaeljkoster | 0:a7458d25d9c9 | 58 | #endif // __SLIDER_RESOURCE_H__ |