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  int 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 
173  protected:
174  LCD();
175 
176  static bool m_serverUnavailable;
177  static LCD *m_lcd;
178  static bool m_enabled;
179 
180  public:
181  ~LCD() override;
182 
183  enum {
184  MUSIC_REPEAT_NONE = 0,
185  MUSIC_REPEAT_TRACK = 1,
186  MUSIC_REPEAT_ALL = 2,
187  };
188 
189  enum {
190  MUSIC_SHUFFLE_NONE = 0,
191  MUSIC_SHUFFLE_RAND = 1,
192  MUSIC_SHUFFLE_SMART = 2,
193  MUSIC_SHUFFLE_ALBUM = 3,
194  MUSIC_SHUFFLE_ARTIST = 4
195  };
196 
197  static LCD *Get(void);
198  static void SetupLCD (void);
199 
200  // Used to actually connect to an LCD device
201  bool connectToHost(const QString &hostname, unsigned int port);
202 
203  // When nothing else is going on, show the time
204  void switchToTime();
205 
206  // Extended functionality for eg SoundGraph iMON LCD devices
207  void setSpeakerLEDs(enum LCDSpeakerSet speaker, bool on);
208  void setAudioFormatLEDs(enum LCDAudioFormatSet acodec, bool on);
209  void setVideoFormatLEDs(enum LCDVideoFormatSet vcodec, bool on);
210  void setVideoSrcLEDs(enum LCDVideoSourceSet vsrc, bool on);
211  void setFunctionLEDs(enum LCDFunctionSet func, bool on);
212  void setTunerLEDs(enum LCDTunerSet tuner, bool on);
213  void setVariousLEDs(enum LCDVariousFlags various, bool on);
214 
215  // When playing music, switch to this and give artist and track name
216  //
217  // Note: the use of switchToMusic is discouraged, because it
218  // has become obvious that most LCD devices cannot handle communications
219  // fast enough to make them useful.
220  void switchToMusic(const QString &artist, const QString &album,
221  const QString &track);
222 
223  // For Live TV, supply the channel number, program title and subtitle
224  //
225  // Note that the "channel" screen can be used for any kind of progress meter
226  // just put whatever you want in the strings, and update the progress as
227  // appropriate;
228  void switchToChannel(const QString &channum = "", const QString &title = "",
229  const QString &subtitle = "");
230 
231  // While watching Live/Recording/Pause Buffer, occasionaly describe how
232  // much of the program has been seen (between 0.0 and 1.0)
233  // (e.g. [current time - start time] / [end time - start time] )
234  void setChannelProgress(const QString &time, float value);
235 
236  // Show the Menu
237  // QPtrList is a pointer to a bunch of menu items
238  // See mythmusic/databasebox.cpp for an example
239  void switchToMenu(QList<LCDMenuItem> &menuItems,
240  const QString &app_name = "",
241  bool popMenu = true);
242 
243  // Show the Generic Progress
244  // QPtrList contains pointers to LCDTextItem objects which allow you to
245  // define the screen, row, and alignment of the text
246  void switchToGeneric(QList<LCDTextItem> &textItems);
247 
251  void setGenericProgress(float value);
252 
257  void setGenericBusy();
258 
259  // Do a music progress bar with the generic level between 0 and 1.0
260  void setMusicProgress(const QString &time, float value);
261 
265  void setMusicRepeat(int repeat);
266 
270  void setMusicShuffle(int shuffle);
271 
272  // Show the Volume Level top_text scrolls
273  void switchToVolume(const QString &app_name);
274 
275  // Do a progress bar with the volume level between 0 and 1.0
276  void setVolumeLevel(float value);
277 
278  // If some other process should be getting all the LCDd screen time (e.g.
279  // mythMusic) we can use this to try and prevent and screens from showing
280  // up without having to actual destroy the LCD object
281  void switchToNothing();
282 
283  // If you want to be pleasant, call shutdown() before deleting your LCD
284  // device
285  void shutdown();
286 
287  void setupLEDs(int(*LedMaskFunc)(void));
288 
289  void stopAll(void);
290 
291  uint getLCDHeight(void) { return m_lcdHeight; }
292  uint getLCDWidth(void) { return m_lcdWidth; }
293 
294  void resetServer(void); // tell the mythlcdserver to reload its settings
295 
296  private slots:
297  void restartConnection(); // Try to re-establish the connection to
298  // LCDServer every 10 seconds
299  void outputLEDs();
300  void sendToServerSlot(const QString &someText);
301 
302 signals:
303  void sendToServer(const QString &someText);
304 
305  private:
306  static bool startLCDServer(void);
307  void init();
308  void handleKeyPress(const QString &keyPressed);
309  static QString quotedString(const QString &string);
310  void describeServer();
311 
312  private slots:
313  void ReadyRead(void);
314  void Disconnected(void);
315 
316  private:
317  QTcpSocket *m_socket {nullptr};
318  QMutex m_socketLock {QMutex::Recursive};
319  QString m_hostname {"localhost"};
320  uint m_port {6545};
321  bool m_connected {false};
322 
323  QTimer *m_retryTimer {nullptr};
324  QTimer *m_ledTimer {nullptr};
325 
326  QString m_sendBuffer;
327  QString m_lastCommand;
328 
329  int m_lcdWidth {0};
330  int m_lcdHeight {0};
331 
332  bool m_lcdReady {false};
333 
334  bool m_lcdShowTime {false};
335  bool m_lcdShowMenu {false};
336  bool m_lcdShowGeneric {false};
337  bool m_lcdShowMusic {false};
338  bool m_lcdShowChannel {false};
339  bool m_lcdShowVolume {false};
340  bool m_lcdShowRecStatus {false};
341  bool m_lcdBacklightOn {false};
342  bool m_lcdHeartbeatOn {false};
343  int m_lcdPopupTime {0};
345  QString m_lcdKeyString;
346 
347  int m_lcdLedMask {0};
348 
349  int (*m_getLEDMask)(void) {nullptr};
350 };
351 
352 #endif
bool isSelected() const
Definition: lcddevice.h:34
void setScrollable(bool value)
Definition: lcddevice.h:83
unsigned int slots[4]
Definition: element.c:38
CHECKED_STATE
Definition: lcddevice.h:17
LCDMenuItem(bool item_selected, CHECKED_STATE item_checked, QString item_name, unsigned int item_indent=0, bool item_scroll=false)
Definition: lcddevice.h:24
void setAlignment(TEXT_ALIGNMENT value)
Definition: lcddevice.h:79
void setItemName(const QString &value)
Definition: lcddevice.h:42
void setScroll(bool value)
Definition: lcddevice.h:43
static bool m_enabled
Definition: lcddevice.h:178
uint getLCDHeight(void)
Definition: lcddevice.h:291
LCDVideoSourceSet
Definition: lcddevice.h:135
QString m_sendBuffer
Definition: lcddevice.h:326
void setText(const QString &value)
Definition: lcddevice.h:80
LCDTextItem(unsigned int row, TEXT_ALIGNMENT align, QString text, QString screen="Generic", bool scroll=false, QString widget="textWidget")
Definition: lcddevice.h:62
QString m_itemText
Definition: lcddevice.h:88
TEXT_ALIGNMENT m_itemAlignment
Definition: lcddevice.h:87
static int shutdown()
#define MBASE_PUBLIC
Definition: mythbaseexp.h:15
QString getScreen() const
Definition: lcddevice.h:74
QString m_lastCommand
Definition: lcddevice.h:327
QString m_lcdKeyString
Definition: lcddevice.h:345
void setScrollPos(unsigned int value)
Definition: lcddevice.h:45
LCDTunerSet
Definition: lcddevice.h:127
QString ItemName() const
Definition: lcddevice.h:35
void setSelected(bool value)
Definition: lcddevice.h:41
bool m_selected
Definition: lcddevice.h:49
static bool m_serverUnavailable
Definition: lcddevice.h:176
string hostname
Definition: caa.py:17
QString m_lcdShowMusicItems
Definition: lcddevice.h:344
unsigned int uint
Definition: compat.h:140
LCDVideoFormatSet
Definition: lcddevice.h:118
const char * m_name
Definition: ParseText.cpp:328
static void init(VideoFrame *vf, VideoFrameType _codec, unsigned char *_buf, int _width, int _height, int _size, const int *p=nullptr, const int *o=nullptr, float _aspect=-1.0F, double _rate=-1.0F, int _aligned=MYTH_WIDTH_ALIGNMENT)
Definition: mythframe.h:230
LCDSpeakerSet
Definition: lcddevice.h:95
void setWidget(const QString &value)
Definition: lcddevice.h:82
void setRow(unsigned int value)
Definition: lcddevice.h:78
CHECKED_STATE isChecked() const
Definition: lcddevice.h:33
CHECKED_STATE m_checked
Definition: lcddevice.h:50
unsigned int getRow() const
Definition: lcddevice.h:71
LCDVariousFlags
Definition: lcddevice.h:142
TEXT_ALIGNMENT getAlignment() const
Definition: lcddevice.h:72
unsigned int m_itemRow
Definition: lcddevice.h:86
void setIndent(unsigned int value)
Definition: lcddevice.h:44
uint getLCDWidth(void)
Definition: lcddevice.h:292
QString m_name
Definition: lcddevice.h:51
bool Scroll() const
Definition: lcddevice.h:36
QString getWidget() const
Definition: lcddevice.h:75
static LCD * m_lcd
Definition: lcddevice.h:177
Definition: lcddevice.h:169
TEXT_ALIGNMENT
Definition: lcddevice.h:57
void incrementScrollPos()
Definition: lcddevice.h:46
unsigned int getScrollPos() const
Definition: lcddevice.h:38
QString getText() const
Definition: lcddevice.h:73
LCDFunctionSet
Definition: lcddevice.h:157
int getScroll() const
Definition: lcddevice.h:76
void setScreen(const QString &value)
Definition: lcddevice.h:81
void setChecked(CHECKED_STATE value)
Definition: lcddevice.h:40
LCDAudioFormatSet
Definition: lcddevice.h:103
unsigned int getIndent() const
Definition: lcddevice.h:37