iap: split iap_handlepkt into a function per mode

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29755 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Bertrik Sikken 2011-04-21 21:50:39 +00:00
parent c77b014283
commit 9ea20660ca

View file

@ -218,25 +218,11 @@ static void iap_set_remote_volume(void)
iap_send_pkt(data, sizeof(data));
}
void iap_handlepkt(void)
static void iap_handlepkt_mode0(void)
{
unsigned int cmd = serbuf[2];
switch (cmd) {
if(!iap_setupflag) return;
if(serbuf[0] == 0) return;
/* if we are waiting for a remote button to go out,
delay the handling of the new packet */
if(!iap_remotetick)
{
queue_post(&button_queue, SYS_IAP_HANDLEPKT, 0);
return;
}
/* Handle Mode 0 */
if (serbuf[1] == 0x00)
{
switch (serbuf[2])
{
case 0x24:
{
/* ipod video send this */
@ -364,14 +350,14 @@ void iap_handlepkt(void)
default:
{
unsigned char data[] = {0x00, 0x02, 0x00, 0x00};
data[3] = serbuf[2]; /* respond with cmd */
data[3] = cmd; /* respond with cmd */
iap_send_pkt(data, sizeof(data));
break;
}
}
}
/* Handle Mode 2 */
else if (serbuf[1] == 0x02)
static void iap_handlepkt_mode2(void)
{
if(serbuf[2] != 0) return;
iap_remotebtn = BUTTON_NONE;
@ -464,10 +450,11 @@ void iap_handlepkt(void)
}
}
}
/* Handle Mode 3 */
else if (serbuf[1] == 0x03)
static void iap_handlepkt_mode3(void)
{
switch(serbuf[2])
unsigned int cmd = serbuf[2];
switch (cmd)
{
/* some kind of status packet? */
case 0x01:
@ -496,16 +483,19 @@ void iap_handlepkt(void)
}
/* get volume from accessory */
case 0x0E:
{
if (serbuf[3] == 0x04)
global_settings.volume = (-58)+((int)serbuf[5]+1)/4;
sound_set_volume(global_settings.volume);
sound_set_volume(global_settings.volume); /* indent BUG? */
break;
}
}
/* Handle Mode 4 */
else if (serbuf[1] == 0x04)
}
static void iap_handlepkt_mode4(void)
{
switch (((unsigned long)serbuf[2] << 8) | serbuf[3])
unsigned int cmd = (serbuf[2] << 8) | serbuf[3];
switch (cmd)
{
/* Get data updated??? flag */
case 0x0009:
@ -817,10 +807,11 @@ void iap_handlepkt(void)
}
}
}
/* Handle Mode 7 */
else if (serbuf[1] == 0x07)
static void iap_handlepkt_mode7(void)
{
switch(serbuf[2])
unsigned int cmd = serbuf[2];
switch (cmd)
{
/* tuner capabilities */
case 0x02:
@ -848,6 +839,30 @@ void iap_handlepkt(void)
}
}
}
void iap_handlepkt(void)
{
if(!iap_setupflag) return;
if(serbuf[0] == 0) return;
/* if we are waiting for a remote button to go out,
delay the handling of the new packet */
if(!iap_remotetick)
{
queue_post(&button_queue, SYS_IAP_HANDLEPKT, 0);
return;
}
unsigned char mode = serbuf[1];
switch (mode) {
case 0: iap_handlepkt_mode0(); break;
case 2: iap_handlepkt_mode2(); break;
case 3: iap_handlepkt_mode3(); break;
case 4: iap_handlepkt_mode4(); break;
case 7: iap_handlepkt_mode7(); break;
}
serbuf[0] = 0;
}