Ticket #24 (closed enhancement: fixed)
Simple non-threaded current state type interface to Wiimotes
| Reported by: | amp | Owned by: | dsmith |
|---|---|---|---|
| Priority: | minor | Milestone: | Version 0.6.00 |
| Component: | libcwiid | Version: | 0.5.02 |
| Keywords: | Cc: |
Description
I think it would be nice to have a simple interface to the wiimote that does not require writing a callback.
I have implemented such an API. It is as follows:
/** A callback that saves the most recent message of each type. It is very useful for program that only need the current state (not the changes in state) and don't want to deal with threading. There is a race condition in the message copies into wiimote_saved_messages[]. A reader could read the message while it is being updated resulting in reading half old and half new data. I don't think this will be a big issue. The new and old values will likely be very close to each other and there is no temporary values written to wiimote_saved_messages[]. However if this is a problem maybe a lock should be added or people who need accuracy should use the event API. */ void wiimote_save_messages(int, int, union wiimote_mesg* []); /** The values saved by wiimote_save_messages(). The data for a given wiimote is in "wiimote_saved_messages[id]". */ extern struct wiimote_mesg_set wiimote_saved_messages[];
where wiimote_mesg_set is a structure containing all the message structures. This can be used as follows:
wiimote = wiimote_connect(&bdaddr, wiimote_save_messages, &wiimote_id)
while( true ) {
printf("Acc: x=%d, y=%d, z=%d\n", wiimote_saved_messages[wiimote_id].acc_mesg.x,
wiimote_saved_messages[wiimote_id].acc_mesg.y,
wiimote_saved_messages[wiimote_id].acc_mesg.z);
usleep(100*1000);
}
I have attached a patch against svn trunk. It also includes a modified version of wmdemo that uses the API.
Attachments
Change History
Note: See
TracTickets for help on using
tickets.

