my fork
Fork of mbed by
Diff: AnalogIn.h
- Revision:
- 44:24d45a770a51
- Parent:
- 43:e2ed12d17f06
- Child:
- 54:71b101360fb9
--- a/AnalogIn.h Fri Oct 26 17:40:46 2012 +0100 +++ b/AnalogIn.h Wed Nov 21 10:49:56 2012 +0000 @@ -1,22 +1,36 @@ -/* mbed Microcontroller Library - AnalogIn - * Copyright (c) 2006-2011 ARM Limited. All rights reserved. - */ - +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ #ifndef MBED_ANALOGIN_H #define MBED_ANALOGIN_H -#include "device.h" +#include "platform.h" #if DEVICE_ANALOGIN -#include "platform.h" -#include "PinNames.h" -#include "PeripheralNames.h" -#include "Base.h" +#include "analogin_api.h" namespace mbed { -/** An analog input, used for reading the voltage on a pin +/** An analog input, used for reading the voltage on a pin * * Example: * @code @@ -29,13 +43,13 @@ * int main() { * while(1) { * if(temperature > 0.5) { - * printf("Too hot! (%f)", temperature.read()); + * printf("Too hot! (%f)", temperature.read()); * } * } * } * @endcode */ -class AnalogIn : public Base { +class AnalogIn { public: @@ -44,20 +58,26 @@ * @param pin AnalogIn pin to connect to * @param name (optional) A string to identify the object */ - AnalogIn(PinName pin, const char *name = NULL); + AnalogIn(PinName pin) { + analogin_init(&_adc, pin); + } /** Read the input voltage, represented as a float in the range [0.0, 1.0] * * @returns A floating-point value representing the current input voltage, measured as a percentage */ - float read(); + float read() { + return analogin_read(&_adc); + } /** Read the input voltage, represented as an unsigned short in the range [0x0, 0xFFFF] * * @returns * 16-bit unsigned short representing the current input voltage, normalised to a 16-bit value */ - unsigned short read_u16(); + unsigned short read_u16() { + return analogin_read_u16(&_adc); + } #ifdef MBED_OPERATORS /** An operator shorthand for read() @@ -73,18 +93,13 @@ * if(volume > 0.25) { ... } * @endcode */ - operator float(); -#endif - -#ifdef MBED_RPC - virtual const struct rpc_method *get_rpc_methods(); - static struct rpc_class *get_rpc_class(); + operator float() { + return read(); + } #endif protected: - - ADCName _adc; - + analogin_t _adc; }; } // namespace mbed