A13_FLAME_example..c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 "flame.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. FlameInit();
  27. usleep(1000000);
  28. while (1)
  29. {
  30. ad_value = GetVoltage();
  31. if(FlameReadData() == 0)
  32. {
  33. printf("Near the flame!\n");
  34. printf("ad_value:%2.2fV\n",ad_value);
  35. BeepStatusSet(ON);
  36. LedWarnStatusSet(ON);
  37. }
  38. else{
  39. printf("Far the flame!\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);