For Nikhil

Dependencies:   4DGL-uLCD-SE EthernetInterface Game_Synchronizer MMA8452 SDFileSystem mbed-rtos mbed wave_player

Fork of 2035_Tanks_Shell by ECE2035 Spring 2015 TA

Files at this revision

API Documentation at this revision

Comitter:
jford38
Date:
Thu Oct 15 22:07:40 2015 +0000
Parent:
4:d8bd8b41468d
Child:
6:3be57cf4bd33
Commit message:
Working graphics commands on LCDs.; circle, line, triangle, filled_circle, filled_rectangle, rectangle, etc.; ; pen_size() seems to kill the LCD's. Don't know why. Probably just gonna exclude it.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
two_player.h Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu Oct 15 19:57:51 2015 +0000
+++ b/main.cpp	Thu Oct 15 22:07:40 2015 +0000
@@ -16,24 +16,23 @@
 
     uLCD.init();
     pc.printf("Initialized...\n");
+    
+    float theta = 0;
     while(1) {
         
-        uLCD.cls();
-        uLCD.background_color(0xAB);
-        uLCD.line(1,1,2,2, 0xAB);
-        uLCD.circle(10,10,100, 0xAB);
-        //uLCD.filled_circle(4,4,10, 0xAB);
-        //uLCD.triangle(1,1, 2,2, 0,3, 0xAB);
-        //uLCD.rectangle(0,0, 1,1, 0xAB);
-        //uLCD.filled_rectangle(1,1, 2,2, 0xAB);
-        //uLCD.pixel(40, 40, 0xAB);
-        //uLCD.pen_size(4);
-        
+        uLCD.line(64,64,64+50*cos(theta),64+50*sin(theta), BLACK);
+        theta += 0.05;
+        uLCD.line(64,64,64+50*cos(theta),64+50*sin(theta), RED);
+        uLCD.circle(10,10,100, GREEN);
+        uLCD.filled_circle(4,4,10, 0xAB);
+        uLCD.triangle(10,10, 20,20, 20,40, 0xAB);
+        uLCD.rectangle(100,100, 90,90, GREEN);
+        uLCD.filled_rectangle(100,100, 110,110, 0xAB);
+        uLCD.pixel(40, 40, WHITE);
         
         uLCD.update();
         buttons = uLCD.get_button_state();
-        pc.printf("Button State: %x %x %x %x %x\n", buttons[0], buttons[1], buttons[2], buttons[3], buttons[4]);
-        wait(1);
-        pc.printf("\033[2J\033[0;0H");
+        //pc.printf("Button State: %x %x %x %x %x\n", buttons[0], buttons[1], buttons[2], buttons[3], buttons[4]);
+        //pc.printf("\033[2J\033[0;0H");
     } 
 }
\ No newline at end of file
--- a/two_player.h	Thu Oct 15 19:57:51 2015 +0000
+++ b/two_player.h	Thu Oct 15 22:07:40 2015 +0000
@@ -26,7 +26,7 @@
 
     enum Color
     {
-        CLS_CMD=1,
+        CLS_CMD,
         BG_COLOR_CMD,
         LINE_CMD,
         CIRCLE_CMD,
@@ -34,13 +34,12 @@
         TRI_CMD,
         RECT_CMD,
         FILLED_RECT_CMD,
-        PIX_CMD,
-        PEN_SZ_CMD
+        PIX_CMD
     };
 
     uLCD_2P(PinName tx, PinName rx, PinName rst, bool player) {
         p1_p2 = player;
-        //LCD = new uLCD_4DGL (tx, rx, rst);        
+        LCD = new uLCD_4DGL (tx, rx, rst);        
     }
     
     void init() {
@@ -115,17 +114,16 @@
     }
     
    
-    void background_color(int color) { draw(BG_COLOR_CMD, color); }
-    void line(int sx, int sy, int ex, int ey, int color) { draw(LINE_CMD, sx, sy, ex, ey, color); }
-    void circle(int x , int y , int radius, int color) { draw(CIRCLE_CMD, x, y, radius, color); }
-    void filled_circle(int x , int y , int radius, int color) { draw(FILLED_CIRCLE_CMD, x, y, radius, color); }
+    void background_color(int color)                                  { draw(BG_COLOR_CMD, color); }
+    void line(int sx, int sy, int ex, int ey, int color)              { draw(LINE_CMD, sx, sy, ex, ey, color); }
+    void circle(int x , int y , int radius, int color)                { draw(CIRCLE_CMD, x, y, radius, color); }
+    void filled_circle(int x , int y , int radius, int color)         { draw(FILLED_CIRCLE_CMD, x, y, radius, color); }
     void triangle(int a, int b, int c, int d , int e, int f, int col) { draw(TRI_CMD, a, b, c, d, e, f, col); }
-    void rectangle(int a, int b, int c, int d, int col) { draw(RECT_CMD, a, b, c, d, col); }
-    void filled_rectangle(int a, int b, int c, int d, int col) { draw(FILLED_RECT_CMD, a, b, c, d, col); }
-    void pixel(int a, int b, int col) { draw(PIX_CMD, a, b, col); }
-    void cls(void) { draw(CLS_CMD); }
+    void rectangle(int a, int b, int c, int d, int col)               { draw(RECT_CMD, a, b, c, d, col); }
+    void filled_rectangle(int a, int b, int c, int d, int col)        { draw(FILLED_RECT_CMD, a, b, c, d, col); }
+    void pixel(int a, int b, int col)                                 { draw(PIX_CMD, a, b, col); }
+    void cls(void)                                                    { draw(CLS_CMD); }
     
