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