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.
Dependencies: mbed BLE_API nRF51822
PowerSwitch/PowerSwitch.cpp@4:adfb32273577, 2019-08-02 (annotated)
- Committer:
- vilesovds
- Date:
- Fri Aug 02 08:22:18 2019 +0000
- Revision:
- 4:adfb32273577
- Parent:
- 0:81f1818af032
Simple project to control mirrorless camera
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| suhamera | 0:81f1818af032 | 1 | #include "PowerSwitch.h" |
| suhamera | 0:81f1818af032 | 2 | #include "mbed.h" |
| suhamera | 0:81f1818af032 | 3 | |
| suhamera | 0:81f1818af032 | 4 | PowerSwitch::PowerSwitch(PinName pin) : _pin(pin) { |
| suhamera | 0:81f1818af032 | 5 | powerState = false; |
| suhamera | 0:81f1818af032 | 6 | } |
| suhamera | 0:81f1818af032 | 7 | |
| suhamera | 0:81f1818af032 | 8 | void PowerSwitch::doSwitch(bool state, float duration){ |
| suhamera | 0:81f1818af032 | 9 | if (state) { |
| suhamera | 0:81f1818af032 | 10 | _pin = 1.0; |
| suhamera | 0:81f1818af032 | 11 | } else{ |
| suhamera | 0:81f1818af032 | 12 | _pin = 0.0; |
| suhamera | 0:81f1818af032 | 13 | } |
| suhamera | 0:81f1818af032 | 14 | |
| suhamera | 0:81f1818af032 | 15 | powerState = state; |
| suhamera | 0:81f1818af032 | 16 | switchPeriod.attach(this, &PowerSwitch::doSwitchEnd, duration); |
| suhamera | 0:81f1818af032 | 17 | |
| suhamera | 0:81f1818af032 | 18 | } |
| suhamera | 0:81f1818af032 | 19 | |
| suhamera | 0:81f1818af032 | 20 | bool PowerSwitch::powerStateOn(void){ |
| suhamera | 0:81f1818af032 | 21 | return powerState; |
| suhamera | 0:81f1818af032 | 22 | } |
| suhamera | 0:81f1818af032 | 23 | |
| suhamera | 0:81f1818af032 | 24 | void PowerSwitch::doSwitchEnd(void){ |
| suhamera | 0:81f1818af032 | 25 | switchPeriod.detach(); |
| suhamera | 0:81f1818af032 | 26 | _pin = 0.0; |
| suhamera | 0:81f1818af032 | 27 | } |