ECG Study Group / Mbed 2 deprecated Programacao_marco

Dependencies:   mbed

main.cpp

Committer:
Jamess
Date:
2015-04-23
Revision:
2:769c937f9228
Parent:
1:94681b7c2565
Child:
3:7d014ee1c543

File content as of revision 2:769c937f9228:

// Goal: Program that receives and send 4 channels of data.
// Receives: 1kHz
// Sends: 70kbits/s
// Ver qual o melhor modo de blueth (i2C,SPI,UART);
/* DONE:
    Receber sinais Analógicos
  */ 
/* TO DO:
    Juntar ao módulo Bluetooth  
  */

#include "mbed.h"

/*------------Definição de Sinais--------------*/

#define ECG1 0
#define ECG2 1
#define RESP 2
#define PPG 3

/*-----READS THE ANALOG SIGNAL FROM THE SENSORS-----*/

AnalogIn Ecg1(A0);
AnalogIn Ecg2(A1);
AnalogIn Resp(A3);
AnalogIn Ppg(A4);


/*------CONTROLS THE DATA RATE OF THE READING------*/
Ticker t0;
Serial pc(USBTX,USBRX);


/*------HANDLES THE TIMER INTERRUPTIONS------------*/

void t0_handler(void);
void rx_Handler(void);
char test = 0;  // Tests the data received from the computer in order to start the reading 
bool Valor=0;      

/*------------BUFFER TO STORE DATA------------------*/

int buffer[4] = {0,0,0,0};



int main() {
    pc.attach(&rx_Handler, pc.RxIrq);
    t0.attach(&t0_handler,0.001);       //deletar depois de implementar rxhandler baixar programa!!!!!
    

}

/*----------------------FUNCTIONS-----------------------*/

    //Reads and send data to the computer 

void t0_handler(void){
    buffer[ECG1] = Ecg1.read_u16();
    buffer[ECG2] = Ecg2.read_u16();
    buffer[RESP] = Resp.read_u16();
    buffer[PPG] = Ppg.read_u16(); 
    //Esses dados devem ser movidos e mandados o LSB e O MSB um de cada vez, o computador use estes dois dados;
    
    //Não usar printf!!! 
    //Use putc instead!
    
    pc.printf("%i,%i,%i,%i\n",buffer[ECG1],buffer[ECG2],buffer[RESP],buffer[PPG]);
    }

    //This function must 

void rx_Handler(void){
  //Por enquanto estou sem  programa que manda dados... ACHAR NOME PC DE CASA!!!
 /* // test = pc.getc();    // it gets the received character
  // if (test=='s'|| test == 'S')
    {   // wake up routine
  //  t0.attach(&t0_handler,0.001); //start counting ----Data read in a 1kHz freq. (1mS)  
        return;
    }else if (test=='e'|| test == 'E')
        {
    t0.detach();
        }*/
   
}