2023-03-26 14:12:27 +02:00
|
|
|
#include <Wire.h>
|
2023-06-20 02:17:23 +02:00
|
|
|
#include "configuration.h"
|
2024-11-05 18:41:41 +01:00
|
|
|
#include "board_pinout.h"
|
2023-06-08 06:58:10 +02:00
|
|
|
#include "display.h"
|
2023-03-26 14:12:27 +02:00
|
|
|
|
2024-05-11 18:02:08 +02:00
|
|
|
|
2024-03-21 13:01:42 +01:00
|
|
|
#ifdef HAS_DISPLAY
|
2024-05-11 18:02:08 +02:00
|
|
|
#ifdef HAS_TFT
|
|
|
|
|
#include <TFT_eSPI.h>
|
|
|
|
|
|
|
|
|
|
TFT_eSPI tft = TFT_eSPI();
|
|
|
|
|
|
|
|
|
|
#ifdef HELTEC_WIRELESS_TRACKER
|
2024-07-09 16:41:26 +02:00
|
|
|
#define bigSizeFont 2.5
|
|
|
|
|
#define smallSizeFont 1.5
|
|
|
|
|
#define lineSpacing 12
|
2024-05-11 18:02:08 +02:00
|
|
|
#endif
|
|
|
|
|
#else
|
2024-08-16 21:52:20 +02:00
|
|
|
#if HAS_EPAPER
|
|
|
|
|
//
|
2024-07-17 22:20:20 +02:00
|
|
|
#else
|
2024-08-16 21:52:20 +02:00
|
|
|
#include <Adafruit_GFX.h>
|
|
|
|
|
#include <Adafruit_SSD1306.h>
|
2024-09-11 21:14:40 +02:00
|
|
|
#if defined(HELTEC_V3) || defined(HELTEC_WS)
|
2024-08-16 21:52:20 +02:00
|
|
|
#define OLED_DISPLAY_HAS_RST_PIN
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef HELTEC_WSL_V3_DISPLAY
|
|
|
|
|
Adafruit_SSD1306 display(128, 64, &Wire1, OLED_RST);
|
|
|
|
|
#else
|
|
|
|
|
Adafruit_SSD1306 display(128, 64, &Wire, OLED_RST);
|
|
|
|
|
#endif
|
2024-07-17 22:20:20 +02:00
|
|
|
#endif
|
2024-05-11 18:02:08 +02:00
|
|
|
#endif
|
2024-03-21 13:01:42 +01:00
|
|
|
#endif
|
2024-06-10 20:00:15 +02:00
|
|
|
|
2024-10-25 16:50:57 +02:00
|
|
|
extern Configuration Config;
|
|
|
|
|
|
|
|
|
|
String oldHeader, oldFirstLine, oldSecondLine, oldThirdLine, oldFourthLine, oldFifthLine, oldSixthLine;
|
|
|
|
|
bool displayFound = false;
|
2023-06-20 02:17:23 +02:00
|
|
|
|
2024-05-11 18:02:08 +02:00
|
|
|
|
|
|
|
|
void cleanTFT() {
|
|
|
|
|
#ifdef HAS_TFT
|
|
|
|
|
tft.fillScreen(TFT_BLACK);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2023-03-26 14:12:27 +02:00
|
|
|
|
2024-08-14 18:32:34 +02:00
|
|
|
void displaySetup() {
|
2024-05-11 18:02:08 +02:00
|
|
|
#ifdef HAS_DISPLAY
|
|
|
|
|
delay(500);
|
|
|
|
|
#ifdef HAS_TFT
|
|
|
|
|
tft.init();
|
|
|
|
|
tft.begin();
|
2024-05-13 04:57:45 +02:00
|
|
|
if (Config.display.turn180) {
|
|
|
|
|
tft.setRotation(3);
|
|
|
|
|
} else {
|
|
|
|
|
tft.setRotation(1);
|
|
|
|
|
}
|
2024-05-11 18:02:08 +02:00
|
|
|
tft.setTextFont(0);
|
|
|
|
|
tft.fillScreen(TFT_BLACK);
|
2024-08-16 21:52:20 +02:00
|
|
|
#else
|
|
|
|
|
#if HAS_EPAPER
|
|
|
|
|
//
|
|
|
|
|
#else
|
|
|
|
|
#ifdef OLED_DISPLAY_HAS_RST_PIN
|
|
|
|
|
pinMode(OLED_RST, OUTPUT);
|
|
|
|
|
digitalWrite(OLED_RST, LOW);
|
|
|
|
|
delay(20);
|
|
|
|
|
digitalWrite(OLED_RST, HIGH);
|
|
|
|
|
#endif
|
2024-07-17 22:20:20 +02:00
|
|
|
|
2024-10-25 16:08:00 +02:00
|
|
|
if(display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
|
2024-10-25 16:50:57 +02:00
|
|
|
displayFound = true;
|
2024-10-29 22:57:23 +01:00
|
|
|
if (Config.display.turn180) display.setRotation(2);
|
2024-10-25 16:08:00 +02:00
|
|
|
display.clearDisplay();
|
|
|
|
|
display.setTextColor(WHITE);
|
|
|
|
|
display.setTextSize(1);
|
|
|
|
|
display.setCursor(0, 0);
|
|
|
|
|
display.ssd1306_command(SSD1306_SETCONTRAST);
|
|
|
|
|
display.ssd1306_command(1);
|
|
|
|
|
display.display();
|
2024-10-25 16:50:57 +02:00
|
|
|
}
|
2024-08-16 21:52:20 +02:00
|
|
|
#endif
|
2024-05-11 18:02:08 +02:00
|
|
|
#endif
|
|
|
|
|
delay(1000);
|
2024-03-21 13:01:42 +01:00
|
|
|
#endif
|
2023-03-26 14:12:27 +02:00
|
|
|
}
|
|
|
|
|
|
2024-08-14 18:32:34 +02:00
|
|
|
void displayToggle(bool toggle) {
|
2024-03-21 13:01:42 +01:00
|
|
|
#ifdef HAS_DISPLAY
|
2024-05-11 18:59:07 +02:00
|
|
|
if (toggle) {
|
|
|
|
|
#ifdef HAS_TFT
|
|
|
|
|
digitalWrite(TFT_BL, HIGH);
|
|
|
|
|
#else
|
2024-08-16 21:52:20 +02:00
|
|
|
#if HAS_EPAPER
|
|
|
|
|
// ... to be continued
|
|
|
|
|
#else
|
2024-10-25 16:50:57 +02:00
|
|
|
if (displayFound) display.ssd1306_command(SSD1306_DISPLAYON);
|
2024-08-16 21:52:20 +02:00
|
|
|
#endif
|
2024-05-11 18:59:07 +02:00
|
|
|
#endif
|
|
|
|
|
} else {
|
|
|
|
|
#ifdef HAS_TFT
|
|
|
|
|
digitalWrite(TFT_BL, LOW);
|
|
|
|
|
#else
|
2024-08-16 21:52:20 +02:00
|
|
|
#if HAS_EPAPER
|
|
|
|
|
// ... to be continued
|
|
|
|
|
#else
|
2024-10-25 16:50:57 +02:00
|
|
|
if (displayFound) display.ssd1306_command(SSD1306_DISPLAYOFF);
|
2024-08-16 21:52:20 +02:00
|
|
|
#endif
|
2024-05-11 18:59:07 +02:00
|
|
|
#endif
|
|
|
|
|
}
|
2024-03-21 13:01:42 +01:00
|
|
|
#endif
|
2023-03-26 14:12:27 +02:00
|
|
|
}
|
|
|
|
|
|
2024-05-15 23:47:29 +02:00
|
|
|
bool shouldCleanTFT(const String& header, const String& line1, const String& line2, const String& line3) {
|
2024-05-11 18:19:19 +02:00
|
|
|
if (oldHeader != header || oldFirstLine != line1 || oldSecondLine != line2 || oldThirdLine != line3) {
|
|
|
|
|
oldHeader = header;
|
|
|
|
|
oldFirstLine = line1;
|
|
|
|
|
oldSecondLine = line2;
|
|
|
|
|
oldThirdLine = line3;
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2023-03-26 14:12:27 +02:00
|
|
|
}
|
|
|
|
|
|
2024-05-15 23:47:29 +02:00
|
|
|
bool shouldCleanTFT(const String& header, const String& line1, const String& line2, const String& line3, const String& line4, const String& line5, const String& line6) {
|
2024-05-11 18:19:19 +02:00
|
|
|
if (oldHeader != header || oldFirstLine != line1 || oldSecondLine != line2 || oldThirdLine != line3 || oldFourthLine != line4 || oldFifthLine != line5 || oldSixthLine != line6) {
|
|
|
|
|
oldHeader = header;
|
|
|
|
|
oldFirstLine = line1;
|
|
|
|
|
oldSecondLine = line2;
|
|
|
|
|
oldThirdLine = line3;
|
|
|
|
|
oldFourthLine = line4;
|
|
|
|
|
oldFifthLine = line5;
|
|
|
|
|
oldSixthLine = line6;
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2023-03-26 14:12:27 +02:00
|
|
|
}
|
|
|
|
|
|
2024-08-14 18:32:34 +02:00
|
|
|
void displayShow(const String& header, const String& line1, const String& line2, const String& line3, int wait) {
|
2024-03-21 13:01:42 +01:00
|
|
|
#ifdef HAS_DISPLAY
|
2024-06-06 05:20:34 +02:00
|
|
|
const String* const lines[] = {&line1, &line2, &line3};
|
2024-05-11 18:02:08 +02:00
|
|
|
#ifdef HAS_TFT
|
2024-05-11 18:19:19 +02:00
|
|
|
if (shouldCleanTFT(header, line1, line2, line3)) {
|
2024-05-11 18:02:08 +02:00
|
|
|
cleanTFT();
|
|
|
|
|
}
|
|
|
|
|
tft.setTextColor(TFT_WHITE,TFT_BLACK);
|
|
|
|
|
tft.setTextSize(bigSizeFont);
|
|
|
|
|
tft.setCursor(0, 0);
|
|
|
|
|
tft.print(header);
|
|
|
|
|
tft.setTextSize(smallSizeFont);
|
2024-06-06 05:20:34 +02:00
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
|
tft.setCursor(0, ((lineSpacing * (2 + i)) - 2));
|
|
|
|
|
tft.print(*lines[i]);
|
|
|
|
|
}
|
2024-05-11 18:02:08 +02:00
|
|
|
#else
|
2024-08-16 21:52:20 +02:00
|
|
|
#ifdef HAS_EPAPER
|
|
|
|
|
// ... to be continued
|
|
|
|
|
#else
|
2024-10-25 16:50:57 +02:00
|
|
|
if (displayFound) {
|
|
|
|
|
display.clearDisplay();
|
|
|
|
|
display.setTextColor(WHITE);
|
|
|
|
|
display.setTextSize(1);
|
|
|
|
|
display.setCursor(0, 0);
|
|
|
|
|
display.println(header);
|
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
|
display.setCursor(0, 8 + (8 * i));
|
|
|
|
|
display.println(*lines[i]);
|
|
|
|
|
}
|
|
|
|
|
display.ssd1306_command(SSD1306_SETCONTRAST);
|
|
|
|
|
display.ssd1306_command(1);
|
|
|
|
|
display.display();
|
2024-08-16 21:52:20 +02:00
|
|
|
}
|
|
|
|
|
#endif
|
2024-05-11 18:02:08 +02:00
|
|
|
#endif
|
|
|
|
|
delay(wait);
|
2024-03-21 13:01:42 +01:00
|
|
|
#endif
|
2023-06-17 01:08:25 +02:00
|
|
|
}
|
|
|
|
|
|
2024-08-14 18:32:34 +02:00
|
|
|
void displayShow(const String& header, const String& line1, const String& line2, const String& line3, const String& line4, const String& line5, const String& line6, int wait) {
|
2024-03-21 13:01:42 +01:00
|
|
|
#ifdef HAS_DISPLAY
|
2024-06-06 05:20:34 +02:00
|
|
|
const String* const lines[] = {&line1, &line2, &line3, &line4, &line5, &line6};
|
2024-05-11 18:02:08 +02:00
|
|
|
#ifdef HAS_TFT
|
2024-05-11 18:19:19 +02:00
|
|
|
if (shouldCleanTFT(header, line1, line2, line3, line4, line5, line6)) {
|
2024-05-11 18:02:08 +02:00
|
|
|
cleanTFT();
|
|
|
|
|
}
|
|
|
|
|
tft.setTextColor(TFT_WHITE,TFT_BLACK);
|
|
|
|
|
tft.setTextSize(bigSizeFont);
|
|
|
|
|
tft.setCursor(0, 0);
|
|
|
|
|
tft.print(header);
|
|
|
|
|
tft.setTextSize(smallSizeFont);
|
2024-06-06 05:20:34 +02:00
|
|
|
for (int i = 0; i < 6; i++) {
|
|
|
|
|
tft.setCursor(0, ((lineSpacing * (2 + i)) - 2));
|
|
|
|
|
tft.print(*lines[i]);
|
|
|
|
|
}
|
2024-05-11 18:02:08 +02:00
|
|
|
#else
|
2024-08-16 21:52:20 +02:00
|
|
|
#ifdef HAS_EPAPER
|
|
|
|
|
// ... to be continued
|
|
|
|
|
#else
|
2024-10-25 16:50:57 +02:00
|
|
|
if (displayFound) {
|
|
|
|
|
display.clearDisplay();
|
|
|
|
|
display.setTextColor(WHITE);
|
|
|
|
|
display.setTextSize(2);
|
|
|
|
|
display.setCursor(0, 0);
|
|
|
|
|
display.println(header);
|
|
|
|
|
display.setTextSize(1);
|
|
|
|
|
for (int i = 0; i < 6; i++) {
|
|
|
|
|
display.setCursor(0, 16 + (8 * i));
|
|
|
|
|
display.println(*lines[i]);
|
|
|
|
|
}
|
|
|
|
|
display.ssd1306_command(SSD1306_SETCONTRAST);
|
|
|
|
|
display.ssd1306_command(1);
|
|
|
|
|
display.display();
|
2024-08-16 21:52:20 +02:00
|
|
|
}
|
|
|
|
|
#endif
|
2024-05-11 18:02:08 +02:00
|
|
|
#endif
|
|
|
|
|
delay(wait);
|
2024-08-16 22:00:58 +02:00
|
|
|
#endif
|
|
|
|
|
}
|