Test code for interfacing to megasquirt ECU.

Dependencies:   jtlcd mbed

Committer:
jont
Date:
Mon Feb 16 08:34:14 2015 +0000
Revision:
4:50203a03ccd2
Parent:
0:cf99a7b873b3
Changed greeting message

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jont 0:cf99a7b873b3 1 #include "mbed.h"
jont 0:cf99a7b873b3 2 #include "Counter.h"
jont 0:cf99a7b873b3 3
jont 0:cf99a7b873b3 4 /*=====================================================================================*/
jont 0:cf99a7b873b3 5 // Counter object, which also setups up irq
jont 0:cf99a7b873b3 6 /*=====================================================================================*/
jont 0:cf99a7b873b3 7
jont 0:cf99a7b873b3 8 //from http://mbed.org/handbook/InterruptIn, modified to add debouncing
jont 0:cf99a7b873b3 9
jont 0:cf99a7b873b3 10 Counter::Counter(PinName pin, void (*function)(void)) : _interrupt(pin) { // create the InterruptIn on the pin specified to Counter
jont 0:cf99a7b873b3 11 _interrupt.fall(this, &Counter::increment); // attach increment function of this counter instance
jont 0:cf99a7b873b3 12 jim.attach(function);
jont 0:cf99a7b873b3 13 t.start(); // timer start
jont 0:cf99a7b873b3 14 }
jont 0:cf99a7b873b3 15
jont 0:cf99a7b873b3 16 void Counter::increment() {
jont 0:cf99a7b873b3 17 if ( t.read_ms() > DEBOUNCING_INTERVAL ) {
jont 0:cf99a7b873b3 18 _count++;
jont 0:cf99a7b873b3 19 time_t seconds = time(NULL);
jont 0:cf99a7b873b3 20 // RingWriteToBuffer(seconds);
jont 0:cf99a7b873b3 21
jont 0:cf99a7b873b3 22 jim.call();
jont 0:cf99a7b873b3 23
jont 0:cf99a7b873b3 24 }
jont 0:cf99a7b873b3 25 t.reset(); // timer reset
jont 0:cf99a7b873b3 26 }
jont 0:cf99a7b873b3 27
jont 0:cf99a7b873b3 28 int Counter::read() {
jont 0:cf99a7b873b3 29 return _count;
jont 0:cf99a7b873b3 30 }
jont 0:cf99a7b873b3 31
jont 0:cf99a7b873b3 32 int Counter::set(int val) {
jont 0:cf99a7b873b3 33 int was = _count;
jont 0:cf99a7b873b3 34 _count = val;
jont 0:cf99a7b873b3 35 return was;
jont 0:cf99a7b873b3 36 }
jont 0:cf99a7b873b3 37
jont 0:cf99a7b873b3 38 void Counter::reset() {
jont 0:cf99a7b873b3 39 _count = 0;
jont 0:cf99a7b873b3 40 }