Move c/h files implementing/defining standard library stuff into a new libc directory...
[kugel-rb.git] / apps / iap.c
blob96713083c1e3203ba0281a7c04b3b55d4bef29b9
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 by Alan Korr & Nick Robinson
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <stdarg.h>
22 #include <memory.h>
23 #include <string.h>
25 #include "iap.h"
26 #include "button.h"
27 #include "config.h"
28 #include "cpu.h"
29 #include "system.h"
30 #include "kernel.h"
31 #include "serial.h"
32 #include "appevents.h"
34 #include "playlist.h"
35 #include "playback.h"
36 #include "audio.h"
37 #include "settings.h"
38 #include "metadata.h"
39 #include "wps.h"
40 #include "sound.h"
41 #include "action.h"
42 #include "powermgmt.h"
44 #include "tuner.h"
45 #include "ipod_remote_tuner.h"
47 static volatile int iap_pollspeed = 0;
48 static volatile bool iap_remotetick = true;
49 static bool iap_setupflag = false, iap_updateflag = false;
50 static int iap_changedctr = 0;
52 static unsigned long iap_remotebtn = 0;
53 static int iap_repeatbtn = 0;
54 static bool iap_btnrepeat = false, iap_btnshuffle = false;
56 unsigned char serbuf[RX_BUFLEN];
57 static int serbuf_i = 0;
59 static unsigned char response[TX_BUFLEN];
60 static int responselen;
62 static void iap_task(void)
64 static int count = 0;
66 count += iap_pollspeed;
67 if (count < (500/10)) return;
69 /* exec every 500ms if pollspeed == 1 */
70 count = 0;
71 queue_post(&button_queue, SYS_IAP_PERIODIC, 0);
74 /* called by playback when the next track starts */
75 static void iap_track_changed(void *ignored)
77 (void)ignored;
78 iap_changedctr = 1;
81 void iap_setup(int ratenum)
83 iap_bitrate_set(ratenum);
84 iap_pollspeed = 0;
85 iap_remotetick = true;
86 iap_updateflag = false;
87 iap_changedctr = 0;
88 iap_setupflag = true;
89 iap_remotebtn = BUTTON_NONE;
90 tick_add_task(iap_task);
91 add_event(PLAYBACK_EVENT_TRACK_CHANGE, false, iap_track_changed);
94 void iap_bitrate_set(int ratenum)
96 switch(ratenum)
98 case 0:
99 serial_bitrate(0);
100 break;
101 case 1:
102 serial_bitrate(9600);
103 break;
104 case 2:
105 serial_bitrate(19200);
106 break;
107 case 3:
108 serial_bitrate(38400);
109 break;
110 case 4:
111 serial_bitrate(57600);
112 break;
116 /* Message format:
117 0xff
118 0x55
119 length
120 mode
121 command (2 bytes)
122 parameters (0-n bytes)
123 checksum (length+mode+parameters+checksum == 0)
126 void iap_send_pkt(const unsigned char * data, int len)
128 int i, chksum;
130 if(len > TX_BUFLEN-4) len = TX_BUFLEN-4;
131 responselen = len + 4;
133 response[0] = 0xFF;
134 response[1] = 0x55;
136 chksum = response[2] = len;
137 for(i = 0; i < len; i ++)
139 chksum += data[i];
140 response[i+3] = data[i];
143 response[i+3] = 0x100 - (chksum & 0xFF);
145 for(i = 0; i < responselen; i ++)
147 while (!tx_rdy()) ;
148 tx_writec(response[i]);
152 int iap_getc(unsigned char x)
154 static unsigned char last_x = 0;
155 static bool newpkt = true;
156 static unsigned char chksum = 0;
158 /* Restart if the sync word is seen */
159 if(x == 0x55 && last_x == 0xff/* && newpkt*/)
161 serbuf[0] = 0;
162 serbuf_i = 0;
163 chksum = 0;
164 newpkt = false;
166 else
168 if(serbuf_i >= RX_BUFLEN)
169 serbuf_i = 0;
171 serbuf[serbuf_i++] = x;
172 chksum += x;
174 last_x = x;
176 /* Broadcast to queue if we have a complete message */
177 if(serbuf_i && (serbuf_i == serbuf[0]+2))
179 serbuf_i = 0;
180 newpkt = true;
181 if(chksum == 0)
182 queue_post(&button_queue, SYS_IAP_HANDLEPKT, 0);
184 return newpkt;
187 void iap_periodic(void)
189 if(!iap_setupflag) return;
190 if(!iap_pollspeed) return;
192 unsigned char data[] = {0x04, 0x00, 0x27, 0x04, 0x00, 0x00, 0x00, 0x00};
193 unsigned long time_elapsed = audio_current_track()->elapsed;
195 time_elapsed += wps_get_ff_rewind_count();
197 data[3] = 0x04; /* playing */
199 /* If info has changed, don't flag it right away */
200 if(iap_changedctr && iap_changedctr++ >= iap_pollspeed * 2)
202 /* track info has changed */
203 iap_changedctr = 0;
204 data[3] = 0x01; /* 0x02 has same effect? */
205 iap_updateflag = true;
208 data[4] = time_elapsed >> 24;
209 data[5] = time_elapsed >> 16;
210 data[6] = time_elapsed >> 8;
211 data[7] = time_elapsed;
212 iap_send_pkt(data, sizeof(data));
215 static void iap_set_remote_volume(void)
217 unsigned char data[] = {0x03, 0x0D, 0x04, 0x00, 0x00};
218 data[4] = (char)((global_settings.volume+58) * 4);
219 iap_send_pkt(data, sizeof(data));
222 void iap_handlepkt(void)
225 if(!iap_setupflag) return;
226 if(serbuf[0] == 0) return;
228 /* if we are waiting for a remote button to go out,
229 delay the handling of the new packet */
230 if(!iap_remotetick)
232 queue_post(&button_queue, SYS_IAP_HANDLEPKT, 0);
233 return;
236 /* Handle Mode 0 */
237 if (serbuf[1] == 0x00)
239 switch (serbuf[2])
241 case 0x24:
243 /* ipod video send this */
244 unsigned char data[] = {0x00, 0x25, 0x00, 0x00, 0x00,
245 0x00, 0x00, 0x00, 0x00,0x01};
246 iap_send_pkt(data, sizeof(data));
247 break;
250 case 0x18:
252 /* ciphered authentication command */
253 /* Isn't used since we don't send the 0x00 0x17 command */
254 break;
257 case 0x15:
259 unsigned char data0[] = {0x00, 0x16, 0x00};
260 iap_send_pkt(data0, sizeof(data0));
261 unsigned char data1[] = {0x00, 0x27, 0x00};
262 iap_send_pkt(data1, sizeof(data1));
263 /* authentication ack, mandatory to enable some hardware */
264 unsigned char data2[] = {0x00, 0x19, 0x00};
265 iap_send_pkt(data2, sizeof(data2));
266 if (radio_present == 1)
268 /* get tuner capacities */
269 unsigned char data3[] = {0x07, 0x01};
270 iap_send_pkt(data3, sizeof(data3));
272 iap_set_remote_volume();
273 break;
276 case 0x13:
278 unsigned char data[] = {0x00, 0x02, 0x00, 0x13};
279 iap_send_pkt(data, sizeof(data));
281 if (serbuf[6] == 0x35)
282 /* FM transmitter sends this: */
283 /* FF 55 0E 00 13 00 00 00 35 00 00 00 04 00 00 00 00 A6 (??)*/
285 unsigned char data2[] = {0x00, 0x27, 0x00};
286 iap_send_pkt(data2, sizeof(data2));
287 unsigned char data3[] = {0x05, 0x02};
288 iap_send_pkt(data3, sizeof(data3));
291 else
293 /* ipod fm remote sends this: */
294 /* FF 55 0E 00 13 00 00 00 8D 00 00 00 0E 00 00 00 03 41 */
295 if (serbuf[6] |= 0x80)
296 radio_present = 1;
297 unsigned char data4[] = {0x00, 0x14};
298 iap_send_pkt(data4, sizeof(data4));
300 break;
303 /* Init */
304 case 0x0F:
306 unsigned char data[] = {0x00, 0x10, 0x00, 0x01, 0x05};
307 data[2] = serbuf[3];
308 iap_send_pkt(data, sizeof(data));
309 break;
312 /* get model info */
313 case 0x0D:
315 /* ipod is supposed to work only with 5G and nano 2G */
316 /*{0x00, 0x0E, 0x00, 0x0B, 0x00, 0x05, 0x50, 0x41, 0x31, 0x34,
317 0x37, 0x4C, 0x4C, 0x00}; PA147LL (IPOD 5G 60 GO) */
318 unsigned char data[] = {0x00, 0x0E, 0x00, 0x0B, 0x00, 0x10,
319 'R', 'O', 'C', 'K', 'B', 'O', 'X', 0x00};
320 iap_send_pkt(data, sizeof(data));
321 break;
324 /* Ipod FM remote sends this: FF 55 02 00 09 F5 */
325 case 0x09:
327 /* ipod5G firmware version */
328 unsigned char data[] = {0x00, 0x0A, 0x01, 0x02, 0x01 };
329 iap_send_pkt(data, sizeof(data));
330 break;
333 /* FM transmitter sends this: */
334 /* FF 55 02 00 05 F9 (mode switch: AiR mode) */
335 case 0x05:
337 unsigned char data[] = {0x00, 0x02, 0x06,
338 0x05, 0x00, 0x00, 0x0B, 0xB8, 0x28};
339 iap_send_pkt(data, sizeof(data));
340 unsigned char data2[] = {0x00, 0x02, 0x00, 0x05};
341 iap_send_pkt(data2, sizeof(data2));
342 break;
345 case 0x01:
347 /* FM transmitter sends this: */
348 /* FF 55 06 00 01 05 00 02 01 F1 (mode switch) */
349 if(serbuf[3] == 0x05)
351 sleep(HZ/3);
352 unsigned char data[] = {0x05, 0x02};
353 iap_send_pkt(data, sizeof(data));
355 /* FM remote sends this: */
356 /* FF 55 03 00 01 02 FA (1st thing sent) */
357 else if(serbuf[3] == 0x02)
359 /* useful only for apple firmware */
361 break;
364 /* default response is with cmd ok packet */
365 default:
367 unsigned char data[] = {0x00, 0x02, 0x00, 0x00};
368 data[3] = serbuf[2]; /* respond with cmd */
369 iap_send_pkt(data, sizeof(data));
370 break;
374 /* Handle Mode 2 */
375 else if (serbuf[1] == 0x02)
377 if(serbuf[2] != 0) return;
378 iap_remotebtn = BUTTON_NONE;
379 iap_remotetick = false;
381 if(serbuf[0] >= 3 && serbuf[3] != 0)
383 if(serbuf[3] & 1)
384 iap_remotebtn |= BUTTON_RC_PLAY;
385 if(serbuf[3] & 2)
386 iap_remotebtn |= BUTTON_RC_VOL_UP;
387 if(serbuf[3] & 4)
388 iap_remotebtn |= BUTTON_RC_VOL_DOWN;
389 if(serbuf[3] & 8)
390 iap_remotebtn |= BUTTON_RC_RIGHT;
391 if(serbuf[3] & 16)
392 iap_remotebtn |= BUTTON_RC_LEFT;
394 else if(serbuf[0] >= 4 && serbuf[4] != 0)
396 if(serbuf[4] & 1) /* play */
398 if (audio_status() != AUDIO_STATUS_PLAY)
400 iap_remotebtn |= BUTTON_RC_PLAY;
401 iap_repeatbtn = 2;
402 iap_remotetick = false;
403 iap_changedctr = 1;
406 if(serbuf[4] & 2) /* pause */
408 if (audio_status() == AUDIO_STATUS_PLAY)
410 iap_remotebtn |= BUTTON_RC_PLAY;
411 iap_repeatbtn = 2;
412 iap_remotetick = false;
413 iap_changedctr = 1;
416 if((serbuf[4] & 128) && !iap_btnshuffle) /* shuffle */
418 iap_btnshuffle = true;
419 if(!global_settings.playlist_shuffle)
421 global_settings.playlist_shuffle = 1;
422 settings_save();
423 if (audio_status() & AUDIO_STATUS_PLAY)
424 playlist_randomise(NULL, current_tick, true);
426 else if(global_settings.playlist_shuffle)
428 global_settings.playlist_shuffle = 0;
429 settings_save();
430 if (audio_status() & AUDIO_STATUS_PLAY)
431 playlist_sort(NULL, true);
434 else
435 iap_btnshuffle = false;
437 else if(serbuf[0] >= 5 && serbuf[5] != 0)
439 if((serbuf[5] & 1) && !iap_btnrepeat) /* repeat */
441 int oldmode = global_settings.repeat_mode;
442 iap_btnrepeat = true;
444 if (oldmode == REPEAT_ONE)
445 global_settings.repeat_mode = REPEAT_OFF;
446 else if (oldmode == REPEAT_ALL)
447 global_settings.repeat_mode = REPEAT_ONE;
448 else if (oldmode == REPEAT_OFF)
449 global_settings.repeat_mode = REPEAT_ALL;
451 settings_save();
452 if (audio_status() & AUDIO_STATUS_PLAY)
453 audio_flush_and_reload_tracks();
455 else
456 iap_btnrepeat = false;
458 if(serbuf[5] & 16) /* ffwd */
460 iap_remotebtn |= BUTTON_RC_RIGHT;
462 if(serbuf[5] & 32) /* frwd */
464 iap_remotebtn |= BUTTON_RC_LEFT;
468 /* Handle Mode 3 */
469 else if (serbuf[1] == 0x03)
471 switch(serbuf[2])
473 /* some kind of status packet? */
474 case 0x01:
476 unsigned char data[] = {0x03, 0x02, 0x00, 0x00, 0x00, 0x00};
477 iap_send_pkt(data, sizeof(data));
478 break;
481 case 0x08:
483 /* ACK */
484 unsigned char data[] = {0x03, 0x00, 0x00, 0x08};
485 iap_send_pkt(data, sizeof(data));
486 break;
489 case 0x0C:
491 /* request ipod volume */
492 if (serbuf[3] == 0x04)
494 iap_set_remote_volume();
496 break;
498 /* get volume from accessory */
499 case 0x0E:
500 if (serbuf[3] == 0x04)
501 global_settings.volume = (-58)+((int)serbuf[5]+1)/4;
502 sound_set_volume(global_settings.volume);
503 break;
506 /* Handle Mode 4 */
507 else if (serbuf[1] == 0x04)
509 switch (((unsigned long)serbuf[2] << 8) | serbuf[3])
511 /* Get data updated??? flag */
512 case 0x0009:
514 unsigned char data[] = {0x04, 0x00, 0x0A, 0x00};
515 data[3] = iap_updateflag ? 0 : 1;
516 iap_send_pkt(data, sizeof(data));
517 break;
519 /* Set data updated??? flag */
520 case 0x000B:
522 iap_updateflag = serbuf[4] ? 0 : 1;
523 /* respond with cmd ok packet */
524 unsigned char data[] = {0x04, 0x00, 0x01, 0x00, 0x00, 0x0B};
525 iap_send_pkt(data, sizeof(data));
526 break;
528 /* Get iPod size? */
529 case 0x0012:
531 unsigned char data[] = {0x04, 0x00, 0x13, 0x01, 0x0B};
532 iap_send_pkt(data, sizeof(data));
533 break;
535 /* Get count of given types */
536 case 0x0018:
538 unsigned char data[] = {0x04, 0x00, 0x19, 0x00, 0x00, 0x00, 0x00};
539 unsigned long num = 0;
540 switch(serbuf[4]) /* type number */
542 case 0x01: /* total number of playlists */
543 num = 1;
544 break;
545 case 0x05: /* total number of songs */
546 num = 1;
548 data[3] = num >> 24;
549 data[4] = num >> 16;
550 data[5] = num >> 8;
551 data[6] = num;
552 iap_send_pkt(data, sizeof(data));
553 break;
555 /* Get time and status */
556 case 0x001C:
558 unsigned char data[] = {0x04, 0x00, 0x1D, 0x00, 0x00, 0x00,
559 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
560 struct mp3entry *id3 = audio_current_track();
561 unsigned long time_total = id3->length;
562 unsigned long time_elapsed = id3->elapsed;
563 int status = audio_status();
564 data[3] = time_total >> 24;
565 data[4] = time_total >> 16;
566 data[5] = time_total >> 8;
567 data[6] = time_total;
568 data[7] = time_elapsed >> 24;
569 data[8] = time_elapsed >> 16;
570 data[9] = time_elapsed >> 8;
571 data[10] = time_elapsed;
572 if (status == AUDIO_STATUS_PLAY)
573 data[11] = 0x01; /* play */
574 else if (status & AUDIO_STATUS_PAUSE)
575 data[11] = 0x02; /* pause */
576 iap_send_pkt(data, sizeof(data));
577 break;
579 /* Get current pos in playlist */
580 case 0x001E:
582 unsigned char data[] = {0x04, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00};
583 long playlist_pos = playlist_next(0);
584 playlist_pos -= playlist_get_first_index(NULL);
585 if(playlist_pos < 0)
586 playlist_pos += playlist_amount();
587 data[3] = playlist_pos >> 24;
588 data[4] = playlist_pos >> 16;
589 data[5] = playlist_pos >> 8;
590 data[6] = playlist_pos;
591 iap_send_pkt(data, sizeof(data));
592 break;
594 /* Get title of a song number */
595 case 0x0020:
596 /* Get artist of a song number */
597 case 0x0022:
598 /* Get album of a song number */
599 case 0x0024:
601 unsigned char data[70] = {0x04, 0x00, 0xFF};
602 struct mp3entry id3;
603 int fd;
604 size_t len;
605 long tracknum = (signed long)serbuf[4] << 24 |
606 (signed long)serbuf[5] << 16 |
607 (signed long)serbuf[6] << 8 | serbuf[7];
608 data[2] = serbuf[3] + 1;
609 memcpy(&id3, audio_current_track(), sizeof(id3));
610 tracknum += playlist_get_first_index(NULL);
611 if(tracknum >= playlist_amount())
612 tracknum -= playlist_amount();
614 /* If the tracknumber is not the current one,
615 read id3 from disk */
616 if(playlist_next(0) != tracknum)
618 struct playlist_track_info info;
619 playlist_get_track_info(NULL, tracknum, &info);
620 fd = open(info.filename, O_RDONLY);
621 memset(&id3, 0, sizeof(struct mp3entry));
622 get_metadata(&id3, fd, info.filename);
623 close(fd);
626 /* Return the requested track data */
627 switch(serbuf[3])
629 case 0x20:
630 len = strlcpy((char *)&data[3], id3.title, 64);
631 iap_send_pkt(data, 4+len);
632 break;
633 case 0x22:
634 len = strlcpy((char *)&data[3], id3.artist, 64);
635 iap_send_pkt(data, 4+len);
636 break;
637 case 0x24:
638 len = strlcpy((char *)&data[3], id3.album, 64);
639 iap_send_pkt(data, 4+len);
640 break;
642 break;
644 /* Set polling mode */
645 case 0x0026:
647 iap_pollspeed = serbuf[4] ? 1 : 0;
648 /*responsed with cmd ok packet */
649 unsigned char data[] = {0x04, 0x00, 0x01, 0x00, 0x00, 0x26};
650 iap_send_pkt(data, sizeof(data));
651 break;
653 /* AiR playback control */
654 case 0x0029:
656 /* respond with cmd ok packet */
657 unsigned char data[] = {0x04, 0x00, 0x01, 0x00, 0x00, 0x29};
658 iap_send_pkt(data, sizeof(data));
659 switch(serbuf[4])
661 case 0x01: /* play/pause */
662 iap_remotebtn = BUTTON_RC_PLAY;
663 iap_repeatbtn = 2;
664 iap_remotetick = false;
665 iap_changedctr = 1;
666 break;
667 case 0x02: /* stop */
668 iap_remotebtn = BUTTON_RC_PLAY|BUTTON_REPEAT;
669 iap_repeatbtn = 2;
670 iap_remotetick = false;
671 iap_changedctr = 1;
672 break;
673 case 0x03: /* skip++ */
674 iap_remotebtn = BUTTON_RC_RIGHT;
675 iap_repeatbtn = 2;
676 iap_remotetick = false;
677 break;
678 case 0x04: /* skip-- */
679 iap_remotebtn = BUTTON_RC_LEFT;
680 iap_repeatbtn = 2;
681 iap_remotetick = false;
682 break;
683 case 0x05: /* ffwd */
684 iap_remotebtn = BUTTON_RC_RIGHT;
685 iap_remotetick = false;
686 if(iap_pollspeed) iap_pollspeed = 5;
687 break;
688 case 0x06: /* frwd */
689 iap_remotebtn = BUTTON_RC_LEFT;
690 iap_remotetick = false;
691 if(iap_pollspeed) iap_pollspeed = 5;
692 break;
693 case 0x07: /* end ffwd/frwd */
694 iap_remotebtn = BUTTON_NONE;
695 iap_remotetick = false;
696 if(iap_pollspeed) iap_pollspeed = 1;
697 break;
699 break;
701 /* Get shuffle mode */
702 case 0x002C:
704 unsigned char data[] = {0x04, 0x00, 0x2D, 0x00};
705 data[3] = global_settings.playlist_shuffle ? 1 : 0;
706 iap_send_pkt(data, sizeof(data));
707 break;
709 /* Set shuffle mode */
710 case 0x002E:
712 if(serbuf[4] && !global_settings.playlist_shuffle)
714 global_settings.playlist_shuffle = 1;
715 settings_save();
716 if (audio_status() & AUDIO_STATUS_PLAY)
717 playlist_randomise(NULL, current_tick, true);
719 else if(!serbuf[4] && global_settings.playlist_shuffle)
721 global_settings.playlist_shuffle = 0;
722 settings_save();
723 if (audio_status() & AUDIO_STATUS_PLAY)
724 playlist_sort(NULL, true);
728 /* respond with cmd ok packet */
729 unsigned char data[] = {0x04, 0x00, 0x01, 0x00, 0x00, 0x2E};
730 iap_send_pkt(data, sizeof(data));
731 break;
733 /* Get repeat mode */
734 case 0x002F:
736 unsigned char data[] = {0x04, 0x00, 0x30, 0x00};
737 if(global_settings.repeat_mode == REPEAT_OFF)
738 data[3] = 0;
739 else if(global_settings.repeat_mode == REPEAT_ONE)
740 data[3] = 1;
741 else
742 data[3] = 2;
743 iap_send_pkt(data, sizeof(data));
744 break;
746 /* Set repeat mode */
747 case 0x0031:
749 int oldmode = global_settings.repeat_mode;
750 if (serbuf[4] == 0)
751 global_settings.repeat_mode = REPEAT_OFF;
752 else if (serbuf[4] == 1)
753 global_settings.repeat_mode = REPEAT_ONE;
754 else if (serbuf[4] == 2)
755 global_settings.repeat_mode = REPEAT_ALL;
757 if (oldmode != global_settings.repeat_mode)
759 settings_save();
760 if (audio_status() & AUDIO_STATUS_PLAY)
761 audio_flush_and_reload_tracks();
764 /* respond with cmd ok packet */
765 unsigned char data[] = {0x04, 0x00, 0x01, 0x00, 0x00, 0x31};
766 iap_send_pkt(data, sizeof(data));
767 break;
769 /* Get Screen Size */
770 case 0x0033:
772 unsigned char data[] = {0x04, 0x00, 0x34,
773 LCD_WIDTH >> 8, LCD_WIDTH & 0xff,
774 LCD_HEIGHT >> 8, LCD_HEIGHT & 0xff,
775 0x01};
776 iap_send_pkt(data, sizeof(data));
777 break;
779 /* Get number songs in current playlist */
780 case 0x0035:
782 unsigned char data[] = {0x04, 0x00, 0x36, 0x00, 0x00, 0x00, 0x00};
783 unsigned long playlist_amt = playlist_amount();
784 data[3] = playlist_amt >> 24;
785 data[4] = playlist_amt >> 16;
786 data[5] = playlist_amt >> 8;
787 data[6] = playlist_amt;
788 iap_send_pkt(data, sizeof(data));
789 break;
791 /* Jump to track number in current playlist */
792 case 0x0037:
794 int paused = (is_wps_fading() || (audio_status() & AUDIO_STATUS_PAUSE));
795 long tracknum = (signed long)serbuf[4] << 24 |
796 (signed long)serbuf[5] << 16 |
797 (signed long)serbuf[6] << 8 | serbuf[7];
798 audio_pause();
799 audio_skip(tracknum - playlist_next(0));
800 if (!paused)
801 audio_resume();
803 /* respond with cmd ok packet */
804 unsigned char data[] = {0x04, 0x00, 0x01, 0x00, 0x00, 0x00};
805 data[4] = serbuf[2];
806 data[5] = serbuf[3];
807 iap_send_pkt(data, sizeof(data));
808 break;
810 default:
812 /* default response is with cmd ok packet */
813 unsigned char data[] = {0x04, 0x00, 0x01, 0x00, 0x00, 0x00};
814 data[4] = serbuf[2];
815 data[5] = serbuf[3];
816 iap_send_pkt(data, sizeof(data));
817 break;
821 /* Handle Mode 7 */
822 else if (serbuf[1] == 0x07)
824 switch(serbuf[2])
826 /* tuner capabilities */
827 case 0x02:
829 /* do nothing */
831 unsigned char data[] = {0x00, 0x27, 0x00};
832 iap_send_pkt(data, sizeof(data));
833 break;
835 /* actual tuner frequency */
836 case 0x0A:
837 /* fall through */
838 /* tuner frequency from scan */
839 case 0x13:
841 rmt_tuner_freq();
842 break;
844 /* RDS station name 0x21 1E 00 + ASCII text*/
845 case 0x21:
847 rmt_tuner_rds_data();
848 break;
852 serbuf[0] = 0;
855 int remote_control_rx(void)
857 int btn = iap_remotebtn;
858 if(iap_repeatbtn)
860 iap_repeatbtn--;
861 if(!iap_repeatbtn)
863 iap_remotebtn = BUTTON_NONE;
864 iap_remotetick = true;
867 else
868 iap_remotetick = true;
870 return btn;