Skip to content

Commit 464d0fd

Browse files
committed
Move display creation from main class to static CDisplay::create()
1 parent 9cb7790 commit 464d0fd

File tree

4 files changed

+180
-169
lines changed

4 files changed

+180
-169
lines changed

Display.cpp

+173
Original file line numberDiff line numberDiff line change
@@ -430,3 +430,176 @@ void CDisplay::writeNXDNRSSIInt(unsigned char rssi)
430430
void CDisplay::writeNXDNBERInt(float ber)
431431
{
432432
}
433+
434+
/* Factory method extracted from MMDVMHost.cpp - BG5HHP */
435+
#include "SerialController.h"
436+
#include "ModemSerialPort.h"
437+
#include "TFTSerial.h"
438+
#include "LCDproc.h"
439+
#include "Nextion.h"
440+
#include "NullDisplay.h"
441+
442+
#include "Conf.h"
443+
#include "Modem.h"
444+
#include "UMP.h"
445+
446+
#if defined(HD44780)
447+
#include "HD44780.h"
448+
#endif
449+
450+
#if defined(OLED)
451+
#include "OLED.h"
452+
#endif
453+
454+
CDisplay* CDisplay::createDisplay(const CConf &conf, CUMP *ump, CModem *modem){
455+
CDisplay *display = NULL;
456+
457+
std::string type = conf.getDisplay();
458+
unsigned int dmrid = conf.getDMRId();
459+
460+
LogInfo("Display Parameters");
461+
LogInfo(" Type: %s", type.c_str());
462+
463+
if (type == "TFT Serial") {
464+
std::string port = conf.getTFTSerialPort();
465+
unsigned int brightness = conf.getTFTSerialBrightness();
466+
467+
LogInfo(" Port: %s", port.c_str());
468+
LogInfo(" Brightness: %u", brightness);
469+
470+
ISerialPort* serial = NULL;
471+
if (port == "modem")
472+
serial = new CModemSerialPort(modem);
473+
else
474+
serial = new CSerialController(port, SERIAL_9600);
475+
476+
display = new CTFTSerial(conf.getCallsign(), dmrid, serial, brightness);
477+
} else if (type == "Nextion") {
478+
std::string port = conf.getNextionPort();
479+
unsigned int brightness = conf.getNextionBrightness();
480+
bool displayClock = conf.getNextionDisplayClock();
481+
bool utc = conf.getNextionUTC();
482+
unsigned int idleBrightness = conf.getNextionIdleBrightness();
483+
unsigned int screenLayout = conf.getNextionScreenLayout();
484+
485+
LogInfo(" Port: %s", port.c_str());
486+
LogInfo(" Brightness: %u", brightness);
487+
LogInfo(" Clock Display: %s", displayClock ? "yes" : "no");
488+
if (displayClock)
489+
LogInfo(" Display UTC: %s", utc ? "yes" : "no");
490+
LogInfo(" Idle Brightness: %u", idleBrightness);
491+
492+
switch (screenLayout) {
493+
case 0U:
494+
LogInfo(" Screen Layout: G4KLX (Default)");
495+
break;
496+
case 2U:
497+
LogInfo(" Screen Layout: ON7LDS");
498+
break;
499+
case 3U:
500+
LogInfo(" Screen Layout: DIY by ON7LDS");
501+
break;
502+
case 4U:
503+
LogInfo(" Screen Layout: DIY by ON7LDS (High speed)");
504+
break;
505+
default:
506+
LogInfo(" Screen Layout: %u (Unknown)", screenLayout);
507+
break;
508+
}
509+
510+
if (port == "modem") {
511+
ISerialPort* serial = new CModemSerialPort(modem);
512+
display = new CNextion(conf.getCallsign(), dmrid, serial, brightness, displayClock, utc, idleBrightness, screenLayout);
513+
} else if (port == "ump") {
514+
if (ump != NULL)
515+
display = new CNextion(conf.getCallsign(), dmrid, ump, brightness, displayClock, utc, idleBrightness, screenLayout);
516+
else
517+
display = new CNullDisplay;
518+
} else {
519+
SERIAL_SPEED baudrate = SERIAL_9600;
520+
if (screenLayout==4U)
521+
baudrate = SERIAL_115200;
522+
ISerialPort* serial = new CSerialController(port, baudrate);
523+
display = new CNextion(conf.getCallsign(), dmrid, serial, brightness, displayClock, utc, idleBrightness, screenLayout);
524+
}
525+
} else if (type == "LCDproc") {
526+
std::string address = conf.getLCDprocAddress();
527+
unsigned int port = conf.getLCDprocPort();
528+
unsigned int localPort = conf.getLCDprocLocalPort();
529+
bool displayClock = conf.getLCDprocDisplayClock();
530+
bool utc = conf.getLCDprocUTC();
531+
bool dimOnIdle = conf.getLCDprocDimOnIdle();
532+
533+
LogInfo(" Address: %s", address.c_str());
534+
LogInfo(" Port: %u", port);
535+
536+
if (localPort == 0 )
537+
LogInfo(" Local Port: random");
538+
else
539+
LogInfo(" Local Port: %u", localPort);
540+
541+
LogInfo(" Dim Display on Idle: %s", dimOnIdle ? "yes" : "no");
542+
LogInfo(" Clock Display: %s", displayClock ? "yes" : "no");
543+
544+
if (displayClock)
545+
LogInfo(" Display UTC: %s", utc ? "yes" : "no");
546+
547+
display = new CLCDproc(address.c_str(), port, localPort, conf.getCallsign(), dmrid, displayClock, utc, conf.getDuplex(), dimOnIdle);
548+
#if defined(HD44780)
549+
} else if (type == "HD44780") {
550+
unsigned int rows = conf.getHD44780Rows();
551+
unsigned int columns = conf.getHD44780Columns();
552+
std::vector<unsigned int> pins = conf.getHD44780Pins();
553+
unsigned int i2cAddress = conf.getHD44780i2cAddress();
554+
bool pwm = conf.getHD44780PWM();
555+
unsigned int pwmPin = conf.getHD44780PWMPin();
556+
unsigned int pwmBright = conf.getHD44780PWMBright();
557+
unsigned int pwmDim = conf.getHD44780PWMDim();
558+
bool displayClock = conf.getHD44780DisplayClock();
559+
bool utc = conf.getHD44780UTC();
560+
561+
if (pins.size() == 6U) {
562+
LogInfo(" Rows: %u", rows);
563+
LogInfo(" Columns: %u", columns);
564+
565+
#if defined(ADAFRUIT_DISPLAY) || defined(PCF8574_DISPLAY)
566+
LogInfo(" Device Address: %#x", i2cAddress);
567+
#else
568+
LogInfo(" Pins: %u,%u,%u,%u,%u,%u", pins.at(0U), pins.at(1U), pins.at(2U), pins.at(3U), pins.at(4U), pins.at(5U));
569+
#endif
570+
571+
LogInfo(" PWM Backlight: %s", pwm ? "yes" : "no");
572+
if (pwm) {
573+
LogInfo(" PWM Pin: %u", pwmPin);
574+
LogInfo(" PWM Bright: %u", pwmBright);
575+
LogInfo(" PWM Dim: %u", pwmDim);
576+
}
577+
578+
LogInfo(" Clock Display: %s", displayClock ? "yes" : "no");
579+
if (displayClock)
580+
LogInfo(" Display UTC: %s", utc ? "yes" : "no");
581+
582+
m_display = new CHD44780(rows, columns, conf.getCallsign(), dmrid, pins, i2cAddress, pwm, pwmPin, pwmBright, pwmDim, displayClock, utc, conf.getDuplex());
583+
}
584+
#endif
585+
586+
#if defined(OLED)
587+
} else if (type == "OLED") {
588+
unsigned char type = conf.getOLEDType();
589+
unsigned char brightness = conf.getOLEDBrightness();
590+
bool invert = conf.getOLEDInvert();
591+
bool scroll = conf.getOLEDScroll();
592+
display = new COLED(type, brightness, invert, scroll, conf.getDMRNetworkSlot1(), conf.getDMRNetworkSlot2());
593+
#endif
594+
} else {
595+
LogWarning("No valid display found, disabling");
596+
display = new CNullDisplay;
597+
}
598+
599+
bool ret = display->open();
600+
if (!ret) {
601+
delete display;
602+
display = new CNullDisplay;
603+
}
604+
return display;
605+
}

Display.h

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525

2626
#include <cstdint>
2727

28+
class CConf;
29+
class CModem;
30+
class CUMP;
31+
2832
class CDisplay
2933
{
3034
public:
@@ -72,6 +76,8 @@ class CDisplay
7276

7377
void clock(unsigned int ms);
7478

79+
static CDisplay* createDisplay(const CConf &conf, CUMP *ump, CModem *modem);
80+
7581
protected:
7682
virtual void setIdleInt() = 0;
7783
virtual void setLockoutInt() = 0;

0 commit comments

Comments
 (0)