Part of the Pacemaker Project; this models the Pacemaker.

Dependencies:   mbed TextLCD mbed-rtos

PMTest.cpp

Committer:
lucastai
Date:
2015-12-01
Revision:
25:18923916215b
Parent:
23:08456978fb78
Child:
26:64e2bc7d544a

File content as of revision 25:18923916215b:

#include "mbed.h"
#include "LPC17xx.h"
#include "TextLCD.h"
#include "rtos.h"
#include "Thread.h"

DigitalOut vsense(p23);
DigitalOut asense(p24);
DigitalIn apace(p22);
DigitalIn vpace(p21);

int timer_count;
int curr_test;
int minwaitV;
int minwaitA;

int needs_num_input = 0;

struct mode{RANDOM,MANUAL,TEST};
mode curr_mode = RANDOM;
Timer t;

int[][] testfunc;




void random_heart(){
    t.reset();
    t.start();

    while(curr_mode == RANDOM){
        int r = rand();

        if(r%2 == 0){
            if(t.read() > minwaitA){
                asense = 1;
                Thread::wait(10);
                asense = 0;
            }
        }else{
            if(t.read() > minwaitV){
                vsense = 1;
                Thread::wait(10);
                vsense = 0;
            }
        }


        t.reset();

    }
}


void kbd_intrp(){
    char a = pc.getc();

    if(needs_num_input){
        // DO O handling
        needs_num_input = 0;
        return;
    }

    if(a = 'R'){
        curr_mode = RANDOM;
    }else if(a == 'T'){
        curr_mode = TEST;
    }else if(a == 'M'){
        curr_mode = MANUAL;
    }
    
    if(a == 'A' && curr_mode = MANUAL){
        asense = 1;
        Thread::wait(10);
        asense = 0;
    }
    
    if(a == 'V' && curr_mode = MANUAL){
        vsense = 1;
        Thread::wait(10);
        vsense = 0;
    }
        



}



// interrupt function
void interrupt_and_run_test(){
    // zero timer, set for 1ms interrupt
    timer0_init(100000)
    
    // wait for atrial pulse
    while(apace != 1}{}
    
    // check if timer was within event
    
    if(timer_count < testfunc[curr_test][0]){
        printf("ATRIAL PULSE FOR TEST " + curr_test + " WAS WITHIN BOUNDS\n");
    }
    
    // send vsense
    
    while(timer_count < testfunc[curr_test][1]){};
    vpace = 1;
    
    // send asense
    while(timer_count < testfunc[curr_test][2]){};
    apace = 1;
    
    // check if timer was in event

    // wait for vpace
    
    // wait for atrial pulse
    while(vpace != 1}{}
    
    // check if timer was within event
    
    if(timer_count < testfunc[curr_test][0]){
        printf("VENT PULSE FOR TEST " + curr_test + " WAS WITHIN BOUNDS\n");
    }