From 42eae6ec9cd9a47d48a1f5dc27dab3fe00612e1e Mon Sep 17 00:00:00 2001 From: lulzette Date: Sun, 23 Feb 2020 21:50:43 +0300 Subject: [PATCH] move --- .vscode/arduino.json | 2 +- frontend.ino | 107 ++++++++++++++++++++++++++++--------------- 2 files changed, 72 insertions(+), 37 deletions(-) diff --git a/.vscode/arduino.json b/.vscode/arduino.json index aa317ad..9021411 100755 --- a/.vscode/arduino.json +++ b/.vscode/arduino.json @@ -1,6 +1,6 @@ { "board": "esp8266:esp8266:generic", - "configuration": "CpuFrequency=80,FlashFreq=40,FlashMode=qio,UploadSpeed=921600,FlashSize=512K0,ResetMethod=ck,Debug=Disabled,DebugLevel=None____", + "configuration": "xtal=80,vt=flash,exception=disabled,ssl=all,ResetMethod=ck,CrystalFreq=26,FlashFreq=40,FlashMode=qio,eesz=4M1M,led=2,sdk=nonosdk221,ip=lm2f,dbg=Disabled,lvl=None____,wipe=none,baud=921600", "sketch": "frontend.ino", "port": "/dev/ttyUSB0" } \ No newline at end of file diff --git a/frontend.ino b/frontend.ino index b1c00b9..b9d1a00 100755 --- a/frontend.ino +++ b/frontend.ino @@ -5,8 +5,6 @@ #include "SSD1306Brzo.h" #include "wifi.h" #include -#include -#include String inTemp,outTemp,pressure,humid; const unsigned short int onTime=6, offTime=23, beepDelay=60, timeOffset=3; @@ -19,20 +17,27 @@ int alarmStop(0); WiFiUDP ntpUDP; NTPClient timeClient(ntpUDP); SSD1306Brzo display(0x3C, 5, 4); - +void demo(); void setup(){ - Serial.begin(115200); //==DISPLAY INIT== display.init(); display.flipScreenVertically(); display.setContrast(255); + // display.invertDisplay(); + display.clear(); + display.fillRect(0,0,128,64); + display.display(); + delay(3000); + if (!digitalRead(0)) //button + demo(120000); + Serial.begin(115200); + //==WIFI CONNECT== WiFi.mode(WIFI_STA); //==NTP INIT== timeClient.begin(); timeClient.setTimeOffset(timeOffset*3600); netTasks(); - // SPIFFS.begin(); } void loop(){ @@ -46,14 +51,13 @@ void loop(){ noTone(15); lastBeep = timeClient.getHours()*60; netTasks(); + // demo(12000); } else { delay(500); } checkAlarm(); } - - void checkAlarm() { for (int i(0);i<10;i++) @@ -78,7 +82,6 @@ void checkAlarm() } } } - void netTasks() { HTTPClient http; WiFi.forceSleepWake(); @@ -141,24 +144,37 @@ void mainScreen() { } display.display(); } -void displayStatus(int state){ - display.clear(); - display.setTextAlignment(TEXT_ALIGN_CENTER); - switch (state) { - case 0: - display.drawString(64, 22, "Connected!"); - break; - case 1: - display.drawString(64, 22, "Connecting..."); - break; - case 2: - display.drawString(64, 22, "Not connected!"); - display.setFont(ArialMT_Plain_10); - display.setTextAlignment(TEXT_ALIGN_LEFT); - display.drawString(0, 53, "we will die in 10s! :0"); - break; +void displayStatus(){ + bool run(true); + display.setFont(ArialMT_Plain_10); + display.setTextAlignment(TEXT_ALIGN_LEFT); + int x(0),y(0); + bool xd(false);//false - right, true - left + + while (run) + { + display.clear(); + if (WiFi.status() != WL_CONNECTED) { + display.fillRect(x,y,30,50); + if (x > 128-30) + xd = true; + if (x < 0) + xd = false; + if (xd) { + x--; + } else { + x++; + } + + display.drawString(1, 52, ssid); + + } + if (WiFi.status() == WL_CONNECTED) { + run = false; + } + display.display(); } - display.display(); + } void updateNtp() { while (!timeClient.update()) @@ -174,15 +190,34 @@ bool nightMode() { void wifiConnect(bool boot) { int beginMillis = millis(); WiFi.begin(ssid, password); - while (WiFi.status() != WL_CONNECTED && millis() - beginMillis < 30000) { - delay(250); - Serial.print("."); - } - if (WiFi.status() != WL_CONNECTED) { - delay(10000); - ESP.reset(); - } else { - Serial.print("Connected to " + String(ssid) + "; IP address: "); - Serial.println(WiFi.localIP()); - } + displayStatus(); } + + +void demo(int duration) +{ + short xp(0),yp(0),xd(1),yd(1); + unsigned int startTime = millis(); + bool run(true); + while (run) { + if ((xp > 128) || (xp < 0)) + { + xd = xd * -1; + } + if ((yp > 64) || (yp < 0)) + { + yd = yd * -1; + } + xp+=xd; + yp+=yd; + + delay(10); + display.clear(); + display.fillCircle(xp,yp,10); + display.display(); + + if (millis() - startTime > duration) + run = false; + } + +} \ No newline at end of file