feat: 电脑音量和显示器亮度设置界面。

This commit is contained in:
Ivan Li 2023-05-03 23:55:54 +08:00
parent 3f5ca686cf
commit a3abff89c5
5 changed files with 114 additions and 7 deletions

View File

@ -1,6 +1,5 @@
idf_component_register( idf_component_register(
SRCS SRCS
"udp_server.c"
"service_discovery.c" "service_discovery.c"
"app_nvs.c" "app_nvs.c"
"ch1116.c" "ch1116.c"
@ -13,6 +12,7 @@ idf_component_register(
# "ambient_light.c" # "ambient_light.c"
# "temperature.c" # "temperature.c"
# "mqtt.c" # "mqtt.c"
"desktop.c"
"main.c" "main.c"
"wifi.c" "wifi.c"
"light.c" "light.c"

View File

@ -16,6 +16,7 @@
#include "lwip/sockets.h" #include "lwip/sockets.h"
#include "lwip/sys.h" #include "lwip/sys.h"
#include "nvs_flash.h" #include "nvs_flash.h"
#include "ui_input.c"
#define UDP_PORT 23042 #define UDP_PORT 23042
@ -24,6 +25,28 @@ static const char *UDP_SERVER_TAG = "UDP_SERVER";
static bool desktop_connected = false; static bool desktop_connected = false;
static uint64_t last_desktop_ping_at = 0; static uint64_t last_desktop_ping_at = 0;
typedef struct desktop_value {
uint8_t value;
uint8_t max;
uint8_t min;
} desktop_value_t;
static desktop_value_t display1_brightness = {
.value = 20,
.max = 100,
.min = 0,
};
static desktop_value_t display2_brightness = {
.value = 20,
.max = 100,
.min = 0,
};
static desktop_value_t computer_volume = {
.value = 20,
.max = 100,
.min = 0,
};
static void udp_server_task(void *pvParameters) { static void udp_server_task(void *pvParameters) {
char rx_buffer[1024]; char rx_buffer[1024];
char addr_str[128]; char addr_str[128];
@ -132,6 +155,71 @@ static void udp_server_task(void *pvParameters) {
vTaskDelete(NULL); vTaskDelete(NULL);
} }
static uint8_t desktop_change_value(desktop_value_t *target, int8_t delta) {
if (delta > 0) {
if ((target->max - target->value) > delta) {
target->value += delta;
} else {
target->value = target->max;
}
} else {
if ((target->value - target->min) > -delta) {
target->value += delta;
} else {
target->value = target->min;
}
}
return target->value;
}
static uint8_t change_display_brightness(uint8_t display_index, int8_t delta) {
switch (display_index) {
case 0:
uint8_t value = desktop_change_value(&display1_brightness, delta);
gui_change_display_brightness(display_index, value);
return value;
case 1:
return desktop_change_value(&display1_brightness, delta);
gui_change_display_brightness(display_index, value);
return value;
default:
ESP_LOGE(UDP_SERVER_TAG, "Invalid display index: %d", display_index);
return 0;
}
}
static uint8_t change_volume(int8_t delta) {
uint8_t value = desktop_change_value(&computer_volume, delta);
gui_change_volume_level(value);
return value;
}
static void desktop_watch_input_task(void *arg) {
s_ui_input_t input;
for (;;) {
if (xQueueReceive(ui_input_event, &input, portMAX_DELAY)) {
switch (input.key) {
case ui_input_key_display_0_brightness:
change_display_brightness(0, input.value);
break;
case ui_input_key_display_1_brightness:
change_display_brightness(1, input.value);
break;
case ui_input_key_computer_volume:
change_volume(input.value);
break;
default:
break;
}
}
}
}
static void change_desktop_connection_status(bool connected) { static void change_desktop_connection_status(bool connected) {
desktop_connected = connected; desktop_connected = connected;
if (connected) { if (connected) {
@ -154,6 +242,8 @@ static void desktop_online_check_task(void *pvParameters) {
void udp_server_init(void) { void udp_server_init(void) {
xTaskCreate(udp_server_task, "udp_server", 4096, (void *)AF_INET, 5, NULL); xTaskCreate(udp_server_task, "udp_server", 4096, (void *)AF_INET, 5, NULL);
xTaskCreate(desktop_online_check_task, "desktop_online_check", 4096, NULL, 10, xTaskCreate(desktop_online_check_task, "desktop_online_check", 1024, NULL, 10,
NULL);
xTaskCreate(desktop_watch_input_task, "desktop_watch_input", 4096, NULL, 7,
NULL); NULL);
} }

View File

@ -261,6 +261,22 @@ static void gui_change_strip_level(int32_t target_value) {
lv_bar_set_value(value_setting_bar, target_value, LV_ANIM_ON); lv_bar_set_value(value_setting_bar, target_value, LV_ANIM_ON);
} }
static void gui_change_display_brightness(int8_t display_index,
int32_t target_value) {
gui_create_value_setting_panel();
lv_label_set_text_fmt(value_setting_label, "Display#%d Brightness",
display_index);
lv_bar_set_range(value_setting_bar, 0, 100);
lv_bar_set_value(value_setting_bar, target_value, LV_ANIM_ON);
}
static void gui_change_volume_level(int32_t target_value) {
gui_create_value_setting_panel();
lv_label_set_text(value_setting_label, "Volume Level");
lv_bar_set_range(value_setting_bar, 0, 100);
lv_bar_set_value(value_setting_bar, target_value, LV_ANIM_ON);
}
void lv_example_bar_6(lv_obj_t *src) { void lv_example_bar_6(lv_obj_t *src) {
static lv_style_t style_bar; static lv_style_t style_bar;
lv_style_init(&style_bar); lv_style_init(&style_bar);

View File

@ -13,7 +13,7 @@
#include "sdkconfig.h" #include "sdkconfig.h"
#include "service_discovery.c" #include "service_discovery.c"
// #include "temperature.c" // #include "temperature.c"
#include "udp_server.c" #include "desktop.c"
#include "ui_input.c" #include "ui_input.c"
#include "wifi.c" #include "wifi.c"

View File

@ -87,6 +87,8 @@ static void ui_input_update_embedded_display(void *arg) {
strcpy(changing_str, "NC"); strcpy(changing_str, "NC");
break; break;
} }
ESP_LOGI(UI_INPUT_TAG, "%s", changing_str);
} }
} }
} }
@ -145,8 +147,6 @@ static void encoder_value_change(encoder_state_t *state) {
return; return;
} }
ESP_LOGI(UI_INPUT_TAG, "key: %d, delta: %d", state->key, delta);
s_ui_input_t event = {.value = delta}; s_ui_input_t event = {.value = delta};
if (state->key == ui_input_raw_key_encoder_0) { if (state->key == ui_input_raw_key_encoder_0) {
if (state->value & 1) { if (state->value & 1) {
@ -164,6 +164,7 @@ static void encoder_value_change(encoder_state_t *state) {
} }
} }
xQueueSend(ui_input_event, &event, NULL); xQueueSend(ui_input_event, &event, NULL);
ESP_LOGI(UI_INPUT_TAG, "key: %d, delta: %d", state->key, delta);
} }
static void ui_input_raw_handler(void *arg) { static void ui_input_raw_handler(void *arg) {
@ -198,7 +199,7 @@ void ui_input_init(void) {
// hook isr handler for specific gpio pin // hook isr handler for specific gpio pin
gpio_isr_handler_add(ENCODER_INT_GPIO, gpio_isr_handler, NULL); gpio_isr_handler_add(ENCODER_INT_GPIO, gpio_isr_handler, NULL);
xTaskCreate(ui_input_update_embedded_display, "ui_input_event", 2048, NULL, // xTaskCreate(ui_input_update_embedded_display, "ui_input_event", 2048, NULL,
10, NULL); // 10, NULL);
xTaskCreate(ui_input_raw_handler, "ui_input_event", 2048, NULL, 10, NULL); xTaskCreate(ui_input_raw_handler, "ui_input_event", 2048, NULL, 10, NULL);
} }