a pacemaker

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers clock.cpp Source File

clock.cpp

00001 #include "clock.h"
00002 
00003 Ticker counter_ticker;
00004 Ticker toggle_ticker;
00005 
00006 double counter = 0;
00007 int atrial_logic = 0;
00008 double atrial_counter = 0;
00009 double atrial_pulse_start_time = 0;
00010 int ventricle_logic = 0;
00011 double ventricle_counter = 0;
00012 double ventricle_pulse_start_time = 0;
00013 int toggle_switch = 0;
00014 
00015 int start_clock(void){
00016     counter_ticker.attach(&increment_counter, 0.0001);
00017     return 1;
00018     }
00019 
00020 int start_toggler(double switch_time){
00021     toggle_ticker.attach(&toggler, switch_time);
00022     return 1;
00023     }
00024     
00025 void increment_counter(void){
00026     counter += 0.0001;
00027     
00028     //records time at the rising edge of an atrial pulse (most recent only)
00029     if ((atrial_logic != 0) && (atrial_counter == 0)){
00030         atrial_pulse_start_time = get_time();
00031         }
00032     
00033     if (atrial_logic != 0){
00034         atrial_counter += 0.0001;
00035         }
00036     else {
00037         atrial_counter = 0;
00038         }
00039         
00040     //records time at the rising edge of a ventricle pulse (most recent only)
00041     if ((ventricle_logic != 0) && (ventricle_counter == 0)){
00042         ventricle_pulse_start_time = get_time();
00043         }
00044         
00045     if (ventricle_logic != 0){
00046         ventricle_counter += 0.0001;
00047         }
00048         
00049     else {
00050         ventricle_counter = 0;
00051         }
00052     }
00053     
00054 void toggler(void){
00055     if(!toggle_switch){
00056     toggle_switch = 1;}
00057     else{
00058     toggle_switch = 0;}
00059     }
00060     
00061 double get_time(void){
00062     return counter;
00063     }
00064     
00065 int get_atrial_logic(void){
00066     return atrial_logic;
00067     }
00068     
00069 int set_atrial_logic(int logic){
00070     atrial_logic = logic;
00071     return 1;
00072     }
00073     
00074 int get_ventricle_logic(void){
00075     return ventricle_logic;
00076     }
00077   
00078 int set_ventricle_logic(int logic){
00079     ventricle_logic = logic;
00080     return 1;
00081     } 
00082     
00083 double get_ventricle_counter(void){
00084     return ventricle_counter;
00085     } 
00086 
00087 double get_atrial_counter(void){
00088     return atrial_counter;
00089     }