The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.
Dependents: hello SerialTestv11 SerialTestv12 Sierpinski ... more
mbed 2
This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.
Diff: drivers/AnalogIn.h
- Revision:
- 170:e95d10626187
- Parent:
- 156:ff21514d8981
- Child:
- 171:3a7713b1edbc
--- a/drivers/AnalogIn.h Fri Jun 22 15:38:59 2018 +0100 +++ b/drivers/AnalogIn.h Thu Sep 06 13:39:34 2018 +0100 @@ -57,7 +57,8 @@ * * @param pin AnalogIn pin to connect to */ - AnalogIn(PinName pin) { + AnalogIn(PinName pin) + { lock(); analogin_init(&_adc, pin); unlock(); @@ -67,7 +68,8 @@ * * @returns A floating-point value representing the current input voltage, measured as a percentage */ - float read() { + float read() + { lock(); float ret = analogin_read(&_adc); unlock(); @@ -79,7 +81,8 @@ * @returns * 16-bit unsigned short representing the current input voltage, normalised to a 16-bit value */ - unsigned short read_u16() { + unsigned short read_u16() + { lock(); unsigned short ret = analogin_read_u16(&_adc); unlock(); @@ -99,22 +102,26 @@ * if(volume > 0.25) { ... } * @endcode */ - operator float() { + operator float() + { // Underlying call is thread safe return read(); } - virtual ~AnalogIn() { + virtual ~AnalogIn() + { // Do nothing } protected: - virtual void lock() { + virtual void lock() + { _mutex->lock(); } - virtual void unlock() { + virtual void unlock() + { _mutex->unlock(); }