2021-11-03 17:55:42 +01:00
|
|
|
#ifndef __display_H__
|
|
|
|
#define __display_H__
|
|
|
|
|
|
|
|
#include "fonts.h"
|
2021-11-08 13:18:06 +01:00
|
|
|
#include <Wire.h>
|
2021-11-03 17:55:42 +01:00
|
|
|
#include "SSD1306Wire.h"
|
|
|
|
|
|
|
|
class display
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
const uint8_t MAX_CONTRAST = 255;
|
|
|
|
SSD1306Wire * _display;
|
2021-11-15 08:25:19 +01:00
|
|
|
uint8_t _dispaddr;
|
|
|
|
int _pin_sda, _pin_scl;
|
2021-12-08 18:25:51 +01:00
|
|
|
bool _screen_flipped;
|
2021-11-03 17:55:42 +01:00
|
|
|
public:
|
2021-11-15 08:25:19 +01:00
|
|
|
display(uint8_t dispaddr, int pin_sda, int pin_scl);
|
2021-11-03 17:55:42 +01:00
|
|
|
~display();
|
2021-11-15 08:25:19 +01:00
|
|
|
void init();
|
2021-11-03 17:55:42 +01:00
|
|
|
void header(String title);
|
|
|
|
void header(String title, bool wificonected, bool localvalues, bool lastdatasent, bool timesynced);
|
|
|
|
void data(unsigned int x, unsigned int y , float val, String valname);
|
|
|
|
void data(unsigned int x, unsigned int y , uint64_t val, String valname);
|
|
|
|
void data(unsigned int x, unsigned int y ,bool valid, String val, String valname, unsigned int digits, String valunit);
|
|
|
|
void show();
|
|
|
|
void clear();
|
2021-12-08 18:25:51 +01:00
|
|
|
void flipScreenVert();
|
|
|
|
void setBrigthness(uint8_t value);
|
2021-11-03 17:55:42 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2021-11-15 08:25:19 +01:00
|
|
|
display::display(uint8_t dispaddr, int pin_sda, int pin_scl)
|
2021-11-03 17:55:42 +01:00
|
|
|
{
|
|
|
|
_pin_sda = pin_sda;
|
|
|
|
_pin_scl = pin_scl;
|
2021-11-15 08:25:19 +01:00
|
|
|
_dispaddr = dispaddr;
|
2021-11-03 17:55:42 +01:00
|
|
|
_display = new SSD1306Wire(_dispaddr, _pin_sda, _pin_scl);
|
|
|
|
}
|
|
|
|
|
|
|
|
display::~display()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-11-15 08:25:19 +01:00
|
|
|
void display::init()
|
2021-11-03 17:55:42 +01:00
|
|
|
{
|
|
|
|
//initialise OLED and display Welcome Message ...
|
|
|
|
_display->init();
|
2021-11-15 08:25:19 +01:00
|
|
|
_display->flipScreenVertically();
|
2021-12-08 18:25:51 +01:00
|
|
|
_screen_flipped = true;
|
2021-11-15 08:25:19 +01:00
|
|
|
_display->setTextAlignment(TEXT_ALIGN_CENTER);
|
2021-11-03 17:55:42 +01:00
|
|
|
_display->setFont(Roboto_Condensed_Bold_16);
|
|
|
|
_display->clear();
|
|
|
|
_display->setContrast(MAX_CONTRAST);
|
|
|
|
_display->drawString(64, 32, "Itsblue.de");
|
|
|
|
_display->display();
|
|
|
|
}
|
|
|
|
|
|
|
|
void display::header(String title, bool wificonected, bool localvalues, bool lastdatasent, bool timesynced)
|
|
|
|
{
|
|
|
|
_display->setTextAlignment(TEXT_ALIGN_CENTER_BOTH);
|
|
|
|
_display->setColor(WHITE);
|
|
|
|
_display->fillRect(0, 1, 128, 12);
|
|
|
|
_display->setColor(BLACK);
|
|
|
|
_display->setFont(ArialMT_Plain_10);
|
|
|
|
unsigned int y = 6;
|
|
|
|
_display->drawString(64, y, title);
|
|
|
|
|
|
|
|
if (wificonected)
|
|
|
|
{
|
|
|
|
_display->drawString(110,y, "Y");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_display->drawString(110, y, "!");
|
|
|
|
}
|
|
|
|
if (localvalues) {
|
|
|
|
if (lastdatasent)
|
|
|
|
{
|
|
|
|
_display->drawString(120, y, " >>");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_display->drawString(120, y, " x ");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_display->drawString(120, y, " R ");
|
|
|
|
}
|
|
|
|
if (timesynced)
|
|
|
|
{
|
|
|
|
_display->drawString(10, y, "(<)");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_display->drawString(10, y, "( )");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void display::header(String title)
|
|
|
|
{
|
|
|
|
header(title, false, true, false, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void display::data(unsigned int x, unsigned int y ,bool valid, String val, String valname, unsigned int digits, String valunit)
|
|
|
|
{
|
|
|
|
_display->setColor(WHITE);
|
|
|
|
_display->setTextAlignment(TEXT_ALIGN_CENTER);
|
|
|
|
_display->setFont(ArialMT_Plain_10);
|
|
|
|
String namestring = valname + ":";
|
|
|
|
_display->drawString(x,y, namestring);
|
|
|
|
_display->setFont(ArialMT_Plain_16);
|
|
|
|
String valstring = "";
|
|
|
|
if (valid == true) {
|
|
|
|
valstring = val;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for(unsigned int digit=0; digit < digits; digit++){
|
|
|
|
valstring+="-";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_display->drawString(x,y+10, valstring);
|
|
|
|
unsigned int valwidth = _display->getStringWidth(valstring)/2;
|
|
|
|
_display->setFont(ArialMT_Plain_10);
|
|
|
|
_display->setTextAlignment(TEXT_ALIGN_LEFT);
|
|
|
|
_display->drawString(x+valwidth,y+10, valunit);
|
|
|
|
_display->setTextAlignment(TEXT_ALIGN_CENTER);
|
|
|
|
}
|
|
|
|
|
|
|
|
void display::data(unsigned int x, unsigned int y , uint64_t val, String valname)
|
|
|
|
{
|
|
|
|
data(x, y,true, String((unsigned long)val,10), valname, 0, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
void display::data(unsigned int x, unsigned int y , float val, String valname)
|
|
|
|
{
|
|
|
|
data(x, y,true, String(val,1), valname, 0, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
void display::show()
|
|
|
|
{
|
|
|
|
_display->display();
|
|
|
|
}
|
|
|
|
|
|
|
|
void display::clear()
|
|
|
|
{
|
|
|
|
_display->clear();
|
|
|
|
}
|
|
|
|
|
2021-12-08 18:25:51 +01:00
|
|
|
void display::flipScreenVert()
|
|
|
|
{
|
|
|
|
if(_screen_flipped == true)
|
|
|
|
{
|
|
|
|
_screen_flipped = false;
|
|
|
|
_display->invertDisplay();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_screen_flipped = true;
|
|
|
|
_display->normalDisplay();
|
|
|
|
//_display->flipScreenVertically();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void display::setBrigthness(uint8_t value)
|
|
|
|
{
|
|
|
|
_display->setBrightness(value);
|
|
|
|
}
|
|
|
|
|
2021-11-03 17:55:42 +01:00
|
|
|
#endif
|