A21_Agriculture_example.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 "BH1750.h"
  19. #include "cmsis_os2.h"
  20. #include "ohos_init.h"
  21. #define TASK_STACK_SIZE 1024 * 8
  22. #define TASK_PRIO 25
  23. uint8_t fan_status;
  24. static void ExampleTask(void)
  25. {
  26. int ret;
  27. uint8_t dht_temperature;
  28. uint8_t dht_humidity;
  29. float Lux;
  30. // BoardInit();
  31. //GPIO_0复用为I2C1_SDA
  32. ret = BoardInit();
  33. if (ret != 0) {
  34. printf("E53_SC1 Init failed!\r\n");
  35. return;
  36. }
  37. while (1)
  38. {
  39. ret = BH1750ReadData(&Lux);
  40. if (ret != 0) {
  41. printf("E53_SC1 Read Data failed!\r\n");
  42. return;
  43. }
  44. printf("Lux data:%.2f\r\n", Lux);
  45. if (Lux < 20) {
  46. LightStatusSet(ON);
  47. } else {
  48. LightStatusSet(OFF);
  49. }
  50. sleep(3);
  51. }
  52. }
  53. static void ExampleEntry(void)
  54. {
  55. osThreadAttr_t attr;
  56. attr.name = "ExampleTask";
  57. attr.attr_bits = 0U;
  58. attr.cb_mem = NULL;
  59. attr.cb_size = 0U;
  60. attr.stack_mem = NULL;
  61. attr.stack_size = TASK_STACK_SIZE;
  62. attr.priority = TASK_PRIO;
  63. if (osThreadNew((osThreadFunc_t)ExampleTask, NULL, &attr) == NULL) {
  64. printf("Failed to create ExampleTask!\n");
  65. }
  66. }
  67. APP_FEATURE_INIT(ExampleEntry);