app_aht10.c
#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>
#include “aht10.h”
extern struct aht10_device *temp_humi_dev;
/* 定义一个温湿度采集线程句柄结构体指针 */
static rt_thread_t aht10_thread = RT_NULL;
/* 温湿度采集线程入口函数*/
static void aht10_thread_entry(void parameter)
{
float humidity, temperature;
while (1)
{
/ read humidity 采集湿度 /
humidity = aht10_read_humidity(temp_humi_dev);
rt_kprintf(“humidity : %d.%d %%\n”, (int)humidity, (int)(humidity * 10) % 10); / former is integer and behind is decimal */
/* read temperature 采集温度 */
temperature = aht10_read_temperature(temp_humi_dev);
rt_kprintf("temperature: %d.%d \n", (int)temperature, (int)(temperature * 10) % 10); /* former is integer and behind is decimal */
rt_thread_mdelay(1000);
}
}
static int app_aht10_init(void)
{
rt_err_t rt_err;
/* 创建温湿度采集线程*/
aht10_thread = rt_thread_create(“aht10 thread”, /* 线程的名称 /
aht10_thread_entry, / 线程入口函数 /
RT_NULL, / 线程入口函数的参数 /
1024, / 线程栈大小,单位是字节 /
25, / 线程的优先级,数值越小优先级越高*/
10); /* 线程的时间片大小 /
/ 如果获得线程控制块,启动这个线程 */
if (aht10_thread != RT_NULL)
rt_err = rt_thread_startup(aht10_thread);
else
rt_kprintf(“aht10 thread create failure !!! \n”);
/* 判断线程是否创建成功 */
if( rt_err != RT_EOK)
rt_kprintf("aht10 thread startup err. \n");
return RT_EOK;
}
INIT_APP_EXPORT(app_aht10_init);
main.c
#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>
#include <drv_lcd.h>
#include <rttlogo.h>
#define DBG_TAG “main”
#define DBG_LVL DBG_LOG
#include <rtdbg.h>
float humidity, temperature;
int main(void)
{
lcd_clear(WHITE);
/* show RT-Thread logo */
lcd_show_image(0, 0, 240, 69, image_rttlogo);
/* set the background color and foreground color */
lcd_set_color(WHITE, BLACK);
/* show some string on lcd */
//lcd_show_string(10, 69, 16, “Hello, RT-Thread!”);
// lcd_show_string(10, 69 + 16, 24, “RT-Thread”);
// lcd_show_string(10, 69 + 16 + 24, 32, “RT-Thread”);
lcd_show_string(10, 75, 24, “Temp: %d.%d C”, (int)temperature, (int)(temperature * 10) % 10);
lcd_show_string(10, 105, 24, “Humi: %d.%d %%”, (int)humidity, (int)(humidity * 10) % 10);
// lcd_show_string(10, 75, 24, “Temp:36.4 C”, (int)temperature, (int)(temperature * 10) % 10);
// lcd_show_string(10, 105, 24, “Humi:49.6 %%”, (int)humidity, (int)(humidity * 10) % 10);
/* draw a line on lcd */
lcd_draw_line(0, 69 + 16 + 24 + 32, 240, 69 + 16 + 24 + 32);
/* draw a concentric circles */
lcd_draw_point(120, 194);
for (int i = 0; i < 46; i += 4)
{
lcd_draw_circle(120, 194, i);
}
return 0;
}
rttlogo.h
SConscript
from building import *
import os
cwd = GetCurrentDir()
CPPPATH = [cwd]
src = Glob(‘*.c’)
group = DefineGroup(‘Applications’, src, depend = [‘’], CPPPATH = CPPPATH)
list = os.listdir(cwd)
for item in list:
if os.path.isfile(os.path.join(cwd, item, ‘SConscript’)):
group = group + SConscript(os.path.join(item, ‘SConscript’))
Return(‘group’)