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