From 0a6d966efbfc9b910d3883c12519296e763ba812 Mon Sep 17 00:00:00 2001 From: ThirstyShark Date: Mon, 18 Mar 2019 22:07:01 -0500 Subject: [PATCH] touch api --- Greenhouse.ino | 119 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 88 insertions(+), 31 deletions(-) diff --git a/Greenhouse.ino b/Greenhouse.ino index 4c4e072..e9dbae8 100644 --- a/Greenhouse.ino +++ b/Greenhouse.ino @@ -131,7 +131,7 @@ String outtext = ""; String oldtext = ""; boolean fastboot = false; boolean debug; - +int menu = 0; boolean ps3 = false; boolean upd = true; boolean s1, s2, s3, s4; @@ -230,6 +230,16 @@ void setup(void) { } debug = false; //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:"; + tft.drawString(out.c_str(), 2, 2, 2); + drawButton(0, 20, 160, 110, "Settings", "ILI9341_YELLOW"); + drawButton(160, 20, 160, 110, "Stats", "ILI9341_GREEN"); + upd = false; } const int sec = 1000; const int min = 1000 * 60; @@ -237,15 +247,37 @@ const int hr = 1000 * 60 * 60; void loop(void) { TSPoint p = ts.getPoint(); if (p.z > ts.pressureThreshhold) { - p.x = map(p.x, TS_MINX, TS_MAXX, tft.height(), 0); - p.y = map(p.y, TS_MINY, TS_MAXY, tft.width(), 0); - Serial.print("X = "); Serial.print(p.x); - Serial.print("\tY = "); Serial.print(p.y); - Serial.print("\tPressure = "); Serial.println(p.z); + p.x = map(p.x, TS_MINX, TS_MAXX, tft.height(), 0); + p.y = map(p.y, TS_MINY, TS_MAXY, tft.width(), 0); + Serial.print("X = "); Serial.print(320 - p.y); + Serial.print("\tY = "); Serial.print(p.x); + Serial.print("\tPressure = "); Serial.println(p.z); + int x = 320 - p.y; + int y = p.x; + if (x < 160 && y < 130) { + button(0, 0); + } + if (x > 160 && y < 130) { + button(1, 0); + } + if (x < 160 && y > 130) { + button(0, 1); + } + if (x > 160 && y > 130) { + button(1, 1); + } } - - if (ps3) { - ADCSRA = 0; + if (upd) { + if (menu == 0) { + drawButton(0, 20, 160, 110, "Settings", "ILI9341_YELLOW"); + drawButton(160, 20, 160, 110, "Stats", "ILI9341_GREEN"); + } + if (menu == 1) { + drawButton(0, 130, 160, 110, "Reset", "ILI9341_GREEN"); + drawButton(0, 20, 320, 110, "Stop", "ILI9341_RED"); + drawButton(160, 130, 160, 110, "Back", "ILI9341_BLUE"); + } + upd = false; } if(Serial.available() > 0) { String txtin = "Serial: " + Serial.readString(); @@ -299,18 +331,7 @@ void loop(void) { }*/ // change upd to true if screen update needed - if(!debug && upd) { - 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:"; - tft.drawString(out.c_str(), 2, 2, 2); - drawButton(0, 20, 160, 110, "Settings", "ILI9341_YELLOW"); - drawButton(160, 20, 160, 110, "Stats", "ILI9341_GREEN"); - upd = false; - } + batteryupd.Update(); water.Update(); } @@ -329,16 +350,14 @@ void checkBat() { delay(10); } if(analogRead(1) > 910) { - out += map(y / 20, 572, 859, 0, 100) - 20; + out += "Using solar poower"; } else { out += map(y / 20, 572, 859, 0, 100); + out += "%"; } - out += "%, Raw: "; + out += ", Raw: "; out += y/20; out += "."; - if(analogRead(1) > 910) { - out += ". Battery Charging."; - } printFastCText(out); } else { String out = "Battery: "; @@ -348,13 +367,10 @@ void checkBat() { delay(10); } if(analogRead(1) > 910) { - out += map(y / 20, 572, 859, 0, 100) - 20; + out += "Using solar."; } else { out += map(y / 20, 572, 859, 0, 100); - } - out += "%"; - if(analogRead(1) > 910) { - out += " Charging"; + out += "%"; } tft.fillRect(160, 0, 160, 20, ILI9341_WHITE); tft.drawString(out.c_str(), 162, 2, 2); @@ -629,7 +645,48 @@ void scrollAddress(uint16_t vsp) { } void drawButton(int x, int y, int w, int h, char* text, char* color) { + tft.fillRect(x, y, w, h, ILI9341_BLACK); tft.setTextFont(4); tft.fillRect(x, y, w, h, color); tft.drawCentreString(text, x + w/2, y + h/2 - 15, 4); } + +void button(int x, int y) { + + if (menu == 0) { + if (x == 0 && y == 0) { + menu = 1; + upd = true; + } + if (x == 1 && y == 0) { + menu = 2; + upd = true; + } + if (x == 0 && y == 1) { + menu = 3; + upd = true; + } + if (x == 1 && y == 1) { + menu = 4; + upd = true; + } + } + else if (menu == 1) { + if (x == 0 && y == 1) { + tft.fillRect(0, 0, 320, 240, ILI9341_BLACK); + pinMode(9, OUTPUT); + digitalWrite(9, LOW); // RESET + } + if (y == 0) { + // STOP CODE HERE + water.Stop(); + menu = 0; + upd = true; + } + if (x == 1 && y == 1) { + menu = 0; + upd = true; + } + } + delay(250); +}