2 * (c) 2011 Siegen, Germany by Nils Faerber <nils.faerber@kernelconcepts.de>
11 #include "metawatch_protocol.h"
13 #define MW_PBUF_LEN 512
15 typedef struct _mwdevice_t {
16 int mw_fd; /* file decriptor for MW connection */
17 char pbuf[MW_PBUF_LEN]; /* protocol receive buffer */
19 unsigned char devtype; /* the device type of the connected device */
20 /* watch message callbacks */
21 void (*mw_get_device_type_response_cb) (struct _mwdevice_t *mwdevice, unsigned char devtype, void *user_data);
22 void *mw_gdtypersp_data;
23 void (*mw_get_real_time_clock_response_cb) (struct _mwdevice_t *mwdevice, struct tm *mw_tm, void *user_data);
24 void *mw_grtcrsp_data;
25 void (*mw_get_battery_voltage_response_cb) (struct _mwdevice_t *mwdevice, unsigned short *voltage, unsigned char *pgood, unsigned char *charging, void *user_data);
26 void *mw_gbatvrsp_data;
27 void (*mw_read_button_config_response_cb) (struct _mwdevice_t *mwdevice, void *user_data);
28 void *mw_rbtncnfrsp_data;
29 void (*mw_read_light_sensor_response_cb) (struct _mwdevice_t *mwdevice, unsigned short *light_level, void *user_data);
31 void (*mw_status_change_event_cb) (struct _mwdevice_t *mwdevice, unsigned char *scrmode, unsigned char *status, void *user_data);
35 void dump_frame(unsigned char *frame, int len);
38 int mw_send_frame(mwdevice_t *mwdevice, unsigned char msg_type, unsigned char options, unsigned char *data, unsigned char len);
40 int mw_set_rtc(mwdevice_t *mwdevice, unsigned char clk1224, unsigned char date_fmt);
42 int mw_nval_operation(mwdevice_t *mwdevice, unsigned char operation, unsigned short identifier, unsigned char size, void *mdata);
44 int mw_set_vibrate_mode(mwdevice_t *mwdevice, unsigned char enable, unsigned short on_time, unsigned short off_time, unsigned char cycles);
46 int mw_configure_watch_mode(mwdevice_t *mwdevice, unsigned char mode, unsigned char save, unsigned char timeout, unsigned char invert);
48 int mw_update_display(mwdevice_t *mwdevice, unsigned char mode, unsigned char copy);
50 int mw_load_template(mwdevice_t *mwdevice, unsigned char mode, unsigned char template_select);
52 int mw_write_buffer(mwdevice_t *mwdevice,
54 unsigned char numlines, /* number of lines, 0=two lines or 1=one line */
55 unsigned char row_offset, /* start at row_offset in display, e.g. lower part in idle @31 */
56 unsigned char *buffer, int buflen);
58 int mw_write_oled_buffer(mwdevice_t *mwdevice,
59 unsigned char mode, /* idle or scroll */
60 unsigned char oled, /* which OLED */
61 unsigned char numcols,
62 unsigned char col_index, /* starting index */
63 unsigned char *buffer, int buflen);
65 int mw_get_device_type_response(mwdevice_t *mwdevice, unsigned char devtype);
66 void mw_set_get_device_type_response_cb(mwdevice_t *mwdevice, void (*mw_get_device_type_response_cb) (mwdevice_t *mwdevice, unsigned char devtype, void *user_data), void *user_data);
68 int mw_get_real_time_clock_response(mwdevice_t *mwdevice, unsigned char *rtcrsp, int len);
69 void mw_set_get_real_time_clock_response_cb(mwdevice_t *mwdevice, void (*mw_get_real_time_clock_response_cb) (mwdevice_t *mwdevice, struct tm *mw_tm, void *user_data), void *user_data);
71 int mw_get_battery_voltage_response(mwdevice_t *mwdevice, unsigned char *batrsp, int len);
72 void mw_set_get_battery_voltage_response_cb(mwdevice_t *mwdevice, void (*mw_get_battery_voltage_response_cb) (mwdevice_t *mwdevice, unsigned short *voltage, unsigned char *pgood, unsigned char *charging, void *user_data), void *user_data);
74 int mw_read_button_config_response(mwdevice_t *mwdevice, unsigned char *btnrsp, int len);
76 int mw_read_light_sensor_response(mwdevice_t *mwdevice, unsigned char *lightrsp, int len);
77 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);
79 int mw_status_change_event(mwdevice_t *mwdevice, unsigned char option, unsigned char *statrsp, int len);
80 void mw_set_status_change_event_cb(mwdevice_t *mwdevice, void (*mw_status_change_event_cb) (mwdevice_t *mwdevice, unsigned char *scrmode, unsigned char *status, void *user_data), void *user_data);
82 int mw_enable_button(mwdevice_t *mwdevice, unsigned char mode, unsigned char button_index, unsigned char press_type, unsigned char callback_type, unsigned char callback_option);
84 int mw_disable_button(mwdevice_t *mwdevice, unsigned char mode, unsigned char button_index, unsigned char press_type);
86 int mw_advance_watch_hands(mwdevice_t *mwdevice, unsigned char hours, unsigned char minutes, unsigned char seconds);
88 int mw_decode_frame(mwdevice_t *mwdevice, unsigned char *buf, int len);
90 int mw_feed_msg_buffer(mwdevice_t *mwdevice, unsigned char *buf, int len);
92 int mw_init(mwdevice_t *mwdevice, int mw_fd);
94 /* helper function to flip bit order in a byte and optionally invert the image */
95 void bmap_buffer_flipinvert(unsigned char flip, unsigned char invert, unsigned char *buf, int len);
97 void mw_send_bitmap(mwdevice_t *mwdevice, unsigned char mode, int width, int height, int offset, unsigned char *bmapbuf, int buflen);
99 #endif /* _METAWATCH_H */