Add GPIO26 speaker beep and melody test.
Play audio on boot and every 12s via the onboard amp; show status on the LVGL UI and document pins. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
23
src/main.cpp
23
src/main.cpp
@@ -2,6 +2,7 @@
|
||||
#include <TFT_eSPI.h>
|
||||
#include <lvgl.h>
|
||||
|
||||
#include "audio_test.h"
|
||||
#include "pins.h"
|
||||
#include "sd_info.h"
|
||||
#include "ui.h"
|
||||
@@ -11,7 +12,9 @@ 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 constexpr uint32_t REFRESH_MS = 3000;
|
||||
static constexpr uint32_t AUDIO_INTERVAL_MS = 12000;
|
||||
|
||||
static void refresh_sd_ui() {
|
||||
SdCardInfo info = sd_read_info();
|
||||
@@ -31,26 +34,29 @@ static void refresh_sd_ui() {
|
||||
}
|
||||
|
||||
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 info\n", lv_version_major(),
|
||||
Serial.printf("LVGL %d.%d.%d | CYD TF + Speaker\n", lv_version_major(),
|
||||
lv_version_minor(), lv_version_patch());
|
||||
|
||||
pinMode(TFT_BL_PIN, OUTPUT);
|
||||
digitalWrite(TFT_BL_PIN, HIGH);
|
||||
|
||||
audio_init();
|
||||
|
||||
lv_init();
|
||||
|
||||
lv_display_t *disp =
|
||||
lv_tft_espi_create(SCREEN_WIDTH, SCREEN_HEIGHT, draw_buf, sizeof(draw_buf));
|
||||
// 横屏:320x240
|
||||
lv_display_set_rotation(disp, LV_DISPLAY_ROTATION_270);
|
||||
|
||||
ui_create();
|
||||
ui_set_audio_status(audio_last_status());
|
||||
|
||||
if (!sd_init()) {
|
||||
Serial.println("SD mount failed at boot");
|
||||
@@ -58,6 +64,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();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
@@ -70,5 +83,11 @@ 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());
|
||||
}
|
||||
|
||||
delay(5);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user