Fixed implementation of splash graphic on boot, minor tweaks
This commit is contained in:
parent
2558981f76
commit
ee83891f34
|
@ -27,10 +27,6 @@ Config::Config() {
|
||||||
pinMode(voltagePinOnePointEight, OUTPUT);
|
pinMode(voltagePinOnePointEight, OUTPUT);
|
||||||
pinMode(voltagePinThreePointThree, OUTPUT);
|
pinMode(voltagePinThreePointThree, OUTPUT);
|
||||||
pinMode(voltagePinFivePointZero, OUTPUT);
|
pinMode(voltagePinFivePointZero, OUTPUT);
|
||||||
|
|
||||||
#if DEBUG == 2
|
|
||||||
serialPort0.begin(115200);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Config::isUIEnabled() {
|
bool Config::isUIEnabled() {
|
||||||
|
|
|
@ -9,11 +9,12 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <SerialPort.h>
|
#include <SerialPort.h>
|
||||||
|
#include <SdFat.h>
|
||||||
|
|
||||||
#ifndef Project_h
|
#ifndef Project_h
|
||||||
#define Project_h
|
#define Project_h
|
||||||
|
|
||||||
#define DEBUG 1 // NONE = 0; MINIMAL = 1; FULL = 2;
|
#define DEBUG 2 // NONE = 0; MINIMAL = 1; FULL = 2;
|
||||||
|
|
||||||
// Whether or not the Arduino Mega 2560 is used as the base board
|
// Whether or not the Arduino Mega 2560 is used as the base board
|
||||||
#define ARD_MEGA_2560 true
|
#define ARD_MEGA_2560 true
|
||||||
|
@ -42,7 +43,10 @@
|
||||||
#define timerThreePin 2 // Maps to Mega pin 12
|
#define timerThreePin 2 // Maps to Mega pin 12
|
||||||
|
|
||||||
// Splash screen related
|
// Splash screen related
|
||||||
#define splashScreenFileName "splash.bmp"
|
#define splashScreenFileName "SPLASH.BMP"
|
||||||
|
|
||||||
|
// SPI SD Card speed (Set to HALF for breadboards, full for better performance)
|
||||||
|
#define SPI_PROJECT_SPEED SPI_HALF_SPEED
|
||||||
|
|
||||||
// Colors / theme of UI
|
// Colors / theme of UI
|
||||||
#define SPLASH_BACKGROUND ST7735_WHITE
|
#define SPLASH_BACKGROUND ST7735_WHITE
|
||||||
|
@ -53,6 +57,8 @@
|
||||||
// Don't change anything below here
|
// Don't change anything below here
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
extern SdFat sd;
|
||||||
|
|
||||||
#define FONT_WIDTH 6
|
#define FONT_WIDTH 6
|
||||||
#define FONT_HEIGHT 8
|
#define FONT_HEIGHT 8
|
||||||
|
|
||||||
|
|
|
@ -480,6 +480,7 @@ void UILCD::bmpDraw(char *filename, uint8_t x, uint8_t y) {
|
||||||
serialPort0.println("UILCD::bmpDraw()");
|
serialPort0.println("UILCD::bmpDraw()");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
SdFat sd;
|
||||||
SdFile bmpFile;
|
SdFile bmpFile;
|
||||||
int bmpWidth, bmpHeight; // W+H in pixels
|
int bmpWidth, bmpHeight; // W+H in pixels
|
||||||
uint8_t bmpDepth; // Bit depth (currently must be 24)
|
uint8_t bmpDepth; // Bit depth (currently must be 24)
|
||||||
|
@ -497,7 +498,14 @@ void UILCD::bmpDraw(char *filename, uint8_t x, uint8_t y) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG == 1
|
serialPort0.println("Starting SD card");
|
||||||
|
// Start the SD Card -- FIXME: This should likely get moved to config
|
||||||
|
if (!sd.begin(SD_CS, SPI_PROJECT_SPEED )) {
|
||||||
|
serialPort0.println("SD.begin(SD_CS, SPI_HALF_SPEED ) -- failed!");
|
||||||
|
sd.initErrorHalt();
|
||||||
|
}
|
||||||
|
|
||||||
|
#if DEBUG >= 1
|
||||||
serialPort0.println();
|
serialPort0.println();
|
||||||
serialPort0.print("Loading image '");
|
serialPort0.print("Loading image '");
|
||||||
serialPort0.print(filename);
|
serialPort0.print(filename);
|
||||||
|
@ -505,47 +513,47 @@ void UILCD::bmpDraw(char *filename, uint8_t x, uint8_t y) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Open requested file on SD card
|
// Open requested file on SD card
|
||||||
if (!bmpFile.open(filename)) {
|
if (!bmpFile.open(filename, O_READ)) {
|
||||||
serialPort0.print(filename);
|
serialPort0.print(filename);
|
||||||
serialPort0.println(" not found");
|
serialPort0.println(" not found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse BMP header
|
// Parse BMP header
|
||||||
if(read16(bmpFile) == 0x4D42) { // BMP signature
|
if(read16(&bmpFile) == 0x4D42) { // BMP signature
|
||||||
long fileSize = read32(bmpFile);
|
uint32_t fileSize = read32(&bmpFile);
|
||||||
#if DEBUG == 2
|
#if DEBUG == 2
|
||||||
serialPort0.print("File size: ");
|
serialPort0.print("File size: ");
|
||||||
serialPort0.println(fileSize);
|
serialPort0.println(fileSize);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
(void)read32(bmpFile); // Read & ignore creator bytes
|
(void)read32(&bmpFile); // Read & ignore creator bytes
|
||||||
bmpImageoffset = read32(bmpFile); // Start of image data
|
bmpImageoffset = read32(&bmpFile); // Start of image data
|
||||||
|
|
||||||
#if DEBUG == 2
|
#if DEBUG == 2
|
||||||
serialPort0.print("Image Offset: ");
|
serialPort0.print("Image Offset: ");
|
||||||
serialPort0.println(bmpImageoffset, DEC);
|
serialPort0.println(bmpImageoffset, DEC);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
float headerSize = read32(bmpFile);
|
// Read DIB header
|
||||||
|
float headerSize = read32(&bmpFile);
|
||||||
|
|
||||||
#if DEBUG == 2
|
#if DEBUG == 2
|
||||||
// Read DIB header
|
|
||||||
serialPort0.print("Header size: ");
|
serialPort0.print("Header size: ");
|
||||||
serialPort0.println(headerSize);
|
serialPort0.println(headerSize);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bmpWidth = read32(bmpFile);
|
bmpWidth = read32(&bmpFile);
|
||||||
bmpHeight = read32(bmpFile);
|
bmpHeight = read32(&bmpFile);
|
||||||
if(read16(bmpFile) == 1) { // # planes -- must be '1'
|
if(read16(&bmpFile) == 1) { // # planes -- must be '1'
|
||||||
bmpDepth = read16(bmpFile); // bits per pixel
|
bmpDepth = read16(&bmpFile); // bits per pixel
|
||||||
#if DEBUG == 2
|
#if DEBUG >= 1
|
||||||
serialPort0.print("Bit Depth: ");
|
serialPort0.print("Bit Depth: ");
|
||||||
serialPort0.println(bmpDepth);
|
serialPort0.println(bmpDepth);
|
||||||
#endif
|
#endif
|
||||||
if((bmpDepth == 24) && (read32(bmpFile) == 0)) { // 0 = uncompressed
|
if((bmpDepth == 24) && (read32(&bmpFile) == 0)) { // 0 = uncompressed
|
||||||
goodBmp = true; // Supported BMP format -- proceed!
|
goodBmp = true; // Supported BMP format -- proceed!
|
||||||
#if DEBUG == 2
|
#if DEBUG >= 1
|
||||||
serialPort0.print("Image size: ");
|
serialPort0.print("Image size: ");
|
||||||
serialPort0.print(bmpWidth);
|
serialPort0.print(bmpWidth);
|
||||||
serialPort0.print('x');
|
serialPort0.print('x');
|
||||||
|
@ -590,14 +598,14 @@ void UILCD::bmpDraw(char *filename, uint8_t x, uint8_t y) {
|
||||||
pos = bmpImageoffset + row * rowSize;
|
pos = bmpImageoffset + row * rowSize;
|
||||||
}
|
}
|
||||||
if(bmpFile.curPosition() != pos) { // Need seek?
|
if(bmpFile.curPosition() != pos) { // Need seek?
|
||||||
bmpFile.seekCur(pos);
|
bmpFile.seekSet(pos);
|
||||||
buffidx = sizeof(sdbuffer); // Force buffer reload
|
buffidx = sizeof(sdbuffer); // Force buffer reload
|
||||||
}
|
}
|
||||||
|
|
||||||
for (col=0; col<w; col++) { // For each pixel...
|
for (col=0; col<w; col++) { // For each pixel...
|
||||||
// Time to read more pixel data?
|
// Time to read more pixel data?
|
||||||
if (buffidx >= sizeof(sdbuffer)) { // Indeed
|
if (buffidx >= sizeof(sdbuffer)) { // Indeed
|
||||||
bmpFile.read(sdbuffer, sizeof(sdbuffer));
|
bmpFile.read(&sdbuffer, sizeof(sdbuffer));
|
||||||
buffidx = 0; // Set index to beginning
|
buffidx = 0; // Set index to beginning
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -628,24 +636,20 @@ void UILCD::bmpDraw(char *filename, uint8_t x, uint8_t y) {
|
||||||
// BMP data is stored little-endian, Arduino is little-endian too.
|
// BMP data is stored little-endian, Arduino is little-endian too.
|
||||||
// May need to reverse subscript order if porting elsewhere.
|
// May need to reverse subscript order if porting elsewhere.
|
||||||
|
|
||||||
uint16_t UILCD::read16(SdFile f) {
|
uint16_t UILCD::read16(SdFile* f) {
|
||||||
#if DEBUG == 2
|
//#if DEBUG == 2
|
||||||
serialPort0.println("UILCD::read16()");
|
// serialPort0.println("UILCD::read16()");
|
||||||
#endif
|
//#endif
|
||||||
uint16_t result;
|
uint16_t result;
|
||||||
((uint8_t *)&result)[0] = f.read(); // LSB
|
int numBytesRead = f->read(&result, sizeof(result));
|
||||||
((uint8_t *)&result)[1] = f.read(); // MSB
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t UILCD::read32(SdFile f) {
|
uint32_t UILCD::read32(SdFile* f) {
|
||||||
#if DEBUG == 2
|
//#if DEBUG == 2
|
||||||
serialPort0.println("UILCD::read32()");
|
// serialPort0.println("UILCD::read32()");
|
||||||
#endif
|
//#endif
|
||||||
uint32_t result;
|
uint32_t result;
|
||||||
((uint8_t *)&result)[0] = f.read(); // LSB
|
int numBytesRead = f->read(&result, sizeof(result));
|
||||||
((uint8_t *)&result)[1] = f.read();
|
|
||||||
((uint8_t *)&result)[2] = f.read();
|
|
||||||
((uint8_t *)&result)[3] = f.read(); // MSB
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,8 +44,8 @@ private:
|
||||||
int currentLine;
|
int currentLine;
|
||||||
screen currentScreen;
|
screen currentScreen;
|
||||||
|
|
||||||
uint32_t read32(SdFile f);
|
uint32_t read32(SdFile* f);
|
||||||
uint16_t read16(SdFile f);
|
uint16_t read16(SdFile* f);
|
||||||
|
|
||||||
void drawSplashScreen();
|
void drawSplashScreen();
|
||||||
void drawMainScreen();
|
void drawMainScreen();
|
||||||
|
|
|
@ -31,8 +31,7 @@
|
||||||
UI* ui;
|
UI* ui;
|
||||||
Config* config;
|
Config* config;
|
||||||
RTC_DS1307 rtc;
|
RTC_DS1307 rtc;
|
||||||
SdFat sd;
|
//SdFile dataFile;
|
||||||
SdFile dataFile;
|
|
||||||
#if ARD_MEGA_2560
|
#if ARD_MEGA_2560
|
||||||
SerialPort<0, 512, 512> serialPort0;
|
SerialPort<0, 512, 512> serialPort0;
|
||||||
SerialPort<1, 512, 512> serialPort1;
|
SerialPort<1, 512, 512> serialPort1;
|
||||||
|
@ -74,13 +73,8 @@ void setup() {
|
||||||
config->setDefaults();
|
config->setDefaults();
|
||||||
ui = new UI();
|
ui = new UI();
|
||||||
|
|
||||||
// Start the SD Card -- FIXME: This should likely get moved to config
|
|
||||||
if (!sd.begin(SD_CS)) {
|
|
||||||
serialPort0.println("SD.begin(SD_CS) -- failed!");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Open data log file -- FIXME: This needs to be controlled via config some
|
// Open data log file -- FIXME: This needs to be controlled via config some
|
||||||
dataFile.open("datalog.txt", O_WRITE | O_CREAT | O_AT_END);
|
//dataFile.open("datalog.txt", O_WRITE | O_CREAT | O_AT_END);
|
||||||
|
|
||||||
// Setup serial IO on an interrupt timer
|
// Setup serial IO on an interrupt timer
|
||||||
// ***THIS MUST BE DONE AFTER new Config()***
|
// ***THIS MUST BE DONE AFTER new Config()***
|
||||||
|
|
Reference in a new issue