Add touch buttons for speaker toggle and music playback.
Enable SoftSPI touch, replace auto beeps with Speaker ON/OFF and Play Music controls, and document usage. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
40
src/main.cpp
40
src/main.cpp
@@ -5,6 +5,7 @@
|
||||
#include "audio_test.h"
|
||||
#include "pins.h"
|
||||
#include "sd_info.h"
|
||||
#include "touch.h"
|
||||
#include "ui.h"
|
||||
|
||||
static constexpr uint32_t DRAW_BUF_SIZE =
|
||||
@@ -12,9 +13,8 @@ static constexpr uint32_t DRAW_BUF_SIZE =
|
||||
static uint32_t draw_buf[DRAW_BUF_SIZE / 4];
|
||||
|
||||
static uint32_t last_refresh_ms = 0;
|
||||
static uint32_t last_audio_ms = 0;
|
||||
static uint32_t last_btn_ui_ms = 0;
|
||||
static constexpr uint32_t REFRESH_MS = 3000;
|
||||
static constexpr uint32_t AUDIO_INTERVAL_MS = 12000;
|
||||
|
||||
static void refresh_sd_ui() {
|
||||
SdCardInfo info = sd_read_info();
|
||||
@@ -23,31 +23,25 @@ static void refresh_sd_ui() {
|
||||
if (!info.mounted) {
|
||||
Serial.printf("Error: %s\n", info.error.c_str());
|
||||
} else {
|
||||
Serial.printf("Type: %s\n", info.type);
|
||||
Serial.printf("FS: %s\n", info.filesystem);
|
||||
Serial.printf("Card: %s\n", format_bytes(info.card_bytes).c_str());
|
||||
Serial.printf("Part: %s\n", format_bytes(info.total_bytes).c_str());
|
||||
Serial.printf("Used: %s\n", format_bytes(info.used_bytes).c_str());
|
||||
Serial.printf("Free: %s\n", format_bytes(info.free_bytes).c_str());
|
||||
Serial.printf("Root entries: %lu\n",
|
||||
static_cast<unsigned long>(info.root_files));
|
||||
Serial.printf("Type: %s FS: %s Cap: %s\n", info.type, info.filesystem,
|
||||
format_bytes(info.card_bytes).c_str());
|
||||
}
|
||||
|
||||
ui_update(info);
|
||||
ui_set_audio_status(audio_last_status());
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
delay(200);
|
||||
Serial.println();
|
||||
Serial.printf("LVGL %d.%d.%d | CYD TF + Speaker\n", lv_version_major(),
|
||||
Serial.printf("LVGL %d.%d.%d | CYD TF + Touch Speaker\n", lv_version_major(),
|
||||
lv_version_minor(), lv_version_patch());
|
||||
|
||||
pinMode(TFT_BL_PIN, OUTPUT);
|
||||
digitalWrite(TFT_BL_PIN, HIGH);
|
||||
|
||||
audio_init();
|
||||
touch_init();
|
||||
|
||||
lv_init();
|
||||
|
||||
@@ -55,8 +49,11 @@ void setup() {
|
||||
lv_tft_espi_create(SCREEN_WIDTH, SCREEN_HEIGHT, draw_buf, sizeof(draw_buf));
|
||||
lv_display_set_rotation(disp, LV_DISPLAY_ROTATION_270);
|
||||
|
||||
lv_indev_t *indev = lv_indev_create();
|
||||
lv_indev_set_type(indev, LV_INDEV_TYPE_POINTER);
|
||||
lv_indev_set_read_cb(indev, touch_read_cb);
|
||||
|
||||
ui_create();
|
||||
ui_set_audio_status(audio_last_status());
|
||||
|
||||
if (!sd_init()) {
|
||||
Serial.println("SD mount failed at boot");
|
||||
@@ -64,18 +61,13 @@ void setup() {
|
||||
|
||||
refresh_sd_ui();
|
||||
last_refresh_ms = millis();
|
||||
|
||||
// 开机立刻测喇叭
|
||||
audio_play_beep_sequence();
|
||||
delay(200);
|
||||
audio_play_melody();
|
||||
ui_set_audio_status(audio_last_status());
|
||||
last_audio_ms = millis();
|
||||
last_btn_ui_ms = millis();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
lv_timer_handler();
|
||||
lv_tick_inc(5);
|
||||
audio_tick();
|
||||
|
||||
uint32_t now = millis();
|
||||
if (now - last_refresh_ms >= REFRESH_MS) {
|
||||
@@ -83,10 +75,10 @@ void loop() {
|
||||
refresh_sd_ui();
|
||||
}
|
||||
|
||||
if (now - last_audio_ms >= AUDIO_INTERVAL_MS) {
|
||||
last_audio_ms = now;
|
||||
audio_play_beep_sequence();
|
||||
ui_set_audio_status(audio_last_status());
|
||||
// 播放过程中刷新按钮文字(Playing / Stop)
|
||||
if (now - last_btn_ui_ms >= 300) {
|
||||
last_btn_ui_ms = now;
|
||||
ui_refresh_audio_buttons();
|
||||
}
|
||||
|
||||
delay(5);
|
||||
|
||||
Reference in New Issue
Block a user