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