first commit
This commit is contained in:
202
ESP8266_DOMOTICZ_ECRAN/Ecran.cpp
Normal file
202
ESP8266_DOMOTICZ_ECRAN/Ecran.cpp
Normal file
@@ -0,0 +1,202 @@
|
||||
#include "Ecran.h"
|
||||
|
||||
Ecran::Ecran()
|
||||
{
|
||||
Serial.println("--------------------------------------");
|
||||
Serial.println("Init Ecran");
|
||||
|
||||
// ECRAN
|
||||
LcdInitialise();
|
||||
// LcdClear();
|
||||
// LcdChar(0, 0, "Starting");
|
||||
|
||||
//
|
||||
// FIN ECRAN
|
||||
}
|
||||
|
||||
// ECRAN Methodes
|
||||
void Ecran::LcdCharacter(char character)
|
||||
{
|
||||
LcdWrite(LCD_D, 0x00);
|
||||
for (int index = 0; index < 5; index++)
|
||||
{
|
||||
LcdWrite(LCD_D, ASCII[character - 0x20][index]);
|
||||
}
|
||||
LcdWrite(LCD_D, 0x00);
|
||||
}
|
||||
|
||||
|
||||
void Ecran::LcdClear(void)
|
||||
{
|
||||
u8g2->clearBuffer();
|
||||
// for (int index = 0; index < LCD_X * LCD_Y / 8; index++)
|
||||
// {
|
||||
// LcdWrite(LCD_D, 0x00);
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
void Ecran::LcdInitialise(void)
|
||||
{
|
||||
static U8G2_PCD8544_84X48_F_4W_SW_SPI u(U8G2_R0,
|
||||
/* clock=*/ PIN_SCLK,
|
||||
/* data=*/ PIN_SDIN,
|
||||
/* cs=*/ PIN_SCE,
|
||||
/* dc=*/ PIN_DC,
|
||||
/* reset=*/ PIN_RESET); // Nokia 5110 Display
|
||||
|
||||
u8g2 = &u;
|
||||
|
||||
u8g2->begin();
|
||||
u8g2->setFont(u8g2_font_6x10_tf);
|
||||
u8g2->setFontRefHeightExtendedText();
|
||||
u8g2->setDrawColor(1);
|
||||
u8g2->setFontPosTop();
|
||||
u8g2->setFontDirection(0);
|
||||
setContrast(contrast);
|
||||
}
|
||||
|
||||
|
||||
void Ecran::LcdChar(int x, int y, char *characters)
|
||||
{
|
||||
u8g2->drawStr(x, y, characters);
|
||||
}
|
||||
|
||||
void Ecran::LcdString(int x, int y, String s)
|
||||
{
|
||||
char cs[s.length() + 1];
|
||||
s.toCharArray(cs, s.length() + 1);
|
||||
LcdChar(x, y, cs);
|
||||
}
|
||||
|
||||
void Ecran::LcdWrite(byte dc, byte data)
|
||||
{
|
||||
digitalWrite(PIN_DC, dc);
|
||||
digitalWrite(PIN_SCE, LOW);
|
||||
shiftOut(PIN_SDIN, PIN_SCLK, MSBFIRST, data);
|
||||
digitalWrite(PIN_SCE, HIGH);
|
||||
}
|
||||
|
||||
void Ecran::setContrast(byte contrast)
|
||||
{
|
||||
//analogWrite(PIN_LCD, contrast);
|
||||
}
|
||||
|
||||
//This takes a large array of bits and sends them to the LCD
|
||||
void Ecran::LcdBitmap(int x, int y, char my_array[])
|
||||
{
|
||||
for (int index = 0 ; index < (x * y / 8) ; index++)
|
||||
{
|
||||
LcdWrite(LCD_DATA, my_array[index]);
|
||||
}
|
||||
}
|
||||
|
||||
//void Ecran::printInfos()
|
||||
//{
|
||||
// // ECRAN
|
||||
// LcdClear();
|
||||
// float fractionC;
|
||||
//
|
||||
// fractionC = temperature - ((int)temperature);
|
||||
//
|
||||
// gotoXY(0,0);
|
||||
// LcdString("TEMP ");
|
||||
// itoa(temperature,strBuffer,10);
|
||||
// LcdString(strBuffer);
|
||||
// itoa(fractionC,strBuffer,10);
|
||||
// LcdString(".");
|
||||
// LcdString(strBuffer);
|
||||
// LcdString("C ");
|
||||
//
|
||||
// fractionC = pression - ((int) pression);
|
||||
//
|
||||
// gotoXY(0,10);
|
||||
// LcdString("Pres ");
|
||||
// itoa(pression,strBuffer,10);
|
||||
// LcdString(strBuffer);
|
||||
// itoa(fractionC,strBuffer,10);
|
||||
// LcdString(".");
|
||||
// LcdString(strBuffer);
|
||||
// LcdString("hp");
|
||||
//
|
||||
// fractionC = lux - ((int) lux);
|
||||
//
|
||||
// gotoXY(0,20);
|
||||
// LcdString("Lum ");
|
||||
// itoa(lux,strBuffer,10);
|
||||
// LcdString(strBuffer);
|
||||
// itoa(fractionC,strBuffer,10);
|
||||
// LcdString(".");
|
||||
// LcdString(strBuffer);
|
||||
// LcdString("Lux ");
|
||||
// // FIN ECRAN
|
||||
//}
|
||||
|
||||
void Ecran::intro()
|
||||
{
|
||||
int a = 0;
|
||||
u8g2->clearBuffer();
|
||||
u8g2->setFontDirection(0);
|
||||
LcdChar(0, 0, "Starting");
|
||||
u8g2->drawStr(30+a,31, " 0");
|
||||
u8g2->setFontDirection(1);
|
||||
u8g2->drawStr(30,31+a, " 90");
|
||||
u8g2->setFontDirection(2);
|
||||
u8g2->drawStr(30-a,31, " 180");
|
||||
u8g2->setFontDirection(3);
|
||||
u8g2->drawStr(30,31-a, " 270");
|
||||
u8g2->sendBuffer();
|
||||
|
||||
delay(2000);
|
||||
const uint8_t frame_size = 24;
|
||||
|
||||
u8g2->clearBuffer();
|
||||
u8g2->drawBox(0, frame_size * 0.5, frame_size * 5, frame_size);
|
||||
u8g2->drawStr(frame_size * 0.5, 50, "Black");
|
||||
u8g2->drawStr(frame_size * 2, 50, "White");
|
||||
u8g2->drawStr(frame_size * 3.5, 50, "XOR");
|
||||
u8g2->setBitmapMode(false /* solid */);
|
||||
u8g2->drawStr(0, 0, "Solid bitmap");
|
||||
u8g2->sendBuffer();
|
||||
|
||||
delay(2000);
|
||||
u8g2->clearBuffer();
|
||||
u8g2->setDrawColor(0);// Black
|
||||
u8g2->drawXBMP(frame_size * 0.5, 24, cross_width, cross_height, cross_bits);
|
||||
u8g2->setDrawColor(1); // White
|
||||
u8g2->drawXBMP(frame_size * 2, 24, cross_width, cross_height, cross_bits);
|
||||
u8g2->setDrawColor(2); // XOR
|
||||
u8g2->drawXBMP(frame_size * 3.5, 24, cross_width, cross_height, cross_bits);
|
||||
|
||||
u8g2->sendBuffer();
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
void Ecran::drawRect(int x0, int y0, int x1, int y1)
|
||||
{
|
||||
u8g2->drawLine(x0, y0, x1, y0);
|
||||
u8g2->drawLine(x1, y0, x1, y1);
|
||||
u8g2->drawLine(x1, y1, x0, y1);
|
||||
u8g2->drawLine(x0, y1, x0, y0);
|
||||
// u8g2->drawLine(LCD_X / 2, 1, LCD_X / 2, LCD_Y -1);
|
||||
}
|
||||
|
||||
void Ecran::drawJauge(int x0, int y0, int x1, int y1, int val, String text)
|
||||
{
|
||||
drawRect(x0, y0, x1, y1);
|
||||
if (val > 100) {
|
||||
val = x1;
|
||||
}
|
||||
u8g2->drawBox(x0, y0, ((x1 - x0) * val) / 100, y1 - y0);
|
||||
if (text != "") {
|
||||
LcdString(x0, y0, text);
|
||||
}
|
||||
// u8g2->drawLine(LCD_X / 2, 1, LCD_X / 2, LCD_Y -1);
|
||||
}
|
||||
|
||||
void Ecran::drawFace(int x0, int y0, int x1, int y1, int x2, int y2)
|
||||
{
|
||||
u8g2->drawLine(x0, y0, x1, y1);
|
||||
u8g2->drawLine(x1, y1, x2, y2);
|
||||
u8g2->drawLine(x2, y2, x0, y0);
|
||||
}
|
||||
Reference in New Issue
Block a user