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: EthernetInterfacePlusHostname NTPClient Onewire RdWebServer SDFileSystem-RTOS mbed-rtos mbed-src
VoltAlerter.cpp@22:14b4060dd027, 2015-10-16 (annotated)
- Committer:
- Bobty
- Date:
- Fri Oct 16 08:42:13 2015 +0000
- Revision:
- 22:14b4060dd027
- Parent:
- 10:72eb217def1f
Re-enabled web folder view on server
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Bobty | 10:72eb217def1f | 1 | // Detect stat of Volt-Alerter |
| Bobty | 10:72eb217def1f | 2 | // Device produces a square wave when voltage detected |
| Bobty | 10:72eb217def1f | 3 | // Cycle time of square wave around 100ms |
| Bobty | 10:72eb217def1f | 4 | // Rob Dobson, 2015 |
| Bobty | 10:72eb217def1f | 5 | |
| Bobty | 10:72eb217def1f | 6 | #include "VoltAlerter.h" |
| Bobty | 10:72eb217def1f | 7 | |
| Bobty | 10:72eb217def1f | 8 | VoltAlerter::VoltAlerter(PinName pinName) : |
| Bobty | 10:72eb217def1f | 9 | _inPin(pinName, PullUp) |
| Bobty | 10:72eb217def1f | 10 | { |
| Bobty | 10:72eb217def1f | 11 | _curPinState = 0; |
| Bobty | 10:72eb217def1f | 12 | _consecutiveLows = 0; |
| Bobty | 10:72eb217def1f | 13 | } |
| Bobty | 10:72eb217def1f | 14 | |
| Bobty | 10:72eb217def1f | 15 | void VoltAlerter::Service() |
| Bobty | 10:72eb217def1f | 16 | { |
| Bobty | 10:72eb217def1f | 17 | // Check pin |
| Bobty | 10:72eb217def1f | 18 | if (!_inPin) |
| Bobty | 10:72eb217def1f | 19 | { |
| Bobty | 10:72eb217def1f | 20 | _curPinState = 1; |
| Bobty | 10:72eb217def1f | 21 | _consecutiveLows = 0; |
| Bobty | 10:72eb217def1f | 22 | return; |
| Bobty | 10:72eb217def1f | 23 | } |
| Bobty | 10:72eb217def1f | 24 | |
| Bobty | 10:72eb217def1f | 25 | // Only set state low if we get X consecutive lows |
| Bobty | 10:72eb217def1f | 26 | _consecutiveLows++; |
| Bobty | 10:72eb217def1f | 27 | if (_consecutiveLows >= CONSECUTIVE_LOWS_REQD_FOR_LOW) |
| Bobty | 10:72eb217def1f | 28 | { |
| Bobty | 10:72eb217def1f | 29 | _curPinState = 0; |
| Bobty | 10:72eb217def1f | 30 | // The following is just to ensure the int doesn't overflow |
| Bobty | 10:72eb217def1f | 31 | _consecutiveLows = CONSECUTIVE_LOWS_REQD_FOR_LOW; |
| Bobty | 10:72eb217def1f | 32 | } |
| Bobty | 10:72eb217def1f | 33 | } |
| Bobty | 10:72eb217def1f | 34 |