A18_ST02D_example.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright (c) 2022 Jinan Bosai Network Technology Co., LTD 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 "st02d.h"
  19. #include "cmsis_os2.h"
  20. #include "ohos_init.h"
  21. #define TASK_STACK_SIZE 1024 * 8
  22. #define TASK_PRIO 25
  23. // #define FLAGS_MSK1 0x00000001U
  24. // osEventFlagsId_t evt_id;
  25. // static void Beep_Alarm(char *arg)
  26. // {
  27. // (void)arg;
  28. // osEventFlagsSet(evt_id, FLAGS_MSK1);
  29. // printf("Beep_Alarm\n");
  30. // }
  31. static void ExampleTask(void)
  32. {
  33. // ST02D_Init();
  34. // Button_Left_Read_Data(Beep_Alarm);
  35. // Button_Right_Read_Data(Beep_Alarm);
  36. // while (1)
  37. // {
  38. // osEventFlagsWait(evt_id, FLAGS_MSK1, osFlagsWaitAny, osWaitForever);
  39. // BeepStatusSet(ON);
  40. // LedWarnStatusSet(ON);
  41. // osDelay(300);
  42. // BeepStatusSet(OFF);
  43. // LedWarnStatusSet(OFF);
  44. // }
  45. ST02D_Init();
  46. // Button_Left_Read_Data(Beep_Alarm);
  47. // Button_Right_Read_Data(Beep_Alarm);
  48. while (1)
  49. {
  50. if(Button_Left_Read_Data() == 0|Button_Right_Read_Data() == 0)
  51. {
  52. BeepStatusSet(ON);
  53. LedWarnStatusSet(ON);
  54. }
  55. else
  56. {
  57. BeepStatusSet(OFF);
  58. LedWarnStatusSet(OFF);
  59. }
  60. sleep(1);
  61. }
  62. }
  63. static void ExampleEntry(void)
  64. {
  65. osThreadAttr_t attr;
  66. attr.name = "ExampleTask";
  67. attr.attr_bits = 0U;
  68. attr.cb_mem = NULL;
  69. attr.cb_size = 0U;
  70. attr.stack_mem = NULL;
  71. attr.stack_size = TASK_STACK_SIZE;
  72. attr.priority = TASK_PRIO;
  73. if (osThreadNew((osThreadFunc_t)ExampleTask, NULL, &attr) == NULL) {
  74. printf("Failed to create ExampleTask!\n");
  75. }
  76. }
  77. APP_FEATURE_INIT(ExampleEntry);