【2024 DigiKey 创意大赛】室内智能照明灯设计---进度篇3
[复制链接]
10.1假期后继续对室内照明灯的程序继续开发,完整了主题程序架构的设计,目前只剩下温度传感器与MPU6050程序未开发。整理架构采用FreeRtos系统,将整体功能分为不同的线程处理,保证整体功能的实时性。
。。。。。。本来也想将温度传感器加入其中,但是发现D6T-1A-2C的IO电平为5V,与ESP32开发板电平不兼容,故后期考虑采用HT-30温湿度传感器开发。
当前,系统已经集成LCD屏幕与小爱同学功能,具体程序如下:
void UI_Init()
{
lv_obj_t *scr = lv_scr_act(); //创建scr
lv_obj_set_pos(scr,0,0);
lv_scr_load(scr);
label_1 =lv_label_create(scr);//创建label
lv_label_set_recolor(label_1,1);//颜色可变换
lv_label_set_long_mode(label_1,LV_LABEL_LONG_SCROLL_CIRCULAR);//设置滚动模式
lv_obj_set_pos(label_1,100,100);//设置位置
lv_obj_set_size(label_1,160,30);//设定大小
lv_label_set_text(label_1, "This is a GUI thread yes");//设定文本内容
label_2 =lv_label_create(scr);//创建labe2
lv_label_set_recolor(label_2,1);//颜色可变换
lv_label_set_long_mode(label_2,LV_LABEL_LONG_SCROLL_CIRCULAR);//设置滚动模式
lv_obj_set_pos(label_2,100,400);//设置位置
lv_obj_set_size(label_2,160,40);//设定大小
lv_label_set_text(label_2, "#ff0000 red#");//设定文本内容
}
/**
* [url=home.php?mod=space&uid=159083]@brief[/url] 初始化
* @param 无
* @retval 无
*/
void My_Init()
{
Serial.begin(115200);
Serial.println(title + " start");
/*Bllier 初始化*/
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
BLINKER_DEBUG.debugAll();
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
Blinker.begin(auth, ssid, pswd);
Blinker.attachData(dataRead);
BlinkerMIOT.attachPowerState(miotPowerState);
BlinkerMIOT.attachColor(miotColor);
BlinkerMIOT.attachMode(miotMode);
BlinkerMIOT.attachBrightness(miotBright);
BlinkerMIOT.attachColorTemperature(miotColoTemp);
BlinkerMIOT.attachQuery(miotQuery);
colorR = 255;
colorG = 255;
colorB = 255;
colorW = 0;
colorT = 0;
wsState = true;
pixels.begin();
pixels.setBrightness(colorW);
WS2812.attach(ws2812_callback);
pixelShow();
/* 屏幕初始化 */
Serial.println("Initialize panel device");
ESP_Panel *panel = new ESP_Panel();
panel->init();
#if LVGL_PORT_AVOID_TEAR
// When avoid tearing function is enabled, configure the RGB bus according to the LVGL configuration
ESP_PanelBus_RGB *rgb_bus = static_cast<ESP_PanelBus_RGB *>(panel->getLcd()->getBus());
rgb_bus->configRgbFrameBufferNumber(LVGL_PORT_DISP_BUFFER_NUM);
rgb_bus->configRgbBounceBufferSize(LVGL_PORT_RGB_BOUNCE_BUFFER_SIZE);
#endif
panel->begin();
/* lvgl初始化 */
Serial.println("Initialize LVGL");
lvgl_port_init(panel->getLcd(), panel->getTouch());
UI_Init();
}
/*======================================= TaskAPPStart ====================================*/
/*
* @brief: 启动创建任务
* @param:none
* @retval:none
*/
void TaskAPPStart()
{
// sem_Blinker = xSemaphoreCreateCounting(1, 0);
// if (sem_Blinker == NULL)
// {
// Serial.println("Blinker信号量创建失败......");
// }
// else
// {
// Serial.println("Blinker信号量创建成功......");
// }
// sem_LVGL = xSemaphoreCreateCounting(1, 0);
// if (sem_LVGL == NULL)
// {
// Serial.println("LVGL信号量创建失败......");
// }
// else
// {
// Serial.println("LVGL信号量创建成功......");
// }
/*创建Blinker线程*/
BaseType_t status;
status = xTaskCreatePinnedToCore(
(TaskFunction_t)ThreadBlinkerEntry, //Weather线程入口
(const char *const) "Thread_Blinker", //线程名称
(const uint32_t)4096 * 2, //线程栈
(void *const)NULL, //Weather线程入口参数
(UBaseType_t)6, //线程优先级 0-24 数值越大优先级越高
(TaskHandle_t *)&ThreadBlinker, //线程句柄
(const BaseType_t)APP_CPU_NUM); //指定内核1
if (status == pdPASS)
{
Serial.println("Blinker线程创建成功...");
}
else
{
Serial.println("Blinker线程创建失败...");
}
/*创建LVGL线程*/
status = xTaskCreatePinnedToCore(
(TaskFunction_t)ThreadLVGLEntry, //OLED线程
(const char *const) "Thread_LVGL", //线程名称
(const uint32_t)4096 * 8, //线程栈
(void *const)NULL, //OLED线程入口参数
(UBaseType_t)2, //线程优先级 0-24 数值越大优先级越高
(TaskHandle_t *)&ThreadLVGL, //线程句柄
(const BaseType_t)APP_CPU_NUM); //指定内核1
if (status == pdPASS)
{
Serial.println("LVGL线程创建成功...");
}
else
{
Serial.println("LVGL线程创建失败...");
}
/*连接网络提示定时器*/
TimeAlarmLED = xTimerCreate(
"TIM_Alarm_LED", //定时器名称
pdMS_TO_TICKS(100), //定时器定时时间
pdTRUE, //pdTRUE = 周期性 , pdFALSE = 一次性
0, //定时器ID
TIMAlarmLEDEntry); //定时器回调函数
xTimerStart(TimeAlarmLED, 0);
delay(1000);
}
/*
* @brief:Blinker线程入口
* @param:none
* @retval:none
*/
void ThreadBlinkerEntry(void *pvParameters)
{
// xSemaphoreTake(sem_Blinker, portMAX_DELAY);
while (1)
{
Blinker.run();
for(int i = 0; i < NUMPIXELS; i++){
pixels.setPixelColor(i, colorR, colorG, colorB);
}
pixels.show();
LedControl(colorW,colorT);
// Serial.println("===================== POST =====================");
vTaskDelay(pdMS_TO_TICKS(10));
}
}
/*
* @brief:LVGL线程入口
* @param:none
* @retval:none
*/
void ThreadLVGLEntry(void *pvParameters)
{
// xSemaphoreTake(sem_LVGL, portMAX_DELAY);
ESP_LOGD(TAG, "Starting LVGL task");
uint32_t task_delay_ms = LVGL_PORT_TASK_MAX_DELAY_MS;
while (1) {
if (lvgl_port_lock(-1)) {
task_delay_ms = lv_timer_handler();
lvgl_port_unlock();
}
if (task_delay_ms > LVGL_PORT_TASK_MAX_DELAY_MS) {
task_delay_ms = LVGL_PORT_TASK_MAX_DELAY_MS;
} else if (task_delay_ms < LVGL_PORT_TASK_MIN_DELAY_MS) {
task_delay_ms = LVGL_PORT_TASK_MIN_DELAY_MS;
}
vTaskDelay(pdMS_TO_TICKS(task_delay_ms));
}
}
/*
* @brief:空闲线程入口
* @param:none
* @retval:none
*/
void TIMAlarmLEDEntry(TimerHandle_t xTimer)
{
// digitalWrite(LED, !digitalRead(LED));
}
void loop()
{
}
|