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: SDFileSystem ds3231 eeprom_Nikita mbed testUniGraphic_150217
Fork of merged_code2_20sept_2017_4th_oct_2017 by
Revision 3:9a06c2bed650, committed 2017-02-10
- Comitter:
- nikitateggi
- Date:
- Fri Feb 10 10:39:13 2017 +0000
- Parent:
- 2:3b7b71bfc941
- Child:
- 4:6bd81bb1790d
- Commit message:
- Peak detect to 400 samples
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/PPG/MAX30102.cpp Fri Feb 10 10:39:13 2017 +0000
@@ -0,0 +1,225 @@
+/** \file max30102.cpp ******************************************************
+*
+* Project: MAXREFDES117#
+* Filename: max30102.cpp
+* Description: This module is an embedded controller driver for the MAX30102
+*
+*
+* --------------------------------------------------------------------
+*
+* This code follows the following naming conventions:
+*
+* char ch_pmod_value
+* char (array) s_pmod_s_string[16]
+* float f_pmod_value
+* int32_t n_pmod_value
+* int32_t (array) an_pmod_value[16]
+* int16_t w_pmod_value
+* int16_t (array) aw_pmod_value[16]
+* uint16_t uw_pmod_value
+* uint16_t (array) auw_pmod_value[16]
+* uint8_t uch_pmod_value
+* uint8_t (array) auch_pmod_buffer[16]
+* uint32_t un_pmod_value
+* int32_t * pn_pmod_value
+*
+* ------------------------------------------------------------------------- */
+/*******************************************************************************
+* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
+*
+* Permission is hereby granted, free of charge, to any person obtaining a
+* copy of this software and associated documentation files (the "Software"),
+* to deal in the Software without restriction, including without limitation
+* the rights to use, copy, modify, merge, publish, distribute, sublicense,
+* and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice shall be included
+* in all copies or substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
+* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+* OTHER DEALINGS IN THE SOFTWARE.
+*
+* Except as contained in this notice, the name of Maxim Integrated
+* Products, Inc. shall not be used except as stated in the Maxim Integrated
+* Products, Inc. Branding Policy.
+*
+* The mere transfer of this software does not imply any licenses
+* of trade secrets, proprietary technology, copyrights, patents,
+* trademarks, maskwork rights, or any other form of intellectual
+* property whatsoever. Maxim Integrated Products, Inc. retains all
+* ownership rights.
+*******************************************************************************
+*/
+#include "mbed.h"
+#include "MAX30102.h"
+#define PIN_I2C1_SCL PTC10
+#define PIN_I2C1_SDA PTC11
+
+
+#ifdef TARGET_MAX32600MBED
+I2C i2c(I2C1_SDA, I2C1_SCL);
+#else
+I2C i2c(PIN_I2C1_SDA, PIN_I2C1_SCL);
+
+#endif
+
+bool maxim_max30102_write_reg(uint8_t uch_addr, uint8_t uch_data)
+/**
+* \brief Write a value to a MAX30102 register
+* \par Details
+* This function writes a value to a MAX30102 register
+*
+* \param[in] uch_addr - register address
+* \param[in] uch_data - register data
+*
+* \retval true on success
+*/
+{
+ char ach_i2c_data[2];
+ ach_i2c_data[0]=uch_addr;
+ ach_i2c_data[1]=uch_data;
+
+ if(i2c.write(I2C_WRITE_ADDR, ach_i2c_data, 2, false)==0)
+ return true;
+ else
+ return false;
+}
+
+bool maxim_max30102_read_reg(uint8_t uch_addr, uint8_t *puch_data)
+/**
+* \brief Read a MAX30102 register
+* \par Details
+* This function reads a MAX30102 register
+*
+* \param[in] uch_addr - register address
+* \param[out] puch_data - pointer that stores the register data
+*
+* \retval true on success
+*/
+{
+ char ch_i2c_data;
+ ch_i2c_data=uch_addr;
+ if(i2c.write(I2C_WRITE_ADDR, &ch_i2c_data, 1, true)!=0)
+ return false;
+ if(i2c.read(I2C_READ_ADDR, &ch_i2c_data, 1, false)==0)
+ {
+ *puch_data=(uint8_t) ch_i2c_data;
+ return true;
+ }
+ else
+ return false;
+}
+
+bool maxim_max30102_init()
+/**
+* \brief Initialize the MAX30102
+* \par Details
+* This function initializes the MAX30102
+*
+* \param None
+*
+* \retval true on success
+*/
+{
+ if(!maxim_max30102_write_reg(REG_INTR_ENABLE_1,0xc0)) // INTR setting
+ return false;
+ if(!maxim_max30102_write_reg(REG_INTR_ENABLE_2,0x00))
+ return false;
+ if(!maxim_max30102_write_reg(REG_FIFO_WR_PTR,0x00)) //FIFO_WR_PTR[4:0]
+ return false;
+ if(!maxim_max30102_write_reg(REG_OVF_COUNTER,0x00)) //OVF_COUNTER[4:0]
+ return false;
+ if(!maxim_max30102_write_reg(REG_FIFO_RD_PTR,0x00)) //FIFO_RD_PTR[4:0]
+ return false;
+ if(!maxim_max30102_write_reg(REG_FIFO_CONFIG,0x2f)) //sample avg = 1, fifo rollover=false, fifo almost full = 17 *MADE CHANGES to OF*
+ return false;
+ if(!maxim_max30102_write_reg(REG_MODE_CONFIG,0x02)) //0x02 for Red only, 0x03 for SpO2 mode 0x07 multimode LED
+ return false;
+ if(!maxim_max30102_write_reg(REG_SPO2_CONFIG,0x35)) // SPO2_ADC range = 4096nA, SPO2 sample rate (100 Hz), LED pulseWidth (400uS) 3f for 400Hz,33 for 800, 37 for 1Khz
+ return false;
+
+ if(!maxim_max30102_write_reg(REG_LED1_PA,0x24)) //Choose value for ~ 7mA for LED1
+ return false;
+ if(!maxim_max30102_write_reg(REG_LED2_PA,0x24)) // Choose value for ~ 7mA for LED2
+ return false;
+ if(!maxim_max30102_write_reg(REG_PILOT_PA,0x7f)) // Choose value for ~ 25mA for Pilot LED
+ return false;
+ return true;
+}
+
+bool maxim_max30102_read_fifo(uint32_t *pun_red_led)
+/**
+* \brief Read a set of samples from the MAX30102 FIFO register
+* \par Details
+* This function reads a set of samples from the MAX30102 FIFO register
+*
+* \param[out] *pun_red_led - pointer that stores the red LED reading data
+* \param[out] *pun_ir_led - pointer that stores the IR LED reading data
+*
+* \retval true on success
+*/
+{
+ uint32_t un_temp;
+ unsigned char uch_temp;
+ *pun_red_led=0;
+ //*pun_ir_led=0;
+ char ach_i2c_data[3];
+
+ //read and clear status register
+ maxim_max30102_read_reg(REG_INTR_STATUS_1, &uch_temp);
+ maxim_max30102_read_reg(REG_INTR_STATUS_2, &uch_temp);
+
+ ach_i2c_data[0]=REG_FIFO_DATA;
+ if(i2c.write(I2C_WRITE_ADDR, ach_i2c_data, 1, true)!=0)
+ return false;
+ if(i2c.read(I2C_READ_ADDR, ach_i2c_data, 3, false)!=0)
+ {
+ return false;
+ }
+ un_temp=(unsigned char) ach_i2c_data[0];
+ un_temp<<=16;
+ *pun_red_led+=un_temp;
+ un_temp=(unsigned char) ach_i2c_data[1];
+ un_temp<<=8;
+ *pun_red_led+=un_temp;
+ un_temp=(unsigned char) ach_i2c_data[2];
+ *pun_red_led+=un_temp;
+
+ //un_temp=(unsigned char) ach_i2c_data[3];
+ //un_temp<<=16;
+ //*pun_ir_led+=un_temp;
+ //un_temp=(unsigned char) ach_i2c_data[4];
+ //un_temp<<=8;
+ //*pun_ir_led+=un_temp;
+ //un_temp=(unsigned char) ach_i2c_data[5];
+ //*pun_ir_led+=un_temp;
+ *pun_red_led&=0x03FFFF; //Mask MSB [23:18]
+ //*pun_ir_led&=0x03FFFF; //Mask MSB [23:18]
+
+
+ return true;
+}
+
+bool maxim_max30102_reset()
+/**
+* \brief Reset the MAX30102
+* \par Details
+* This function resets the MAX30102
+*
+* \param None
+*
+* \retval true on success
+*/
+{
+ i2c.frequency(400000);
+ if(!maxim_max30102_write_reg(REG_MODE_CONFIG,0x40))
+ return false;
+ else
+ return true;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PPG/MAX30102.h Fri Feb 10 10:39:13 2017 +0000 @@ -0,0 +1,97 @@ +/** \file max30102.h ****************************************************** +* +* Project: MAXREFDES117# +* Filename: max30102.h +* Description: This module is an embedded controller driver header file for MAX30102 +* +* +* -------------------------------------------------------------------- +* +* This code follows the following naming conventions: +* +* char ch_pmod_value +* char (array) s_pmod_s_string[16] +* float f_pmod_value +* int32_t n_pmod_value +* int32_t (array) an_pmod_value[16] +* int16_t w_pmod_value +* int16_t (array) aw_pmod_value[16] +* uint16_t uw_pmod_value +* uint16_t (array) auw_pmod_value[16] +* uint8_t uch_pmod_value +* uint8_t (array) auch_pmod_buffer[16] +* uint32_t un_pmod_value +* int32_t * pn_pmod_value +* +* ------------------------------------------------------------------------- */ +/******************************************************************************* +* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES +* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +* +* Except as contained in this notice, the name of Maxim Integrated +* Products, Inc. shall not be used except as stated in the Maxim Integrated +* Products, Inc. Branding Policy. +* +* The mere transfer of this software does not imply any licenses +* of trade secrets, proprietary technology, copyrights, patents, +* trademarks, maskwork rights, or any other form of intellectual +* property whatsoever. Maxim Integrated Products, Inc. retains all +* ownership rights. +******************************************************************************* +*/ +#ifndef MAX30102_H_ +#define MAX30102_H_ + +#include "mbed.h" + +#define I2C_WRITE_ADDR 0xAE +#define I2C_READ_ADDR 0xAF + +//register addresses +#define REG_INTR_STATUS_1 0x00 +#define REG_INTR_STATUS_2 0x01 +#define REG_INTR_ENABLE_1 0x02 +#define REG_INTR_ENABLE_2 0x03 +#define REG_FIFO_WR_PTR 0x04 +#define REG_OVF_COUNTER 0x05 +#define REG_FIFO_RD_PTR 0x06 +#define REG_FIFO_DATA 0x07 +#define REG_FIFO_CONFIG 0x08 +#define REG_MODE_CONFIG 0x09 +#define REG_SPO2_CONFIG 0x0A +#define REG_LED1_PA 0x0C +#define REG_LED2_PA 0x0D +#define REG_PILOT_PA 0x10 +#define REG_MULTI_LED_CTRL1 0x11 +#define REG_MULTI_LED_CTRL2 0x12 +#define REG_TEMP_INTR 0x1F +#define REG_TEMP_FRAC 0x20 +#define REG_TEMP_CONFIG 0x21 +#define REG_PROX_INT_THRESH 0x30 +#define REG_REV_ID 0xFE +#define REG_PART_ID 0xFF + +bool maxim_max30102_init(); +bool maxim_max30102_read_fifo(uint32_t *pun_red_led); //(uint32_t *pun_red_led, uint32_t *pun_ir_led); +bool maxim_max30102_write_reg(uint8_t uch_addr, uint8_t uch_data); +bool maxim_max30102_read_reg(uint8_t uch_addr, uint8_t *puch_data); +bool maxim_max30102_reset(void); + +#endif /* MAX30102_H_ */ \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bp.cpp Fri Feb 10 10:39:13 2017 +0000
@@ -0,0 +1,205 @@
+//BP Optimised Program for Averaging the received value from PPG and ECG & Check for SD card Storage//
+
+
+/** ECG ADS1291 Test program.
+ADS1291 is a single channel ECG chip
+with a 24 bit Sigma-Delta ADC
+ */
+
+#include "mbed.h"
+#include "MAX30102.h" // BP ADD
+#include <string.h>
+#include <stdio.h>
+#include "ds3231.h"
+#include "SDFileSystem.h"
+#include "rtc.h"
+#include "sdcard.h"
+#include "ec_bp.h"
+#include "bp.h"
+#include "display_modules.h"
+
+
+Serial bc(USBTX,USBRX);
+DigitalIn INTR(PTC7);
+
+
+
+int bp() {
+
+//------------------BP ADD------------------------------//{
+int location; // BP ADD
+int32_t n_red_buffer_length = 1500; //data length
+uint32_t aun_red_buffer[1500]; //Red LED sensor data, set to 500
+uint32_t red_value;
+uint32_t ecg_value;
+uint8_t uch_dummy;
+uint32_t ecg_buf[1000];
+int32_t ecg_buffer_length = 1000;
+float SBP, DBP, PWV, delta_t;
+int d = 210;
+
+uint32_t un_min, un_max, un_prev_data, ecg_min, ecg_max ; //variables to calculate the on-board LED brightness that reflects the heartbeats
+ int i, j;
+ float ecg_location, ppg_location;
+ int32_t n_brightness;
+
+ n_brightness=0;
+ un_min=0x3FFFF;
+ un_max=0;
+ ecg_min = 0xFFFFFF;
+ ecg_max = 0;
+ //---------------- BP ADD-----------------------------//}
+
+
+ //time_t epoch_time;
+ //int fp;
+ int concatenate_value1 = 0;
+//uint32_t ecg_buf[1500];
+//int32_t ecg_der[1500];
+//int buff1[15]= {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
+int32_t sample_sum; // static int32_t avg[1500];
+ int32_t count = 0; int32_t fs = 500; int32_t w=0,w1=0;
+
+ unsigned char chk = 1;
+ bc.baud(baud_rate);
+ // mySpi.frequency(freq) ;
+ // mySpi.format(bits, mode) ;
+ freqset();
+ // Ds3231 rtc(PTC11, PTC10); //sda,scl2yy
+
+ //------------------BP ADD---------------------------// {
+ while(bc.readable()==0)
+ {
+ bc.printf("\x1B[2J"); //clear terminal program screen
+ bc.printf("Press any key to start conversion\n\r");
+ wait(1);
+ }
+ wait(5);
+ bc.printf("Start of capture, Remain CALM and Donot MOVE\n");
+ wait(2);
+ //-------------------BP ADD---------------------------//}
+
+ setupfunc();
+ ecgsetupfunc();
+ //--------------- BP ADD------------------------------------//{
+ maxim_max30102_reset(); // PPG reset
+ maxim_max30102_init(); // PPG ADC register Initialise
+ //---------------BP ADD ----------------------------------// }
+
+
+ chk = 1;
+ bc.printf("rawecg......................\n");
+ for(int i=0; i<N_ECG; i++)
+ {
+
+ concatenate_value1=readvalue();
+ ecg_buf[i] = concatenate_value1;
+
+ bc.printf( "%d\n", concatenate_value1);
+ maxim_max30102_read_reg(0,&uch_dummy);
+ while(INTR.read()==1);
+ maxim_max30102_read_fifo((aun_red_buffer+i));
+ //bc.printf( "%d\n", concatenate_value1);
+ // bc.printf("%d\n",aun_red_buffer[i]);
+ //sd_write(concatenate_value); - -- BP ADD commented
+ //printf( "%d\n", concatenate_value); -- BP ADD commented
+ // bc.printf("loop2");
+ }
+
+ for (int w=1000; w < n_red_buffer_length; w++) // for reading extra 500 PPG samples.
+ {
+ //bc.printf("loop2");
+ while(INTR.read()==1);
+ maxim_max30102_read_fifo((aun_red_buffer+w));
+ }
+
+
+ //sd_close(); -- BP ADD commented
+
+ int32_t ecg_n_denom;
+
+ // 4 pt Moving Average ECG
+ bc.printf("PRINTING ECG 4 POINT IN DECIMAL........\n");
+ for(int y=0; y<996; y++){
+ ecg_n_denom= ( ecg_buf[y]+ ecg_buf[y+1]+ ecg_buf[y+2]+ ecg_buf[y+3]);
+ ecg_buf[y]= ecg_n_denom/(int32_t)4;
+ }
+ for( int l= 0; l<1000; l++){
+ bc.printf("%d\n",ecg_buf[l]); //PRINTING ecg AFTER AVERAGING
+ }
+bc.printf("PRINTING PPG IN DECIMAL (after averaging)........\n");
+int32_t ppg_n_denom;
+ // 4 pt Moving Average PPG
+ for(int f=0; f<1496; f++){
+ ppg_n_denom= ( aun_red_buffer[f]+aun_red_buffer[f+1]+ aun_red_buffer[f+2]+ aun_red_buffer[f+3]);
+ aun_red_buffer[f]= ppg_n_denom/(int32_t)4;
+ }
+ for( int b = 0; b<1500; b++){
+ bc.printf("%d\n",aun_red_buffer[b]);
+ }
+
+
+for(int f=0; f<ecg_buffer_length; f++)
+ {
+ if(ecg_min > ecg_buf[f])
+ ecg_min = ecg_buf[f]; //update signal min
+ if(ecg_max < ecg_buf[f])
+ {
+ ecg_max=ecg_buf[f]; //update signal max
+ ecg_location = f+1;
+ }
+ }
+ bc.printf( "ecg_location = %f\n", ecg_location);
+
+for(int g = ecg_location; g < (ecg_location+400); g++) // Peak detect changed to 400 samples from 500 samples
+ {
+ if(un_min>aun_red_buffer[g])
+ un_min=aun_red_buffer[g]; //update signal min
+ if(un_max<aun_red_buffer[g])
+ {
+ un_max=aun_red_buffer[g]; //update signal max
+ ppg_location = g+1;
+ }
+ }
+bc.printf( "ppg_location = %f\n", ppg_location);
+
+delta_t = (2*(ppg_location - ecg_location))/1000;
+bc.printf( "delta_t = %f\n", delta_t);
+
+PWV = d/delta_t;
+bc.printf( "PWV = %f\n", PWV);
+
+SBP = 0.0508955*PWV+62.559;
+DBP = 0.0494*PWV + 17.480;
+
+
+bc.printf( "SBP = %f\n", SBP);
+bc.printf( "DBP = %f\n", DBP);
+
+screen_bp1(SBP,DBP);
+
+
+//-----------------WRITE ECG &PPG
+
+sd_open_BPfile(1);
+for (int w=0; w < 1000; w++)
+{
+ecg_value = ecg_buf[w];
+sd_write(ecg_value);
+}
+
+
+
+for (int w=0; w < n_red_buffer_length; w++)
+{
+red_value = aun_red_buffer[w];
+sd_write(red_value);
+}
+sd_close();
+
+//----------- FINISHED WRITING ECG & PPG TO SD CARD
+
+
+
+
+ } // End of main function
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bp.h Fri Feb 10 10:39:13 2017 +0000 @@ -0,0 +1,8 @@ +#ifndef BP_H_ +#define BP_H_ + + +int bp(); +#endif + +
--- a/display_modules.cpp Mon Jan 30 10:57:38 2017 +0000
+++ b/display_modules.cpp Fri Feb 10 10:39:13 2017 +0000
@@ -4,7 +4,7 @@
#include "display_modules.h"
#include "touch_modules.h"
#include "rtc.h"
-#include "main.h"
+//#include "main.h"
BusOut dataBus( PTC12, PTC13, PTB10, PTC9, PTD4, PTD5, PTD6, PTD7 ); // 16 pins//POC
@@ -20,7 +20,6 @@
{
char buff1[32];
time_t epoch_time;
- DisableTouch();
lcd.ClearScreen();
lcd.SetFont(&TerminusFont);
epoch_time=rtc_read();
@@ -34,15 +33,14 @@
lcd.Print( "CONFIG",70,170,COLOR_BLACK,COLOR_YELLOW,0);
lcd.FillRoundRect(60,230,180,300,COLOR_GREEN);
lcd.Print( "TEST",90,250,COLOR_BLACK,COLOR_GREEN,0);
- EnableTouch();
-
- }
+
+ }
void screen_main_2(int pid)//main screen
{
char buff2[10];
- DisableTouch();
+
lcd.FillRect(5,10,250,120,COLOR_BLACK);
//lcd.Print( "SenseSmart", CENTER, 95);
sprintf(buff2 ,"%d", pid);
@@ -50,7 +48,9 @@
lcd.Print(buff2,200,50,COLOR_YELLOW,COLOR_BLACK, 0);
lcd.SetFont(&TerminusBigFont);
- lcd.FillRect(5,120,230,320,COLOR_BLACK);
+ // lcd.FillRect(5,120,230,320,COLOR_BLACK);
+ lcd.FillRoundRect(60,130,180,200,COLOR_BLACK);
+ lcd.FillRoundRect(60,230,180,300,COLOR_BLACK);
lcd.FillRoundRect(10,130,100,200,COLOR_CYAN);
lcd.Print( "BG",40,160,COLOR_BLACK,COLOR_CYAN,0);
lcd.FillRoundRect(130,130,220,200,COLOR_YELLOW);
@@ -59,14 +59,14 @@
lcd.Print( "BP",40,245,COLOR_BLACK,COLOR_MAGENTA,0);
lcd.FillRoundRect(130,215,220,285,COLOR_GREEN);
lcd.Print( "HOME",150,245,COLOR_BLACK,COLOR_GREEN,0);
- EnableTouch();
+
}
void screen_main_1()//main screen
{
- DisableTouch();
+
lcd.SetFont(&TerminusBigFont);
lcd.FillRect(5,127,230,320,COLOR_BLACK);
lcd.FillRoundRect(10,130,100,200,COLOR_CYAN);
@@ -77,71 +77,116 @@
lcd.Print( "FILE",20,245,COLOR_BLACK,COLOR_MAGENTA,0);
lcd.FillRoundRect(130,215,220,285,COLOR_GREEN);
lcd.Print( "HOME",145,245,COLOR_BLACK,COLOR_GREEN,0);
- EnableTouch();
+
}
void screen_ecg()
{
- DisableTouch();
- lcd.FillRect(5,127,230,320,COLOR_BLACK);
+
+ // lcd.FillRect(5,127,230,320,COLOR_BLACK);
+
+ lcd.FillRoundRect(10,130,100,200,COLOR_BLACK);
+ lcd.FillRoundRect(130,130,220,200,COLOR_BLACK);
+ lcd.FillRoundRect(10,215,100,285,COLOR_BLACK);
+ lcd.FillRoundRect(130,215,220,285,COLOR_BLACK);
+
lcd.FillRoundRect(60,130,180,200,COLOR_YELLOW);
lcd.Print( "START",80,150,COLOR_BLACK,COLOR_YELLOW,0);
// lcd.Print( "CONFIG",70,170,COLOR_BLACK,COLOR_YELLOW,0);
lcd.FillRoundRect(60,230,180,300,COLOR_GREEN);
lcd.Print( "RET",100,250,COLOR_BLACK,COLOR_GREEN,0);
- EnableTouch();
+
}
void screen_ecg_2()
{
- DisableTouch();
- lcd.FillRect(5,90,230,320,COLOR_BLACK);
- lcd.Print( "DONE", CENTER, 95);
+
+ lcd.FillRect(5,90,230,150,COLOR_BLACK);
+ lcd.Print( " Tst is Done ",3,150,COLOR_GREEN,COLOR_BLACK,0);
+ // lcd.Print( "DONE", CENTER, 95);
+ // lcd.Print( "s Done ",80,150,COLOR_GREEN,COLOR_BLACK,0);
+ lcd.FillRect(10,215,230,290,COLOR_BLACK);
+ // lcd.FillRoundRect(10,215,100,285,COLOR_MAGENTA);
+ // lcd.FillRoundRect(130,215,220,285,COLOR_GREEN);
lcd.FillRoundRect(60,230,180,300,COLOR_GREEN);
lcd.Print( "RET",100,250,COLOR_BLACK,COLOR_GREEN,0);
- EnableTouch();
+
}
void screen_bp() // bp main screen
{
- DisableTouch();
- lcd.FillRect(5,127,230,320,COLOR_BLACK);
+ lcd.FillRoundRect(10,130,100,200,COLOR_BLACK);
+ lcd.FillRoundRect(130,130,220,200,COLOR_BLACK);
+ lcd.FillRoundRect(10,215,100,285,COLOR_BLACK);
+ lcd.FillRoundRect(130,215,220,285,COLOR_BLACK);
+
lcd.FillRoundRect(60,130,180,200,COLOR_YELLOW);
lcd.Print( "START",80,150,COLOR_BLACK,COLOR_YELLOW,0);
// lcd.Print( "CONFIG",70,170,COLOR_BLACK,COLOR_YELLOW,0);
lcd.FillRoundRect(60,230,180,300,COLOR_GREEN);
lcd.Print( "RET",100,250,COLOR_BLACK,COLOR_GREEN,0);
- EnableTouch();
- }
+
+ }
+
+ void screen_bp1(float SBP, float DBP) // bp main screen
+ {
+ lcd.FillRoundRect(3,130,200,200,COLOR_BLACK);
+ lcd.FillRoundRect(60,230,180,300,COLOR_BLACK);
+ char buf[10];
+ sprintf (buf, "SBP: %f",SBP);
+ lcd.Print( buf, 5,100,COLOR_CYAN,COLOR_BLACK, 0);
+ sprintf (buf, "DBP: %f",DBP);
+ lcd.Print( buf, 5,150,COLOR_CYAN,COLOR_BLACK, 0);
+ lcd.FillRoundRect(60,230,180,300,COLOR_GREEN);
+ lcd.Print( "RET",100,250,COLOR_BLACK,COLOR_GREEN,0);
+}
+
+
+
void screen_glc() // glc main screen
{
- DisableTouch();
+
//lcd.FillRect(5,127,230,320,COLOR_BLACK);
- lcd.FillRect(5,127,230,320,COLOR_BLACK);
+ // lcd.FillRect(5,127,230,320,COLOR_BLACK);
+ lcd.FillRoundRect(10,130,100,200,COLOR_BLACK);
+ lcd.FillRoundRect(130,130,220,200,COLOR_BLACK);
+ lcd.FillRoundRect(10,215,100,285,COLOR_BLACK);
+ lcd.FillRoundRect(130,215,220,285,COLOR_BLACK);
lcd.FillRoundRect(60,130,180,200,COLOR_YELLOW);
lcd.Print( "START",80,150,COLOR_BLACK,COLOR_YELLOW,0);
lcd.FillRoundRect(60,230,180,300,COLOR_GREEN);
lcd.Print( "RET",100,250,COLOR_BLACK,COLOR_GREEN,0);
- EnableTouch();
+
}
+ void screen_bp2()
+ {
+
+
+ lcd.FillRoundRect(3,130,200,200,COLOR_BLACK);
+ lcd.FillRoundRect(60,230,180,300,COLOR_BLACK);
+ lcd.FillRect(5,215,230,290,COLOR_BLACK);
+
-
+}
void ecg_countdown()
{
char tim1[5];
- DisableTouch();
- lcd.DrawRect(20,90,90,40,COLOR_BLACK);
- lcd.FillRect(5,127,230,320,COLOR_BLACK);
+
+ // lcd.DrawRect(20,90,90,40,COLOR_BLACK);
+ // lcd.FillRect(5,127,230,320,COLOR_BLACK);
+ lcd.FillRoundRect(3,130,200,200,COLOR_BLACK);
+ lcd.FillRoundRect(60,230,180,300,COLOR_BLACK);
+ lcd.FillRect(5,215,230,290,COLOR_BLACK);
lcd.Print( "ECG starts in", CENTER, 95);
for(int i=5;i>=0;i--)
{
@@ -151,14 +196,14 @@
}
lcd.Print( "Tst in Progres",3,150,COLOR_GREEN,COLOR_BLACK,0);
- EnableTouch();
+
}
void screen_again()
{
- DisableTouch();
+
//lcd.DrawRect(20,90,90,40,COLOR_BLACK);
lcd.FillRect(5,127,230,200,COLOR_BLACK);
lcd.Print( "Take test",50,130 ,COLOR_CYAN,COLOR_BLACK, 0);
@@ -172,42 +217,45 @@
void screen_glc_2()
{
- DisableTouch();
+
lcd.FillRect(5,127,230,320,COLOR_BLACK);
lcd.FillRoundRect(60,230,180,300,COLOR_GREEN);
lcd.Print( "RET",100,250,COLOR_BLACK,COLOR_GREEN,0);
- EnableTouch();
+
}
void glc_1()
{
- DisableTouch();
+
//lcd.ClearScreen();
- lcd.DrawRect(20,90,90,40,COLOR_BLACK);
- lcd.FillRect(5,127,230,320,COLOR_BLACK);
+ // lcd.DrawRect(20,90,90,40,COLOR_BLACK);
+ // lcd.FillRect(5,127,230,320,COLOR_BLACK);
+ lcd.FillRoundRect(3,130,200,200,COLOR_BLACK);
+ lcd.FillRoundRect(60,230,180,300,COLOR_BLACK);
+ lcd.FillRect(5,215,230,290,COLOR_BLACK);
lcd.Print( "BLOOD GLUCOSE",20,130 ,COLOR_CYAN,COLOR_BLACK, 0); // align text to center horizontally and use starndard colors
lcd.Print( "Insert strip",5,160,COLOR_MAGENTA,COLOR_BLACK, 0); // align text to center horizontally and use starndard colors
}
void glc_2()
{
- DisableTouch();
+
lcd.Print( "Strip Detected",5,160, COLOR_GREEN,COLOR_BLACK, 0);
lcd.Print( "Insert Blood",5,190,COLOR_RED,COLOR_BLACK, 0);
}
void glc_3()
{
- DisableTouch();
+
lcd.Print( "Blood Detected",5,190,COLOR_GREEN,COLOR_BLACK, 0);
lcd.Print( "computing", 5,220,COLOR_MAGENTA,COLOR_BLACK, 0);
}
void glc_4(unsigned int mgdl)
{
- DisableTouch();
+
lcd.FillRect(5,127,230,320,COLOR_BLACK);
char buf[10];
sprintf (buf, "BG is %d mg/dl",mgdl);
--- a/display_modules.h Mon Jan 30 10:57:38 2017 +0000 +++ b/display_modules.h Fri Feb 10 10:39:13 2017 +0000 @@ -18,4 +18,5 @@ void glc_4(unsigned int mgdl); void screen_again(); void screen_glc_2(); + void screen_bp1(float SBP, float DBP) ; #endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ec_bp.cpp Fri Feb 10 10:39:13 2017 +0000
@@ -0,0 +1,343 @@
+#include "mbed.h"
+#include "ec_bp.h"
+//#include "ecg_dec.h"
+
+//PIN DECLARATIONS
+//Serial pc(USBTX,USBRX);
+SPI mySpi(PIN_MOSI, PIN_MISO, PIN_SCLK) ;
+DigitalIn DRDY_BAR(PTC8);
+
+DigitalOut CHIPSEL_BAR(PTD0);
+DigitalOut ADS_START(PTC16);
+DigitalOut RESET_BAR(PTC17);
+DigitalOut myled(LED1);
+PwmOut led(PTB18);
+ float value = 0;
+ unsigned int value1;
+ unsigned int value2;
+ unsigned int value3;
+ unsigned int value4;
+ unsigned int value5;
+ unsigned int value6;
+ unsigned int data1;
+ unsigned int count;
+
+//unsigned char chk2= 0;
+//float value = 0;
+/*unsigned int value1 = 0;
+unsigned int value2 = 0;
+unsigned int value3 = 0;
+unsigned int value4 = 0;
+unsigned int value5 = 0;
+unsigned int value6 = 0;
+unsigned int data1 = 0;
+unsigned int count = 0;*/
+
+//static int32_t ecg_x[500];
+ /* SPI is the spi function written in mbed and mySpi is the instance name*/
+
+typedef void (*func_ptr)(void) ; /*creates typedef to function pointer, does not take any arguement and returns void*/
+
+
+void lpf_coef(void);
+float lpf( float coeff[5], float);
+void drdy_int(void);
+/*FILE *sd_openfile(char *buf);
+void sd_write (FILE *n,int value);
+void sd_close(FILE *n);
+time_t rtc_read();*/
+
+typedef struct _cmd_func {
+ char *name ;
+ func_ptr func ;
+} cmd_func_type ;
+
+cmd_func_type cmd_list[] = { /*"cmd_func_type cmd_list[]" is same as "struct cmd_list[]"*/
+ {"help", doHelp},
+ {"status", doStatus},
+ {"freq", doFreq},
+ {"mode", doMode},
+ {"bit", doBit},
+ {"write", doWrite},
+ {"read", doRead},
+ {"loop", doLoop},
+ { 0, 0 }
+} ;
+
+func_ptr getFunc(char *cmd) /*here "func_ptr is same as void*/
+{
+ int i = 0 ;
+ while(cmd_list[i].name != 0) {
+ if (strcmp(cmd, cmd_list[i].name) == 0) {
+ return(cmd_list[i].func) ; ;
+ }
+ i++ ;
+ }
+ return(0) ;
+}
+
+void doHello()
+{
+ printf("=== spi test program ===\n\r") ;
+ printf("please set your terminal program\n\r") ;
+ printf("local echo on\n\r") ;
+ printf("\n\r") ;
+}
+
+
+void setup()
+{
+ //initially make all inputs low until power is up and stabilized
+ CHIPSEL_BAR = 0;
+ ADS_START = 0;
+ RESET_BAR = 0;
+ //wait for oscillator to wake up
+ wait(1);
+
+ CHIPSEL_BAR = 1;
+ RESET_BAR = 1; //wait for tpor time
+ //wait for power on reset
+ wait(1);
+ RESET_BAR = 0; // send a reset pulse and wait for t_reset amount of time
+ wait(1);
+ RESET_BAR = 1;//release the reset
+ //Wait for 18 tclks = 36 us
+ wait_us(36);
+
+ //Device wakes up in RDATAC mode so send SDATAC command to write to registers
+ cmdWrite(CMD_SDATAC) ;
+// printf("Device is in SDATAC mode\n");
+
+ regRead(REG_ID);
+ printf("DEVICE ID register read from ADS is= 0x%X\n",data1);
+ wait(1);
+
+ //Since we are using internal 2.42V reference and enable clock on the CLK PIN
+ //Write 0xA8 to CONFIG2 register
+ regWrite(REG_CONFIG2,no_mode);
+
+ //Set continuous sampling mode, 500 SPS
+ regWrite(REG_CONFIG1,sps500);
+
+ //PGA Gain = 6, inputs shorted for noise measurements
+ regWrite(REG_CH1SET, offset_meas);
+
+ //read data from CONFIG2 register
+ regRead(REG_CONFIG2);
+// printf("REG_CONFIG2 register read from ADS for initial setup is= 0x%X\n",data1);
+
+ //read data from CONFIG1 register
+ regRead(REG_CONFIG1);
+// printf("REG_CONFIG1 register read from ADS for initial setup is= 0x%X\n",data1);
+
+ //read data from CONFIG1 register
+ regRead(REG_CH1SET);
+// printf("REG_CH1SET register read from ADS for initial setup is= 0x%X\n",data1);
+}
+
+void testsetup()
+{
+ //Send SDATAC command to write to registers to set test signals
+ cmdWrite(CMD_SDATAC) ;
+ printf("Device is in SDATAC mode\n");
+
+ //Since we are using internal 2.42V reference and enable clock on the CLK PIN
+ //Write 0xA3 to CONFIG2 register to set test signal and its freq = 1Hz
+ regWrite(REG_CONFIG2,test_mode);
+
+ //PGA Gain = 6, test signal selected
+ regWrite(REG_CH1SET, test_inp);
+
+ //read data from CONFIG2 register
+ regRead(REG_CONFIG2);
+ printf("REG_CONFIG2 register read from ADS for test signal setup is= 0x%X\n",data1);
+
+ //read data from CONFIG1 register
+ regRead(REG_CH1SET);
+ printf("REG_CH1SET register read from ADS for test signal setup is= 0x%X\n",data1);
+}
+
+void ecgsetup()
+{
+cmdWrite(CMD_SDATAC) ; //Set to SDATAC mode to set CH1SET register
+
+regWrite(REG_CONFIG1,sps500);
+regWrite(REG_CONFIG2, default_mode);//put INT_TEST and TEST_FREQ bits to default mode(set those bits to '0')
+regWrite(REG_LOFF, loff_conf);
+regWrite(REG_CH1SET, elec_inp);// Set to read normal electrode input
+regWrite(REG_RLD_SENS, rld_sens_sig);//Set RLD_SENS
+regWrite(REG_LOFF_SENS, loff_sens_sig);//Set LOFF_SENS
+regWrite(REG_MISC1, misc1_inp );//Set RESP1
+regWrite(REG_MISC2, misc2_inp );//Set RESP2
+//printf("connect ECG leads\n");
+wait(0.5);
+regRead(REG_LOFF_STAT);//Read LOFF_STAT register
+printf("REG_LOFF_STAT register read from ADS for ecg setup is= 0x%X\n",data1);
+}
+
+void doHelp(void)
+{
+ printf("=== spi test ===\n\r") ;
+ printf("commands available\n\r") ;
+ printf("help\n\r") ;
+ printf("status\n\r") ;
+ printf("freq freq_in_hz\n\r") ;
+ printf("mode (0 | 1 | 2 | 3)\n\r") ;
+ printf("bit (4 - 16)\n\r") ;
+ printf("write value\n\r") ;
+ printf("read\n\r") ;
+ printf("loop number (set repeat number for read/write)\n\r") ;
+}
+
+void doStatus(void)
+{
+ printf("=== Status Report ===\n\r") ;
+ printf("bits: %d\n\r", bits) ;
+ printf("mode: %d\n\r", mode) ;
+ printf("freq: %d Hz\n\r", freq) ;
+ printf("loop: %d\n\r", loop) ;
+}
+
+void doFreq(void)
+{
+ // int freq = 0 ;
+ // scanf("%d", &freq) ;
+ printf("setting frequency to %d\n\r", freq) ;
+ mySpi.frequency(freq) ;
+}
+
+void doMode(void)
+{
+ //scanf("%d", &mode) ;
+ printf("setting format(%d, %d)\n\r",bits, mode) ;
+ mySpi.format(bits, mode) ;
+}
+
+void doBit(void)
+{
+ // scanf("%d", &bits) ;
+ printf("setting format(%d, %d)\n\r",bits, mode) ;
+ mySpi.format(bits, mode) ;
+}
+
+void doWrite(void)
+{
+
+ //DRDY_BAR1.disable_irq();
+
+ CHIPSEL_BAR = 0;
+ // int freq1 = 50000;
+ // mySpi.frequency(freq1) ;
+ value1 = mySpi.write(0x00);
+ value2 = mySpi.write(0x00);
+ value3 = mySpi.write(0x00);
+ value4 = mySpi.write(0x00);
+ value5 = mySpi.write(0x00);
+ value6 = mySpi.write(0x00);
+
+ CHIPSEL_BAR = 0;
+ //DRDY_BAR1.enable_irq();
+}
+
+void doRead(void)
+{
+ int dummy = 0 ;
+
+ while(!DRDY_BAR)
+ ADS_START = 0;
+
+ value = mySpi.write(dummy) ;
+
+}
+
+void doLoop(void)
+{
+ // scanf("%d", &loop) ;
+ printf("repeat number has been set to %d\n\r", loop) ;
+}
+
+void cmdWrite(int data)
+{
+ CHIPSEL_BAR = 0;
+ mySpi.write(data) ;
+ wait_ms(1);
+ CHIPSEL_BAR = 1;
+}
+
+void regWrite(int address, int data)
+{
+ int data_to_send = CMD_WREG << 5;
+ data_to_send = data_to_send | address;
+ CHIPSEL_BAR = 0;
+ mySpi.write(data_to_send);
+ wait_ms(1);
+ mySpi.write(0x00) ;
+ wait_ms(1);
+ mySpi.write(data) ;
+ wait_ms(1);
+ CHIPSEL_BAR = 1;
+}
+
+void regRead(int address)
+{
+ int data_to_receive = CMD_RREG << 5;
+ data_to_receive = data_to_receive | address;
+ CHIPSEL_BAR = 0;
+ mySpi.write(data_to_receive);
+ wait_ms(1);
+ mySpi.write(0x00) ;
+ wait_ms(1);
+ data1 = mySpi.write(0x00) ;
+
+ //printf("DEVICE ID register read from ADS is= 0x%X\n",data1);
+
+ //wait_ms(1);
+ CHIPSEL_BAR = 1;
+}
+
+
+
+void freqset()
+{
+mySpi.frequency(freq) ;
+ mySpi.format(bits, mode) ;
+ }
+
+
+
+ void setupfunc()
+ {
+ setup() ;
+ cmdWrite(CMD_RDATAC) ;
+ ADS_START = 1;
+ }
+
+ void ecgsetupfunc()
+{
+ ecgsetup(); // To set the ADS1291 registers for ECG signal generation
+ cmdWrite(CMD_RDATAC) ;
+ ADS_START = 1;
+
+ }
+
+ void ecgtestsetupfunc()
+{
+ testsetup(); // To set the ADS1291 registers for ECG signal generation
+ cmdWrite(CMD_RDATAC) ;
+ ADS_START = 1;
+
+ }
+int readvalue()
+ {
+ int concatenate_value;
+ while(DRDY_BAR);
+ doWrite() ;
+ concatenate_value = ((value4<< 16)|(value5 <<8) |(value6));
+
+ return concatenate_value;
+ }
+
+
+
+
+
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ec_bp.h Fri Feb 10 10:39:13 2017 +0000 @@ -0,0 +1,100 @@ +#ifndef EC_BP_H_ +#define EC_BP_H_ + +typedef void (*func_ptr)(void) ; /*creates typedef to function pointer, does not take any arguement and returns void*/ + +void doHelp(void) ; +void doStatus(void) ; +void doFreq(void) ; +void doMode(void) ; +void doBit(void) ; +void doWrite(void) ; +void doWrite2(void) ; +void doRead(void) ; +void doLoop(void) ; +void setup(void); +void testsetup(void); +void ecgsetup(void); +void regWrite(int,int); +void cmdWrite(int); +void regRead(int); +void lpf_coef(void); +float lpf( float coeff[5], float); +void drdy_int(void); +void freqset(); +void ecgtestsetupfunc(); + +#define PIN_MOSI PTA16 +#define PIN_MISO PTA17 +#define PIN_SCLK PTD1 +#define MA4_SIZE 4 // DO NOT CHANGE +//SDFileSystem sd(PTE1, PTE3, PTE2, PTE4, "sd"); + +//SPI commands +#define CMD_WAKEUP 0x02 +#define CMD_STANDBY 0x04 +#define CMD_RESET 0x06 +#define CMD_START 0x08 +#define CMD_STOP 0x0A +#define CMD_OFFSET_CAL 0x1A +#define CMD_RDATAC 0x10 +#define CMD_SDATAC 0x11 +#define CMD_RDATA 0x12 +//Note the following commands are 3 bits and have the following structure +// CMD_REGr_rrrr; where r_rrrr is the register address given below +#define CMD_WREG 0x02 +#define CMD_RREG 0x01 + +//SPI registers addresses, 5 bits width +#define REG_ID 0x00 +#define REG_CONFIG1 0x01 +#define REG_CONFIG2 0x02 +#define REG_LOFF 0x03 +#define REG_CH1SET 0x04 +#define REG_CH2SET 0x05 +#define REG_RLD_SENS 0x06 +#define REG_LOFF_SENS 0x07 +#define REG_LOFF_STAT 0x08 +#define REG_MISC1 0x09 +#define REG_MISC2 0x0A +#define REG_GIPO 0x0B + +//Register bit configurations +#define sps500 0x02 //CONFIG1 REG bits 010 +#define sps125 0x00 //CONFIG1 REG bits 000 +#define sps1k 0x03 //CONFIG1 REG bits 011 +#define no_mode 0xA8 //CONFIG2 REG set to zero for device check +#define test_mode 0xA3 //CONFIG2 REG bits set to test mode, to generate a square wave +#define default_mode 0xE0 //CONFIG2 REG bits set to default mode, to generate ECG signal from an external input +#define loff_conf 0xF0 //LOFF register bits set to F0 to configure LOFF reg for leadoff detection +#define offset_meas 0x01 //CH1SET REG set to Gain = 6 and offset measurement +#define test_inp 0x05 //CH1SET REG set to Gain = 6 and generate test signal +#define elec_inp 0x00 //CH1SET REG set to Gain = 6 and take in electrode input +#define rld_sens_sig 0x23 +#define loff_sens_sig 0x03 +#define misc1_inp 0x02 +#define misc2_inp 0x03 + +#define LSHIFT_8 8 //left shift the obtained 8bit data by 8 values +#define LSHIFT_16 16 ////left shift the obtained 8bit data by 16 values +#define N_ERR 100 +#define N_TEST 500 +#define N_ECG 1000 + + +//SPI SETTINGS +#define baud_rate 115200 +#define freq 1000000 +#define bits 8 +#define mode 1 +#define loop 1000000 + +//PPG DECLARATION +#define MAX_BRIGHTNESS 255 // BP ADD + void setupfunc(); + void ecgsetupfunc(); + int readvalue(); +#endif + + +
--- a/ecg_dec.h Mon Jan 30 10:57:38 2017 +0000 +++ b/ecg_dec.h Fri Feb 10 10:39:13 2017 +0000 @@ -3,7 +3,7 @@ #ifndef ECG_DEC_H_ #define ECG_DEC_H_ -#include "mbed.h" +/*#include "mbed.h" //#include "rtos.h" #define PIN_MOSI PTA16 #define PIN_MISO PTA17 @@ -61,7 +61,28 @@ #define N_ERR 100 #define N_TEST 500 #define N_ECG 2000 +SPI mySpi(PIN_MOSI, PIN_MISO, PIN_SCLK) ; +//PIN DECLARATIONS +Serial pc(USBTX,USBRX); +DigitalIn DRDY_BAR(PTC8); +DigitalIn INTR(PTC7); +DigitalOut CHIPSEL_BAR(PTD0); +DigitalOut ADS_START(PTC16); +DigitalOut RESET_BAR(PTC17); +DigitalOut myled(LED1); + +PwmOut led(PTB18); +//SPI SETTINGS +#define baud_rate 115200 +#define freq 1000000 +#define bits 8 +#define mode 1 +#define loop 1000000 + +//PPG DECLARATION +#define MAX_BRIGHTNESS 255 // BP ADD int ecg(int pid); - +*/ +int ecg(int pid); #endif \ No newline at end of file
--- a/ecgg.cpp Mon Jan 30 10:57:38 2017 +0000
+++ b/ecgg.cpp Fri Feb 10 10:39:13 2017 +0000
@@ -4,7 +4,6 @@
*/
#include "mbed.h"
-//#include "timer.h"
#include <string.h>
#include <stdio.h>
#include "ds3231.h"
@@ -12,434 +11,37 @@
#include "ecg_dec.h"
#include "rtc.h"
#include "sdcard.h"
-//#include "rtos.h"
-
-//SPI SETTINGS
-#define baud_rate 115200
-#define freq 1000000
-#define bits 8
-#define mode 1
-#define loop 1000000
-
-//PIN DECLARATIONS
-Serial pc(USBTX,USBRX);
-DigitalIn DRDY_BAR(PTC8);
-DigitalOut CHIPSEL_BAR(PTD0);
-DigitalOut ADS_START(PTC16);
-DigitalOut RESET_BAR(PTC17);
-
-//FILE *fp = NULL;
-
-
-//unsigned char chk2= 0;
-float value = 0;
-unsigned int value1 = 0;
-unsigned int value2 = 0;
-unsigned int value3 = 0;
-unsigned int value4 = 0;
-unsigned int value5 = 0;
-unsigned int value6 = 0;
-unsigned int data1 = 0;
-unsigned int count = 0;
-
-//static int32_t ecg_x[500];
-SPI mySpi(PIN_MOSI, PIN_MISO, PIN_SCLK) ; /* SPI is the spi function written in mbed and mySpi is the instance name*/
-
-typedef void (*func_ptr)(void) ; /*creates typedef to function pointer, does not take any arguement and returns void*/
-
-void doHelp(void) ;
-void doStatus(void) ;
-void doFreq(void) ;
-void doMode(void) ;
-void doBit(void) ;
-void doWrite(void) ;
-void doWrite2(void) ;
-void doRead(void) ;
-void doLoop(void) ;
-void setup(void);
-void testsetup(void);
-void ecgsetup(void);
-void regWrite(int,int);
-void cmdWrite(int);
-void regRead(int);
-void lpf_coef(void);
-float lpf( float coeff[5], float);
-void drdy_int(void);
-/*FILE *sd_openfile(char *buf);
-void sd_write (FILE *n,int value);
-void sd_close(FILE *n);
-time_t rtc_read();*/
-
-typedef struct _cmd_func {
- char *name ;
- func_ptr func ;
-} cmd_func_type ;
+#include "ec_bp.h"
+Serial pc(USBTX,USBRX);
-cmd_func_type cmd_list[] = { /*"cmd_func_type cmd_list[]" is same as "struct cmd_list[]"*/
- {"help", doHelp},
- {"status", doStatus},
- {"freq", doFreq},
- {"mode", doMode},
- {"bit", doBit},
- {"write", doWrite},
- {"read", doRead},
- {"loop", doLoop},
- { 0, 0 }
-} ;
-
-func_ptr getFunc(char *cmd) /*here "func_ptr is same as void*/
-{
- int i = 0 ;
- while(cmd_list[i].name != 0) {
- if (strcmp(cmd, cmd_list[i].name) == 0) {
- return(cmd_list[i].func) ; ;
- }
- i++ ;
- }
- return(0) ;
-}
-
-void doHello()
-{
- printf("=== spi test program ===\n\r") ;
- printf("please set your terminal program\n\r") ;
- printf("local echo on\n\r") ;
- printf("\n\r") ;
-}
-
-int ecg(int pid) {
- //time_t epoch_time;
- //int fp;
- int concatenate_value = 0;
-
-//uint32_t ecg_buf[1500];
-//int32_t ecg_der[1500];
-//int buff1[15]= {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
-int32_t sample_sum; // static int32_t avg[1500];
- count = 0; int32_t fs = 500; int32_t w=0,w1=0;
-Timer t;
- unsigned char chk = 1;
- pc.baud(baud_rate);
- mySpi.frequency(freq) ;
- mySpi.format(bits, mode) ;
- // Ds3231 rtc(PTC11, PTC10); //sda,scl2yy
-
-
-
- //Initialize ADS1291
- setup() ;
-
- //Put device back in RDATAC mode
- cmdWrite(CMD_RDATAC) ;
-// printf("The device is in RDATAC mode\n");
-//Activate conversion, At this point DRDY should toggle
- ADS_START = 1;
-
- // printf( "ADC noise data is= \n");
- for(int i=0;i<N_ERR;i++)
- {
- while(DRDY_BAR);
- doWrite() ;
- //printf( "ADC status is= %X %X %X\n", value1,value2,value3);
- concatenate_value = ((value4<< LSHIFT_16)|(value5 <<LSHIFT_8) |(value6));
- // printf( "%X\n", concatenate_value);
- }
- /*testsetup(); // To set the ADS1291 registers for internal test signal generation
- wait(0.2);
- cmdWrite(CMD_RDATAC) ;
- //printf("The device is in RDATAC mode\n");
- // printf("Test data is\n");
- ADS_START = 1;
- //printf("Test data is\n");
- sd_open_file();
-
- for(int j=0;j<N_TEST;j++)
- {
- while(DRDY_BAR);
- doWrite() ;
- concatenate_value = ((value4<< LSHIFT_16)|(value5 <<LSHIFT_8) |(value6));
-
- sd_write(concatenate_value);
- pc.printf("%d\n",concatenate_value);
- // fprintf(fp,"%d\n",concatenate_value) ;
- }
- sd_close();*/
-
- ecgsetup(); // To set the ADS1291 registers for ECG signal generation
-// printf("\n Reading****");
- //DRDY_BAR1.enable_irq();
- cmdWrite(CMD_RDATAC) ;
-// printf("The device is in RDATAC mode\n");
- ADS_START = 1;
- chk = 1;
- t.start();
- sd_open_ECGfile(pid);
- for(int i=0; i<N_ECG; i++)
- {
- while(DRDY_BAR);
- doWrite() ;
- concatenate_value = ((value4<< 16)|(value5 <<8) |(value6));
- sd_write(concatenate_value);
- //printf( "%d\n", concatenate_value);
- }
- sd_close();
- t.stop();
- printf( "%f\n", t.read());
- /*
- // remove DC of ecg signal
- uint32_t ecg_mean=0, buf_length = 500;
- printf("DC removed\ ECG Data\n");
- for (int k=0 ; k<buf_length ; k++ )
- {ecg_mean = ecg_mean+ ecg_buf[k] ;
- /// printf("ecg_mean is %d\n",ecg_mean);
- }
- ecg_mean =ecg_mean/buf_length ;
- //printf("ecg_mean is %d\n",ecg_mean);
- for (k=0 ; k<buf_length ; k++ )
- {
- ecg_x[k] = ecg_buf[k] - ecg_mean ;
- printf("%d\n",(ecg_x[k]));
- }
- */
- // 4 pt Moving Average
- /*printf("Averaged ECG Data\n");
- for(int k=0; k<N_ECG; k++)
- {
- // sample_sum= ( ecg_x[k]+ecg_x[k+1]+ ecg_x[k+2]+ ecg_x[k+3]);
- sample_sum= ( ecg_buf[k]+ecg_buf[k+1]+ ecg_buf[k+2]+ ecg_buf[k+3]);
- ecg_buf[k]= sample_sum/(int32_t)4;
-
-// printf("%d\n",(ecg_buf[k]));
- }
-
- // Derivative filtering of the averaged ECG signal
-// printf("Derivative filtered ECG Data\n");
- ecg_der[0]=0;
- for(int k=0; k<N_ECG-3; k++)
- {
- w1= (fs*(ecg_buf[k+1]-ecg_buf[k]));
- //w1=1;
- // w=0.995;
- // ecg_der[k]=(w+w1);
- w=(1*ecg_der[k]);
- ecg_der[k+1]=(w1+w);
- // printf("ecg_der[k+1]=%d\n",(ecg_der[k+1]));
- // printf("w=%f\n", w);
- // printf("w1=%f\n", w1);
- // printf("%d\n",(ecg_der[k]));
- //printf("k=%d\n", k);
- }*/
- } // End of main function
-
-//for initial configurations
-void setup()
-{
- //initially make all inputs low until power is up and stabilized
- CHIPSEL_BAR = 0;
- ADS_START = 0;
- RESET_BAR = 0;
- //wait for oscillator to wake up
- wait(1);
-
- CHIPSEL_BAR = 1;
- RESET_BAR = 1; //wait for tpor time
- //wait for power on reset
- wait(1);
- RESET_BAR = 0; // send a reset pulse and wait for t_reset amount of time
- wait(1);
- RESET_BAR = 1;//release the reset
- //Wait for 18 tclks = 36 us
- wait_us(36);
-
- //Device wakes up in RDATAC mode so send SDATAC command to write to registers
- cmdWrite(CMD_SDATAC) ;
-// printf("Device is in SDATAC mode\n");
-
- regRead(REG_ID);
- printf("DEVICE ID register read from ADS is= 0x%X\n",data1);
- wait(1);
-
- //Since we are using internal 2.42V reference and enable clock on the CLK PIN
- //Write 0xA8 to CONFIG2 register
- regWrite(REG_CONFIG2,no_mode);
-
- //Set continuous sampling mode, 500 SPS
- regWrite(REG_CONFIG1,sps500);
-
- //PGA Gain = 6, inputs shorted for noise measurements
- regWrite(REG_CH1SET, offset_meas);
-
- //read data from CONFIG2 register
- regRead(REG_CONFIG2);
-// printf("REG_CONFIG2 register read from ADS for initial setup is= 0x%X\n",data1);
-
- //read data from CONFIG1 register
- regRead(REG_CONFIG1);
-// printf("REG_CONFIG1 register read from ADS for initial setup is= 0x%X\n",data1);
-
- //read data from CONFIG1 register
- regRead(REG_CH1SET);
-// printf("REG_CH1SET register read from ADS for initial setup is= 0x%X\n",data1);
-}
+int ecg(int pid)
+ {
-void testsetup()
-{
- //Send SDATAC command to write to registers to set test signals
- cmdWrite(CMD_SDATAC) ;
- printf("Device is in SDATAC mode\n");
-
- //Since we are using internal 2.42V reference and enable clock on the CLK PIN
- //Write 0xA3 to CONFIG2 register to set test signal and its freq = 1Hz
- regWrite(REG_CONFIG2,test_mode);
-
- //PGA Gain = 6, test signal selected
- regWrite(REG_CH1SET, test_inp);
-
- //read data from CONFIG2 register
- regRead(REG_CONFIG2);
- printf("REG_CONFIG2 register read from ADS for test signal setup is= 0x%X\n",data1);
-
- //read data from CONFIG1 register
- regRead(REG_CH1SET);
- printf("REG_CH1SET register read from ADS for test signal setup is= 0x%X\n",data1);
-}
-
-void ecgsetup()
-{
-cmdWrite(CMD_SDATAC) ; //Set to SDATAC mode to set CH1SET register
-
-regWrite(REG_CONFIG1,sps500);
-regWrite(REG_CONFIG2, default_mode);//put INT_TEST and TEST_FREQ bits to default mode(set those bits to '0')
-regWrite(REG_LOFF, loff_conf);
-regWrite(REG_CH1SET, elec_inp);// Set to read normal electrode input
-regWrite(REG_RLD_SENS, rld_sens_sig);//Set RLD_SENS
-regWrite(REG_LOFF_SENS, loff_sens_sig);//Set LOFF_SENS
-regWrite(REG_MISC1, misc1_inp );//Set RESP1
-regWrite(REG_MISC2, misc2_inp );//Set RESP2
-//printf("connect ECG leads\n");
-wait(0.5);
-regRead(REG_LOFF_STAT);//Read LOFF_STAT register
-printf("REG_LOFF_STAT register read from ADS for ecg setup is= 0x%X\n",data1);
-}
-
-void doHelp(void)
-{
- printf("=== spi test ===\n\r") ;
- printf("commands available\n\r") ;
- printf("help\n\r") ;
- printf("status\n\r") ;
- printf("freq freq_in_hz\n\r") ;
- printf("mode (0 | 1 | 2 | 3)\n\r") ;
- printf("bit (4 - 16)\n\r") ;
- printf("write value\n\r") ;
- printf("read\n\r") ;
- printf("loop number (set repeat number for read/write)\n\r") ;
-}
-
-void doStatus(void)
-{
- printf("=== Status Report ===\n\r") ;
- printf("bits: %d\n\r", bits) ;
- printf("mode: %d\n\r", mode) ;
- printf("freq: %d Hz\n\r", freq) ;
- printf("loop: %d\n\r", loop) ;
-}
-
-void doFreq(void)
-{
- // int freq = 0 ;
- // scanf("%d", &freq) ;
- printf("setting frequency to %d\n\r", freq) ;
- mySpi.frequency(freq) ;
-}
-
-void doMode(void)
-{
- //scanf("%d", &mode) ;
- printf("setting format(%d, %d)\n\r",bits, mode) ;
- mySpi.format(bits, mode) ;
-}
-
-void doBit(void)
-{
- // scanf("%d", &bits) ;
- printf("setting format(%d, %d)\n\r",bits, mode) ;
- mySpi.format(bits, mode) ;
-}
-
-void doWrite(void)
-{
-
- //DRDY_BAR1.disable_irq();
-
- CHIPSEL_BAR = 0;
- // int freq1 = 50000;
- // mySpi.frequency(freq1) ;
- value1 = mySpi.write(0x00);
- value2 = mySpi.write(0x00);
- value3 = mySpi.write(0x00);
- value4 = mySpi.write(0x00);
- value5 = mySpi.write(0x00);
- value6 = mySpi.write(0x00);
-
- CHIPSEL_BAR = 0;
- //DRDY_BAR1.enable_irq();
-}
-
-void doRead(void)
-{
- int dummy = 0 ;
+ int concatenate_value2 = 0;
+ int32_t sample_sum; // static int32_t avg[1500];
+ int32_t count = 0; int32_t fs = 500; int32_t w=0,w1=0;
+ Timer t;
+ unsigned char chk = 1;
+ pc.baud(baud_rate);
+ freqset();
+ setupfunc();
+ ecgsetupfunc();
+ chk = 1;
+ // t.start();
+ sd_open_ECGfile(pid);
- while(!DRDY_BAR)
- ADS_START = 0;
-
- value = mySpi.write(dummy) ;
-
-}
-
-void doLoop(void)
-{
- // scanf("%d", &loop) ;
- printf("repeat number has been set to %d\n\r", loop) ;
-}
-
-void cmdWrite(int data)
-{
- CHIPSEL_BAR = 0;
- mySpi.write(data) ;
- wait_ms(1);
- CHIPSEL_BAR = 1;
-}
-
-void regWrite(int address, int data)
-{
- int data_to_send = CMD_WREG << 5;
- data_to_send = data_to_send | address;
- CHIPSEL_BAR = 0;
- mySpi.write(data_to_send);
- wait_ms(1);
- mySpi.write(0x00) ;
- wait_ms(1);
- mySpi.write(data) ;
- wait_ms(1);
- CHIPSEL_BAR = 1;
-}
-
-void regRead(int address)
-{
- int data_to_receive = CMD_RREG << 5;
- data_to_receive = data_to_receive | address;
- CHIPSEL_BAR = 0;
- mySpi.write(data_to_receive);
- wait_ms(1);
- mySpi.write(0x00) ;
- wait_ms(1);
- data1 = mySpi.write(0x00) ;
-
- //printf("DEVICE ID register read from ADS is= 0x%X\n",data1);
-
- //wait_ms(1);
- CHIPSEL_BAR = 1;
-}
\ No newline at end of file
+ for(int i=0; i<N_ECG; i++)
+ {
+ concatenate_value2= readvalue();
+ sd_write(concatenate_value2);
+ pc.printf( "%d\n", concatenate_value2);
+ }
+
+ sd_close();
+ // t.stop();
+ // printf( "%f\n", t.read());
+
+
+ } // End of main function
--- a/main.cpp Mon Jan 30 10:57:38 2017 +0000
+++ b/main.cpp Fri Feb 10 10:39:13 2017 +0000
@@ -6,6 +6,7 @@
#include "ecg_dec.h"
#include "touch_modules.h"
#include "glc.h"
+#include "bp.h"
#include "sdcard.h"
@@ -20,16 +21,16 @@
int main(){
-unsigned char state;
-unsigned char state1;
-unsigned char nstate;
-unsigned char nstate1;
-int pid=0;
-unsigned char flag=0;
-unsigned char ecg_flag=0;
-unsigned char glc_flag=0;
+ unsigned char state;
+ unsigned char state1;
+ unsigned char nstate;
+ unsigned char nstate1;
+ int pid=0; // patient ID
+ unsigned char flag=0;
+ unsigned char ecg_flag=0;
+ unsigned char glc_flag=0;
- unsigned int mgdll;
+
DisableTouch();
gc.baud(115200);
@@ -42,19 +43,20 @@
while(1)
{
- detect_touch(); // detrmine the touch points
+
+ detect_touch(); // detrmine the touch points
switch(state)
{
case 1: state1=touch_main(); // determining the touch for main screen
state=0;
nstate1=state1;
- break;
+ break;
case 2:
state1=touch_main_1(); // determining the touch for glc screen
state=0;
- nstate1=state1;
+ nstate1=state1;
break;
case 3:
@@ -73,14 +75,12 @@
case 5:
state1=touch_ecg(); // determining the touch for bp screen
state=0;
- nstate1=state1;
- break;
+ nstate1=state1;
+ break;
case 6:
state1=touch_ret(); // determining the touch for bp screen
state=0;
- nstate1=state1;
- // gc.printf("state=%d", state);
- //gc.printf("state1=%d", state1);
+ nstate1=state1;
break;
case 7:
@@ -89,20 +89,25 @@
nstate1=state1;
break;
+ case 8:
+ state1=touch_bp(); // determining the touch for bp screen
+ state=0;
+ nstate1=state1;
+ break;
+
+
+
case 10 : DisableTouch();
wait_ms(300);
EnableTouch();
- state=nstate;
- // gc.printf("%d", nstate);
- //state=0;
- break;
+ state=nstate;
+ break;
default : DisableTouch();
wait_ms(300);
EnableTouch();
- state=nstate;
- // gc.printf("%d", nstate);
- break;
+ state=nstate;
+ break;
}
@@ -116,13 +121,11 @@
case 0:
DisableTouch();
wait_ms(300);
-
state=nstate;
- EnableTouch();
-
+ EnableTouch();
break;
- case 1:
+ case 1: DisableTouch();
screen_main(); // glc main screen
state1=0;
state=1;
@@ -130,19 +133,18 @@
flag=0;
ecg_flag=0;
glc_flag=0;
-
+ EnableTouch();
break;
- case 2:
+ case 2: DisableTouch();
screen_main_1(); // glc main screen
state1=0;
state=2;
nstate=state;
-
-
+ EnableTouch();
break;
- case 3:
+ case 3: DisableTouch();
if (flag==0)
{
pid=pid+1;
@@ -163,9 +165,10 @@
state1=0;
state=3;
nstate=state;
+ EnableTouch();
break;
- case 4:
+ case 4: DisableTouch();
if (glc_flag==1)
{
screen_again(); //bp main screen
@@ -179,10 +182,12 @@
state=4;
nstate=state;
}
+ EnableTouch();
+
break;
- case 5:
+ case 5: DisableTouch();
if (ecg_flag==1)
{
screen_again();
@@ -198,20 +203,36 @@
state=5;
nstate=state;
}
+ EnableTouch();
break;
- case 7:
+ case 6: DisableTouch();
+ screen_bp();
+ EnableTouch();
+ state1=0;
+ state=8;
+ break;
+
+
+
+
+
+ case 7: DisableTouch();
glc(pid);
glc_flag=1;
wait(5);
// glc_4(mgdll);
- state1=9;
+ state1=0;
+ screen_glc_2();
+
+ state=6;;
// gc.printf("%d", state);
+ EnableTouch();
break;
- case 8:
+ case 8: DisableTouch();
ecg_countdown();
ecg(pid);
@@ -220,20 +241,36 @@
state=6;
nstate=state;
ecg_flag=1;
+
// ble.printf("ecg");
+ EnableTouch();
break;
case 9:
-
+ DisableTouch();
screen_glc_2();
state1=0;
state=6;
nstate=state;
-
-
+ EnableTouch();
break;
+
+ case 11:
+ DisableTouch();
+ screen_bp2();
+ bp();
+ state1=0;
+ // wait(1);
+ state=6;
+ nstate=state;
+ EnableTouch();
+ break;
+
+
+
default :
+
state1=nstate1;
break;
--- a/main.h Mon Jan 30 10:57:38 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,7 +0,0 @@ -#ifndef DISPLAY_MODULES_H_ -#define DISPLAY_MODULES_H_ - - - - -#endif \ No newline at end of file
--- a/sdcard.cpp Mon Jan 30 10:57:38 2017 +0000
+++ b/sdcard.cpp Fri Feb 10 10:39:13 2017 +0000
@@ -3,7 +3,7 @@
#include "SDFileSystem.h"
#include "sdcard.h"
#include "rtc.h"
- #include "main.h"
+
SDFileSystem sd(PTE1, PTE3, PTE2, PTE4, "sd");
FILE *fp=NULL;
@@ -23,6 +23,7 @@
}
+
void sd_open_GLCfilee(int pid)
{
--- a/touch_modules.cpp Mon Jan 30 10:57:38 2017 +0000
+++ b/touch_modules.cpp Fri Feb 10 10:39:13 2017 +0000
@@ -29,16 +29,18 @@
{
wait_ms(200); ///wait for debounce check
if (Touch_D)
- {
- Touch_D.fall(&touch1); //determine the touch co-ordinates
+ {
+
+ Touch_D.fall(&touch1);
+ //determine the touch co-ordinates
break;
}
- DisableTouch();
+ DisableTouch();
//kc.printf("touch");
}
}
-
+ EnableTouch();
}
@@ -118,7 +120,7 @@
}
else if ( ((xt >= 35) && (xt<=100)) && ( (yt>= 65) && (yt<= 118) ) ) // BP
{
- //state=5;
+ state=6;
}
else if ( ((xt >= 130) && (xt<=195)) && ( (yt>= 65) && (yt<= 118) ) ) // Home
@@ -182,36 +184,17 @@
{
unsigned char state;
-if ( ((xt >=28) && (xt<=125)) && ( (yt>= 225) && (yt<= 285) ) )
- {
- state=1;
-
- }
-
- else if ( ((xt >=35) && (xt<=100)) && ( (yt>= 135) && (yt<= 185) ) )
+ if ( ((xt >=70) && (xt<=170)) && ( (yt>= 140) && (yt<= 195) ) ) // GLC
{
- state=2;
-
+ state=11;
}
- else if ( ((xt >=130) && (xt<=195)) && ( (yt>= 135) && (yt<= 185) ) )
- {
- state=3;
-
-
- }
- else if ( ((xt >= 35) && (xt<=100)) && ( (yt>= 65) && (yt<= 118) ) )
+ else if ( ((xt >=70) && (xt<=170)) && ( (yt>=90) && (yt<=140) ) ) // ECG
{
- state=4;
-
- }
- else if ( ((xt >= 130) && (xt<=195)) && ( (yt>= 65) && (yt<= 118) ) )
- {
- state=5;
-
- }
- else
+ // state=2;
+ }
+ else
state=10;
return state;
--- a/touch_modules.h Mon Jan 30 10:57:38 2017 +0000 +++ b/touch_modules.h Fri Feb 10 10:39:13 2017 +0000 @@ -19,4 +19,5 @@ unsigned char touch_bp(); unsigned char touch_ret(); unsigned char touch_again(); + void screen_bp2(); #endif \ No newline at end of file
