| Index: emcore/trunk/button.c |
| — | — | @@ -36,45 +36,45 @@ |
| 37 | 37 | mutex_init(&button_mutex);
|
| 38 | 38 | }
|
| 39 | 39 |
|
| 40 | | -int button_register_handler(void (*handler)(enum button_event, int which, int value))
|
| | 40 | +struct button_hook_entry* button_register_handler(void (*handler)(void*, enum button_event,
|
| | 41 | + int, int),
|
| | 42 | + void* user)
|
| 41 | 43 | {
|
| 42 | 44 | struct button_hook_entry* hook;
|
| 43 | 45 | hook = (struct button_hook_entry*)malloc(sizeof(struct button_hook_entry));
|
| | 46 | + if (!hook) return NULL;
|
| 44 | 47 | hook->owner = current_thread;
|
| 45 | 48 | hook->handler = handler;
|
| | 49 | + hook->user = user;
|
| 46 | 50 | mutex_lock(&button_mutex, TIMEOUT_BLOCK);
|
| 47 | 51 | hook->next = head_button_hook;
|
| 48 | 52 | head_button_hook = hook;
|
| 49 | 53 | mutex_unlock(&button_mutex);
|
| 50 | | - return 0;
|
| | 54 | + return hook;
|
| 51 | 55 | }
|
| 52 | 56 |
|
| 53 | | -int button_unregister_handler(void (*handler)(enum button_event, int which, int value))
|
| | 57 | +int button_unregister_handler(struct button_hook_entry* hook)
|
| 54 | 58 | {
|
| 55 | 59 | struct button_hook_entry* h;
|
| 56 | | - struct button_hook_entry* handle = NULL;
|
| 57 | 60 | int result = -1;
|
| 58 | 61 | mutex_lock(&button_mutex, TIMEOUT_BLOCK);
|
| 59 | | - if (head_button_hook && head_button_hook->handler == handler)
|
| | 62 | + if (head_button_hook == hook)
|
| 60 | 63 | {
|
| 61 | | - handle = head_button_hook;
|
| 62 | 64 | head_button_hook = head_button_hook->next;
|
| 63 | | - free(handle);
|
| | 65 | + free(hook);
|
| 64 | 66 | result = 0;
|
| 65 | 67 | }
|
| 66 | 68 | else
|
| 67 | 69 | {
|
| 68 | 70 | for (h = head_button_hook; h && h->next; h = h->next);
|
| 69 | | - if (h->next->handler != handler)
|
| | 71 | + if (h->next == hook)
|
| 70 | 72 | {
|
| 71 | | - handle = h->next;
|
| 72 | 73 | h->next = h->next->next;
|
| 73 | | - free(handle);
|
| | 74 | + free(hook);
|
| 74 | 75 | result = 0;
|
| 75 | 76 | }
|
| 76 | 77 | }
|
| 77 | 78 | mutex_unlock(&button_mutex);
|
| 78 | | - if (handle) free(handle);
|
| 79 | 79 | return result;
|
| 80 | 80 | }
|
| 81 | 81 |
|
| — | — | @@ -84,7 +84,7 @@ |
| 85 | 85 | struct button_hook_entry* h;
|
| 86 | 86 | mutex_lock(&button_mutex, TIMEOUT_BLOCK);
|
| 87 | 87 | for (h = head_button_hook; h; h = h->next)
|
| 88 | | - h->handler(eventtype, which, value);
|
| | 88 | + h->handler(h->user, eventtype, which, value);
|
| 89 | 89 | mutex_unlock(&button_mutex);
|
| 90 | 90 | }
|
| 91 | 91 |
|
| Index: emcore/trunk/button.h |
| — | — | @@ -37,6 +37,7 @@ |
| 38 | 38 | WHEEL_UNTOUCH,
|
| 39 | 39 | WHEEL_POSITION,
|
| 40 | 40 | WHEEL_MOVED,
|
| | 41 | + WHEEL_MOVED_ACCEL,
|
| 41 | 42 | WHEEL_FORWARD,
|
| 42 | 43 | WHEEL_BACKWARD
|
| 43 | 44 | };
|
| — | — | @@ -45,13 +46,16 @@ |
| 46 | 47 | {
|
| 47 | 48 | struct button_hook_entry* next;
|
| 48 | 49 | struct scheduler_thread* owner;
|
| 49 | | - void (*handler)(enum button_event, int which, int value);
|
| | 50 | + void (*handler)(void*, enum button_event, int, int);
|
| | 51 | + void* user;
|
| 50 | 52 | };
|
| 51 | 53 |
|
| 52 | 54 |
|
| 53 | 55 | void button_init() INITCODE_ATTR;
|
| 54 | | -int button_register_handler(void (*handler)(enum button_event, int which, int value));
|
| 55 | | -int button_unregister_handler(void (*handler)(enum button_event, int which, int value));
|
| | 56 | +struct button_hook_entry* button_register_handler(void (*handler)(void*, enum button_event,
|
| | 57 | + int, int),
|
| | 58 | + void* user);
|
| | 59 | +int button_unregister_handler(struct button_hook_entry* hook);
|
| 56 | 60 | void button_send_event(enum button_event eventtype, int which, int value) ICODE_ATTR;
|
| 57 | 61 | void button_unregister_all_of_thread(struct scheduler_thread* process);
|
| 58 | 62 |
|
| Index: emcore/trunk/target/ipodnano3g/clickwheel.c |
| — | — | @@ -95,8 +95,9 @@ |
| 96 | 96 | if (distance < -48) distance += 96;
|
| 97 | 97 | else if (distance > 48) distance -= 96;
|
| 98 | 98 | DEBUGF("Wheel moved %d units without accel", distance);
|
| | 99 | + button_send_event(WHEEL_MOVED, 0, distance);
|
| 99 | 100 | DEBUGF("Wheel moved %d units with accel", distance * packets);
|
| 100 | | - button_send_event(WHEEL_MOVED, 0, distance);
|
| | 101 | + button_send_event(WHEEL_MOVED_ACCEL, 0, distance * packets);
|
| 101 | 102 | collect += distance * packets;
|
| 102 | 103 | enum button_event e = collect > 0 ? WHEEL_FORWARD : WHEEL_BACKWARD;
|
| 103 | 104 | int data = (collect > 0 ? collect : -collect) / 128;
|