4 |
|
// |
5 |
|
// $Id$ |
6 |
|
|
7 |
+ |
#include <algorithm> |
8 |
|
#include <iomanip> |
9 |
|
#include <iostream> |
10 |
|
#include <sstream> |
11 |
|
|
12 |
|
#include <foreach.hpp> |
13 |
|
#include <hash.hpp> |
14 |
+ |
#include <iconv.hpp> |
15 |
|
#include <regex.hpp> |
16 |
|
#include <scopes.hpp> |
17 |
|
#include <timing.hpp> |
23 |
|
#include <sys/sysctl.h> |
24 |
|
#include <sys/utsname.h> |
25 |
|
|
24 |
– |
#include <sqlite3.h> |
25 |
– |
|
26 |
|
#include "Display.hpp" |
27 |
+ |
#include "MenuList.hpp" |
28 |
|
|
29 |
|
bool debug(false); |
30 |
|
|
31 |
|
class DashInterface |
32 |
|
{ |
33 |
< |
enum Mode { Uname, Music, English, Metric, Nautical, Menu } mode; |
34 |
< |
enum { Running }; |
33 |
> |
enum Mode { Uname, Music, English, Metric, Nautical, Menu } mode, previous; |
34 |
> |
enum { Running, Audio }; |
35 |
> |
enum { Stopped, Paused, Playing } audio; |
36 |
|
Timing::Time now; |
37 |
+ |
IConv::IConv ascii; |
38 |
|
Display display; |
39 |
|
Pthreads::ThreadMutex displayLock; |
40 |
< |
//Audacious::Audacious audacious; |
40 |
> |
Audacious::Audacious audacious; |
41 |
|
//GPS::GPS gps; |
42 |
+ |
MenuList *list; |
43 |
+ |
bool append; |
44 |
+ |
|
45 |
+ |
inline std::string Filter(const std::string input) |
46 |
+ |
{ |
47 |
+ |
std::string output(ascii.Convert(input)); |
48 |
+ |
|
49 |
+ |
std::replace(output.begin(), output.end(), '~', '\xce'); |
50 |
+ |
|
51 |
+ |
return output; |
52 |
+ |
} |
53 |
|
|
54 |
|
void Mode_(bool change = false) |
55 |
|
{ |
56 |
|
switch (mode) |
57 |
|
{ |
58 |
|
case Uname: |
59 |
< |
Uname_(change); |
46 |
< |
|
47 |
< |
break; |
59 |
> |
return Uname_(change); |
60 |
|
case Music: |
61 |
+ |
if (audacious.IsRunning()) |
62 |
+ |
{ |
63 |
+ |
int position(audacious.GetPlaylistPosition()); |
64 |
+ |
std::string artist(Filter(audacious.GetTupleFieldData(_B("artist"), position))); |
65 |
+ |
|
66 |
+ |
artist.resize(20, ' '); |
67 |
+ |
display.Set(0, 1, artist); |
68 |
+ |
|
69 |
+ |
std::string title(Filter(audacious.GetTupleFieldData(_B("title"), position))); |
70 |
+ |
|
71 |
+ |
title.resize(20, ' '); |
72 |
+ |
display.Set(0, 2, title); |
73 |
+ |
|
74 |
+ |
int played(audacious.GetOutputTime() / 1000); |
75 |
+ |
int left(audacious.GetPlaylistTime(position) / 1000 - played); |
76 |
+ |
char *times; |
77 |
+ |
|
78 |
+ |
::asprintf(×, "%2i:%02i -%2i:%02i", played / 60, played % 60, left / 60, left % 60); |
79 |
+ |
|
80 |
+ |
std::string times_(times); |
81 |
+ |
|
82 |
+ |
std::free(times); |
83 |
+ |
|
84 |
+ |
times_.resize(20, ' '); |
85 |
+ |
display.Set(0, 3, times_); |
86 |
+ |
} |
87 |
+ |
else |
88 |
+ |
{ |
89 |
+ |
display.Set(0, 1, std::string(20, ' ')); |
90 |
+ |
display.Set(0, 2, std::string(20, ' ')); |
91 |
+ |
display.Set(0, 3, _B(" -:-- - -:-- ")); |
92 |
+ |
} |
93 |
+ |
|
94 |
+ |
return; |
95 |
|
case English: |
96 |
|
case Metric: |
97 |
|
case Nautical: |
98 |
+ |
display.Set(0, 1, _B("STUB: GPS ") + (mode == English ? _B("English ") : mode == Metric ? _B("Metric ") : _B("Nautical "))); |
99 |
+ |
display.Set(0, 2, std::string(20, ' ')); |
100 |
+ |
display.Set(0, 3, std::string(20, ' ')); |
101 |
+ |
|
102 |
+ |
return; |
103 |
|
case Menu: |
104 |
< |
break; |
104 |
> |
if (change) |
105 |
> |
{ |
106 |
> |
display.SetCursorStyle(Display::InvertingBlinkingBlock); |
107 |
> |
|
108 |
> |
append = true; |
109 |
> |
list = new TopList(display, audacious, append); |
110 |
> |
|
111 |
> |
list->Render(); |
112 |
> |
} |
113 |
|
} |
114 |
|
} |
115 |
|
|
123 |
|
|
124 |
|
static Pcre::RegEx version(_B("^(\\d+\\.\\d+)-([A-Z])[A-Z]*(-p\\d+)?.*$")); |
125 |
|
Pcre::RegEx::Match match(version(os.release)); |
126 |
+ |
std::string name(os.sysname + _B(" ") + match[1] + match[2] + match[3]); |
127 |
|
|
128 |
< |
display.Set(0, 1, os.sysname + _B(" ") + match[1] + match[2] + match[3]); |
128 |
> |
name.resize(20, ' '); |
129 |
> |
display.Set(0, 1, name); |
130 |
|
} |
131 |
|
|
132 |
|
int mib[] = { CTL_KERN, KERN_BOOTTIME }; |
155 |
|
|
156 |
|
std::string then(when); |
157 |
|
|
97 |
– |
then.append(17 - std::strlen(when), ' '); |
98 |
– |
|
158 |
|
std::free(when); |
159 |
|
|
160 |
+ |
then.resize(17, ' '); |
161 |
+ |
|
162 |
|
if (change) |
163 |
|
display.Set(0, 2, _B("up ") + then); |
164 |
|
else |
177 |
|
|
178 |
|
::asprintf(&load, "%.2f, %.2f, %.2f", averages[0], averages[1] , averages[2]); |
179 |
|
|
180 |
< |
display.Set(0, 3, load + std::string(20 - std::strlen(load), ' ')); |
180 |
> |
std::string load_(load); |
181 |
|
|
182 |
|
std::free(load); |
183 |
+ |
|
184 |
+ |
load_.resize(20, ' '); |
185 |
+ |
display.Set(0, 3, load_); |
186 |
|
} |
187 |
|
} |
188 |
|
|
204 |
|
|
205 |
|
goto change; |
206 |
|
case Display::LeftPress: |
207 |
< |
std::cerr << _B("Previous") << std::endl; |
207 |
> |
if (audacious.IsRunning()) |
208 |
> |
audacious.PlaylistPrevious(); |
209 |
|
|
210 |
|
goto update; |
211 |
|
case Display::RightPress: |
212 |
< |
std::cerr << _B("Next") << std::endl; |
212 |
> |
if (audacious.IsRunning()) |
213 |
> |
audacious.PlaylistNext(); |
214 |
|
|
215 |
|
goto update; |
216 |
|
case Display::EnterPress: |
217 |
< |
std::cerr << _B("Menu") << std::endl; |
152 |
< |
|
217 |
> |
previous = mode; |
218 |
|
mode = Menu; |
219 |
|
|
220 |
|
goto change; |
221 |
|
case Display::ExitPress: |
222 |
< |
std::cerr << _B("Play/Pause") << std::endl; |
222 |
> |
if (audacious.IsRunning()) |
223 |
> |
audacious.PlayPause(); |
224 |
|
|
225 |
|
goto update; |
226 |
|
default: |
232 |
|
update: Mode_(change); |
233 |
|
} |
234 |
|
else |
235 |
< |
return; |
235 |
> |
switch (activity) |
236 |
> |
{ |
237 |
> |
case Display::UpPress: |
238 |
> |
return (++*list).Render(); |
239 |
> |
case Display::DownPress: |
240 |
> |
return (--*list).Render(); |
241 |
> |
case Display::LeftPress: |
242 |
> |
list = list->Left(); |
243 |
> |
|
244 |
> |
goto render; |
245 |
> |
case Display::RightPress: |
246 |
> |
list = list->Right(); |
247 |
> |
|
248 |
> |
goto render; |
249 |
> |
case Display::EnterPress: |
250 |
> |
list = list->Enter(); |
251 |
> |
|
252 |
> |
render: if (list != NULL) |
253 |
> |
return list->Render(); |
254 |
> |
|
255 |
> |
goto exit; |
256 |
> |
case Display::ExitPress: |
257 |
> |
delete list; |
258 |
> |
|
259 |
> |
exit: mode = previous; |
260 |
> |
|
261 |
> |
display.SetCursorStyle(Display::NoCursor); |
262 |
> |
display.Set(0, 0, _B(" ")); |
263 |
> |
display.Set(18, 0, _B(" ")); |
264 |
> |
|
265 |
> |
Mode_(true); |
266 |
> |
default: |
267 |
> |
return; |
268 |
> |
} |
269 |
|
} |
270 |
|
|
271 |
|
public: |
272 |
< |
DashInterface(const std::string &device) : mode(Uname), display(device, reinterpret_cast<Display::Callback>(::Buttons), this) |
272 |
> |
DashInterface(const std::string &device) : mode(Uname), audio(Stopped), ascii(_B("ASCII//TRANSLIT//IGNORE"), _B("UTF-8")), display(device, reinterpret_cast<Display::Callback>(::Buttons), this) |
273 |
|
{ |
274 |
|
_synchronized (displayLock) |
275 |
|
{ |
279 |
|
|
280 |
|
display.Set(Running, Display::Green, 0); |
281 |
|
display.Set(Running, Display::Red, 100); |
282 |
+ |
display.Set(Audio, Display::Green, 0); |
283 |
+ |
display.Set(Audio, Display::Red, 100); |
284 |
|
|
285 |
|
uint8_t mask(Display::Up | Display::Enter | Display::Cancel | Display::Left | Display::Right | Display::Down); |
286 |
|
|
311 |
|
display.Set(2, 0, when); |
312 |
|
} |
313 |
|
|
314 |
+ |
if (audacious.IsRunning() && audacious.IsPlaying()) |
315 |
+ |
if (audacious.IsPaused()) |
316 |
+ |
{ |
317 |
+ |
if (audio != Paused) |
318 |
+ |
{ |
319 |
+ |
display.Set(Audio, Display::Green, 100); |
320 |
+ |
display.Set(Audio, Display::Red, 100); |
321 |
+ |
|
322 |
+ |
audio = Paused; |
323 |
+ |
} |
324 |
+ |
} |
325 |
+ |
else |
326 |
+ |
{ |
327 |
+ |
if (audio != Playing) |
328 |
+ |
{ |
329 |
+ |
display.Set(Audio, Display::Green, 100); |
330 |
+ |
display.Set(Audio, Display::Red, 0); |
331 |
+ |
|
332 |
+ |
audio = Playing; |
333 |
+ |
} |
334 |
+ |
} |
335 |
+ |
else if (audio != Stopped) |
336 |
+ |
{ |
337 |
+ |
display.Set(Audio, Display::Green, 0); |
338 |
+ |
display.Set(Audio, Display::Red, 100); |
339 |
+ |
|
340 |
+ |
audio = Stopped; |
341 |
+ |
} |
342 |
+ |
|
343 |
|
Mode_(); |
344 |
|
} |
345 |
|
|