|
|
@ -1,7 +1,16 @@
|
|
|
|
#include "SPI.h"
|
|
|
|
#include "SPI.h"
|
|
|
|
#include "Adafruit_GFX.h"
|
|
|
|
#include "Adafruit_GFX.h"
|
|
|
|
#include "Adafruit_TFTLCD.h"
|
|
|
|
//#include "Adafruit_TFTLCD.h"
|
|
|
|
//#include "Adafruit_ImageReader.h"
|
|
|
|
#include "SPI.h"
|
|
|
|
|
|
|
|
#include "Adafruit_GFX.h"
|
|
|
|
|
|
|
|
#include "Adafruit_ILI9341.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);
|
|
|
|
#include <TouchScreen.h>
|
|
|
|
#include <TouchScreen.h>
|
|
|
|
#include <avr/power.h>
|
|
|
|
#include <avr/power.h>
|
|
|
|
#include <avr/sleep.h>
|
|
|
|
#include <avr/sleep.h>
|
|
|
@ -67,10 +76,10 @@ word pin50 = 50;
|
|
|
|
word pin51 = 51;
|
|
|
|
word pin51 = 51;
|
|
|
|
word pin52 = 52;
|
|
|
|
word pin52 = 52;
|
|
|
|
word pin53 = 53;
|
|
|
|
word pin53 = 53;
|
|
|
|
word LCD_RD = A0;
|
|
|
|
//word LCD_RD = A0;
|
|
|
|
word LCD_WR = A1;
|
|
|
|
//word LCD_WR = A1;
|
|
|
|
word LCD_CD = A2;
|
|
|
|
//word LCD_CD = A2;
|
|
|
|
word LCD_CS = A3;
|
|
|
|
//word LCD_CS = A3;
|
|
|
|
word pinA4 = A4;
|
|
|
|
word pinA4 = A4;
|
|
|
|
word pinA5 = A5;
|
|
|
|
word pinA5 = A5;
|
|
|
|
word pinA6 = A6;
|
|
|
|
word pinA6 = A6;
|
|
|
@ -94,7 +103,7 @@ word pinA15 = A15;
|
|
|
|
#define YELLOW 0xFFE0
|
|
|
|
#define YELLOW 0xFFE0
|
|
|
|
#define WHITE 0xFFFF
|
|
|
|
#define WHITE 0xFFFF
|
|
|
|
|
|
|
|
|
|
|
|
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, A0);
|
|
|
|
//Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, A0);
|
|
|
|
|
|
|
|
|
|
|
|
#define YP A4
|
|
|
|
#define YP A4
|
|
|
|
#define XM A5
|
|
|
|
#define XM A5
|
|
|
@ -102,9 +111,9 @@ Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, A0);
|
|
|
|
#define XP 31
|
|
|
|
#define XP 31
|
|
|
|
|
|
|
|
|
|
|
|
#define TS_MINX 100
|
|
|
|
#define TS_MINX 100
|
|
|
|
#define TS_MINY 82
|
|
|
|
#define TS_MINY 150
|
|
|
|
#define TS_MAXX 812
|
|
|
|
#define TS_MAXX 900
|
|
|
|
#define TS_MAXY 890
|
|
|
|
#define TS_MAXY 900
|
|
|
|
|
|
|
|
|
|
|
|
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 333);
|
|
|
|
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 333);
|
|
|
|
|
|
|
|
|
|
|
@ -116,6 +125,7 @@ boolean debug = true;
|
|
|
|
|
|
|
|
|
|
|
|
//Adafruit_Image img;
|
|
|
|
//Adafruit_Image img;
|
|
|
|
// Plant logo
|
|
|
|
// Plant logo
|
|
|
|
|
|
|
|
|
|
|
|
static unsigned const char images_bits[] PROGMEM = {
|
|
|
|
static unsigned const char images_bits[] PROGMEM = {
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
@ -831,16 +841,18 @@ boolean s1, s2, s3, s4;
|
|
|
|
|
|
|
|
|
|
|
|
void setup(void) {
|
|
|
|
void setup(void) {
|
|
|
|
Serial.begin(9600);
|
|
|
|
Serial.begin(9600);
|
|
|
|
tft.reset();
|
|
|
|
//tft.reset();
|
|
|
|
tft.begin(0x9341);
|
|
|
|
tft.begin();
|
|
|
|
tft.setRotation(1);
|
|
|
|
tft.setRotation(1);
|
|
|
|
if(!fastboot) {
|
|
|
|
if(!fastboot) {
|
|
|
|
tft.fillScreen(WHITE);
|
|
|
|
tft.fillScreen(ILI9341_WHITE);
|
|
|
|
tft.drawXBitmap(0, 14, images_bits, 320, 212, GREEN); // loading
|
|
|
|
yield();
|
|
|
|
|
|
|
|
tft.drawXBitmap(0, 14, images_bits, 320, 212, ILI9341_GREEN); // loading
|
|
|
|
delay(4000);
|
|
|
|
delay(4000);
|
|
|
|
tft.fillScreen(WHITE);
|
|
|
|
tft.fillScreen(ILI9341_WHITE);
|
|
|
|
|
|
|
|
yield();
|
|
|
|
delay(1000);
|
|
|
|
delay(1000);
|
|
|
|
//tft.fillRect(0, 0, 320, 23, BLACK);
|
|
|
|
//tft.fillRect(0, 0, 320, 23, ILI9341_BLACK);
|
|
|
|
printConsoleText("Booting GreenhouseOS...||");
|
|
|
|
printConsoleText("Booting GreenhouseOS...||");
|
|
|
|
delay(250);
|
|
|
|
delay(250);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -894,21 +906,57 @@ void loop(void) {
|
|
|
|
String txtin = "Serial: " + Serial.readString();
|
|
|
|
String txtin = "Serial: " + Serial.readString();
|
|
|
|
printConsoleText(txtin.substring(0, txtin.length() - 1));
|
|
|
|
printConsoleText(txtin.substring(0, txtin.length() - 1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long mil = millis();
|
|
|
|
getMoisture();
|
|
|
|
String tmp = "[";
|
|
|
|
|
|
|
|
if(mil / 1000 < 10) {
|
|
|
|
|
|
|
|
tmp += " ";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if(mil / 1000 < 100) {
|
|
|
|
|
|
|
|
tmp += " ";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if(mil / 1000 < 1000) {
|
|
|
|
|
|
|
|
tmp += " ";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if(mil / 1000 < 10000) {
|
|
|
|
|
|
|
|
tmp += " ";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if(mil / 1000 < 100000) {
|
|
|
|
|
|
|
|
tmp += " ";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if(mil / 1000 < 1000000) {
|
|
|
|
|
|
|
|
tmp += " ";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp += mil / 1000;
|
|
|
|
|
|
|
|
tmp += ".";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(mil % 1000 < 10) {
|
|
|
|
|
|
|
|
tmp += "00";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if(mil % 1000 < 100) {
|
|
|
|
|
|
|
|
tmp += "0";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp += mil % 1000;
|
|
|
|
|
|
|
|
tmp += "]";
|
|
|
|
|
|
|
|
//printConsoleText(tmp);
|
|
|
|
|
|
|
|
//if(mil % 60000 < 3000) {
|
|
|
|
|
|
|
|
getMoisture();
|
|
|
|
|
|
|
|
//delay(500);
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
// change upd to true if screen update needed
|
|
|
|
// change upd to true if screen update needed
|
|
|
|
if(!debug && upd) {
|
|
|
|
if(!debug && upd) {
|
|
|
|
tft.fillScreen(BLACK);
|
|
|
|
tft.fillScreen(ILI9341_BLACK);
|
|
|
|
tft.fillRect(0, 0, 320, 20, WHITE);
|
|
|
|
yield();
|
|
|
|
|
|
|
|
tft.fillRect(0, 0, 320, 20, ILI9341_WHITE);
|
|
|
|
tft.setCursor(2, 2);
|
|
|
|
tft.setCursor(2, 2);
|
|
|
|
tft.setTextSize(2);
|
|
|
|
tft.setTextSize(2);
|
|
|
|
tft.setTextColor(BLACK);
|
|
|
|
tft.setTextColor(ILI9341_BLACK);
|
|
|
|
tft.print("Water Level: ");
|
|
|
|
tft.print("Water Level: ");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
upd = false;
|
|
|
|
upd = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ISR (WDT_vect)
|
|
|
|
ISR (WDT_vect)
|
|
|
@ -1064,7 +1112,7 @@ void enablePS(int level) {
|
|
|
|
if(level > 1) {
|
|
|
|
if(level > 1) {
|
|
|
|
Serial.end();
|
|
|
|
Serial.end();
|
|
|
|
power_adc_disable();
|
|
|
|
power_adc_disable();
|
|
|
|
power_spi_disable();
|
|
|
|
//power_spi_disable();
|
|
|
|
power_usart0_disable();
|
|
|
|
power_usart0_disable();
|
|
|
|
power_usart1_disable();
|
|
|
|
power_usart1_disable();
|
|
|
|
power_usart2_disable();
|
|
|
|
power_usart2_disable();
|
|
|
@ -1092,7 +1140,8 @@ void clearLog() {
|
|
|
|
|
|
|
|
|
|
|
|
void printConsoleText(String text) {
|
|
|
|
void printConsoleText(String text) {
|
|
|
|
if (outtext.equals("") && debug) {
|
|
|
|
if (outtext.equals("") && debug) {
|
|
|
|
tft.fillScreen(BLACK);
|
|
|
|
tft.fillScreen(ILI9341_BLACK);
|
|
|
|
|
|
|
|
yield();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
oldtext = outtext;
|
|
|
|
oldtext = outtext;
|
|
|
|
if (text.length() <= 53) {
|
|
|
|
if (text.length() <= 53) {
|
|
|
@ -1125,7 +1174,7 @@ void printConsoleText(String text) {
|
|
|
|
//tft.setCursor(0, 0);
|
|
|
|
//tft.setCursor(0, 0);
|
|
|
|
//tft.fillScreen(BLACK);
|
|
|
|
//tft.fillScreen(BLACK);
|
|
|
|
tft.setCursor(0, (count) * 8);
|
|
|
|
tft.setCursor(0, (count) * 8);
|
|
|
|
tft.setTextColor(WHITE);
|
|
|
|
tft.setTextColor(ILI9341_WHITE);
|
|
|
|
tft.setTextSize(1);
|
|
|
|
tft.setTextSize(1);
|
|
|
|
for(int x = count - 1; x >= 0; x--) {
|
|
|
|
for(int x = count - 1; x >= 0; x--) {
|
|
|
|
String tmp = getString(outtext, x);
|
|
|
|
String tmp = getString(outtext, x);
|
|
|
|