Finished Lab 4 Pt 1
Dependencies: mbed Sounds PinDetect
Revision 0:daf9e2f8e1a1, committed 2019-04-05
- Comitter:
- trmontgomery
- Date:
- Fri Apr 05 19:46:26 2019 +0000
- Commit message:
- Finished Lab 4 pt 1
Changed in this revision
diff -r 000000000000 -r daf9e2f8e1a1 Buzzy.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Buzzy.cpp Fri Apr 05 19:46:26 2019 +0000 @@ -0,0 +1,185 @@ +#include "Buzzy.h" +#include "Ghosts.h" +#include "BuzzyGraphics.h" +#include "uLCD_4DGL.h" +#include "Speaker.h" + +extern char gDynaMaze[MAZE_NUM_ROW][MAZE_NUM_COL]; +extern Ghosts gGhosts[NUM_GHOSTS]; +extern Buzzy gBuzzy; +extern uLCD_4DGL guLCD; +extern Speaker gSpeakerOut; +extern DigitalOut myled1; + + + +///////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////// +// Constructor +Buzzy::Buzzy(enDIRECTIONS inDir, unsigned int inRow, unsigned int inCol): +Sprite(inDir, inRow, inCol) +{ + m_CurrentDirection = RIGHT_DIR; +} +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// +void Buzzy::Move() +{ + + if (m_DesiredDirection == NO_DIR) + { + // Nothing to do + // Switch over to the siren sound + gSpeakerOut.SwitchSound(Speaker::SIREN); + return; + } + + //Try to move Buzzy in desired direction + switch(m_DesiredDirection){ + + case UP_DIR: { + if (IsMoveAllowed(m_RowPos+1, m_ColPos)) { + m_CurrentDirection = UP_DIR; + } else { + //m_CurrentDirection = NO_DIR; + } + break; + } + + case DOWN_DIR: { + if (IsMoveAllowed(m_RowPos-1, m_ColPos)) { + m_CurrentDirection = DOWN_DIR; + }else { + //m_CurrentDirection = NO_DIR; + } + break; + } + + case LEFT_DIR: { + if (IsMoveAllowed(m_RowPos, m_ColPos-1)) { + m_CurrentDirection = LEFT_DIR; + }else { + // m_CurrentDirection = NO_DIR; + } + break; + } + + case RIGHT_DIR: { + if (IsMoveAllowed(m_RowPos, m_ColPos+1)) { + m_CurrentDirection = RIGHT_DIR; + }else { + //m_CurrentDirection = NO_DIR; + } + break; + } + } + + //if you can't move in the desired direction keep going in the current direction + switch(m_CurrentDirection){ + case UP_DIR:{ + if (IsMoveAllowed(m_RowPos+1, m_ColPos)){ + gBuzzy.DrawInNewLocation(m_RowPos+1, m_ColPos); + } + break; + } + case DOWN_DIR:{ + if (IsMoveAllowed(m_RowPos-1, m_ColPos)){ + gBuzzy.DrawInNewLocation(m_RowPos-1, m_ColPos); + } + break; + } + case LEFT_DIR:{ + if (IsMoveAllowed(m_RowPos, m_ColPos-1)){ + gBuzzy.DrawInNewLocation(m_RowPos, m_ColPos-1); + } + break; + } + case RIGHT_DIR:{ + if (IsMoveAllowed(m_RowPos, m_ColPos+1)){ + gBuzzy.DrawInNewLocation(m_RowPos, m_ColPos+1); + } + break; + } + } + +} +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// +void Buzzy::DrawInNewLocation(const int &nRow,const int &nCol) +{ + int x1, y1; + // Test if we hit a honeydrop or fruit or ghost + if (gDynaMaze[nRow][nCol] == HONEYDROP_SQUARE){ + gBuzzy.honey++; + gSpeakerOut.SwitchSound(Speaker::CHOMP); + myled1 = !myled1; + } else { + gSpeakerOut.SwitchSound(Speaker::SIREN); + myled1 = !myled1; + } + + x1 = (3*m_RowPos+1)-4; + y1 = (3*m_ColPos+1)-4; + guLCD.BLIT(x1, y1, 9, 9, &BuzzyIcon[2][0][0]); + + + //update the dynamic maze + gDynaMaze[m_RowPos][m_ColPos] = 0; + gDynaMaze[nRow][nCol] = 5; + + //draw Buzzy in new location + x1 = (3*nRow+1)-4; + y1 = (3*nCol+1)-4; + guLCD.BLIT(x1, y1, 9, 9, &BuzzyIcon[GetImageIndex()][0][0]); + + //update Buzzy's location + gBuzzy.SetLocation(nRow, nCol); +} +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// +bool Buzzy::DidGhostGetBuzzy() +{ + + return false; +} +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// +bool Buzzy::IsMoveAllowed(const int &nNewRow, const int &nNewCol) +{ + bool a,b,c; + + switch(m_DesiredDirection){ + case UP_DIR: { + a = gCnstMaze[nNewRow+1][nNewCol-1] != 1; + b = gCnstMaze[nNewRow+1][nNewCol] != 1; + c = gCnstMaze[nNewRow+1][nNewCol+1] != 1; + break; + } + case DOWN_DIR: { + a = gCnstMaze[nNewRow-1][nNewCol-1] != 1; + b = gCnstMaze[nNewRow-1][nNewCol] != 1; + c = gCnstMaze[nNewRow-1][nNewCol+1] != 1; + break; + } + case LEFT_DIR: { + a = gCnstMaze[nNewRow-1][nNewCol-1] != 1; + b = gCnstMaze[nNewRow][nNewCol-1] != 1; + c = gCnstMaze[nNewRow+1][nNewCol-1] != 1; + break; + } + case RIGHT_DIR: { + a = gCnstMaze[nNewRow-1][nNewCol+1] != 1; + b = gCnstMaze[nNewRow][nNewCol+1] != 1; + c = gCnstMaze[nNewRow+1][nNewCol+1] != 1; + break; + } + } + + return a && b && c; + +}
diff -r 000000000000 -r daf9e2f8e1a1 Buzzy.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Buzzy.h Fri Apr 05 19:46:26 2019 +0000 @@ -0,0 +1,20 @@ +#pragma once + +#include "Sprite.h" + +class Buzzy : public Sprite +{ + public: + Buzzy(){m_CurrentDirection = m_DesiredDirection = Sprite::LEFT_DIR;m_nActiveImage=0;}; + // Constructor + Buzzy(enDIRECTIONS inDir, unsigned int inRow, unsigned int inCol); + + virtual ~Buzzy(){}; + virtual void Move(); + virtual bool IsMoveAllowed(const int &nNewRow, const int &nNewCol); + + void DrawInNewLocation(const int &nRow,const int &nCol); + bool DidGhostGetBuzzy(); + int honey; + +};
diff -r 000000000000 -r daf9e2f8e1a1 DrawMaze.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DrawMaze.cpp Fri Apr 05 19:46:26 2019 +0000 @@ -0,0 +1,54 @@ +#include "uLCD_4DGL.h" +#include "BuzzyGraphics.h" +#include "Buzzy.h" + +extern uLCD_4DGL guLCD; +extern char gDynaMaze[MAZE_NUM_ROW][MAZE_NUM_COL]; +extern Buzzy gBuzzy; +///////////////////////////////////////////////////////////////////// +// The maze is a scaled down version of the LCD display +// Each element in the maze is really a 3x3 segment of the LCD +// This must be taken into account when drawing the maze on the LCD + + +// Draw a wall tile when +void DrawMazeWall(int const &x1, int const &y1) +{ + int ii = 3*x1+1; + int jj = 3*y1+1; + guLCD.filled_rectangle(ii-1, jj-1, ii+1, jj+1, _BLUE); +} +/* +////////////////////////////////////////////////////////////////////// +Use the following #defines to determine which icon to draw in the LCD +#define BLUE_SQUARE 1 +#define HONEYDROP_SQUARE 2 +#define PWRUP_SQUARE 3 +#define GHOST_ICON 4 +#define BUZZY_ICON 5 +#define TRAP_LINE 6 + +When drawing the ghosts draw one of each color +*/ +void DrawMaze() +{ + + for (int ii = 0 ; ii < MAZE_NUM_ROW ; ii++) + { + for (int jj = 0 ; jj < MAZE_NUM_COL ; jj++) + { + if (gDynaMaze[ii][jj] == HONEYDROP_SQUARE){ + guLCD.BLIT(ii*3, jj*3, 3, 3, &HoneyDropIcon[0][0]); + } else if (gDynaMaze[ii][jj] == BLUE_SQUARE){ + DrawMazeWall(ii, jj); + } else if (gDynaMaze[ii][jj] == PWRUP_SQUARE){ + guLCD.BLIT((ii*3+1)-4, (jj*3+1)-4, 9, 9, &PowerUpIcon[0][0]); + } else if (gDynaMaze[ii][jj] == GHOST_ICON){ + guLCD.BLIT((ii*3)-4, (jj*3)-4, 9, 9, &VioletGhost[0][0][0]); + } else if (gDynaMaze[ii][jj] == BUZZY_ICON){ + guLCD.BLIT((3*ii+1)-4, (3*jj+1)-4, 9, 9, &BuzzyIcon[0][0][0]); + gBuzzy.SetLocation(ii,jj); + } + } + } +} \ No newline at end of file
diff -r 000000000000 -r daf9e2f8e1a1 Ghosts.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Ghosts.cpp Fri Apr 05 19:46:26 2019 +0000 @@ -0,0 +1,7 @@ +#include "Ghosts.h" +///////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////// +void Ghosts::Move() +{ +}
diff -r 000000000000 -r daf9e2f8e1a1 Ghosts.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Ghosts.h Fri Apr 05 19:46:26 2019 +0000 @@ -0,0 +1,10 @@ +#pragma once + +#include "Sprite.h" + +class Ghosts : public Sprite +{ + public: + virtual void Move(); + virtual bool IsMoveAllowed(const int &nNewRow, const int &nNewCol){return true;} +};
diff -r 000000000000 -r daf9e2f8e1a1 LCDGraphics/BuzzyGraphics.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LCDGraphics/BuzzyGraphics.h Fri Apr 05 19:46:26 2019 +0000 @@ -0,0 +1,281 @@ +#pragma once + +#define WHITE 0xFFFFFF +#define BLACK 0x000000 +#define _RED_ 0xFF0000 +#define GREEN 0x00FF00 +#define _BLUE 0x0000FF +#define LGREY 0xBFBFBF +#define DGREY 0x5F5F5F + +#define YELLW 0xFFFF00 +#define LBLUE 0x00FFFF +#define _PINK 0xFF80FF +#define VIOLT 0x8080FF +#define LGREN 0x80FF00 +#define LPECH 0xF78D4C +#define DPECH 0xC96830 +#define RPECH 0xF25427 + +/////////////////////////////// +/////////////////////////////// +// Tiles +const int TrapLine[9][9] = +{ + {BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK}, + {BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK}, + {BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK}, + {BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK}, + {_PINK, _PINK, _PINK, _PINK, _PINK, _PINK, _PINK, _PINK, _PINK}, + {_PINK, _PINK, _PINK, _PINK, _PINK, _PINK, _PINK, _PINK, _PINK}, + {BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK}, + {BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK}, + {BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK} +}; +const int FruitIcon[9][9] = +{ + {BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK}, + {BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK}, + {BLACK, BLACK, BLACK, YELLW, YELLW, BLACK, BLACK, BLACK, BLACK}, + {BLACK, BLACK, YELLW, YELLW, YELLW, YELLW, YELLW, BLACK, BLACK}, + {BLACK, BLACK, YELLW, YELLW, YELLW, YELLW, YELLW, BLACK, BLACK}, + {BLACK, BLACK, YELLW, YELLW, YELLW, YELLW, YELLW, BLACK, BLACK}, + {BLACK, BLACK, BLACK, YELLW, YELLW, YELLW, BLACK, BLACK, BLACK}, + {BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK}, + {BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK} +}; +const int PowerUpIcon[9][9] = +{ + {BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK}, + {BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK}, + {BLACK, BLACK, BLACK, _RED_, _RED_, BLACK, BLACK, BLACK, BLACK}, + {BLACK, BLACK, _RED_, _RED_, _RED_, _RED_, _RED_, BLACK, BLACK}, + {BLACK, BLACK, _RED_, _RED_, _RED_, _RED_, _RED_, BLACK, BLACK}, + {BLACK, BLACK, _RED_, _RED_, _RED_, _RED_, _RED_, BLACK, BLACK}, + {BLACK, BLACK, BLACK, _RED_, _RED_, _RED_, BLACK, BLACK, BLACK}, + {BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK}, + {BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK} +}; +const int HoneyDropIcon[3][3] = +{ + {BLACK, YELLW, BLACK}, + {YELLW, YELLW, YELLW}, + {BLACK, YELLW, BLACK} +}; +/////////////////////////////// +/////////////////////////////// +// PacMan +const int BuzzyIcon[3][9][9] = +{ +{ + {BLACK, BLACK, BLACK, YELLW, YELLW, YELLW, BLACK, BLACK, BLACK}, + {BLACK, YELLW, YELLW, YELLW, YELLW, YELLW, YELLW, YELLW, BLACK}, + {BLACK, YELLW, YELLW, YELLW, YELLW, BLACK, YELLW, YELLW, BLACK}, + {YELLW, YELLW, YELLW, YELLW, YELLW, YELLW, YELLW, YELLW, YELLW}, + {YELLW, YELLW, YELLW, YELLW, YELLW, YELLW, YELLW, YELLW, YELLW}, + {YELLW, YELLW, YELLW, YELLW, YELLW, YELLW, YELLW, YELLW, YELLW}, + {BLACK, YELLW, YELLW, YELLW, YELLW, YELLW, YELLW, YELLW, BLACK}, + {BLACK, YELLW, YELLW, YELLW, YELLW, YELLW, YELLW, YELLW, BLACK}, + {BLACK, BLACK, BLACK, YELLW, YELLW, YELLW, BLACK, BLACK, BLACK} +}, +{ + {BLACK, BLACK, BLACK, YELLW, YELLW, YELLW, BLACK, BLACK, BLACK}, + {BLACK, YELLW, YELLW, YELLW, YELLW, YELLW, YELLW, YELLW, BLACK}, + {BLACK, YELLW, YELLW, YELLW, YELLW, BLACK, YELLW, YELLW, BLACK}, + {YELLW, YELLW, YELLW, YELLW, YELLW, YELLW, YELLW, BLACK, BLACK}, + {YELLW, YELLW, YELLW, YELLW, YELLW, YELLW, YELLW, BLACK, BLACK}, + {YELLW, YELLW, YELLW, YELLW, YELLW, YELLW, YELLW, BLACK, BLACK}, + {BLACK, YELLW, YELLW, YELLW, YELLW, YELLW, YELLW, YELLW, BLACK}, + {BLACK, YELLW, YELLW, YELLW, YELLW, YELLW, YELLW, YELLW, BLACK}, + {BLACK, BLACK, BLACK, YELLW, YELLW, YELLW, BLACK, BLACK, BLACK} +}, +{ + {BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK}, + {BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK}, + {BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK}, + {BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK}, + {BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK}, + {BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK}, + {BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK}, + {BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK}, + {BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK} +} + +}; + +/////////////////////////////// +/////////////////////////////// +// Ghosts +const int VioletGhost[2][9][9] = +{ +{ + {BLACK, BLACK, BLACK, VIOLT, VIOLT, VIOLT, BLACK, BLACK, BLACK}, + {BLACK, VIOLT, VIOLT, VIOLT, VIOLT, VIOLT, VIOLT, VIOLT, BLACK}, + {BLACK, VIOLT, WHITE, BLACK, VIOLT, WHITE, BLACK, VIOLT, BLACK}, + {BLACK, VIOLT, WHITE, WHITE, VIOLT, WHITE, WHITE, VIOLT, BLACK}, + {BLACK, VIOLT, VIOLT, VIOLT, VIOLT, VIOLT, VIOLT, VIOLT, VIOLT}, + {VIOLT, VIOLT, VIOLT, VIOLT, VIOLT, VIOLT, VIOLT, VIOLT, VIOLT}, + {VIOLT, VIOLT, VIOLT, VIOLT, VIOLT, VIOLT, VIOLT, VIOLT, VIOLT}, + {VIOLT, VIOLT, BLACK, VIOLT, VIOLT, VIOLT, BLACK, VIOLT, VIOLT}, + {VIOLT, BLACK, BLACK, BLACK, VIOLT, BLACK, BLACK, BLACK, VIOLT} +}, +{ + {BLACK, BLACK, BLACK, VIOLT, VIOLT, VIOLT, BLACK, BLACK, BLACK}, + {BLACK, VIOLT, VIOLT, VIOLT, VIOLT, VIOLT, VIOLT, VIOLT, BLACK}, + {BLACK, VIOLT, BLACK, WHITE, VIOLT, BLACK, WHITE, VIOLT, BLACK}, + {BLACK, VIOLT, WHITE, WHITE, VIOLT, WHITE, WHITE, VIOLT, VIOLT}, + {BLACK, VIOLT, VIOLT, VIOLT, VIOLT, VIOLT, VIOLT, VIOLT, VIOLT}, + {VIOLT, VIOLT, VIOLT, VIOLT, VIOLT, VIOLT, VIOLT, VIOLT, VIOLT}, + {VIOLT, VIOLT, VIOLT, VIOLT, VIOLT, VIOLT, VIOLT, VIOLT, VIOLT}, + {VIOLT, VIOLT, VIOLT, VIOLT, VIOLT, VIOLT, VIOLT, VIOLT, VIOLT}, + {VIOLT, BLACK, BLACK, BLACK, VIOLT, BLACK, BLACK, BLACK, VIOLT} +}, + +}; +const int BlueGhost[2][9][9] = +{ +{ + {BLACK, BLACK, BLACK, LBLUE, LBLUE, LBLUE, BLACK, BLACK, BLACK}, + {BLACK, LBLUE, LBLUE, LBLUE, LBLUE, LBLUE, LBLUE, LBLUE, BLACK}, + {BLACK, LBLUE, WHITE, BLACK, LBLUE, WHITE, BLACK, LBLUE, BLACK}, + {BLACK, LBLUE, WHITE, WHITE, LBLUE, WHITE, WHITE, LBLUE, BLACK}, + {BLACK, LBLUE, LBLUE, LBLUE, LBLUE, LBLUE, LBLUE, LBLUE, LBLUE}, + {LBLUE, LBLUE, LBLUE, LBLUE, LBLUE, LBLUE, LBLUE, LBLUE, LBLUE}, + {LBLUE, LBLUE, LBLUE, LBLUE, LBLUE, LBLUE, LBLUE, LBLUE, LBLUE}, + {LBLUE, LBLUE, BLACK, LBLUE, LBLUE, LBLUE, BLACK, LBLUE, LBLUE}, + {LBLUE, BLACK, BLACK, BLACK, LBLUE, BLACK, BLACK, BLACK, LBLUE} +}, +{ + {BLACK, BLACK, BLACK, LBLUE, LBLUE, LBLUE, BLACK, BLACK, BLACK}, + {BLACK, LBLUE, LBLUE, LBLUE, LBLUE, LBLUE, LBLUE, LBLUE, BLACK}, + {BLACK, LBLUE, BLACK, WHITE, LBLUE, BLACK, WHITE, LBLUE, BLACK}, + {BLACK, LBLUE, WHITE, WHITE, LBLUE, WHITE, WHITE, LBLUE, LBLUE}, + {BLACK, LBLUE, LBLUE, LBLUE, LBLUE, LBLUE, LBLUE, LBLUE, LBLUE}, + {LBLUE, LBLUE, LBLUE, LBLUE, LBLUE, LBLUE, LBLUE, LBLUE, LBLUE}, + {LBLUE, LBLUE, LBLUE, LBLUE, LBLUE, LBLUE, LBLUE, LBLUE, LBLUE}, + {LBLUE, LBLUE, LBLUE, LBLUE, LBLUE, LBLUE, LBLUE, LBLUE, LBLUE}, + {LBLUE, BLACK, BLACK, BLACK, LBLUE, BLACK, BLACK, BLACK, LBLUE} +}, + +}; +const int PinkGhost[2][9][9] = +{ +{ + {BLACK, BLACK, BLACK, _PINK, _PINK, _PINK, BLACK, BLACK, BLACK}, + {BLACK, _PINK, _PINK, _PINK, _PINK, _PINK, _PINK, _PINK, BLACK}, + {BLACK, _PINK, WHITE, BLACK, _PINK, WHITE, BLACK, _PINK, BLACK}, + {BLACK, _PINK, WHITE, WHITE, _PINK, WHITE, WHITE, _PINK, BLACK}, + {BLACK, _PINK, _PINK, _PINK, _PINK, _PINK, _PINK, _PINK, _PINK}, + {_PINK, _PINK, _PINK, _PINK, _PINK, _PINK, _PINK, _PINK, _PINK}, + {_PINK, _PINK, _PINK, _PINK, _PINK, _PINK, _PINK, _PINK, _PINK}, + {_PINK, _PINK, BLACK, _PINK, _PINK, _PINK, BLACK, _PINK, _PINK}, + {_PINK, BLACK, BLACK, BLACK, _PINK, BLACK, BLACK, BLACK, _PINK} +}, +{ + {BLACK, BLACK, BLACK, _PINK, _PINK, _PINK, BLACK, BLACK, BLACK}, + {BLACK, _PINK, _PINK, _PINK, _PINK, _PINK, _PINK, _PINK, BLACK}, + {BLACK, _PINK, BLACK, WHITE, _PINK, BLACK, WHITE, _PINK, BLACK}, + {BLACK, _PINK, WHITE, WHITE, _PINK, WHITE, WHITE, _PINK, _PINK}, + {BLACK, _PINK, _PINK, _PINK, _PINK, _PINK, _PINK, _PINK, _PINK}, + {_PINK, _PINK, _PINK, _PINK, _PINK, _PINK, _PINK, _PINK, _PINK}, + {_PINK, _PINK, _PINK, _PINK, _PINK, _PINK, _PINK, _PINK, _PINK}, + {_PINK, _PINK, _PINK, _PINK, _PINK, _PINK, _PINK, _PINK, _PINK}, + {_PINK, BLACK, BLACK, BLACK, _PINK, BLACK, BLACK, BLACK, _PINK} +}, + +}; +const int GreenGhost[2][9][9] = +{ +{ + {BLACK, BLACK, BLACK, LGREN, LGREN, LGREN, BLACK, BLACK, BLACK}, + {BLACK, LGREN, LGREN, LGREN, LGREN, LGREN, LGREN, LGREN, BLACK}, + {BLACK, LGREN, WHITE, BLACK, LGREN, WHITE, BLACK, LGREN, BLACK}, + {BLACK, LGREN, WHITE, WHITE, LGREN, WHITE, WHITE, LGREN, BLACK}, + {BLACK, LGREN, LGREN, LGREN, LGREN, LGREN, LGREN, LGREN, LGREN}, + {LGREN, LGREN, LGREN, LGREN, LGREN, LGREN, LGREN, LGREN, LGREN}, + {LGREN, LGREN, LGREN, LGREN, LGREN, LGREN, LGREN, LGREN, LGREN}, + {LGREN, LGREN, BLACK, LGREN, LGREN, LGREN, BLACK, LGREN, LGREN}, + {LGREN, BLACK, BLACK, BLACK, LGREN, BLACK, BLACK, BLACK, LGREN} +}, +{ + {BLACK, BLACK, BLACK, LGREN, LGREN, LGREN, BLACK, BLACK, BLACK}, + {BLACK, LGREN, LGREN, LGREN, LGREN, LGREN, LGREN, LGREN, BLACK}, + {BLACK, LGREN, BLACK, WHITE, LGREN, BLACK, WHITE, LGREN, BLACK}, + {BLACK, LGREN, WHITE, WHITE, LGREN, WHITE, WHITE, LGREN, LGREN}, + {BLACK, LGREN, LGREN, LGREN, LGREN, LGREN, LGREN, LGREN, LGREN}, + {LGREN, LGREN, LGREN, LGREN, LGREN, LGREN, LGREN, LGREN, LGREN}, + {LGREN, LGREN, LGREN, LGREN, LGREN, LGREN, LGREN, LGREN, LGREN}, + {LGREN, LGREN, LGREN, LGREN, LGREN, LGREN, LGREN, LGREN, LGREN}, + {LGREN, BLACK, BLACK, BLACK, LGREN, BLACK, BLACK, BLACK, LGREN} +}, + +}; +#define MAZE_NUM_ROW 40 +#define MAZE_NUM_COL 42 +#define MAZE_SCALE 3 + +#define GAME_PAUSED 0 +#define GAME_RUNNING 1 +#define GAME_OVER 2 +#define NUM_GHOSTS 4 +#define NUM_ALL_SPRITES (NUM_GHOSTS + 1) + + +#define BLUE_SQUARE 1 +#define HONEYDROP_SQUARE 2 +#define PWRUP_SQUARE 3 +#define GHOST_ICON 4 +#define BUZZY_ICON 5 +#define TRAP_LINE 6 + +/////////////////////////////// +/////////////////////////////// +// Maze +// The maze is a scaled down version of the LCD display +// Each element in the maze is really a 3x3 segment of the LCD +// This must be taken into account when drawing the maze +const char gCnstMaze[MAZE_NUM_ROW][MAZE_NUM_COL] = +{ +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, +1,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,1,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,0,2,0,1, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, +1,0,2,0,1,1,1,1,1,0,0,0,1,1,1,1,1,0,2,0,0,0,0,0,1,1,1,1,1,1,0,0,0,1,1,1,1,1,0,2,0,1, +1,0,0,0,1,1,1,1,1,0,2,0,1,1,1,1,1,0,0,0,2,0,2,0,1,1,1,1,1,1,0,2,0,1,1,1,1,1,0,0,0,1, +1,0,3,0,1,1,1,1,1,0,0,0,1,1,1,1,1,0,2,0,0,0,0,0,1,1,1,1,1,1,0,0,0,1,1,1,1,1,0,3,0,1, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, +1,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,1,0,2,0,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,1, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, +1,0,2,0,1,1,1,1,1,0,2,0,1,1,1,1,1,0,2,0,1,0,2,0,1,1,1,1,1,1,0,2,0,1,1,1,1,1,0,2,0,1, +1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,1,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1, +1,0,2,0,2,0,2,0,2,0,2,0,1,1,1,1,1,0,2,0,1,0,2,0,1,1,1,1,1,1,0,2,0,2,0,2,0,2,0,2,0,1, +1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,1,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1, +1,1,1,1,1,1,1,1,1,0,2,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,2,0,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,0,0,0,1,0,2,0,2,0,2,0,4,0,2,0,2,0,2,0,1,1,0,0,0,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,0,2,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,2,0,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,0,0,0,1,0,2,0,1,1,1,6,6,6,1,1,1,0,2,0,1,1,0,0,0,1,1,1,1,1,1,1,1,1, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,1,0,0,0,0,0,0,0,1,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,4,0,4,0,4,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,1,1,1,1,1,1,1,1,0,0,0,1,0,2,0,1,0,0,0,0,0,0,0,1,0,0,0,1,1,0,2,0,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,0,2,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0,2,0,1,1,0,0,0,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,0,0,0,1,0,2,0,1,1,1,1,1,1,1,1,1,0,0,0,1,1,0,2,0,1,1,1,1,1,1,1,1,1, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, +1,0,2,0,2,0,2,0,2,0,2,0,0,0,2,0,2,0,2,0,5,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,0,2,0,1, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, +1,0,3,0,1,1,1,1,1,0,2,0,1,1,1,1,1,0,0,0,1,1,0,2,0,1,1,1,1,1,0,2,0,1,1,1,1,1,0,2,0,1, +1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,2,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,1, +1,0,2,0,2,0,2,0,1,0,2,0,2,0,2,0,1,0,0,0,1,1,0,2,0,2,0,2,0,1,0,2,0,2,0,2,0,1,0,3,0,1, +1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,2,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,1, +1,1,1,1,1,0,2,0,1,0,2,0,1,0,2,0,1,0,0,0,1,1,1,1,1,1,0,0,0,1,0,2,0,1,0,2,0,1,0,2,0,1, +1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1, +1,0,2,0,2,0,2,0,2,0,2,0,1,0,2,0,2,0,2,0,1,1,0,2,0,2,0,2,0,2,0,2,0,1,0,2,0,2,0,2,0,1, +1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1, +1,0,2,0,1,1,1,1,1,1,1,1,1,1,1,1,0,2,0,1,1,1,0,2,0,1,1,1,1,1,1,1,1,1,1,1,1,0,2,0,1,1, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1, +1,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,0,3,0,2,0,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,1,1, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 +}; + +
diff -r 000000000000 -r daf9e2f8e1a1 LCDGraphics/uLCD_4DGL.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LCDGraphics/uLCD_4DGL.h Fri Apr 05 19:46:26 2019 +0000 @@ -0,0 +1,348 @@ +// +// uLCD_4DGL is a class to drive 4D Systems TFT touch screens +// +// Fork of 4DGL library for 4D Systems LCD displays +// Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr> +// Modifed for Goldelox processor <2013> Jim Hamblen +// +// uLCD_4DGL is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// uLCD_4DGL is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with uLCD_4DGL. If not, see <http://www.gnu.org/licenses/>. + +// @author Stephane Rochon + +#include "mbed.h" +#ifndef _uLCD +#define _uLCD 0 +// Debug Verbose off - SGE commands echoed to USB serial for debugmode=1 +#ifndef DEBUGMODE +#define DEBUGMODE 0 +#endif + +// Common WAIT value in milliseconds between commands +#define TEMPO 0 + +// 4DGL SGE Function values for Goldelox Processor +#define CLS '\xD7' +#define BAUDRATE '\x0B' //null prefix +#define VERSION '\x08' //null prefix +#define BCKGDCOLOR '\x6E' +#define TXTBCKGDCOLOR '\x7E' +#define DISPCONTROL '\x68' +#define SETVOLUME '\x76' +#define CIRCLE '\xCD' +#define FCIRCLE '\xCC' +#define TRIANGLE '\xC9' +#define LINE '\xD2' +#define FRECTANGLE '\xCE' +#define RECTANGLE '\xCF' +#define ELLIPSE '\x65' //na +#define PIXEL '\xCB' +#define READPIXEL '\xCA' +#define SCREENCOPY '\x63' //na? +#define PENSIZE '\xD8' +#define SETFONT '\x7D' +#define TEXTMODE '\x77' +#define TEXTBOLD '\x76' +#define TEXTITALIC '\x75' +#define TEXTINVERSE '\x74' +#define TEXTUNDERLINE '\x73' +#define TEXTWIDTH '\x7C' +#define TEXTHEIGHT '\x7B' +#define TEXTCHAR '\xFE' +#define TEXTSTRING '\x06' //null prefix +#define MOVECURSOR '\xE4' +#define BLITCOM '\x0A' +#define PUTCHAR '\xFE' +#define DISPPOWER '\x66' +//media commands for uSD card +#define MINIT '\xB1' +#define SBADDRESS '\xB9' +#define SSADDRESS '\xB8' +#define READBYTE '\xB7' +#define READWORD '\xB6' +#define WRITEBYTE '\xB5' +#define WRITEWORD '\xB4' +#define FLUSHMEDIA '\xB2' +#define DISPLAYIMAGE '\xB3' +#define DISPLAYVIDEO '\xBB' +#define DISPLAYFRAME '\xBA' + + + +// Screen answers +#define ACK '\x06' +#define NAK '\x15' + + + +// Screen states +#define OFF '\x00' +#define ON '\x01' + +// Graphics modes +#define SOLID '\x00' +#define WIREFRAME '\x01' + +// Text modes +#define TRANSPARENT '\x00' +#define OPAQUE '\x01' + +// Fonts Sizes +#define FONT_7X8 '\x00' //only builtin font +#define FONT_5X7 '\x04' +#define FONT_8X8 '\x01' +#define FONT_8X12 '\x02' +#define FONT_12X16 '\x03' +#define MEDIAFONT '\x07' + + +// Data speed +#define BAUD_110 27271 +#define BAUD_300 9999 +#define BAUD_600 4999 +#define BAUD_1200 2499 +#define BAUD_2400 1249 +#define BAUD_4800 624 +#define BAUD_9600 312 +#define BAUD_14400 207 +#define BAUD_19200 155 +#define BAUD_31250 95 +#define BAUD_38400 77 +#define BAUD_56000 53 +#define BAUD_57600 51 +#define BAUD_115200 25 +#define BAUD_128000 22 +#define BAUD_256000 11 +#define BAUD_300000 10 +#define BAUD_375000 8 +#define BAUD_500000 6 +#define BAUD_600000 4 +#define BAUD_750000 3 +#define BAUD_1000000 2 +#define BAUD_1500000 1 +#define BAUD_3000000 0 + +// Defined Colors +#define WHITE 0xFFFFFF +#define BLACK 0x000000 +#define RED 0xFF0000 +#define GREEN 0x00FF00 +#define BLUE 0x0000FF +#define LGREY 0xBFBFBF +#define DGREY 0x5F5F5F + +// Mode data +#define BACKLIGHT '\x00' +#define DISPLAY '\x01' +#define CONTRAST '\x02' +#define POWER '\x03' +#define ORIENTATION '\x04' +#define TOUCH_CTRL '\x05' +#define IMAGE_FORMAT '\x06' +#define PROTECT_FAT '\x08' + +// change this to your specific screen (newer versions) if needed +// Startup orientation is PORTRAIT so SIZE_X must be lesser than SIZE_Y +//uLCD144-G2 is a 128 by 128 pixel display +#define SIZE_X 128 +#define SIZE_Y 128 + +#define IS_LANDSCAPE 0 +#define IS_PORTRAIT 1 + +// Screen orientation +#define LANDSCAPE '\x00' +#define LANDSCAPE_R '\x01' +#define PORTRAIT '\x02' +#define PORTRAIT_R '\x03' + +// Parameters +#define ENABLE '\x00' +#define DISABLE '\x01' +#define RESET '\x02' + +#define NEW '\x00' +#define OLD '\x01' + +#define DOWN '\x00' +#define UP '\x01' + +#define PROTECT '\x00' +#define UNPROTECT '\x02' + +//************************************************************************** +// \class uLCD_4DGL uLCD_4DGL.h +// \brief This is the main class. It shoud be used like this : uLCD_4GDL myLCD(p9,p10,p11); +/** +Example: +* @code +* // Display a white circle on the screen +* #include "mbed.h" +* #include " uLCD_4DGL.h" +* +* uLCD_4GDL myLCD(p9,p10,p11); +* +* int main() { +* myLCD.circle(120, 160, 80, WHITE); +* } +* @endcode +*/ + +class uLCD_4DGL : public Stream +{ + +public : + + uLCD_4DGL(PinName tx, PinName rx, PinName rst); + +// General Commands ******************************************************************************* + + /** Clear the entire screen using the current background colour */ + void cls(); + + /** Reset screen */ + void reset(); + + + /** Set serial Baud rate (both sides : screen and mbed) + * @param Speed Correct BAUD value (see uLCD_4DGL.h) + */ + void baudrate(int speed); + + /** Set background colour to the specified value + * @param color in HEX RGB like 0xFF00FF + */ + void background_color(int color); + + /** Set screen display mode to specific values + * @param mode See 4DGL documentation + * @param value See 4DGL documentation + */ + void textbackground_color(int color); + + /** Set screen display mode to specific values + * @param mode See 4DGL documentation + * @param value See 4DGL documentation + */ + void display_control(char mode); + void display_power(char mode); + /** Set internal speaker to specified value + * @param value Correct range is 8 - 127 + */ + void set_volume(char value); + +// Graphics Commands ******************************************************************************* + + /** Draw a circle centered at x,y with a radius and a colour. It uses Pen Size stored value to draw a solid or wireframe circle + * @param x Horizontal position of the circle centre + * @param y Vertical position of the circle centre + * @param radius Radius of the circle + * @param color Circle color in HEX RGB like 0xFF00FF + */ + void circle(int x , int y , int radius, int color); + void filled_circle(int x , int y , int radius, int color); + void triangle(int, int, int, int, int, int, int); + void line(int, int, int, int, int); + void rectangle(int, int, int, int, int); + void filled_rectangle(int, int, int, int, int); + void pixel(int, int, int); + int read_pixel(int, int); + void pen_size(char); + void BLIT(int x, int y, int w, int h, const int *colors); + +// Text Commands + void set_font(char); + void set_font_size(char width, char height); + void text_mode(char); + void text_bold(char); + void text_italic(char); + void text_inverse(char); + void text_underline(char); + void text_width(char); + void text_height(char); + void text_char(char, char, char, int); + void text_string(char *, char, char, char, int); + void locate(char, char); + void color(int); + void putc(char); + void puts(char *); + +//Media Commands + int media_init(); + void set_byte_address(int, int); + void set_sector_address(int, int); + char read_byte(); + int read_word(); + void write_byte(int); + void write_word(int); + void flush_media(); + void display_image(int, int); + void display_video(int, int); + void display_frame(int, int, int); + +// Screen Data + int type; + int revision; + int firmware; + int reserved1; + int reserved2; + +// Text data + char current_col; + char current_row; + int current_color; + char current_font; + char current_orientation; + char max_col; + char max_row; + int current_w, current_h; + int current_fx, current_fy; + int current_wf, current_hf; + + +protected : + + Serial _cmd; + DigitalOut _rst; + //used by printf + virtual int _putc(int c) { + putc(c); + return 0; + }; + virtual int _getc() { + return -1; + } + + void freeBUFFER (void); + void writeBYTE (char); + void writeBYTEfast (char); + int writeCOMMAND(char *, int); + int writeCOMMANDnull(char *, int); + int readVERSION (char *, int); + int getSTATUS (char *, int); + int version (void); +#if DEBUGMODE + Serial pc; +#endif // DEBUGMODE +}; + +typedef unsigned char BYTE; +#endif + + + + + + + +
diff -r 000000000000 -r daf9e2f8e1a1 LCDGraphics/uLCD_4DGL_Graphics.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LCDGraphics/uLCD_4DGL_Graphics.cpp Fri Apr 05 19:46:26 2019 +0000 @@ -0,0 +1,311 @@ +// +// uLCD_4DGL is a class to drive 4D Systems LCD screens +// +// Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr> +// Modifed for Goldelox processor <2013> Jim Hamblen +// +// uLCD_4DGL is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// uLCD_4DGL is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with uLCD_4DGL. If not, see <http://www.gnu.org/licenses/>. + +#include "mbed.h" +#include "uLCD_4DGL.h" + +#define ARRAY_SIZE(X) sizeof(X)/sizeof(X[0]) + +//**************************************************************************************************** +void uLCD_4DGL :: circle(int x, int y , int radius, int color) // draw a circle in (x,y) +{ + char command[9]= ""; + + command[0] = CIRCLE; + + command[1] = (x >> 8) & 0xFF; + command[2] = x & 0xFF; + + command[3] = (y >> 8) & 0xFF; + command[4] = y & 0xFF; + + command[5] = (radius >> 8) & 0xFF; + command[6] = radius & 0xFF; + + int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits + int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits + int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits + + command[7] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color + command[8] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color + + writeCOMMAND(command, 9); +} +//**************************************************************************************************** +void uLCD_4DGL :: filled_circle(int x, int y , int radius, int color) // draw a circle in (x,y) +{ + char command[9]= ""; + + command[0] = FCIRCLE; + + command[1] = (x >> 8) & 0xFF; + command[2] = x & 0xFF; + + command[3] = (y >> 8) & 0xFF; + command[4] = y & 0xFF; + + command[5] = (radius >> 8) & 0xFF; + command[6] = radius & 0xFF; + + int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits + int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits + int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits + + command[7] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color + command[8] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color + + writeCOMMAND(command, 9); +} + +//**************************************************************************************************** +void uLCD_4DGL :: triangle(int x1, int y1 , int x2, int y2, int x3, int y3, int color) // draw a traingle +{ + char command[15]= ""; + + command[0] = TRIANGLE; + + command[1] = (x1 >> 8) & 0xFF; + command[2] = x1 & 0xFF; + + command[3] = (y1 >> 8) & 0xFF; + command[4] = y1 & 0xFF; + + command[5] = (x2 >> 8) & 0xFF; + command[6] = x2 & 0xFF; + + command[7] = (y2 >> 8) & 0xFF; + command[8] = y2 & 0xFF; + + command[9] = (x3 >> 8) & 0xFF; + command[10] = x3 & 0xFF; + + command[11] = (y3 >> 8) & 0xFF; + command[12] = y3 & 0xFF; + + int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits + int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits + int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits + + command[13] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color + command[14] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color + + writeCOMMAND(command, 15); +} + +//**************************************************************************************************** +void uLCD_4DGL :: line(int x1, int y1 , int x2, int y2, int color) // draw a line +{ + char command[11]= ""; + + command[0] = LINE; + + command[1] = (x1 >> 8) & 0xFF; + command[2] = x1 & 0xFF; + + command[3] = (y1 >> 8) & 0xFF; + command[4] = y1 & 0xFF; + + command[5] = (x2 >> 8) & 0xFF; + command[6] = x2 & 0xFF; + + command[7] = (y2 >> 8) & 0xFF; + command[8] = y2 & 0xFF; + + int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits + int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits + int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits + + command[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color + command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color + + writeCOMMAND(command, 11); +} + +//**************************************************************************************************** +void uLCD_4DGL :: rectangle(int x1, int y1 , int x2, int y2, int color) // draw a rectangle +{ + char command[11]= ""; + + command[0] = RECTANGLE; + + command[1] = (x1 >> 8) & 0xFF; + command[2] = x1 & 0xFF; + + command[3] = (y1 >> 8) & 0xFF; + command[4] = y1 & 0xFF; + + command[5] = (x2 >> 8) & 0xFF; + command[6] = x2 & 0xFF; + + command[7] = (y2 >> 8) & 0xFF; + command[8] = y2 & 0xFF; + + int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits + int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits + int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits + + command[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color + command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color + + writeCOMMAND(command, 11); +} + +//**************************************************************************************************** +void uLCD_4DGL :: filled_rectangle(int x1, int y1 , int x2, int y2, int color) // draw a rectangle +{ + char command[11]= ""; + + command[0] = FRECTANGLE; + + command[1] = (x1 >> 8) & 0xFF; + command[2] = x1 & 0xFF; + + command[3] = (y1 >> 8) & 0xFF; + command[4] = y1 & 0xFF; + + command[5] = (x2 >> 8) & 0xFF; + command[6] = x2 & 0xFF; + + command[7] = (y2 >> 8) & 0xFF; + command[8] = y2 & 0xFF; + + int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits + int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits + int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits + + command[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color + command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color + + writeCOMMAND(command, 11); +} + + + +//**************************************************************************************************** +void uLCD_4DGL :: pixel(int x, int y, int color) // draw a pixel +{ + char command[7]= ""; + + command[0] = PIXEL; + + command[1] = (x >> 8) & 0xFF; + command[2] = x & 0xFF; + + command[3] = (y >> 8) & 0xFF; + command[4] = y & 0xFF; + + int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits + int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits + int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits + + command[5] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color + command[6] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color + + writeCOMMAND(command, 7); +} +//**************************************************************************************************** +void uLCD_4DGL :: BLIT(int x, int y, int w, int h, const int *colors) // draw a block of pixels +{ + int red5, green6, blue5; + writeBYTEfast('\x00'); + writeBYTEfast(BLITCOM); + writeBYTEfast((x >> 8) & 0xFF); + writeBYTEfast(x & 0xFF); + writeBYTEfast((y >> 8) & 0xFF); + writeBYTEfast(y & 0xFF); + writeBYTEfast((w >> 8) & 0xFF); + writeBYTE(w & 0xFF); + writeBYTE((h >> 8) & 0xFF); + writeBYTE(h & 0xFF); + wait_ms(1); + for (int i=0; i<w*h; i++) { + red5 = (colors[i] >> (16 + 3)) & 0x1F; // get red on 5 bits + green6 = (colors[i] >> (8 + 2)) & 0x3F; // get green on 6 bits + blue5 = (colors[i] >> (0 + 3)) & 0x1F; // get blue on 5 bits + writeBYTEfast(((red5 << 3) + (green6 >> 3)) & 0xFF); // first part of 16 bits color + writeBYTEfast(((green6 << 5) + (blue5 >> 0)) & 0xFF); // second part of 16 bits color + } + int resp=0; + while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer + if (_cmd.readable()) resp = _cmd.getc(); // read response if any + switch (resp) { + case ACK : // if OK return 1 + resp = 1; + break; + case NAK : // if NOK return -1 + resp = -1; + break; + default : + resp = 0; // else return 0 + break; + } +#if DEBUGMODE + pc.printf(" Answer received : %d\n",resp); +#endif + +} +//****************************************************************************************************** +int uLCD_4DGL :: read_pixel(int x, int y) // read screen info and populate data +{ + + char command[6]= ""; + command[0] = 0xFF; + command[1] = READPIXEL; + + command[2] = (x >> 8) & 0xFF; + command[3] = x & 0xFF; + + command[4] = (y >> 8) & 0xFF; + command[5] = y & 0xFF; + + int i, temp = 0, color = 0, resp = 0; + char response[3] = ""; + + freeBUFFER(); + + for (i = 0; i < 6; i++) { // send all chars to serial port + writeBYTE(command[i]); + } + + while (!_cmd.readable()) wait_ms(TEMPO); // wait a bit for screen answer + + while ( resp < ARRAY_SIZE(response)) { //read ack and 16-bit color response + temp = _cmd.getc(); + response[resp++] = (char)temp; + } + + color = ((response[1] << 8) + response[2]); + + return color; +} + + +//**************************************************************************************************** +void uLCD_4DGL :: pen_size(char mode) // set pen to SOLID or WIREFRAME +{ + char command[2]= ""; + + command[0] = PENSIZE; + command[1] = mode; + writeCOMMAND(command, 2); +} + + + +
diff -r 000000000000 -r daf9e2f8e1a1 LCDGraphics/uLCD_4DGL_Media.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LCDGraphics/uLCD_4DGL_Media.cpp Fri Apr 05 19:46:26 2019 +0000 @@ -0,0 +1,178 @@ +// +// uLCD_4DGL is a class to drive 4D Systems LCD screens +// +// Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr> +// Modifed for Goldelox processor <2013> Jim Hamblen +// +// uLCD_4DGL is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// uLCD_4DGL is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with uLCD_4DGL. If not, see <http://www.gnu.org/licenses/>. + +#include "mbed.h" +#include "uLCD_4DGL.h" + + +//Media Commands + +//****************************************************************************************************** +int uLCD_4DGL :: media_init() +{ + int resp = 0; + char command[1] = ""; + command[0] = MINIT; + writeCOMMAND(command, 1); + while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer + if (_cmd.readable()) { + resp = _cmd.getc(); // read response + resp = resp << 8 + _cmd.getc(); + } + return resp; +} + +//****************************************************************************************************** +void uLCD_4DGL :: set_byte_address(int hi, int lo) +{ + char command[5]= ""; + command[0] = SBADDRESS; + + command[1] = (hi >> 8) & 0xFF; + command[2] = hi & 0xFF; + + command[3] = (lo >> 8) & 0xFF; + command[4] = lo & 0xFF; + writeCOMMAND(command, 5); +} + +//****************************************************************************************************** +void uLCD_4DGL :: set_sector_address(int hi, int lo) +{ + + char command[5]= ""; + command[0] = SSADDRESS; + + command[1] = (hi >> 8) & 0xFF; + command[2] = hi & 0xFF; + + command[3] = (lo >> 8) & 0xFF; + command[4] = lo & 0xFF; + writeCOMMAND(command, 5); +} + +//****************************************************************************************************** +char uLCD_4DGL :: read_byte() +{ + char resp = 0; + char command[1] = ""; + command[0] = READBYTE; + writeCOMMAND(command, 1); + while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer + if (_cmd.readable()) { + resp = _cmd.getc(); // read response + resp = _cmd.getc(); + } + return resp; +} + +//****************************************************************************************************** +int uLCD_4DGL :: read_word() +{ + int resp=0; + char command[1] = ""; + command[0] = READWORD; + writeCOMMAND(command, 1); + while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer + if (_cmd.readable()) { + resp = _cmd.getc(); // read response + resp = resp << 8 + _cmd.getc(); + } + return resp; +} + +//****************************************************************************************************** +void uLCD_4DGL :: write_byte(int value) +{ + char command[3]= ""; + + command[0] = WRITEBYTE; + + command[1] = (value >> 8) & 0xFF; + command[2] = value & 0xFF; + writeCOMMAND(command,3); +} + +//****************************************************************************************************** +void uLCD_4DGL :: write_word(int value) +{ + char command[3]= ""; + + command[0] = WRITEWORD; + + command[1] = (value >> 8) & 0xFF; + command[2] = value & 0xFF; + writeCOMMAND(command,3); +} + +//****************************************************************************************************** +void uLCD_4DGL :: flush_media() +{ + char command[1] = ""; + command[0] = FLUSHMEDIA; + writeCOMMAND(command, 1); +} + +//****************************************************************************************************** +void uLCD_4DGL :: display_image(int x, int y) +{ + char command[6]= ""; + command[0] = DISPLAYIMAGE; + + command[1] = (x >> 8) & 0xFF; + command[2] = x & 0xFF; + + command[3] = (y >> 8) & 0xFF; + command[4] = y & 0xFF; + writeCOMMAND(command, 5); +} + +//****************************************************************************************************** +void uLCD_4DGL :: display_video(int x, int y) +{ + char command[5]= ""; + command[0] = DISPLAYVIDEO; + + command[1] = (x >> 8) & 0xFF; + command[2] = x & 0xFF; + + command[3] = (y >> 8) & 0xFF; + command[4] = y & 0xFF; + writeCOMMAND(command, 5); +} + +//****************************************************************************************************** +void uLCD_4DGL :: display_frame(int x, int y, int w) +{ + char command[7]= ""; + + command[0] = DISPLAYFRAME; + + command[1] = (x >> 8) & 0xFF; + command[2] = x & 0xFF; + + command[3] = (y >> 8) & 0xFF; + command[4] = y & 0xFF; + + command[5] = (w >> 8) & 0xFF; + command[6] = w & 0xFF; + writeCOMMAND(command,7); +} + +
diff -r 000000000000 -r daf9e2f8e1a1 LCDGraphics/uLCD_4DGL_Text.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LCDGraphics/uLCD_4DGL_Text.cpp Fri Apr 05 19:46:26 2019 +0000 @@ -0,0 +1,344 @@ +// +// uLCD_4DGL is a class to drive 4D Systems TFT touch screens +// +// Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr> +// Modifed for Goldelox processor <2013> Jim Hamblen +// +// uLCD_4DGL is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// uLCD_4DGL is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with uLCD_4DGL. If not, see <http://www.gnu.org/licenses/>. + +#include "mbed.h" +#include "uLCD_4DGL.h" + +//**************************************************************************************************** +void uLCD_4DGL :: set_font_size(char width, char height) // set font size +{ + if (current_orientation == IS_PORTRAIT) { + current_fx = width; + current_fy = height; + } else { + current_fy = height; + current_fx = width; + } + max_col = current_w / (current_fx*current_wf); + max_row = current_h / (current_fy*current_hf); +} + +//**************************************************************************************************** +void uLCD_4DGL :: set_font(char mode) // set font - system or SD media +{ + char command[3]= ""; + + command[0] = SETFONT; + command[1] = 0; + command[2] = mode; + + current_font = mode; + + if (current_orientation == IS_PORTRAIT) { + current_w = SIZE_X; + current_h = SIZE_Y; + } else { + current_w = SIZE_Y; + current_h = SIZE_X; + } + + switch (mode) { + case FONT_5X7 : + + current_fx = 6; + current_fy = 8; + break; + case FONT_7X8 : + current_fx = 7; + current_fy = 8; + break; + case FONT_8X8 : + current_fx = 8; + current_fy = 8; + break; + case FONT_8X12 : + current_fx = 8; + current_fy = 12; + break; + case FONT_12X16 : + current_fx = 12; + current_fy = 16; + break; + default: + current_fx = 8; + current_fy = 8; + } + + max_col = current_w / (current_fx*current_wf); + max_row = current_h / (current_fy*current_hf); + + writeCOMMAND(command, 3); +} + + + +//**************************************************************************************************** +void uLCD_4DGL :: text_mode(char mode) // set text mode +{ + char command[3]= ""; + + command[0] = TEXTMODE; + command[1] = 0; + command[2] = mode; + + writeCOMMAND(command, 3); +} + +//**************************************************************************************************** +void uLCD_4DGL :: text_bold(char mode) // set text mode +{ + char command[3]= ""; + + command[0] = TEXTBOLD; + command[1] = 0; + command[2] = mode; + + writeCOMMAND(command, 3); +} + +//**************************************************************************************************** +void uLCD_4DGL :: text_italic(char mode) // set text mode +{ + char command[3]= ""; + + command[0] = TEXTITALIC; + command[1] = 0; + command[2] = mode; + + writeCOMMAND(command, 3); +} + +//**************************************************************************************************** +void uLCD_4DGL :: text_inverse(char mode) // set text mode +{ + char command[3]= ""; + + command[0] = TEXTINVERSE; + command[1] = 0; + command[2] = mode; + + writeCOMMAND(command, 3); +} + +//**************************************************************************************************** +void uLCD_4DGL :: text_underline(char mode) // set text mode +{ + char command[3]= ""; + + command[0] = TEXTUNDERLINE; + command[1] = 0; + command[2] = mode; + + writeCOMMAND(command, 3); +} + +//**************************************************************************************************** +void uLCD_4DGL :: text_width(char width) // set text width +{ + char command[3]= ""; + + command[0] = TEXTWIDTH; + command[1] = 0; + command[2] = width; + current_wf = width; + max_col = current_w / (current_fx*current_wf); + writeCOMMAND(command, 3); +} + +//**************************************************************************************************** +void uLCD_4DGL :: text_height(char height) // set text height +{ + char command[3]= ""; + + command[0] = TEXTHEIGHT; + command[1] = 0; + command[2] = height; + current_hf = height; + max_row = current_h / (current_fy*current_hf); + writeCOMMAND(command, 3); +} + + +//**************************************************************************************************** +void uLCD_4DGL :: text_char(char c, char col, char row, int color) // draw a text char +{ + char command[6]= ""; + command[0] = 0xE4; //move cursor + command[1] = 0; + command[2] = row; + command[3] = 0; + command[4] = col; + writeCOMMAND(command, 5); + + command[0] = 0x7F; //set color + + int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits + int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits + int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits + + command[1] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color + command[2] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color + writeCOMMAND(command, 3); + + command[0] = TEXTCHAR; //print char + command[1] = 0; + command[2] = c; + writeCOMMAND(command, 3); + +} + + +//**************************************************************************************************** +void uLCD_4DGL :: text_string(char *s, char col, char row, char font, int color) // draw a text string +{ + + char command[1000]= ""; + int size = strlen(s); + int i = 0; + + set_font(font); + + command[0] = 0xE4; //move cursor + command[1] = 0; + command[2] = row; + command[3] = 0; + command[4] = col; + writeCOMMAND(command, 5); + + command[0] = 0x7F; //set color + int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits + int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits + int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits + + command[1] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color + command[2] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color + writeCOMMAND(command, 3); + + command[0] = TEXTSTRING; + for (i=0; i<size; i++) command[1+i] = s[i]; + command[1+size] = 0; + writeCOMMANDnull(command, 2 + size); +} + + + +//**************************************************************************************************** +void uLCD_4DGL :: locate(char col, char row) // place text curssor at col, row +{ + char command[5] = ""; + current_col = col; + current_row = row; + command[0] = MOVECURSOR; //move cursor + command[1] = 0; + command[2] = current_row; + command[3] = 0; + command[4] = current_col; + writeCOMMAND(command, 5); +} + +//**************************************************************************************************** +void uLCD_4DGL :: color(int color) // set text color +{ + char command[5] = ""; + current_color = color; + command[0] = 0x7F; //set color + + int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits + int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits + int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits + + command[1] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color + command[2] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color + writeCOMMAND(command, 3); +} + +//**************************************************************************************************** +void uLCD_4DGL :: putc(char c) // place char at current cursor position +//used by virtual printf function _putc +{ + char command[6] =""; + if(c<0x20) { + if(c=='\n') { + current_col = 0; + current_row++; + command[0] = MOVECURSOR; //move cursor to start of next line + command[1] = 0; + command[2] = current_row; + command[3] = 0; + command[4] = current_col; + writeCOMMAND(command, 5); + } + if(c=='\r') { + current_col = 0; + command[0] = MOVECURSOR; //move cursor to start of line + command[1] = 0; + command[2] = current_row; + command[3] = 0; + command[4] = current_col; + writeCOMMAND(command, 5); + } + if(c=='\f') { + uLCD_4DGL::cls(); //clear screen on form feed + } + } else { + command[0] = PUTCHAR; + command[1] = 0x00; + command[2] = c; + writeCOMMAND(command,3); + current_col++; + } + if (current_col == max_col) { + current_col = 0; + current_row++; + command[0] = MOVECURSOR; //move cursor to next line + command[1] = 0; + command[2] = current_row; + command[3] = 0; + command[4] = current_col; + writeCOMMAND(command, 5); + } + if (current_row == max_row) { + current_row = 0; + command[0] = MOVECURSOR; //move cursor back to start + command[1] = 0; + command[2] = current_row; + command[3] = 0; + command[4] = current_col; + writeCOMMAND(command, 5); + } +} + + +//**************************************************************************************************** +void uLCD_4DGL :: puts(char *s) // place string at current cursor position +{ + + text_string(s, current_col, current_row, current_font, current_color); + + current_col += strlen(s); + + if (current_col >= max_col) { + current_row += current_col / max_col; + current_col %= max_col; + } + if (current_row >= max_row) { + current_row %= max_row; + } +} +
diff -r 000000000000 -r daf9e2f8e1a1 LCDGraphics/uLCD_4DGL_main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LCDGraphics/uLCD_4DGL_main.cpp Fri Apr 05 19:46:26 2019 +0000 @@ -0,0 +1,470 @@ +// +// uLCD_4DGL is a class to drive 4D Systems uLCD 144 G2 +// +// Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr> +// Modifed for Goldelox processor <2013> Jim Hamblen +// +// uLCD_4DGL is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// uLCD_4DGL is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with uLCD_4DGL. If not, see <http://www.gnu.org/licenses/>. + +#include "mbed.h" +#include "uLCD_4DGL.h" + +#define ARRAY_SIZE(X) sizeof(X)/sizeof(X[0]) + +//Serial pc(USBTX,USBRX); + + +//****************************************************************************************************** +uLCD_4DGL :: uLCD_4DGL(PinName tx, PinName rx, PinName rst) : _cmd(tx, rx), + _rst(rst) +#if DEBUGMODE + ,pc(USBTX, USBRX) +#endif // DEBUGMODE +{ + // Constructor + _cmd.baud(9600); +#if DEBUGMODE + pc.baud(115200); + + pc.printf("\n\n\n"); + pc.printf("*********************\n"); + pc.printf("uLCD_4DGL CONSTRUCTOR\n"); + pc.printf("*********************\n"); +#endif + + _rst = 1; // put RESET pin to high to start TFT screen + reset(); + cls(); // clear screen + current_col = 0; // initial cursor col + current_row = 0; // initial cursor row + current_color = WHITE; // initial text color + current_orientation = IS_PORTRAIT; // initial screen orientation + current_hf = 1; + current_wf = 1; + set_font(FONT_7X8); // initial font +// text_mode(OPAQUE); // initial texr mode +} + +//****************************************************************************************************** +void uLCD_4DGL :: writeBYTE(char c) // send a BYTE command to screen +{ + + _cmd.putc(c); + wait_us(500); //mbed is too fast for LCD at high baud rates in some long commands + +#if DEBUGMODE + pc.printf(" Char sent : 0x%02X\n",c); +#endif + +} + +//****************************************************************************************************** +void uLCD_4DGL :: writeBYTEfast(char c) // send a BYTE command to screen +{ + + _cmd.putc(c); + //wait_ms(0.0); //mbed is too fast for LCD at high baud rates - but not in short commands + +#if DEBUGMODE + pc.printf(" Char sent : 0x%02X\n",c); +#endif + +} +//****************************************************************************************************** +void uLCD_4DGL :: freeBUFFER(void) // Clear serial buffer before writing command +{ + + while (_cmd.readable()) _cmd.getc(); // clear buffer garbage +} + +//****************************************************************************************************** +int uLCD_4DGL :: writeCOMMAND(char *command, int number) // send several BYTES making a command and return an answer +{ + +#if DEBUGMODE + pc.printf("\n"); + pc.printf("New COMMAND : 0x%02X\n", command[0]); +#endif + int i, resp = 0; + freeBUFFER(); + writeBYTE(0xFF); + for (i = 0; i < number; i++) { + if (i<16) + writeBYTEfast(command[i]); // send command to serial port + else + writeBYTE(command[i]); // send command to serial port but slower + } + while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer + if (_cmd.readable()) resp = _cmd.getc(); // read response if any + switch (resp) { + case ACK : // if OK return 1 + resp = 1; + break; + case NAK : // if NOK return -1 + resp = -1; + break; + default : + resp = 0; // else return 0 + break; + } +#if DEBUGMODE + pc.printf(" Answer received : %d\n",resp); +#endif + + return resp; +} + +//************************************************************************** +void uLCD_4DGL :: reset() // Reset Screen +{ + wait_ms(5); + _rst = 0; // put RESET pin to low + wait_ms(5); // wait a few milliseconds for command reception + _rst = 1; // put RESET back to high + wait(3); // wait 3s for screen to restart + + freeBUFFER(); // clean buffer from possible garbage +} +//****************************************************************************************************** +int uLCD_4DGL :: writeCOMMANDnull(char *command, int number) // send several BYTES making a command and return an answer +{ + +#if DEBUGMODE + pc.printf("\n"); + pc.printf("New COMMAND : 0x%02X\n", command[0]); +#endif + int i, resp = 0; + freeBUFFER(); + writeBYTE(0x00); //command has a null prefix byte + for (i = 0; i < number; i++) { + if (i<16) //don't overflow LCD UART buffer + writeBYTEfast(command[i]); // send command to serial port + else + writeBYTE(command[i]); // send command to serial port with delay + } + while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer + if (_cmd.readable()) resp = _cmd.getc(); // read response if any + switch (resp) { + case ACK : // if OK return 1 + resp = 1; + break; + case NAK : // if NOK return -1 + resp = -1; + break; + default : + resp = 0; // else return 0 + break; + } +#if DEBUGMODE + pc.printf(" Answer received : %d\n",resp); +#endif + + return resp; +} + +//************************************************************************** +void uLCD_4DGL :: cls() // clear screen +{ + char command[1] = ""; + + command[0] = CLS; + writeCOMMAND(command, 1); + current_row=0; + current_col=0; + current_hf = 1; + current_wf = 1; + set_font(FONT_7X8); // initial font +} + +//************************************************************************** +int uLCD_4DGL :: version() // get API version +{ + + char command[2] = ""; + command[0] = '\x00'; + command[1] = VERSION; + return readVERSION(command, 2); +} + +//************************************************************************** +void uLCD_4DGL :: baudrate(int speed) // set screen baud rate +{ + char command[3]= ""; + writeBYTE(0x00); + command[0] = BAUDRATE; + command[1] = 0; + int newbaud = BAUD_9600; + switch (speed) { + case 110 : + newbaud = BAUD_110; + break; + case 300 : + newbaud = BAUD_300; + break; + case 600 : + newbaud = BAUD_600; + break; + case 1200 : + newbaud = BAUD_1200; + break; + case 2400 : + newbaud = BAUD_2400; + break; + case 4800 : + newbaud = BAUD_4800; + break; + case 9600 : + newbaud = BAUD_9600; + break; + case 14400 : + newbaud = BAUD_14400; + break; + case 19200 : + newbaud = BAUD_19200; + break; + case 31250 : + newbaud = BAUD_31250; + break; + case 38400 : + newbaud = BAUD_38400; + break; + case 56000 : + newbaud = BAUD_56000; + break; + case 57600 : + newbaud = BAUD_57600; + break; + case 115200 : + newbaud = BAUD_115200; + break; + case 128000 : + newbaud = BAUD_128000; + break; + case 256000 : + newbaud = BAUD_256000; + break; + case 300000 : + newbaud = BAUD_300000; + speed = 272727; + break; + case 375000 : + newbaud = BAUD_375000; + speed = 333333; + break; + case 500000 : + newbaud = BAUD_500000; + speed = 428571; + break; + case 600000 : + newbaud = BAUD_600000; + break; + case 750000 : //rates over 600000 are not documented, but seem to work + newbaud = BAUD_750000; + break; + case 1000000 : + newbaud = BAUD_1000000; + break; + case 1500000 : + newbaud = BAUD_1500000; + break; + case 3000000 : + newbaud = BAUD_3000000; + break; + default : + newbaud = BAUD_9600; + speed = 9600; + break; + } + + int i, resp = 0; + + freeBUFFER(); + command[1] = char(newbaud >>8); + command[2] = char(newbaud % 256); + wait_ms(1); + for (i = 0; i <3; i++) writeBYTEfast(command[i]); // send command to serial port + for (i = 0; i<10; i++) wait_ms(1); + //dont change baud until all characters get sent out + _cmd.baud(speed); // set mbed to same speed + i=0; + while ((!_cmd.readable()) && (i<25000)) { + wait_ms(TEMPO); // wait for screen answer - comes 100ms after change + i++; //timeout if ack character missed by baud change + } + if (_cmd.readable()) resp = _cmd.getc(); // read response if any + switch (resp) { + case ACK : // if OK return 1 + resp = 1; + break; + case NAK : // if NOK return -1 + resp = -1; + break; + default : + resp = 0; // else return 0 + break; + } +} + +//****************************************************************************************************** +int uLCD_4DGL :: readVERSION(char *command, int number) // read screen info and populate data +{ + + int i, temp = 0, resp = 0; + char response[5] = ""; + + freeBUFFER(); + + for (i = 0; i < number; i++) writeBYTE(command[i]); // send all chars to serial port + + while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer + + while (_cmd.readable() && resp < ARRAY_SIZE(response)) { + temp = _cmd.getc(); + response[resp++] = (char)temp; + } + switch (resp) { + case 2 : // if OK populate data and return 1 + revision = response[0]<<8 + response[1]; + resp = 1; + break; + default : + resp = 0; // else return 0 + break; + } + return resp; +} + +//**************************************************************************************************** +void uLCD_4DGL :: background_color(int color) // set screen background color +{ + char command[3]= ""; // input color is in 24bits like 0xRRGGBB + + command[0] = BCKGDCOLOR; + + int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits + int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits + int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits + + command[1] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color + command[2] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color + + writeCOMMAND(command, 3); +} + +//**************************************************************************************************** +void uLCD_4DGL :: textbackground_color(int color) // set screen background color +{ + char command[3]= ""; // input color is in 24bits like 0xRRGGBB + + command[0] = TXTBCKGDCOLOR; + + int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits + int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits + int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits + + command[1] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color + command[2] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color + + writeCOMMAND(command, 3); +} + +//**************************************************************************************************** +void uLCD_4DGL :: display_control(char mode) // set screen mode to value +{ + char command[3]= ""; + + command[0] = DISPCONTROL; + command[1] = 0; + command[2] = mode; + + if (mode == ORIENTATION) { + switch (mode) { + case LANDSCAPE : + current_orientation = IS_LANDSCAPE; + break; + case LANDSCAPE_R : + current_orientation = IS_LANDSCAPE; + break; + case PORTRAIT : + current_orientation = IS_PORTRAIT; + break; + case PORTRAIT_R : + current_orientation = IS_PORTRAIT; + break; + } + } + writeCOMMAND(command, 3); + set_font(current_font); +} +//**************************************************************************************************** +void uLCD_4DGL :: display_power(char mode) // set screen mode to value +{ + char command[3]= ""; + + command[0] = DISPPOWER; + command[1] = 0; + command[2] = mode; + writeCOMMAND(command, 3); +} +//**************************************************************************************************** +void uLCD_4DGL :: set_volume(char value) // set sound volume to value +{ + char command[2]= ""; + + command[0] = SETVOLUME; + command[1] = value; + + writeCOMMAND(command, 2); +} + + +//****************************************************************************************************** +int uLCD_4DGL :: getSTATUS(char *command, int number) // read screen info and populate data +{ + +#if DEBUGMODE + pc.printf("\n"); + pc.printf("New COMMAND : 0x%02X\n", command[0]); +#endif + + int i, temp = 0, resp = 0; + char response[5] = ""; + + freeBUFFER(); + + for (i = 0; i < number; i++) writeBYTE(command[i]); // send all chars to serial port + + while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer + + while (_cmd.readable() && resp < ARRAY_SIZE(response)) { + temp = _cmd.getc(); + response[resp++] = (char)temp; + } + switch (resp) { + case 4 : + resp = (int)response[1]; // if OK populate data + break; + default : + resp = -1; // else return 0 + break; + } + +#if DEBUGMODE + pc.printf(" Answer received : %d\n", resp); +#endif + + return resp; +} + +
diff -r 000000000000 -r daf9e2f8e1a1 PinDetect.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PinDetect.lib Fri Apr 05 19:46:26 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/trmontgomery/code/PinDetect/#045ce8e569c8
diff -r 000000000000 -r daf9e2f8e1a1 Sounds.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sounds.lib Fri Apr 05 19:46:26 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/trmontgomery/code/Sounds/#fee2c7336410
diff -r 000000000000 -r daf9e2f8e1a1 Sprite.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sprite.cpp Fri Apr 05 19:46:26 2019 +0000 @@ -0,0 +1,35 @@ +#include "Sprite.h" +///////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////// +// Default Constructor +Sprite::Sprite(): +m_CurrentDirection(NO_DIR), +m_DesiredDirection(NO_DIR), +m_RowPos(0), +m_ColPos(0), +m_nActiveImage(0) +{ + +} +///////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////// +// Constructor +Sprite::Sprite(enDIRECTIONS inDir, unsigned int inRow, unsigned int inCol): +m_CurrentDirection(inDir), +m_DesiredDirection(inDir), +m_RowPos(inRow), +m_ColPos(inCol), +m_nActiveImage(0) +{ + +} +///////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////// +// SetDesiredDirectionToMove +void Sprite::SetDesiredDirectionToMove(enDIRECTIONS dir) +{ + m_DesiredDirection = dir; +}
diff -r 000000000000 -r daf9e2f8e1a1 Sprite.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sprite.h Fri Apr 05 19:46:26 2019 +0000 @@ -0,0 +1,32 @@ +#pragma once + +class Sprite +{ +public: + enum enDIRECTIONS {NO_DIR, UP_DIR, DOWN_DIR, LEFT_DIR, RIGHT_DIR}; + // Default Constructor + Sprite(); + // Constructor + Sprite(enDIRECTIONS inDir, unsigned int inRow, unsigned int inCol); + + virtual ~Sprite(){}; + + void SetDesiredDirectionToMove(enDIRECTIONS dir); + + virtual void SetLocation(const int &nRow, const int &nCol) {m_RowPos=nRow;m_ColPos=nCol;}; + + virtual void Move() = 0; + virtual bool IsMoveAllowed(const int &nNewRow, const int &nNewCol) = 0; + virtual int GetImageIndex() {return (m_nActiveImage++)%2;} + +protected: + + enDIRECTIONS m_CurrentDirection; + enDIRECTIONS m_DesiredDirection; + + unsigned int m_RowPos; + unsigned int m_ColPos; + int m_nActiveImage; + + +};
diff -r 000000000000 -r daf9e2f8e1a1 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Apr 05 19:46:26 2019 +0000 @@ -0,0 +1,160 @@ +#include "mbed.h" +#include <stdio.h> +#include "Speaker.h" +#include "PinDetect.h" +#include "BuzzyGraphics.h" +#include "uLCD_4DGL.h" + +#include "Buzzy.h" +#include "Ghosts.h" + +DigitalOut myled1(LED1); +DigitalOut myled2(LED2); +DigitalOut myled3(LED3); +DigitalOut myled4(LED4); +//////////////////////////////////////// +// Setup instance of LCD display +uLCD_4DGL guLCD(p9, p10, p11); // serial tx, serial rx, reset pin; +//////////////////////////////////////// +// Setup instances of push button pins +PinDetect gPB_left(p21); +PinDetect gPB_right(p22); +PinDetect gPB_up(p23); +PinDetect gPB_down(p24); +// Create Buzzy and Ghosts +Buzzy gBuzzy; +Ghosts gGhosts[NUM_GHOSTS]; +// Variable indicates if game is paused or running +int gGameState = GAME_PAUSED; +// Declare and initialize the speaker +Speaker gSpeakerOut(p26); + +//////////////////////////////////////////////////////// +// This is the maze that changes as the game is played +char gDynaMaze[MAZE_NUM_ROW][MAZE_NUM_COL]; + +////////////////////////// +// Prototype functions +void DrawMaze(); + +////////////////////////////////////////////////////////////////////// +// Interrupt routine +// used to output next analog sample whenever a timer interrupt occurs +void Sample_timer_interrupt(void) +{ + // Call speaker function to play next value +} +//--------------------------------------------------------------------------------------------------- +// Callback routine is interrupt activated by a debounced pb_left hit +void pb_left_hit_callback (void) +{ + // Update game state and tell Buzzy to go left + gBuzzy.SetDesiredDirectionToMove(Sprite::LEFT_DIR); +} +//--------------------------------------------------------------------------------------------------- +// Callback routine is interrupt activated by a debounced pb_right hit +void pb_right_hit_callback (void) +{ + // Update game state and tell Buzzy to go right + gBuzzy.SetDesiredDirectionToMove(Sprite::RIGHT_DIR); +} +//--------------------------------------------------------------------------------------------------- +// Callback routine is interrupt activated by a debounced pb_up hit +void pb_up_hit_callback (void) +{ + // Update game state and tell Buzzy to go up + gBuzzy.SetDesiredDirectionToMove(Sprite::UP_DIR); +} +//--------------------------------------------------------------------------------------------------- +// Callback routine is interrupt activated by a debounced pb_down hit +void pb_down_hit_callback (void) +{ + // Update game state and tell Buzzy to go down + gBuzzy.SetDesiredDirectionToMove(Sprite::DOWN_DIR); +} +//--------------------------------------------------------------------------------------------------- +int main() +{ + + // Setup push buttons + gPB_left.mode(PullUp); + gPB_right.mode(PullUp); + gPB_up.mode(PullUp); + gPB_down.mode(PullUp); + // Delay for initial pullup to take effect + wait(.01); + // Setup Interrupt callback functions for a pb hit + gPB_left.attach_deasserted(&pb_left_hit_callback); + gPB_right.attach_deasserted(&pb_right_hit_callback); + gPB_up.attach_deasserted(&pb_up_hit_callback); + gPB_down.attach_deasserted(&pb_down_hit_callback); + // Setup speaker + gSpeakerOut.period(1.0/200000.0); + // set up a timer to be used for sample rate interrupts + Ticker Sample_Period; + Sample_Period.attach(&Sample_timer_interrupt, 1.0/(20000.0)); + + //Setup LCD display + guLCD.display_control(PORTRAIT); + guLCD.background_color(BLACK); + guLCD.cls(); + guLCD.baudrate(BAUD_3000000); //jack up baud rate to max for fast display + wait(1.0); + + // Start sampling pb inputs using interrupts + gPB_left.setSampleFrequency(); + gPB_right.setSampleFrequency(); + gPB_up.setSampleFrequency(); + gPB_down.setSampleFrequency(); + ////////////////////////////////////// + // Everything should be ready to start playing the game. + + while(1) + { + guLCD.cls(); + // Ask the user if they would like to play a game. + guLCD.printf("Would you like to play??"); + // Wait for a button to be pressed + while(gPB_left == 1){ + wait(1); + } + guLCD.cls(); + // Initialize needed parts + for (int ii = 0 ; ii < MAZE_NUM_ROW ; ii++) + { + for (int jj = 0 ; jj < MAZE_NUM_COL ; jj++) + { + gDynaMaze[ii][jj] = gCnstMaze[ii][jj]; + } + } + // Reset the Ghosts and Buzzy states + gBuzzy.SetDesiredDirectionToMove(Sprite::RIGHT_DIR); + // Start up new game + gBuzzy.honey = 0; + + // Play introduction sounds while drawing the Maze + gSpeakerOut.SwitchSound(Speaker::BEGIN); + DrawMaze(); + // Start Game loop + gGameState = GAME_RUNNING; + while (gGameState == GAME_RUNNING) + { + // Move Buzzy and any active ghosts + gBuzzy.Move(); + // Check to see if Buzzy has eaten all the honey drops + if(gBuzzy.honey == 10){ + gGameState = 0; + } + // Break out of loop if all honey drops are consumed + + wait(0.001); + } + + guLCD.cls(); + guLCD.printf("GAME OVER!!"); + wait(2); + + gGameState = GAME_PAUSED; + } + +} //end main \ No newline at end of file
diff -r 000000000000 -r daf9e2f8e1a1 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Apr 05 19:46:26 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/3a7713b1edbc \ No newline at end of file
diff -r 000000000000 -r daf9e2f8e1a1 mbed_config.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed_config.h Fri Apr 05 19:46:26 2019 +0000 @@ -0,0 +1,43 @@ +/* + * mbed SDK + * Copyright (c) 2017 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Automatically generated configuration file. +// DO NOT EDIT, content will be overwritten. + +#ifndef __MBED_CONFIG_DATA__ +#define __MBED_CONFIG_DATA__ + +// Configuration parameters +#define MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE 9600 // set by library:platform +#define MBED_CONF_PLATFORM_ERROR_ALL_THREADS_INFO 0 // set by library:platform +#define MBED_CONF_PLATFORM_ERROR_DECODE_HTTP_URL_STR "\nFor more info, visit: https://armmbed.github.io/mbedos-error/?error=0x%08X" // set by library:platform +#define MBED_CONF_PLATFORM_ERROR_FILENAME_CAPTURE_ENABLED 0 // set by library:platform +#define MBED_CONF_PLATFORM_ERROR_HIST_ENABLED 0 // set by library:platform +#define MBED_CONF_PLATFORM_ERROR_HIST_SIZE 4 // set by library:platform +#define MBED_CONF_PLATFORM_FORCE_NON_COPYABLE_ERROR 0 // set by library:platform +#define MBED_CONF_PLATFORM_MAX_ERROR_FILENAME_LEN 16 // set by library:platform +#define MBED_CONF_PLATFORM_POLL_USE_LOWPOWER_TIMER 0 // set by library:platform +#define MBED_CONF_PLATFORM_STDIO_BAUD_RATE 9600 // set by library:platform +#define MBED_CONF_PLATFORM_STDIO_BUFFERED_SERIAL 0 // set by library:platform +#define MBED_CONF_PLATFORM_STDIO_CONVERT_NEWLINES 0 // set by library:platform +#define MBED_CONF_PLATFORM_STDIO_CONVERT_TTY_NEWLINES 0 // set by library:platform +#define MBED_CONF_PLATFORM_STDIO_FLUSH_AT_EXIT 1 // set by library:platform +#define MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE ETHERNET // set by target:LPC1768 +#define MBED_CONF_TARGET_US_TICKER_TIMER 3 // set by target:LPC1768 +#define MBED_MEM_TRACING_ENABLED 0 // set by library:platform + +#endif