11 |
|
|
12 |
|
#include <foreach.hpp> |
13 |
|
#include <hash.hpp> |
14 |
– |
#include <iconv.hpp> |
14 |
|
#include <regex.hpp> |
15 |
|
#include <scopes.hpp> |
16 |
|
#include <timing.hpp> |
17 |
|
|
19 |
– |
#include <Audacious.hpp> |
18 |
|
#include <GPS.hpp> |
19 |
|
|
20 |
|
#include <sys/types.h> |
21 |
|
#include <sys/sysctl.h> |
22 |
|
#include <sys/utsname.h> |
23 |
|
|
26 |
– |
#include <sqlite3.h> |
27 |
– |
|
24 |
|
#include "Display.hpp" |
25 |
+ |
#include "MenuList.hpp" |
26 |
|
|
27 |
|
bool debug(false); |
28 |
|
|
31 |
|
enum Mode { Uname, Music, English, Metric, Nautical, Menu } mode, previous; |
32 |
|
enum { Running, Audio }; |
33 |
|
enum { Stopped, Paused, Playing } audio; |
37 |
– |
enum Level { Top, Artist, Album, Song } level; |
34 |
|
Timing::Time now; |
39 |
– |
IConv::IConv ascii; |
40 |
– |
Display display; |
41 |
– |
Pthreads::ThreadMutex displayLock; |
35 |
|
Audacious::Audacious audacious; |
36 |
|
//GPS::GPS gps; |
37 |
+ |
MusicLibrary::Library library; |
38 |
+ |
MenuList *list; |
39 |
+ |
bool append; |
40 |
+ |
Display display; |
41 |
+ |
Pthreads::ThreadMutex displayLock; |
42 |
|
|
43 |
< |
inline std::string Filter(const std::string input) |
43 |
> |
void Mode_(bool change = false) |
44 |
|
{ |
45 |
< |
std::string output(ascii.Convert(input)); |
45 |
> |
if (mode != Menu) |
46 |
> |
{ |
47 |
> |
char when[16]; |
48 |
|
|
49 |
< |
std::replace(output.begin(), output.end(), '~', char(206)); |
49 |
> |
std::strftime(when, sizeof (when), "%l:%M:%S %p %Z", std::localtime(now)); |
50 |
|
|
51 |
< |
return output; |
52 |
< |
} |
51 |
> |
display.Set(2, 0, when); |
52 |
> |
} |
53 |
|
|
54 |
– |
void Mode_(bool change = false) |
55 |
– |
{ |
54 |
|
switch (mode) |
55 |
|
{ |
56 |
|
case Uname: |
61 |
|
int position(audacious.GetPlaylistPosition()); |
62 |
|
std::string artist(Filter(audacious.GetTupleFieldData(_B("artist"), position))); |
63 |
|
|
64 |
< |
display.Set(0, 1, artist.size() > 20 ? artist.erase(20) : artist.append(20 - artist.size(), ' ')); |
64 |
> |
artist.resize(20, ' '); |
65 |
> |
display.Set(0, 1, artist); |
66 |
|
|
67 |
|
std::string title(Filter(audacious.GetTupleFieldData(_B("title"), position))); |
68 |
|
|
69 |
< |
display.Set(0, 2, title.size() > 20 ? title.erase(20) : title.append(20 - title.size(), ' ')); |
69 |
> |
title.resize(20, ' '); |
70 |
> |
display.Set(0, 2, title); |
71 |
|
|
72 |
|
int played(audacious.GetOutputTime() / 1000); |
73 |
|
int left(audacious.GetPlaylistTime(position) / 1000 - played); |
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), ' ')); |
78 |
> |
std::string times_(times); |
79 |
|
|
80 |
|
std::free(times); |
81 |
+ |
|
82 |
+ |
times_.resize(20, ' '); |
83 |
+ |
display.Set(0, 3, times_); |
84 |
|
} |
85 |
|
else |
86 |
|
{ |
100 |
|
return; |
101 |
|
case Menu: |
102 |
|
if (change) |
103 |
< |
level = Top; |
103 |
> |
{ |
104 |
> |
display.SetCursorPosition(19, 0); |
105 |
> |
display.SetCursorStyle(Display::InvertingBlinkingBlock); |
106 |
> |
|
107 |
> |
append = true; |
108 |
> |
list = new TopList(display, audacious, append, library); |
109 |
> |
|
110 |
> |
list->Render(); |
111 |
> |
} |
112 |
|
} |
113 |
|
} |
114 |
|
|
124 |
|
Pcre::RegEx::Match match(version(os.release)); |
125 |
|
std::string name(os.sysname + _B(" ") + match[1] + match[2] + match[3]); |
126 |
|
|
127 |
< |
display.Set(0, 1, name.append(20 - name.size(), ' ')); |
127 |
> |
name.resize(20, ' '); |
128 |
> |
display.Set(0, 1, name); |
129 |
|
} |
130 |
|
|
131 |
|
int mib[] = { CTL_KERN, KERN_BOOTTIME }; |
154 |
|
|
155 |
|
std::string then(when); |
156 |
|
|
145 |
– |
then.append(17 - std::strlen(when), ' '); |
146 |
– |
|
157 |
|
std::free(when); |
158 |
|
|
159 |
+ |
then.resize(17, ' '); |
160 |
+ |
|
161 |
|
if (change) |
162 |
|
display.Set(0, 2, _B("up ") + then); |
163 |
|
else |
176 |
|
|
177 |
|
::asprintf(&load, "%.2f, %.2f, %.2f", averages[0], averages[1] , averages[2]); |
178 |
|
|
179 |
< |
display.Set(0, 3, load + std::string(20 - std::strlen(load), ' ')); |
179 |
> |
std::string load_(load); |
180 |
|
|
181 |
|
std::free(load); |
182 |
+ |
|
183 |
+ |
load_.resize(20, ' '); |
184 |
+ |
display.Set(0, 3, load_); |
185 |
|
} |
186 |
|
} |
187 |
|
|
234 |
|
switch (activity) |
235 |
|
{ |
236 |
|
case Display::UpPress: |
237 |
+ |
return (--*list).Render(); |
238 |
|
case Display::DownPress: |
239 |
+ |
return (++*list).Render(); |
240 |
|
case Display::LeftPress: |
241 |
+ |
list = list->Left(); |
242 |
+ |
|
243 |
+ |
goto render; |
244 |
|
case Display::RightPress: |
245 |
+ |
list = list->Right(); |
246 |
+ |
|
247 |
+ |
goto render; |
248 |
|
case Display::EnterPress: |
249 |
< |
return; |
249 |
> |
list = list->Enter(); |
250 |
> |
|
251 |
> |
render: if (list != NULL) |
252 |
> |
return list->Render(); |
253 |
> |
|
254 |
> |
goto exit; |
255 |
|
case Display::ExitPress: |
256 |
< |
mode = previous; |
256 |
> |
delete list; |
257 |
> |
|
258 |
> |
exit: mode = previous; |
259 |
|
|
260 |
+ |
display.SetCursorStyle(Display::NoCursor); |
261 |
|
display.Set(0, 0, _B(" ")); |
262 |
|
display.Set(18, 0, _B(" ")); |
263 |
|
|
268 |
|
} |
269 |
|
|
270 |
|
public: |
271 |
< |
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) |
271 |
> |
DashInterface(const std::string &device) : mode(Uname), audio(Stopped), display(device, reinterpret_cast<Display::Callback>(::Buttons), this) |
272 |
|
{ |
273 |
|
_synchronized (displayLock) |
274 |
|
{ |
275 |
|
display.Clear(); |
276 |
+ |
display.SetCursorStyle(Display::NoCursor); |
277 |
|
display.SetBacklight(100); |
278 |
|
display.Set(2, 0, _B("--:--:-- -- ---")); |
279 |
|
|
302 |
|
{ |
303 |
|
now = Timing::GetTimeOfDay(); |
304 |
|
|
273 |
– |
if (mode != Menu) |
274 |
– |
{ |
275 |
– |
char when[16]; |
276 |
– |
|
277 |
– |
std::strftime(when, sizeof (when), "%l:%M:%S %p %Z", std::localtime(now)); |
278 |
– |
|
279 |
– |
display.Set(2, 0, when); |
280 |
– |
} |
281 |
– |
|
305 |
|
if (audacious.IsRunning() && audacious.IsPlaying()) |
306 |
|
if (audacious.IsPaused()) |
307 |
|
{ |