From 8273a809e84d103fc45ef6868202db7f638233e9 Mon Sep 17 00:00:00 2001 From: Blueforcer Date: Fri, 20 Apr 2018 13:45:41 +0200 Subject: [PATCH] Game --- lib/Applications/PongApp.cpp | 2 +- lib/Applications/SnakeApp.cpp | 32 ++++++++++---------------------- lib/Applications/WeatherApp.h | 4 ++-- lib/Applications/YoutubeApp.cpp | 9 ++++++--- platformio.ini | 4 +--- src/main.cpp | 6 ++++++ 6 files changed, 26 insertions(+), 31 deletions(-) diff --git a/lib/Applications/PongApp.cpp b/lib/Applications/PongApp.cpp index 6ccb81c..0dac149 100644 --- a/lib/Applications/PongApp.cpp +++ b/lib/Applications/PongApp.cpp @@ -28,7 +28,7 @@ void PongApp::render(DisplayManager& display) { oldPaddleY = paddleY; display.show(); - if (currentMillis - prevMillis >= 100) { + if (currentMillis - prevMillis >= 150) { prevMillis = currentMillis; if (ballX > 32 - 1 || ballX < 0) { diff --git a/lib/Applications/SnakeApp.cpp b/lib/Applications/SnakeApp.cpp index e0408f9..c76b6bc 100644 --- a/lib/Applications/SnakeApp.cpp +++ b/lib/Applications/SnakeApp.cpp @@ -6,12 +6,9 @@ const int RIGHT = 1; const int BOTTOM = 2; const int LEFT = 3; -// Snake const int MAX_SNAKE_LENGTH = 15; -// Variables - // direction of movement int snakeX[MAX_SNAKE_LENGTH]; // X-coordinates of snake int snakeY[MAX_SNAKE_LENGTH]; // Y-coordinates of snake int snakeLength = 1; // nr of parts of snake @@ -26,23 +23,18 @@ int matrixColor; void userLose(){ - - + //toDo snakeLength = 1; - } void userWin(){ - - - + //toDo snakeLength = 1; - } boolean inPlayField(int x, int y){ - return (x>=0) && (x<32) && (y>=0) && (y<8); + return (x>=1) && (x<32) && (y>=1) && (y<8); } boolean isPartOfSnake(int x, int y){ @@ -58,7 +50,7 @@ boolean isPartOfSnake(int x, int y){ void snakeCheck(){ for(int i=1; i 0; i--) { - if((direction == RIGHT) && (snakeX[0]-snakeLength == 31)) + if((direction == RIGHT) && (snakeX[0]-snakeLength == 32)) snakeX[0] = -1; else if((direction == LEFT) && (snakeX[0]+ snakeLength == 0)) snakeX[0] = 32; else snakeX[i] = snakeX[i-1]; - if((direction == TOP) && (snakeY[0]+snakeLength == 0)) + if((direction == TOP) && (snakeY[0]+snakeLength == 1)) snakeY[0] = 8; else if((direction == BOTTOM) && (snakeY[0]-snakeLength == 7)) snakeY[0] = -1; @@ -153,14 +145,10 @@ void SnakeApp::render(DisplayManager& display) { unsigned long currenttime = millis(); if(currenttime - fruitPrevTime >= fruitBlinkTime) { - //fruitLed = (fruitLed == LED_RED) ? LED_OFF : LED_RED; fruitPrevTime = currenttime; } display.drawPixel(fruitX, fruitY, {255,0,0}); } - - - display.show(); } diff --git a/lib/Applications/WeatherApp.h b/lib/Applications/WeatherApp.h index 7b573fa..980bf7d 100644 --- a/lib/Applications/WeatherApp.h +++ b/lib/Applications/WeatherApp.h @@ -9,8 +9,8 @@ class WeatherApp : public IApplication { private: - int temperature; - int humidity; + float temperature; + float humidity; String icon; String city; diff --git a/lib/Applications/YoutubeApp.cpp b/lib/Applications/YoutubeApp.cpp index 8a18358..3f340d2 100644 --- a/lib/Applications/YoutubeApp.cpp +++ b/lib/Applications/YoutubeApp.cpp @@ -37,10 +37,13 @@ void YoutubeApp::enable() { JsonObject& root = jsonBuffer.parseObject(response); jsonBuffer.clear(); if (!root.success()) { - Serial.println("Failed parsing API response"); + Serial.println("Failed parsing API response. Use last response"); } - - subscribers = root["items"][0]["statistics"]["subscriberCount"]; + int sub = root["items"][0]["statistics"]["subscriberCount"]; + if (sub>0){ + subscribers = sub; + } + } diff --git a/platformio.ini b/platformio.ini index 633f5e7..64f2825 100644 --- a/platformio.ini +++ b/platformio.ini @@ -20,11 +20,9 @@ lib_deps = PubSubClient Adafruit NeoMatrix Adafruit NeoPixel - Adafruit GFX Library + https://github.com/Blueforcer/Adafruit-GFX-Library Adafruit Unified Sensor WifiManager - thinger.io - WeatherStation JsonStreamingParser DHT sensor library ArduinoJson diff --git a/src/main.cpp b/src/main.cpp index 053be51..1aecdb4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,6 +20,8 @@ ApplicationManager& applications = ApplicationManager::getInstance(); AwtrixSettings& settings = AwtrixSettings::getInstance(); void setup() { +ESP.wdtDisable(); +ESP.wdtEnable(WDTO_8S); Serial.begin(115200); Serial1.begin(9800); settings.loadSPIFFS(); @@ -57,7 +59,11 @@ void loop() { wifi.loop(); udp.loop(); if (MQTT_ACTIVE) mqtt.loop(); + + + if (SETTINGS_FOUND) applications.loop(); + if (BLYNK_ACTIVE) ESPblynk.loop(); if (AUTO_BRIGHTNESS) DisplayManager::getInstance().checkLight(); }