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.
main.cpp@0:906c21fbf97c, 2010-09-27 (annotated)
- Committer:
- kasturir
- Date:
- Mon Sep 27 22:51:19 2010 +0000
- Revision:
- 0:906c21fbf97c
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| kasturir | 0:906c21fbf97c | 1 | // Author: kasturir@ucla.edu (Kasturi Rangan Raghavan) |
| kasturir | 0:906c21fbf97c | 2 | // \file |
| kasturir | 0:906c21fbf97c | 3 | // QRSDet library ported to OOP |
| kasturir | 0:906c21fbf97c | 4 | // Allows easy adjustment of sampling rates |
| kasturir | 0:906c21fbf97c | 5 | |
| kasturir | 0:906c21fbf97c | 6 | #include <mbed.h> |
| kasturir | 0:906c21fbf97c | 7 | #include <scmRTOS.h> |
| kasturir | 0:906c21fbf97c | 8 | #include <qrsdet/qrsdet2-inl.h> |
| kasturir | 0:906c21fbf97c | 9 | |
| kasturir | 0:906c21fbf97c | 10 | AnalogIn ecg_in(p20); |
| kasturir | 0:906c21fbf97c | 11 | DigitalOut led1(LED1); |
| kasturir | 0:906c21fbf97c | 12 | DigitalOut led2(LED2); |
| kasturir | 0:906c21fbf97c | 13 | PwmOut led3(LED3); |
| kasturir | 0:906c21fbf97c | 14 | DigitalOut led4(LED4); |
| kasturir | 0:906c21fbf97c | 15 | |
| kasturir | 0:906c21fbf97c | 16 | |
| kasturir | 0:906c21fbf97c | 17 | typedef OS::process<OS::pr0, 200> TEcgSampler; |
| kasturir | 0:906c21fbf97c | 18 | |
| kasturir | 0:906c21fbf97c | 19 | TEcgSampler EcgSampler; |
| kasturir | 0:906c21fbf97c | 20 | |
| kasturir | 0:906c21fbf97c | 21 | OS::TEventFlag ecg_sampler_ef; |
| kasturir | 0:906c21fbf97c | 22 | |
| kasturir | 0:906c21fbf97c | 23 | int main() { |
| kasturir | 0:906c21fbf97c | 24 | OS::Run(); |
| kasturir | 0:906c21fbf97c | 25 | } |
| kasturir | 0:906c21fbf97c | 26 | |
| kasturir | 0:906c21fbf97c | 27 | template<> OS_PROCESS void TEcgSampler::Exec() { |
| kasturir | 0:906c21fbf97c | 28 | float float_val; |
| kasturir | 0:906c21fbf97c | 29 | int int_val; |
| kasturir | 0:906c21fbf97c | 30 | qrsdet::QRSFilterParams qrs_filter_params(8.0); |
| kasturir | 0:906c21fbf97c | 31 | qrsdet::QRSDet2 *qrs_filter = |
| kasturir | 0:906c21fbf97c | 32 | new qrsdet::QRSDet2(qrs_filter_params); |
| kasturir | 0:906c21fbf97c | 33 | qrsdet::DelayFilter *delay_filter = new qrsdet::DelayFilter(45); |
| kasturir | 0:906c21fbf97c | 34 | for(;;) { |
| kasturir | 0:906c21fbf97c | 35 | ecg_sampler_ef.Wait(); |
| kasturir | 0:906c21fbf97c | 36 | led2 = !led2; |
| kasturir | 0:906c21fbf97c | 37 | float_val = ecg_in.read(); |
| kasturir | 0:906c21fbf97c | 38 | int_val = float_val * 128; |
| kasturir | 0:906c21fbf97c | 39 | int qrs_val = qrs_filter->Process(int_val); |
| kasturir | 0:906c21fbf97c | 40 | int delay_val = delay_filter->Process(int_val); |
| kasturir | 0:906c21fbf97c | 41 | led3 = delay_val/128.0; |
| kasturir | 0:906c21fbf97c | 42 | if (qrs_val > 0) led4 = !led4; |
| kasturir | 0:906c21fbf97c | 43 | |
| kasturir | 0:906c21fbf97c | 44 | } |
| kasturir | 0:906c21fbf97c | 45 | } |
| kasturir | 0:906c21fbf97c | 46 | |
| kasturir | 0:906c21fbf97c | 47 | void OS::SystemTimerUserHook() { |
| kasturir | 0:906c21fbf97c | 48 | static int cnt=0; |
| kasturir | 0:906c21fbf97c | 49 | if (++cnt == 8) { |
| kasturir | 0:906c21fbf97c | 50 | cnt = 0; |
| kasturir | 0:906c21fbf97c | 51 | led1 = !led1; |
| kasturir | 0:906c21fbf97c | 52 | ecg_sampler_ef.Signal(); |
| kasturir | 0:906c21fbf97c | 53 | } |
| kasturir | 0:906c21fbf97c | 54 | } |
| kasturir | 0:906c21fbf97c | 55 | |
| kasturir | 0:906c21fbf97c | 56 | void OS::IdleProcessUserHook() { |
| kasturir | 0:906c21fbf97c | 57 | __WFI(); |
| kasturir | 0:906c21fbf97c | 58 | } |