[mythtv] [PATCH] LCD bug fixes
DanM
dan at milkcarton.com
Mon Aug 18 23:59:22 EDT 2003
Isaac, I did find one bug, in init(), switchToTime() would get called
before lcd_ready was set true. Fixed that, also put in some connection
retry code in case LCDd goes down unexpectedly (read: user such as
myself restarts LCDd to try something). Thank you for getting the rest
of the stuff committed.
If anyone out there has a LCD, especially one with a keypad; please
message me off list; I'd like to get feedback, bounce a few ideas
around. . .
-dan
-------------- next part --------------
Index: lcddevice.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/lcddevice.cpp,v
retrieving revision 1.17
diff -u -d -r1.17 lcddevice.cpp
--- lcddevice.cpp 18 Aug 2003 21:28:22 -0000 1.17
+++ lcddevice.cpp 19 Aug 2003 06:50:28 -0000
@@ -80,6 +80,9 @@
menuPreScrollTimer = new QTimer(this);
connect(menuPreScrollTimer, SIGNAL(timeout()), this,
SLOT(beginScrollingMenuText()));
+
+ retryTimer = new QTimer(this);
+ connect(retryTimer, SIGNAL(timeout()), this, SLOT(restartConnection()));
}
void LCD::connectToHost(const QString &lhostname, unsigned int lport)
@@ -113,12 +116,30 @@
scrollingText.prepend(" ");
scrollPosition = lcdWidth;
- scrollTimer->start(400, FALSE);
+ scrollTimer->start(400, false);
}
void LCD::sendToServer(const QString &someText)
{
#ifdef LCD_DEVICE
+ //Check the socket, make sure the connection is still up
+ if(socket->state() == QSocket::Idle)
+ {
+ if(!lcd_ready)
+ return;
+
+ lcd_ready = false;
+
+ //Stop everything
+ stopAll();
+
+ // Ack, connection to server has been severed
+ // try to re-establish the connection
+ retryTimer->start(10000, FALSE);
+ cerr << "lcddevice: Connection to LCDd died unexpectedly. Trying to reconnect every 10 seconds. . ." << endl;
+ return;
+ }
+
QTextStream os(socket);
last_command = someText;
@@ -145,6 +166,16 @@
#endif
}
+void LCD::restartConnection()
+{
+ //Reset the flag
+ lcd_ready = false;
+ connected = false;
+
+ //Retry to connect. . . Maybe the user restarted LCDd?
+ connectToHost(hostname, port);
+}
+
void LCD::serverSendingData()
{
QString lineFromServer, tempString;
@@ -258,7 +289,10 @@
void LCD::init()
{
- QString aString, bString;
+ //Stop the timer
+ retryTimer->stop();
+
+ QString aString;
int i;
connected = TRUE;
@@ -341,8 +375,10 @@
sendToServer("backlight 255");
+ lcd_ready = true;
+
switchToTime(); // clock is on by default
-
+
// send buffer if there's anything in there
if(send_buffer.length() > 0)
@@ -351,7 +387,6 @@
send_buffer = "";
}
- lcd_ready = true;
}
void LCD::setWidth(unsigned int x)
@@ -440,11 +475,17 @@
void LCD::stopAll()
{
- sendToServer("screen_set Music priority 255");
- sendToServer("screen_set Channel priority 255");
- sendToServer("screen_set Generic priority 255");
- sendToServer("screen_set Volume priority 255");
- sendToServer("screen_set Menu priority 255");
+ // The usual reason things would get this far and then
+ // lcd_ready being false is the connection died and we're trying
+ // to re-establish the connection
+ if(lcd_ready)
+ {
+ sendToServer("screen_set Music priority 255");
+ sendToServer("screen_set Channel priority 255");
+ sendToServer("screen_set Generic priority 255");
+ sendToServer("screen_set Volume priority 255");
+ sendToServer("screen_set Menu priority 255");
+ }
preScrollTimer->stop();
scrollTimer->stop();
Index: lcddevice.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/lcddevice.h,v
retrieving revision 1.10
diff -u -d -r1.10 lcddevice.h
--- lcddevice.h 18 Aug 2003 21:28:22 -0000 1.10
+++ lcddevice.h 19 Aug 2003 06:50:28 -0000
@@ -173,7 +173,8 @@
private slots:
void veryBadThings(int); // Communication Errors
void serverSendingData(); // Data coming back from LCDd
-
+ void restartConnection(); // Try to re-establish the connection to LCDd every 10 seconds
+
void outputTime(); // Fire from a timer
void outputMusic(); // Short timer (equalizer)
void outputChannel(); // Longer timer (progress bar)
@@ -211,7 +212,7 @@
void handleKeyPress(QString key);
void startVolume(QString app_name);
- unsigned int theMode;
+ unsigned int theMode;
QSocket *socket;
QTimer *timeTimer;
@@ -220,9 +221,10 @@
QTimer *genericTimer;
QTimer *scrollTimer;
QTimer *preScrollTimer;
- QTimer *menuScrollTimer;
- QTimer *menuPreScrollTimer;
+ QTimer *menuScrollTimer;
+ QTimer *menuPreScrollTimer;
QTimer *popMenuTimer;
+ QTimer *retryTimer;
void setWidth(unsigned int);
void setHeight(unsigned int);
More information about the mythtv-dev
mailing list