Misc bug fixes, minor code cleanup, initial sd card data logging implementation

This commit is contained in:
Mike C 2013-04-25 21:38:21 -04:00
parent c6c7ec4ad5
commit f4f8367236
6 changed files with 84 additions and 42 deletions

View file

@ -238,11 +238,13 @@ void Config::processSerialData() {
int inByte = Serial3.read();
Serial.write(inByte);
ui->blinkCancelButton();
dataFile.print(inByte);
}
if (Serial.available()) {
int inByte = Serial.read();
Serial3.write(inByte);
ui->blinkOKButton();
dataFile.print(inByte);
}
break;
case 1: // db9_null
@ -250,11 +252,13 @@ void Config::processSerialData() {
int inByte = Serial2.read();
Serial.write(inByte);
ui->blinkCancelButton();
dataFile.print(inByte);
}
if (Serial.available()) {
int inByte = Serial.read();
Serial2.write(inByte);
ui->blinkOKButton();
dataFile.print(inByte);
}
break;
case 2: // cisco
@ -262,12 +266,17 @@ void Config::processSerialData() {
int inByte = Serial1.read();
Serial.write(inByte);
ui->blinkCancelButton();
dataFile.print(inByte);
}
if (Serial.available()) {
int inByte = Serial.read();
Serial1.write(inByte);
ui->blinkOKButton();
dataFile.print(inByte);
}
break;
}
// Flush data written to log file
dataFile.flush();
}

View file

@ -13,6 +13,7 @@
#include "Project.h"
#include "UI.h"
#include <SD.h>
// Forward declaration of UI
class UI;
@ -20,6 +21,9 @@ class UI;
// Use global config and ui objects defined / initialized in main ino file
extern UI* ui;
// File to log data to
extern File dataFile;
class Config {
private:
// Mode info needed

View file

@ -36,6 +36,9 @@
// Timer pins
#define timerThreePin 2 // Maps to Mega pin 12
// Splash screen related
#define splashScreenFileName "splash.bmp"
// Colors / theme of UI
#define SPLASH_BACKGROUND ST7735_WHITE
#define BACKGROUND ST7735_BLACK

View file

@ -30,14 +30,22 @@ UI::UI() {
}
void UI::blinkOKButton() {
if (!config->isUIEnabled()) {
if (config->isUIEnabled()) {
okButton->turnOffLed();
okButton->turnOnLed();
}
else {
okButton->turnOnLed();
okButton->turnOffLed();
}
}
void UI::blinkCancelButton() {
if (!config->isUIEnabled()) {
if (config->isUIEnabled()) {
cancelButton->turnOffLed();
cancelButton->turnOnLed();
}
else {
cancelButton->turnOnLed();
cancelButton->turnOffLed();
}

View file

@ -29,7 +29,7 @@ UILCD::UILCD() {
tft->initR(INITR_BLACKTAB);
tft->setRotation(3);
if (!SD.begin(SD_CS) && DEBUG) {
if (!SD.begin(SD_CS)) {
Serial.println("SD.begin(SD_CS) -- failed!");
}
}
@ -188,17 +188,17 @@ void UILCD::mainScreenHilight(joyDirection direction) {
// Skip blank lines
if (config->getSerialMode() == ttl) {
#if DEBUG == 2
#if DEBUG == 2
Serial.println("Serial ttl blank line skip");
#endif
#endif
if (currentLine == 3 || currentLine == 6) {
currentLine -= 1;
}
}
else {
#if DEBUG == 2
#if DEBUG == 2
Serial.println("Non-serial ttl blank line skip");
#endif
#endif
if (currentLine == 2 || currentLine == 5) {
currentLine -= 1;
}
@ -225,17 +225,17 @@ void UILCD::mainScreenHilight(joyDirection direction) {
// Skip blank lines
if (config->getSerialMode() == ttl) {
#if DEBUG == 2
#if DEBUG == 2
Serial.println("Serial ttl blank line skip");
#endif
#endif
if (currentLine == 3 || currentLine == 6) {
currentLine += 1;
}
}
else {
#if DEBUG == 2
#if DEBUG == 2
Serial.println("Non-serial ttl blank line skip");
#endif
#endif
if (currentLine == 2 || currentLine == 5) {
currentLine += 1;
}
@ -472,7 +472,7 @@ void UILCD::drawSplashScreen() {
#endif
tft->setCursor(0,0);
tft->fillScreen(SPLASH_BACKGROUND);
bmpDraw("splash.bmp", 13, 0);
bmpDraw(splashScreenFileName, 13, 0);
delay(1250);
for (int16_t y=0; y < tft->height(); y+=1) {
tft->drawFastHLine(0, y, tft->width(), BACKGROUND);
@ -481,9 +481,10 @@ void UILCD::drawSplashScreen() {
}
void UILCD::bmpDraw(char *filename, uint8_t x, uint8_t y) {
#if DEBUG == 2
#if DEBUG == 2
Serial.println("UILCD::bmpDraw()");
#endif
#endif
File bmpFile;
int bmpWidth, bmpHeight; // W+H in pixels
uint8_t bmpDepth; // Bit depth (currently must be 24)
@ -497,40 +498,47 @@ void UILCD::bmpDraw(char *filename, uint8_t x, uint8_t y) {
uint8_t r, g, b;
uint32_t pos = 0, startTime = millis();
if((x >= tft->width()) || (y >= tft->height())) return;
if((x >= tft->width()) || (y >= tft->height())) {
return;
}
#if DEBUG == 2
#if DEBUG == 2
Serial.println();
Serial.print("Loading image '");
Serial.print(filename);
Serial.println('\'');
#endif
#endif
// Open requested file on SD card
if ((bmpFile = SD.open(filename)) == NULL) {
#if DEBUG == 2
Serial.print("File not found");
#endif
return;
}
// Parse BMP header
if(read16(bmpFile) == 0x4D42) { // BMP signature
long fileSize = read32(bmpFile);
#if DEBUG == 2
Serial.print("File size: ");
Serial.println(read32(bmpFile));
Serial.println(fileSize);
#endif
(void)read32(bmpFile); // Read & ignore creator bytes
bmpImageoffset = read32(bmpFile); // Start of image data
#if DEBUG == 2
Serial.print("Image Offset: ");
Serial.println(bmpImageoffset, DEC);
#endif
// Read DIB header
float headerSize = read32(bmpFile);
#if DEBUG == 2
// Read DIB header
Serial.print("Header size: ");
Serial.println(read32(bmpFile));
Serial.println(headerSize);
#endif
bmpWidth = read32(bmpFile);
bmpHeight = read32(bmpFile);
if(read16(bmpFile) == 1) { // # planes -- must be '1'
@ -540,7 +548,6 @@ void UILCD::bmpDraw(char *filename, uint8_t x, uint8_t y) {
Serial.println(bmpDepth);
#endif
if((bmpDepth == 24) && (read32(bmpFile) == 0)) { // 0 = uncompressed
goodBmp = true; // Supported BMP format -- proceed!
#if DEBUG == 2
Serial.print("Image size: ");
@ -562,8 +569,12 @@ void UILCD::bmpDraw(char *filename, uint8_t x, uint8_t y) {
// Crop area to be loaded
w = bmpWidth;
h = bmpHeight;
if((x+w-1) >= tft->width()) w = tft->width() - x;
if((y+h-1) >= tft->height()) h = tft->height() - y;
if((x+w-1) >= tft->width()) {
w = tft->width() - x;
}
if((y+h-1) >= tft->height()) {
h = tft->height() - y;
}
// Set TFT address window to clipped image bounds
tft->setAddrWindow(x, y, x+w-1, y+h-1);
@ -576,10 +587,12 @@ void UILCD::bmpDraw(char *filename, uint8_t x, uint8_t y) {
// and scanline padding. Also, the seek only takes
// place if the file position actually needs to change
// (avoids a lot of cluster math in SD library).
if(flip) // Bitmap is stored bottom-to-top order (normal BMP)
if(flip) { // Bitmap is stored bottom-to-top order (normal BMP)
pos = bmpImageoffset + (bmpHeight - 1 - row) * rowSize;
else // Bitmap is stored top-to-bottom
}
else { // Bitmap is stored top-to-bottom
pos = bmpImageoffset + row * rowSize;
}
if(bmpFile.position() != pos) { // Need seek?
bmpFile.seek(pos);
buffidx = sizeof(sdbuffer); // Force buffer reload
@ -610,7 +623,9 @@ void UILCD::bmpDraw(char *filename, uint8_t x, uint8_t y) {
}
bmpFile.close();
if(!goodBmp && DEBUG == 2) Serial.println("BMP format not recognized.");
if(!goodBmp) {
Serial.println("BMP format not recognized.");
}
}
// These read 16- and 32-bit types from the SD card file.

View file

@ -29,6 +29,7 @@
UI* ui;
Config* config;
RTC_DS1307 rtc;
File dataFile;
// helper for interrupt method call
void processSerial() {
@ -63,6 +64,8 @@ void setup() {
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
dataFile = SD.open("datalog.txt", FILE_WRITE);
}
void loop() {