updated screen + added OTA
This commit is contained in:
152
lcd.cpp
152
lcd.cpp
@@ -38,6 +38,7 @@ TFT_eSprite needle = TFT_eSprite(&tft); // Sprite object for needle
|
||||
TFT_eSprite spr = TFT_eSprite(&tft); // Sprite for meter reading
|
||||
TFT_eSprite nameSpr = TFT_eSprite(&tft);
|
||||
TFT_eSprite unitSpr = TFT_eSprite(&tft);
|
||||
TFT_eSprite ProgressBar = TFT_eSprite(&tft);
|
||||
|
||||
// Jpeg image array attached to this sketch
|
||||
#include "dial.h"
|
||||
@@ -49,6 +50,7 @@ uint16_t *tft_buffer;
|
||||
bool buffer_loaded = false;
|
||||
uint16_t spr_width = 0;
|
||||
uint16_t name_spr_width = 0;
|
||||
bool progessbarActive = false;
|
||||
|
||||
void createNeedle(void);
|
||||
void plotNeedle(int16_t angle, uint16_t ms_delay);
|
||||
@@ -69,29 +71,58 @@ bool tft_output(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t *bitmap)
|
||||
return 1;
|
||||
}
|
||||
|
||||
// =======================================================================================
|
||||
// Setup
|
||||
// =======================================================================================
|
||||
void initLCD()
|
||||
void setBacklight(uint8_t value)
|
||||
{
|
||||
Serial.print("InitLCD:");
|
||||
// The byte order can be swapped (set true for TFT_eSPI)
|
||||
TJpgDec.setSwapBytes(true);
|
||||
ledcWrite(TFT_BL_PWMCHANNEL, value);
|
||||
}
|
||||
|
||||
// The jpeg decoder must be given the exact name of the rendering function above
|
||||
TJpgDec.setCallback(tft_output);
|
||||
void createProgressBar(void)
|
||||
{
|
||||
ProgressBar.createSprite(220, 30);
|
||||
ProgressBar.fillSprite(TFT_BLACK);
|
||||
ProgressBar.drawRoundRect(0, 2, 220, 22, 5, TFT_BLUE);
|
||||
ProgressBar.pushSprite(10, 270);
|
||||
}
|
||||
|
||||
tft.begin();
|
||||
tft.setRotation(0);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
void ProgressbarVisible(bool visible)
|
||||
{
|
||||
progessbarActive = visible;
|
||||
if (!visible)
|
||||
{
|
||||
ProgressBar.fillSprite(TFT_BLACK);
|
||||
ProgressBar.pushSprite(10, 270);
|
||||
}
|
||||
}
|
||||
|
||||
pinMode(TFT_BL, OUTPUT);
|
||||
void setOTAProgress(uint8_t value)
|
||||
{
|
||||
uint16_t progress = map(value, 0, 100, 0, 212);
|
||||
ProgressBar.drawRoundRect(0, 2, 220, 22, 5, TFT_BLUE);
|
||||
ProgressBar.fillRoundRect(4, 5, progress, 15, 3, TFT_BLUE);
|
||||
if (progessbarActive)
|
||||
{
|
||||
ProgressBar.pushSprite(10, 270);
|
||||
}
|
||||
}
|
||||
|
||||
// Draw the dial
|
||||
TJpgDec.drawJpg(0, 0, dial, sizeof(dial));
|
||||
tft.drawCircle(DIAL_CENTRE_X, DIAL_CENTRE_Y, NEEDLE_RADIUS - NEEDLE_LENGTH, TFT_DARKGREY);
|
||||
void createNameSprite(void)
|
||||
{
|
||||
nameSpr.setTextFont(2);
|
||||
name_spr_width = nameSpr.textWidth("---Sensor Name---");
|
||||
nameSpr.createSprite(name_spr_width, nameSpr.fontHeight() * 2 + 2);
|
||||
uint16_t bg_color = tft.readPixel(120, 120); // Get colour from dial centre
|
||||
|
||||
// Load the font and create the Sprite for reporting the value
|
||||
nameSpr.fillSprite(bg_color);
|
||||
nameSpr.setTextColor(TFT_WHITE, bg_color);
|
||||
nameSpr.setTextDatum(MC_DATUM);
|
||||
nameSpr.setTextPadding(name_spr_width);
|
||||
nameSpr.drawString("Sensor Name", name_spr_width / 2, nameSpr.fontHeight() / 2);
|
||||
nameSpr.drawString("Unit", name_spr_width / 2, nameSpr.fontHeight() / 2 * 3 + 2);
|
||||
nameSpr.pushSprite(DIAL_CENTRE_X - name_spr_width / 2, DIAL_CENTRE_Y + 40, 2);
|
||||
}
|
||||
|
||||
void createValueSprinte(void)
|
||||
{
|
||||
spr.loadFont(AA_FONT_LARGE);
|
||||
spr_width = spr.textWidth("277");
|
||||
spr.createSprite(spr_width, spr.fontHeight());
|
||||
@@ -102,25 +133,45 @@ void initLCD()
|
||||
spr.setTextPadding(spr_width);
|
||||
spr.drawNumber(0, spr_width / 2, spr.fontHeight() / 2);
|
||||
spr.pushSprite(DIAL_CENTRE_X - spr_width / 2, DIAL_CENTRE_Y - spr.fontHeight() / 2);
|
||||
}
|
||||
|
||||
// Plot the label text
|
||||
nameSpr.setTextFont(2);
|
||||
name_spr_width = nameSpr.textWidth("---Sensor Name---");
|
||||
nameSpr.createSprite(name_spr_width, nameSpr.fontHeight() * 2 + 2);
|
||||
nameSpr.fillSprite(bg_color);
|
||||
nameSpr.setTextColor(TFT_WHITE, bg_color);
|
||||
nameSpr.setTextDatum(MC_DATUM);
|
||||
nameSpr.setTextPadding(name_spr_width);
|
||||
nameSpr.drawString("Sensor Name", name_spr_width / 2, nameSpr.fontHeight() / 2);
|
||||
nameSpr.drawString("Unit", name_spr_width / 2, nameSpr.fontHeight() / 2 * 3 + 2); nameSpr.pushSprite(DIAL_CENTRE_X - name_spr_width / 2, DIAL_CENTRE_Y + 40, 2);
|
||||
nameSpr.pushSprite(DIAL_CENTRE_X - name_spr_width / 2, DIAL_CENTRE_Y + 40, 2);
|
||||
void createDail(void)
|
||||
{
|
||||
TJpgDec.setSwapBytes(true);
|
||||
|
||||
// The jpeg decoder must be given the exact name of the rendering function above
|
||||
TJpgDec.setCallback(tft_output);
|
||||
// Draw the dial
|
||||
TJpgDec.drawJpg(0, 0, dial, sizeof(dial));
|
||||
tft.drawCircle(DIAL_CENTRE_X, DIAL_CENTRE_Y, NEEDLE_RADIUS - NEEDLE_LENGTH, TFT_DARKGREY);
|
||||
|
||||
// Define where the needle pivot point is on the TFT before
|
||||
// creating the needle so boundary calculation is correct
|
||||
tft.setPivot(DIAL_CENTRE_X, DIAL_CENTRE_Y);
|
||||
}
|
||||
|
||||
// Create the needle Sprite
|
||||
// =======================================================================================
|
||||
// Setup
|
||||
// =======================================================================================
|
||||
void initLCD()
|
||||
{
|
||||
Serial.print("InitLCD:");
|
||||
// The byte order can be swapped (set true for TFT_eSPI)
|
||||
|
||||
tft.begin();
|
||||
tft.setRotation(0);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
|
||||
// Create the Sprites
|
||||
createProgressBar();
|
||||
createDail();
|
||||
createValueSprinte();
|
||||
createNeedle();
|
||||
createNameSprite();
|
||||
|
||||
ledcSetup(TFT_BL_PWMCHANNEL, TFT_BL_FREQ, TFT_BL_BITS);
|
||||
ledcAttachPin(TFT_BL, TFT_BL_PWMCHANNEL);
|
||||
ledcWrite(TFT_BL_PWMCHANNEL, 64);
|
||||
|
||||
// Reset needle position to 0
|
||||
plotNeedle(0, 0, 0);
|
||||
@@ -150,6 +201,47 @@ uint32_t display_last_update = 0;
|
||||
#define MINGUAGE 0
|
||||
#define DISPLAY_ROTATE 15 //sec
|
||||
|
||||
uint32_t backlightTimeout = 0;
|
||||
#define BACKLIGHTTIMEOUT 60000
|
||||
#define BACKLIGHTONBRGT 129
|
||||
#define BACKLIGHTSTEP 5
|
||||
uint8_t backloghtBrightness = BACKLIGHTONBRGT;
|
||||
|
||||
void backlightRefresh(void)
|
||||
{
|
||||
backlightTimeout = millis();
|
||||
}
|
||||
|
||||
void handleBacklight(void)
|
||||
{
|
||||
uint32_t timeNow = millis();
|
||||
if (!backlightTimeout)
|
||||
{
|
||||
backlightRefresh();
|
||||
}
|
||||
if (timeNow - backlightTimeout > BACKLIGHTTIMEOUT)
|
||||
{
|
||||
if (backloghtBrightness > BACKLIGHTSTEP)
|
||||
{
|
||||
backloghtBrightness -= BACKLIGHTSTEP;
|
||||
Serial.printf("LCD: backlight %d\n", backloghtBrightness);
|
||||
}
|
||||
else
|
||||
{
|
||||
backloghtBrightness = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (backloghtBrightness < BACKLIGHTONBRGT)
|
||||
{
|
||||
backloghtBrightness += BACKLIGHTSTEP;
|
||||
Serial.printf("LCD: backlight %d", backloghtBrightness);
|
||||
}
|
||||
}
|
||||
ledcWrite(TFT_BL_PWMCHANNEL, backloghtBrightness);
|
||||
}
|
||||
|
||||
void handleLCD()
|
||||
{
|
||||
static uint16_t angle;
|
||||
@@ -226,6 +318,8 @@ void handleLCD()
|
||||
nameSpr.drawString(sensor->getName().c_str(), name_spr_width / 2, nameSpr.fontHeight() / 2);
|
||||
nameSpr.drawString(sensor->getUnit().c_str(), name_spr_width / 2, nameSpr.fontHeight() / 2 * 3 + 2);
|
||||
nameSpr.pushSprite(DIAL_CENTRE_X - name_spr_width / 2, DIAL_CENTRE_Y + 40, 2);
|
||||
|
||||
handleBacklight();
|
||||
}
|
||||
|
||||
// =======================================================================================
|
||||
|
||||
Reference in New Issue
Block a user