CQ Publishing
/
tg_201410s6_Plethysmographs
トランジスタ技術2014年10月号第6章のソフトウェア
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 /** 00002 * @file Main.cpp 00003 * @brief Send pulse waveform and pulse rate 00004 * @date 2014.08.08 00005 * @version 1.0.0 00006 */ 00007 #include "mbed.h" 00008 #include "USBSerial.h" 00009 #include "PulseRate.h" 00010 00011 #define PACKET_HEADER (0xAA) 00012 #define PULSE_RATE_ID (0xBB) 00013 #define BYTE_MASK (0xFF) 00014 00015 USBSerial serial; 00016 PulseRate pr(p20, LED1, p26); /* AD, LED, Beep */ 00017 00018 /** Send data packet 00019 * @param second_val Byte data at packet address 0x01 00020 * @param data_val Short data at packet address 0x02, 0x03 00021 */ 00022 bool send_packet(int second_val, int data_val) 00023 { 00024 if(serial.writeable()) { 00025 serial.putc(PACKET_HEADER); 00026 serial.putc(second_val & BYTE_MASK); 00027 serial.putc((data_val >> 8 ) & BYTE_MASK); 00028 serial.putc(data_val & BYTE_MASK); 00029 return true; 00030 } 00031 else 00032 { 00033 return false; 00034 } 00035 } 00036 00037 /** Main function 00038 */ 00039 int main() { 00040 uint32_t num; 00041 int32_t wave; 00042 uint32_t rate; 00043 00044 pr.start_sampling(); /* start procedure */ 00045 00046 while(1) { 00047 /* Pulse waveform */ 00048 if(pr.get_wave(num, wave)) { 00049 send_packet(num, wave); 00050 } 00051 /* Pulse rate */ 00052 if(pr.get_pr_val(rate)) { 00053 send_packet(PULSE_RATE_ID, rate); 00054 } 00055 } 00056 }
Generated on Wed Jul 13 2022 19:52:00 by 1.7.2