19#include <QApplication>
22#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
23#include <QStringConverter>
42#define LOC QString("LCDdevice: ")
45 : m_retryTimer(new QTimer(this)), m_ledTimer(new QTimer(this))
57 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
58 "An LCD object now exists (LCD() was called)");
87 lcd_host =
GetMythDB()->GetSetting(
"LCDServerHost",
"localhost");
88 int lcd_port =
GetMythDB()->GetNumSetting(
"LCDServerPort", 6545);
92 if (lcd_host ==
"localhost")
93 lcd_host =
"127.0.0.1";
95 if (
m_enabled && lcd_host.length() > 0 && lcd_port > 1024)
111 LOG(VB_NETWORK, LOG_DEBUG,
LOC +
112 QString(
"connecting to host: %1 - port: %2")
113 .arg(lhostname).arg(lport));
131 if (
myth_system(
"ps ch -C mythlcdserver -o pid > /dev/null", flags) == 1)
134 LOG(VB_GENERAL, LOG_NOTICE,
"Starting mythlcdserver");
138 LOG(VB_GENERAL, LOG_ERR,
"Failed start MythTV LCD Server");
145 for (
int count = 1; count <= 10 && !
m_connected; count++)
147 LOG(VB_GENERAL, LOG_INFO, QString(
"Connecting to lcd server: "
154 QObject::connect(
m_socket, &QIODevice::readyRead,
156 QObject::connect(
m_socket, &QAbstractSocket::disconnected,
188 if (
m_socket->thread() != QThread::currentThread())
190 LOG(VB_GENERAL, LOG_ERR,
191 "Sending to LCDServer from wrong thread.");
196 if (QAbstractSocket::ConnectedState !=
m_socket->state())
204 LOG(VB_GENERAL, LOG_ERR,
205 "Connection to LCDServer died unexpectedly. "
206 "Trying to reconnect every 10 seconds...");
213#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
214 os.setCodec(QTextCodec::codecForName(
"ISO 8859-1"));
216 os.setEncoding(QStringConverter::Latin1);
223 LOG(VB_NETWORK, LOG_DEBUG,
LOC +
224 QString(
"Sending to Server: %1").arg(someText));
227 os << someText <<
"\n";
256 QString lineFromServer;
265 int dataSize =
static_cast<int>(
m_socket->bytesAvailable() + 1);
266 QByteArray data(dataSize + 1, 0);
268 m_socket->read(data.data(), dataSize);
270 lineFromServer = data;
271 lineFromServer = lineFromServer.simplified();
274 if (lineFromServer !=
"OK")
275 LOG(VB_NETWORK, LOG_DEBUG,
LOC + QString(
"Received from server: %1")
276 .arg(lineFromServer));
278 aList = lineFromServer.split(
' ');
279 if (aList[0] ==
"CONNECTED")
283 if (aList.count() != 3)
285 LOG(VB_GENERAL, LOG_ERR,
LOC +
"received bad no. of arguments in "
286 "CONNECTED response from LCDServer");
293 LOG(VB_GENERAL, LOG_ERR,
LOC +
"received bad int for width in "
294 "CONNECTED response from LCDServer");
300 LOG(VB_GENERAL, LOG_ERR,
LOC +
"received bad int for height in "
301 "CONNECTED response from LCDServer");
306 else if (aList[0] ==
"HUH?")
308 LOG(VB_GENERAL, LOG_WARNING,
LOC +
"Something is getting passed to "
309 "LCDServer that it does not understand");
310 LOG(VB_GENERAL, LOG_WARNING,
LOC +
313 else if (aList[0] ==
"KEY")
323 QChar mykey = keyPressed.at(0);
335 key = Qt::Key_Escape;
337 QCoreApplication::postEvent(
338 (QObject *)(QApplication::activeWindow()),
378 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
"stopAll");
479 emit
sendToServer(QString(
"SET_GENERIC_PROGRESS 0 %1").arg(value));
497 QString().setNum(value));
505 emit
sendToServer(QString(
"SET_MUSIC_PLAYER_PROP SHUFFLE %1").arg(shuffle));
513 emit
sendToServer(QString(
"SET_MUSIC_PLAYER_PROP REPEAT %1").arg(repeat));
523 else if (value > 1.0F)
527 emit
sendToServer(
"SET_VOLUME_LEVEL " + QString().setNum(value));
549 aString =
"UPDATE_LEDS ";
550 aString += QString::number(mask);
560 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
"switchToTime");
570 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
"switchToMusic");
578 const QString &subtitle)
583 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
"switchToChannel");
596 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
"switchToMenu");
598 if (menuItems.isEmpty())
601 QString s =
"SWITCH_TO_MENU ";
604 s +=
' ' + QString(popMenu ?
"TRUE" :
"FALSE");
607 QListIterator<LCDMenuItem> it(menuItems);
619 s +=
" NOTCHECKABLE";
621 s +=
' ' + QString(curItem->
isSelected() ?
"TRUE" :
"FALSE");
622 s +=
' ' + QString(curItem->
Scroll() ?
"TRUE" :
"FALSE");
636 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
"switchToGeneric");
638 if (textItems.isEmpty())
641 QString s =
"SWITCH_TO_GENERIC";
643 QListIterator<LCDTextItem> it(textItems);
650 sRow.setNum(curItem->
getRow());
658 s +=
" ALIGN_CENTERED";
662 s +=
' ' + QString(curItem->
getScroll() ?
"TRUE" :
"FALSE");
673 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
"switchToVolume");
683 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
"switchToNothing");
692 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
"shutdown");
708 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
"RESET");
717 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
"An LCD device is being snuffed out of "
718 "existence (~LCD() was called)");
730 QString sRes = string;
731 sRes.replace(QString(
"\""), QString(
"\"\""));
732 sRes =
"\"" + sRes +
"\"";
QString getScreen() const
TEXT_ALIGNMENT getAlignment() const
unsigned int getRow() const
void setAudioFormatLEDs(enum LCDAudioFormatSet acodec, bool on)
void setVideoSrcLEDs(enum LCDVideoSourceSet vsrc, bool on)
void setVolumeLevel(float value)
void setupLEDs(int(*LedMaskFunc)(void))
void sendToServer(const QString &someText)
void setFunctionLEDs(enum LCDFunctionSet func, bool on)
static void SetupLCD(void)
QString m_lcdShowMusicItems
bool connectToHost(const QString &hostname, unsigned int port)
void setGenericProgress(float value)
Update the generic progress bar.
static bool m_serverUnavailable
QRecursiveMutex m_socketLock
void setSpeakerLEDs(enum LCDSpeakerSet speaker, bool on)
void setGenericBusy()
Update the generic screen to display a busy spinner.
static QString quotedString(const QString &string)
void setMusicRepeat(int repeat)
Set music player's repeat properties.
int(* m_getLEDMask)(void)
void switchToMusic(const QString &artist, const QString &album, const QString &track)
void setTunerLEDs(enum LCDTunerSet tuner, bool on)
void setMusicProgress(const QString &time, float value)
void setMusicShuffle(int shuffle)
Set music player's shuffle properties.
void setVariousLEDs(enum LCDVariousFlags various, bool on)
void setVideoFormatLEDs(enum LCDVideoFormatSet vcodec, bool on)
void switchToMenu(QList< LCDMenuItem > &menuItems, const QString &app_name="", bool popMenu=true)
void switchToVolume(const QString &app_name)
static bool startLCDServer(void)
void sendToServerSlot(const QString &someText)
void switchToChannel(const QString &channum="", const QString &title="", const QString &subtitle="")
void switchToGeneric(QList< LCDTextItem > &textItems)
void handleKeyPress(const QString &keyPressed)
void setChannelProgress(const QString &time, float value)
@ GENERIC_EXIT_RUNNING
Process is running.
QString GetAppBinDir(void)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
@ kMSDontBlockInputDevs
avoid blocking LIRC & Joystick Menu
@ kMSRunShell
run process through shell
@ kMSRunBackground
run child in the background
@ kMSDontDisableDrawing
avoid disabling UI drawing
uint myth_system(const QString &command, uint flags, std::chrono::seconds timeout)
static eu8 clamp(eu8 value, eu8 low, eu8 high)