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> |
31 |
|
|
32 |
|
class DashInterface |
33 |
|
{ |
34 |
< |
enum Mode { Uname, Music, English, Metric, Nautical, Menu } mode; |
35 |
< |
enum { Running }; |
34 |
> |
enum Mode { Uname, Music, English, Metric, Nautical, Menu } mode, previous; |
35 |
> |
enum { Running, Audio }; |
36 |
> |
enum { Stopped, Paused, Playing } audio; |
37 |
> |
enum Level { Top, Artist, Album, Song } level; |
38 |
|
Timing::Time now; |
39 |
+ |
IConv::IConv ascii; |
40 |
|
Display display; |
41 |
|
Pthreads::ThreadMutex displayLock; |
42 |
< |
//Audacious::Audacious audacious; |
42 |
> |
Audacious::Audacious audacious; |
43 |
|
//GPS::GPS gps; |
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(), '~', char(206)); |
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 |
+ |
display.Set(0, 1, artist.size() > 20 ? artist.erase(20) : artist.append(20 - artist.size(), ' ')); |
67 |
+ |
|
68 |
+ |
std::string title(Filter(audacious.GetTupleFieldData(_B("title"), position))); |
69 |
+ |
|
70 |
+ |
display.Set(0, 2, title.size() > 20 ? title.erase(20) : title.append(20 - title.size(), ' ')); |
71 |
+ |
|
72 |
+ |
int played(audacious.GetOutputTime() / 1000); |
73 |
+ |
int left(audacious.GetPlaylistTime(position) / 1000 - played); |
74 |
+ |
char *times; |
75 |
+ |
|
76 |
+ |
::asprintf(×, "%2i:%02i -%2i:%02i", played / 60, played % 60, left / 60, left % 60); |
77 |
+ |
|
78 |
+ |
display.Set(0, 3, times + std::string(20 - std::strlen(times), ' ')); |
79 |
+ |
|
80 |
+ |
std::free(times); |
81 |
+ |
} |
82 |
+ |
else |
83 |
+ |
{ |
84 |
+ |
display.Set(0, 1, std::string(20, ' ')); |
85 |
+ |
display.Set(0, 2, std::string(20, ' ')); |
86 |
+ |
display.Set(0, 3, _B(" -:-- - -:-- ")); |
87 |
+ |
} |
88 |
+ |
|
89 |
+ |
return; |
90 |
|
case English: |
91 |
|
case Metric: |
92 |
|
case Nautical: |
93 |
+ |
display.Set(0, 1, _B("STUB: GPS ") + (mode == English ? _B("English ") : mode == Metric ? _B("Metric ") : _B("Nautical "))); |
94 |
+ |
display.Set(0, 2, std::string(20, ' ')); |
95 |
+ |
display.Set(0, 3, std::string(20, ' ')); |
96 |
+ |
|
97 |
+ |
return; |
98 |
|
case Menu: |
99 |
< |
break; |
99 |
> |
if (change) |
100 |
> |
level = Top; |
101 |
|
} |
102 |
|
} |
103 |
|
|
111 |
|
|
112 |
|
static Pcre::RegEx version(_B("^(\\d+\\.\\d+)-([A-Z])[A-Z]*(-p\\d+)?.*$")); |
113 |
|
Pcre::RegEx::Match match(version(os.release)); |
114 |
+ |
std::string name(os.sysname + _B(" ") + match[1] + match[2] + match[3]); |
115 |
|
|
116 |
< |
display.Set(0, 1, os.sysname + _B(" ") + match[1] + match[2] + match[3]); |
116 |
> |
display.Set(0, 1, name.append(20 - name.size(), ' ')); |
117 |
|
} |
118 |
|
|
119 |
|
int mib[] = { CTL_KERN, KERN_BOOTTIME }; |
188 |
|
|
189 |
|
goto change; |
190 |
|
case Display::LeftPress: |
191 |
< |
std::cerr << _B("Previous") << std::endl; |
191 |
> |
if (audacious.IsRunning()) |
192 |
> |
audacious.PlaylistPrevious(); |
193 |
|
|
194 |
|
goto update; |
195 |
|
case Display::RightPress: |
196 |
< |
std::cerr << _B("Next") << std::endl; |
196 |
> |
if (audacious.IsRunning()) |
197 |
> |
audacious.PlaylistNext(); |
198 |
|
|
199 |
|
goto update; |
200 |
|
case Display::EnterPress: |
201 |
< |
std::cerr << _B("Menu") << std::endl; |
152 |
< |
|
201 |
> |
previous = mode; |
202 |
|
mode = Menu; |
203 |
|
|
204 |
|
goto change; |
205 |
|
case Display::ExitPress: |
206 |
< |
std::cerr << _B("Play/Pause") << std::endl; |
206 |
> |
if (audacious.IsRunning()) |
207 |
> |
audacious.PlayPause(); |
208 |
|
|
209 |
|
goto update; |
210 |
|
default: |
216 |
|
update: Mode_(change); |
217 |
|
} |
218 |
|
else |
219 |
< |
return; |
219 |
> |
switch (activity) |
220 |
> |
{ |
221 |
> |
case Display::UpPress: |
222 |
> |
case Display::DownPress: |
223 |
> |
case Display::LeftPress: |
224 |
> |
case Display::RightPress: |
225 |
> |
case Display::EnterPress: |
226 |
> |
return; |
227 |
> |
case Display::ExitPress: |
228 |
> |
mode = previous; |
229 |
> |
|
230 |
> |
display.Set(0, 0, _B(" ")); |
231 |
> |
display.Set(18, 0, _B(" ")); |
232 |
> |
|
233 |
> |
Mode_(true); |
234 |
> |
default: |
235 |
> |
return; |
236 |
> |
} |
237 |
|
} |
238 |
|
|
239 |
|
public: |
240 |
< |
DashInterface(const std::string &device) : mode(Uname), display(device, reinterpret_cast<Display::Callback>(::Buttons), this) |
240 |
> |
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) |
241 |
|
{ |
242 |
|
_synchronized (displayLock) |
243 |
|
{ |
247 |
|
|
248 |
|
display.Set(Running, Display::Green, 0); |
249 |
|
display.Set(Running, Display::Red, 100); |
250 |
+ |
display.Set(Audio, Display::Green, 0); |
251 |
+ |
display.Set(Audio, Display::Red, 100); |
252 |
|
|
253 |
|
uint8_t mask(Display::Up | Display::Enter | Display::Cancel | Display::Left | Display::Right | Display::Down); |
254 |
|
|
279 |
|
display.Set(2, 0, when); |
280 |
|
} |
281 |
|
|
282 |
+ |
if (audacious.IsRunning() && audacious.IsPlaying()) |
283 |
+ |
if (audacious.IsPaused()) |
284 |
+ |
{ |
285 |
+ |
if (audio != Paused) |
286 |
+ |
{ |
287 |
+ |
display.Set(Audio, Display::Green, 100); |
288 |
+ |
display.Set(Audio, Display::Red, 100); |
289 |
+ |
|
290 |
+ |
audio = Paused; |
291 |
+ |
} |
292 |
+ |
} |
293 |
+ |
else |
294 |
+ |
{ |
295 |
+ |
if (audio != Playing) |
296 |
+ |
{ |
297 |
+ |
display.Set(Audio, Display::Green, 100); |
298 |
+ |
display.Set(Audio, Display::Red, 0); |
299 |
+ |
|
300 |
+ |
audio = Playing; |
301 |
+ |
} |
302 |
+ |
} |
303 |
+ |
else if (audio != Stopped) |
304 |
+ |
{ |
305 |
+ |
display.Set(Audio, Display::Green, 0); |
306 |
+ |
display.Set(Audio, Display::Red, 100); |
307 |
+ |
|
308 |
+ |
audio = Stopped; |
309 |
+ |
} |
310 |
+ |
|
311 |
|
Mode_(); |
312 |
|
} |
313 |
|
|