A04_NOISE_example.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 "noise.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. usleep(1000000);
  28. while (1)
  29. {
  30. ad_value = GetVoltage();
  31. if(NoiseReadData() == 0)
  32. {
  33. printf("Near the noise!\n");
  34. printf("ad_value:%2.2fV\n",ad_value);
  35. LedWarnStatusSet(ON);
  36. }
  37. else{
  38. printf("Far the noise!\n");
  39. printf("ad_value:%2.2fV\n",ad_value);
  40. LedWarnStatusSet(OFF);
  41. }
  42. sleep(1);
  43. }
  44. }
  45. static void ExampleEntry(void)
  46. {
  47. osThreadAttr_t attr;
  48. attr.name = "ExampleTask";
  49. attr.attr_bits = 0U;
  50. attr.cb_mem = NULL;
  51. attr.cb_size = 0U;
  52. attr.stack_mem = NULL;
  53. attr.stack_size = TASK_STACK_SIZE;
  54. attr.priority = TASK_PRIO;
  55. if (osThreadNew((osThreadFunc_t)ExampleTask, NULL, &attr) == NULL) {
  56. printf("Failed to create ExampleTask!\n");
  57. }
  58. }
  59. APP_FEATURE_INIT(ExampleEntry);