ardunio TFT_eSPI库与Audio库冲突解决

TFT_eSPI库与Audio库发生冲突,原因是TFT_eSPI库引用了FS.h,其中命名空间为fs,定义了FS类,Audio.h开启sdFat库后,也有一个fs命名空间,然后在sdFat类基础上又定义了一个FS类。

audio.h文件

#define SDFATFS_USED  // activate for SdFat
#ifdef SDFATFS_USED
//typedef File32 File;
typedef FsFile File;

namespace fs {
    class FS : public SdFat {
    public:
        bool begin(SdCsPin_t csPin = SS, uint32_t maxSck = SD_SCK_MHZ(25)) { return SdFat::begin(csPin, maxSck); }
        bool begin(SdSpiConfig config){return SdFat::begin(config);}
    };

    class SDFATFS : public fs::FS {
    public:
        // sdcard_type_t cardType();
        uint64_t cardSize() {
            return totalBytes();
        }
        uint64_t usedBytes() {
            // set SdFatConfig MAINTAIN_FREE_CLUSTER_COUNT non-zero. Then only the first call will take time.
            return (uint64_t)(clusterCount() - freeClusterCount()) * (uint64_t)bytesPerCluster();
        }
        uint64_t totalBytes() {
            return (uint64_
#include <Arduino.h> #include <TFT_eSPI.h> #include <SD.h> #include <WiFi.h> #include <WebServer.h> #include <HTTPClient.h> #include <Audio.h> #include <esp_sleep.h> #include <ArduinoJson.h> #include <SPIFFS.h> #include <cstdint> // 硬件配置 #define TFT_CS 1 #define TFT_DC 2 #define SD_CS 10 #define TOUCH_CS 16 #define CONFIG_PIN 18 #define MIC_PIN 40 // 用户配置 #define DEFAULT_VOLUME 8 #define DEEPSEEK_KEY "your-api-key" #define CONFIG_AP_PASS "12345678" TFT_eSPI tft; WebServer server(80); Audio audio; // 触摸校准参数 uint16_t touchCalibration[4] = { 275, 3490, 286, 3515 }; // 函数声明 void showCenterText(const String &text, uint16_t color); bool connectWiFi(); void enterDeepSleep(); void handleVoiceCommand(); void initTouch(); void showMainUI(); void startSmartConfig(); void wakeFromSleep(); void handleTouchInput(uint16_t x, uint16_t y); void changeVoiceProfile(uint8_t index); void processVoiceCommand(); String getChatResponse(const String &input); String parseJSONResponse(String json); void recordAudio(int seconds); String speechToText(); void textToSpeech(String text); void setup() { Serial.begin(115200); pinMode(CONFIG_PIN, INPUT_PULLUP); // 显示初始化 tft.init(); tft.setRotation(3); tft.fillScreen(TFT_BLACK); initTouch(); // 存储初始化 if(!SD.begin(SD_CS, SPI, 40000000)){ showCenterText("SD卡故障", TFT_RED); while(1); } // 网络连接 if(digitalRead(CONFIG_PIN) == LOW || !connectWiFi()){ startSmartConfig(); } // 音频初始化 audio.setPinout(45, 47, 21); audio.setVolume(DEFAULT_VOLUME); showMainUI(); } void loop() { static uint32_t lastActive = millis(); server.handleClient(); audio.loop(); if(millis() - lastActive > 300000) enterDeepSleep(); uint16_t x, y; if(tft.getTouch(&x, &y)){ lastActive = millis(); wakeFromSleep(); handleTouchInput(x, y); } } // 触摸功能模块 void initTouch() { tft.setTouchCalibrate(touchCalibration); tft.fillScreen(TFT_BLUE); tft.drawString("轻触屏幕校准", 60, 140, 2); w
03-21
评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值