A17_CH2O.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 <math.h>
  19. #include "ohos_init.h"
  20. #include "cmsis_os2.h"
  21. #include "CH2O.h"
  22. #define TASK_STACK_SIZE 1024*8
  23. #define TASK_PRIO 25
  24. static void ExampleTask(void)
  25. {
  26. int ret;
  27. float ppm;
  28. BoardInit();
  29. //Sensor calibration
  30. usleep(1000000);
  31. MQ2PPMCalibration();
  32. while (1) {
  33. printf("=======================================\r\n");
  34. printf("*************A22_MQ2_example***********\r\n");
  35. printf("=======================================\r\n");
  36. //get mq2 ppm
  37. ret = GetMQ2PPM(&ppm);
  38. if (ret != 0) {
  39. printf("ADC Read Fail\n");
  40. return ;
  41. }
  42. printf("ppm:%.3f \n", ppm);
  43. if (ppm > 20) {
  44. BeepStatusSet(ON);
  45. LedSafeStatusSet(OFF);
  46. LedWarnStatusSet(ON);
  47. } else {
  48. BeepStatusSet(OFF);
  49. LedSafeStatusSet(ON);
  50. LedWarnStatusSet(OFF);
  51. }
  52. usleep(1000000);
  53. }
  54. }
  55. /**
  56. * @brief Main Entry of the A22_MQ2 Example
  57. *
  58. */
  59. static void ExampleEntry(void)
  60. {
  61. osThreadAttr_t attr;
  62. attr.name = "ExampleTask";
  63. attr.attr_bits = 0U;
  64. attr.cb_mem = NULL;
  65. attr.cb_size = 0U;
  66. attr.stack_mem = NULL;
  67. attr.stack_size = TASK_STACK_SIZE;
  68. attr.priority = TASK_PRIO;
  69. if (osThreadNew((osThreadFunc_t)ExampleTask, NULL, &attr) == NULL) {
  70. printf("Failed to create ExampleTask!\n");
  71. }
  72. }
  73. APP_FEATURE_INIT(ExampleEntry);