Giro en su propio eje Presentado por: Julio Fajardo, Cesar Pacheco, Angel Trujillo, Daniel Vizcaya

Dependencies:   mbed

Fork of 01_Embebidos by Daniel Vizcaya

01_main.cpp

Committer:
Bethory
Date:
2018-03-12
Revision:
3:3665eb7346e2
Child:
4:8a884a5dd8c8

File content as of revision 3:3665eb7346e2:

#include "mbed.h"
#include "draw.h"
#define CM_EJECUTAR 0xFF
#define CM_GUARDAR 0xFE
#define CM_VERTEX2D 0xFD
#define CM_DRAW 0XFC
#define CM_NODRAW 0xFB
#define CM_STOP 0xFA
#define CM_END 0xF0

#define MEM_SIZE 10
#define MEM_TYPE uint32_t //significa que de ahora en más donde diga MEM_TYPE será tipo uint32_t

uint8_t mem_head = 0;
uint8_t mem_tail = 0;
bool full = 0;

MEM_TYPE buffer[MEM_SIZE];
Serial command(USBTX, USBRX);

void mem_free(){ //Estaba como uint32_t no como void
    mem_head=0;
    full=0;
}

bool mem_put(MEM_TYPE data){ //Escribir
    if (full)
        return 1;
    buffer[mem_head] = data; //carga en dato en el buffer
    mem_head += 1;
    if (mem_head == MEM_SIZE)
        full =1;
    return 0;
}

bool mem_get(MEM_TYPE* data){ //Leer
    if (mem_head == 0)
        return 1; 
    if (mem_head == mem_tail)
        return 1; 
    *data = buffer[mem_tail];
    mem_tail += 1;
    return 0;
}

void ejecutar(){
    command.printf("se inicia el comando de ejecutar...\n");
    /*for(int i=1;i<=MEM_SIZE;i++){
        command.printf("%x\n",buffer[i]);
    }*/
}

void guardar(){
    command.printf("se inicia el comando de guardar...\n");
    MEM_TYPE val; //significa que la variable "val" es del tipo uint32_t
    char raw_data;
    
    while(1 && !full){
        for(int i=1;i<=4;i++){
            raw_data=command.getc();
            command.printf("%x",raw_data);
            if(raw_data==CM_STOP)
                return;
            if(i==1){
                val=raw_data;
            }else{
                
                val=val << 8;
                val=val|raw_data;
            }
            command.printf(" %d",i);
            command.printf(" %x\n",val);
        }
        mem_put(val);
    }
    //mem_get(&val); //&val es la dirección de la variable, no su contenido
    //command.putc(val); //manda por puerto serial el contenido de "val" npi para qué
}

int main(){
    init_servo();
    command.baud(9600);
    home(); //llama a no_draw y va a 0,0
   
    char read_cc;
    while(1){
        read_cc=command.getc();
        switch (read_cc){
            case  CM_EJECUTAR: ejecutar(); break;
            case  CM_GUARDAR: guardar(); break;
            default: command.printf("error de comando \n");break ;      
        }
    }  
}
/*
FE FB FD 00 00 F0
FC F0 FD 32 00 F0
FD 32 32 F0 FD 00
32 F0 FD 00 00 F0
FB F0 FA F0 FF

FE FB 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
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

#define CM_EJECUTAR 0xFF
#define CM_GUARDAR 0xFE
#define CM_VERTEX2D 0xFD
#define CM_DRAW 0XFC
#define CM_NODRAW 0xFB
#define CM_STOP 0xFA
#define CM_END 0xF0
*/