打开task\_example.c文件,内容如下:
###
  该任务实现的功能:获取温湿度数据,在显示屏上进行显示,进入低功耗模式,定期唤醒再获取温湿度数据,再显示,然后再进入低功耗,如此反复。
```
#include "task_example.h"
#include "svc_log.h"
#include "svc_humiture.h"
#include "svc_system.h"
#include "mathlib.h"
#include <string.h>
/*
* System Status for this task, we can contorls this status to decide work mode.
*/
static svc_system_status_descripter_t task_example_status;
/*
* Function declaration: System status feedback function.
*/
static svc_system_status_descripter_t task_example_status_feedback(void);
/*
* Function declaration: Runner for this task.
*/
static void task_example_run(void);
/*
* Function declaration: Deepsleep for this task.
*/
static void task_example_deepsleep(void);
/*
* Task initialization.
*/
void task_example_init()
{
/* Set current system status to BUSY */
task_example_status.indication = SVC_SYSTEM_STATUS_BUSY;
/* Register system status feedback function */
svc_system_register_status_feedback(task_example_status_feedback);
/* Start a timer to get temperature and humidity */
svc_system_start_timer(task_example_run, 1000, 0);
}
/*
* Function implementation: Runner for this task.
*/
void task_example_run()
{
float temp, humi;
char temp_str[16] = "Temp(C): ";
char humi_str[16] = "Humi(%): ";
/* Get temperature and humidity and then display on the LCD */
if (svc_humiture_get(&temp, &humi) == 0) {
strcpy(&temp_str[strlen(temp_str)], ftoa(temp, 1));
strcpy(&humi_str[strlen(humi_str)], ftoa(humi, 1));
svc_log_write_lcd_lines(1, temp_str, 0, humi_str, 0);
}
/* Start a timer to enter deepsleep mode */
svc_system_start_timer(task_example_deepsleep, 3000, 0);
}
/*
* Function implementation: Deepsleep for this task.
*/
void task_example_deepsleep()
{
/* Set this task status to SVC_SYSTEM_STATUS_PERIODIC_DEEPSLEEP */
task_example_status.indication = SVC_SYSTEM_STATUS_PERIODIC_DEEPSLEEP;
/* Deepsleep for 5 seconds */
task_example_status.seconds = 5;
}
/*
* Function implementation: System status feedback function.
*/
svc_system_status_descripter_t task_example_status_feedback()
{
return task_example_status;
}
```
- 框架介绍
- Main 函数
- HAL 函数接口说明
- hal_system.h
- hal_systick.h
- hal_idt.h
- hal_ioctl.h
- hal_flash.h
- hal_lpm.h
- hal_rtc.h
- hal_iwdg.h
- hal_uart.h
- hal_i2c.h
- hal_led.h
- hal_button.h
- hal_vht2x.h
- hal_lcd.h
- Services 函数接口说明
- svc_system.h
- svc_database.h
- svc_hid.h
- svc_msg.h
- svc_humiture.h
- svc_log.h
- Tasks 说明
- task_system.c
- task_example.c
- Libs 函数接口说明
- mathlib.h
- json.h
- atcmd.h
- atcmd_proxy.h
- libwifi.h
- libs1.h