• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 Nanjing Xiaoxiongpai Intelligent 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 
16 #include <stdio.h>
17 #include <string.h>
18 #include <unistd.h>
19 
20 #include "E53_SC1.h"
21 #include "cmsis_os2.h"
22 #include "ohos_init.h"
23 
24 #define TASK_STACK_SIZE (1024 * 8)
25 #define TASK_PRIO 25
26 #define MIN_LUX 20
27 #define TASK_DELAY_1S 1000000
28 
ExampleTask(void)29 static void ExampleTask(void)
30 {
31     int ret;
32     float Lux;
33 
34     ret = E53SC1Init();
35     if (ret != 0) {
36         printf("E53_SC1 Init failed!\r\n");
37         return;
38     }
39 
40     while (1) {
41         printf("=======================================\r\n");
42         printf("*************E53_SC1_example***********\r\n");
43         printf("=======================================\r\n");
44         ret = E53SC1ReadData(&Lux);
45         if (ret != 0) {
46             printf("E53_SC1 Read Data failed!\r\n");
47             return;
48         }
49         printf("Lux data:%.2f\r\n", Lux);
50         if (Lux < MIN_LUX) {
51             LightStatusSet(ON);
52         } else {
53             LightStatusSet(OFF);
54         }
55         usleep(TASK_DELAY_1S);
56     }
57 }
58 
ExampleEntry(void)59 static void ExampleEntry(void)
60 {
61     osThreadAttr_t attr;
62 
63     attr.name = "ExampleTask";
64     attr.attr_bits = 0U;
65     attr.cb_mem = NULL;
66     attr.cb_size = 0U;
67     attr.stack_mem = NULL;
68     attr.stack_size = TASK_STACK_SIZE;
69     attr.priority = TASK_PRIO;
70 
71     if (osThreadNew((osThreadFunc_t)ExampleTask, NULL, &attr) == NULL) {
72         printf("Failed to create ExampleTask!\n");
73     }
74 }
75 
76 APP_FEATURE_INIT(ExampleEntry);