diff options
Diffstat (limited to 'dumblogger/datalogger.cpp')
| -rw-r--r-- | dumblogger/datalogger.cpp | 48 |
1 files changed, 38 insertions, 10 deletions
diff --git a/dumblogger/datalogger.cpp b/dumblogger/datalogger.cpp index 0b3d82c..9dace67 100644 --- a/dumblogger/datalogger.cpp +++ b/dumblogger/datalogger.cpp @@ -114,7 +114,6 @@ const int sensor_pin = 12; void hardwareSetup(void) { spi.begin(SPI_281_250KHZ, MSBFIRST, 0); // move to sdcard init? - pinMode(YEL_LED, OUTPUT); pinMode(GRN_LED, OUTPUT); pinMode(BLU_LED, OUTPUT); @@ -122,8 +121,10 @@ void hardwareSetup(void) { digitalWrite(BLU_LED, LOW); digitalWrite(GRN_LED, HIGH); SerialUSB.begin(); - Serial1.begin(9600); - Serial2.begin(9600); +#ifdef LOGGING_SERIAL_DEVICE + Serial1.begin(9600); +#endif + Serial2.begin(9600); // probably should initialize the monitor. sdCardStatus=sdCardInit(); @@ -131,7 +132,8 @@ void hardwareSetup(void) { /*-----------------------------------------------------------------------Setup() * *----------------------------------------------------------------------------*/ - +HardwareTimer timer(1); +static void ledTask(); void setup( void ) { hardwareSetup(); @@ -146,8 +148,26 @@ void setup( void ) // Setup the sensor pin as an analog input pinMode(sensor_pin,INPUT_ANALOG); - registerAction(_DIR_, DIRaction); + setupKeywords(); + registerAction(_DIR_, &DIRaction); + registerAction(_TYP_, &TYPaction); + timer.pause(); + + // Set up period + timer.setPeriod(1000); // in microseconds + + // Set up an interrupt on channel 1 + timer.setMode(TIMER_CH1,TIMER_OUTPUT_COMPARE); + timer.setCompare(TIMER_CH1, 1); // Interrupt 1 count after each update + timer.attachInterrupt(TIMER_CH1,ledTask); + + + // Refresh the timer's count, prescale, and overflow + timer.refresh(); + + // Start the timer counting + timer.resume(); } @@ -156,13 +176,15 @@ void setup( void ) *----------------------------------------------------------------------------*/ static void ledTask() -{ - togglePin(BLU_LED); +{ static int count; + if (++count>=500) { + togglePin(BLU_LED); + count=0; + } } static void serialTasks() { char ch; - setupKeywords(); while ((consoleComm.gotline==false) && (SerialUSB.available())) { if ((((ch=SerialUSB.read())!='\r') && (ch!='\n')) &&(consoleComm.len<MAX_COMMAND_LINE_LENGTH) @@ -176,6 +198,7 @@ static void serialTasks() { } //SerialUSB.write(ch); } +#ifdef LOGGING_SERIAL_DEVICE while ((deviceComm.gotline==false) && (Serial1.available())) { if ((((ch=Serial1.read())!='\r') && (ch!='\n')) &&(deviceComm.len<MAX_COMMAND_LINE_LENGTH) @@ -189,6 +212,7 @@ static void serialTasks() { } //SerialUSB.write(ch); } +#endif } // Force init to be called *first*, i.e. before static object allocation. @@ -202,10 +226,14 @@ int main(void) { // should never get past setup. while (true) { serialTasks(); //move to - if (consoleComm.gotline) { + if (consoleComm.gotline) { handleConsoleInput(&consoleComm); } - +#ifdef LOGGING_SERIAL_DEVICE + if (deviceComm.gotline) { + handleDeviceInput(&deviceComm); + } +#endif } |
