![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Version 8, working version with Alix, sams and ollies code. Displays time, date and sensor info onto terminal, LCD and networking, and saves onto SD card.
Dependencies: BMP280 ELEC350-Practicals-FZ429 TextLCD BME280 ntp-client
SwitchManager.hpp@12:4c7eaac8ceef, 2018-12-31 (annotated)
- Committer:
- Alix955
- Date:
- Mon Dec 31 19:20:22 2018 +0000
- Revision:
- 12:4c7eaac8ceef
- Parent:
- 9:f5eae5211225
Version 8, integration of Alix & Sams work with older(?) version of ollies. Displays time, date and all sensor information onto LCD, Terminal and Networking, and saves sensor info to SD card.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Alix955 | 9:f5eae5211225 | 1 | #ifndef _SWITCHMANAGER_ |
Alix955 | 9:f5eae5211225 | 2 | #define _SWITCHMANAGER_ |
Alix955 | 9:f5eae5211225 | 3 | |
Alix955 | 9:f5eae5211225 | 4 | #include "mbed.h" |
Alix955 | 9:f5eae5211225 | 5 | #include "sample_hardware.hpp" |
Alix955 | 9:f5eae5211225 | 6 | #include "LCD.hpp" |
Alix955 | 9:f5eae5211225 | 7 | |
Alix955 | 9:f5eae5211225 | 8 | InterruptIn sw1(PE_12); |
Alix955 | 9:f5eae5211225 | 9 | |
Alix955 | 9:f5eae5211225 | 10 | //This class manages an Interrupt attached to a button |
Alix955 | 9:f5eae5211225 | 11 | //It automatically manages the switch-debounce using edge detection and timers |
Alix955 | 9:f5eae5211225 | 12 | |
Alix955 | 9:f5eae5211225 | 13 | class SwitchManager { |
Alix955 | 9:f5eae5211225 | 14 | private: |
Alix955 | 9:f5eae5211225 | 15 | // enum State {LOW, LOW_DEBOUNCE, HIGH, HIGH_DEBOUNCE}; |
Alix955 | 9:f5eae5211225 | 16 | InterruptIn& switchInterrupt; |
Alix955 | 9:f5eae5211225 | 17 | Timeout t; |
Alix955 | 9:f5eae5211225 | 18 | |
Alix955 | 9:f5eae5211225 | 19 | void waitForRising() { |
Alix955 | 9:f5eae5211225 | 20 | //Turn off interrupt |
Alix955 | 9:f5eae5211225 | 21 | switchInterrupt.rise(NULL); |
Alix955 | 9:f5eae5211225 | 22 | //Turn on timer |
Alix955 | 9:f5eae5211225 | 23 | t.attach(callback(this, &SwitchManager::waitForStabilityRising), 0.2); |
Alix955 | 9:f5eae5211225 | 24 | } |
Alix955 | 9:f5eae5211225 | 25 | |
Alix955 | 9:f5eae5211225 | 26 | void waitForStabilityRising() { |
Alix955 | 9:f5eae5211225 | 27 | //Look for falling edge |
Alix955 | 9:f5eae5211225 | 28 | switchInterrupt.fall(callback(this, &SwitchManager::waitForFalling)); |
Alix955 | 9:f5eae5211225 | 29 | } |
Alix955 | 9:f5eae5211225 | 30 | |
Alix955 | 9:f5eae5211225 | 31 | void waitForFalling() { |
Alix955 | 12:4c7eaac8ceef | 32 | //When button is pressed, adds update_time_date function to the LCD queue |
Alix955 | 9:f5eae5211225 | 33 | m_oDisplay.LCD_Queue.call(&m_oDisplay, &LCD_Data::update_time_date); |
Alix955 | 9:f5eae5211225 | 34 | switchInterrupt.fall(NULL); |
Alix955 | 9:f5eae5211225 | 35 | t.attach(callback(this, &SwitchManager::waitForStabilityFalling), 0.2); |
Alix955 | 9:f5eae5211225 | 36 | } |
Alix955 | 9:f5eae5211225 | 37 | |
Alix955 | 9:f5eae5211225 | 38 | void waitForStabilityFalling() { |
Alix955 | 9:f5eae5211225 | 39 | //Look for rising edge |
Alix955 | 9:f5eae5211225 | 40 | switchInterrupt.rise(callback(this, &SwitchManager::waitForRising)); |
Alix955 | 9:f5eae5211225 | 41 | } |
Alix955 | 9:f5eae5211225 | 42 | |
Alix955 | 9:f5eae5211225 | 43 | public: |
Alix955 | 9:f5eae5211225 | 44 | SwitchManager(InterruptIn& intIn) : switchInterrupt(intIn) { |
Alix955 | 9:f5eae5211225 | 45 | //Listen for rising edge |
Alix955 | 9:f5eae5211225 | 46 | switchInterrupt.rise(callback(this, &SwitchManager::waitForRising)); |
Alix955 | 9:f5eae5211225 | 47 | } |
Alix955 | 9:f5eae5211225 | 48 | ~SwitchManager() { |
Alix955 | 9:f5eae5211225 | 49 | //Turn off LED and shut off any ISRs |
Alix955 | 9:f5eae5211225 | 50 | switchInterrupt.rise(NULL); |
Alix955 | 9:f5eae5211225 | 51 | switchInterrupt.fall(NULL); |
Alix955 | 9:f5eae5211225 | 52 | t.detach(); |
Alix955 | 9:f5eae5211225 | 53 | } |
Alix955 | 9:f5eae5211225 | 54 | }; |
Alix955 | 9:f5eae5211225 | 55 | |
Alix955 | 9:f5eae5211225 | 56 | SwitchManager sm1(sw1); |
Alix955 | 9:f5eae5211225 | 57 | |
Alix955 | 9:f5eae5211225 | 58 | #endif |