Ticket #324: lcddevice.h

File lcddevice.h, 7.0 KB (added by Paul, 20 years ago)

same goes for the lcddevice.h

Line 
1#ifndef LCDDEVICE_H_
2#define LCDDEVICE_H_
3
4#include <iostream>
5#include <qobject.h>
6#include <qstringlist.h>
7#include <qvaluevector.h>
8#include <qsocket.h>
9#include <qtimer.h>
10#include <qdatetime.h>
11
12using namespace std;
13
14enum CHECKED_STATE {CHECKED = 0, UNCHECKED, NOTCHECKABLE };
15
16class LCDMenuItem
17{
18 public:
19 LCDMenuItem() {}
20 LCDMenuItem(bool item_selected, CHECKED_STATE item_checked,
21 QString item_name, unsigned int item_indent = 0)
22 {
23 selected = item_selected;
24 checked = item_checked;
25 name = item_name;
26 indent = item_indent;
27 scrollPosition = indent;
28 }
29
30 ~LCDMenuItem() {}
31
32 CHECKED_STATE isChecked() { return checked; }
33 bool isSelected() { return selected; }
34 QString ItemName() { return name; }
35 bool Scroll() { return scroll; }
36 unsigned int getIndent() { return indent; }
37 unsigned int getScrollPos() { return scrollPosition; }
38
39 void setChecked(CHECKED_STATE value) { checked = value; }
40 void setSelected(bool value) { selected = value; }
41 void setItemName(QString value) { name = value; }
42 void setScroll(bool value) { scroll = value; }
43 void setIndent(unsigned int value) { indent = value; }
44 void setScrollPos(unsigned int value) { scrollPosition = value; }
45 void incrementScrollPos() { ++scrollPosition; }
46
47 private:
48 bool selected;
49 CHECKED_STATE checked;
50 QString name;
51 bool scroll;
52 unsigned int indent;
53 unsigned int scrollPosition;
54};
55
56enum TEXT_ALIGNMENT {ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTERED };
57
58class LCDTextItem
59{
60 public:
61 LCDTextItem() {}
62 LCDTextItem(unsigned int row, TEXT_ALIGNMENT align, QString text,
63 QString screen = "Generic", bool scroll = false)
64 {
65 itemRow = row;
66 itemAlignment = align;
67 itemText = text;
68 itemScreen = screen;
69 itemScrollable = scroll;
70 }
71
72 ~LCDTextItem(){};
73
74 unsigned int getRow() { return itemRow; }
75 TEXT_ALIGNMENT getAlignment() { return itemAlignment; }
76 QString getText() { return itemText; }
77 QString getScreen() { return itemScreen; }
78 int getScroll() { return itemScrollable; }
79
80 void setRow(unsigned int value) { itemRow = value; }
81 void setAlignment(TEXT_ALIGNMENT value) { itemAlignment = value; }
82 void setText(QString value) { itemText = value; }
83 void setScreen(QString value) { itemScreen = value; }
84 void setScrollable(bool value) { itemScrollable = value; }
85
86 private:
87 unsigned int itemRow;
88 TEXT_ALIGNMENT itemAlignment;
89 QString itemText;
90 QString itemScreen;
91 bool itemScrollable;
92};
93
94class LCD : public QObject
95{
96 Q_OBJECT
97
98 protected:
99 LCD();
100
101 static bool m_server_unavailable;
102 static class LCD * m_lcd;
103
104 public:
105 ~LCD();
106
107 static class LCD * Get(void);
108 static void SetupLCD (void);
109
110 // Used to actually connect to an LCD device
111 bool connectToHost(const QString &hostname, unsigned int port);
112
113 // When nothing else is going on, show the time
114 void switchToTime();
115
116 // When playing music, switch to this and give artist and track name
117 //
118 // Note: the use of switchToMusic and setLevels is discouraged, because it
119 // has become obvious that most LCD devices cannot handle communications
120 // fast enough to make them useful.
121 void switchToMusic(const QString &artist, const QString &album, const QString &track);
122
123 // You can set 10 (or less) equalizer values here (between 0.0 and 1.0)
124 void setLevels(int numbLevels, float *values);
125
126 // For Live TV, supply the channel number, program title and subtitle
127 //
128 // Note that the "channel" screen can be used for any kind of progress meter
129 // just put whatever you want in the strings, and update the progress as
130 // appropriate; see the demo app mythlcd for an example)
131 void switchToChannel(QString channum = "", QString title = "",
132 QString subtitle = "");
133
134 // While watching Live/Recording/Pause Buffer, occasionaly describe how
135 // much of the program has been seen (between 0.0 and 1.0)
136 // (e.g. [current time - start time] / [end time - start time] )
137 void setChannelProgress(float percentViewed);
138
139 // Show the Menu
140 // QPtrList is a pointer to a bunch of menu items
141 // See mythmusic/databasebox.cpp for an example
142 void switchToMenu(QPtrList<LCDMenuItem> *menuItems, QString app_name = "",
143 bool popMenu = true);
144
145 // Show the Generic Progress
146 // QPtrList contains pointers to LCDTextItem objects which allow you to
147 // define the screen, row, and alignment of the text
148 void switchToGeneric(QPtrList<LCDTextItem> *textItems);
149
150 // Do a progress bar with the generic level between 0 and 1.0
151 void setGenericProgress(float generic_progress);
152
153 // Do a music progress bar with the generic level between 0 and 1.0
154 void setMusicProgress(QString time, float generic_progress);
155
156 // Show the Volume Level top_text scrolls
157 void switchToVolume(QString app_name);
158
159 // Do a progress bar with the volume level between 0 and 1.0
160 void setVolumeLevel(float volume_level);
161
162 // If some other process should be getting all the LCDd screen time (e.g.
163 // mythMusic) we can use this to try and prevent and screens from showing
164 // up without having to actual destroy the LCD object
165 void switchToNothing();
166
167 // If you want to be pleasant, call shutdown() before deleting your LCD
168 // device
169 void shutdown();
170
171 // outputText spins through the ptr list and outputs the text according to
172 // the params set in the LCDTextItem object
173 // gContext->LCDsetGenericProgress(percent_heard) for an example
174// void outputText(QPtrList<LCDTextItem> *textItems);
175
176 void setupLEDs(int(*LedMaskFunc)(void));
177
178 void stopAll(void);
179
180 uint getLCDHeight(void) { return lcd_height; }
181 uint getLCDWidth(void) { return lcd_width; }
182
183 private slots:
184 void veryBadThings(int); // Communication Errors
185 void serverSendingData(); // Data coming back from LCDd
186
187 void restartConnection(); // Try to re-establish the connection to
188 // LCDServer every 10 seconds
189 void outputLEDs();
190
191 private:
192 void sendToServer(const QString &someText);
193 void init();
194 void handleKeyPress(QString key);
195 QString quotedString(const QString &s);
196
197 QSocket *socket;
198 QTimer *retryTimer;
199 QTimer *LEDTimer;
200
201 void describeServer();
202
203 bool connected;
204
205 QString send_buffer;
206 QString last_command;
207 QString hostname;
208 unsigned int port;
209
210 int lcd_width;
211 int lcd_height;
212
213 bool lcd_ready;
214
215 bool lcd_showtime;
216 bool lcd_showmenu;
217 bool lcd_showgeneric;
218 bool lcd_showmusic;
219 bool lcd_showchannel;
220 bool lcd_showvolume;
221 bool lcd_showrecstatus;
222 bool lcd_backlighton;
223 bool lcd_heartbeaton;
224 int lcd_popuptime;
225 QString lcd_showmusic_items;
226 QString lcd_keystring;
227
228 int (*GetLEDMask)(void);
229};
230
231#endif