|
|
|
@ -121,6 +121,8 @@ boolean debug = true;
|
|
|
|
|
boolean ps3 = false;
|
|
|
|
|
boolean upd;
|
|
|
|
|
boolean s1, s2, s3, s4;
|
|
|
|
|
String outtext2 = "";
|
|
|
|
|
int linecount = 0;
|
|
|
|
|
|
|
|
|
|
void setup(void) {
|
|
|
|
|
Serial.begin(9600);
|
|
|
|
@ -143,49 +145,49 @@ void setup(void) {
|
|
|
|
|
//tft.fillRect(0, 0, 320, 23, ILI9341_BLACK);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
printConsoleText("Booting GreenhouseOS...||");
|
|
|
|
|
printFastCText("Booting GreenhouseOS...||");
|
|
|
|
|
delay(250);
|
|
|
|
|
if(!didDraw) {
|
|
|
|
|
printConsoleText("[FAILED] SD Card not detected!");
|
|
|
|
|
printFastCText("[FAILED] SD Card not detected!");
|
|
|
|
|
}
|
|
|
|
|
printConsoleText("[ OK ] Enabling powersaving features... "); // 53 characters wide
|
|
|
|
|
printFastCText("[ OK ] Enabling powersaving features... "); // 53 characters wide example
|
|
|
|
|
enablePS(3);
|
|
|
|
|
upd = true;
|
|
|
|
|
|
|
|
|
|
if (!soil1.begin(0x36)) {
|
|
|
|
|
printConsoleText("[ INFO ] Soil sensor 1 unplugged.");
|
|
|
|
|
printFastCText("[ INFO ] Soil sensor 1 unplugged.");
|
|
|
|
|
s1 = false;
|
|
|
|
|
} else {
|
|
|
|
|
String out = "[ OK ] Soil sensor 1 connected. Version: ";
|
|
|
|
|
out += (soil1.getVersion(), HEX);
|
|
|
|
|
printConsoleText(out);
|
|
|
|
|
printFastCText(out);
|
|
|
|
|
s1 = true;
|
|
|
|
|
}
|
|
|
|
|
if (!soil2.begin(0x37)) {
|
|
|
|
|
printConsoleText("[ INFO ] Soil sensor 2 unplugged.");
|
|
|
|
|
printFastCText("[ INFO ] Soil sensor 2 unplugged.");
|
|
|
|
|
s2 = false;
|
|
|
|
|
} else {
|
|
|
|
|
String out = "[ OK ] Soil sensor 2 connected. Version: ";
|
|
|
|
|
out += (soil2.getVersion(), HEX);
|
|
|
|
|
printConsoleText(out);
|
|
|
|
|
printFastCText(out);
|
|
|
|
|
s2 = true;
|
|
|
|
|
}
|
|
|
|
|
if (!soil3.begin(0x38)) {
|
|
|
|
|
printConsoleText("[ INFO ] Soil sensor 3 unplugged.");
|
|
|
|
|
printFastCText("[ INFO ] Soil sensor 3 unplugged.");
|
|
|
|
|
s3 = false;
|
|
|
|
|
} else {
|
|
|
|
|
String out = "[ OK ] Soil sensor 3 connected. Version: ";
|
|
|
|
|
out += (soil3.getVersion(), HEX);
|
|
|
|
|
printConsoleText(out);
|
|
|
|
|
printFastCText(out);
|
|
|
|
|
s3 = true;
|
|
|
|
|
}
|
|
|
|
|
if (!soil4.begin(0x39)) {
|
|
|
|
|
printConsoleText("[ INFO ] Soil sensor 4 unplugged.");
|
|
|
|
|
printFastCText("[ INFO ] Soil sensor 4 unplugged.");
|
|
|
|
|
s4 = false;
|
|
|
|
|
} else {
|
|
|
|
|
String out = "[ OK ] Soil sensor 4 connected. Version: ";
|
|
|
|
|
out += (soil4.getVersion(), HEX);
|
|
|
|
|
printConsoleText(out);
|
|
|
|
|
printFastCText(out);
|
|
|
|
|
s4 = true;
|
|
|
|
|
}
|
|
|
|
|
getMoisture();
|
|
|
|
@ -197,7 +199,13 @@ void loop(void) {
|
|
|
|
|
}
|
|
|
|
|
if(Serial.available() > 0) {
|
|
|
|
|
String txtin = "Serial: " + Serial.readString();
|
|
|
|
|
printConsoleText(txtin.substring(0, txtin.length() - 1));
|
|
|
|
|
int x = 0;
|
|
|
|
|
while(txtin.length() > 53) {
|
|
|
|
|
printFastCText(txtin.substring(0, 53);
|
|
|
|
|
txtin = txtin.substring(53);
|
|
|
|
|
}
|
|
|
|
|
printFastCText(txtin.substring(0, txtin.length() - 1));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
unsigned long mil = millis();
|
|
|
|
|
/*String tmp = "[";
|
|
|
|
@ -411,7 +419,7 @@ void getMoisture() {
|
|
|
|
|
int sm1 = map(soil1.touchRead(0), 0, 1023, 0, 100);
|
|
|
|
|
if(sm1 > 6000 && t1 < 1) {
|
|
|
|
|
s1 = false;
|
|
|
|
|
printConsoleText("[ INFO ] Soil sensor 1 unplugged.");
|
|
|
|
|
printFastCText("[ INFO ] Soil sensor 1 unplugged.");
|
|
|
|
|
} else {
|
|
|
|
|
printS1(t1, sm1);
|
|
|
|
|
}
|
|
|
|
@ -419,7 +427,7 @@ void getMoisture() {
|
|
|
|
|
if (soil1.begin(0x36)) {
|
|
|
|
|
clearLog();
|
|
|
|
|
s1 = true;
|
|
|
|
|
printConsoleText("[ INFO ] Soil sensor 1 connected.");
|
|
|
|
|
printFastCText("[ INFO ] Soil sensor 1 connected.");
|
|
|
|
|
float t1 = soil1.getTemp();
|
|
|
|
|
int sm1 = map(soil1.touchRead(0), 0, 1023, 0, 100);
|
|
|
|
|
printS1(t1, sm1);
|
|
|
|
@ -431,7 +439,7 @@ void getMoisture() {
|
|
|
|
|
int sm2 = map(soil2.touchRead(0), 0, 1023, 0, 100);
|
|
|
|
|
if(sm2 > 6000 && t2 < 1) {
|
|
|
|
|
s2 = false;
|
|
|
|
|
printConsoleText("[ INFO ] Soil sensor 2 unplugged.");
|
|
|
|
|
printFastCText("[ INFO ] Soil sensor 2 unplugged.");
|
|
|
|
|
} else {
|
|
|
|
|
printS2(t2, sm2);
|
|
|
|
|
}
|
|
|
|
@ -439,7 +447,7 @@ void getMoisture() {
|
|
|
|
|
if (soil2.begin(0x37)) {
|
|
|
|
|
clearLog();
|
|
|
|
|
s2 = true;
|
|
|
|
|
printConsoleText("[ INFO ] Soil sensor 2 connected.");
|
|
|
|
|
printFastCText("[ INFO ] Soil sensor 2 connected.");
|
|
|
|
|
float t2 = soil2.getTemp();
|
|
|
|
|
int sm2 = map(soil2.touchRead(0), 0, 1023, 0, 100);
|
|
|
|
|
printS2(t2, sm2);
|
|
|
|
@ -451,7 +459,7 @@ void getMoisture() {
|
|
|
|
|
int sm3 = map(soil3.touchRead(0), 0, 1023, 0, 100);
|
|
|
|
|
if(sm3 > 6000 && t3 < 1) {
|
|
|
|
|
s3 = false;
|
|
|
|
|
printConsoleText("[ INFO ] Soil sensor 3 unplugged.");
|
|
|
|
|
printFastCText("[ INFO ] Soil sensor 3 unplugged.");
|
|
|
|
|
} else {
|
|
|
|
|
printS3(t3, sm3);
|
|
|
|
|
}
|
|
|
|
@ -459,7 +467,7 @@ void getMoisture() {
|
|
|
|
|
if (soil3.begin(0x38)) {
|
|
|
|
|
clearLog();
|
|
|
|
|
s3 = true;
|
|
|
|
|
printConsoleText("[ INFO ] Soil sensor 3 connected.");
|
|
|
|
|
printFastCText("[ INFO ] Soil sensor 3 connected.");
|
|
|
|
|
float t3 = soil3.getTemp();
|
|
|
|
|
int sm3 = map(soil3.touchRead(0), 0, 1023, 0, 100);
|
|
|
|
|
printS3(t3, sm3);
|
|
|
|
@ -471,7 +479,7 @@ void getMoisture() {
|
|
|
|
|
int sm4 = map(soil4.touchRead(0), 0, 1023, 0, 100);
|
|
|
|
|
if(sm4 > 6000 && t4 < 1) {
|
|
|
|
|
s4 = false;
|
|
|
|
|
printConsoleText("[ INFO ] Soil sensor 4 unplugged.");
|
|
|
|
|
printFastCText("[ INFO ] Soil sensor 4 unplugged.");
|
|
|
|
|
} else {
|
|
|
|
|
printS4(t4, sm4);
|
|
|
|
|
}
|
|
|
|
@ -479,7 +487,7 @@ void getMoisture() {
|
|
|
|
|
if (soil4.begin(0x39)) {
|
|
|
|
|
clearLog();
|
|
|
|
|
s4 = true;
|
|
|
|
|
printConsoleText("[ INFO ] Soil sensor 4 connected.");
|
|
|
|
|
printFastCText("[ INFO ] Soil sensor 4 connected.");
|
|
|
|
|
float t4 = soil4.getTemp();
|
|
|
|
|
int sm4 = map(soil4.touchRead(0), 0, 1023, 0, 100);
|
|
|
|
|
printS4(t4, sm4);
|
|
|
|
@ -492,11 +500,13 @@ void printS1(float t, int sm) {
|
|
|
|
|
out += t;
|
|
|
|
|
out += " C, ";
|
|
|
|
|
out += (t * 9.0 / 5.0 + 32);
|
|
|
|
|
out += " F|";
|
|
|
|
|
out += " F";
|
|
|
|
|
printFastCText(out);
|
|
|
|
|
out = "";
|
|
|
|
|
out += "[ OK ] Soil sensor 1 moisture: ";
|
|
|
|
|
out += sm;
|
|
|
|
|
out += "%";
|
|
|
|
|
printConsoleText(out);
|
|
|
|
|
printFastCText(out);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void printS2(float t, int sm) {
|
|
|
|
@ -504,11 +514,13 @@ void printS2(float t, int sm) {
|
|
|
|
|
out += t;
|
|
|
|
|
out += " C, ";
|
|
|
|
|
out += (t * 9.0 / 5.0 + 32);
|
|
|
|
|
out += " F|";
|
|
|
|
|
out += " F";
|
|
|
|
|
printFastCText(out);
|
|
|
|
|
out = "";
|
|
|
|
|
out += "[ OK ] Soil sensor 2 moisture: ";
|
|
|
|
|
out += sm;
|
|
|
|
|
out += "%";
|
|
|
|
|
printConsoleText(out);
|
|
|
|
|
printFastCText(out);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void printS3(float t, int sm) {
|
|
|
|
@ -516,11 +528,13 @@ void printS3(float t, int sm) {
|
|
|
|
|
out += t;
|
|
|
|
|
out += " C, ";
|
|
|
|
|
out += (t * 9.0 / 5.0 + 32);
|
|
|
|
|
out += " F|";
|
|
|
|
|
out += " F";
|
|
|
|
|
printFastCText(out);
|
|
|
|
|
out = "";
|
|
|
|
|
out += "[ OK ] Soil sensor 3 moisture: ";
|
|
|
|
|
out += sm;
|
|
|
|
|
out += "%";
|
|
|
|
|
printConsoleText(out);
|
|
|
|
|
printFastCText(out);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void printS4(float t, int sm) {
|
|
|
|
@ -528,11 +542,13 @@ void printS4(float t, int sm) {
|
|
|
|
|
out += t;
|
|
|
|
|
out += " C, ";
|
|
|
|
|
out += (t * 9.0 / 5.0 + 32);
|
|
|
|
|
out += " F|";
|
|
|
|
|
out += " F";
|
|
|
|
|
printFastCText(out);
|
|
|
|
|
out = "";
|
|
|
|
|
out += "[ OK ] Soil sensor 4 moisture: ";
|
|
|
|
|
out += sm;
|
|
|
|
|
out += "%";
|
|
|
|
|
printConsoleText(out);
|
|
|
|
|
printFastCText(out);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -546,9 +562,9 @@ void enablePS(int level) {
|
|
|
|
|
pinMode(x, OUTPUT);
|
|
|
|
|
digitalWrite(x, LOW);
|
|
|
|
|
}
|
|
|
|
|
printConsoleText("[ OK ] Enabled Level 1 powersaving.");
|
|
|
|
|
printFastCText("[ OK ] Enabled Level 1 powersaving.");
|
|
|
|
|
} else {
|
|
|
|
|
printConsoleText("[FAILED] Powersaving: Argument must be > 0.");
|
|
|
|
|
printFastCText("[FAILED] Powersaving: Argument must be > 0.");
|
|
|
|
|
}
|
|
|
|
|
if(level > 1) {
|
|
|
|
|
Serial.end();
|
|
|
|
@ -563,7 +579,7 @@ void enablePS(int level) {
|
|
|
|
|
power_timer4_disable();
|
|
|
|
|
power_timer5_disable();
|
|
|
|
|
//power_twi_disable(); // twi needed for soil sensors / i2c
|
|
|
|
|
printConsoleText("[ OK ] Enabled Level 2 powersaving.");
|
|
|
|
|
printFastCText("[ OK ] Enabled Level 2 powersaving.");
|
|
|
|
|
}
|
|
|
|
|
if(level > 2) {
|
|
|
|
|
// disable ADC
|
|
|
|
@ -571,12 +587,15 @@ void enablePS(int level) {
|
|
|
|
|
//power_all_disable();
|
|
|
|
|
ps3 = true;
|
|
|
|
|
|
|
|
|
|
printConsoleText("[ OK ] Enabled Level 3 powersaving.|[ INFO ] All powersaving features enabled.");
|
|
|
|
|
printFastCText("[ OK ] Enabled Level 3 powersaving.");
|
|
|
|
|
printFastCText("[ INFO ] All powersaving features enabled.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void clearLog() {
|
|
|
|
|
outtext = "";
|
|
|
|
|
outtext2 = "";
|
|
|
|
|
linecount = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void printConsoleText(String text) {
|
|
|
|
@ -602,7 +621,7 @@ void printConsoleText(String text) {
|
|
|
|
|
outtext += text.substring(x, x + 53);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(text.length() % 53 != 0) {
|
|
|
|
|
if (text.length() % 53 != 0) {
|
|
|
|
|
outtext += text.substring(text.length() - text.length() % 53, text.length()) + "|";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -611,16 +630,16 @@ void printConsoleText(String text) {
|
|
|
|
|
outtext.remove(0, outtext.indexOf("|") + 1);
|
|
|
|
|
count--;
|
|
|
|
|
}
|
|
|
|
|
if(debug) {
|
|
|
|
|
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--) {
|
|
|
|
|
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))) {
|
|
|
|
|
if (!tmp.equals(getString(oldtext, x))) {
|
|
|
|
|
tft.fillRect(0, tft.getCursorY(), 320, 8, BLACK);
|
|
|
|
|
tft.print(tmp);
|
|
|
|
|
}
|
|
|
|
@ -630,8 +649,8 @@ void printConsoleText(String text) {
|
|
|
|
|
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("|")) {
|
|
|
|
|
for (int x = 0; x < l; x++) {
|
|
|
|
|
if (s.substring(x, x + 1).equals("|")) {
|
|
|
|
|
newlines ++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -641,9 +660,9 @@ 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("|")) {
|
|
|
|
|
if (s.substring(x, x + 1).equals("|")) {
|
|
|
|
|
count ++;
|
|
|
|
|
if(count - 1 == index) {
|
|
|
|
|
if (count - 1 == index) {
|
|
|
|
|
return s.substring(lastsemi, x);
|
|
|
|
|
}
|
|
|
|
|
lastsemi = x + 1;
|
|
|
|
@ -652,3 +671,32 @@ String getString(String s, int index) {
|
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
if (text.length() < 53) {
|
|
|
|
|
outtext2 += text;
|
|
|
|
|
for (int x = text.length(); x < 53; x++) {
|
|
|
|
|
outtext2 += " ";
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
outtext2 += text;
|
|
|
|
|
}
|
|
|
|
|
if (debug) {
|
|
|
|
|
//tft.setCursor(0, 0);
|
|
|
|
|
//tft.fillScreen(BLACK);
|
|
|
|
|
int lc2 = linecount;
|
|
|
|
|
tft.setCursor(0, lc2 * 8);
|
|
|
|
|
tft.setTextColor(ILI9341_WHITE);
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|