LoRa_APRS_iGate/src/display.cpp

306 lines
11 KiB
C++
Raw Permalink Normal View History

2025-07-15 22:28:23 +02:00
/* Copyright (C) 2025 Ricardo Guzman - CA2RXU
*
* This file is part of LoRa APRS iGate.
*
* LoRa APRS iGate is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LoRa APRS iGate is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LoRa APRS iGate. If not, see <https://www.gnu.org/licenses/>.
*/
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();
2025-01-22 03:57:56 +01:00
TFT_eSprite sprite = TFT_eSprite(&tft);
2024-05-11 18:02:08 +02:00
#ifdef HELTEC_WIRELESS_TRACKER
2024-11-06 16:47:42 +01:00
#define bigSizeFont 2
#define smallSizeFont 1
#define lineSpacing 10
2024-05-11 18:02:08 +02:00
#endif
2025-01-22 03:00:49 +01:00
#if defined(TTGO_T_DECK_GPS) || defined(TTGO_T_DECK_PLUS)
#define bigSizeFont 5
#define smallSizeFont 2
2025-01-22 03:57:56 +01:00
#define lineSpacing 25
2025-01-22 03:00:49 +01:00
#endif
2025-01-22 03:57:56 +01:00
uint16_t redColor = 0xc8a2;
2024-05-11 18:02:08 +02:00
#else
2024-11-05 23:14:22 +01:00
#ifdef HAS_EPAPER
2025-02-28 20:48:26 +01:00
#include <heltec-eink-modules.h>
#include "Fonts/FreeSansBold9pt7b.h"
2025-09-02 03:32:28 +02:00
#ifdef HELTEC_WP_V1
EInkDisplay_WirelessPaperV1_1 display;
#endif
2025-09-02 16:17:03 +02:00
/*#ifdef HELTEC_WP_V1_2 // SOON!
EInkDisplay_WirelessPaperV1_2 display;
#endif*/
2025-02-28 20:48:26 +01:00
String lastEpaperText;
2024-07-17 22:20:20 +02:00
#else
2024-08-16 21:52:20 +02:00
#include <Adafruit_GFX.h>
2025-03-03 16:15:50 +01:00
#if defined(TTGO_T_Beam_S3_SUPREME_V3)
#include <Adafruit_SH110X.h>
Adafruit_SH1106G display(128, 64, &Wire, OLED_RST);
2024-08-16 21:52:20 +02:00
#else
2025-03-03 16:15:50 +01:00
#include <Adafruit_SSD1306.h>
#ifdef HELTEC_WSL_V3_DISPLAY
Adafruit_SSD1306 display(128, 64, &Wire1, OLED_RST);
#else
Adafruit_SSD1306 display(128, 64, &Wire, OLED_RST);
#endif
2024-08-16 21:52:20 +02:00
#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
2025-05-18 14:44:46 +02:00
2024-10-25 16:50:57 +02:00
extern Configuration Config;
bool displayFound = false;
2023-06-20 02:17:23 +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);
}
2025-01-22 03:57:56 +01:00
pinMode(TFT_BL, OUTPUT);
digitalWrite(TFT_BL, HIGH);
2024-05-11 18:02:08 +02:00
tft.setTextFont(0);
tft.fillScreen(TFT_BLACK);
2025-01-22 03:57:56 +01:00
#if defined(TTGO_T_DECK_GPS) || defined(TTGO_T_DECK_PLUS)
sprite.createSprite(320,240);
#else
sprite.createSprite(160,80);
#endif
2024-08-16 21:52:20 +02:00
#else
2024-11-05 23:14:22 +01:00
#ifdef HAS_EPAPER
2025-02-28 20:48:26 +01:00
display.landscape();
display.printCenter("LoRa APRS iGate Initialising...");
2025-10-15 22:12:38 +02:00
if (Config.display.turn180) display.setRotation(2);
2025-02-28 20:48:26 +01:00
display.update();
2024-08-16 21:52:20 +02:00
#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
2025-03-03 16:15:50 +01:00
#if defined(TTGO_T_Beam_S3_SUPREME_V3)
2025-11-09 01:13:57 +01:00
if (display.begin(0x3c, false)) {
2025-03-03 16:15:50 +01:00
displayFound = true;
if (Config.display.turn180) display.setRotation(2);
display.clearDisplay();
display.setTextColor(SH110X_WHITE);
display.setTextSize(1);
display.setCursor(0, 0);
display.setContrast(1);
display.display();
}
#else
if(display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
displayFound = true;
if (Config.display.turn180) display.setRotation(2);
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(1);
display.setCursor(0, 0);
display.ssd1306_command(SSD1306_SETCONTRAST);
display.ssd1306_command(1);
display.display();
}
#endif
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-11-05 23:14:22 +01:00
#ifdef HAS_EPAPER
2025-02-28 20:48:26 +01:00
display.printCenter("EPAPER Display Disabled by toggle...");
display.update();
2024-08-16 21:52:20 +02:00
#else
2025-03-03 16:15:50 +01:00
#if defined(TTGO_T_Beam_S3_SUPREME_V3)
if (displayFound) display.oled_command(SH110X_DISPLAYON);
#else
if (displayFound) display.ssd1306_command(SSD1306_DISPLAYON);
#endif
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-11-05 23:14:22 +01:00
#ifdef HAS_EPAPER
2025-02-28 20:48:26 +01:00
display.printCenter("Enabled EPAPER Display...");
display.update();
2024-08-16 21:52:20 +02:00
#else
2025-03-03 16:15:50 +01:00
#if defined(TTGO_T_Beam_S3_SUPREME_V3)
if (displayFound) display.oled_command(SH110X_DISPLAYOFF);
#else
if (displayFound) display.ssd1306_command(SSD1306_DISPLAYOFF);
#endif
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-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
2025-01-22 03:57:56 +01:00
sprite.fillSprite(TFT_BLACK);
#if defined(HELTEC_WIRELESS_TRACKER)
sprite.fillRect(0, 0, 160, 19, redColor);
#endif
#if defined(TTGO_T_DECK_GPS) || defined(TTGO_T_DECK_PLUS)
sprite.fillRect(0, 0, 320, 43, redColor);
#endif
sprite.setTextFont(0);
sprite.setTextSize(bigSizeFont);
sprite.setTextColor(TFT_WHITE, redColor);
sprite.drawString(header, 3, 3);
sprite.setTextSize(smallSizeFont);
sprite.setTextColor(TFT_WHITE, TFT_BLACK);
2024-06-06 05:20:34 +02:00
for (int i = 0; i < 3; i++) {
2025-01-22 03:57:56 +01:00
sprite.drawString(*lines[i], 3, (lineSpacing * (2 + i)) - 2);
2024-06-06 05:20:34 +02:00
}
2025-01-22 03:57:56 +01:00
sprite.pushSprite(0,0);
2024-05-11 18:02:08 +02:00
#else
2024-08-16 21:52:20 +02:00
#ifdef HAS_EPAPER
2025-02-28 20:48:26 +01:00
display.clearMemory();
display.setCursor(5,10);
display.setFont(&FreeSansBold9pt7b);
display.println(header);
display.setFont(NULL);
for (int i = 0; i < 3; i++) {
display.setCursor(0, 25 + (14 * i));
display.println(*lines[i]);
}
display.update();
2024-08-16 21:52:20 +02:00
#else
2024-10-25 16:50:57 +02:00
if (displayFound) {
display.clearDisplay();
2025-03-03 16:15:50 +01:00
#if defined(TTGO_T_Beam_S3_SUPREME_V3)
display.setTextColor(SH110X_WHITE);
#else
display.setTextColor(WHITE);
#endif
2024-10-25 16:50:57 +02:00
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]);
}
2025-03-03 16:15:50 +01:00
#if defined(TTGO_T_Beam_S3_SUPREME_V3)
display.setContrast(1);
#else
display.ssd1306_command(SSD1306_SETCONTRAST);
display.ssd1306_command(1);
#endif
2024-10-25 16:50:57 +02:00
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
2025-01-22 03:57:56 +01:00
sprite.fillSprite(TFT_BLACK);
#if defined(HELTEC_WIRELESS_TRACKER)
sprite.fillRect(0, 0, 160, 19, redColor);
#endif
#if defined(TTGO_T_DECK_GPS) || defined(TTGO_T_DECK_PLUS)
sprite.fillRect(0, 0, 320, 43, redColor);
#endif
sprite.setTextFont(0);
sprite.setTextSize(bigSizeFont);
sprite.setTextColor(TFT_WHITE, redColor);
sprite.drawString(header, 3, 3);
sprite.setTextSize(smallSizeFont);
sprite.setTextColor(TFT_WHITE, TFT_BLACK);
2024-06-06 05:20:34 +02:00
for (int i = 0; i < 6; i++) {
2025-01-22 03:57:56 +01:00
sprite.drawString(*lines[i], 3, (lineSpacing * (2 + i)) - 2);
2024-06-06 05:20:34 +02:00
}
2025-01-22 03:57:56 +01:00
sprite.pushSprite(0,0);
2024-05-11 18:02:08 +02:00
#else
2024-08-16 21:52:20 +02:00
#ifdef HAS_EPAPER
2025-02-28 20:48:26 +01:00
lastEpaperText = header + line1 + line2 + line3 + line4 + line5 + line6;
display.clearMemory();
display.setCursor(5,10);
display.setFont(&FreeSansBold9pt7b);
display.println(header);
display.setFont(NULL);
for (int i = 0; i < 6; i++) {
display.setCursor(0, 25 + (14 * i));
display.println(*lines[i]);
}
display.update();
2024-08-16 21:52:20 +02:00
#else
2024-10-25 16:50:57 +02:00
if (displayFound) {
display.clearDisplay();
2025-03-03 16:15:50 +01:00
#if defined(TTGO_T_Beam_S3_SUPREME_V3)
display.setTextColor(SH110X_WHITE);
#else
display.setTextColor(WHITE);
#endif
2024-10-25 16:50:57 +02:00
display.setTextSize(2);
display.setCursor(0, 0);
display.println(header);
2025-03-03 16:22:22 +01:00
display.setTextSize(1);
2024-10-25 16:50:57 +02:00
for (int i = 0; i < 6; i++) {
display.setCursor(0, 16 + (8 * i));
display.println(*lines[i]);
}
2025-03-03 16:15:50 +01:00
#if defined(TTGO_T_Beam_S3_SUPREME_V3)
display.setContrast(1);
#else
display.ssd1306_command(SSD1306_SETCONTRAST);
display.ssd1306_command(1);
#endif
2024-10-25 16:50:57 +02:00
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
}