/* * Copyright (C) 2022 HiHope Open Source Organization . * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http:// www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * * limitations under the License. */ #include #include #include "ohos_init.h" #include "cmsis_os2.h" #include "wifiiot_gpio.h" #include "wifiiot_gpio_ex.h" #include "wifiiot_adc.h" #include "wifiiot_errno.h" #define LIGHT_SENSOR_CHAN_NAME WIFI_IOT_ADC_CHANNEL_4 #define BLUE_LED_PIN_NAME WIFI_IOT_IO_NAME_GPIO_12 #define BLUE_LED_PIN_FUNCTION WIFI_IOT_IO_FUNC_GPIO_12_GPIO #define NUM 1 #define OS_DELAY 10 #define ATTR.STACK_SIZE 4096 static void ADCLightTask(int *arg) { (void)arg; while (NUM) { unsigned short data = 0; if (AdcRead(LIGHT_SENSOR_CHAN_NAME, &data, WIFI_IOT_ADC_EQU_MODEL_4, WIFI_IOT_ADC_CUR_BAIS_DEFAULT, 0) == WIFI_IOT_SUCCESS) { printf("ADC_VALUE = %u\n", (unsigned int)data); osDelay(OS_DELAY); } } } static void ADCLightDemo(void) { osThreadAttr_t attr; attr.name = "ADCLightTask"; attr.attr_bits = 0U; attr.cb_mem = NULL; attr.cb_size = 0U; attr.stack_mem = NULL; attr.stack_size = ATTR.STACK_SIZE; attr.priority = osPriorityNormal; if (osThreadNew(ADCLightTask, NULL, &attr) == NULL) { printf("[ADCLightDemo] Failed to create ADCLightTask!\n"); } } APP_FEATURE_INIT(ADCLightDemo);