1 Star 0 Fork 5

raymonlee/Arduino_ESP32_LyricBox

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
paintingclass.cpp 3.26 KB
一键复制 编辑 原始数据 按行查看 历史
mingyee 提交于 2022-10-25 05:56 . update paintingclass.cpp.
#include "paintingclass.h"
#include <../../fastLED/src/FastLED.h> //fastLED相对路径
extern btMusicBox music;
String last_title = "";
String last_artist = "";
uint8_t flag_first = 0;
uint8_t music_lyrics[100] = {0};
uint8_t music_lyrics1[100] = {0};
std::chrono::steady_clock::time_point _audioUpdate;
paintingclass* director = nullptr;
//必须要实现的dot2d导演对象代理方法
class MainDelegate : public dot2d::DirectorDelegate
{
void render()
{
FastLED.show();
// 输出ESP32内存占用情况
// Serial.printf("-----Free Heap Mem : %d [%.2f%%]-----\n",
// ESP.getFreeHeap(),
// ESP.getFreeHeap()/(double)ESP.getHeapSize()*100);
// Serial.printf("-----Free PSRAM Mem: %d [%.2f%%]-----\n",
// ESP.getFreePsram(),
// ESP.getFreePsram()/(double)ESP.getPsramSize()*100);
}
size_t write(uint8_t c)
{
return Serial.write(c);
}
//返回一个RGB对象的顺序表指针,用于初始化硬件屏幕
void initMatrix(dot2d::DTRGB *data)
{
FastLED.addLeds<WS2812Controller800Khz,MATRIX_LED_PIN, GRB>((CRGB* )data,MATRIX_WIDTH*MATRIX_HEIGHT,0);
FastLED.setBrightness(MATRIX_MAX_BRIGHTNESS); //设置WS2812屏幕亮度
}
//用于计算坐标为(x,y)的灯珠在RGB对象顺序表中的具体位置,适配不同排列方式的屏幕,在此处修改
uint32_t dotOrder(uint16_t x,uint16_t y)
{
//uint16_t order = y*MATRIX_WIDTH;
// if ((y%2)==0)
// {
// order+=x;
// }else
// {
// order+=(MATRIX_WIDTH-x-1);
// }
// uint16_t order = x*MATRIX_HEIGHT;
// order+=(MATRIX_HEIGHT-y-1);
uint16_t order = x*MATRIX_HEIGHT;
order += y;
return order;
}
};
void attendpaintingclass(void)
{
painting = paintingclass::getInstance(); //获取导演对象
painting->setDelegate(new MainDelegate()); //设置导演代理
painting->setFramesPerSecond(30); //设置帧速率
painting->initDotCanvas(MATRIX_WIDTH,MATRIX_HEIGHT); //初始化导演画布
painting->runWithScene(dot2d::MusicLyrics::create());
}
void audioLyricsupdate(uint16_t duration)
{
int gbk_len = 0;
auto now = std::chrono::steady_clock::now();
int64_t dt = std::chrono::duration_cast<std::chrono::milliseconds>(now - _audioUpdate).count();
if(dt >= duration)
{
_audioUpdate = now;
music.updateMeta();
if(music.artist.compareTo(last_artist) != 0){
// Serial.print("Artist: ");
// Serial.println(music.artist);
// Serial.print("Album: ");
// Serial.println(music.album);
// Serial.print("Genre: ");
// Serial.println(music.genre);
last_artist = music.artist;
}
if(music.title.compareTo(last_title)!=0){
// Serial.print("Title: ");
Serial.println(music.title);
if(-1 != SwitchToGbk((const uint8_t *)music.title.c_str(),strlen(music.title.c_str()),music_lyrics1,&gbk_len)){
memcpy(music_lyrics,music_lyrics1,sizeof(music_lyrics1));
}
last_title = music.title;
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/raymonlee/Arduino_ESP32_LyricBox.git
git@gitee.com:raymonlee/Arduino_ESP32_LyricBox.git
raymonlee
Arduino_ESP32_LyricBox
Arduino_ESP32_LyricBox
master

搜索帮助