Grupo T / Mbed OS GRUPOT

classes.h

Committer:
lucasfontenla
Date:
2018-05-17
Revision:
26:f891ff6beb33
Parent:
24:92f612ca218b
Child:
27:3bbc354adea6

File content as of revision 26:f891ff6beb33:

#define tx PC_10
#define rx PC_11

#define sendTime 0.5

Serial ihm(tx, rx); //tx e rx (D1 e D0)

class IHM { 
    int n;
    string buffer;
    char buffer_char[8];
    
    public:
        int debug;
    
        // PUBLIC FUNCTIONS ----------------------------------------------------------------------------------------------------------------------------------------
        void send_position(float X, float Y, float Z){
            //printf("Position sent\n\r");
            buffer = "";
            
            buffer.append("p");
            
            n = sprintf(buffer_char, "X%.2f", X);
            buffer.append(buffer_char);    
            n = sprintf(buffer_char, "Y%.2f", Y);
            buffer.append(buffer_char);  
            n = sprintf(buffer_char, "Z%.2f", Z);
            buffer.append(buffer_char); 
            
            send(buffer); 
        }
        
        void action_complete(void){
            send("a");    
        }

    private:
        
        // PRIVATE FUNCTIONS ----------------------------------------------------------------------------------------------------------------------------------------
        void send(string msg){
            msg.append("x");
            
            for(int i = 0; i < msg.length(); i++){
                ihm.putc(msg[i]);
                wait_ms(15);   
            }
            printf("Sent\n\r");
        }       
};