[4670a1]: xbmc / linux / XLCDproc.cpp  Maximize  Restore  History

Repo status: analyzing...

Download this file

295 lines (253 with data), 7.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
/*
* Copyright (C) 2005-2008 Team XBMC
* http://www.xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
#include "PlatformInclude.h"
#include "XLCDproc.h"
#include "../utils/log.h"
#include "../utils/TimeUtils.h"
#include "AdvancedSettings.h"
#include "GUISettings.h"
#define SCROLL_SPEED_IN_MSEC 250
XLCDproc::XLCDproc()
{
m_iActualpos = 0;
m_iBackLight = 32;
m_iLCDContrast = 50;
m_bStop = true;
sockfd = -1;
m_lastInitAttempt = 0;
m_initRetryInterval = INIT_RETRY_INTERVAL;
m_used = true;
}
XLCDproc::~XLCDproc()
{
}
void XLCDproc::Initialize()
{
if (!g_guiSettings.GetBool("system.haslcd"))
return ;//nothing to do
// don't try to initialize too often
int now = CTimeUtils::GetTimeMS();
if (!m_used || now < m_lastInitAttempt + m_initRetryInterval)
return;
m_lastInitAttempt = now;
ILCD::Initialize();
struct hostent *server;
server = gethostbyname("localhost");
if (server == NULL)
{
CLog::Log(LOGERROR, "XLCDproc::%s - Unable to resolve LCDd host.", __FUNCTION__);
return;
}
struct sockaddr_in serv_addr;
sockfd = socket(AF_INET, SOCK_STREAM, 0);
memset((char *) &serv_addr, 0, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
memmove((char *)&serv_addr.sin_addr,
(char *)server->h_addr_list[0],
server->h_length);
//Connect to default LCDd port, hard coded for now.
serv_addr.sin_port = htons(13666);
if (connect(sockfd,(struct sockaddr*)&serv_addr,sizeof(serv_addr)) < 0)
{
// give up after 60 seconds
if (m_initRetryInterval > INIT_RETRY_INTERVAL_MAX)
{
m_used = false;
CLog::Log(LOGERROR, "XLCDproc::%s - Unable to connect to host. Giving up.", __FUNCTION__);
}
else
{
m_initRetryInterval *= 2;
CLog::Log(LOGERROR, "XLCDproc::%s - Unable to connect to host. Retry in %d seconds.", __FUNCTION__,
m_initRetryInterval/1000);
}
return;
}
// reset the retry interval after a successful connect
m_initRetryInterval = INIT_RETRY_INTERVAL;
// Start a new session
CStdString hello;
hello = "hello\n";
if (write(sockfd,hello.c_str(),hello.size()) < 0)
{
CLog::Log(LOGERROR, "XLCDproc::%s - Unable to write to socket", __FUNCTION__);
return;
}
// Receive LCDproc data to determine row and column information
char reply[1024];
unsigned int i=0;
if (read(sockfd,reply,1024) < 0)
CLog::Log(LOGERROR, "XLCDproc::%s - Unable to read from socket", __FUNCTION__);
while ((strncmp("lcd",reply+i,3) != 0 ) && (i<(strlen(reply)-5))) i++;
if(sscanf(reply+i,"lcd wid %u hgt %u", &m_iColumns, &m_iRows))
CLog::Log(LOGDEBUG, "XLCDproc::%s - LCDproc data: Columns %i - Rows %i.", __FUNCTION__, m_iColumns, m_iRows);
//Build command to setup screen
CStdString cmd;
cmd = "screen_add xbmc\n";
if (!g_advancedSettings.m_lcdHeartbeat)
cmd.append("screen_set xbmc -heartbeat off\n");
if (g_advancedSettings.m_lcdScrolldelay != 0)
{
cmd.append("widget_add xbmc line1 scroller\n");
cmd.append("widget_add xbmc line2 scroller\n");
cmd.append("widget_add xbmc line3 scroller\n");
cmd.append("widget_add xbmc line4 scroller\n");
}
else
{
cmd.append("widget_add xbmc line1 string\n");
cmd.append("widget_add xbmc line2 string\n");
cmd.append("widget_add xbmc line3 string\n");
cmd.append("widget_add xbmc line4 string\n");
}
//Send to server
if (write(sockfd,cmd.c_str(),cmd.size()) < 0)
CLog::Log(LOGERROR, "XLCDproc::%s - Unable to write to socket", __FUNCTION__);
m_bStop = false;
}
bool XLCDproc::IsConnected()
{
CStdString cmd;
cmd = "noop\n";
if (write(sockfd,cmd.c_str(),cmd.size()) >= 0)
{
return true;
}
else
{
return false;
}
}
void XLCDproc::SetBackLight(int iLight)
{
if (sockfd > 0)
{
//Build command
CStdString cmd;
if (iLight == 0) {
m_bStop = true;
cmd = "screen_set xbmc -backlight off\n";
cmd.append("widget_del xbmc line1\n");
cmd.append("widget_del xbmc line2\n");
cmd.append("widget_del xbmc line3\n");
cmd.append("widget_del xbmc line4\n");
}
if (iLight > 0) {
m_bStop = false;
cmd = "screen_set xbmc -backlight on\n";
if (g_advancedSettings.m_lcdScrolldelay != 0)
{
cmd.append("widget_add xbmc line1 scroller\n");
cmd.append("widget_add xbmc line2 scroller\n");
cmd.append("widget_add xbmc line3 scroller\n");
cmd.append("widget_add xbmc line4 scroller\n");
}
else
{
cmd.append("widget_add xbmc line1 string\n");
cmd.append("widget_add xbmc line2 string\n");
cmd.append("widget_add xbmc line3 string\n");
cmd.append("widget_add xbmc line4 string\n");
}
}
//Send to server
if (write(sockfd,cmd.c_str(),cmd.size()) < 0)
CLog::Log(LOGERROR, "XLCDproc::%s - Unable to write to socket", __FUNCTION__);
}
}
void XLCDproc::SetContrast(int iContrast)
{
//TODO: Not sure if you can control contrast from client
}
void XLCDproc::Stop()
{
//Close connection
if (sockfd >= 0)
shutdown(sockfd, SHUT_RDWR);
m_bStop = true;
}
void XLCDproc::Suspend()
{
if (!m_bStop)
{
if (sockfd > 0)
{
//Build command to suspend screen
CStdString cmd;
cmd = "screen_set xbmc -priority hidden\n";
//Send to server
if (write(sockfd,cmd.c_str(),cmd.size()) < 0)
CLog::Log(LOGERROR, "XLCDproc::%s - Unable to write to socket", __FUNCTION__);
}
}
}
void XLCDproc::Resume()
{
if (!m_bStop)
{
if (sockfd > 0)
{
//Build command to resume screen
CStdString cmd;
cmd = "screen_set xbmc -priority info\n";
//Send to server
if (write(sockfd,cmd.c_str(),cmd.size()) < 0)
CLog::Log(LOGERROR, "XLCDproc::%s - Unable to write to socket", __FUNCTION__);
}
}
}
void XLCDproc::SetLine(int iLine, const CStdString& strLine)
{
if (m_bStop)
return;
if (iLine < 0 || iLine >= (int)m_iRows)
return;
CStdString cmd;
CStdString strLineLong = strLine;
strLineLong.Trim();
StringToLCDCharSet(strLineLong);
//make string fit the display if it's smaller than the width
if (strLineLong.size() < m_iColumns)
strLineLong.append(m_iColumns - strLineLong.size(), ' ');
//else if the string doesn't fit the display, lcdproc will scroll it, so we need a space
else if (strLineLong.size() > m_iColumns)
strLineLong += " ";
if (strLineLong != m_strLine[iLine])
{
int ln = iLine + 1;
if (g_advancedSettings.m_lcdScrolldelay != 0)
cmd.Format("widget_set xbmc line%i 1 %i %i %i m %i \"%s\"\n", ln, ln, m_iColumns, ln, g_advancedSettings.m_lcdScrolldelay, strLineLong.c_str());
else
cmd.Format("widget_set xbmc line%i 1 %i \"%s\"\n", ln, ln, strLineLong.c_str());
if (write(sockfd, cmd.c_str(), cmd.size()) < 0)
{
m_bStop = true;
CLog::Log(LOGERROR, "XLCDproc::%s - Unable to write to socket, LCDd not running?", __FUNCTION__);
return;
}
m_bUpdate[iLine] = true;
m_strLine[iLine] = strLineLong;
m_event.Set();
}
}
void XLCDproc::Process()
{
}

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks