Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "../core/options.h"
- #if DSP_MODEL==DSP_SSD1306 || DSP_MODEL==DSP_SSD1306x32
- #include "displaySSD1306.h"
- #include <Wire.h>
- #include "../core/player.h"
- #include "../core/config.h"
- #include "../core/network.h"
- #ifndef SCREEN_ADDRESS
- #define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32 or scan it https://create.arduino.cc/projecthub/abdularbi17/how-to-scan-i2c-address-in-arduino-eaadda
- #endif
- #if DSP_MODEL==DSP_SSD1306
- //#define LOGO_WIDTH 21
- //#define LOGO_HEIGHT 32
- //const unsigned char logo [] PROGMEM=
- //{
- // 0x06, 0x03, 0x00, 0x0f, 0x07, 0x80, 0x1f, 0x8f, 0xc0, 0x1f, 0x8f, 0xc0,
- // 0x0f, 0x07, 0x80, 0x06, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- // 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x03, 0xff, 0x00, 0x0f, 0xff, 0x80,
- // 0x1f, 0xff, 0xc0, 0x1f, 0xff, 0xc0, 0x3f, 0x8f, 0xe0, 0x7e, 0x03, 0xf0,
- // 0x7c, 0x01, 0xf0, 0x7c, 0x01, 0xf0, 0x7f, 0xff, 0xf0, 0xff, 0xff, 0xf8,
- // 0xff, 0xff, 0xf8, 0xff, 0xff, 0xf8, 0x7c, 0x00, 0x00, 0x7c, 0x00, 0x00,
- // 0x7e, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x3f, 0xc0, 0xe0, 0x3f, 0xff, 0xe0,
- // 0x1f, 0xff, 0xe0, 0x0f, 0xff, 0xe0, 0x03, 0xff, 0xc0, 0x00, 0xfe, 0x00
- //};
- //#endif
- #define LOGO_WIDTH 90
- #define LOGO_HEIGHT 64
- const unsigned char logo [] PROGMEM = {
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00011111,B01111000,B00000000,B00000000,B01111001,B11100000,B00000000,B11111000,B00111111,
- B00000000,B00000000,B00000000,B00011111,B00111100,B00000000,B00000000,B01111001,B11100000,B00000000,B11111000,B00111111,
- B00000000,B00000000,B00000000,B00011111,B00111100,B00000000,B00000000,B01111000,B11000000,B00000000,B11111000,B00111111,
- B00000000,B00000000,B00000000,B00011111,B00111110,B00000000,B00000000,B01111000,B00000000,B00000000,B01110000,B00111111,
- B00000011,B11000110,B00111100,B00011111,B01111110,B00111111,B10000111,B11111001,B11100001,B11110000,B01110000,B00111111,
- B00000011,B11000110,B11101111,B00011111,B01111110,B01110011,B11001110,B01111001,B11100011,B10111000,B01110000,B00111111,
- B00000001,B11100100,B11101111,B00011111,B00111100,B00100011,B11011100,B01111001,B11100111,B01111100,B01110000,B00111111,
- B00000001,B11100101,B11100111,B10011111,B00111000,B00010111,B11011100,B01111001,B11100111,B00111100,B01100000,B00111111,
- B00000000,B11111001,B11100111,B10011111,B11110000,B01110111,B11011110,B01111001,B11101111,B00111110,B00100000,B00111111,
- B00000000,B11111001,B11110011,B10011111,B01111110,B11110011,B11011110,B01111001,B11101111,B10011110,B00000000,B00111111,
- B00000000,B01111000,B11110011,B10011111,B01111110,B11110011,B11011111,B01111001,B11100111,B10011100,B11110000,B00111111,
- B00000000,B01110000,B11110011,B10011111,B00111110,B11111011,B11001111,B01111001,B11100111,B10011100,B11110000,B00111111,
- B00000001,B00110000,B01110111,B00011111,B00111110,B01111011,B11000111,B01111001,B11100011,B10111000,B11110000,B00111111,
- B00000011,B00100000,B00011100,B00011111,B00011100,B00111111,B11000011,B11111001,B11100000,B11110000,B01110000,B00111111,
- B00000111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000011,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000001,B10000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111
- };
- #endif
- #ifndef I2CFREQ_HZ
- #define I2CFREQ_HZ 4000000UL
- #endif
- TwoWire I2CSSD1306 = TwoWire(0);
- DspCore::DspCore(): Adafruit_SSD1306(128, ((DSP_MODEL==DSP_SSD1306)?64:32), &I2CSSD1306, I2C_RST, I2CFREQ_HZ) { }
- #include "tools/utf8RusGFX.h"
- void DspCore::initDisplay() {
- I2CSSD1306.begin(I2C_SDA, I2C_SCL);
- if (!begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
- Serial.println(F("SSD1306 allocation failed"));
- for (;;); // Don't proceed, loop forever
- }
- #include "tools/oledcolorfix.h"
- cp437(true);
- flip();
- invert();
- setTextWrap(false);
- plItemHeight = playlistConf.widget.textsize*(CHARHEIGHT-1)+playlistConf.widget.textsize*4;
- plTtemsCount = round((float)height()/plItemHeight);
- if(plTtemsCount%2==0) plTtemsCount++;
- plCurrentPos = plTtemsCount/2;
- plYStart = (height() / 2 - plItemHeight / 2) - plItemHeight * (plTtemsCount - 1) / 2 + playlistConf.widget.textsize*2;
- }
- void DspCore::drawLogo(uint16_t top) {
- #if DSP_MODEL==DSP_SSD1306
- drawBitmap((width() - LOGO_WIDTH ) / 2, 8, logo, LOGO_WIDTH, LOGO_HEIGHT, 1);
- #else
- setTextSize(1);
- setCursor((width() - 6*CHARWIDTH) / 2, 0);
- setTextColor(TFT_FG, TFT_BG);
- print(utf8Rus("ёRadio", false));
- setTextSize(1);
- #endif
- display();
- }
- void DspCore::printPLitem(uint8_t pos, const char* item, ScrollWidget& current){
- setTextSize(playlistConf.widget.textsize);
- if (pos == plCurrentPos) {
- current.setText(item);
- } else {
- uint8_t plColor = (abs(pos - plCurrentPos)-1)>4?4:abs(pos - plCurrentPos)-1;
- setTextColor(config.theme.playlist[plColor], config.theme.background);
- setCursor(TFT_FRAMEWDT, plYStart + pos * plItemHeight);
- fillRect(0, plYStart + pos * plItemHeight - 1, width(), plItemHeight - 2, config.theme.background);
- print(utf8Rus(item, true));
- }
- }
- void DspCore::drawPlaylist(uint16_t currentItem) {
- uint8_t lastPos = config.fillPlMenu(currentItem - plCurrentPos, plTtemsCount);
- if(lastPos<plTtemsCount){
- fillRect(0, lastPos*plItemHeight+plYStart, width(), height()/2, config.theme.background);
- }
- }
- void DspCore::clearDsp(bool black) {
- fillScreen(TFT_BG);
- }
- uint8_t DspCore::_charWidth(unsigned char c){
- return CHARWIDTH*clockTimeHeight;
- }
- 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::_getTimeBounds() {
- _timewidth = textWidth(_timeBuf);
- char buf[4];
- strftime(buf, 4, "%H", &network.timeinfo);
- _dotsLeft=textWidth(buf);
- }
- void DspCore::_clockSeconds(){
- setTextSize(clockTimeHeight);
- #if DSP_MODEL!=DSP_SSD1306x32
- setTextColor((network.timeinfo.tm_sec % 2 == 0) ? config.theme.clock : config.theme.background, config.theme.background);
- #else
- setTextColor((network.timeinfo.tm_sec % 2 == 0) ? 0 : 1, 1);
- #endif
- setCursor(_timeleft+_dotsLeft, clockTop);
- print(":"); /* print dots */
- #if DSP_MODEL!=DSP_SSD1306x32
- setTextSize(1);
- setCursor(_timeleft+_timewidth+1, clockTop);
- setTextColor(config.theme.clock, config.theme.background);
- sprintf(_bufforseconds, "%02d", network.timeinfo.tm_sec);
- print(_bufforseconds);
- #endif
- //setFont();
- }
- void DspCore::_clockDate(){ }
- void DspCore::_clockTime(){
- if(_oldtimeleft>0) dsp.fillRect(_oldtimeleft, clockTop, _oldtimewidth, clockTimeHeight*CHARHEIGHT, config.theme.background);
- #if DSP_MODEL!=DSP_SSD1306x32
- _timeleft = (width()/2 - _timewidth/2)+clockRightSpace;
- setTextColor(config.theme.clock, config.theme.background);
- #else
- _timeleft = (width() - _timewidth)-clockRightSpace;
- setTextColor(0, 1);
- #endif
- setTextSize(clockTimeHeight);
- setCursor(_timeleft, clockTop);
- print(_timeBuf);
- //setFont();
- strlcpy(_oldTimeBuf, _timeBuf, sizeof(_timeBuf));
- _oldtimewidth = _timewidth;
- _oldtimeleft = _timeleft;
- }
- 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::clearClock(){
- dsp.fillRect(_timeleft, clockTop, _timewidth, clockTimeHeight*CHARHEIGHT, config.theme.background);
- }
- void DspCore::startWrite(void) { }
- void DspCore::endWrite(void) { }
- void DspCore::loop(bool force) {
- display();
- delay(0);
- }
- void DspCore::charSize(uint8_t textsize, uint8_t& width, uint16_t& height){
- width = textsize * CHARWIDTH;
- height = textsize * CHARHEIGHT;
- }
- void DspCore::setTextSize(uint8_t s){
- Adafruit_GFX::setTextSize(s);
- }
- void DspCore::flip(){
- setRotation(config.store.flipscreen?2:0);
- }
- void DspCore::invert(){
- invertDisplay(config.store.invertdisplay);
- }
- void DspCore::sleep(void) { ssd1306_command(SSD1306_DISPLAYOFF); }
- void DspCore::wake(void) { ssd1306_command(SSD1306_DISPLAYON); }
- 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_SSD1306::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_SSD1306::writeFillRect(x, y, w, h, color);
- }
- void DspCore::setClipping(clipArea ca){
- _cliparea = ca;
- _clipping = true;
- }
- void DspCore::clearClipping(){
- _clipping = false;
- }
- void DspCore::setNumFont(){
- setTextSize(2);
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement