A03_MAX30102_example.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright (c) 2020 Nanjing Xiaoxiongpai Intelligent Technology Co., Ltd.
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include <unistd.h>
  18. // #include "max30102.h"
  19. #include "algorithm.h"
  20. #include "cmsis_os2.h"
  21. #include "ohos_init.h"
  22. #include "blood.h"
  23. #define TASK_STACK_SIZE 1024 * 8
  24. #define TASK_PRIO 25
  25. uint32_t aun_ir_buffer[500]; //IR LED sensor data
  26. int32_t n_ir_buffer_length; //data length
  27. uint32_t aun_red_buffer[500]; //Red LED sensor data
  28. int32_t n_sp02; //SPO2 value
  29. int8_t ch_spo2_valid; //indicator to show if the SP02 calculation is valid
  30. int32_t n_heart_rate; //heart rate value
  31. int8_t ch_hr_valid; //indicator to show if the heart rate calculation is valid
  32. uint8_t uch_dummy;
  33. #define MAX_BRIGHTNESS 255
  34. static void ExampleTask(void)
  35. {
  36. //variables to calculate the on-board LED brightness that reflects the heartbeats
  37. uint32_t un_min, un_max, un_prev_data;
  38. int i;
  39. int32_t n_brightness;
  40. float f_temp;
  41. uint8_t temp_num=0;
  42. uint8_t temp[6]={0,0,0,0,0,0};
  43. uint8_t str[100];
  44. uint8_t dis_hr=0,dis_spo2=0;
  45. BoardInit();
  46. maxim_max30102_init();
  47. printf("\r\n MAX30102 init \r\n");
  48. for(i = 0;i < 128;i++)
  49. {
  50. while(GetInit()==0)
  51. {
  52. max30102_read_fifo();
  53. }
  54. }
  55. while(1)
  56. {
  57. // deal_Temp();
  58. blood_Loop();
  59. }
  60. }
  61. static void ExampleEntry(void)
  62. {
  63. osThreadAttr_t attr;
  64. attr.name = "ExampleTask";
  65. attr.attr_bits = 0U;
  66. attr.cb_mem = NULL;
  67. attr.cb_size = 0U;
  68. attr.stack_mem = NULL;
  69. attr.stack_size = TASK_STACK_SIZE;
  70. attr.priority = TASK_PRIO;
  71. if (osThreadNew((osThreadFunc_t)ExampleTask, NULL, &attr) == NULL) {
  72. printf("Failed to create ExampleTask!\n");
  73. }
  74. }
  75. APP_FEATURE_INIT(ExampleEntry);