12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- #include <stdio.h>
- #include <string.h>
- #include <unistd.h>
- #include "flame.h"
- #include "cmsis_os2.h"
- #include "ohos_init.h"
- #define TASK_STACK_SIZE 1024 * 8
- #define TASK_PRIO 25
- static void ExampleTask(void)
- {
- float ad_value;
- FlameInit();
- usleep(1000000);
- while (1)
- {
- ad_value = GetVoltage();
- if(FlameReadData() == 0)
- {
- printf("Near the flame!\n");
- printf("ad_value:%2.2fV\n",ad_value);
- BeepStatusSet(ON);
- LedWarnStatusSet(ON);
-
- }
- else{
- printf("Far the flame!\n");
- printf("ad_value:%2.2fV\n",ad_value);
- BeepStatusSet(OFF);
- LedWarnStatusSet(OFF);
- }
- sleep(1);
- }
- }
- 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);
|