projeto de corrida

Dependencies:   TermControl

Files at this revision

API Documentation at this revision

Comitter:
diegocavalcanti
Date:
Sat Dec 10 13:43:20 2016 +0000
Commit message:
projeto

Changed in this revision

.gitignore Show annotated file Show diff for this revision Revisions of this file
README.md Show annotated file Show diff for this revision Revisions of this file
TermControl.h Show annotated file Show diff for this revision Revisions of this file
TermControl.lib Show annotated file Show diff for this revision Revisions of this file
img/uvision.png Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 476c153c1126 .gitignore
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.gitignore	Sat Dec 10 13:43:20 2016 +0000
@@ -0,0 +1,4 @@
+.build
+.mbed
+projectfiles
+*.py*
diff -r 000000000000 -r 476c153c1126 README.md
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/README.md	Sat Dec 10 13:43:20 2016 +0000
@@ -0,0 +1,89 @@
+# Getting started with Blinky on mbed OS
+
+This is a very simple guide, reviewing the steps required to get Blinky working on an mbed OS platform.
+
+Please install [mbed CLI](https://github.com/ARMmbed/mbed-cli#installing-mbed-cli).
+
+## Get the example application!
+
+From the command line, import the example:
+
+```
+mbed import mbed-os-example-blinky
+cd mbed-os-example-blinky
+```
+
+### Now compile
+
+Invoke `mbed compile` specifying the name of your platform and your favorite toolchain (`GCC_ARM`, `ARM`, `IAR`). For example, for the ARM Compiler 5:
+
+```
+mbed compile -m K64F -t ARM
+```
+
+Your PC may take a few minutes to compile your code. At the end you should get the following result:
+
+```
+[snip]
++----------------------------+-------+-------+------+
+| Module                     | .text | .data | .bss |
++----------------------------+-------+-------+------+
+| Misc                       | 13939 |    24 | 1372 |
+| core/hal                   | 16993 |    96 |  296 |
+| core/rtos                  |  7384 |    92 | 4204 |
+| features/FEATURE_IPV4      |    80 |     0 |  176 |
+| frameworks/greentea-client |  1830 |    60 |   44 |
+| frameworks/utest           |  2392 |   512 |  292 |
+| Subtotals                  | 42618 |   784 | 6384 |
++----------------------------+-------+-------+------+
+Allocated Heap: unknown
+Allocated Stack: unknown
+Total Static RAM memory (data + bss): 7168 bytes
+Total RAM memory (data + bss + heap + stack): 7168 bytes
+Total Flash memory (text + data + misc): 43402 bytes
+Image: .\.build\K64F\ARM\mbed-os-example-blinky.bin
+```
+
+### Program your board
+
+1. Connect your mbed device to the computer over USB.
+1. Copy the binary file to the mbed device .
+1. Press the reset button to start the program.
+
+You should see the LED of your platform turning on and off.
+
+Congratulations if you managed to complete this test!
+
+## Export the project to Keil MDK and debug your application
+
+From the command line, run the following command:
+
+```
+mbed export -m K64F -i uvision
+```
+
+To debug the application:
+
+1. Start uVision.
+1. Import the uVision project generated earlier.
+1. Compile your application and generate an `.axf` file.
+1. Make sure uVision is configured to debug over CMSIS-DAP (From the Project menu > Options for Target '...' > Debug tab > Use CMSIS-DAP Debugger).
+1. Set breakpoints and start a debug session.
+
+![Image of uVision](img/uvision.png)
+
+## Troubleshooting
+
+1. Make sure `mbed-cli` is working correctly and its version is greater than `0.8.9`
+
+ ```
+ mbed --version
+ ```
+
+ If not, you can update it easily:
+
+ ```
+ pip install mbed-cli --upgrade
+ ```
+
+2. If using Keil MDK, make sure you have a license installed. [MDK-Lite](http://www.keil.com/arm/mdk.asp) has a 32KB restriction on code size.
diff -r 000000000000 -r 476c153c1126 TermControl.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TermControl.h	Sat Dec 10 13:43:20 2016 +0000
@@ -0,0 +1,133 @@
+#ifndef TERMCONTROL_H
+#define TERMCONTROL_H
+#include "mbed.h"
+#include <string>
+//0x1B is escape
+//#define FLASH_STRING const char * const
+
+/** A simple class for sending VT100 terminal escape codes for handling things such as moving the cursor and clearing the screen
+  */
+class TermControl
+{
+    public:
+    TermControl()
+    {
+    
+    }
+    /** @Param term The stream to send the escape codes to
+     */
+    TermControl(Stream* term)
+    {
+        Term=term;
+    }
+    void SetTerminal(Stream* term)
+    {
+        Term=term;
+    }
+    Stream* GetTerminal()
+    {
+        return Term;
+    }
+    //terminal control
+    /** Resets the terminal to defaults
+     */
+    void Reset()
+    {
+        Print("\x1Bc");
+    }
+    /** Clears the screen
+     */
+    void Clear()
+    {
+        Term->printf("\x1B[2J");
+    }
+    /** Prints the specified string at coordinates x,y 
+     *  The cursor position is not changed
+     * 
+     *  @param x The X coordinate, or column
+     *  @param y The Y coordinate, or row
+     *  @param s The string to print
+     */
+    void PrintAt(int x, int y, string s)
+    {
+        SaveCursor();
+        ResetCursor();
+        SetCursor(x,y);
+        Print(s);
+        RestoreCursor();
+    }
+    //todo void PrintfAt(int x, int y, string f, ...);
+    /** Get a character from the terminal stream
+     */
+    char GetChar()
+    {
+        return Term->getc();
+    }
+    /** Sets the cursor's position to x,y
+     */
+    void SetCursor(int x, int y)
+    {
+        Term->printf("\x1B[%i;%iH",y,x);
+    }
+    /** Resets the cursor to (0,0), the top left hand corner of the screen
+     */
+    void ResetCursor()
+    {
+        Term->printf("\x1B[H");
+    }
+    /** Saves the cursor on the display-side. It can only remember one cursor position at a time.
+     * ie, this can't be nested
+     */
+    void SaveCursor()
+    {
+        Term->printf("\x1B[s");
+    }
+    /** Restores the cursor on the display-side. It can only remember and store one cursor position at a time.
+     * ie, this can't be nested
+     */
+    void RestoreCursor()
+    {
+        Term->printf("\x1B[u");
+    }
+    /** Enables a scrolling "window" at the specified beginning and ending rows
+     * @param begin The beginning row
+     * @param end The ending row
+     */
+    void EnableScrolling(int begin, int end) //begin and end are row numbers
+    {
+        Term->printf("\x1B[%i;%ir",begin,end);
+    } 
+    /** Scrolls down the scrolling "window" by 1 line. Note, EnableScrolling is required before this can be called
+     */
+    void ScrollDown()
+    {
+        Term->printf("\x1BD");
+    }
+    /** Scrolls up the scrolling "window" by 1 line. Note, EnableScrolling is required before this can be called
+     */
+    void ScrollUp()
+    {
+        Term->printf("\x1BM");
+    }
+    /** Erases the current line the cursor is on.
+     */
+    void EraseLine()
+    {
+        Term->printf("\x1B[2K");
+    }
+    /** Prints the specified string to the string at the current cursor position
+     */
+    void Print(string s)
+    {
+        Term->puts(s.c_str());
+    }
+    
+    
+    private:
+    Stream *Term;
+};
+    
+
+
+
+#endif
\ No newline at end of file
diff -r 000000000000 -r 476c153c1126 TermControl.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TermControl.lib	Sat Dec 10 13:43:20 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/earlz/code/TermControl/#ef410bacf0e5
diff -r 000000000000 -r 476c153c1126 img/uvision.png
Binary file img/uvision.png has changed
diff -r 000000000000 -r 476c153c1126 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Dec 10 13:43:20 2016 +0000
@@ -0,0 +1,263 @@
+#include "mbed.h"
+#include "stdlib.h"
+#include "rtos.h"
+#include "TermControl.h"
+
+Serial pc(USBTX, USBRX);
+Serial pc2(USBTX, USBRX);
+char tela[20][6];
+bool jogando;
+
+// main() runs in its own thread in the OS
+// (note the calls to Thread::wait below for delays)
+
+bool verificaesquerda(){
+    if(
+    tela[16][1] == 'o' && 
+    tela[17][0] == 'o' &&  
+    tela[17][1] == 'o' && 
+    tela[17][2] == 'o' && 
+    tela[18][1] == 'o' && 
+    tela[19][0] == 'o' && 
+    tela[19][2] == 'o'){
+        return true;               
+    }else{
+        return false;    
+    }    
+}
+bool verificadireita(){
+    if( tela[16][4] == 'o' || 
+            tela[17][3] == 'o' || 
+            tela[17][4] == 'o' || 
+            tela[17][5] == 'o' || 
+            tela[18][4] == 'o' || 
+            tela[19][3] == 'o' || 
+            tela[19][5] == 'o'){
+        return true;               
+    }else{
+        return false;    
+    }    
+}
+
+void car_left(){
+        
+       
+        if(tela[16][1] == 'o' && tela[17][0] == 'o' &&  tela[17][1] == 'o' && tela[17][2] == 'o' && tela[18][1] == 'o' && tela[19][0] == 'o' && tela[19][2] == 'o'){
+            
+        
+                tela[16][1] = 'o';
+                tela[17][0] = 'o';
+                tela[17][1] = 'o';
+                tela[17][2] = 'o';
+                tela[18][1] = 'o';
+                tela[19][0] = 'o';
+                tela[19][2] = 'o';
+            
+        }else{
+            tela[16][4] = ' ';
+            tela[17][3] = ' ';
+            tela[17][4] = ' ';
+            tela[17][5] = ' ';
+            tela[18][4] = ' ';
+            tela[19][3] = ' ';
+            tela[19][5] = ' ';
+            
+            tela[16][1] = 'o';
+            tela[17][0] = 'o';
+            tela[17][1] = 'o';
+            tela[17][2] = 'o';
+            tela[18][1] = 'o';
+            tela[19][0] = 'o';
+            tela[19][2] = 'o';
+        }
+        
+            
+        
+}
+void car_right(){
+        if(tela[16][1] == 'o' && tela[17][0] == 'o' &&  tela[17][1] == 'o' && tela[17][2] == 'o' && tela[18][1] == 'o' && tela[19][0] == 'o' && tela[19][2] == 'o'){
+            tela[16][4] = 'o';
+            tela[17][3] = 'o';
+            tela[17][4] = 'o';
+            tela[17][5] = 'o';
+            tela[18][4] = 'o';
+            tela[19][3] = 'o';
+            tela[19][5] = 'o';
+            
+            tela[16][1] = ' ';
+            tela[17][0] = ' ';
+            tela[17][1] = ' ';
+            tela[17][2] = ' ';
+            tela[18][1] = ' ';
+            tela[19][0] = ' ';
+            tela[19][2] = ' ';
+
+        }else{
+            tela[16][4] = 'o';
+            tela[17][3] = 'o';
+            tela[17][4] = 'o';
+            tela[17][5] = 'o';
+            tela[18][4] = 'o';
+            tela[19][3] = 'o';
+            tela[19][5] = 'o';
+        }
+        
+}
+
+void keyboard(void) {
+    while(jogando) {
+            char comando = pc2.getc();
+            
+                if(comando == 97){
+                    car_left();
+                }
+                if(comando == 100){
+                    car_right();
+                }
+                
+                Thread::wait(500);
+    }
+}
+
+int main() {
+    jogando=true;
+    TermControl ctrl;
+    ctrl.SetTerminal(&pc);
+    Thread t1;
+    t1.start(keyboard);
+    int pontuacao =0;
+    int velocidade = 500;
+   
+    
+    int mov = 1;
+    int new_car = 1;
+    
+    pc.baud(115200);
+    
+    for(int i=0; i < 20; i++){
+        for(int j=0; j < 6; j++){
+            tela[i][j] = ' ';
+            
+        }
+    }
+    
+    int side_car = rand()%2;
+    
+    if(side_car == 0){
+        car_left();
+    }
+    if(side_car == 1){
+        car_right();
+    }
+    
+    while (jogando){
+            
+            if(new_car%8 == 0){
+                pontuacao++;  
+                int lado_carros = rand()%2;
+                pc.printf("%d", lado_carros);
+                pc.printf("\r\n");
+                
+                
+                    if(lado_carros == 0){
+                            tela[0][1] = '#';
+                            tela[1][0] = '#';
+                            tela[1][1] = '#';
+                            tela[1][2] = '#';
+                            tela[2][1] = '#';
+                            tela[3][0] = '#';
+                            tela[3][2] = '#';
+                    }
+                    if(lado_carros == 1){
+                            tela[0][4] = '#';
+                            tela[1][3] = '#';
+                            tela[1][4] = '#';
+                            tela[1][5] = '#';
+                            tela[2][4] = '#';
+                            tela[3][3] = '#';
+                            tela[3][5] = '#'; 
+                    }
+                }
+            new_car++;
+            
+            
+        for(int i = 0; i< 20; i++) {
+            for(int j = 0; j < 6; j++) {
+                pc.printf("%c", tela[i][j]);
+                
+            }
+            pc.printf("\r\n");
+            
+        }    
+            
+       
+        
+        for(int i = 19; i >= 0; i--) {
+             for(int j = 5; j >= 0; j--) {
+                
+                             
+                    bool verifica = verificadireita();
+                    if(verifica){
+                        if(
+                            tela[16][4] == '#' || 
+                            tela[17][3] == '#' || 
+                            tela[17][4] == '#' || 
+                            tela[17][5] == '#' || 
+                            tela[18][4] == '#' || 
+                            tela[19][3] == '#' || 
+                            tela[19][5] == '#' ){            
+                            
+                            
+                            jogando=false;
+                          
+                            break;
+                           
+                        }else if(tela[i][j] == '#'){
+                             tela[i][j] = ' ';
+                              tela[i+mov][j] = '#';
+                              
+                        }
+                                            
+                        
+                    }else {
+                       if(
+                            tela[16][1] == '#' ||               
+                            tela[17][0] == '#' ||
+                            tela[17][1] == '#' ||
+                            tela[17][2] == '#' ||                
+                            tela[18][1] == '#' ||                
+                            tela[19][0] == '#' ||                
+                            tela[19][2] == '#' ){            
+                            
+                            jogando=false;
+                            
+                            break;
+                           
+                        }else if(tela[i][j] == '#'){
+                             tela[i][j] = ' ';
+                              tela[i+mov][j] = '#';
+                              
+                            
+                        }                    
+                        
+                    }//IF
+            }//FOR
+           
+        }//FOR
+        
+        
+         
+              
+        pc.printf("%d", pontuacao);
+        velocidade=velocidade-2;
+        Thread::wait(velocidade);
+        //ctrl.Clear();
+        pc.printf("\x1B[2J");
+    }
+    pc.printf("%s", "GAME OVER!");
+    pc.printf("%s", "SUA PONTUACAO: ");
+    pc.printf("%d", pontuacao);
+
+  
+}
+
diff -r 000000000000 -r 476c153c1126 mbed-os.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Sat Dec 10 13:43:20 2016 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#a1c0840b3d69060e5eb708edb18358e424a40f51