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: TextLCD mbed-rtos mbed
Fork of mbed_PM by
main.cpp@1:e4a204ef28bc, 2015-12-01 (annotated)
- Committer:
- harry8989
- Date:
- Tue Dec 01 00:53:34 2015 +0000
- Revision:
- 1:e4a204ef28bc
- Parent:
- 0:093bb69f95f0
Added preliminary display and alarm
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| aconnors | 0:093bb69f95f0 | 1 | #include "mbed.h" |
| aconnors | 0:093bb69f95f0 | 2 | #include "rtos.h" |
| harry8989 | 1:e4a204ef28bc | 3 | #include "TextLCD.h" |
| harry8989 | 1:e4a204ef28bc | 4 | |
| harry8989 | 1:e4a204ef28bc | 5 | Serial keyboard(USBTX, USBRX); |
| harry8989 | 1:e4a204ef28bc | 6 | |
| harry8989 | 1:e4a204ef28bc | 7 | int PacemakerA, PacemakerV = 0; |
| harry8989 | 1:e4a204ef28bc | 8 | DigitalOut Apace(), Vpace(); |
| harry8989 | 1:e4a204ef28bc | 9 | DigitalIn Aget(), Vget(); |
| harry8989 | 1:e4a204ef28bc | 10 | |
| harry8989 | 1:e4a204ef28bc | 11 | int PacemakerModeGuard = 0; |
| harry8989 | 1:e4a204ef28bc | 12 | |
| harry8989 | 1:e4a204ef28bc | 13 | void PacemakerSense() { |
| harry8989 | 1:e4a204ef28bc | 14 | |
| harry8989 | 1:e4a204ef28bc | 15 | } |
| harry8989 | 1:e4a204ef28bc | 16 | |
| harry8989 | 1:e4a204ef28bc | 17 | void PacemakerKeyboard() { |
| harry8989 | 1:e4a204ef28bc | 18 | while(1) { |
| harry8989 | 1:e4a204ef28bc | 19 | char c = keyboard.getc(); |
| harry8989 | 1:e4a204ef28bc | 20 | switch(c) { |
| harry8989 | 1:e4a204ef28bc | 21 | case 'n': |
| harry8989 | 1:e4a204ef28bc | 22 | case 'N': |
| harry8989 | 1:e4a204ef28bc | 23 | PacemakerModeGuard = 0; |
| harry8989 | 1:e4a204ef28bc | 24 | break; |
| harry8989 | 1:e4a204ef28bc | 25 | case 's': |
| harry8989 | 1:e4a204ef28bc | 26 | case 'S': |
| harry8989 | 1:e4a204ef28bc | 27 | PacemakerModeGuard = 1; |
| harry8989 | 1:e4a204ef28bc | 28 | break; |
| harry8989 | 1:e4a204ef28bc | 29 | case 'e': |
| harry8989 | 1:e4a204ef28bc | 30 | case 'E': |
| harry8989 | 1:e4a204ef28bc | 31 | PacemakerModeGuard = 2; |
| harry8989 | 1:e4a204ef28bc | 32 | break; |
| harry8989 | 1:e4a204ef28bc | 33 | case 'm': |
| harry8989 | 1:e4a204ef28bc | 34 | case 'M': |
| harry8989 | 1:e4a204ef28bc | 35 | PacemakerModeGuard = 3; |
| harry8989 | 1:e4a204ef28bc | 36 | break; |
| harry8989 | 1:e4a204ef28bc | 37 | case 'a': |
| harry8989 | 1:e4a204ef28bc | 38 | case 'A': |
| harry8989 | 1:e4a204ef28bc | 39 | if(PacemakerModeGuard == 3) { |
| harry8989 | 1:e4a204ef28bc | 40 | PacemakerA = 1; |
| harry8989 | 1:e4a204ef28bc | 41 | Thread::wait(10); |
| harry8989 | 1:e4a204ef28bc | 42 | PacemakerA = 0; |
| harry8989 | 1:e4a204ef28bc | 43 | } |
| harry8989 | 1:e4a204ef28bc | 44 | break; |
| harry8989 | 1:e4a204ef28bc | 45 | case 'v': |
| harry8989 | 1:e4a204ef28bc | 46 | case 'V': |
| harry8989 | 1:e4a204ef28bc | 47 | } |
| harry8989 | 1:e4a204ef28bc | 48 | } |
| harry8989 | 1:e4a204ef28bc | 49 | } |
| aconnors | 0:093bb69f95f0 | 50 | |
| harry8989 | 1:e4a204ef28bc | 51 | |
| harry8989 | 1:e4a204ef28bc | 52 | Timer obsInt; |
| harry8989 | 1:e4a204ef28bc | 53 | int observationInterval = 10; //observation interval in seconds |
| harry8989 | 1:e4a204ef28bc | 54 | float vget_count = 0.; // A counter that increments every time a ventricular pulse has been detected |
| harry8989 | 1:e4a204ef28bc | 55 | Semaphore heartBeat(1); |
| harry8989 | 1:e4a204ef28bc | 56 | float DisplayMe; |
| harry8989 | 1:e4a204ef28bc | 57 | void PacemakerDisplay() { |
| harry8989 | 1:e4a204ef28bc | 58 | if (obsInt.read_ms()/1000 >= observationInterval) { //reporting interval exceeded |
| harry8989 | 1:e4a204ef28bc | 59 | obsInt.stop(); |
| harry8989 | 1:e4a204ef28bc | 60 | heartBeat.wait(); //DONT LET ANY OTHER CODE RUN RIGHT NOW |
| harry8989 | 1:e4a204ef28bc | 61 | DisplayMe = vget_count*(60/observationInterval); |
| harry8989 | 1:e4a204ef28bc | 62 | lcd.printf("HR = %s\n", DisplayMe); // multiplies the number of counted Vgets by the number of observation periods in one minute, |
| harry8989 | 1:e4a204ef28bc | 63 | PacemakerAlarm(DisplayMe); |
| harry8989 | 1:e4a204ef28bc | 64 | vget_count = 0; |
| harry8989 | 1:e4a204ef28bc | 65 | obsInt.reset(); |
| harry8989 | 1:e4a204ef28bc | 66 | heartBeat.release(); //OTHER CODE CAN RUN AGAIN |
| harry8989 | 1:e4a204ef28bc | 67 | } |
| harry8989 | 1:e4a204ef28bc | 68 | } |
| harry8989 | 1:e4a204ef28bc | 69 | void PacemakerAlarm(int HeartRate) { //Takes the heart rate and returns an appropriate message; runs whenever display is updated |
| harry8989 | 1:e4a204ef28bc | 70 | if HeartRate > LRI { |
| harry8989 | 1:e4a204ef28bc | 71 | lcd.printf("HR TOO FAST\n"); |
| harry8989 | 1:e4a204ef28bc | 72 | } else if HeartRate < URI{ |
| harry8989 | 1:e4a204ef28bc | 73 | lcd.printf("HR TOO SLOW\n"); |
| harry8989 | 1:e4a204ef28bc | 74 | } else{ |
| harry8989 | 1:e4a204ef28bc | 75 | lcd.printf(" \n"); |
| harry8989 | 1:e4a204ef28bc | 76 | } |
| harry8989 | 1:e4a204ef28bc | 77 | } |
| harry8989 | 1:e4a204ef28bc | 78 | |
| harry8989 | 1:e4a204ef28bc | 79 | void PacemakerLED() { |
| harry8989 | 1:e4a204ef28bc | 80 | |
| harry8989 | 1:e4a204ef28bc | 81 | } |
| harry8989 | 1:e4a204ef28bc | 82 | |
| harry8989 | 1:e4a204ef28bc | 83 | |
| harry8989 | 1:e4a204ef28bc | 84 | |
| harry8989 | 1:e4a204ef28bc | 85 | int main() { |
| harry8989 | 1:e4a204ef28bc | 86 | |
| harry8989 | 1:e4a204ef28bc | 87 | } |
| harry8989 | 1:e4a204ef28bc | 88 |
