Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: hello SerialTestv11 SerialTestv12 Sierpinski ... more
Diff: drivers/AnalogOut.h
- Revision:
- 170:e95d10626187
- Parent:
- 156:ff21514d8981
- Child:
- 171:3a7713b1edbc
--- a/drivers/AnalogOut.h Fri Jun 22 15:38:59 2018 +0100 +++ b/drivers/AnalogOut.h Thu Sep 06 13:39:34 2018 +0100 @@ -57,7 +57,8 @@ * * @param pin AnalogOut pin to connect to */ - AnalogOut(PinName pin) { + AnalogOut(PinName pin) + { analogout_init(&_dac, pin); } @@ -68,7 +69,8 @@ * 0.0f (representing 0v / 0%) and 1.0f (representing 3.3v / 100%). * Values outside this range will be saturated to 0.0f or 1.0f. */ - void write(float value) { + void write(float value) + { lock(); analogout_write(&_dac, value); unlock(); @@ -79,7 +81,8 @@ * @param value 16-bit unsigned short representing the output voltage, * normalised to a 16-bit value (0x0000 = 0v, 0xFFFF = 3.3v) */ - void write_u16(unsigned short value) { + void write_u16(unsigned short value) + { lock(); analogout_write_u16(&_dac, value); unlock(); @@ -95,7 +98,8 @@ * @note * This value may not match exactly the value set by a previous write(). */ - float read() { + float read() + { lock(); float ret = analogout_read(&_dac); unlock(); @@ -105,7 +109,8 @@ /** An operator shorthand for write() * \sa AnalogOut::write() */ - AnalogOut& operator= (float percent) { + AnalogOut &operator= (float percent) + { // Underlying write call is thread safe write(percent); return *this; @@ -114,7 +119,8 @@ /** An operator shorthand for write() * \sa AnalogOut::write() */ - AnalogOut& operator= (AnalogOut& rhs) { + AnalogOut &operator= (AnalogOut &rhs) + { // Underlying write call is thread safe write(rhs.read()); return *this; @@ -123,22 +129,26 @@ /** An operator shorthand for read() * \sa AnalogOut::read() */ - operator float() { + operator float() + { // Underlying read call is thread safe return read(); } - virtual ~AnalogOut() { + virtual ~AnalogOut() + { // Do nothing } protected: - virtual void lock() { + virtual void lock() + { _mutex.lock(); } - virtual void unlock() { + virtual void unlock() + { _mutex.unlock(); }