1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- #include <stdio.h>
- #include <string.h>
- #include <unistd.h>
- #include <math.h>
- #include "ohos_init.h"
- #include "cmsis_os2.h"
- #include "MQ5.h"
- #define TASK_STACK_SIZE 1024*8
- #define TASK_PRIO 25
- static void ExampleTask(void)
- {
- int ret;
- float ppm;
-
- BoardInit();
-
- usleep(1000000);
- MQ5PPMCalibration();
-
- while (1) {
- printf("=======================================\r\n");
- printf("*************A02_MQ5_example***********\r\n");
- printf("=======================================\r\n");
-
- ret = GetMQ5PPM(&ppm);
- if (ret != 0) {
- printf("ADC Read Fail\n");
- return ;
- }
- printf("ppm:%.3f \n", ppm);
- if (ppm > 30) {
- BeepStatusSet(ON);
- LedStatusSet(ON);
- } else {
- BeepStatusSet(OFF);
- LedStatusSet(OFF);
- }
- usleep(1000000);
- }
- }
- static void ExampleEntry(void)
- {
- osThreadAttr_t attr;
- attr.name = "ExampleTask";
- attr.attr_bits = 0U;
- attr.cb_mem = NULL;
- attr.cb_size = 0U;
- attr.stack_mem = NULL;
- attr.stack_size = TASK_STACK_SIZE;
- attr.priority = TASK_PRIO;
- if (osThreadNew((osThreadFunc_t)ExampleTask, NULL, &attr) == NULL) {
- printf("Failed to create ExampleTask!\n");
- }
- }
- APP_FEATURE_INIT(ExampleEntry);
|