18 #include <QApplication> 20 #include <QTextStream> 38 #define LOC QString("LCDdevice: ") 42 m_socket(nullptr), m_socketLock(QMutex::Recursive),
43 m_hostname(
"localhost"), m_port(6545),
46 m_retryTimer(new QTimer(this)), m_LEDTimer(new QTimer(this)),
48 m_lcdWidth(0), m_lcdHeight(0),
52 m_lcdShowMusic(
false), m_lcdShowChannel(
false),
53 m_lcdShowVolume(
false), m_lcdShowRecStatus(
false),
54 m_lcdBacklightOn(
false), m_lcdHeartbeatOn(
false),
58 m_lcdShowMusicItems(),
74 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
75 "An LCD object now exists (LCD() was called)");
110 if (lcd_host ==
"localhost")
111 lcd_host =
"127.0.0.1";
113 if (
m_enabled && lcd_host.length() > 0 && lcd_port > 1024)
129 LOG(VB_NETWORK, LOG_DEBUG,
LOC +
130 QString(
"connecting to host: %1 - port: %2")
131 .arg(lhostname).arg(lport));
148 if (
myth_system(
"ps ch -C mythlcdserver -o pid > /dev/null", flags) == 1)
151 LOG(VB_GENERAL, LOG_NOTICE,
"Starting mythlcdserver");
155 LOG(VB_GENERAL, LOG_ERR,
"Failed start MythTV LCD Server");
169 LOG(VB_GENERAL, LOG_INFO, QString(
"Connecting to lcd server: " 178 QObject::connect(
m_socket, SIGNAL(readyRead()),
180 QObject::connect(
m_socket, SIGNAL(disconnected()),
214 if (
m_socket->thread() != QThread::currentThread())
216 LOG(VB_GENERAL, LOG_ERR,
217 "Sending to LCDServer from wrong thread.");
222 if (QAbstractSocket::ConnectedState !=
m_socket->state())
230 LOG(VB_GENERAL, LOG_ERR,
231 "Connection to LCDServer died unexpectedly. " 232 "Trying to reconnect every 10 seconds...");
239 os.setCodec(QTextCodec::codecForName(
"ISO 8859-1"));
245 LOG(VB_NETWORK, LOG_DEBUG,
LOC +
246 QString(
"Sending to Server: %1").arg(someText));
249 os << someText <<
"\n";
278 QString lineFromServer;
280 QStringList::Iterator it;
288 int dataSize =
m_socket->bytesAvailable() + 1;
289 QByteArray data(dataSize + 1, 0);
291 m_socket->read(data.data(), dataSize);
293 lineFromServer = data;
294 lineFromServer = lineFromServer.replace( QRegExp(
"\n"),
" " );
295 lineFromServer = lineFromServer.replace( QRegExp(
"\r"),
" " );
296 lineFromServer = lineFromServer.simplified();
299 if (lineFromServer !=
"OK")
300 LOG(VB_NETWORK, LOG_DEBUG,
LOC + QString(
"Received from server: %1")
301 .arg(lineFromServer));
303 aList = lineFromServer.split(
' ');
304 if (aList[0] ==
"CONNECTED")
308 if (aList.count() != 3)
310 LOG(VB_GENERAL, LOG_ERR,
LOC +
"received bad no. of arguments in " 311 "CONNECTED response from LCDServer");
318 LOG(VB_GENERAL, LOG_ERR,
LOC +
"received bad int for width in " 319 "CONNECTED response from LCDServer");
325 LOG(VB_GENERAL, LOG_ERR,
LOC +
"received bad int for height in " 326 "CONNECTED response from LCDServer");
331 else if (aList[0] ==
"HUH?")
333 LOG(VB_GENERAL, LOG_WARNING,
LOC +
"Something is getting passed to " 334 "LCDServer that it does not understand");
335 LOG(VB_GENERAL, LOG_WARNING,
LOC +
338 else if (aList[0] ==
"KEY")
346 QChar mykey = keyPressed.at(0);
358 key = Qt::Key_Escape;
360 QCoreApplication::postEvent(
361 (QObject *)(QApplication::activeWindow()),
401 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
"stopAll");
491 value = std::min(std::max(0.0f, value), 1.0f);
501 value = std::min(std::max(0.0f, value), 1.0f);
502 sendToServer(QString(
"SET_GENERIC_PROGRESS 0 %1").arg(value));
518 value = std::min(std::max(0.0f, value), 1.0f);
520 QString().setNum(value));
528 sendToServer(QString(
"SET_MUSIC_PLAYER_PROP SHUFFLE %1").arg(shuffle));
536 sendToServer(QString(
"SET_MUSIC_PLAYER_PROP REPEAT %1").arg(repeat));
546 else if (value > 1.0f)
549 sendToServer(
"SET_VOLUME_LEVEL " + QString().setNum(value));
572 aString =
"UPDATE_LEDS ";
573 aString += QString::number(mask);
583 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
"switchToTime");
593 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
"switchToMusic");
601 const QString &subtitle)
606 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
"switchToChannel");
619 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
"switchToMenu");
621 if (menuItems.isEmpty())
624 QString s =
"SWITCH_TO_MENU ";
627 s +=
' ' + QString(popMenu ?
"TRUE" :
"FALSE");
630 QListIterator<LCDMenuItem> it(menuItems);
642 s +=
" NOTCHECKABLE";
644 s +=
' ' + QString(curItem->
isSelected() ?
"TRUE" :
"FALSE");
645 s +=
' ' + QString(curItem->
Scroll() ?
"TRUE" :
"FALSE");
659 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
"switchToGeneric");
661 if (textItems.isEmpty())
664 QString s =
"SWITCH_TO_GENERIC";
666 QListIterator<LCDTextItem> it(textItems);
673 sRow.setNum(curItem->
getRow());
681 s +=
" ALIGN_CENTERED";
685 s +=
' ' + QString(curItem->
getScroll() ?
"TRUE" :
"FALSE");
696 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
"switchToVolume");
706 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
"switchToNothing");
715 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
"shutdown");
731 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
"RESET");
740 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
"An LCD device is being snuffed out of " 741 "existence (~LCD() was called)");
753 QString sRes = string;
754 sRes.replace(QRegExp(
"\""), QString(
"\"\""));
755 sRes =
"\"" + sRes +
"\"";
void setAudioFormatLEDs(enum LCDAudioFormatSet acodec, bool on)
avoid disabling UI drawing
void sendToServerSlot(const QString &someText)
void switchToChannel(const QString &channum="", const QString &title="", const QString &subtitle="")
void setGenericProgress(float generic_progress)
Update the generic progress bar.
void setTunerLEDs(enum LCDTunerSet tuner, bool on)
void setFunctionLEDs(enum LCDFunctionSet video, bool on)
void switchToGeneric(QList< LCDTextItem > &textItems)
run child in the background
static void SetupLCD(void)
void sendToServer(const QString &someText)
void setMusicShuffle(int shuffle)
Set music player's shuffle properties.
void switchToMenu(QList< LCDMenuItem > &menuItems, const QString &app_name="", bool popMenu=true)
int GetNumSetting(const QString &key, int defaultval)
void handleKeyPress(const QString &keyPressed)
QString getScreen() const
void setChannelProgress(const QString &time, float percentViewed)
QString GetAppBinDir(void)
run process through shell
void setVideoFormatLEDs(enum LCDVideoFormatSet vcodec, bool on)
bool GetBoolSetting(const QString &key, bool defaultval)
static bool m_serverUnavailable
#define GENERIC_EXIT_RUNNING
Process is running.
QString m_lcdShowMusicItems
uint myth_system(const QString &command, uint flags, uint timeout)
void setVariousLEDs(enum LCDVariousFlags various, bool on)
QString GetSetting(const QString &_key, const QString &defaultval)
void switchToVolume(const QString &app_name)
#define LOG(_MASK_, _LEVEL_, _STRING_)
unsigned int getRow() const
TEXT_ALIGNMENT getAlignment() const
bool startLCDServer(void)
void setMusicRepeat(int repeat)
Set music player's repeat properties.
void setupLEDs(int(*LedMaskFunc)(void))
void setSpeakerLEDs(enum LCDSpeakerSet speaker, bool on)
void setVideoSrcLEDs(enum LCDVideoSourceSet vsrc, bool on)
void switchToMusic(const QString &artist, const QString &album, const QString &track)
void setVolumeLevel(float volume_level)
QString quotedString(const QString &string)
bool connectToHost(const QString &hostname, unsigned int port)
void setMusicProgress(const QString &time, float generic_progress)
avoid blocking LIRC & Joystick Menu
void setGenericBusy()
Update the generic screen to display a busy spinner.