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:
- 5:b58e5d191b17
- Parent:
- 4:f7d06462819b
- Child:
- 6:27a323008a53
diff -r f7d06462819b -r b58e5d191b17 main.cpp
--- a/main.cpp Wed Apr 29 13:08:15 2015 +0000
+++ b/main.cpp Thu Apr 30 15:49:56 2015 +0000
@@ -12,12 +12,23 @@
#include "mbed.h"
/*--------------Signal Definition-----------------*/
-
+//16bits buffer
#define ECG1 0
#define ECG2 1
#define RESP 2
#define PPG 3
+//8bits buffer
+#define LSB_ECG1 0
+#define MSB_ECG1 1
+#define LSB_ECG2 2
+#define MSB_ECG2 3
+#define LSB_RESP 4
+#define MSB_RESP 5
+#define LSB_PPG 6
+#define MSB_PPG 7
+
+
/*---------------- Sample Speed Timer --------------*/
#define TIMER_RATE 1
@@ -28,6 +39,8 @@
AnalogIn Resp(A3);
AnalogIn Ppg(A4);
+DigitalOut testSpeed(PTE1);
+
/*------CONTROLS THE DATA RATE OF THE READING------*/
Ticker t0;
@@ -40,13 +53,12 @@
void rx_Handler(void);
char test = 0; // Tests the data received from the computer in order to start the reading
-bool Valor=0;
-bool rx_Interrupt = 0;
-bool TimerStatus = 0;
+
/*------------BUFFER TO STORE DATA------------------*/
-int buffer[4] = {0,0,0,0};
+int buffer_16[4] = {0,0,0,0};
+char buffer_8[8] = {0,0,0,0,0,0,0,0};
@@ -54,42 +66,48 @@
pc.printf("main");
pc.attach(&rx_Handler, pc.RxIrq);
- while(1){
-
- while(rx_Interrupt){
-
- if(test == '2'|| test == '2')
- { // wake up routine
- pc.printf("Should go to timer");
- t0.attach(&t0_handler,TIMER_RATE); //start counting ----Data read in a 1kHz freq. (1mS)
-
- }else if (test=='3'|| test == '3')
- {
- t0.detach();
- }
-
+
+ while(1){}
+
+ //aciona porta
- 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]);//PUTC
- TimerStatus = 0;
- }
-
-}}
+ //pc.printf("%i,%i,%i,%i\n",buffer[ECG1],buffer[ECG2],buffer[RESP],buffer[PPG]);//PUTC
+
+
+}
/*----------------------FUNCTIONS-----------------------*/
//Reads and send data to the computer
void t0_handler(void){
- TimerStatus = 1;
+
+//Reads the Analog Ports
+ buffer_16[ECG1] = Ecg1.read_u16();
+ buffer_16[ECG2] = Ecg2.read_u16();
+ buffer_16[RESP] = Resp.read_u16();
+ buffer_16[PPG] = Ppg.read_u16();
+
+//Divides de buffer 16 into multiple buffers;
+
+ buffer_8[LSB_ECG1] = (buffer_16[ECG1]&&0x0F);
+ buffer_8[MSB_ECG1] = (buffer_16[ECG1]&&0xF);
+
+ buffer_8[LSB_ECG2] = (buffer_16[ECG2]&&0x0F);
+ buffer_8[LSB_ECG2] = (buffer_16[ECG2]&&0xF);
+
+ buffer_8[LSB_RESP] = (buffer_16[RESP]&&0x0F);
+ buffer_8[MSB_RESP] = (buffer_16[RESP]&&0xF);
+
+ buffer_8[LSB_PPG] = (buffer_16[PPG]&&0x0F);
+ buffer_8[MSB_PPG] = (buffer_16[PPG]&&0xF);
+
+//Sends to the computer
+ for (int j = 0;j<8;j++){
+ pc.putc(buffer_8[j]);
+ }
+
+
}
//This function must
@@ -99,9 +117,20 @@
// 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);
+ pc.putc(test);//debug
+
+//--Tests the Receive Character----
+
+ if(test == '2'|| test == '2')
+ {
+ t0.attach(&t0_handler,TIMER_RATE);
+
+ }else if (test=='3'|| test == '3')
+ {
+ t0.detach();
+ }
+
}
/*Commit