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

@ -7,7 +7,7 @@ PREFIX = /usr/local/
CFLAGS = -Wall -g -DDEBUG -O2 $(CCFLAGS) `pkg-config --cflags glib-2.0` `pkg-config --cflags dbus-glib-1` `pkg-config --cflags dbus-1` `pkg-config --cflags libsoup-2.4`
#CFLAGS = -Wall -O2 $(CCFLAGS)
LDFLAGS = `pkg-config --libs glib-2.0` `pkg-config --libs dbus-glib-1` `pkg-config --libs dbus-1` `pkg-config --libs libsoup-2.4`
LDFLAGS = `pkg-config --libs glib-2.0` `pkg-config --libs dbus-glib-1` `pkg-config --libs dbus-1` `pkg-config --libs libxml-2.0` `pkg-config --libs libsoup-2.4`
PRGNAME = metawatch

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");

View file

@ -17,6 +17,7 @@ typedef struct _mwdevice_t {
char pbuf[MW_PBUF_LEN]; /* protocol receive buffer */
int pbuf_len;
unsigned char devtype; /* the device type of the connected device */
unsigned char screen_mode; /* the current assumed screen mode */
/* watch message callbacks */
void (*mw_get_device_type_response_cb) (struct _mwdevice_t *mwdevice, unsigned char devtype, void *user_data);
void *mw_gdtypersp_data;
@ -26,6 +27,8 @@ typedef struct _mwdevice_t {
void *mw_gbatvrsp_data;
void (*mw_read_button_config_response_cb) (struct _mwdevice_t *mwdevice, void *user_data);
void *mw_rbtncnfrsp_data;
void (*mw_button_event_message_cb) (struct _mwdevice_t *mwdevice, unsigned char buttons, unsigned char options, void *user_data);
void *mw_btnevmsg_data;
void (*mw_read_light_sensor_response_cb) (struct _mwdevice_t *mwdevice, unsigned short *light_level, void *user_data);
void *mw_rlsrsp_data;
void (*mw_status_change_event_cb) (struct _mwdevice_t *mwdevice, unsigned char *scrmode, unsigned char *status, void *user_data);
@ -73,6 +76,9 @@ void mw_set_get_battery_voltage_response_cb(mwdevice_t *mwdevice, void (*mw_get_
int mw_read_button_config_response(mwdevice_t *mwdevice, unsigned char *btnrsp, int len);
int mw_button_event_message(mwdevice_t *mwdevice, unsigned char *btnevt, int len, unsigned char opts);
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);
int mw_read_light_sensor_response(mwdevice_t *mwdevice, unsigned char *lightrsp, int len);
void mw_set_read_light_sensor_response_cb(mwdevice_t *mwdevice, void (*mw_read_light_sensor_response_cb) (mwdevice_t *mwdevice, unsigned short *light_level, void *user_data), void *user_data);

View file

@ -310,7 +310,7 @@ void draw_idle_calendar(mwdevice_t *mwdevice)
px=0;
py=3;
for (i=0; i<7; i++) {
snprintf(pnum, 3, dnames[i]);
snprintf(pnum, 3, "%s", dnames[i]);
mw_buf_print(mwbuf, px, py, pnum, 0, MW_WHITE, MW_BLACK);
px += 14;
};
@ -396,7 +396,13 @@ void test_application(mwdevice_t *mwdevice)
unsigned char *bbuf;
int len;
mw_enable_button(mwdevice, MW_SCREEN_MODE_IDLE, MW_BUTTON_A, MW_BUTTON_IMMEDIATE, MW_BUTTON_EVENT_MESSAGE, MW_BUTTON_A);
mw_enable_button(mwdevice, MW_SCREEN_MODE_APPLICATION, MW_BUTTON_A, MW_BUTTON_IMMEDIATE, MW_BUTTON_EVENT_MESSAGE, MW_BUTTON_A);
mw_enable_button(mwdevice, MW_SCREEN_MODE_APPLICATION, MW_BUTTON_B, MW_BUTTON_IMMEDIATE, MW_BUTTON_EVENT_MESSAGE, MW_BUTTON_B);
mw_enable_button(mwdevice, MW_SCREEN_MODE_APPLICATION, MW_BUTTON_C, MW_BUTTON_IMMEDIATE, MW_BUTTON_EVENT_MESSAGE, MW_BUTTON_C);
mw_enable_button(mwdevice, MW_SCREEN_MODE_APPLICATION, MW_BUTTON_E, MW_BUTTON_IMMEDIATE, MW_BUTTON_EVENT_MESSAGE, MW_BUTTON_E);
mw_enable_button(mwdevice, MW_SCREEN_MODE_APPLICATION, MW_BUTTON_F, MW_BUTTON_IMMEDIATE, MW_BUTTON_EVENT_MESSAGE, MW_BUTTON_F);
mw_configure_watch_mode(mwdevice, MW_SCREEN_MODE_APPLICATION, 0, 30, 0);
mwbuf = mw_alloc_pbuffer(96, 96, 1);
@ -681,6 +687,20 @@ signal_filter (DBusConnection *connection, DBusMessage *message, void *user_data
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
void mw_button_event_message_cb(mwdevice_t *mwdevice, unsigned char buttons, unsigned char options, void *user_data)
{
g_print("button event cb:0x%02x 0x%02x\n", buttons, options);
g_print("screen is %d\n", mwdevice->screen_mode);
if (mwdevice->screen_mode == MW_SCREEN_MODE_IDLE) {
if (buttons == MW_BUTTON_A)
test_application(mwdevice);
}
if (mwdevice->screen_mode == MW_SCREEN_MODE_APPLICATION) {
if (buttons == MW_BUTTON_C)
mw_update_display(mwdevice, MW_SCREEN_MODE_IDLE, 0);
}
}
int main(int argc, char **argv)
{
int mw_fd;
@ -763,6 +783,7 @@ int main(int argc, char **argv)
mdata.cmdline_pos = 0;
mw_init(&mdata.mwdevice, mw_fd);
mw_set_button_event_message_cb(&mdata.mwdevice, mw_button_event_message_cb, NULL);
g_main_loop_run (mdata.mloop);