A02_WATER_example.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright (c) 2020  Jinan Bosai Network 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. #include <stdio.h>
  16. #include <string.h>
  17. #include <unistd.h>
  18. #include "WATER.h"
  19. #include "cmsis_os2.h"
  20. #include "ohos_init.h"
  21. #define TASK_STACK_SIZE 1024 * 8
  22. #define TASK_PRIO 25
  23. static void ExampleTask(void)
  24. {
  25. float ad_value;
  26. BoardInit();
  27. while (1)
  28. {
  29. ad_value = GetVoltage();
  30. if(WaterReadData() == 0)
  31. {
  32. printf("Near the water!\n");
  33. printf("ad_value:%2.2fV\n",ad_value);
  34. BeepStatusSet(ON);
  35. LedWarnStatusSet(ON);
  36. }
  37. else
  38. {
  39. printf("Far the water!\n");
  40. printf("ad_value:%2.2fV\n",ad_value);
  41. BeepStatusSet(OFF);
  42. LedWarnStatusSet(OFF);
  43. }
  44. sleep(1);
  45. }
  46. }
  47. static void ExampleEntry(void)
  48. {
  49. osThreadAttr_t attr;
  50. attr.name = "ExampleTask";
  51. attr.attr_bits = 0U;
  52. attr.cb_mem = NULL;
  53. attr.cb_size = 0U;
  54. attr.stack_mem = NULL;
  55. attr.stack_size = TASK_STACK_SIZE;
  56. attr.priority = TASK_PRIO;
  57. if (osThreadNew((osThreadFunc_t)ExampleTask, NULL, &attr) == NULL) {
  58. printf("Failed to create ExampleTask!\n");
  59. }
  60. }
  61. APP_FEATURE_INIT(ExampleEntry);