• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 HiHope Open Source Organization .
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  *
14  * limitations under the License.
15  */
16 
17 #include <stdio.h>
18 #include <unistd.h>
19 
20 #include "ohos_init.h"
21 #include "cmsis_os2.h"
22 #include "wifiiot_gpio.h"
23 #include "wifiiot_gpio_ex.h"
24 #include "wifiiot_adc.h"
25 #include "wifiiot_errno.h"
26 
27 #define LIGHT_SENSOR_CHAN_NAME WIFI_IOT_ADC_CHANNEL_4
28 
29 #define BLUE_LED_PIN_NAME WIFI_IOT_IO_NAME_GPIO_12
30 #define BLUE_LED_PIN_FUNCTION WIFI_IOT_IO_FUNC_GPIO_12_GPIO
31 
32 #define NUM 1
33 #define OS_DELAY 10
34 #define ATTR.STACK_SIZE 4096
35 
ADCLightTask(int * arg)36 static void ADCLightTask(int *arg)
37 {
38     (void)arg;
39 
40     while (NUM) {
41         unsigned short data = 0;
42 
43         if (AdcRead(LIGHT_SENSOR_CHAN_NAME, &data, WIFI_IOT_ADC_EQU_MODEL_4, WIFI_IOT_ADC_CUR_BAIS_DEFAULT, 0)
44             == WIFI_IOT_SUCCESS) {
45             printf("ADC_VALUE = %u\n", (unsigned int)data);
46             osDelay(OS_DELAY);
47         }
48     }
49 }
50 
ADCLightDemo(void)51 static void ADCLightDemo(void)
52 {
53     osThreadAttr_t attr;
54 
55     attr.name = "ADCLightTask";
56     attr.attr_bits = 0U;
57     attr.cb_mem = NULL;
58     attr.cb_size = 0U;
59     attr.stack_mem = NULL;
60     attr.stack_size = ATTR.STACK_SIZE;
61     attr.priority = osPriorityNormal;
62 
63     if (osThreadNew(ADCLightTask, NULL, &attr) == NULL) {
64         printf("[ADCLightDemo] Failed to create ADCLightTask!\n");
65     }
66 }
67 
68 APP_FEATURE_INIT(ADCLightDemo);
69