MythTV  master
lcddevice.h
Go to the documentation of this file.
1 #ifndef LCDDEVICE_H_
2 #define LCDDEVICE_H_
3 
4 #include <utility>
5 
6 // Qt headers
7 #include <QList>
8 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
9 #include <QMutex>
10 #else
11 #include <QRecursiveMutex>
12 #endif
13 #include <QObject>
14 #include <QStringList>
15 
16 class QTimer;
17 
18 // MythTV headers
19 #include "mythbaseexp.h"
20 
22 
23 class QTcpSocket;
24 
26 {
27  public:
28  LCDMenuItem(bool item_selected, CHECKED_STATE item_checked,
29  QString item_name, unsigned int item_indent = 0,
30  bool item_scroll = false) :
31  m_selected(item_selected), m_checked(item_checked),
32  m_name(std::move(item_name)), m_scroll(item_scroll),
33  m_indent(item_indent), m_scrollPosition(item_indent)
34  {
35  }
36 
37  CHECKED_STATE isChecked() const { return m_checked; }
38  bool isSelected() const { return m_selected; }
39  QString ItemName() const { return m_name; }
40  bool Scroll() const { return m_scroll; }
41  unsigned int getIndent() const { return m_indent; }
42  unsigned int getScrollPos() const { return m_scrollPosition; }
43 
44  void setChecked(CHECKED_STATE value) { m_checked = value; }
45  void setSelected(bool value) { m_selected = value; }
46  void setItemName(const QString& value) { m_name = value; }
47  void setScroll(bool value) { m_scroll = value; }
48  void setIndent(unsigned int value) { m_indent = value; }
49  void setScrollPos(unsigned int value) { m_scrollPosition = value; }
50  void incrementScrollPos() { ++m_scrollPosition; }
51 
52  private:
53  bool m_selected;
55  QString m_name;
56  bool m_scroll {false};
57  unsigned int m_indent {0};
58  unsigned int m_scrollPosition {0};
59 };
60 
62 
64 {
65  public:
66  LCDTextItem(unsigned int row, TEXT_ALIGNMENT align, QString text,
67  QString screen = "Generic", bool scroll = false,
68  QString widget = "textWidget") :
69  m_itemRow(row), m_itemAlignment(align),
70  m_itemText(std::move(text)), m_itemScreen(std::move(screen)),
71  m_itemWidget(std::move(widget)), m_itemScrollable(scroll)
72  {
73  }
74 
75  unsigned int getRow() const { return m_itemRow; }
76  TEXT_ALIGNMENT getAlignment() const { return m_itemAlignment; }
77  QString getText() const { return m_itemText; }
78  QString getScreen() const { return m_itemScreen; }
79  QString getWidget() const { return m_itemWidget; }
80  bool getScroll() const { return m_itemScrollable; }
81 
82  void setRow(unsigned int value) { m_itemRow = value; }
83  void setAlignment(TEXT_ALIGNMENT value) { m_itemAlignment = value; }
84  void setText(const QString &value) { m_itemText = value; }
85  void setScreen(const QString &value) { m_itemScreen = value; }
86  void setWidget(const QString &value) { m_itemWidget = value; }
87  void setScrollable(bool value) { m_itemScrollable = value; }
88 
89  private:
90  unsigned int m_itemRow;
92  QString m_itemText;
93  QString m_itemScreen {"Generic"};
94  QString m_itemWidget {"textWidget"};
95  bool m_itemScrollable {false};
96 };
97 
98 //only one active at a time
100  SPEAKER_MASK = 0x00000030,
101  SPEAKER_LR = 1 << 4,
102  SPEAKER_51 = 2 << 4,
103  SPEAKER_71 = 3 << 4,
104 };
105 
106 //only one active at a time
108  AUDIO_MASK = 0x0000E000 | 0x00070000,
109 
110  AUDIO_MP3 = 1 << 13,
111  AUDIO_OGG = 2 << 13,
112  AUDIO_WMA2 = 3 << 13,
113  AUDIO_WAV = 4 << 13,
114 
115  AUDIO_MPEG2 = 1 << 16,
116  AUDIO_AC3 = 2 << 16,
117  AUDIO_DTS = 3 << 16,
118  AUDIO_WMA = 4 << 16,
119 };
120 
121 //only one active at a time
123  VIDEO_MASK = 0x00380000,
124  VIDEO_MPG = 1 << 19,
125  VIDEO_DIVX = 2 << 19,
126  VIDEO_XVID = 3 << 19,
127  VIDEO_WMV = 4 << 19,
128 };
129 
130 //only one active at a time
132  TUNER_MASK = 0x00000080 | 0x00000800 | 0x00001000,
133  TUNER_SRC = 0x00000080,
134  TUNER_SRC1 = 0x00000800,
135  TUNER_SRC2 = 0x00001000,
136 };
137 
138 //only one active at a time
140  VSRC_MASK = 0x00000100 | 0x00000200,
141  VSRC_FIT = 0x00000100,
142  VSRC_TV = 0x00000200,
143 };
144 
145 //can be enabled/disabled separately
147  VARIOUS_VOL = 0x00400000,
148  VARIOUS_TIME = 0x00800000,
149  VARIOUS_ALARM = 0x01000000,
150  VARIOUS_RECORD = 0x02000000,
151  VARIOUS_REPEAT = 0x04000000,
152  VARIOUS_SHUFFLE = 0x08000000,
153  VARIOUS_DISC_IN = 0x20000000,
154  VARIOUS_HDTV = 0x00000400,
155  VARIOUS_SPDIF = 0x1 << 9,
156  SPDIF_MASK = 0x00000040,
157 };
158 
159 
160 //only one active at a time
162  //0=none, 1=music, 2=movie, 3=photo, 4=CD/DVD, 5=TV, 6=Web, 7=News/Weather * 2
163  FUNC_MASK = 0xE,
164  FUNC_MUSIC = 1 << 1,
165  FUNC_MOVIE = 2 << 1,
166  FUNC_PHOTO = 3 << 1,
167  FUNC_DVD = 4 << 1,
168  FUNC_TV = 5 << 1,
169  FUNC_WEB = 6 << 1,
170  FUNC_NEWS = 7 << 1,
171 };
172 
173 class MBASE_PUBLIC LCD : public QObject
174 {
175  Q_OBJECT
176  friend class TestLcdDevice;
177 
178  protected:
179  LCD();
180 
181  static bool m_serverUnavailable;
182  static LCD *m_lcd;
183  static bool m_enabled;
184 
185  public:
186  ~LCD() override;
187 
188  enum {
189  MUSIC_REPEAT_NONE = 0,
190  MUSIC_REPEAT_TRACK = 1,
191  MUSIC_REPEAT_ALL = 2,
192  };
193 
194  enum {
195  MUSIC_SHUFFLE_NONE = 0,
196  MUSIC_SHUFFLE_RAND = 1,
197  MUSIC_SHUFFLE_SMART = 2,
198  MUSIC_SHUFFLE_ALBUM = 3,
199  MUSIC_SHUFFLE_ARTIST = 4
200  };
201 
202  static LCD *Get(void);
203  static void SetupLCD (void);
204 
205  // Used to actually connect to an LCD device
206  bool connectToHost(const QString &hostname, unsigned int port);
207 
208  // When nothing else is going on, show the time
209  void switchToTime();
210 
211  // Extended functionality for eg SoundGraph iMON LCD devices
212  void setSpeakerLEDs(enum LCDSpeakerSet speaker, bool on);
213  void setAudioFormatLEDs(enum LCDAudioFormatSet acodec, bool on);
214  void setVideoFormatLEDs(enum LCDVideoFormatSet vcodec, bool on);
215  void setVideoSrcLEDs(enum LCDVideoSourceSet vsrc, bool on);
216  void setFunctionLEDs(enum LCDFunctionSet func, bool on);
217  void setTunerLEDs(enum LCDTunerSet tuner, bool on);
218  void setVariousLEDs(enum LCDVariousFlags various, bool on);
219 
220  // When playing music, switch to this and give artist and track name
221  //
222  // Note: the use of switchToMusic is discouraged, because it
223  // has become obvious that most LCD devices cannot handle communications
224  // fast enough to make them useful.
225  void switchToMusic(const QString &artist, const QString &album,
226  const QString &track);
227 
228  // For Live TV, supply the channel number, program title and subtitle
229  //
230  // Note that the "channel" screen can be used for any kind of progress meter
231  // just put whatever you want in the strings, and update the progress as
232  // appropriate;
233  void switchToChannel(const QString &channum = "", const QString &title = "",
234  const QString &subtitle = "");
235 
236  // While watching Live/Recording/Pause Buffer, occasionaly describe how
237  // much of the program has been seen (between 0.0 and 1.0)
238  // (e.g. [current time - start time] / [end time - start time] )
239  void setChannelProgress(const QString &time, float value);
240 
241  // Show the Menu
242  // QPtrList is a pointer to a bunch of menu items
243  // See mythmusic/databasebox.cpp for an example
244  void switchToMenu(QList<LCDMenuItem> &menuItems,
245  const QString &app_name = "",
246  bool popMenu = true);
247 
248  // Show the Generic Progress
249  // QPtrList contains pointers to LCDTextItem objects which allow you to
250  // define the screen, row, and alignment of the text
251  void switchToGeneric(QList<LCDTextItem> &textItems);
252 
256  void setGenericProgress(float value);
257 
262  void setGenericBusy();
263 
264  // Do a music progress bar with the generic level between 0 and 1.0
265  void setMusicProgress(const QString &time, float value);
266 
270  void setMusicRepeat(int repeat);
271 
275  void setMusicShuffle(int shuffle);
276 
277  // Show the Volume Level top_text scrolls
278  void switchToVolume(const QString &app_name);
279 
280  // Do a progress bar with the volume level between 0 and 1.0
281  void setVolumeLevel(float value);
282 
283  // If some other process should be getting all the LCDd screen time (e.g.
284  // mythMusic) we can use this to try and prevent and screens from showing
285  // up without having to actual destroy the LCD object
286  void switchToNothing();
287 
288  // If you want to be pleasant, call shutdown() before deleting your LCD
289  // device
290  void shutdown();
291 
292  void setupLEDs(int(*LedMaskFunc)(void));
293 
294  void stopAll(void);
295 
296  int getLCDHeight(void) const { return m_lcdHeight; }
297  int getLCDWidth(void) const { return m_lcdWidth; }
298 
299  void resetServer(void); // tell the mythlcdserver to reload its settings
300 
301  private slots:
302  void restartConnection(); // Try to re-establish the connection to
303  // LCDServer every 10 seconds
304  void outputLEDs();
305  void sendToServerSlot(const QString &someText);
306 
307 signals:
308  void sendToServer(const QString &someText);
309 
310  private:
311  static bool startLCDServer(void);
312  void init();
313  void handleKeyPress(const QString &keyPressed);
314  static QString quotedString(const QString &string);
315  void describeServer();
316 
317  private slots:
318  void ReadyRead(void);
319  void Disconnected(void);
320 
321  private:
322  QTcpSocket *m_socket {nullptr};
323 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
324  QMutex m_socketLock {QMutex::Recursive};
325 #else
326  QRecursiveMutex m_socketLock;
327 #endif
328  QString m_hostname {"localhost"};
329  uint m_port {6545};
330  bool m_connected {false};
331 
332  QTimer *m_retryTimer {nullptr};
333  QTimer *m_ledTimer {nullptr};
334 
335  QString m_sendBuffer;
336  QString m_lastCommand;
337 
338  int m_lcdWidth {0};
339  int m_lcdHeight {0};
340 
341  bool m_lcdReady {false};
342 
343  bool m_lcdShowTime {false};
344  bool m_lcdShowMenu {false};
345  bool m_lcdShowGeneric {false};
346  bool m_lcdShowMusic {false};
347  bool m_lcdShowChannel {false};
348  bool m_lcdShowVolume {false};
349  bool m_lcdShowRecStatus {false};
350  bool m_lcdBacklightOn {false};
351  bool m_lcdHeartbeatOn {false};
352  int m_lcdPopupTime {0};
354  QString m_lcdKeyString;
355 
356  int m_lcdLedMask {0};
357 
358  int (*m_getLEDMask)(void) {nullptr};
359 };
360 
361 #endif
FUNC_MUSIC
@ FUNC_MUSIC
Definition: lcddevice.h:164
LCDTextItem::getScroll
bool getScroll() const
Definition: lcddevice.h:80
TUNER_MASK
@ TUNER_MASK
Definition: lcddevice.h:132
LCDTextItem::m_itemAlignment
TEXT_ALIGNMENT m_itemAlignment
Definition: lcddevice.h:91
LCDMenuItem::m_name
QString m_name
Definition: lcddevice.h:55
FUNC_TV
@ FUNC_TV
Definition: lcddevice.h:168
VARIOUS_TIME
@ VARIOUS_TIME
Definition: lcddevice.h:148
VIDEO_WMV
@ VIDEO_WMV
Definition: lcddevice.h:127
LCD::getLCDHeight
int getLCDHeight(void) const
Definition: lcddevice.h:296
LCDFunctionSet
LCDFunctionSet
Definition: lcddevice.h:161
LCDTextItem::LCDTextItem
LCDTextItem(unsigned int row, TEXT_ALIGNMENT align, QString text, QString screen="Generic", bool scroll=false, QString widget="textWidget")
Definition: lcddevice.h:66
LCDSpeakerSet
LCDSpeakerSet
Definition: lcddevice.h:99
LCDMenuItem::getScrollPos
unsigned int getScrollPos() const
Definition: lcddevice.h:42
LCDTunerSet
LCDTunerSet
Definition: lcddevice.h:131
LCDMenuItem::incrementScrollPos
void incrementScrollPos()
Definition: lcddevice.h:50
LCDTextItem::getText
QString getText() const
Definition: lcddevice.h:77
TUNER_SRC1
@ TUNER_SRC1
Definition: lcddevice.h:134
LCDVariousFlags
LCDVariousFlags
Definition: lcddevice.h:146
VARIOUS_DISC_IN
@ VARIOUS_DISC_IN
Definition: lcddevice.h:153
FUNC_WEB
@ FUNC_WEB
Definition: lcddevice.h:169
LCD::m_lastCommand
QString m_lastCommand
Definition: lcddevice.h:336
mythbaseexp.h
LCDMenuItem::setChecked
void setChecked(CHECKED_STATE value)
Definition: lcddevice.h:44
VARIOUS_RECORD
@ VARIOUS_RECORD
Definition: lcddevice.h:150
SPEAKER_71
@ SPEAKER_71
Definition: lcddevice.h:103
SPEAKER_LR
@ SPEAKER_LR
Definition: lcddevice.h:101
FUNC_PHOTO
@ FUNC_PHOTO
Definition: lcddevice.h:166
FUNC_NEWS
@ FUNC_NEWS
Definition: lcddevice.h:170
LCD::m_enabled
static bool m_enabled
Definition: lcddevice.h:183
VIDEO_XVID
@ VIDEO_XVID
Definition: lcddevice.h:126
VSRC_FIT
@ VSRC_FIT
Definition: lcddevice.h:141
AUDIO_WMA2
@ AUDIO_WMA2
Definition: lcddevice.h:112
SPEAKER_MASK
@ SPEAKER_MASK
Definition: lcddevice.h:100
UNCHECKED
@ UNCHECKED
Definition: lcddevice.h:21
LCDMenuItem::setScrollPos
void setScrollPos(unsigned int value)
Definition: lcddevice.h:49
LCD::m_lcdKeyString
QString m_lcdKeyString
Definition: lcddevice.h:354
LCDAudioFormatSet
LCDAudioFormatSet
Definition: lcddevice.h:107
AUDIO_MPEG2
@ AUDIO_MPEG2
Definition: lcddevice.h:115
SPEAKER_51
@ SPEAKER_51
Definition: lcddevice.h:102
LCDTextItem::setAlignment
void setAlignment(TEXT_ALIGNMENT value)
Definition: lcddevice.h:83
LCDMenuItem::m_selected
bool m_selected
Definition: lcddevice.h:53
FUNC_MOVIE
@ FUNC_MOVIE
Definition: lcddevice.h:165
LCD::getLCDWidth
int getLCDWidth(void) const
Definition: lcddevice.h:297
MBASE_PUBLIC
#define MBASE_PUBLIC
Definition: mythbaseexp.h:15
LCD::m_socketLock
QRecursiveMutex m_socketLock
Definition: lcddevice.h:326
AUDIO_AC3
@ AUDIO_AC3
Definition: lcddevice.h:116
LCDTextItem::m_itemText
QString m_itemText
Definition: lcddevice.h:92
LCDMenuItem::isChecked
CHECKED_STATE isChecked() const
Definition: lcddevice.h:37
LCDMenuItem::setScroll
void setScroll(bool value)
Definition: lcddevice.h:47
LCD::m_lcd
static LCD * m_lcd
Definition: lcddevice.h:182
VSRC_MASK
@ VSRC_MASK
Definition: lcddevice.h:140
LCDTextItem::setText
void setText(const QString &value)
Definition: lcddevice.h:84
AUDIO_OGG
@ AUDIO_OGG
Definition: lcddevice.h:111
LCDTextItem::setRow
void setRow(unsigned int value)
Definition: lcddevice.h:82
AUDIO_MP3
@ AUDIO_MP3
Definition: lcddevice.h:110
ALIGN_CENTERED
@ ALIGN_CENTERED
Definition: lcddevice.h:61
LCDTextItem::getAlignment
TEXT_ALIGNMENT getAlignment() const
Definition: lcddevice.h:76
VARIOUS_SPDIF
@ VARIOUS_SPDIF
Definition: lcddevice.h:155
LCDMenuItem::setIndent
void setIndent(unsigned int value)
Definition: lcddevice.h:48
LCDVideoSourceSet
LCDVideoSourceSet
Definition: lcddevice.h:139
uint
unsigned int uint
Definition: compat.h:144
LCDTextItem::getWidget
QString getWidget() const
Definition: lcddevice.h:79
LCDTextItem::m_itemRow
unsigned int m_itemRow
Definition: lcddevice.h:90
LCDTextItem::getScreen
QString getScreen() const
Definition: lcddevice.h:78
AUDIO_MASK
@ AUDIO_MASK
Definition: lcddevice.h:108
AUDIO_WMA
@ AUDIO_WMA
Definition: lcddevice.h:118
shutdown
static int shutdown()
Definition: mythtv/programs/mythshutdown/main.cpp:454
AUDIO_WAV
@ AUDIO_WAV
Definition: lcddevice.h:113
ALIGN_LEFT
@ ALIGN_LEFT
Definition: lcddevice.h:61
LCDMenuItem
Definition: lcddevice.h:25
VARIOUS_SHUFFLE
@ VARIOUS_SHUFFLE
Definition: lcddevice.h:152
TEXT_ALIGNMENT
TEXT_ALIGNMENT
Definition: lcddevice.h:61
LCDMenuItem::ItemName
QString ItemName() const
Definition: lcddevice.h:39
VIDEO_MASK
@ VIDEO_MASK
Definition: lcddevice.h:123
CHECKED_STATE
CHECKED_STATE
Definition: lcddevice.h:21
ALIGN_RIGHT
@ ALIGN_RIGHT
Definition: lcddevice.h:61
LCDTextItem::setScreen
void setScreen(const QString &value)
Definition: lcddevice.h:85
NOTCHECKABLE
@ NOTCHECKABLE
Definition: lcddevice.h:21
VARIOUS_VOL
@ VARIOUS_VOL
Definition: lcddevice.h:147
LCDVideoFormatSet
LCDVideoFormatSet
Definition: lcddevice.h:122
AUDIO_DTS
@ AUDIO_DTS
Definition: lcddevice.h:117
VSRC_TV
@ VSRC_TV
Definition: lcddevice.h:142
std
Definition: mythchrono.h:23
VIDEO_MPG
@ VIDEO_MPG
Definition: lcddevice.h:124
FUNC_MASK
@ FUNC_MASK
Definition: lcddevice.h:163
TUNER_SRC2
@ TUNER_SRC2
Definition: lcddevice.h:135
VARIOUS_REPEAT
@ VARIOUS_REPEAT
Definition: lcddevice.h:151
LCDMenuItem::setSelected
void setSelected(bool value)
Definition: lcddevice.h:45
SPDIF_MASK
@ SPDIF_MASK
Definition: lcddevice.h:156
LCDTextItem
Definition: lcddevice.h:63
TUNER_SRC
@ TUNER_SRC
Definition: lcddevice.h:133
LCDTextItem::setScrollable
void setScrollable(bool value)
Definition: lcddevice.h:87
LCDMenuItem::getIndent
unsigned int getIndent() const
Definition: lcddevice.h:41
VIDEO_DIVX
@ VIDEO_DIVX
Definition: lcddevice.h:125
LCDMenuItem::isSelected
bool isSelected() const
Definition: lcddevice.h:38
LCDTextItem::setWidget
void setWidget(const QString &value)
Definition: lcddevice.h:86
CHECKED
@ CHECKED
Definition: lcddevice.h:21
musicbrainzngs.caa.hostname
string hostname
Definition: caa.py:17
LCD::m_serverUnavailable
static bool m_serverUnavailable
Definition: lcddevice.h:181
LCD::m_sendBuffer
QString m_sendBuffer
Definition: lcddevice.h:335
FUNC_DVD
@ FUNC_DVD
Definition: lcddevice.h:167
LCDMenuItem::LCDMenuItem
LCDMenuItem(bool item_selected, CHECKED_STATE item_checked, QString item_name, unsigned int item_indent=0, bool item_scroll=false)
Definition: lcddevice.h:28
LCD::m_lcdShowMusicItems
QString m_lcdShowMusicItems
Definition: lcddevice.h:353
LCDTextItem::getRow
unsigned int getRow() const
Definition: lcddevice.h:75
LCDMenuItem::m_checked
CHECKED_STATE m_checked
Definition: lcddevice.h:54
VARIOUS_ALARM
@ VARIOUS_ALARM
Definition: lcddevice.h:149
LCDMenuItem::Scroll
bool Scroll() const
Definition: lcddevice.h:40
LCDMenuItem::setItemName
void setItemName(const QString &value)
Definition: lcddevice.h:46
LCD
Definition: lcddevice.h:173
VARIOUS_HDTV
@ VARIOUS_HDTV
Definition: lcddevice.h:154