Switch to TFT_ILI9341 for waaaaaaaaaay faster text rendering, deprecate old consoletext
This commit is contained in:
parent
6340186e15
commit
02c6d58080
162
Greenhouse.ino
162
Greenhouse.ino
@ -1,13 +1,26 @@
|
||||
#include <TFT_FastPin.h>
|
||||
#include <TFT_ILI9341.h>
|
||||
#include <User_Setup.h>
|
||||
|
||||
#include "SPI.h"
|
||||
#include "Adafruit_GFX.h"
|
||||
#include "Adafruit_ILI9341.h"
|
||||
//#include "./PDQ_ILI9341_config.h"
|
||||
//#include "PDQ_GFX.h"
|
||||
//#include "PDQ_ILI9341.h"
|
||||
#include "SD.h"
|
||||
#include <Fonts/FreeSerif12pt7b.h> // include fancy serif font
|
||||
#include <Fonts/FreeSans12pt7b.h>
|
||||
// For the Adafruit shield, these are the default.
|
||||
#define TFT_DC 48
|
||||
#define TFT_CS 49
|
||||
|
||||
// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
|
||||
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
|
||||
TFT_ILI9341 tft;
|
||||
extern "C" char __data_start[]; // start of SRAM data
|
||||
extern "C" char _end[]; // end of SRAM data (used to check amount of SRAM this program's variables use)
|
||||
extern "C" char __data_load_end[]; // end of FLASH (used to check amount of Flash this program's code and data uses)
|
||||
|
||||
|
||||
#include <TouchScreen.h>
|
||||
#include <avr/power.h>
|
||||
#include <avr/sleep.h>
|
||||
@ -127,25 +140,35 @@ int linecount = 0;
|
||||
void setup(void) {
|
||||
Serial.begin(9600);
|
||||
//tft.reset();
|
||||
#if defined(ILI9341_RST_PIN) // reset like Adafruit does
|
||||
FastPin<ILI9341_RST_PIN>::setOutput();
|
||||
FastPin<ILI9341_RST_PIN>::hi();
|
||||
FastPin<ILI9341_RST_PIN>::lo();
|
||||
delay(1);
|
||||
FastPin<ILI9341_RST_PIN>::hi();
|
||||
#endif
|
||||
tft.begin();
|
||||
yield();
|
||||
//tft.reset();
|
||||
tft.setRotation(1);
|
||||
boolean didDraw = true;
|
||||
|
||||
if(!fastboot) {
|
||||
if (SD.begin(SD_CS)) {
|
||||
tft.fillScreen(ILI9341_WHITE);
|
||||
bmpDraw("gbs.bmp", 0, 0);
|
||||
delay(4000);
|
||||
} else {
|
||||
//if (SD.begin(SD_CS)) {
|
||||
//tft.fillScreen(ILI9341_WHITE);
|
||||
//bmpDraw("gbs.bmp", 0, 0);
|
||||
//delay(4000);
|
||||
//} else {
|
||||
didDraw = false;
|
||||
}
|
||||
// }
|
||||
tft.fillScreen(ILI9341_WHITE);
|
||||
yield();
|
||||
//yield();
|
||||
//tft.fillRect(0, 0, 320, 23, ILI9341_BLACK);
|
||||
|
||||
}
|
||||
printFastCText("Booting GreenhouseOS...||");
|
||||
clearLog();
|
||||
printFastCText("Booting GreenhouseOS...");
|
||||
printFastCText("");
|
||||
printFastCText("");
|
||||
delay(250);
|
||||
if(!didDraw) {
|
||||
printFastCText("[FAILED] SD Card not detected!");
|
||||
@ -201,7 +224,7 @@ void loop(void) {
|
||||
String txtin = "Serial: " + Serial.readString();
|
||||
int x = 0;
|
||||
while(txtin.length() > 53) {
|
||||
printFastCText(txtin.substring(0, 53);
|
||||
printFastCText(txtin.substring(0, 53));
|
||||
txtin = txtin.substring(53);
|
||||
}
|
||||
printFastCText(txtin.substring(0, txtin.length() - 1));
|
||||
@ -239,9 +262,12 @@ void loop(void) {
|
||||
tmp += mil % 1000;
|
||||
tmp += "]";*/
|
||||
//printConsoleText(tmp);
|
||||
//tft.scrollTo(320);
|
||||
if(mil % 60000 < 3000) {
|
||||
getMoisture();
|
||||
delay(500);
|
||||
//tft.scrollTo(480);
|
||||
//tft.setAddrWindow(320, 0, 320, 240);
|
||||
}
|
||||
|
||||
// change upd to true if screen update needed
|
||||
@ -261,7 +287,7 @@ void loop(void) {
|
||||
}
|
||||
|
||||
#define BUFFPIXEL 80
|
||||
|
||||
/*
|
||||
void bmpDraw(char *filename, int16_t x, int16_t y) {
|
||||
|
||||
File bmpFile;
|
||||
@ -391,7 +417,7 @@ void bmpDraw(char *filename, int16_t x, int16_t y) {
|
||||
bmpFile.close();
|
||||
if(!goodBmp) Serial.println(F("BMP format not recognized."));
|
||||
}
|
||||
|
||||
*/
|
||||
uint16_t read16(File &f) {
|
||||
uint16_t result;
|
||||
((uint8_t *)&result)[0] = f.read(); // LSB
|
||||
@ -555,8 +581,10 @@ void printS4(float t, int sm) {
|
||||
void enablePS(int level) {
|
||||
if (level > 0) {
|
||||
for(int x = 0; x <= 19; x++) {
|
||||
pinMode(x, OUTPUT);
|
||||
digitalWrite(x, LOW);
|
||||
if(x != 8) {
|
||||
pinMode(x, OUTPUT);
|
||||
digitalWrite(x, LOW);
|
||||
}
|
||||
}
|
||||
for(int x = 32; x <= 53; x++) {
|
||||
pinMode(x, OUTPUT);
|
||||
@ -596,86 +624,14 @@ void clearLog() {
|
||||
outtext = "";
|
||||
outtext2 = "";
|
||||
linecount = 0;
|
||||
}
|
||||
|
||||
void printConsoleText(String text) {
|
||||
if (outtext.equals("") && debug) {
|
||||
tft.fillScreen(ILI9341_BLACK);
|
||||
yield();
|
||||
}
|
||||
oldtext = outtext;
|
||||
if (text.length() <= 53) {
|
||||
outtext += text + "|";
|
||||
} else {
|
||||
int l = text.length() - text.length() % 53;
|
||||
for (int x = 0; x < l; x += 53) {
|
||||
boolean keep = true;
|
||||
for (int y = 0; y < 53; y++) {
|
||||
if (text.substring(x + y, x + y + 1).equals("|")) {
|
||||
keep = false;
|
||||
}
|
||||
}
|
||||
if (keep) {
|
||||
outtext += text.substring(x, x + 53) + "|";
|
||||
} else {
|
||||
outtext += text.substring(x, x + 53);
|
||||
}
|
||||
}
|
||||
if (text.length() % 53 != 0) {
|
||||
outtext += text.substring(text.length() - text.length() % 53, text.length()) + "|";
|
||||
}
|
||||
}
|
||||
int count = countSemicolons(outtext);
|
||||
while (count > 30) {
|
||||
outtext.remove(0, outtext.indexOf("|") + 1);
|
||||
count--;
|
||||
}
|
||||
if (debug) {
|
||||
//tft.setCursor(0, 0);
|
||||
//tft.fillScreen(BLACK);
|
||||
tft.setCursor(0, (count) * 8);
|
||||
tft.setTextColor(ILI9341_WHITE);
|
||||
tft.setTextSize(1);
|
||||
for (int x = count - 1; x >= 0; x--) {
|
||||
String tmp = getString(outtext, x);
|
||||
tft.setCursor(0, tft.getCursorY() - 8);
|
||||
if (!tmp.equals(getString(oldtext, x))) {
|
||||
tft.fillRect(0, tft.getCursorY(), 320, 8, BLACK);
|
||||
tft.print(tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
int countSemicolons(String s) {
|
||||
int newlines = 0;
|
||||
int l = s.length();
|
||||
for (int x = 0; x < l; x++) {
|
||||
if (s.substring(x, x + 1).equals("|")) {
|
||||
newlines ++;
|
||||
}
|
||||
}
|
||||
return newlines;
|
||||
}
|
||||
String getString(String s, int index) {
|
||||
int count = 0;
|
||||
int lastsemi = 0;
|
||||
for (int x = 0; x < s.length(); x++) {
|
||||
if (s.substring(x, x + 1).equals("|")) {
|
||||
count ++;
|
||||
if (count - 1 == index) {
|
||||
return s.substring(lastsemi, x);
|
||||
}
|
||||
lastsemi = x + 1;
|
||||
}
|
||||
|
||||
}
|
||||
return "";
|
||||
tft.fillScreen(ILI9341_BLACK);
|
||||
}
|
||||
|
||||
void printFastCText(String text) { // NOTE: text MUST be under 53 characters long! (this is how the code runs faster)
|
||||
linecount ++;
|
||||
if (linecount > 30) {
|
||||
outtext2 = outtext2.substring(30);
|
||||
outtext2 = outtext2.substring(53);
|
||||
//scrollAddress(8);
|
||||
}
|
||||
if (text.length() < 53) {
|
||||
outtext2 += text;
|
||||
@ -688,15 +644,21 @@ void printFastCText(String text) { // NOTE: text MUST be under 53 characters lon
|
||||
if (debug) {
|
||||
//tft.setCursor(0, 0);
|
||||
//tft.fillScreen(BLACK);
|
||||
int lc2 = linecount;
|
||||
tft.setCursor(0, lc2 * 8);
|
||||
tft.setTextColor(ILI9341_WHITE);
|
||||
tft.setCursor(0, 0);
|
||||
tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK);
|
||||
tft.setTextSize(1);
|
||||
for (int x = count - 1; x >= 0; x--) {
|
||||
String tmp = outtext2.substring(x * 53, x*53 + 53);
|
||||
tft.setCursor(0, tft.getCursorY() - 8);
|
||||
tft.fillRect(0, tft.getCursorY(), 320, 8, BLACK);
|
||||
tft.print(tmp);
|
||||
}
|
||||
//int cursory = linecount * 8;
|
||||
//for (int x = linecount - 1; x >= 0; x--) {
|
||||
//tft.setCursor(0, cursory - 8);
|
||||
//tft.fillRect(0, cursory - 8, 320, 8, BLACK);
|
||||
//tft.fillScreen(ILI9341_BLACK);
|
||||
tft.print(outtext2);
|
||||
//cursory -= 8;
|
||||
//}
|
||||
}
|
||||
}
|
||||
void scrollAddress(uint16_t vsp) {
|
||||
tft.writecommand(ILI9341_VSCRSADD); // Vertical scrolling pointer
|
||||
tft.writedata(vsp>>8);
|
||||
tft.writedata(vsp);
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
33
PDQ_ILI9341_config.h
Normal file
33
PDQ_ILI9341_config.h
Normal file
@ -0,0 +1,33 @@
|
||||
//
|
||||
// PDQ_ILI9341 configuration
|
||||
//
|
||||
// You need to include this file above #include "PDQ_ILI9341.h" in your sketch.
|
||||
// Check settings on lines marked with "<=".
|
||||
|
||||
// NOTE: These are typical hookups individual boards will vary, please check your documentation.
|
||||
// CAUTION: While Adafruit boards generally always come with needed level-converters, I find many
|
||||
// other LCD displays advertised as supporting 5V only support 5V power (with a regulator).
|
||||
// They still only have 3.3V safe logic (CS, DC, RESET, MOSI, SCK marked with * below).
|
||||
// If this is the case you will need a voltage level-converter (e.g., HC4050, divider circuit etc.).
|
||||
//
|
||||
// LCD PIN Uno (328) Leo (32u4) 644/1284
|
||||
// ------- --------- ---------- --------
|
||||
// 1 VCC 3.3V/5V 3.3V/5V 3.3V/5V // +3.3V or 5V with on-board regulator
|
||||
// 2 GND GND GND GND
|
||||
// 3* CS 10 10 4 // Could be any GPIO pin, but then need to make sure SS isn't a LOW input (or slave SPI mode)
|
||||
// 4* RESET 0/8/RESET 0/8/RESET 0/RESET // This relies on soft-reset. You can also use Arduino reset pin (if correct voltage).
|
||||
// 5* DC/RS 9 9 3 // Could be any GPIO pin
|
||||
// 6* SDI/MOSI 11 ICSP4 5 // HW SPI pin (can't change)
|
||||
// 7* SCK 13 ICSP3 7 // HW SPI pin (can't change) NOTE: On Uno this causes on-board LED to flicker during SPI use
|
||||
// 8* LED 3.3V/5V 3.3V/5V 3.3V/5V // LCD screen blanked when LOW (could use GPIO for PWM dimming)
|
||||
// 9 SDO/MISO - - - // (not used if present, LCD code is currently "write only")
|
||||
//
|
||||
// * = Typically only 3.3V safe logic-line (unless board has level converter [ala Adafruit]). Be careful with 5V!
|
||||
|
||||
#define ILI9341_CS_PIN 49 // <= /CS pin (chip-select, LOW to get attention of ILI9341, HIGH and it ignores SPI bus)
|
||||
#define ILI9341_DC_PIN 48 // <= DC pin (1=data or 0=command indicator line) also called RS
|
||||
#define ILI9341_RST_PIN 8 // <= RST pin (optional)
|
||||
// (other pins used are dictated by AVR HW SPI used as shown above)
|
||||
|
||||
// other PDQ library options
|
||||
#define ILI9341_SAVE_SPCR 1 // <= 0/1 with 1 to save/restore AVR SPI control register (to "play nice" when other SPI use)
|
84
User_Setup.h
Normal file
84
User_Setup.h
Normal file
@ -0,0 +1,84 @@
|
||||
// USER DEFINED SETTINGS V16
|
||||
// Set fonts to be loaded, pins used and SPI control method
|
||||
|
||||
|
||||
// ##################################################################################
|
||||
//
|
||||
// Define the fonts that are to be used here
|
||||
//
|
||||
// ##################################################################################
|
||||
|
||||
// Comment out the #defines below with // to stop that font being loaded
|
||||
// As supplied font 8 is disabled by commenting out
|
||||
//
|
||||
// If all fonts are loaded the extra FLASH space required is about 17000 bytes...
|
||||
// To save FLASH space only enable the fonts you need!
|
||||
|
||||
#define LOAD_GLCD // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH
|
||||
#define LOAD_FONT2 // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters
|
||||
#define LOAD_FONT4 // Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters
|
||||
#define LOAD_FONT6 // Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm
|
||||
#define LOAD_FONT7 // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:.
|
||||
//#define LOAD_FONT8 // Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-.
|
||||
|
||||
|
||||
// ##################################################################################
|
||||
//
|
||||
// Define the pins that are used to interface with the display here
|
||||
//
|
||||
// ##################################################################################
|
||||
|
||||
// We must use hardware SPI
|
||||
// FYI Mega SCK is pin 52, MOSI is 51, UNO/NanoPro micro etc SCK is pin 13 and MOSI is 11
|
||||
// Leonardo Pro micro SCK is pin 15 and MOSI is 16
|
||||
|
||||
// These are the control pins I use on my Mega setup
|
||||
// TFT_CS 47 // Chip select control pin
|
||||
// TFT_DC 48 // Data Command control pin
|
||||
// TFT_RST 44 // Reset pin (could connect to Arduino RESET pin)
|
||||
|
||||
// These are the control pins I use on my UNO/Nano/Pro Micro/ATmega328 setup
|
||||
// TFT_CS 10 // Chip select control pin
|
||||
// TFT_DC 9 // Data Command control pin
|
||||
// TFT_RST 7 // Reset pin (could connect to Arduino RESET pin)
|
||||
|
||||
// ###### EDIT THE PIN NUMBERS IN THE 3 LINES FOLLOWING TO SUIT YOUR SETUP ######
|
||||
|
||||
#define TFT_CS 49 // Chip select control pin
|
||||
#define TFT_DC 48 // Data Command control pin
|
||||
#define TFT_RST 8 // Reset pin (could connect to Arduino RESET pin)
|
||||
|
||||
|
||||
// ##################################################################################
|
||||
//
|
||||
// Other speed up options
|
||||
//
|
||||
// ##################################################################################
|
||||
|
||||
// If your sketch uses the GLCD font in size 1 with background then uncomment
|
||||
// this next line will speed up rendering x5, code size will increase 136 bytes
|
||||
// Only worth it if you print lots of GLCD font text...
|
||||
|
||||
#define FAST_GLCD
|
||||
|
||||
// Uncomment the following #define to invoke a 20% faster drawLine() function
|
||||
// This speeds up other funtions such as triangle outline drawing too
|
||||
// Code size penalty is about 72 bytes
|
||||
|
||||
#define FAST_LINE
|
||||
|
||||
// Comment out the following #define to stop boundary checking and clipping
|
||||
// for fillRectangle()and fastH/V lines. This speeds up other funtions such as text
|
||||
// rendering where size>1. Sketch then must not draw graphics/text outside screen
|
||||
// boundary. Code saving for no bounds check (i.e. commented out) is 316 bytes
|
||||
|
||||
//#define CLIP_CHECK
|
||||
|
||||
// Comment out the following #define if "SPI Transactions" do not need to be
|
||||
// supported. Tranaction support is required if other SPI devices use interrupts.
|
||||
// When commented out the code size will be ~700 bytes smaller and sketches will
|
||||
// run slightly faster, so leave it commented out unless you need it!
|
||||
// Transaction support is needed to work with SD libraru but not needed with TFT_SdFat
|
||||
|
||||
// #define SUPPORT_TRANSACTIONS
|
||||
|
Loading…
x
Reference in New Issue
Block a user