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