This commit is contained in:
e2002
2022-10-14 11:00:49 +03:00
parent dbe0f32e14
commit 1c4b1dec6e
94 changed files with 5320 additions and 6613 deletions

View File

@@ -1,135 +1,33 @@
#include "../../options.h"
#include "../core/options.h"
#if DSP_MODEL==DSP_GC9106
#include "displayGC9106.h"
#include <SPI.h>
#include "fonts/bootlogo40.h"
#include "../../player.h"
#include "../../config.h"
#include "../../network.h"
#include "../core/player.h"
#include "../core/config.h"
#include "../core/network.h"
#ifndef DEF_SPI_FREQ
#define DEF_SPI_FREQ 24000000 /* set it to 0 for system default */
#define DEF_SPI_FREQ 24000000 /* set it to 0 for system default */
#endif
#define CLOCK_DELTA 16
#define TAKE_MUTEX() if(player.mutex_pl) xSemaphoreTake(player.mutex_pl, portMAX_DELAY)
#define GIVE_MUTEX() if(player.mutex_pl) xSemaphoreGive(player.mutex_pl)
DspCore::DspCore(): Adafruit_GC9106Ex(TFT_CS, TFT_DC, TFT_RST) {
DspCore::DspCore(): Adafruit_GC9106Ex(TFT_CS, TFT_DC, TFT_RST) { }
}
#include "tools/utf8RusGFX.h"
char* DspCore::utf8Rus(const char* str, bool uppercase) {
int index = 0;
static char strn[BUFLEN];
bool E = false;
strlcpy(strn, str, BUFLEN);
if (uppercase) {
bool next = false;
for (char *iter = strn; *iter != '\0'; ++iter)
{
if (E) {
E = false;
continue;
}
byte rus = (byte) * iter;
if (rus == 208 && (byte) * (iter + 1) == 129) { // ёКостыли
*iter = (char)209;
*(iter + 1) = (char)145;
E = true;
continue;
}
if (rus == 209 && (byte) * (iter + 1) == 145) {
*iter = (char)209;
*(iter + 1) = (char)145;
E = true;
continue;
}
if (next) {
if (rus >= 128 && rus <= 143) *iter = (char)(rus + 32);
if (rus >= 176 && rus <= 191) *iter = (char)(rus - 32);
next = false;
}
if (rus == 208) next = true;
if (rus == 209) {
*iter = (char)208;
next = true;
}
*iter = toupper(*iter);
}
}
while (strn[index])
{
if (strn[index] >= 0xBF)
{
switch (strn[index]) {
case 0xD0: {
if (strn[index + 1] == 0x81) {
strn[index] = 0xA8;
break;
}
if (strn[index + 1] >= 0x90 && strn[index + 1] <= 0xBF) strn[index] = strn[index + 1] + 0x30;
break;
}
case 0xD1: {
if (strn[index + 1] == 0x91) {
//strn[index] = 0xB7;
strn[index] = 0xB8;
break;
}
if (strn[index + 1] >= 0x80 && strn[index + 1] <= 0x8F) strn[index] = strn[index + 1] + 0x70;
break;
}
}
int sind = index + 2;
while (strn[sind]) {
strn[sind - 1] = strn[sind];
sind++;
}
strn[sind - 1] = 0;
}
index++;
}
return strn;
}
void DspCore::apScreen() {
setTextSize(1);
setTextColor(config.theme.title1, config.theme.background);
setCursor(TFT_FRAMEWDT, TFT_FRAMEWDT + 2 * TFT_LINEHGHT);
print("AP NAME: ");
print(apSsid);
setCursor(TFT_FRAMEWDT, TFT_FRAMEWDT + 3 * TFT_LINEHGHT);
print("PASSWORD: ");
print(apPassword);
setTextColor(config.theme.title2, config.theme.background);
setCursor(TFT_FRAMEWDT, 107);
print("SETTINGS PAGE ON: ");
setCursor(TFT_FRAMEWDT, 117);
print("http://");
print(WiFi.softAPIP().toString().c_str());
print("/");
}
void DspCore::initD(uint16_t &screenwidth, uint16_t &screenheight) {
void DspCore::initDisplay() {
begin(DEF_SPI_FREQ);
cp437(true);
invert();
// fillScreen(TFT_BG);
flip();
setTextWrap(false);
screenwidth = width();
screenheight = height();
swidth = screenwidth;
sheight = screenheight;
setClockBounds();
}
void DspCore::drawLogo() {
fillScreen(0x0000);
drawRGBBitmap((swidth - 62) / 2, 5, bootlogo40, 62, 40);
void DspCore::drawLogo(uint16_t top) {
drawRGBBitmap((width() - 62) / 2, 5, bootlogo40, 62, 40);
}
void DspCore::drawPlaylist(uint16_t currentItem, char* currentItemText) {
@@ -138,8 +36,7 @@ void DspCore::drawPlaylist(uint16_t currentItem, char* currentItemText) {
}
config.fillPlMenu(plMenu, currentItem - 3, PLMITEMS);
setTextSize(2);
int yStart = (sheight / 2 - PLMITEMHEIGHT / 2) - PLMITEMHEIGHT * (PLMITEMS - 1) / 2 + 3;
//fillRect(0, (sheight / 2 - PLMITEMHEIGHT / 2) - 1, swidth, PLMITEMHEIGHT + 2, TFT_LOGO);
int yStart = (height() / 2 - PLMITEMHEIGHT / 2) - PLMITEMHEIGHT * (PLMITEMS - 1) / 2 + 3;
for (byte i = 0; i < PLMITEMS; i++) {
if (abs(i - 3) == 3) setTextColor(config.theme.playlist[2], config.theme.background);
if (abs(i - 3) == 2) setTextColor(config.theme.playlist[1], config.theme.background);
@@ -148,181 +45,77 @@ void DspCore::drawPlaylist(uint16_t currentItem, char* currentItemText) {
strlcpy(currentItemText, plMenu[i], PLMITEMLENGHT - 1);
} else {
setCursor(TFT_FRAMEWDT, yStart + i * PLMITEMHEIGHT);
fillRect(0, yStart + i * PLMITEMHEIGHT - 1, swidth, PLMITEMHEIGHT - 4, config.theme.background);
fillRect(0, yStart + i * PLMITEMHEIGHT - 1, width(), PLMITEMHEIGHT - 4, config.theme.background);
print(utf8Rus(plMenu[i], true));
}
}
}
void DspCore::clearDsp() {
fillScreen(config.theme.background);
void DspCore::clearDsp(bool black) {
fillScreen(black?0:config.theme.background);
}
void DspCore::drawScrollFrame(uint16_t texttop, uint16_t textheight, uint16_t bg) {
fillRect(0, texttop, TFT_FRAMEWDT, textheight, bg);
fillRect(swidth - TFT_FRAMEWDT, texttop, TFT_FRAMEWDT, textheight, bg);
GFXglyph *pgm_read_glyph_ptr(const GFXfont *gfxFont, uint8_t c) {
return gfxFont->glyph + c;
}
void DspCore::getScrolBbounds(const char* text, const char* separator, byte textsize, uint16_t &tWidth, uint16_t &tHeight, uint16_t &sWidth) {
int16_t x1, y1;
uint16_t w, h;
setTextSize(textsize);
getTextBounds(text, 0, 0, &x1, &y1, &w, &h);
tWidth = w;
tHeight = h;
getTextBounds(separator, 0, 0, &x1, &y1, &w, &h);
sWidth = w;
uint8_t DspCore::_charWidth(unsigned char c){
GFXglyph *glyph = pgm_read_glyph_ptr(&DS_DIGI28pt7b, c - 0x20);
return pgm_read_byte(&glyph->xAdvance);
}
void DspCore::clearScroll(uint16_t texttop, uint16_t textheight, uint16_t bg) {
fillRect(0, texttop-2, swidth, textheight+3, bg);
uint16_t DspCore::textWidth(const char *txt){
uint16_t w = 0, l=strlen(txt);
for(uint16_t c=0;c<l;c++) w+=_charWidth(txt[c]);
return w;
}
void DspCore::centerText(const char* text, byte y, uint16_t fg, uint16_t bg) {
int16_t x1, y1;
uint16_t w, h;
const char* txt = text;
getTextBounds(txt, 0, 0, &x1, &y1, &w, &h);
setTextColor(fg);
setCursor((swidth - w) / 2, y);
fillRect(0, y, swidth, h, bg);
print(txt);
void DspCore::_getTimeBounds() {
_timewidth = textWidth(_timeBuf);
char buf[4];
strftime(buf, 4, "%H", &network.timeinfo);
_dotsLeft=textWidth(buf);
}
void DspCore::rightText(const char* text, byte y, uint16_t fg, uint16_t bg) {
int16_t x1, y1;
uint16_t w, h;
getTextBounds(text, 0, 0, &x1, &y1, &w, &h);
setTextColor(fg);
setCursor(swidth - w - TFT_FRAMEWDT, y);
fillRect(swidth - w - TFT_FRAMEWDT, y, w, h, bg);
print(text);
}
void DspCore::displayHeapForDebug() {
}
void DspCore::setClockBounds(){
void DspCore::_clockSeconds(){
setTextSize(1);
setFont(&DS_DIGI28pt7b);
setTextSize(1);
getTextBounds("88:88", 0, 0, &x, &y, &cwidth, &cheight);
uint16_t header = TFT_FRAMEWDT + 4 * TFT_LINEHGHT;
uint16_t footer = TFT_FRAMEWDT * 2 + TFT_LINEHGHT + 5;
clockY = header + (sheight - header - footer) / 2 - cheight / 2 - 6;
setTextColor((network.timeinfo.tm_sec % 2 == 0) ? config.theme.clock : config.theme.background, config.theme.background);
setCursor(_timeleft+_dotsLeft, clockTop);
print(":"); /* print dots */
setFont();
}
void DspCore::printClock(const char* timestr) {
void DspCore::_clockDate(){ }
}
byte DspCore::getPw(uint16_t ncwidth){
byte pw = 6;
if(ncwidth<35) pw = 7;
if(ncwidth<20) pw = 8;
return pw;
}
void DspCore::printClock(struct tm timeinfo, bool dots, bool redraw){
char timeBuf[50] = { 0 };
char tmpBuf[4] = { 0 };
uint16_t ncwidth, ncheight;
uint16_t clockdelta=config.store.vumeter?CLOCK_DELTA:0;
strftime(timeBuf, sizeof(timeBuf), "%H %M", &timeinfo);
void DspCore::_clockTime(){
if(_oldtimeleft>0) dsp.fillRect(_oldtimeleft, clockTop-clockTimeHeight+1, _oldtimewidth, clockTimeHeight, config.theme.background);
_timeleft = (width()/2 - _timewidth/2)+clockRightSpace;
setTextSize(1);
setFont(&DS_DIGI28pt7b);
if(strstr(oldTimeBuf, timeBuf)==NULL || redraw){
getTextBounds(oldTimeBuf, 0, 0, &x, &y, &wot, &hot);
setCursor((swidth - wot) / 2 - 4 + clockdelta, clockY+28+6);
setTextColor(config.theme.background);
print(oldTimeBuf);
dot = (swidth - wot) / 2 - 4 + clockdelta;
/* dots */
strlcpy(tmpBuf, oldTimeBuf, 3);
getTextBounds(tmpBuf, 0, 0, &x, &y, &ncwidth, &ncheight);
dot = dot + ncwidth + getPw(ncwidth);
setCursor(dot, clockY+28+6);
print(":");
/* dots */
strlcpy(oldTimeBuf, timeBuf, 20);
setTextSize(1);
getTextBounds(timeBuf, 0, 0, &x, &y, &ncwidth, &ncheight);
setTextColor(config.theme.clock);
setCursor((swidth - ncwidth) / 2 - 4 + clockdelta, clockY+28+6);
dot = (swidth - ncwidth) / 2 - 4 + clockdelta;
setTextSize(1);
print(timeBuf);
/* dots */
strftime(timeBuf, sizeof(timeBuf), "%H", &timeinfo);
getTextBounds(timeBuf, 0, 0, &x, &y, &ncwidth, &ncheight);
dot = dot + ncwidth + getPw(ncwidth);
/* dots */
}
setCursor(dot, clockY+28+6);
setTextColor(dots?config.theme.background:config.theme.clock);
print(":");
setFont();
yield();
}
#define VTOP TITLE_TOP1+6
void DspCore::drawVolumeBar(bool withNumber) {
int16_t vTop = sheight - TFT_FRAMEWDT - 2;
int16_t vWidth = swidth - TFT_FRAMEWDT * 2;
uint8_t ww = map(config.store.volume, 0, 254, 0, vWidth);
fillRect(TFT_FRAMEWDT, vTop, vWidth, 2, config.theme.background);
fillRect(TFT_FRAMEWDT, vTop, ww, 2, config.theme.volbarout);
if (withNumber) {
setTextSize(1);
setTextColor(config.theme.digit);
setFont(&DS_DIGI28pt7b);
char volstr[4];
uint16_t wv, hv;
int16_t x1, y1;
sprintf(volstr, "%d", config.store.volume);
getTextBounds(volstr, 0, 0, &x1, &y1, &wv, &hv);
fillRect(TFT_FRAMEWDT, VTOP, swidth - TFT_FRAMEWDT / 2, hv + 3, config.theme.background);
setCursor((swidth - wv) / 2, VTOP + hv);
print(volstr);
setFont();
}
}
void DspCore::drawNextStationNum(uint16_t num) {
setTextSize(1);
setTextColor(config.theme.digit);
setFont(&DS_DIGI28pt7b);
char numstr[7];
uint16_t wv, hv;
int16_t x1, y1;
sprintf(numstr, "%d", num);
getTextBounds(numstr, 0, 0, &x1, &y1, &wv, &hv);
fillRect(TFT_FRAMEWDT, VTOP, swidth - TFT_FRAMEWDT / 2, hv + 3, config.theme.background);
setCursor((swidth - wv) / 2, VTOP + hv);
print(numstr);
setTextColor(config.theme.clock, config.theme.background);
setCursor(_timeleft, clockTop);
print(_timeBuf);
setFont();
strlcpy(_oldTimeBuf, _timeBuf, sizeof(_timeBuf));
_oldtimewidth = _timewidth;
_oldtimeleft = _timeleft;
}
void DspCore::frameTitle(const char* str) {
setTextSize(2);
centerText(str, TFT_FRAMEWDT, config.theme.meta, config.theme.background);
void DspCore::printClock(uint16_t top, uint16_t rightspace, uint16_t timeheight, bool redraw){
clockTop = top;
clockRightSpace = rightspace;
clockTimeHeight = timeheight;
strftime(_timeBuf, sizeof(_timeBuf), "%H:%M", &network.timeinfo);
if(strcmp(_oldTimeBuf, _timeBuf)!=0 || redraw){
_getTimeBounds();
_clockTime();
}
_clockSeconds();
}
void DspCore::rssi(const char* str) {
int16_t vTop = sheight - TFT_FRAMEWDT * 2 - TFT_LINEHGHT - 2;
setTextSize(1);
rightText(str, vTop, config.theme.rssi, config.theme.background);
}
void DspCore::ip(const char* str) {
int16_t vTop = sheight - TFT_FRAMEWDT * 2 - TFT_LINEHGHT - 2;
setTextSize(1);
setTextColor(config.theme.ip, config.theme.background);
setCursor(4, vTop);
print(str);
void DspCore::clearClock(){
dsp.fillRect(_timeleft, clockTop-clockTimeHeight, _timewidth+CHARWIDTH*3*2+24, clockTimeHeight+10+CHARHEIGHT, config.theme.background);
}
void DspCore::startWrite(void) {
@@ -335,45 +128,17 @@ void DspCore::endWrite(void) {
GIVE_MUTEX();
}
/*
void DspCore::sendCommand(uint8_t commandByte, uint8_t *dataBytes, uint8_t numDataBytes) {
TAKE_MUTEX();
Adafruit_GC9106Ex::sendCommand(commandByte, dataBytes, numDataBytes);
GIVE_MUTEX();
void DspCore::loop(bool force) { }
void DspCore::charSize(uint8_t textsize, uint8_t& width, uint16_t& height){
width = textsize * CHARWIDTH;
height = textsize * CHARHEIGHT;
}
void DspCore::sendCommand(uint8_t commandByte, const uint8_t *dataBytes, uint8_t numDataBytes) {
TAKE_MUTEX();
Adafruit_GC9106Ex::sendCommand(commandByte, dataBytes, numDataBytes);
GIVE_MUTEX();
void DspCore::setTextSize(uint8_t s){
Adafruit_GFX::setTextSize(s);
}
void DspCore::sendCommand16(uint16_t commandWord, const uint8_t *dataBytes, uint8_t numDataBytes) {
TAKE_MUTEX();
Adafruit_GC9106Ex::sendCommand16(commandWord, dataBytes, numDataBytes);
GIVE_MUTEX();
}*/
void DspCore::set_TextSize(uint8_t s) {
setTextSize(s);
}
void DspCore::set_TextColor(uint16_t fg, uint16_t bg) {
setTextColor(fg, bg);
}
void DspCore::set_Cursor(int16_t x, int16_t y) {
setCursor(x, y);
}
void DspCore::printText(const char* txt) {
print(txt);
}
void DspCore::loop(bool force) {
}
void DspCore::flip(){
setRotation(config.store.flipscreen?1:3);
}
@@ -385,4 +150,33 @@ void DspCore::invert(){
void DspCore::sleep(void) { sendCommand(GC9106_SLPIN); delay(150); sendCommand(GC9106_DISPOFF); delay(150); }
void DspCore::wake(void) { sendCommand(GC9106_DISPON); delay(150); sendCommand(GC9106_SLPOUT); delay(150); }
void DspCore::writePixel(int16_t x, int16_t y, uint16_t color) {
if(_clipping){
if ((x < _cliparea.left) || (x > _cliparea.left+_cliparea.width) || (y < _cliparea.top) || (y > _cliparea.top + _cliparea.height)) return;
}
Adafruit_GC9106Ex::writePixel(x, y, color);
}
void DspCore::writeFillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color) {
if(_clipping){
if ((x < _cliparea.left) || (x >= _cliparea.left+_cliparea.width) || (y < _cliparea.top) || (y > _cliparea.top + _cliparea.height)) return;
}
Adafruit_GC9106Ex::writeFillRect(x, y, w, h, color);
}
void DspCore::setClipping(clipArea ca){
_cliparea = ca;
_clipping = true;
}
void DspCore::clearClipping(){
_clipping = false;
}
void DspCore::setNumFont(){
setFont(&DS_DIGI28pt7b);
setTextSize(1);
}
#endif