Dave H's version of the EVB Demo. Sends to specific conduit, and sends with a comma separated text string
Dependencies: DOGS102 ISL29011 MMA845x MPL3115A2 NCP5623B libmDot mbed-rtos mbed-src
Fork of MTDOT-EVBDemo by
Revision 3:68e974f5f532, committed 2015-07-15
- Comitter:
- falingtrea
- Date:
- Wed Jul 15 14:20:33 2015 +0000
- Parent:
- 2:75adc72aa6a0
- Child:
- 4:51d7c24bbf91
- Commit message:
- Added threads for push button switch debounce.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Jul 09 20:32:03 2015 +0000 +++ b/main.cpp Wed Jul 15 14:20:33 2015 +0000 @@ -2,7 +2,7 @@ * @file main.cpp * @brief Main application for mDot-EVB demo * @author Tim Barr MultiTech Systems Inc. - * @version 1.02 + * @version 1.03 * @see * * Copyright (c) 2015 @@ -21,10 +21,13 @@ * * 1.01 TAB 7/6/15 Removed NULL pointer from evbAmbientLight creation call. * - * 1.02 TAB 7/9/15 Send logo to LCD before attempting connection to LoRa network. Added + * 1.02 TAB 7/8/15 Send logo to LCD before attempting connection to LoRa network. Added * information on setting up for public LoRa network. Moved SW setup to * beginning of main. Removed printf call from ISR functions. Added * additional checks for exit_program. + * + * 1.03 TAB 7/15/15 Added threads for push button switch debounce. + * */ #include "mbed.h" @@ -130,15 +133,20 @@ convert32 convertl; convert16 converts; +// flags for pushbutton debounce code +bool pb1_low = false; +bool pb2_low = false; + void pb1ISR(void); void pb2ISR(void); +void pb1_debounce(void const *args); +void pb2_debounce(void const *args); +Thread* thread_3; void log_error(mDot* dot, const char* msg, int32_t retval); void config_pkt_xmit (void const *args); -Thread* thread1; - int main() { @@ -149,7 +157,10 @@ debugUART.baud(921600); // mDotUART.baud(9600); // mdot UART unused but available on external connector - thread1 = new Thread(config_pkt_xmit); // start thread that sends LoRa packet when SW2 pressed + Thread thread_1(pb1_debounce); // threads for de-bouncing pushbutton switches + Thread thread_2(pb2_debounce); + + thread_3 = new Thread(config_pkt_xmit); // start thread that sends LoRa packet when SW2 pressed evbAccel = new MMA845x(mDoti2c,MMA845x::SA0_VSS); // setup Accelerometer evbBaro = new MPL3115A2(mDoti2c); // setup Barometric sensor @@ -530,28 +541,78 @@ } /* - * Ends program when button 1 pushed + * Sets pb1_low flag. Slag is cleared in pb1_debounce thread */ void pb1ISR(void) { + if (!pb1_low) + pb1_low = true; +} - exit_program = true; +/* + * Debounces pb1. Also exits program if pushbutton 1 is pressed + */ +void pb1_debounce(void const *args) +{ + + static uint8_t count = 0; + + while (true) { + + if (pb1_low && (mDot08 == 0)) + count++; + else { + count = 0; + pb1_low = false; + } + + if (count == 5) + exit_program = true; + + Thread::wait(5); + } } /* - * changes packet transmit time to every other, every fifth, or every tenth sample when SW2 pushed - * Also triggers a thread to transmit a configuration packet + * Sets pb2_low flag. Flag is cleared in pb2_debounce thread */ void pb2ISR(void) { + if (!pb2_low) + pb2_low = true; +} - if (pckt_time >= 5) - pckt_time /= 2; - else pckt_time = 20; +/* + * Debounces pb2. Also changes packet transmit time to every other, + * every fifth, or every tenth sample when SW2 pushed + * Also triggers a thread to transmit a configuration packet + */ +void pb2_debounce(void const *args) +{ + + static uint8_t count = 0; + + while (true) { - thread1->signal_set(0x10); // signal config_pkt_xmit to send packet + if (pb2_low && (mDot09 == 0)) + count++; + else { + count = 0; + pb2_low = false; + } + + if (count == 5){ -} + if (pckt_time >= 5) + pckt_time /= 2; + else pckt_time = 20; + + thread_3->signal_set(0x10); // signal config_pkt_xmit to send packet + } + + Thread::wait(5); + } + } /* * Function that print clear text verion of mDot errors