A19_MXL90614_example.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright (c) 2020  Jinan Bosai Network 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 "mlx90614.h"
  19. #include "cmsis_os2.h"
  20. #include "ohos_init.h"
  21. #define TASK_STACK_SIZE 1024 * 8
  22. #define TASK_PRIO 25
  23. static void ExampleTask(void)
  24. {
  25. MLX90614_Init();
  26. while (1) {
  27. printf("\r\n Ambient Temp: %0.2f \r\n", MLX90614_Read_TempData(MLX90614_RAM | AMBIENT_TEMP)); // ambient
  28. printf("\r\n Object Temp: %0.2f \r\n", MLX90614_Read_TempData(MLX90614_RAM | OBJECT_TEMP)); // object
  29. if(MLX90614_Read_TempData(MLX90614_RAM | OBJECT_TEMP)>32)
  30. {
  31. LedSafeStatusSet(OFF);
  32. LedWarnStatusSet(ON);
  33. BeepStatusSet(ON);
  34. }
  35. else
  36. {
  37. LedSafeStatusSet(ON);
  38. LedWarnStatusSet(OFF);
  39. BeepStatusSet(OFF);
  40. }
  41. sleep(2);
  42. }
  43. }
  44. static void ExampleEntry(void)
  45. {
  46. osThreadAttr_t attr;
  47. attr.name = "ExampleTask";
  48. attr.attr_bits = 0U;
  49. attr.cb_mem = NULL;
  50. attr.cb_size = 0U;
  51. attr.stack_mem = NULL;
  52. attr.stack_size = TASK_STACK_SIZE;
  53. attr.priority = TASK_PRIO;
  54. if (osThreadNew((osThreadFunc_t)ExampleTask, NULL, &attr) == NULL) {
  55. printf("Failed to create ExampleTask!\n");
  56. }
  57. }
  58. APP_FEATURE_INIT(ExampleEntry);