diff --git a/animationfunctions.ino b/animationfunctions.ino index d92a0f3..436ac7a 100644 --- a/animationfunctions.ino +++ b/animationfunctions.ino @@ -330,7 +330,6 @@ int randomtetris(bool init){ } } else{ - uint8_t tempscreen[HEIGHT+3][WIDTH] = {0}; uint8_t moveX = WIDTH-1; uint8_t moveY = HEIGHT+2; // moving blocks exists -> move them one pixel down @@ -338,7 +337,6 @@ int randomtetris(bool init){ for(int c = WIDTH-1; c >= 0; c--){ for(int r = HEIGHT+1; r >= 0; r--){ if((screen[r][c] != 0) && tomove[screen[r][c]]){ - tempscreen[r+1][c] = screen[r][c]; screen[r+1][c] = screen[r][c]; screen[r][c] = 0; // save top left corner of block diff --git a/ledmatrix.cpp b/ledmatrix.cpp index da5919b..28935cf 100644 --- a/ledmatrix.cpp +++ b/ledmatrix.cpp @@ -135,7 +135,7 @@ void LEDMatrix::setMinIndicator(uint8_t pattern, uint32_t color) void LEDMatrix::gridAddPixel(uint8_t x, uint8_t y, uint32_t color) { // limit ranges of x and y - if(x >= 0 && x < WIDTH && y >= 0 && y < HEIGHT){ + if(x < WIDTH && y < HEIGHT){ targetgrid[y][x] = color; } else{ diff --git a/ntp_client_plus.cpp b/ntp_client_plus.cpp index 9de9488..5cdd252 100644 --- a/ntp_client_plus.cpp +++ b/ntp_client_plus.cpp @@ -250,7 +250,7 @@ void NTPClientPlus::calcDate() // calc how many leap days since 1.Jan 1900 int leapDays = 0; - for (int i = 1900; i < this->_dateYear; i++) + for (unsigned int i = 1900; i < this->_dateYear; i++) { // check if leap year if (this->isLeapYear(i)) @@ -278,7 +278,7 @@ void NTPClientPlus::calcDate() this->_dateDay = 0; // calc day of month - for (int i = 0; i < this->_dateMonth; i++) + for (unsigned int i = 0; i < this->_dateMonth; i++) { this->_dateDay = this->_dateDay + daysInMonth[i]; } @@ -289,7 +289,7 @@ void NTPClientPlus::calcDate() // 1. Januar 1900 was a monday this->_dayOfWeek = 1; - for (int i = 0; i < days1900; i++) + for (unsigned long i = 0; i < days1900; i++) { if (this->_dayOfWeek < 7) @@ -335,7 +335,7 @@ unsigned int NTPClientPlus::getYear() unsigned int days = 0; unsigned int days1900 = 0; - int for_i = 0; + unsigned long for_i = 0; bool leapYear = LOW; days1900 = sec1900 / this->secondperday; diff --git a/pong.cpp b/pong.cpp index c30e7e3..49cceff 100644 --- a/pong.cpp +++ b/pong.cpp @@ -56,7 +56,7 @@ void Pong::loopCycle(){ * @param playerid id of player {0, 1} */ void Pong::ctrlUp(uint8_t playerid){ - if (millis() > _lastButtonClick + DEBOUNCE_TIME) { + if (millis() > _lastButtonClick + DEBOUNCE_TIME_PONG) { _playerMovement[playerid] = PADDLE_MOVE_DOWN; // need to swap direction as field is rotated 180deg _lastButtonClick = millis(); } @@ -68,7 +68,7 @@ void Pong::ctrlUp(uint8_t playerid){ * @param playerid id of player {0, 1} */ void Pong::ctrlDown(uint8_t playerid){ - if (millis() > _lastButtonClick + DEBOUNCE_TIME) { + if (millis() > _lastButtonClick + DEBOUNCE_TIME_PONG) { _playerMovement[playerid] = PADDLE_MOVE_UP; // need to swap direction as field is rotated 180deg _lastButtonClick = millis(); } @@ -80,7 +80,7 @@ void Pong::ctrlDown(uint8_t playerid){ * @param playerid id of player {0, 1} */ void Pong::ctrlNone(uint8_t playerid){ - if (millis() > _lastButtonClick + DEBOUNCE_TIME) { + if (millis() > _lastButtonClick + DEBOUNCE_TIME_PONG) { _playerMovement[playerid] = PADDLE_MOVE_NONE; _lastButtonClick = millis(); } @@ -189,7 +189,7 @@ void Pong::endGame() */ void Pong::updateGame() { - if ((millis() - _lastDrawUpdate) < GAME_DELAY) { + if ((millis() - _lastDrawUpdate) < GAME_DELAY_PONG) { return; } _lastDrawUpdate = millis(); @@ -273,7 +273,7 @@ void Pong::resetLEDs() */ void Pong::toggleLed(uint8_t x, uint8_t y, uint8_t type) { - uint32_t color; + uint32_t color = LEDMatrix::Color24bit(0, 0, 0); switch(type) { case LED_TYPE_PADDLE: diff --git a/pong.h b/pong.h index e873e66..e5c226c 100644 --- a/pong.h +++ b/pong.h @@ -18,12 +18,12 @@ #include "ledmatrix.h" #include "udplogger.h" -#define DEBOUNCE_TIME 10 // in ms +#define DEBOUNCE_TIME_PONG 10 // in ms #define X_MAX 11 #define Y_MAX 11 -#define GAME_DELAY 80 // in ms +#define GAME_DELAY_PONG 80 // in ms #define BALL_DELAY_MAX 350 // in ms #define BALL_DELAY_MIN 50 // in ms #define BALL_DELAY_STEP 5 // in ms diff --git a/snake.cpp b/snake.cpp index bffe225..c8cb119 100644 --- a/snake.cpp +++ b/snake.cpp @@ -56,7 +56,7 @@ void Snake::loopCycle() * */ void Snake::ctrlUp(){ - if (millis() > _lastButtonClick + DEBOUNCE_TIME && _gameState == GAME_STATE_RUNNING) { + if (millis() > _lastButtonClick + DEBOUNCE_TIME_SNAKE && _gameState == GAME_STATE_RUNNING) { (*_logger).logString("Snake: UP"); _userDirection = DIRECTION_DOWN; // need to swap direction as field is rotated 180deg _lastButtonClick = millis(); @@ -68,7 +68,7 @@ void Snake::ctrlUp(){ * */ void Snake::ctrlDown(){ - if (millis() > _lastButtonClick + DEBOUNCE_TIME && _gameState == GAME_STATE_RUNNING) { + if (millis() > _lastButtonClick + DEBOUNCE_TIME_SNAKE && _gameState == GAME_STATE_RUNNING) { (*_logger).logString("Snake: DOWN"); _userDirection = DIRECTION_UP; // need to swap direction as field is rotated 180deg _lastButtonClick = millis(); @@ -80,7 +80,7 @@ void Snake::ctrlDown(){ * */ void Snake::ctrlRight(){ - if (millis() > _lastButtonClick + DEBOUNCE_TIME && _gameState == GAME_STATE_RUNNING) { + if (millis() > _lastButtonClick + DEBOUNCE_TIME_SNAKE && _gameState == GAME_STATE_RUNNING) { (*_logger).logString("Snake: RIGHT"); _userDirection = DIRECTION_LEFT; // need to swap direction as field is rotated 180deg _lastButtonClick = millis(); @@ -92,7 +92,7 @@ void Snake::ctrlRight(){ * */ void Snake::ctrlLeft(){ - if (millis() > _lastButtonClick + DEBOUNCE_TIME && _gameState == GAME_STATE_RUNNING) { + if (millis() > _lastButtonClick + DEBOUNCE_TIME_SNAKE && _gameState == GAME_STATE_RUNNING) { (*_logger).logString("Snake: LEFT"); _userDirection = DIRECTION_RIGHT; // need to swap direction as field is rotated 180deg _lastButtonClick = millis(); @@ -138,9 +138,9 @@ void Snake::initGame() */ void Snake::updateGame() { - if ((millis() - _lastDrawUpdate) > GAME_DELAY) { + if ((millis() - _lastDrawUpdate) > GAME_DELAY_SNAKE) { (*_logger).logString("Snake: update game"); - toggleLed(_tail[_wormLength-1].x, _tail[_wormLength-1].y, LED_TYPE_OFF); + toggleLed(_tail[_wormLength-1].x, _tail[_wormLength-1].y, LED_TYPE_EMPTY); switch(_userDirection) { case DIRECTION_RIGHT: if (_head.x > 0) { @@ -198,14 +198,14 @@ void Snake::endGame() */ void Snake::updateTail() { - for(int i=_wormLength-1; i>0; i--) { + for(unsigned int i=_wormLength-1; i>0; i--) { _tail[i].x = _tail[i-1].x; _tail[i].y = _tail[i-1].y; } _tail[0].x = _head.x; _tail[0].y = _head.y; - for(int i=0; i<_wormLength; i++) { + for(unsigned int i=0; i<_wormLength; i++) { if (_tail[i].x > -1) { toggleLed(_tail[i].x, _tail[i].y, LED_TYPE_SNAKE); } @@ -223,7 +223,7 @@ void Snake::updateFood() found = true; _food.x = random(0, X_MAX); _food.y = random(0, Y_MAX); - for(int i=0; i<_wormLength; i++) { + for(unsigned int i=0; i<_wormLength; i++) { if (_tail[i].x == _food.x && _tail[i].y == _food.y) { found = false; } @@ -246,7 +246,7 @@ bool Snake::isCollision() if (_head.y < 0 || _head.y >= Y_MAX) { return true; } - for(int i=1; i<_wormLength; i++) { + for(unsigned int i=1; i<_wormLength; i++) { if (_tail[i].x == _head.x && _tail[i].y == _head.y) { return true; } @@ -263,13 +263,13 @@ bool Snake::isCollision() */ void Snake::toggleLed(uint8_t x, uint8_t y, uint8_t type) { - uint32_t color; + uint32_t color = LEDMatrix::Color24bit(0, 0, 0); switch(type) { case LED_TYPE_SNAKE: color = LEDMatrix::Color24bit(0, 100, 100); break; - case LED_TYPE_OFF: + case LED_TYPE_EMPTY: color = LEDMatrix::Color24bit(0, 0, 0); break; case LED_TYPE_FOOD: diff --git a/snake.h b/snake.h index f5d6abf..f4619cb 100644 --- a/snake.h +++ b/snake.h @@ -17,15 +17,15 @@ #include "ledmatrix.h" #include "udplogger.h" -#define DEBOUNCE_TIME 300 // in ms +#define DEBOUNCE_TIME_SNAKE 300 // in ms #define X_MAX 11 #define Y_MAX 11 -#define GAME_DELAY 400 // in ms +#define GAME_DELAY_SNAKE 400 // in ms #define LED_TYPE_SNAKE 1 -#define LED_TYPE_OFF 2 +#define LED_TYPE_EMPTY 2 #define LED_TYPE_FOOD 3 #define LED_TYPE_BLOOD 4 diff --git a/tetris.cpp b/tetris.cpp index b605082..09fe84a 100644 --- a/tetris.cpp +++ b/tetris.cpp @@ -45,8 +45,8 @@ void Tetris::loopCycle(){ if (_activeBrick.enabled) { // move faster down when allow drop if (_allowdrop) { - if (millis() > _droptime + 50) { - _droptime = millis(); + if (millis() > _dropTime + 50) { + _dropTime = millis(); shiftActiveBrick(DIR_DOWN); printField(); } @@ -77,10 +77,10 @@ void Tetris::loopCycle(){ _tetrisGameOver = false; (*_logger).logString("Tetris: end"); everythingRed(); - _tetrisshowscore = millis(); + _tetrisshowscoreTime = millis(); } - if (millis() > (_tetrisshowscore + RED_END_TIME)) { + if (millis() > (_tetrisshowscoreTime + RED_END_TIME)) { resetLEDs(); _score = _nbRowsTotal; showscore(); @@ -95,7 +95,7 @@ void Tetris::loopCycle(){ * */ void Tetris::ctrlStart() { - if (millis() > _lastButtonClick + DEBOUNCE_TIME) + if (millis() > _lastButtonClick + DEBOUNCE_TIME_TETRIS) { _lastButtonClick = millis(); _gameStatet = GAME_STATE_INITt; @@ -107,7 +107,7 @@ void Tetris::ctrlStart() { * */ void Tetris::ctrlPlayPause() { - if (millis() > _lastButtonClick + DEBOUNCE_TIME) + if (millis() > _lastButtonClick + DEBOUNCE_TIME_TETRIS) { _lastButtonClick = millis(); if (_gameStatet == GAME_STATE_PAUSEDt) { @@ -128,7 +128,7 @@ void Tetris::ctrlPlayPause() { * */ void Tetris::ctrlRight() { - if (millis() > _lastButtonClick + DEBOUNCE_TIME && _gameStatet == GAME_STATE_RUNNINGt) + if (millis() > _lastButtonClick + DEBOUNCE_TIME_TETRIS && _gameStatet == GAME_STATE_RUNNINGt) { _lastButtonClick = millis(); shiftActiveBrick(DIR_RIGHT); @@ -141,7 +141,7 @@ void Tetris::ctrlRight() { * */ void Tetris::ctrlLeft() { - if (millis() > _lastButtonClick + DEBOUNCE_TIME && _gameStatet == GAME_STATE_RUNNINGt) + if (millis() > _lastButtonClick + DEBOUNCE_TIME_TETRIS && _gameStatet == GAME_STATE_RUNNINGt) { _lastButtonClick = millis(); shiftActiveBrick(DIR_LEFT); @@ -154,7 +154,7 @@ void Tetris::ctrlLeft() { * */ void Tetris::ctrlUp() { - if (millis() > _lastButtonClick + DEBOUNCE_TIME && _gameStatet == GAME_STATE_RUNNINGt) + if (millis() > _lastButtonClick + DEBOUNCE_TIME_TETRIS && _gameStatet == GAME_STATE_RUNNINGt) { _lastButtonClick = millis(); rotateActiveBrick(); @@ -168,7 +168,7 @@ void Tetris::ctrlUp() { */ void Tetris::ctrlDown() { // longer debounce time, to prevent immediate drop - if (millis() > _lastButtonClickr + DEBOUNCE_TIME*5 && _gameStatet == GAME_STATE_RUNNINGt) + if (millis() > _lastButtonClickr + DEBOUNCE_TIME_TETRIS*5 && _gameStatet == GAME_STATE_RUNNINGt) { _allowdrop = true; _lastButtonClickr = millis(); @@ -178,9 +178,10 @@ void Tetris::ctrlDown() { /** * @brief Set game speed * - * @param i new speed value + * @param i new speed value (0 - 15) */ -void Tetris::setSpeed(int32_t i) { +void Tetris::setSpeed(uint8_t i) { + if(i > 15) i = 15; (*_logger).logString("setSpeed: " + String(i)); _speedtetris = -10 * i + 150; } @@ -321,12 +322,11 @@ boolean Tetris::checkFieldCollision(struct Brick * brick) { boolean Tetris::checkSidesCollision(struct Brick * brick) { //Check vertical collision with sides of field uint8_t bx, by; - uint8_t fx, fy; + int8_t fx; for (by = 0; by < MAX_BRICK_SIZE; by++) { for (bx = 0; bx < MAX_BRICK_SIZE; bx++) { if ( (*brick).pix[bx][by] == 1) { fx = (*brick).xpos + bx;//Determine actual position in the field of the current pix of the brick - fy = (*brick).ypos + by; if (fx < 0 || fx >= WIDTH) { return true; } @@ -450,7 +450,7 @@ void Tetris::shiftActiveBrick(int dir) { */ void Tetris::addActiveBrickToField() { uint8_t bx, by; - uint8_t fx, fy; + int8_t fx, fy; for (by = 0; by < MAX_BRICK_SIZE; by++) { for (bx = 0; bx < MAX_BRICK_SIZE; bx++) { fx = _activeBrick.xpos + bx; diff --git a/tetris.h b/tetris.h index c06cef5..e5b372f 100644 --- a/tetris.h +++ b/tetris.h @@ -17,7 +17,7 @@ #include "ledmatrix.h" #include "udplogger.h" -#define DEBOUNCE_TIME 100 +#define DEBOUNCE_TIME_TETRIS 100 #define RED_END_TIME 1500 #define GAME_STATE_RUNNINGt 1 #define GAME_STATE_ENDt 2 @@ -90,7 +90,7 @@ class Tetris{ void ctrlLeft(); void ctrlUp(); void ctrlDown(); - void setSpeed(int32_t i); + void setSpeed(uint8_t i); void loopCycle(); @@ -119,21 +119,20 @@ class Tetris{ Brick _activeBrick; Field _field; - long _lastButtonClick = 0; - long _lastButtonClickr = 0; + unsigned long _lastButtonClick = 0; + unsigned long _lastButtonClickr = 0; int _score = 0; int _gameStatet = GAME_STATE_INITt; - uint16_t _brickSpeed; + unsigned int _brickSpeed; unsigned long _nbRowsThisLevel; unsigned long _nbRowsTotal; bool _tetrisGameOver; unsigned long _prevUpdateTime = 0; - - long _tetrisshowscore; - long _droptime = 0; - int _speedtetris = 80; + unsigned long _tetrisshowscoreTime = 0; + unsigned long _dropTime = 0; + unsigned int _speedtetris = 80; bool _allowdrop; // color library diff --git a/udplogger.h b/udplogger.h index 8ec9c3d..c26fa49 100644 --- a/udplogger.h +++ b/udplogger.h @@ -31,7 +31,7 @@ class UDPLogger{ int _port; WiFiUDP _Udp; char _packetBuffer[100]; - long _lastSend; + unsigned long _lastSend; }; #endif \ No newline at end of file diff --git a/wordclock_esp8266.ino b/wordclock_esp8266.ino index a2fc0c2..00472e9 100644 --- a/wordclock_esp8266.ino +++ b/wordclock_esp8266.ino @@ -998,7 +998,6 @@ void handleCommand() { */ String split(String s, char parser, int index) { String rs=""; - int parserIndex = index; int parserCnt=0; int rFromIndex=0, rToIndex=-1; while (index >= parserCnt) { diff --git a/wordclockfunctions.ino b/wordclockfunctions.ino index 829ddab..ecbdc6e 100644 --- a/wordclockfunctions.ino +++ b/wordclockfunctions.ino @@ -42,11 +42,9 @@ void drawMinuteIndicator(uint8_t minutes, uint32_t color){ * @return int: 0 if successful, -1 if sentence not possible to display */ int showStringOnClock(String message, uint32_t color){ - int messageStart = 0; String word = ""; int lastLetterClock = 0; int positionOfWord = 0; - int nextSpace = 0; int index = 0; // add space on the end of message for splitting @@ -66,7 +64,7 @@ int showStringOnClock(String message, uint32_t color){ if(positionOfWord >= 0){ // word found on clock -> enable leds in targetgrid - for(int i = 0; i < word.length(); i++){ + for(unsigned int i = 0; i < word.length(); i++){ int x = (positionOfWord + i)%WIDTH; int y = (positionOfWord + i)/WIDTH; ledmatrix.gridAddPixel(x, y, color); @@ -79,7 +77,6 @@ int showStringOnClock(String message, uint32_t color){ logger.logString("word is not possible to show on clock: " + String(word)); return -1; } - //logger.logString(String(nextSpace) + " - " + String()); }else{ // end - no more word in message break; diff --git a/wordclockfunctions.ino_english b/wordclockfunctions.ino_english index f76c3a8..0153b68 100644 --- a/wordclockfunctions.ino_english +++ b/wordclockfunctions.ino_english @@ -41,11 +41,9 @@ void drawMinuteIndicator(uint8_t minutes, uint32_t color) { * @return int: 0 if successful, -1 if sentence not possible to display */ int showStringOnClock(String message, uint32_t color) { - int messageStart = 0; String word = ""; int lastLetterClock = 0; int positionOfWord = 0; - int nextSpace = 0; int index = 0; // add space on the end of message for splitting @@ -65,7 +63,7 @@ int showStringOnClock(String message, uint32_t color) { if (positionOfWord >= 0) { // word found on clock -> enable leds in targetgrid - for (int i = 0; i < word.length(); i++) { + for (unsigned int i = 0; i < word.length(); i++) { int x = (positionOfWord + i) % WIDTH; int y = (positionOfWord + i) / WIDTH; ledmatrix.gridAddPixel(x, y, color); @@ -77,7 +75,6 @@ int showStringOnClock(String message, uint32_t color) { logger.logString("word is not possible to show on clock: " + String(word)); return -1; } - //logger.logString(String(nextSpace) + " - " + String()); } else { // end - no more word in message break; diff --git a/wordclockfunctions.ino_italian b/wordclockfunctions.ino_italian index f3b2a56..a1f0f47 100644 --- a/wordclockfunctions.ino_italian +++ b/wordclockfunctions.ino_italian @@ -42,11 +42,9 @@ void drawMinuteIndicator(uint8_t minutes, uint32_t color){ * @return int: 0 if successful, -1 if sentence not possible to display */ int showStringOnClock(String message, uint32_t color){ - int messageStart = 0; String word = ""; int lastLetterClock = 0; int positionOfWord = 0; - int nextSpace = 0; int index = 0; // add space on the end of message for splitting @@ -66,7 +64,7 @@ int showStringOnClock(String message, uint32_t color){ if(positionOfWord >= 0){ // word found on clock -> enable leds in targetgrid - for(int i = 0; i < word.length(); i++){ + for(unsigned int i = 0; i < word.length(); i++){ int x = (positionOfWord + i)%WIDTH; int y = (positionOfWord + i)/WIDTH; ledmatrix.gridAddPixel(x, y, color); @@ -79,7 +77,6 @@ int showStringOnClock(String message, uint32_t color){ logger.logString("word is not possible to show on clock: " + String(word)); return -1; } - //logger.logString(String(nextSpace) + " - " + String()); }else{ // end - no more word in message break;