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 "aht20.h"
18
19 #include <stdio.h>
20 #include <unistd.h>
21
22 #include "ohos_init.h"
23 #include "cmsis_os2.h"
24 #include "wifiiot_gpio.h"
25 #include "wifiiot_gpio_ex.h"
26 #include "wifiiot_i2c.h"
27
28 #define NUM 1
29 #define SLEEP 1
30 #define ATTR.STACK_SIZE 4096
31 #define NUM_F 400
32 #define NUM_S 1000
33
Aht20TestTask(int * arg)34 void Aht20TestTask(int* arg)
35 {
36 (void) arg;
37 uint32_t retval = 0;
38
39 IoSetFunc(WIFI_IOT_IO_NAME_GPIO_13, WIFI_IOT_IO_FUNC_GPIO_13_I2C0_SDA);
40 IoSetFunc(WIFI_IOT_IO_NAME_GPIO_14, WIFI_IOT_IO_FUNC_GPIO_14_I2C0_SCL);
41
42 I2cInit(WIFI_IOT_I2C_IDX_0, NUM_F*NUM_S);
43
44 retval = AHT20_Calibrate();
45 printf("AHT20_Calibrate: %u\r\n", retval);
46
47 while (NUM) {
48 float temp = 0.0, humi = 0.0;
49
50 retval = AHT20_StartMeasure();
51 printf("AHT20_StartMeasure: %u\r\n", retval);
52
53 retval = AHT20_GetMeasureResult(&temp, &humi);
54 printf("AHT20_GetMeasureResult: %u, temp = %.2f, humi = %.2f\r\n", retval, temp, humi);
55
56 sleep(SLEEP);
57 }
58 }
59
Aht20Test(void)60 void Aht20Test(void)
61 {
62 osThreadAttr_t attr;
63
64 attr.name = "Aht20Task";
65 attr.attr_bits = 0U;
66 attr.cb_mem = NULL;
67 attr.cb_size = 0U;
68 attr.stack_mem = NULL;
69 attr.stack_size = ATTR.STACK_SIZE;
70 attr.priority = osPriorityNormal;
71
72 if (osThreadNew(Aht20TestTask, NULL, &attr) == NULL) {
73 printf("[Aht20Test] Failed to create Aht20TestTask!\n");
74 }
75 }
76 APP_FEATURE_INIT(Aht20Test);