Acercamiento a lo que pide el profe
Fork of 01-01EjercicioFuncionXY by
Tomando como base los ejemplos que el Ing. Ferney subió, realizamos este primer acercamiento al objetivo del primer corte.
en síntesis se generó el código de guardar y ejecutar.
Slds!
01_main.cpp@5:8e100835b017, 2018-03-14 (annotated)
- Committer:
- Bethory
- Date:
- Wed Mar 14 05:17:52 2018 +0000
- Revision:
- 5:8e100835b017
- Parent:
- 4:8a884a5dd8c8
- Child:
- 6:87a37f4163bd
Lista la parte de guardar
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Bethory | 3:3665eb7346e2 | 1 | #include "mbed.h" |
Bethory | 3:3665eb7346e2 | 2 | #include "draw.h" |
Bethory | 3:3665eb7346e2 | 3 | #define CM_EJECUTAR 0xFF |
Bethory | 3:3665eb7346e2 | 4 | #define CM_GUARDAR 0xFE |
Bethory | 3:3665eb7346e2 | 5 | #define CM_VERTEX2D 0xFD |
Bethory | 3:3665eb7346e2 | 6 | #define CM_DRAW 0XFC |
Bethory | 3:3665eb7346e2 | 7 | #define CM_NODRAW 0xFB |
Bethory | 3:3665eb7346e2 | 8 | #define CM_STOP 0xFA |
Bethory | 4:8a884a5dd8c8 | 9 | #define CM_ENTER 0xF0 |
Bethory | 3:3665eb7346e2 | 10 | |
Bethory | 3:3665eb7346e2 | 11 | #define MEM_SIZE 10 |
Bethory | 3:3665eb7346e2 | 12 | #define MEM_TYPE uint32_t //significa que de ahora en más donde diga MEM_TYPE será tipo uint32_t |
Bethory | 3:3665eb7346e2 | 13 | |
Bethory | 3:3665eb7346e2 | 14 | uint8_t mem_head = 0; |
Bethory | 3:3665eb7346e2 | 15 | uint8_t mem_tail = 0; |
Bethory | 3:3665eb7346e2 | 16 | bool full = 0; |
Bethory | 3:3665eb7346e2 | 17 | |
Bethory | 3:3665eb7346e2 | 18 | MEM_TYPE buffer[MEM_SIZE]; |
Bethory | 3:3665eb7346e2 | 19 | Serial command(USBTX, USBRX); |
Bethory | 3:3665eb7346e2 | 20 | |
Bethory | 3:3665eb7346e2 | 21 | void mem_free(){ //Estaba como uint32_t no como void |
Bethory | 3:3665eb7346e2 | 22 | mem_head=0; |
Bethory | 3:3665eb7346e2 | 23 | full=0; |
Bethory | 3:3665eb7346e2 | 24 | } |
Bethory | 3:3665eb7346e2 | 25 | |
Bethory | 3:3665eb7346e2 | 26 | bool mem_put(MEM_TYPE data){ //Escribir |
Bethory | 3:3665eb7346e2 | 27 | if (full) |
Bethory | 3:3665eb7346e2 | 28 | return 1; |
Bethory | 3:3665eb7346e2 | 29 | buffer[mem_head] = data; //carga en dato en el buffer |
Bethory | 3:3665eb7346e2 | 30 | mem_head += 1; |
Bethory | 3:3665eb7346e2 | 31 | if (mem_head == MEM_SIZE) |
Bethory | 3:3665eb7346e2 | 32 | full =1; |
Bethory | 3:3665eb7346e2 | 33 | return 0; |
Bethory | 3:3665eb7346e2 | 34 | } |
Bethory | 3:3665eb7346e2 | 35 | |
Bethory | 3:3665eb7346e2 | 36 | bool mem_get(MEM_TYPE* data){ //Leer |
Bethory | 3:3665eb7346e2 | 37 | if (mem_head == 0) |
Bethory | 3:3665eb7346e2 | 38 | return 1; |
Bethory | 3:3665eb7346e2 | 39 | if (mem_head == mem_tail) |
Bethory | 3:3665eb7346e2 | 40 | return 1; |
Bethory | 3:3665eb7346e2 | 41 | *data = buffer[mem_tail]; |
Bethory | 3:3665eb7346e2 | 42 | mem_tail += 1; |
Bethory | 3:3665eb7346e2 | 43 | return 0; |
Bethory | 3:3665eb7346e2 | 44 | } |
Bethory | 3:3665eb7346e2 | 45 | |
Bethory | 3:3665eb7346e2 | 46 | void ejecutar(){ |
Bethory | 3:3665eb7346e2 | 47 | command.printf("se inicia el comando de ejecutar...\n"); |
Bethory | 5:8e100835b017 | 48 | for(int j=0;j<=mem_head;j++){ |
Bethory | 5:8e100835b017 | 49 | command.printf("%x\n",buffer[j]); |
Bethory | 5:8e100835b017 | 50 | } |
Bethory | 3:3665eb7346e2 | 51 | } |
Bethory | 3:3665eb7346e2 | 52 | |
Bethory | 3:3665eb7346e2 | 53 | void guardar(){ |
Bethory | 3:3665eb7346e2 | 54 | command.printf("se inicia el comando de guardar...\n"); |
Bethory | 5:8e100835b017 | 55 | MEM_TYPE val; //significa que la variable "val" es del tipo uint32_t |
Bethory | 4:8a884a5dd8c8 | 56 | char dato1,dato2; |
Bethory | 5:8e100835b017 | 57 | do{ |
Bethory | 5:8e100835b017 | 58 | dato1=command.getc(); |
Bethory | 5:8e100835b017 | 59 | if(dato1==CM_STOP){ |
Bethory | 5:8e100835b017 | 60 | dato2=command.getc(); |
Bethory | 5:8e100835b017 | 61 | if(dato2==CM_ENTER){ |
Bethory | 5:8e100835b017 | 62 | val=dato1; |
Bethory | 5:8e100835b017 | 63 | mem_put(val); |
Bethory | 5:8e100835b017 | 64 | return; |
Bethory | 5:8e100835b017 | 65 | } |
Bethory | 4:8a884a5dd8c8 | 66 | } |
Bethory | 5:8e100835b017 | 67 | if(dato1==CM_NODRAW|dato1==CM_DRAW){ |
Bethory | 5:8e100835b017 | 68 | dato2=command.getc(); |
Bethory | 5:8e100835b017 | 69 | if(dato2==CM_ENTER){ |
Bethory | 5:8e100835b017 | 70 | val=dato1; |
Bethory | 5:8e100835b017 | 71 | mem_put(val); |
Bethory | 5:8e100835b017 | 72 | } |
Bethory | 4:8a884a5dd8c8 | 73 | } |
Bethory | 5:8e100835b017 | 74 | if(dato1==CM_VERTEX2D){ |
Bethory | 4:8a884a5dd8c8 | 75 | dato2=command.getc(); |
Bethory | 4:8a884a5dd8c8 | 76 | if(dato2<=0x32){ |
Bethory | 5:8e100835b017 | 77 | val=CM_VERTEX2D; |
Bethory | 4:8a884a5dd8c8 | 78 | val=val<<8; |
Bethory | 4:8a884a5dd8c8 | 79 | val=val|dato2; |
Bethory | 4:8a884a5dd8c8 | 80 | dato2=command.getc(); |
Bethory | 5:8e100835b017 | 81 | if(dato2<=0x32){ |
Bethory | 4:8a884a5dd8c8 | 82 | val=val<<8; |
Bethory | 5:8e100835b017 | 83 | val=val|dato2; |
Bethory | 5:8e100835b017 | 84 | dato2=command.getc(); |
Bethory | 5:8e100835b017 | 85 | if(dato2==CM_ENTER){ |
Bethory | 5:8e100835b017 | 86 | val=val<<8; |
Bethory | 5:8e100835b017 | 87 | val=val|CM_ENTER; |
Bethory | 5:8e100835b017 | 88 | mem_put(val); |
Bethory | 5:8e100835b017 | 89 | } |
Bethory | 5:8e100835b017 | 90 | } |
Bethory | 5:8e100835b017 | 91 | } |
Bethory | 5:8e100835b017 | 92 | } |
Bethory | 5:8e100835b017 | 93 | }while(!full); |
Bethory | 4:8a884a5dd8c8 | 94 | } |
Bethory | 4:8a884a5dd8c8 | 95 | |
Bethory | 4:8a884a5dd8c8 | 96 | int main(){ |
Bethory | 4:8a884a5dd8c8 | 97 | init_servo(); |
Bethory | 4:8a884a5dd8c8 | 98 | command.baud(9600); |
Bethory | 4:8a884a5dd8c8 | 99 | home(); //llama a no_draw y va a 0,0 |
Bethory | 4:8a884a5dd8c8 | 100 | |
Bethory | 4:8a884a5dd8c8 | 101 | char read_cc; |
Bethory | 4:8a884a5dd8c8 | 102 | while(1){ |
Bethory | 4:8a884a5dd8c8 | 103 | read_cc=command.getc(); |
Bethory | 4:8a884a5dd8c8 | 104 | switch (read_cc){ |
Bethory | 4:8a884a5dd8c8 | 105 | case CM_GUARDAR: guardar(); break; //FE |
Bethory | 4:8a884a5dd8c8 | 106 | case CM_EJECUTAR: ejecutar(); break; //FF |
Bethory | 4:8a884a5dd8c8 | 107 | default: command.printf("Error de comando \n");break; |
Bethory | 4:8a884a5dd8c8 | 108 | } |
Bethory | 4:8a884a5dd8c8 | 109 | } |
Bethory | 4:8a884a5dd8c8 | 110 | } |
Bethory | 4:8a884a5dd8c8 | 111 | /* |
Bethory | 4:8a884a5dd8c8 | 112 | FE FB FD 00 00 F0 |
Bethory | 4:8a884a5dd8c8 | 113 | FC F0 FD 32 00 F0 |
Bethory | 4:8a884a5dd8c8 | 114 | FD 32 32 F0 FD 00 |
Bethory | 4:8a884a5dd8c8 | 115 | 32 F0 FD 00 00 F0 |
Bethory | 4:8a884a5dd8c8 | 116 | FB F0 FA F0 FF |
Bethory | 4:8a884a5dd8c8 | 117 | |
Bethory | 4:8a884a5dd8c8 | 118 | FE F0 FD 54 32 F0 FC F0 FD 32 00 F0 FD 32 32 F0 FD 00 32 F0 FD 00 00 F0 FB F0 FA F0 FF |
Bethory | 4:8a884a5dd8c8 | 119 | FE 12 34 12 34 12 34 12 34 12 34 12 34 12 34 12 34 12 34 12 34 12 34 12 34 12 FA FF |
Bethory | 4:8a884a5dd8c8 | 120 | |
Bethory | 4:8a884a5dd8c8 | 121 | #define CM_EJECUTAR 0xFF |
Bethory | 4:8a884a5dd8c8 | 122 | #define CM_GUARDAR 0xFE |
Bethory | 4:8a884a5dd8c8 | 123 | #define CM_VERTEX2D 0xFD |
Bethory | 4:8a884a5dd8c8 | 124 | #define CM_DRAW 0XFC |
Bethory | 4:8a884a5dd8c8 | 125 | #define CM_NODRAW 0xFB |
Bethory | 4:8a884a5dd8c8 | 126 | #define CM_STOP 0xFA |
Bethory | 4:8a884a5dd8c8 | 127 | #define CM_END 0xF0 |
Bethory | 4:8a884a5dd8c8 | 128 | |
Bethory | 4:8a884a5dd8c8 | 129 | while(!full){ |
Bethory | 3:3665eb7346e2 | 130 | for(int i=1;i<=4;i++){ |
Bethory | 3:3665eb7346e2 | 131 | raw_data=command.getc(); |
Bethory | 3:3665eb7346e2 | 132 | command.printf("%x",raw_data); |
Bethory | 3:3665eb7346e2 | 133 | if(raw_data==CM_STOP) |
Bethory | 3:3665eb7346e2 | 134 | return; |
Bethory | 3:3665eb7346e2 | 135 | if(i==1){ |
Bethory | 3:3665eb7346e2 | 136 | val=raw_data; |
Bethory | 3:3665eb7346e2 | 137 | }else{ |
Bethory | 3:3665eb7346e2 | 138 | |
Bethory | 3:3665eb7346e2 | 139 | val=val << 8; |
Bethory | 3:3665eb7346e2 | 140 | val=val|raw_data; |
Bethory | 3:3665eb7346e2 | 141 | } |
Bethory | 3:3665eb7346e2 | 142 | command.printf(" %d",i); |
Bethory | 3:3665eb7346e2 | 143 | command.printf(" %x\n",val); |
Bethory | 3:3665eb7346e2 | 144 | } |
Bethory | 3:3665eb7346e2 | 145 | mem_put(val); |
Bethory | 3:3665eb7346e2 | 146 | } |
Bethory | 3:3665eb7346e2 | 147 | //mem_get(&val); //&val es la dirección de la variable, no su contenido |
Bethory | 3:3665eb7346e2 | 148 | //command.putc(val); //manda por puerto serial el contenido de "val" npi para qué |
Bethory | 3:3665eb7346e2 | 149 | |
Bethory | 3:3665eb7346e2 | 150 | */ |