00001 #ifndef LCDDEVICE_H_
00002 #define LCDDEVICE_H_
00003
00004 #include <iostream>
00005
00006 #include <QObject>
00007 #include <QStringList>
00008 #include <QTimer>
00009 #include <QDateTime>
00010 #include <QMutex>
00011 #include <QList>
00012
00013 #include "mythbaseexp.h"
00014 #include "mythsocket_cb.h"
00015
00016 enum CHECKED_STATE {CHECKED = 0, UNCHECKED, NOTCHECKABLE };
00017
00018 class MBASE_PUBLIC LCDMenuItem
00019 {
00020 public:
00021 LCDMenuItem(bool item_selected, CHECKED_STATE item_checked,
00022 QString item_name, unsigned int item_indent = 0,
00023 bool item_scroll = false)
00024 {
00025 selected = item_selected;
00026 checked = item_checked;
00027 name = item_name;
00028 scroll = item_scroll;
00029 indent = item_indent;
00030 scrollPosition = indent;
00031 }
00032
00033 CHECKED_STATE isChecked() const { return checked; }
00034 bool isSelected() const { return selected; }
00035 QString ItemName() const { return name; }
00036 bool Scroll() const { return scroll; }
00037 unsigned int getIndent() const { return indent; }
00038 unsigned int getScrollPos() const { return scrollPosition; }
00039
00040 void setChecked(CHECKED_STATE value) { checked = value; }
00041 void setSelected(bool value) { selected = value; }
00042 void setItemName(QString value) { name = value; }
00043 void setScroll(bool value) { scroll = value; }
00044 void setIndent(unsigned int value) { indent = value; }
00045 void setScrollPos(unsigned int value) { scrollPosition = value; }
00046 void incrementScrollPos() { ++scrollPosition; }
00047
00048 private:
00049 bool selected;
00050 CHECKED_STATE checked;
00051 QString name;
00052 bool scroll;
00053 unsigned int indent;
00054 unsigned int scrollPosition;
00055 };
00056
00057 enum TEXT_ALIGNMENT {ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTERED };
00058
00059 class MBASE_PUBLIC LCDTextItem
00060 {
00061 public:
00062 LCDTextItem(unsigned int row, TEXT_ALIGNMENT align, QString text,
00063 QString screen = "Generic", bool scroll = false,
00064 QString widget = "textWidget")
00065 {
00066 itemRow = row;
00067 itemAlignment = align;
00068 itemText = text;
00069 itemScreen = screen;
00070 itemWidget = widget;
00071 itemScrollable = scroll;
00072 }
00073
00074 unsigned int getRow() const { return itemRow; }
00075 TEXT_ALIGNMENT getAlignment() const { return itemAlignment; }
00076 QString getText() const { return itemText; }
00077 QString getScreen() const { return itemScreen; }
00078 QString getWidget() const { return itemWidget; }
00079 int getScroll() const { return itemScrollable; }
00080
00081 void setRow(unsigned int value) { itemRow = value; }
00082 void setAlignment(TEXT_ALIGNMENT value) { itemAlignment = value; }
00083 void setText(QString value) { itemText = value; }
00084 void setScreen(QString value) { itemScreen = value; }
00085 void setWidget(QString value) { itemWidget = value; }
00086 void setScrollable(bool value) { itemScrollable = value; }
00087
00088 private:
00089 unsigned int itemRow;
00090 TEXT_ALIGNMENT itemAlignment;
00091 QString itemText;
00092 QString itemScreen;
00093 QString itemWidget;
00094 bool itemScrollable;
00095 };
00096
00097
00098 enum LCDSpeakerSet {
00099 SPEAKER_MASK = 0x00000030,
00100 SPEAKER_LR = 1 << 4,
00101 SPEAKER_51 = 2 << 4,
00102 SPEAKER_71 = 3 << 4,
00103 };
00104
00105
00106 enum LCDAudioFormatSet {
00107 AUDIO_MASK = 0x0000E000 | 0x00070000,
00108
00109 AUDIO_MP3 = 1 << 13,
00110 AUDIO_OGG = 2 << 13,
00111 AUDIO_WMA2 = 3 << 13,
00112 AUDIO_WAV = 4 << 13,
00113
00114 AUDIO_MPEG2 = 1 << 16,
00115 AUDIO_AC3 = 2 << 16,
00116 AUDIO_DTS = 3 << 16,
00117 AUDIO_WMA = 4 << 16,
00118 };
00119
00120
00121 enum LCDVideoFormatSet {
00122 VIDEO_MASK = 0x00380000,
00123 VIDEO_MPG = 1 << 19,
00124 VIDEO_DIVX = 2 << 19,
00125 VIDEO_XVID = 3 << 19,
00126 VIDEO_WMV = 4 << 19,
00127 };
00128
00129
00130 enum LCDTunerSet {
00131 TUNER_MASK = 0x00000080 | 0x00000800 | 0x00001000,
00132 TUNER_SRC = 0x00000080,
00133 TUNER_SRC1 = 0x00000800,
00134 TUNER_SRC2 = 0x00001000,
00135 };
00136
00137
00138 enum LCDVideoSourceSet {
00139 VSRC_MASK = 0x00000100 | 0x00000200,
00140 VSRC_FIT = 0x00000100,
00141 VSRC_TV = 0x00000200,
00142 };
00143
00144
00145 enum LCDVariousFlags {
00146 VARIOUS_VOL = 0x00400000,
00147 VARIOUS_TIME = 0x00800000,
00148 VARIOUS_ALARM = 0x01000000,
00149 VARIOUS_RECORD = 0x02000000,
00150 VARIOUS_REPEAT = 0x04000000,
00151 VARIOUS_SHUFFLE = 0x08000000,
00152 VARIOUS_DISC_IN = 0x20000000,
00153 VARIOUS_HDTV = 0x00000400,
00154 VARIOUS_SPDIF = 0x1 << 9,
00155 SPDIF_MASK = 0x00000040,
00156 };
00157
00158
00159
00160 enum LCDFunctionSet {
00161
00162 FUNC_MASK = 0xE,
00163 FUNC_MUSIC = 1 << 1,
00164 FUNC_MOVIE = 2 << 1,
00165 FUNC_PHOTO = 3 << 1,
00166 FUNC_DVD = 4 << 1,
00167 FUNC_TV = 5 << 1,
00168 FUNC_WEB = 6 << 1,
00169 FUNC_NEWS = 7 << 1,
00170 };
00171
00172 class MBASE_PUBLIC LCD : public QObject, public MythSocketCBs
00173 {
00174 Q_OBJECT
00175
00176 protected:
00177 LCD();
00178
00179 static bool m_server_unavailable;
00180 static LCD *m_lcd;
00181 static bool m_enabled;
00182
00183 public:
00184 ~LCD();
00185
00186 enum {
00187 MUSIC_REPEAT_NONE = 0,
00188 MUSIC_REPEAT_TRACK = 1,
00189 MUSIC_REPEAT_ALL = 2,
00190 };
00191
00192 enum {
00193 MUSIC_SHUFFLE_NONE = 0,
00194 MUSIC_SHUFFLE_RAND = 1,
00195 MUSIC_SHUFFLE_SMART = 2,
00196 MUSIC_SHUFFLE_ALBUM = 3,
00197 MUSIC_SHUFFLE_ARTIST = 4
00198 };
00199
00200 static LCD *Get(void);
00201 static void SetupLCD (void);
00202
00203
00204 bool connectToHost(const QString &hostname, unsigned int port);
00205
00206
00207 void switchToTime();
00208
00209
00210 void setSpeakerLEDs(enum LCDSpeakerSet speaker, bool on);
00211 void setAudioFormatLEDs(enum LCDAudioFormatSet acodec, bool on);
00212 void setVideoFormatLEDs(enum LCDVideoFormatSet vcodec, bool on);
00213 void setVideoSrcLEDs(enum LCDVideoSourceSet vsrc, bool on);
00214 void setFunctionLEDs(enum LCDFunctionSet video, bool on);
00215 void setTunerLEDs(enum LCDTunerSet tuner, bool on);
00216 void setVariousLEDs(enum LCDVariousFlags various, bool on);
00217
00218
00219
00220
00221
00222
00223 void switchToMusic(const QString &artist, const QString &album,
00224 const QString &track);
00225
00226
00227
00228
00229
00230
00231 void switchToChannel(QString channum = "", QString title = "",
00232 QString subtitle = "");
00233
00234
00235
00236
00237 void setChannelProgress(const QString &time, float percentViewed);
00238
00239
00240
00241
00242 void switchToMenu(QList<LCDMenuItem> &menuItems, QString app_name = "",
00243 bool popMenu = true);
00244
00245
00246
00247
00248 void switchToGeneric(QList<LCDTextItem> &textItems);
00249
00253 void setGenericProgress(float generic_progress);
00254
00259 void setGenericBusy();
00260
00261
00262 void setMusicProgress(QString time, float generic_progress);
00263
00267 void setMusicRepeat(int repeat);
00268
00272 void setMusicShuffle(int shuffle);
00273
00274
00275 void switchToVolume(QString app_name);
00276
00277
00278 void setVolumeLevel(float volume_level);
00279
00280
00281
00282
00283 void switchToNothing();
00284
00285
00286
00287 void shutdown();
00288
00289 void setupLEDs(int(*LedMaskFunc)(void));
00290
00291 void stopAll(void);
00292
00293 uint getLCDHeight(void) { return lcd_height; }
00294 uint getLCDWidth(void) { return lcd_width; }
00295
00296 void resetServer(void);
00297
00298 private slots:
00299 void restartConnection();
00300
00301 void outputLEDs();
00302
00303 private:
00304 bool startLCDServer(void);
00305 void sendToServer(const QString &someText);
00306 void init();
00307 void handleKeyPress(QString key);
00308 QString quotedString(const QString &s);
00309 void describeServer();
00310
00311
00312 void connected(MythSocket *sock) { (void)sock; }
00313 void connectionClosed(MythSocket *sock);
00314 void readyRead(MythSocket *sock);
00315 void connectionFailed(MythSocket *sock);
00316
00317 MythSocket *socket;
00318 QMutex socketLock;
00319 QString hostname;
00320 uint port;
00321 bool bConnected;
00322
00323 QTimer *retryTimer;
00324 QTimer *LEDTimer;
00325
00326 QString send_buffer;
00327 QString last_command;
00328
00329 int lcd_width;
00330 int lcd_height;
00331
00332 bool lcd_ready;
00333
00334 bool lcd_showtime;
00335 bool lcd_showmenu;
00336 bool lcd_showgeneric;
00337 bool lcd_showmusic;
00338 bool lcd_showchannel;
00339 bool lcd_showvolume;
00340 bool lcd_showrecstatus;
00341 bool lcd_backlighton;
00342 bool lcd_heartbeaton;
00343 int lcd_popuptime;
00344 QString lcd_showmusic_items;
00345 QString lcd_keystring;
00346
00347 int lcd_ledmask;
00348
00349 int (*GetLEDMask)(void);
00350 };
00351
00352 #endif