合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
打开task\_example.c文件,内容如下: ### &emsp;&emsp;该任务实现的功能:获取温湿度数据,在显示屏上进行显示,进入低功耗模式,定期唤醒再获取温湿度数据,再显示,然后再进入低功耗,如此反复。 ``` #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; } ```