Add button message callback handling and sample code

This commit is contained in:
Nils Faerber 2011-11-09 00:11:14 +01:00
parent b11171caa5
commit 681932903c
4 changed files with 53 additions and 3 deletions

View file

@ -170,6 +170,7 @@ int mw_configure_watch_mode(mwdevice_t *mwdevice, unsigned char mode, unsigned c
int mw_update_display(mwdevice_t *mwdevice, unsigned char mode, unsigned char copy)
{
mwdevice->screen_mode = (mode & 0x0f);
return mw_send_frame(mwdevice, MW_UPDATE_DISPLAY, (mode & 0x0f) | ((copy & 0x01) << 4), NULL, 0);
}
@ -449,6 +450,26 @@ void mw_set_read_button_config_response_cb(mwdevice_t *mwdevice, void (*mw_read_
mwdevice->mw_rbtncnfrsp_data = user_data;
}
int mw_button_event_message(mwdevice_t *mwdevice, unsigned char *btnevt, int len, unsigned char opts)
{
#ifdef DEBUG
fprintf(stderr, " button %d options %d\n", btnevt[0], opts);
#endif
if (mwdevice->mw_button_event_message_cb != NULL)
mwdevice->mw_button_event_message_cb(mwdevice, btnevt[0], opts, mwdevice->mw_btnevmsg_data);
return 0;
}
void mw_set_button_event_message_cb(mwdevice_t *mwdevice, void (*mw_button_event_message_cb) (mwdevice_t *mwdevice, unsigned char buttons, unsigned char options, void *user_data), void *user_data)
{
if (mw_button_event_message_cb != NULL)
mwdevice->mw_button_event_message_cb = mw_button_event_message_cb;
if (user_data != NULL)
mwdevice->mw_btnevmsg_data = user_data;
}
int mw_read_light_sensor_response(mwdevice_t *mwdevice, unsigned char *lightrsp, int len)
{
unsigned char power_good = lightrsp[0];
@ -478,9 +499,10 @@ int mw_status_change_event(mwdevice_t *mwdevice, unsigned char option, unsigned
unsigned char mode = (option & 0x0f);
unsigned char status = statrsp[0];
#ifdef DEBUG
fprintf(stderr, "Status change event for mode %s: %s\n", mw_screen_mode_names[option&0x0f], mw_status_string[statrsp[0]]);
fprintf(stderr, "Status change event for mode %s: %s\n", mw_screen_mode_names[mode], mw_status_string[status]);
#endif
// mwdevice->screen_mode = mode;
if (mwdevice->mw_status_change_event_cb != NULL)
mwdevice->mw_status_change_event_cb(mwdevice, &mode, &status, mwdevice->mw_stchev_data);
@ -551,6 +573,7 @@ int mw_decode_frame(mwdevice_t *mwdevice, unsigned char *buf, int len)
break;
case MW_BUTTON_EVENT_MESSAGE:
fprintf(stderr, "Button event message\n");
mw_button_event_message(mwdevice, msgdata, msgdatalen, msgopt);
break;
case MW_LOW_BATTERY_BT_OFF_MSG:
fprintf(stderr, "Watch battery extremely low - radio will turn off\n");