2013-03-10 18:26:41 +00:00
|
|
|
/*
|
|
|
|
Serial Adapter Project: Dynamic serial TTY passthroughs
|
2013-03-27 01:38:14 +00:00
|
|
|
by: Mike Crosson
|
|
|
|
Nusku Networks
|
|
|
|
date: 2013/03/09
|
|
|
|
license: CC-BY SA 3.0 - Creative commons share-alike 3.0
|
|
|
|
use this code however you'd like, just keep this license and
|
|
|
|
attribute.
|
|
|
|
*/
|
2013-03-10 18:26:41 +00:00
|
|
|
|
2013-04-25 22:14:23 +00:00
|
|
|
#include <Wire.h>
|
2013-04-09 21:56:19 +00:00
|
|
|
|
2013-03-10 18:26:41 +00:00
|
|
|
#include "Project.h"
|
2013-04-07 03:20:17 +00:00
|
|
|
#include "Config.h"
|
2013-04-06 21:01:46 +00:00
|
|
|
#include "UIButton.h"
|
|
|
|
#include "UIJoystickPSP.h"
|
2013-04-06 23:21:06 +00:00
|
|
|
#include "UILCD.h"
|
2013-04-07 05:32:42 +00:00
|
|
|
#include "UI.h"
|
2013-03-13 20:29:54 +00:00
|
|
|
|
2013-04-06 22:44:34 +00:00
|
|
|
#include <Adafruit_GFX.h>
|
|
|
|
#include <Adafruit_ST7735.h>
|
|
|
|
#include <SPI.h>
|
2013-04-26 18:17:21 +00:00
|
|
|
#include <SerialPort.h>
|
|
|
|
#include <SdFile.h>
|
|
|
|
#include <SdFat.h>
|
2013-04-06 22:44:34 +00:00
|
|
|
|
2013-04-25 02:49:26 +00:00
|
|
|
#include <TimerThree.h>
|
2013-04-25 23:40:07 +00:00
|
|
|
#include <Metro.h>
|
|
|
|
#include "RTClib.h"
|
2013-04-25 02:49:26 +00:00
|
|
|
|
2013-04-27 21:34:35 +00:00
|
|
|
// Globals used by main classes
|
2013-04-07 05:32:42 +00:00
|
|
|
UI* ui;
|
|
|
|
Config* config;
|
2013-04-25 22:14:23 +00:00
|
|
|
RTC_DS1307 rtc;
|
2013-04-27 21:34:35 +00:00
|
|
|
SdFile dataFile;
|
|
|
|
SdFat sd;
|
|
|
|
|
|
|
|
#if ARD_DUE
|
2013-04-27 18:57:28 +00:00
|
|
|
SerialPort<0, 4096, 4096> serialPort0;
|
|
|
|
SerialPort<1, 4096, 4096> serialPort1;
|
|
|
|
SerialPort<2, 4096, 4096> serialPort2;
|
|
|
|
SerialPort<3, 4096, 4096> serialPort3;
|
2013-04-27 21:34:35 +00:00
|
|
|
#else
|
|
|
|
SerialPort<0, 512, 512> serialPort0;
|
|
|
|
SerialPort<1, 512, 512> serialPort1;
|
|
|
|
SerialPort<2, 512, 512> serialPort2;
|
|
|
|
SerialPort<3, 512, 512> serialPort3;
|
2013-04-27 18:57:28 +00:00
|
|
|
#endif
|
2013-04-06 22:44:34 +00:00
|
|
|
|
2013-04-25 02:49:26 +00:00
|
|
|
// helper for interrupt method call
|
|
|
|
void processSerial() {
|
|
|
|
config->processSerialData();
|
|
|
|
}
|
|
|
|
|
2013-03-10 18:26:41 +00:00
|
|
|
void setup() {
|
2013-04-25 22:14:23 +00:00
|
|
|
// Setup various IO busses
|
2013-04-26 18:17:21 +00:00
|
|
|
serialPort0.begin(115200);
|
2013-04-25 22:14:23 +00:00
|
|
|
Wire.begin();
|
2013-04-17 02:02:09 +00:00
|
|
|
|
2013-04-27 21:34:35 +00:00
|
|
|
// Start the SD Card -- This should come very early
|
|
|
|
// Not in config to guarantee it comes online very very early
|
|
|
|
serialPort0.println("Starting SD card");
|
|
|
|
if (!sd.begin(SD_CS, SPI_PROJECT_SPEED )) {
|
|
|
|
serialPort0.println("SD.begin(SD_CS, SPI_SPEED ) -- failed!");
|
|
|
|
sd.initErrorHalt();
|
|
|
|
}
|
|
|
|
|
2013-04-25 22:14:23 +00:00
|
|
|
// Ensure RTC is set to run on battery
|
|
|
|
// clear /EOSC bit
|
|
|
|
// Sometimes necessary to ensure that the clock
|
|
|
|
// keeps running on just battery power. Once set,
|
|
|
|
// it shouldn't need to be reset but it's a good
|
|
|
|
// idea to make sure.
|
|
|
|
Wire.beginTransmission(0x68); // address DS3231
|
|
|
|
Wire.write(0x0E); // select register
|
|
|
|
Wire.write(0b00011100); // write register bitmap, bit 7 is /EOSC
|
|
|
|
Wire.endTransmission();
|
|
|
|
|
2013-04-26 18:17:21 +00:00
|
|
|
// Start real time clock
|
2013-04-25 22:14:23 +00:00
|
|
|
rtc.begin();
|
|
|
|
|
|
|
|
// Stuff used for serial and UI
|
2013-04-07 03:20:17 +00:00
|
|
|
config = new Config();
|
|
|
|
config->setDefaults();
|
2013-04-17 23:59:03 +00:00
|
|
|
ui = new UI();
|
2013-04-25 02:49:26 +00:00
|
|
|
|
2013-04-26 18:17:21 +00:00
|
|
|
// Open data log file -- FIXME: This needs to be controlled via config some
|
2013-04-27 21:21:21 +00:00
|
|
|
//dataFile.open("datalog.txt", O_WRITE | O_CREAT | O_AT_END);
|
2013-04-26 18:17:21 +00:00
|
|
|
|
2013-04-25 02:49:26 +00:00
|
|
|
// Setup serial IO on an interrupt timer
|
|
|
|
// ***THIS MUST BE DONE AFTER new Config()***
|
2013-04-26 18:17:21 +00:00
|
|
|
// ***THIS MUST BE DONE AFTER SD INIT***
|
2013-04-25 02:49:26 +00:00
|
|
|
Timer3.initialize(100); // initialize timer3, value in micro seconds
|
|
|
|
Timer3.pwm(timerThreePin, 512); // setup pwm on appropriate pin, 50% duty cycle
|
|
|
|
Timer3.attachInterrupt(processSerial); // attaches method as a timer overflow interrupt
|
2013-03-10 18:26:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
2013-04-25 02:49:26 +00:00
|
|
|
// Serial data is processed via an interrupt so isn't needed in the main loop
|
2013-04-07 05:32:42 +00:00
|
|
|
ui->processInputEvents();
|
2013-04-09 21:56:19 +00:00
|
|
|
ui->processTimeoutEvents();
|
2013-03-10 18:26:41 +00:00
|
|
|
}
|
2013-04-06 22:44:34 +00:00
|
|
|
|