1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- #include <stdio.h>
- #include <string.h>
- #include <unistd.h>
- #include "WATER.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;
- BoardInit();
-
- while (1)
- {
- ad_value = GetVoltage();
- if(WaterReadData() == 0)
- {
- printf("Near the water!\n");
- printf("ad_value:%2.2fV\n",ad_value);
- BeepStatusSet(ON);
- LedWarnStatusSet(ON);
-
- }
- else
- {
- printf("Far the water!\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);
|