Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 3:7d014ee1c543
- Parent:
- 2:769c937f9228
- Child:
- 4:f7d06462819b
--- a/main.cpp Thu Apr 23 19:21:58 2015 +0000
+++ b/main.cpp Wed Apr 29 13:01:10 2015 +0000
@@ -11,13 +11,16 @@
#include "mbed.h"
-/*------------Definição de Sinais--------------*/
+/*--------------Signal Definition-----------------*/
#define ECG1 0
#define ECG2 1
#define RESP 2
#define PPG 3
+/*------------- Sample Speed Timer --------*/
+#define TIMER_RATE 1
+
/*-----READS THE ANALOG SIGNAL FROM THE SENSORS-----*/
AnalogIn Ecg1(A0);
@@ -31,12 +34,15 @@
Serial pc(USBTX,USBRX);
-/*------HANDLES THE TIMER INTERRUPTIONS------------*/
+/*------HANDLES THE TIMER AND SERIAL 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;
+bool Valor=0;
+bool rx_Interrupt = 0;
+bool TimerStatus = 0;
/*------------BUFFER TO STORE DATA------------------*/
@@ -45,41 +51,54 @@
int main() {
+ pc.printf("main");
pc.attach(&rx_Handler, pc.RxIrq);
- t0.attach(&t0_handler,0.001); //deletar depois de implementar rxhandler baixar programa!!!!!
+ while(1){
+
+ while(rx_Interrupt){
+
+ if(test == '2'|| test == '2')
+ { // wake up routine
+ t0.attach(&t0_handler,TIMER_RATE); //start counting ----Data read in a 1kHz freq. (1mS)
+
+ }else if (test=='3'|| test == '3')
+ {
+ t0.detach();
+ }
+
+
+ rx_Interrupt = 0;
+ }
+
+ if (TimerStatus){
+
+ buffer[ECG1] = Ecg1.read_u16();
+ buffer[ECG2] = Ecg2.read_u16();
+ buffer[RESP] = Resp.read_u16();
+ buffer[PPG] = Ppg.read_u16();
+ pc.printf("%i,%i,%i,%i\n",buffer[ECG1],buffer[ECG2],buffer[RESP],buffer[PPG]);
+ TimerStatus = 0;
+ }
-}
+}}
/*----------------------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]);
+ TimerStatus = 1;
}
- //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();
- }*/
-
+
+ // A programação não estava funcionando poisnão se deve utilizar interrupções para realizar grandes tarefas;
+ // Elas travam e não funciona mais nada.
+ // Como fazer para não ficar testando no main?? Sexta feira no globo reporter
+
+ rx_Interrupt = 1;
+ test = pc.getc(); // it gets the received character
+ pc.putc(test);
+
}