Add button messages and handling
This commit is contained in:
parent
b13e74e7ce
commit
6e7a56e3e8
3 changed files with 110 additions and 5 deletions
53
metawatch.c
53
metawatch.c
|
@ -182,6 +182,37 @@ void mw_write_buffer(int mw_fd,
|
||||||
mw_send_frame(mw_fd, MW_WRITE_BUFFER, (mode & 0x0f) | (((numlines & 0x01)<< 4) & 0x10), mdata, numlines ? 13 : 26);
|
mw_send_frame(mw_fd, MW_WRITE_BUFFER, (mode & 0x0f) | (((numlines & 0x01)<< 4) & 0x10), mdata, numlines ? 13 : 26);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void mw_enable_button(int mw_fd,
|
||||||
|
unsigned char mode,
|
||||||
|
unsigned char button_index,
|
||||||
|
unsigned char press_type,
|
||||||
|
unsigned char callback_type,
|
||||||
|
unsigned char callback_option)
|
||||||
|
{
|
||||||
|
unsigned char mdata[32];
|
||||||
|
|
||||||
|
memset(mdata, 0, 32);
|
||||||
|
mdata[0] = mode;
|
||||||
|
mdata[1] = button_index;
|
||||||
|
mdata[2] = press_type;
|
||||||
|
mdata[3] = callback_type;
|
||||||
|
mdata[4] = callback_option;
|
||||||
|
mw_send_frame(mw_fd, MW_ENABLE_BUTTON, 0, mdata, 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mw_disable_button(int mw_fd,
|
||||||
|
unsigned char mode,
|
||||||
|
unsigned char button_index,
|
||||||
|
unsigned char press_type)
|
||||||
|
{
|
||||||
|
unsigned char mdata[32];
|
||||||
|
|
||||||
|
memset(mdata, 0, 32);
|
||||||
|
mdata[0] = mode;
|
||||||
|
mdata[1] = button_index;
|
||||||
|
mdata[2] = press_type;
|
||||||
|
mw_send_frame(mw_fd, MW_ENABLE_BUTTON, 0, mdata, 3);
|
||||||
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
* Watch responses, events or notifications
|
* Watch responses, events or notifications
|
||||||
|
@ -222,6 +253,22 @@ void mw_get_battery_voltage_response(int mw_fd, unsigned char *batrsp, int len)
|
||||||
fprintf(stderr, "battery is at %dV, %s and %s\n", voltage, power_good ? "power is good" : "power fault", bat_charging ? "charging" : "not charging");
|
fprintf(stderr, "battery is at %dV, %s and %s\n", voltage, power_good ? "power is good" : "power fault", bat_charging ? "charging" : "not charging");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void mw_read_button_config_response(int mw_fd, unsigned char *btnrsp, int len)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "read button config response\n");
|
||||||
|
fprintf(stderr, "screen mode : 0x%02x\n", btnrsp[0]);
|
||||||
|
fprintf(stderr, "button index : 0x%02x\n", btnrsp[1]);
|
||||||
|
fprintf(stderr, "mask table : 0x%02x (", btnrsp[2]);
|
||||||
|
fprintf(stderr, "%s ", (btnrsp[2] & 0x01) ? "Absolute, " : "");
|
||||||
|
fprintf(stderr, "%s ", (btnrsp[2] & 0x02) ? "Press&Release, " : "");
|
||||||
|
fprintf(stderr, "%s ", (btnrsp[2] & 0x04) ? "Press&Hold, " : "");
|
||||||
|
fprintf(stderr, "%s ", (btnrsp[2] & 0x08) ? "Press&LongHold, " : "");
|
||||||
|
fprintf(stderr, "%s ", (btnrsp[2] & 0x10) ? "Immediate" : "");
|
||||||
|
fprintf(stderr, ")\n");
|
||||||
|
fprintf(stderr, "callback msg type: 0x%02x\n", btnrsp[3]);
|
||||||
|
fprintf(stderr, "callback msg opts: 0x%02d\n", btnrsp[4]);
|
||||||
|
}
|
||||||
|
|
||||||
void mw_read_light_sensor_response(int mw_fd, unsigned char *lightrsp, int len)
|
void mw_read_light_sensor_response(int mw_fd, unsigned char *lightrsp, int len)
|
||||||
{
|
{
|
||||||
unsigned char power_good = lightrsp[0];
|
unsigned char power_good = lightrsp[0];
|
||||||
|
@ -316,6 +363,12 @@ int decode_frame(int mw_fd, unsigned char *buf, int len)
|
||||||
case MW_LOW_BATTERY_WARNING_MSG:
|
case MW_LOW_BATTERY_WARNING_MSG:
|
||||||
fprintf(stderr, "Watch battery low, please connect charger\n");
|
fprintf(stderr, "Watch battery low, please connect charger\n");
|
||||||
break;
|
break;
|
||||||
|
case MW_READ_BUTTON_CONFIG_RSP:
|
||||||
|
mw_read_button_config_response(mw_fd, msgdata, len-2);
|
||||||
|
break;
|
||||||
|
case MW_BUTTON_EVENT_MESSAGE:
|
||||||
|
fprintf(stderr, "Button event message\n");
|
||||||
|
break;
|
||||||
case MW_LOW_BATTERY_BT_OFF_MSG:
|
case MW_LOW_BATTERY_BT_OFF_MSG:
|
||||||
fprintf(stderr, "Watch battery extremely low - radio will turn off\n");
|
fprintf(stderr, "Watch battery extremely low - radio will turn off\n");
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -65,11 +65,28 @@
|
||||||
#define MW_ACCELEROMETER 0xea
|
#define MW_ACCELEROMETER 0xea
|
||||||
|
|
||||||
|
|
||||||
|
/* screen modes */
|
||||||
#define MW_SCREEN_MODE_IDLE 0x00
|
#define MW_SCREEN_MODE_IDLE 0x00
|
||||||
#define MW_SCREEN_MODE_APPLICATION 0x01
|
#define MW_SCREEN_MODE_APPLICATION 0x01
|
||||||
#define MW_SCREEN_MODE_NOTIFICATION 0x02
|
#define MW_SCREEN_MODE_NOTIFICATION 0x02
|
||||||
#define MW_SCREEN_MODE_SCROLL 0x03
|
#define MW_SCREEN_MODE_SCROLL 0x03
|
||||||
|
|
||||||
|
|
||||||
|
/* button definitions */
|
||||||
|
#define MW_BUTTON_A 0x00
|
||||||
|
#define MW_BUTTON_B 0x01
|
||||||
|
#define MW_BUTTON_C 0x02
|
||||||
|
#define MW_BUTTON_D 0x03
|
||||||
|
#define MW_BUTTON_RES4 0x04
|
||||||
|
#define MW_BUTTON_E 0x05
|
||||||
|
#define MW_BUTTON_F 0x06
|
||||||
|
#define MW_BUTTON_PULLSW 0x07
|
||||||
|
|
||||||
|
#define MW_BUTTON_IMMEDIATE 0x00
|
||||||
|
#define MW_BUTTON_PRESS_AND_RELEASE 0x01
|
||||||
|
#define MW_BUTTON_HOLD_RELEASE 0x02
|
||||||
|
#define MW_BUTTON_LONG_HOLD_RELEASE 0x03
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
45
mw_main.c
45
mw_main.c
|
@ -217,6 +217,35 @@ void test_notification(int mw_fd)
|
||||||
mw_set_vibrate_mode(mw_fd, 1, 300, 300, 3);
|
mw_set_vibrate_mode(mw_fd, 1, 300, 300, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_application(int mw_fd)
|
||||||
|
{
|
||||||
|
mw_buffer *mwbuf;
|
||||||
|
unsigned char *bbuf;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
mw_enable_button(mw_fd, MW_SCREEN_MODE_APPLICATION, MW_BUTTON_A, MW_BUTTON_IMMEDIATE, MW_BUTTON_EVENT_MESSAGE, MW_BUTTON_A);
|
||||||
|
mw_configure_watch_mode(mw_fd, MW_SCREEN_MODE_APPLICATION, 0, 30, 0);
|
||||||
|
|
||||||
|
mwbuf = mw_alloc_pbuffer(96, 96, 1);
|
||||||
|
mw_buf_clear(mwbuf, MW_BLACK);
|
||||||
|
|
||||||
|
mw_buf_print(mwbuf, 0, 0, " Application ", 0, MW_BLACK, MW_WHITE);
|
||||||
|
mw_buf_print(mwbuf, 0, 9, "0123456789012345", 0, MW_WHITE, MW_BLACK);
|
||||||
|
mw_buf_print(mwbuf, 0, 18, "0123456789g12345", 0, MW_WHITE, MW_BLACK);
|
||||||
|
mw_buf_print(mwbuf, 0, 27, "0123456789012345", 0, MW_WHITE, MW_BLACK);
|
||||||
|
mw_buf_print(mwbuf, 0, 36, "0123456789012345", 0, MW_WHITE, MW_BLACK);
|
||||||
|
mw_buf_print(mwbuf, 0, 45, "0123456789012345", 0, MW_WHITE, MW_BLACK);
|
||||||
|
mw_buf_print(mwbuf, 0, 54, "0123456789g12345", 0, MW_WHITE, MW_BLACK);
|
||||||
|
mw_buf_print(mwbuf, 0, 63, "0123456789012345", 0, MW_WHITE, MW_BLACK);
|
||||||
|
mw_buf_print(mwbuf, 0, 72, "0123456789012345", 0, MW_WHITE, MW_BLACK);
|
||||||
|
mw_buf_print(mwbuf, 0, 81, "0123456789012345", 0, MW_WHITE, MW_BLACK);
|
||||||
|
|
||||||
|
bbuf = mw_make_mw_buffer(mwbuf, &len);
|
||||||
|
mw_send_bitmap(mw_fd, MW_SCREEN_MODE_APPLICATION, 96, 96, 0, bbuf, len);
|
||||||
|
mw_update_display(mw_fd, MW_SCREEN_MODE_APPLICATION, 1);
|
||||||
|
mw_free_pbuffer(mwbuf);
|
||||||
|
}
|
||||||
|
|
||||||
void print_help(void)
|
void print_help(void)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -224,6 +253,7 @@ void print_help(void)
|
||||||
void process_cmd(char *cmdline, int clinep, int mw_fd)
|
void process_cmd(char *cmdline, int clinep, int mw_fd)
|
||||||
{
|
{
|
||||||
unsigned char mdata[32];
|
unsigned char mdata[32];
|
||||||
|
unsigned int intopt;
|
||||||
|
|
||||||
fprintf(stderr, "command: '%s'\n", cmdline);
|
fprintf(stderr, "command: '%s'\n", cmdline);
|
||||||
|
|
||||||
|
@ -259,12 +289,14 @@ void process_cmd(char *cmdline, int clinep, int mw_fd)
|
||||||
mw_update_display(mw_fd, MW_SCREEN_MODE_IDLE, 0);
|
mw_update_display(mw_fd, MW_SCREEN_MODE_IDLE, 0);
|
||||||
}
|
}
|
||||||
if (strncmp(cmdline, "rbtcfg", 6) == 0) {
|
if (strncmp(cmdline, "rbtcfg", 6) == 0) {
|
||||||
|
intopt = cmdline[7]-0x30;
|
||||||
mdata[0] = 0; /* idle screen */
|
mdata[0] = 0; /* idle screen */
|
||||||
mdata[1] = 1; /* button index */
|
mdata[1] = intopt; /* button index */
|
||||||
mdata[2] = 2; /* button press type */
|
/* for reading the config those are unnecessary */
|
||||||
mdata[3] = 3; /* callback message type */
|
mdata[2] = 0; /* button press type */
|
||||||
mdata[4] = 4; /* callback message option */
|
mdata[3] = 0; /* callback message type */
|
||||||
mw_send_frame(mw_fd, MW_READ_BUTTON_CONFIG, 0, NULL, 0);
|
mdata[4] = 0; /* callback message option */
|
||||||
|
mw_send_frame(mw_fd, MW_READ_BUTTON_CONFIG, 0, mdata, 5);
|
||||||
}
|
}
|
||||||
if (strncmp(cmdline, "svib", 4) == 0) {
|
if (strncmp(cmdline, "svib", 4) == 0) {
|
||||||
mw_set_vibrate_mode(mw_fd, 1, 300, 300, 5);
|
mw_set_vibrate_mode(mw_fd, 1, 300, 300, 5);
|
||||||
|
@ -287,6 +319,9 @@ void process_cmd(char *cmdline, int clinep, int mw_fd)
|
||||||
if (strncmp(cmdline, "tnote", 5) == 0) {
|
if (strncmp(cmdline, "tnote", 5) == 0) {
|
||||||
test_notification(mw_fd);
|
test_notification(mw_fd);
|
||||||
}
|
}
|
||||||
|
if (strncmp(cmdline, "tapp", 4) == 0) {
|
||||||
|
test_application(mw_fd);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue