ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/truck/DashInterface/Display.cpp
(Generate patch)

Comparing:
SteeringWheelRemote/Audacious.cpp (file contents), Revision 7 by douglas, 2007-05-06T22:12:04-07:00 vs.
DashInterface/Display.cpp (file contents), Revision 28 by douglas, 2008-02-25T21:13:59-08:00

# Line 1 | Line 1
1 < // Beep Remote
1 > // Display (Crystalfontz CFA-635 USB LCD)
2   //
3   // Douglas Thrift
4   //
5   // $Id$
6  
7 < #include <audacious/beepctrl.h>
7 > #include <foreach.hpp>
8  
9 < #include "Audacious.hpp"
9 > #include <iostream>
10  
11 < void Audacious::Playlist(char **list, int size, bool enqueue)
12 < {
13 <        ::xmms_remote_playlist(session, list, size, enqueue);
14 < }
15 <
16 < int Audacious::GetVersion() const
17 < {
18 <        return ::xmms_remote_get_version(session);
19 < }
20 <
21 < void Audacious::PlaylistAdd(::GList *list)
22 < {
23 <        ::xmms_remote_playlist_add(session, list);
24 < }
25 <
26 < void Audacious::PlaylistDelete(int position)
27 < {
28 <        ::xmms_remote_playlist_delete(session, position);
29 < }
30 <
31 < void Audacious::Play()
32 < {
33 <        ::xmms_remote_play(session);
34 < }
35 <
36 < void Audacious::Pause()
37 < {
38 <        ::xmms_remote_pause(session);
39 < }
40 <
41 < void Audacious::Stop()
42 < {
43 <        ::xmms_remote_stop(session);
44 < }
45 <
46 < bool Audacious::IsPlaying() const
47 < {
48 <        return ::xmms_remote_is_playing(session);
49 < }
50 <
51 < bool Audacious::IsPaused() const
52 < {
53 <        return ::xmms_remote_is_paused(session);
54 < }
55 <
56 < int Audacious::GetPlaylistPosition() const
57 < {
58 <        return ::xmms_remote_get_playlist_pos(session);
59 < }
60 <
61 < void Audacious::SetPlaylistPosition(int position)
62 < {
63 <        ::xmms_remote_set_playlist_pos(session, position);
64 < }
65 <
66 < int Audacious::GetPlaylistLength() const
67 < {
68 <        return ::xmms_remote_get_playlist_length(session);
69 < }
70 <
71 < void Audacious::PlaylistClear()
72 < {
73 <        return ::xmms_remote_playlist_clear(session);
74 < }
75 <
76 < int Audacious::GetOutputTime() const
77 < {
78 <        return ::xmms_remote_get_output_time(session);
79 < }
80 <
81 < void Audacious::JumpToTime(int position)
82 < {
83 <        ::xmms_remote_jump_to_time(session, position);
84 < }
85 <
86 < void Audacious::GetVolume(int& left, int& right) const
87 < {
88 <        ::xmms_remote_get_volume(session, &left, &right);
89 < }
90 <
91 < int Audacious::GetMainVolume() const
92 < {
93 <        return ::xmms_remote_get_main_volume(session);
94 < }
95 <
96 < int Audacious::GetBalance() const
97 < {
98 <        return ::xmms_remote_get_balance(session);
99 < }
100 <
101 < void Audacious::SetVolume(int left, int right)
102 < {
103 <        ::xmms_remote_set_volume(session, left, right);
104 < }
105 <
106 < void Audacious::SetMainVolume(int volume)
107 < {
108 <        ::xmms_remote_set_main_volume(session, volume);
109 < }
110 <
111 < void Audacious::SetBalance(int balance)
112 < {
113 <        ::xmms_remote_set_balance(session, balance);
114 < }
115 <
116 < std::string Audacious::GetSkin() const
117 < {
118 <        return ::xmms_remote_get_skin(session);
119 < }
120 <
121 < void Audacious::SetSkin(const std::string &skin)
122 < {
123 <        ::xmms_remote_set_skin(session, const_cast<char*>(skin.c_str()));
124 < }
125 <
126 < std::string Audacious::GetPlaylistFile(int position) const
127 < {
128 <        return ::xmms_remote_get_playlist_file(session, position);
129 < }
130 <
131 < std::string Audacious::GetPlaylistTitle(int position) const
132 < {
133 <        return ::xmms_remote_get_playlist_title(session, position);
134 < }
135 <
136 < int Audacious::GetPlaylistTime(int position) const
137 < {
138 <        return ::xmms_remote_get_playlist_time(session, position);
139 < }
11 > #include <fcntl.h>
12 > #include <termios.h>
13  
14 < void Audacious::GetInfo(int &rate, int &frequency, int &channels) const
142 < {
143 <        ::xmms_remote_get_info(session, &rate, &frequency, &channels);
144 < }
14 > #include "Display.hpp"
15  
16 < void Audacious::MainWindowToggle(bool show)
147 < {
148 <        ::xmms_remote_main_win_toggle(session, show);
149 < }
16 > extern bool debug;
17  
18 < void Audacious::PlaylistWindowToggle(bool show)
18 > static uint16_t GetCRC(uint8_t *buffer, size_t length)
19   {
20 <        ::xmms_remote_pl_win_toggle(session, show);
21 < }
20 >        static const uint16_t table[256] = {
21 >                0x00000,0x01189,0x02312,0x0329B,0x04624,0x057AD,0x06536,0x074BF,
22 >                0x08C48,0x09DC1,0x0AF5A,0x0BED3,0x0CA6C,0x0DBE5,0x0E97E,0x0F8F7,
23 >                0x01081,0x00108,0x03393,0x0221A,0x056A5,0x0472C,0x075B7,0x0643E,
24 >                0x09CC9,0x08D40,0x0BFDB,0x0AE52,0x0DAED,0x0CB64,0x0F9FF,0x0E876,
25 >                0x02102,0x0308B,0x00210,0x01399,0x06726,0x076AF,0x04434,0x055BD,
26 >                0x0AD4A,0x0BCC3,0x08E58,0x09FD1,0x0EB6E,0x0FAE7,0x0C87C,0x0D9F5,
27 >                0x03183,0x0200A,0x01291,0x00318,0x077A7,0x0662E,0x054B5,0x0453C,
28 >                0x0BDCB,0x0AC42,0x09ED9,0x08F50,0x0FBEF,0x0EA66,0x0D8FD,0x0C974,
29 >                0x04204,0x0538D,0x06116,0x0709F,0x00420,0x015A9,0x02732,0x036BB,
30 >                0x0CE4C,0x0DFC5,0x0ED5E,0x0FCD7,0x08868,0x099E1,0x0AB7A,0x0BAF3,
31 >                0x05285,0x0430C,0x07197,0x0601E,0x014A1,0x00528,0x037B3,0x0263A,
32 >                0x0DECD,0x0CF44,0x0FDDF,0x0EC56,0x098E9,0x08960,0x0BBFB,0x0AA72,
33 >                0x06306,0x0728F,0x04014,0x0519D,0x02522,0x034AB,0x00630,0x017B9,
34 >                0x0EF4E,0x0FEC7,0x0CC5C,0x0DDD5,0x0A96A,0x0B8E3,0x08A78,0x09BF1,
35 >                0x07387,0x0620E,0x05095,0x0411C,0x035A3,0x0242A,0x016B1,0x00738,
36 >                0x0FFCF,0x0EE46,0x0DCDD,0x0CD54,0x0B9EB,0x0A862,0x09AF9,0x08B70,
37 >                0x08408,0x09581,0x0A71A,0x0B693,0x0C22C,0x0D3A5,0x0E13E,0x0F0B7,
38 >                0x00840,0x019C9,0x02B52,0x03ADB,0x04E64,0x05FED,0x06D76,0x07CFF,
39 >                0x09489,0x08500,0x0B79B,0x0A612,0x0D2AD,0x0C324,0x0F1BF,0x0E036,
40 >                0x018C1,0x00948,0x03BD3,0x02A5A,0x05EE5,0x04F6C,0x07DF7,0x06C7E,
41 >                0x0A50A,0x0B483,0x08618,0x09791,0x0E32E,0x0F2A7,0x0C03C,0x0D1B5,
42 >                0x02942,0x038CB,0x00A50,0x01BD9,0x06F66,0x07EEF,0x04C74,0x05DFD,
43 >                0x0B58B,0x0A402,0x09699,0x08710,0x0F3AF,0x0E226,0x0D0BD,0x0C134,
44 >                0x039C3,0x0284A,0x01AD1,0x00B58,0x07FE7,0x06E6E,0x05CF5,0x04D7C,
45 >                0x0C60C,0x0D785,0x0E51E,0x0F497,0x08028,0x091A1,0x0A33A,0x0B2B3,
46 >                0x04A44,0x05BCD,0x06956,0x078DF,0x00C60,0x01DE9,0x02F72,0x03EFB,
47 >                0x0D68D,0x0C704,0x0F59F,0x0E416,0x090A9,0x08120,0x0B3BB,0x0A232,
48 >                0x05AC5,0x04B4C,0x079D7,0x0685E,0x01CE1,0x00D68,0x03FF3,0x02E7A,
49 >                0x0E70E,0x0F687,0x0C41C,0x0D595,0x0A12A,0x0B0A3,0x08238,0x093B1,
50 >                0x06B46,0x07ACF,0x04854,0x059DD,0x02D62,0x03CEB,0x00E70,0x01FF9,
51 >                0x0F78F,0x0E606,0x0D49D,0x0C514,0x0B1AB,0x0A022,0x092B9,0x08330,
52 >                0x07BC7,0x06A4E,0x058D5,0x0495C,0x03DE3,0x02C6A,0x01EF1,0x00F78,
53 >        };
54 >        register uint16_t crc(0xffff);
55  
56 < void Audacious::EqualizerWindowToggle(bool show)
57 < {
158 <        ::xmms_remote_eq_win_toggle(session, show);
159 < }
56 >        while (length--)
57 >                crc = (crc >> 8) ^ table[(crc ^ *buffer++) & 0xff];
58  
59 < bool Audacious::IsMainWindow() const
162 < {
163 <        return ::xmms_remote_is_main_win(session);
59 >        return ~crc;
60   }
61  
62 < bool Audacious::IsPlaylistWindow() const
62 > Display::Packet::Packet(Display::Packet::Command command, uint8_t length, const uint8_t *data) : command(command), length(length)
63   {
64 <        return ::xmms_remote_is_pl_win(session);
65 < }
64 >        if (length > sizeof (this->data))
65 >                throw;
66  
67 < bool Audacious::IsEqualizerWindow() const
172 < {
173 <        return ::xmms_remote_is_eq_win(session);
174 < }
67 >        ::memcpy(this->data, data, length);
68  
69 < void Audacious::ShowPreferencesBox()
177 < {
178 <        ::xmms_remote_show_prefs_box(session);
69 >        crc = GetCRC(reinterpret_cast<uint8_t *>(this), length + 2);
70   }
71  
72 < void Audacious::ToggleAlwaysOnTop(bool always)
72 > void operator<<(int fd, const Display::Packet::Packet &packet)
73   {
74 <        ::xmms_remote_toggle_aot(session, always);
75 < }
74 >        if (packet.length != sizeof (packet.data))
75 >                ::memcpy(const_cast<uint8_t *>(packet.data) + packet.length, &packet.crc, 2);
76  
77 < void Audacious::Eject()
187 < {
188 <        ::xmms_remote_eject(session);
77 >        Posix::Write(fd, &packet, packet.length + 4);
78   }
79  
80 < void Audacious::PlaylistPrevious()
80 > void operator>>(int fd, Display::Packet::Packet &packet)
81   {
82 <        ::xmms_remote_playlist_prev(session);
83 < }
82 >        Posix::Read(fd, &packet, 2);
83 >        Posix::Read(fd, packet.data, packet.length);
84 >        Posix::Read(fd, &packet.crc, 2);
85  
86 < void Audacious::PlaylistNext()
87 < {
88 <        ::xmms_remote_playlist_next(session);
199 < }
86 >        if (debug)
87 >        {
88 >                char *data;
89  
90 < void Audacious::PlaylistAddUrl(const std::string &url)
202 < {
203 <        ::xmms_remote_playlist_add_url_string(session, const_cast<char*>(url.c_str()));
204 < }
90 >                ::asprintf(&data, "0x%02x %i ", packet.command, packet.length);
91  
92 < bool Audacious::IsRunning() const
207 < {
208 <        return ::xmms_remote_is_running(session);
209 < }
210 <
211 < void Audacious::ToggleRepeat()
212 < {
213 <        ::xmms_remote_toggle_repeat(session);
214 < }
215 <
216 < void Audacious::ToggleShuffle()
217 < {
218 <        ::xmms_remote_toggle_shuffle(session);
219 < }
92 >                std::cerr << data << '[' << packet.GetData() << ']' << std::endl;
93  
94 < bool Audacious::IsRepeat() const
95 < {
223 <        return ::xmms_remote_is_repeat(session);
94 >                std::free(data);
95 >        }
96   }
97  
98 < bool Audacious::IsShuffle() const
98 > Display::Display(const std::string &device) : ucom(Posix::Open(device, O_RDWR | O_NOCTTY))
99   {
100 <        return ::xmms_remote_is_shuffle(session);
229 < }
100 >        ::termios state;
101  
102 < void Audacious::GetEqualizer(float& preamp, float bands[10]) const
103 < {
104 <        float* bands_;
102 >        Posix::CheckError(::tcgetattr(ucom, &state));
103 >        Posix::CheckError(::cfsetospeed(&state, B115200));
104 >        Posix::CheckError(::cfsetispeed(&state, B115200));
105  
106 <        ::xmms_remote_get_eq(session, &preamp, &bands_);
106 >        state.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | INPCK | ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXOFF);
107 >        state.c_iflag |= IGNPAR;
108 >        state.c_oflag &= ~(OPOST | ONLCR | ONOCR | ONLRET);
109 >        state.c_cflag &= ~(CSIZE | PARENB | PARODD | HUPCL | CRTSCTS);
110 >        state.c_cflag |= CREAD | CS8 | CSTOPB | CLOCAL;
111 >        state.c_lflag &= ~(ISIG | ICANON | IEXTEN | ECHO);
112 >        state.c_lflag |= NOFLSH;
113  
114 <        _forall (uint8_t, index, 0, 10)
238 <                bands[index] = bands[index];
239 <
240 <        ::g_free(bands_);
114 >        Posix::CheckError(::tcsetattr(ucom, TCSANOW, &state));
115   }
116  
117 < float Audacious::GetEqualizerPreamp() const
117 > Display::Packet Display::Communicate(Display::Packet::Command command, uint8_t length, const uint8_t *data)
118   {
119 <        return ::xmms_remote_get_eq_preamp(session);
246 < }
119 >        Packet packet(command, length, data), response;
120  
121 < float Audacious::GetEqualizerBand(int band) const
249 < {
250 <        return ::xmms_remote_get_eq_band(session, band);
251 < }
121 >        ucom << packet;
122  
123 < void Audacious::SetEqualizer(float preamp, float bands[10])
124 < {
125 <        ::xmms_remote_set_eq(session, preamp, bands);
256 < }
123 >        _forever
124 >        {
125 >                ucom >> response;
126  
127 < void Audacious::SetEqualizerPreamp(float preamp)
128 < {
260 <        ::xmms_remote_set_eq_preamp(session, preamp);
261 < }
127 >                if (packet.command | Packet::Response == response.command)
128 >                        return response;
129  
130 < void Audacious::SetEqualizerBand(int band, float value)
131 < {
132 <        ::xmms_remote_set_eq_band(session, band, value);
133 < }
267 <
268 < // XMMS 1.2.1
269 < void Audacious::Quit()
270 < {
271 <        ::xmms_remote_quit(session);
272 < }
273 <
274 < // XMMS 1.2.6
275 < void Audacious::PlayPause()
276 < {
277 <        ::xmms_remote_play_pause(session);
278 < }
279 <
280 < void Audacious::PlaylistInsertUrl(const std::string &url, int position)
281 < {
282 <        ::xmms_remote_playlist_ins_url_string(session, const_cast<char*>(url.c_str()), position);
283 < }
284 <
285 < // XMMS 1.2.11
286 < void Audacious::PlayqueueAdd(int position)
287 < {
288 <        ::xmms_remote_playqueue_add(session, position);
289 < }
290 <
291 < void Audacious::PlayqueueRemove(int position)
292 < {
293 <        ::xmms_remote_playqueue_remove(session, position);
294 < }
295 <
296 < int Audacious::GetPlayqueueLength() const
297 < {
298 <        return ::xmms_remote_get_playqueue_length(session);
299 < }
130 >                switch (response.command)
131 >                {
132 >                case Packet::KeyActivity:
133 >                        keyActivity.push(response);
134  
135 < void Audacious::ToggleAdvance()
136 < {
137 <        ::xmms_remote_toggle_advance(session);
135 >                        break;
136 >                case Packet::FanSpeedReport:
137 >                case Packet::TemperatureSensorReport:
138 >                        break;
139 >                }
140 >        }
141   }
142  
143 < bool Audacious::IsAdvance() const
143 > bool Display::Ping(const std::string &data)
144   {
145 <        return ::xmms_remote_is_advance(session);
145 >        return data == Communicate(Packet::PingCommand, data).GetData();
146   }
147  
148 < // BMP 0.9.7
312 < void Audacious::Activate()
148 > std::string Display::Version()
149   {
150 <        ::xmms_remote_activate(session);
150 >        return Communicate(Packet::GetHardwareAndFirmwareVersion).GetData();
151   }
152  
153 < // Audacious 1.1
318 < void Audacious::ShowJumpToFileBox()
153 > void Display::SetCursorPosition(uint8_t column, uint8_t row)
154   {
155 <        ::xmms_remote_show_jtf_box(session);
321 < }
322 <
323 < void Audacious::PlayqueueClear()
324 < {
325 <        ::xmms_remote_playqueue_clear(session);
326 < }
155 >        const uint8_t data[] = { column, row };
156  
157 < bool Audacious::PlayqueueIsQueued(int position) const
329 < {
330 <        return ::xmms_remote_playqueue_is_queued(session, position);
157 >        Communicate(Packet::SetLCDCursorPosition, 2, data);
158   }
159  
160 < int Audacious::GetPlayqueuePosition(int position) const
160 > void Display::SetCursorStyle(Display::CursorStyle style)
161   {
162 <        return ::xmms_remote_get_playqueue_position(session, position);
336 < }
162 >        uint8_t data(style);
163  
164 < int Audacious::GetPlayqueueQueuePosition(int position) const
339 < {
340 <        return ::xmms_remote_get_playqueue_queue_position(session, position);
164 >        Communicate(Packet::SetLCDCursorStyle, 1, &data);
165   }
166  
167 < // Audacious 1.2
344 < void Audacious::SetSessionUri(const std::string &uri)
167 > void Display::KeyReporting(uint8_t press, uint8_t release)
168   {
169 <        ::audacious_set_session_uri(const_cast<char *>(uri.c_str()));
347 < }
169 >        const uint8_t data[] = { press, release };
170  
171 < std::string Audacious::GetSessionUri() const
350 < {
351 <        return ::audacious_get_session_uri(session);
352 < }
353 <
354 < void Audacious::SetSessionType(Type type)
355 < {
356 <        ::audacious_set_session_type(type);
357 < }
358 <
359 < // Audacious 1.3
360 < void Audacious::PlaylistEnqueueToTemp(const std::string &string)
361 < {
362 <        ::xmms_remote_playlist_enqueue_to_temp(session, const_cast<char *>(string.c_str()));
363 < }
364 <
365 < std::string Audacious::GetTupleFieldData(const std::string &field, int position)
366 < {
367 <        return ::audacious_get_tuple_field_data(session, const_cast<char *>(field.c_str()), position);
171 >        Communicate(Packet::ConfigureKeyReporting, 2, data);
172   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines