small bug fixes and enhancements, bump version to 0.3.5

master
ThirstyShark 5 years ago
parent 4d84d3a40d
commit e40e51849c

@ -230,7 +230,7 @@ void setup(void) {
} }
clearLog(); clearLog();
printFastCText("Booting GreenhouseOS..."); printFastCText("Booting GreenhouseOS...");
printFastCText("Version: 0.3.0"); printFastCText("Version: 0.3.5");
printFastCText(""); printFastCText("");
delay(250); delay(250);
if(!didDraw) { if(!didDraw) {
@ -281,7 +281,6 @@ void setup(void) {
//getMoisture(); //getMoisture();
tft.fillScreen(ILI9341_BLACK); tft.fillScreen(ILI9341_BLACK);
tft.fillRect(0, 0, 160, 20, ILI9341_WHITE); tft.fillRect(0, 0, 160, 20, ILI9341_WHITE);
tft.setCursor(2, 2);
tft.setTextFont(4); tft.setTextFont(4);
tft.setTextColor(ILI9341_BLACK); tft.setTextColor(ILI9341_BLACK);
String out = "Water Level:"; String out = "Water Level:";
@ -332,6 +331,18 @@ void loop(void) {
button(1, 1); button(1, 1);
} }
} }
if(touch(300, -10, 40, 30, p)) {
debug = !debug;
if(!debug) {
upd = true;
tft.fillScreen(ILI9341_BLACK);
tft.fillRect(0, 0, 160, 20, ILI9341_WHITE);
tft.setTextColor(ILI9341_BLACK);
String out = "Water Level:";
tft.drawString(out.c_str(), 2, 2, 2);
checkBat();
}
}
} }
else { else {
if(screenoff < millis() && screenoff != 0) { if(screenoff < millis() && screenoff != 0) {
@ -341,8 +352,8 @@ void loop(void) {
screenoff = millis() + 60000; screenoff = millis() + 60000;
} }
} }
if ((batteryupd.m_milliseconds - millis() + batteryupd.m_lastRunTimestamp) / (sec / 4) == 0 && menu == 2) { if ((batteryupd.m_milliseconds - millis() + batteryupd.m_lastRunTimestamp) / (sec / 4) == 0 && menu == 2 && !debug) {
upd = true; drawStats();
} }
if (upd) { if (upd) {
if (menu == 0) { if (menu == 0) {
@ -363,86 +374,119 @@ void loop(void) {
drawButton(160, 130, 160, 110, "Back", ILI9341_BLUE); drawButton(160, 130, 160, 110, "Back", ILI9341_BLUE);
} }
if (menu == 2) { if (menu == 2) {
//debug = true; drawButton(0, 20, 320, 220, "", ILI9341_WHITE);
//printFastCText("pressed");
tft.fillRect(0, 20, 320, 220, ILI9341_WHITE);
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
String txt = "Humidity: ";
txt += h;
txt += "%";
displayText(2, 30, false, txt, 4);
txt = "Temperature: ";
txt += f;
txt += " degrees";
displayText(2, 53, false, txt, 4);
txt = (water.m_milliseconds - millis() + water.m_lastRunTimestamp) / 60000 + 1; // ceil instead of floor
txt += " minutes until water";
displayText(2, 76, false, txt, 4);
// moisture, temperature, next cycle, how much water, power usage, sensor connections
drawButton(160, 130, 160, 110, "Back", ILI9341_BLUE); drawButton(160, 130, 160, 110, "Back", ILI9341_BLUE);
if(fani) { drawStats();
drawButton(2, 100, 157, 35, "Intake Fan", ILI9341_GREEN); if(b1[1]) {
if(b1[0]) {
drawButton(5, 135, 70, 45, "1*", ILI9341_GREEN);
} else {
drawButton(5, 135, 70, 45, "1*", ILI9341_RED);
}
} else { } else {
drawButton(2, 100, 157, 35, "Intake Fan", ILI9341_RED); if(b1[0]) {
drawButton(5, 135, 70, 45, "1", ILI9341_GREEN);
} else {
drawButton(5, 135, 70, 45, "1", ILI9341_RED);
}
} }
if(fano) { if(b2[1]) {
drawButton(161, 100, 157, 35, "Exhaust Fan", ILI9341_GREEN); if(b2[0]) {
drawButton(85, 135, 70, 45, "2*", ILI9341_GREEN);
} else {
drawButton(85, 135, 70, 45, "2*", ILI9341_RED);
}
} else { } else {
drawButton(161, 100, 157, 35, "Exhaust Fan", ILI9341_RED); if(b2[0]) {
drawButton(85, 135, 70, 45, "2", ILI9341_GREEN);
} else {
drawButton(85, 135, 70, 45, "2", ILI9341_RED);
}
} }
drawButton(160, 130, 160, 110, "Back", ILI9341_BLUE); if(b3[1]) {
drawButton(0, 130, 160, 110, "", ILI9341_WHITE); if(b3[0]) {
if(b1[0]) { drawButton(5, 190, 70, 45, "3*", ILI9341_GREEN);
drawButton(5, 135, 70, 45, "1", ILI9341_GREEN); } else {
drawButton(5, 190, 70, 45, "3*", ILI9341_RED);
}
} else { } else {
drawButton(5, 135, 70, 45, "1", ILI9341_RED); if(b3[0]) {
drawButton(5, 190, 70, 45, "3", ILI9341_GREEN);
} else {
drawButton(5, 190, 70, 45, "3", ILI9341_RED);
}
} }
if(b2[0]) { if(b4[1]) {
drawButton(85, 135, 70, 45, "2", ILI9341_GREEN); if(b4[0]) {
drawButton(85, 190, 70, 45, "4*", ILI9341_GREEN);
} else {
drawButton(85, 190, 70, 45, "4*", ILI9341_RED);
}
} else { } else {
drawButton(85, 135, 70, 45, "2", ILI9341_RED); if(b4[0]) {
} drawButton(85, 190, 70, 45, "4", ILI9341_GREEN);
if(b3[0]) { } else {
drawButton(5, 190, 70, 45, "3", ILI9341_GREEN); drawButton(85, 190, 70, 45, "4", ILI9341_RED);
} else { }
drawButton(5, 190, 70, 45, "3", ILI9341_RED);
}
if(b4[0]) {
drawButton(85, 190, 70, 45, "4", ILI9341_GREEN);
} else {
drawButton(85, 190, 70, 45, "4", ILI9341_RED);
} }
} }
if (menu == 3) { if (menu == 3) {
tft.fillRect(0, 20, 320, 220, ILI9341_WHITE); drawButton(0, 20, 320, 220, "", ILI9341_WHITE);
drawButton(160, 130, 160, 110, "Back", ILI9341_BLUE); drawButton(160, 130, 160, 110, "Back", ILI9341_BLUE);
drawUD(uda); drawUD(uda);
if(b1[0]) { if(b1[1]) {
drawButton(5, 135, 70, 45, "1", ILI9341_GREEN); if(b1[0]) {
drawButton(5, 135, 70, 45, "1*", ILI9341_GREEN);
} else {
drawButton(5, 135, 70, 45, "1*", ILI9341_RED);
}
} else { } else {
drawButton(5, 135, 70, 45, "1", ILI9341_RED); if(b1[0]) {
drawButton(5, 135, 70, 45, "1", ILI9341_GREEN);
} else {
drawButton(5, 135, 70, 45, "1", ILI9341_RED);
}
} }
if(b2[0]) { if(b2[1]) {
drawButton(85, 135, 70, 45, "2", ILI9341_GREEN); if(b2[0]) {
drawButton(85, 135, 70, 45, "2*", ILI9341_GREEN);
} else {
drawButton(85, 135, 70, 45, "2*", ILI9341_RED);
}
} else { } else {
drawButton(85, 135, 70, 45, "2", ILI9341_RED); if(b2[0]) {
drawButton(85, 135, 70, 45, "2", ILI9341_GREEN);
} else {
drawButton(85, 135, 70, 45, "2", ILI9341_RED);
}
} }
if(b3[0]) { if(b3[1]) {
drawButton(5, 190, 70, 45, "3", ILI9341_GREEN); if(b3[0]) {
drawButton(5, 190, 70, 45, "3*", ILI9341_GREEN);
} else {
drawButton(5, 190, 70, 45, "3*", ILI9341_RED);
}
} else { } else {
drawButton(5, 190, 70, 45, "3", ILI9341_RED); if(b3[0]) {
drawButton(5, 190, 70, 45, "3", ILI9341_GREEN);
} else {
drawButton(5, 190, 70, 45, "3", ILI9341_RED);
}
} }
if(b4[0]) { if(b4[1]) {
drawButton(85, 190, 70, 45, "4", ILI9341_GREEN); if(b4[0]) {
drawButton(85, 190, 70, 45, "4*", ILI9341_GREEN);
} else {
drawButton(85, 190, 70, 45, "4*", ILI9341_RED);
}
} else { } else {
drawButton(85, 190, 70, 45, "4", ILI9341_RED); if(b4[0]) {
drawButton(85, 190, 70, 45, "4", ILI9341_GREEN);
} else {
drawButton(85, 190, 70, 45, "4", ILI9341_RED);
}
} }
displayText(15, 45, false, "Water amount:", 4); displayText(15, 45, false, "Water amount:", 4);
} }
upd = false; upd = false;
} }
@ -466,35 +510,20 @@ ISR (WDT_vect)
} // end of WDT_vect } // end of WDT_vect
void checkBat() { void checkBat() {
if(debug) { String out = "Battery: ";
String out = "[ OK ] Battery: "; int y = checkPin(0, 20);
int y = checkPin(0, 20); if(analogRead(1) > 910) {
if(analogRead(1) > 910) { out += "Using solar.";
out += "Using solar power";
} else {
out += map(y / 20, 572, 859, 0, 100);
out += "%";
}
out += ", Raw: ";
out += y/20;
out += ".";
printFastCText(out);
} else { } else {
String out = "Battery: "; out += map(y / 20, 572, 859, 0, 100);
int y = checkPin(0, 20); out += "%";
if(analogRead(1) > 910) {
out += "Using solar.";
} else {
out += map(y / 20, 572, 859, 0, 100);
out += "%";
}
tft.fillRect(160, 0, 160, 20, ILI9341_WHITE);
tft.drawString(out.c_str(), 162, 2, 2);
} }
drawButton(160, 0, 160, 20, "", ILI9341_WHITE);
tft.drawString(out.c_str(), 162, 2, 2);
// check water level // check water level
// A37: Top // A37: Top
// A34: Bottom // A34: Bottom
if (digitalRead(34) == 0) drawButton(140, 2, 16, 16, "", ILI9341_RED); /*if (digitalRead(34) == 0)*/ drawButton(140, 2, 16, 16, "", ILI9341_RED);
if (digitalRead(35) == 0) drawButton(140, 2, 16, 16, "", ILI9341_ORANGE); if (digitalRead(35) == 0) drawButton(140, 2, 16, 16, "", ILI9341_ORANGE);
if (digitalRead(36) == 0) drawButton(140, 2, 16, 16, "", ILI9341_YELLOW); if (digitalRead(36) == 0) drawButton(140, 2, 16, 16, "", ILI9341_YELLOW);
if (digitalRead(37) == 0) drawButton(140, 2, 16, 16, "", ILI9341_GREEN); if (digitalRead(37) == 0) drawButton(140, 2, 16, 16, "", ILI9341_GREEN);
@ -525,6 +554,42 @@ void checkBat() {
} }
} }
void drawStats() {
printFastCText("[ INFO ] Updating statistics.");
tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
String txt = "Humidity: ";
txt += h;
txt += "%";
displayText(2, 30, false, txt, 4);
txt = "Temperature: ";
txt += f;
txt += " degrees";
displayText(2, 53, false, txt, 4);
txt = (water.m_milliseconds - millis() + water.m_lastRunTimestamp) / 60000 + 1; // ceil instead of floor
txt += " minutes until water";
displayText(2, 76, false, txt, 4);
tft.setTextColor(ILI9341_BLACK);
// moisture, temperature, next cycle, how much water, power usage, sensor connections
if(fani) {
drawButton(5, 100, 150, 35, "Intake Fan", ILI9341_GREEN);
} else {
drawButton(5, 100, 150, 35, "Intake Fan", ILI9341_RED);
}
if(fano) {
drawButton(165, 100, 150, 35, "Exhaust Fan", ILI9341_GREEN);
} else {
drawButton(165, 100, 150, 35, "Exhaust Fan", ILI9341_RED);
}
drawButton(165, 125, 150, 5, "", ILI9341_WHITE);
drawButton(165, 130, 150, 5, "", ILI9341_BLUE);
drawButton(5, 125, 150, 10, "", ILI9341_WHITE);
}
int checkPin(byte pin, int count) { int checkPin(byte pin, int count) {
int out = 0; int out = 0;
for (int x = 0; x < count; x++) { for (int x = 0; x < count; x++) {
@ -604,6 +669,7 @@ void runWater() {
} }
digitalWrite(7, LOW); digitalWrite(7, LOW);
} }
void getMoisture() { void getMoisture() {
float h = dht.readHumidity(); float h = dht.readHumidity();
// Read temperature as Celsius (the default) // Read temperature as Celsius (the default)
@ -818,20 +884,11 @@ void printFastCText(String text) { // NOTE: text MUST be under 53 characters lon
outtext2 += text; outtext2 += text;
} }
if (debug) { if (debug) {
//tft.setCursor(0, 0);
//tft.fillScreen(BLACK);
tft.setCursor(0, 0); tft.setCursor(0, 0);
tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK); tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK);
tft.setTextSize(1); tft.setTextSize(1);
tft.setTextFont(1); tft.setTextFont(1);
//int cursory = linecount * 8; tft.print(outtext2);
//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) { void scrollAddress(uint16_t vsp) {
@ -841,6 +898,7 @@ void scrollAddress(uint16_t vsp) {
} }
void drawButton(int x, int y, int w, int h, char* text, word color) { void drawButton(int x, int y, int w, int h, char* text, word color) {
if(debug) return;
//tft.fillRect(x, y, w, h, ILI9341_BLACK); //tft.fillRect(x, y, w, h, ILI9341_BLACK);
tft.setTextFont(4); tft.setTextFont(4);
tft.fillRect(x, y, w, h, color); tft.fillRect(x, y, w, h, color);
@ -848,7 +906,6 @@ void drawButton(int x, int y, int w, int h, char* text, word color) {
} }
void button(int x, int y) { void button(int x, int y) {
if (menu == 0) { if (menu == 0) {
if (x == 0 && y == 0) { if (x == 0 && y == 0) {
menu = 1; menu = 1;
@ -877,7 +934,7 @@ void button(int x, int y) {
} }
else if (menu == 1) { else if (menu == 1) {
if (x == 0 && y == 1) { if (x == 0 && y == 1) {
tft.fillRect(0, 0, 320, 240, ILI9341_BLACK); drawButton(0, 0, 320, 240, "", ILI9341_BLACK);
pinMode(9, OUTPUT); pinMode(9, OUTPUT);
digitalWrite(9, LOW); // RESET digitalWrite(9, LOW); // RESET
} }
@ -899,6 +956,7 @@ void button(int x, int y) {
if (x == 1 && y == 1) { if (x == 1 && y == 1) {
menu = 0; menu = 0;
upd = true; upd = true;
dispbox = 0;
updBoxMenu(1); updBoxMenu(1);
updBoxMenu(2); updBoxMenu(2);
updBoxMenu(3); updBoxMenu(3);
@ -910,18 +968,22 @@ void button(int x, int y) {
if(touch(0, 130, 80, 55, p)) { if(touch(0, 130, 80, 55, p)) {
updBoxMenu(1); updBoxMenu(1);
drawBoxMenu(1); drawBoxMenu(1);
updBoxMenu(1);
} }
if(touch(80, 130, 80, 55, p)) { if(touch(80, 130, 80, 55, p)) {
updBoxMenu(2); updBoxMenu(2);
drawBoxMenu(2); drawBoxMenu(2);
updBoxMenu(2);
} }
if(touch(0, 185, 80, 55, p)) { if(touch(0, 185, 80, 55, p)) {
updBoxMenu(3); updBoxMenu(3);
drawBoxMenu(3); drawBoxMenu(3);
updBoxMenu(3);
} }
if(touch(80, 185, 80, 55, p)) { if(touch(80, 185, 80, 55, p)) {
updBoxMenu(4); updBoxMenu(4);
drawBoxMenu(4); drawBoxMenu(4);
updBoxMenu(4);
} }
} }
// skip 4 lol, oops // skip 4 lol, oops
@ -936,26 +998,29 @@ void button(int x, int y) {
if (x == 0 && y == 1) { if (x == 0 && y == 1) {
if(dispbox == 1) { if(dispbox == 1) {
b1[0] = !b1[0]; b1[0] = !b1[0];
drawBoxMenu(1); printFastCText("[ INFO ] Toggling box 1.");
} }
if(dispbox == 2) { if(dispbox == 2) {
b2[0] = !b2[0]; b2[0] = !b2[0];
drawBoxMenu(2); printFastCText("[ INFO ] Toggling box 2.");
} }
if(dispbox == 3) { if(dispbox == 3) {
b3[0] = !b3[0]; b3[0] = !b3[0];
drawBoxMenu(3); printFastCText("[ INFO ] Toggling box 3.");
} }
if(dispbox == 4) { if(dispbox == 4) {
b4[0] = !b4[0]; b4[0] = !b4[0];
drawBoxMenu(4); printFastCText("[ INFO ] Toggling box 4.");
} }
drawBoxMenu(dispbox);
updBoxMenu(dispbox);
} }
} }
delay(250); delay(175);
} }
void displayText(int x, int y, boolean center, String text, int size) { void displayText(int x, int y, boolean center, String text, int size) {
if (debug) return;
if (center) { if (center) {
tft.drawCentreString(text.c_str(), x, y, size); tft.drawCentreString(text.c_str(), x, y, size);
} else { } else {
@ -968,8 +1033,8 @@ void drawSlider(int data[]) {
int y = data[1]; int y = data[1];
int w = data[2]; int w = data[2];
int d = data[3]; int d = data[3];
tft.fillRect(x, y, w, 20, ILI9341_BLACK); drawButton(x, y, w, 20, "", ILI9341_BLACK);
tft.fillRect(x + d, y, 20, 20, ILI9341_GREEN); drawButton(x + d, y, 20, 20, "", ILI9341_GREEN);
} }
void drawUD(int data[]) { void drawUD(int data[]) {
@ -1008,7 +1073,7 @@ void updUD(int data[]) {
String out = ""; String out = "";
out += d; out += d;
out += "%"; out += "%";
tft.fillRect(x, y + 15, 70, 25, ILI9341_WHITE); drawButton(x, y + 15, 70, 25, "", ILI9341_WHITE);
tft.drawString(out.c_str(), x, y + 15, 4); tft.drawString(out.c_str(), x, y + 15, 4);
} }
else if (yt >= y + 15 && yt <= y + 60 && d > data[3]) { else if (yt >= y + 15 && yt <= y + 60 && d > data[3]) {
@ -1018,7 +1083,7 @@ void updUD(int data[]) {
String out = ""; String out = "";
out += d; out += d;
out += "%"; out += "%";
tft.fillRect(x, y + 15, 70, 25, ILI9341_WHITE); drawButton(x, y + 15, 70, 25, "", ILI9341_WHITE);
tft.drawString(out.c_str(), x, y + 15, 4); tft.drawString(out.c_str(), x, y + 15, 4);
} }
} }
@ -1040,7 +1105,7 @@ void drawBoxMenu(int box) {
return; return;
} }
menu = 5; menu = 5;
tft.fillRect(0, 20, 320, 220, ILI9341_WHITE); drawButton(0, 20, 320, 220, "", ILI9341_WHITE);
if (box == 1) { if (box == 1) {
if(!b1[0]) { if(!b1[0]) {
displayText(15, 35, false, "Plant Box 1 Disabled", 4); displayText(15, 35, false, "Plant Box 1 Disabled", 4);
@ -1105,12 +1170,20 @@ void updBoxMenu(int box) {
updUD(ud1); updUD(ud1);
if(ud1[2] != uda[2]) { if(ud1[2] != uda[2]) {
b1[1] = true; b1[1] = true;
if(box == dispbox) {
drawButton(15, 95, 100, 30, "", ILI9341_WHITE);
}
} else {
displayText(15, 95, false, "In sync", 4);
} }
} else { } else {
updUD(ud1); updUD(ud1);
if(ud1[2] == uda[2]) { if(ud1[2] == uda[2]) {
b1[1] = false; b1[1] = false;
} if(box == dispbox) {
displayText(15, 95, false, "In sync", 4);
}
}
} }
} }
if (box == 2) { if (box == 2) {
@ -1119,11 +1192,19 @@ void updBoxMenu(int box) {
updUD(ud2); updUD(ud2);
if(ud2[2] != uda[2]) { if(ud2[2] != uda[2]) {
b2[1] = true; b2[1] = true;
if(box == dispbox) {
drawButton(15, 95, 100, 30, "", ILI9341_WHITE);
}
} else {
displayText(15, 95, false, "In sync", 4);
} }
} else { } else {
updUD(ud2); updUD(ud2);
if(ud2[2] == uda[2]) { if(ud2[2] == uda[2]) {
b2[1] = false; b2[1] = false;
if(box == dispbox) {
displayText(15, 95, false, "In sync", 4);
}
} }
} }
} }
@ -1133,11 +1214,19 @@ void updBoxMenu(int box) {
updUD(ud3); updUD(ud3);
if(ud3[2] != uda[2]) { if(ud3[2] != uda[2]) {
b3[1] = true; b3[1] = true;
if(box == dispbox) {
drawButton(15, 95, 100, 30, "", ILI9341_WHITE);
}
} else {
displayText(15, 95, false, "In sync", 4);
} }
} else { } else {
updUD(ud3); updUD(ud3);
if(ud3[2] == uda[2]) { if(ud3[2] == uda[2]) {
b3[1] = false; b3[1] = false;
if(box == dispbox) {
displayText(15, 95, false, "In sync", 4);
}
} }
} }
} }
@ -1147,11 +1236,19 @@ void updBoxMenu(int box) {
updUD(ud4); updUD(ud4);
if(ud4[2] != uda[2]) { if(ud4[2] != uda[2]) {
b4[1] = true; b4[1] = true;
if(box == dispbox) {
drawButton(15, 95, 100, 30, "", ILI9341_WHITE);
}
} else {
displayText(15, 95, false, "In sync", 4);
} }
} else { } else {
updUD(ud4); updUD(ud4);
if(ud4[2] == uda[2]) { if(ud4[2] == uda[2]) {
b4[1] = false; b4[1] = false;
if(box == dispbox) {
displayText(15, 95, false, "In sync", 4);
}
} }
} }
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save