-    void pen_size(char sz) { draw(PEN_SZ_CMD, sz); }
     /*void BLIT(int x1, int y1, int x2, int y2, int *colors) {
         int size = abs((x1-x2)*(y1-y2));
         // pad to a multiple of 4 and memset buffer...
@@ -145,11 +143,13 @@
     }
     
     void update() {
+        int buffer_size;
         sock->set_blocking(true, 100);
         if(p1_p2 == PLAYER1) {
-            sock->send_all((char*)buffer, (buffer_idx+1)*sizeof(buffer[0]));
+            buffer_size = buffer_idx;
+            sock->send_all((char*)buffer, (buffer_size+1)*sizeof(buffer[0]));
             buffer_idx = 0;
- 
+            
             int n = sock->receive((char*)buttons, sizeof(buttons));
             if(n < 0) {pc.printf("RECEIVE ERROR.\n");}          
         
@@ -157,40 +157,64 @@
             int n = sock->receive((char*)buffer, sizeof(buffer));  
             if(n < 0) {pc.printf("RECEIVE ERROR.\n");}
             buffer[n] = '\0';   
+            buffer_size = n/sizeof(buffer[0]) - 1;
+            
             sock->send_all((char*)buttons, sizeof(buttons));          
         }
-        
-        int i = 0;    
-        pc.printf("Buffer: ");    
-        while(buffer[i] != '\0') {
+            
+        //pc.printf("Buffer: ");    
+        /*for(int i=0; i<buffer_size; i++) {
             pc.printf("%d ", buffer[i]);
             i++;
         }
         pc.printf("\n");
-        
+        */
         int idx = 0;
-        while(buffer[idx] != '\0') {
+        while(idx < buffer_size) {
             char cmd = buffer[idx];
             idx++;
             
             switch(cmd) {
+                case CLS_CMD:
+                    LCD->cls();
+                    //pc.printf("Clear the screen!\n");
+                    break;
                 case BG_COLOR_CMD:
-                    //LCD->background_color(buffer[idx+1]);
-                    pc.printf("Change the background to %x\n", buffer[idx]);
+                    LCD->background_color(buffer[idx+1]);
+                    //pc.printf("Change the background to 0x%X\n", buffer[idx]);
                     idx += 1;
                     break;
                 case LINE_CMD:
-                    pc.printf("LINE: (%d, %d) - (%d, %d) COLOR: %X\n", buffer[idx], buffer[idx+1], buffer[idx+2], buffer[idx+3], buffer[idx+4]);
+                    //pc.printf("LINE: (%d, %d) - (%d, %d) COLOR: 0x%X\n", buffer[idx], buffer[idx+1], buffer[idx+2], buffer[idx+3], buffer[idx+4]);
+                    LCD->line(buffer[idx], buffer[idx+1], buffer[idx+2], buffer[idx+3], buffer[idx+4]);
                     idx += 5;
                     break;
-                case CLS_CMD:
-                    //LCD->cls();
-                    pc.printf("Clear the screen!\n");
+                case CIRCLE_CMD:
+                    //pc.printf("CIRCLE: (%d, %d), r=%d\n", buffer[idx], buffer[idx+1], buffer[idx+2]);
+                    LCD->circle(buffer[idx], buffer[idx+1], buffer[idx+2], buffer[idx+3]);
+                    idx += 4;
+                    break;
+                case FILLED_CIRCLE_CMD:
+                    //pc.printf("CIRCLE: (%d, %d), r=%d\n", buffer[idx], buffer[idx+1], buffer[idx+2]);
+                    LCD->filled_circle(buffer[idx], buffer[idx+1], buffer[idx+2], buffer[idx+3]);
+                    idx += 4;
                     break;
-                case CIRCLE_CMD:
-                    //LCD->cls();
-                    pc.printf("CIRCLE: (%d, %d), r=%d\n", buffer[idx], buffer[idx+1], buffer[idx+2]);
-                    idx += 4;
+                case TRI_CMD:
+                    //pc.printf("CIRCLE: (%d, %d), r=%d\n", buffer[idx], buffer[idx+1], buffer[idx+2]);
+                    LCD->triangle(buffer[idx], buffer[idx+1], buffer[idx+2], buffer[idx+3], buffer[idx+4], buffer[idx+5], buffer[idx+6]);
+                    idx += 7;
+                    break;
+                case RECT_CMD:
+                    LCD->rectangle(buffer[idx], buffer[idx+1], buffer[idx+2], buffer[idx+3], buffer[idx+4]);
+                    idx += 5;
+                    break;
+                case FILLED_RECT_CMD:
+                    LCD->filled_rectangle(buffer[idx], buffer[idx+1], buffer[idx+2], buffer[idx+3], buffer[idx+4]);
+                    idx += 5;
+                    break;
+                case PIX_CMD:
+                    LCD->pixel(buffer[idx], buffer[idx+1], buffer[idx+2]);
+                    idx += 3;
                     break;
                 default:
                     pc.printf("UNKNOWN CMD %d: This could get ugly!\n", cmd);
@@ -207,10 +231,10 @@
         delete eth; 
     }
  
-    private:
+    //private:
         bool master_slave;
         
-        int buffer[256];
+        int buffer[1024];
         int  buffer_idx;
         
         TCPSocketServer* server;