Solution for Bluetooth SIG hands-on training course
Dependencies: BLE_API mbed-dev-bin nRF51822-bluetooth-mdw
Fork of microbit-dal-bluetooth-mdw_starter by
Diff: source/drivers/MicroBitPin.cpp
- Revision:
- 66:2fc7d7c2fffc
- Parent:
- 65:f7ebabf23e15
diff -r f7ebabf23e15 -r 2fc7d7c2fffc source/drivers/MicroBitPin.cpp --- a/source/drivers/MicroBitPin.cpp Wed Jul 13 12:18:45 2016 +0100 +++ b/source/drivers/MicroBitPin.cpp Wed Jul 13 12:18:46 2016 +0100 @@ -57,6 +57,7 @@ this->id = id; this->name = name; this->capability = capability; + this->pullMode = MICROBIT_DEFAULT_PULLMODE; // Power up in a disconnected, low power state. // If we're unused, this is how it will stay... @@ -159,7 +160,7 @@ if (!(status & (IO_STATUS_DIGITAL_IN | IO_STATUS_EVENT_ON_EDGE | IO_STATUS_EVENT_PULSE_ON_EDGE))) { disconnect(); - pin = new DigitalIn(name,PullDown); + pin = new DigitalIn(name, (PinMode)pullMode); status |= IO_STATUS_DIGITAL_IN; } @@ -169,6 +170,25 @@ return ((DigitalIn *)pin)->read(); } +/** + * Configures this IO pin as a digital input with the specified internal pull-up/pull-down configuraiton (if necessary) and tests its current value. + * + * @param pull one of the mbed pull configurations: PullUp, PullDown, PullNone + * + * @return 1 if this input is high, 0 if input is LO, or MICROBIT_NOT_SUPPORTED + * if the given pin does not have digital capability. + * + * @code + * MicroBitPin P0(MICROBIT_ID_IO_P0, MICROBIT_PIN_P0, PIN_CAPABILITY_BOTH); + * P0.getDigitalValue(PullUp); // P0 is either 0 or 1; + * @endcode + */ +int MicroBitPin::getDigitalValue(PinMode pull) +{ + setPull(pull); + return getDigitalValue(); +} + int MicroBitPin::obtainAnalogChannel() { // Move into an analogue input state if necessary, if we are no longer the focus of a DynamicPWM instance, allocate ourselves again! @@ -451,6 +471,8 @@ */ int MicroBitPin::setPull(PinMode pull) { + pullMode = pull; + if ((status & IO_STATUS_DIGITAL_IN)) { ((DigitalIn *)pin)->mode(pull); @@ -528,7 +550,7 @@ disconnect(); pin = new TimedInterruptIn(name); - ((TimedInterruptIn *)pin)->mode(PullDown); + ((TimedInterruptIn *)pin)->mode((PinMode)pullMode); ((TimedInterruptIn *)pin)->rise(this, &MicroBitPin::onRise); ((TimedInterruptIn *)pin)->fall(this, &MicroBitPin::onFall); }