Demo PAH8011+HeartRate on nRF52
Dependencies: mbed pixart_heart_rate_demo pixart_heart_rate_lib_keil_m4
Revision 1:3abb06bb21c5, committed 2017-10-30
- Comitter:
- pixus_mbed
- Date:
- Mon Oct 30 06:28:53 2017 +0000
- Parent:
- 0:a6408c845aba
- Commit message:
- Change to pixart_heart_rate_demo
Changed in this revision
diff -r a6408c845aba -r 3abb06bb21c5 main.cpp --- a/main.cpp Fri Oct 27 08:53:49 2017 +0000 +++ b/main.cpp Mon Oct 30 06:28:53 2017 +0000 @@ -1,127 +1,19 @@ -#include "mbed.h" -#include "system_clock.h" +#include "pixart_heart_rate_demo.h" -#include "pixart_pah8011.h" -#include "pixart_heart_rate.h" +#include <mbed.h> static Serial pc(USBTX, USBRX); static I2C i2c(I2C_SDA0, I2C_SCL0); -static InterruptIn pah8011_interrupt(p13); - -static volatile bool has_pah8011_interrupt = false; -static uint64_t pah8011_interrupt_timestamp = 0; - - -static void error_handler() -{ - pc.printf("error_handler()!\n"); - - while (true) - { - } -} +static InterruptIn interrupt(p13); -static void debug_print(const char *fmt, ...) -{ - char msg[128]; - va_list marker; - va_start(marker, fmt); - vsprintf(msg, fmt, marker); - va_end(marker); - pc.printf(msg); -} - -static void pah8011_interrupt_handle(void) -{ - has_pah8011_interrupt = true; - pah8011_interrupt_timestamp = system_clock_get_tick(); -} - -static uint64_t time_to_millisec(uint64_t time) -{ - return system_clock_time_to_milliseconds(time); -} int main(void) { - // system clock - system_clock_init(); - - // serial port - pc.baud(115200); - pc.printf("Pixart PAH8011 demo\n"); - - // interrupt - pah8011_interrupt.rise(pah8011_interrupt_handle); + pc.baud(115200); - // heart_rate - pixart::heart_rate heart_rate(time_to_millisec); - heart_rate.enable_debug_print(debug_print); - if (!heart_rate.init()) - { - pc.printf("heart_rate.init() failed\n"); - error_handler(); - } - - // pah8011 - pixart::pah8011 pah8011; - pah8011.enable_debug_print(debug_print); - if (!pah8011.init(i2c)) - { - pc.printf("pah8011.init() failed\n"); - error_handler(); - } - if (!pah8011.enable_ppg()) - { - pc.printf("pah8011.enable_ppg() failed\n"); - error_handler(); - } - - while(true) - { - if (has_pah8011_interrupt) - { - has_pah8011_interrupt = false; - - if (!pah8011.task()) - { - pc.printf("pah8011.task() failed\n"); - error_handler(); - } - - pixart::pah8011::task_result result; - if (pah8011.get_result(result)) - { - if (result.ch_num != 2) - error_handler(); - - for (uint32_t i = 0; i < result.num_per_ch; ++i) - { - pixart::heart_rate::ppg_sample ppg_sample; - ppg_sample.ch1 = result.data[i * result.ch_num + 0]; - ppg_sample.ch2 = result.data[i * result.ch_num + 1]; - ppg_sample.is_touched = result.is_touched; - ppg_sample.timestamp = pah8011_interrupt_timestamp; - heart_rate.set_ppg_sample(ppg_sample); - - pixart::heart_rate::accel_sample accel_sample; - accel_sample.x = 0.0f; - accel_sample.y = 0.0f; - accel_sample.z = 0.0f; - accel_sample.timestamp = pah8011_interrupt_timestamp; - heart_rate.set_accel_sample(accel_sample); - - } - - pixart::heart_rate::result hr_result = heart_rate.get_result(); - if (hr_result.ret == pixart::heart_rate::ret_success) - { - pc.printf("time = %llu, hr = %d, hr_trust_level = %d\n", pah8011_interrupt_timestamp, (int)hr_result.hr, hr_result.hr_trust_level); - } - } - } - } + // demo + pixart::heart_rate_demo demo(i2c, interrupt, pc); + demo.run(); } -
diff -r a6408c845aba -r 3abb06bb21c5 pixart_heart_rate.lib --- a/pixart_heart_rate.lib Fri Oct 27 08:53:49 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://os.mbed.com/users/bell_huang/code/pixart_heart_rate/#70ed6c78681c
diff -r a6408c845aba -r 3abb06bb21c5 pixart_heart_rate_demo.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pixart_heart_rate_demo.lib Mon Oct 30 06:28:53 2017 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/bell_huang/code/pixart_heart_rate_demo/#e03a9fcf825c
diff -r a6408c845aba -r 3abb06bb21c5 pixart_pah8011.lib --- a/pixart_pah8011.lib Fri Oct 27 08:53:49 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://os.mbed.com/users/bell_huang/code/pixart_pah8011/#37451de228e4
diff -r a6408c845aba -r 3abb06bb21c5 system_clock.cpp --- a/system_clock.cpp Fri Oct 27 08:53:49 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -#include "system_clock.h" - -#include <mbed.h> - - -static Ticker g_ticker; -static volatile uint64_t g_sys_tick = 0; - - -static void system_tick_handle(void) -{ - g_sys_tick++; -} - -void system_clock_init() -{ - g_sys_tick = 0; - - g_ticker.attach(system_tick_handle, 0.001f); -} - -uint64_t system_clock_get_tick() -{ - return g_sys_tick; -} - -uint64_t system_clock_time_to_milliseconds(uint64_t time) -{ - return time; -} -
diff -r a6408c845aba -r 3abb06bb21c5 system_clock.h --- a/system_clock.h Fri Oct 27 08:53:49 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -#ifndef __system_clock_h__ -#define __system_clock_h__ - - -#include <stdint.h> - - -void system_clock_init(); -uint64_t system_clock_get_tick(); - -uint64_t system_clock_time_to_milliseconds(uint64_t time); - - -#endif // header guard - -