From 95c23bb5685f4079704971e0be7ab4e627e3a828 Mon Sep 17 00:00:00 2001
From: Purdea Andrei <andrei@purdea.ro>
Date: Tue, 29 Jan 2013 01:30:56 +0200
Subject: [PATCH] get navigation mode running with ipod accessories

---
 apps/iap.c                |   19 +++++++++++++++++++
 firmware/drivers/button.c |    3 ++-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/apps/iap.c b/apps/iap.c
index 6fe0a03..afe02b8 100644
--- a/apps/iap.c
+++ b/apps/iap.c
@@ -547,6 +547,25 @@ static void iap_handlepkt_mode2(unsigned int len, const unsigned char *buf)
         {
             iap_remotebtn |= BUTTON_RC_LEFT;
         }
+        if(buf[4] & 0x40)
+        {
+            iap_remotebtn |= BUTTON_MENU;
+        }
+        if(buf[4] & 0x80)
+        {
+            iap_remotebtn |= BUTTON_SELECT;
+        }
+    }
+    else if(len >= 6 && buf[5] != 0)
+    {
+        if(buf[5] & 0x01)
+        {
+            iap_remotebtn |= BUTTON_SCROLL_BACK;
+        }
+        if(buf[5] & 0x02)
+        {
+            iap_remotebtn |= BUTTON_SCROLL_FWD;
+        }
     }
 }
 
diff --git a/firmware/drivers/button.c b/firmware/drivers/button.c
index c165e8f..5adc0bf 100644
--- a/firmware/drivers/button.c
+++ b/firmware/drivers/button.c
@@ -668,7 +668,8 @@ int button_apply_acceleration(const unsigned int data)
         if (v > 1)
             delta *= v;
     }
-
+    if (delta == 0) return 1; /* In case we didn't provide button data
+            (if the scroll event didn't come from the click wheel) */
     return delta;
 }
 #endif /* HAVE_WHEEL_ACCELERATION */
-- 
1.7.10.4

