Jon Trinder
/
gu_squirt_tester
Test code for interfacing to megasquirt ECU.
Counter/Counter.h@0:cf99a7b873b3, 2015-02-14 (annotated)
- Committer:
- jont
- Date:
- Sat Feb 14 08:50:32 2015 +0000
- Revision:
- 0:cf99a7b873b3
First version checkpoint
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jont | 0:cf99a7b873b3 | 1 | #ifndef COUNTER_ |
jont | 0:cf99a7b873b3 | 2 | #define COUNTER_ |
jont | 0:cf99a7b873b3 | 3 | |
jont | 0:cf99a7b873b3 | 4 | #define DEBOUNCING_INTERVAL 200 // Debouncing interval (in mili-seconds) |
jont | 0:cf99a7b873b3 | 5 | /*=====================================================================================*/ |
jont | 0:cf99a7b873b3 | 6 | // Counter object, which also setups up irq |
jont | 0:cf99a7b873b3 | 7 | /*=====================================================================================*/ |
jont | 0:cf99a7b873b3 | 8 | |
jont | 0:cf99a7b873b3 | 9 | //from http://mbed.org/handbook/InterruptIn, modified to add debouncing |
jont | 0:cf99a7b873b3 | 10 | class Counter |
jont | 0:cf99a7b873b3 | 11 | { |
jont | 0:cf99a7b873b3 | 12 | public: |
jont | 0:cf99a7b873b3 | 13 | Counter(PinName pin, void (*function)(void)); |
jont | 0:cf99a7b873b3 | 14 | |
jont | 0:cf99a7b873b3 | 15 | void increment(); |
jont | 0:cf99a7b873b3 | 16 | |
jont | 0:cf99a7b873b3 | 17 | int read(); |
jont | 0:cf99a7b873b3 | 18 | |
jont | 0:cf99a7b873b3 | 19 | int set(int val); |
jont | 0:cf99a7b873b3 | 20 | |
jont | 0:cf99a7b873b3 | 21 | void reset(); |
jont | 0:cf99a7b873b3 | 22 | |
jont | 0:cf99a7b873b3 | 23 | private: |
jont | 0:cf99a7b873b3 | 24 | InterruptIn _interrupt; |
jont | 0:cf99a7b873b3 | 25 | volatile int _count; |
jont | 0:cf99a7b873b3 | 26 | Timer t; // To manage debounce by menchanical switch |
jont | 0:cf99a7b873b3 | 27 | protected: |
jont | 0:cf99a7b873b3 | 28 | //the callback |
jont | 0:cf99a7b873b3 | 29 | FunctionPointer jim; |
jont | 0:cf99a7b873b3 | 30 | }; |
jont | 0:cf99a7b873b3 | 31 | |
jont | 0:cf99a7b873b3 | 32 | |
jont | 0:cf99a7b873b3 | 33 | |
jont | 0:cf99a7b873b3 | 34 | #endif |