A11_PM2_5_example.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright (c) 2022 Jinan Bosai Network Technology Co., LTD 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 "PM2_5.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. PM2D5Data data;
  26. BoardInit();
  27. // LedWarnStatusSet(ON);
  28. LedSafeStatusSet(ON);
  29. while (1) {
  30. PM2DReadData(&data);
  31. printf("\r\n******************************PM1.0 is %d\r\n", data.pm1_0);
  32. printf("\r\n******************************PM2.5 is %d\r\n", data.pm2_5);
  33. printf("\r\n******************************PM10 is %d\r\n", data.pm10);
  34. sleep(1);
  35. }
  36. }
  37. static void ExampleEntry(void)
  38. {
  39. osThreadAttr_t attr;
  40. attr.name = "ExampleTask";
  41. attr.attr_bits = 0U;
  42. attr.cb_mem = NULL;
  43. attr.cb_size = 0U;
  44. attr.stack_mem = NULL;
  45. attr.stack_size = TASK_STACK_SIZE;
  46. attr.priority = TASK_PRIO;
  47. if (osThreadNew((osThreadFunc_t)ExampleTask, NULL, &attr) == NULL) {
  48. printf("Failed to create ExampleTask!\n");
  49. }
  50. }
  51. APP_FEATURE_INIT(ExampleEntry);