A11_PM2_5_example.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 "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. while (1) {
  28. PM2DReadData(&data);
  29. // printf("\r\n******************************PM1.0 is %d\r\n", data.pm1_0);
  30. // printf("\r\n******************************PM2.5 is %d\r\n", data.pm2_5);
  31. // printf("\r\n******************************PM10 is %d\r\n", data.pm10);
  32. // sleep(1);
  33. RelayStatusSet(ON);
  34. osDelay(200);
  35. RelayStatusSet(OFF);
  36. osDelay(200);
  37. }
  38. }
  39. static void ExampleEntry(void)
  40. {
  41. osThreadAttr_t attr;
  42. attr.name = "ExampleTask";
  43. attr.attr_bits = 0U;
  44. attr.cb_mem = NULL;
  45. attr.cb_size = 0U;
  46. attr.stack_mem = NULL;
  47. attr.stack_size = TASK_STACK_SIZE;
  48. attr.priority = TASK_PRIO;
  49. if (osThreadNew((osThreadFunc_t)ExampleTask, NULL, &attr) == NULL) {
  50. printf("Failed to create ExampleTask!\n");
  51. }
  52. }
  53. APP_FEATURE_INIT(ExampleEntry);