Subversion Repositories freemyipod

Rev

Rev 132 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 132 Rev 138
Line 36... Line 36...
36
static bool oldtouched IBSS_ATTR;
36
static bool oldtouched IBSS_ATTR;
37
static int oldpos IBSS_ATTR;
37
static int oldpos IBSS_ATTR;
38
static int oldbuttons IBSS_ATTR;
38
static int oldbuttons IBSS_ATTR;
39
static uint32_t lastpacket IBSS_ATTR;
39
static uint32_t lastpacket IBSS_ATTR;
40
static int packets IBSS_ATTR;
40
static int packets IBSS_ATTR;
-
 
41
static int collect IBSS_ATTR;
-
 
42
static int lastdiff IBSS_ATTR;
41
 
43
 
42
 
44
 
43
void clickwheel_thread(void) ICODE_ATTR;
45
void clickwheel_thread(void) ICODE_ATTR;
44
void clickwheel_thread()
46
void clickwheel_thread()
45
{
47
{
Line 66... Line 68...
66
 
68
 
67
            if (newtouched)
69
            if (newtouched)
68
            {
70
            {
69
                if (!oldtouched) button_send_event(WHEEL_TOUCH, 0, newpos);
71
                if (!oldtouched) button_send_event(WHEEL_TOUCH, 0, newpos);
70
                button_send_event(WHEEL_POSITION, 0, newpos);
72
                button_send_event(WHEEL_POSITION, 0, newpos);
71
                if (TIMEOUT_EXPIRED(lastpacket, 200000)) packets = 5;
-
 
72
                else packets++;
-
 
73
                if (packets > 100) packets = 100;
-
 
74
                int distance = newpos - oldpos;
73
                int distance = newpos - oldpos;
-
 
74
                if (TIMEOUT_EXPIRED(lastpacket, 200000) || lastdiff * distance < 0) packets = 10;
-
 
75
                else packets++;
-
 
76
                lastdiff = distance;
-
 
77
                if (packets > 200) packets = 200;
75
                if (distance < -48) distance += 96;
78
                if (distance < -48) distance += 96;
76
                else if (distance > 48) distance -= 96;
79
                else if (distance > 48) distance -= 96;
77
                distance *= packets;
80
                collect += distance * packets;
78
                button_send_event(WHEEL_MOVED, 0, distance);
81
                button_send_event(WHEEL_MOVED, 0, distance);
79
                enum button_event e = distance > 0 ? WHEEL_FORWARD : WHEEL_BACKWARD;
82
                enum button_event e = collect > 0 ? WHEEL_FORWARD : WHEEL_BACKWARD;
80
                distance = distance > 0 ? distance : -distance;
83
                int data = (collect > 0 ? collect : -collect) / 128;
81
                button_send_event(e, 0, distance >> 6);
84
                if (data) button_send_event(e, 0, data);
-
 
85
                collect %= 128;
82
            }
86
            }
83
            else if (oldtouched)
87
            else if (oldtouched)
84
            {
88
            {
85
                button_send_event(WHEEL_POSITION, 0, newpos);
89
                button_send_event(WHEEL_POSITION, 0, newpos);
86
                button_send_event(WHEEL_UNTOUCH, 0, newpos);
90
                button_send_event(WHEEL_UNTOUCH, 0, newpos);
-
 
91
                collect = 0;
-
 
92
                packets = 0;
-
 
93
                lastdiff = 0;
87
            }
94
            }
88
 
95
 
89
            oldbuttons = newbuttons;
96
            oldbuttons = newbuttons;
90
            oldpos = newpos;
97
            oldpos = newpos;
91
            oldtouched = newtouched;
98
            oldtouched = newtouched;
Line 101... Line 108...
101
{
108
{
102
    wakeup_init(&clickwheel_wakeup);
109
    wakeup_init(&clickwheel_wakeup);
103
    oldtouched = false;
110
    oldtouched = false;
104
    oldbuttons = 0;
111
    oldbuttons = 0;
105
    lastpacket = 0;
112
    lastpacket = 0;
-
 
113
    collect = 0;
-
 
114
    lastdiff = 0;
106
    INTMSK |= 1 << IRQ_WHEEL;
115
    INTMSK |= 1 << IRQ_WHEEL;
107
    PWRCON(1) &= ~1;
116
    PWRCON(1) &= ~1;
108
    PCON15 = (PCON15 & ~0xFFFF0000) | 0x22220000;
117
    PCON15 = (PCON15 & ~0xFFFF0000) | 0x22220000;
109
    PUNK15 = 0xF0;
118
    PUNK15 = 0xF0;
110
    WHEEL08 = 0x3A980;
119
    WHEEL08 = 0x3A980;