2 * (c) 2011 Siegen, Germany by Nils Faerber <nils.faerber@kernelconcepts.de>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 #include <sys/types.h>
31 #include "metawatch.h"
32 #include "metawatch_protocol.h"
33 #include "crc16ccitt.h"
37 const char *mw_screen_mode_names[] = {
40 "notification screen",
44 const char *mw_status_string[] = {
52 #define MW_FRAME_DELAY 0x00
54 /* ----------------------------------------------------------------------
56 * ---------------------------------------------------------------------- */
58 void dump_frame(unsigned char *frame, int len)
63 fprintf(stderr, "0x%02x ", frame[i]);
64 fprintf(stderr, "\n");
68 int mw_send_frame(mwdevice_t *mwdevice, unsigned char msg_type, unsigned char options, unsigned char *data, unsigned char len)
71 unsigned char frame[64];
72 int tlen = len + 6; /* payload + 6 bytes frameing */
80 if (data != NULL && len > 0)
81 memcpy(frame+4, data, len);
83 crc = crc16ccitt(frame, len+4);
84 *(unsigned short *)(frame+len+4) = crc;
87 dump_frame(frame, tlen);
90 while (((ret = write(mwdevice->mw_fd, frame, tlen)) >= 0) && (tlen > 0))
94 usleep(MW_FRAME_DELAY);
96 if (tlen == 0 && ret >= 0)
103 /* ----------------------------------------------------------------------
104 * Host to watch commands
105 * ---------------------------------------------------------------------- */
108 int mw_set_rtc(mwdevice_t *mwdevice, struct tm *mw_tm)
111 unsigned char data[32];
113 year = mw_tm->tm_year + 1900;
114 data[0] = (year & 0x0f00) >> 8;
115 data[1] = (year & 0x00ff);
116 data[2] = mw_tm->tm_mon + 1;
117 data[3] = mw_tm->tm_mday;
118 data[4] = mw_tm->tm_wday;
119 data[5] = mw_tm->tm_hour;
120 data[6] = mw_tm->tm_min;
121 data[7] = mw_tm->tm_sec;
123 return mw_send_frame(mwdevice, MW_SET_REAL_TIME_CLOCK, 0, data, 8);
126 int mw_nval_operation(mwdevice_t *mwdevice, unsigned char operation, unsigned short identifier, unsigned char size, void *mdata)
128 unsigned char data[32];
130 data[0] = (identifier & 0x00ff);
131 data[1] = (identifier & 0xff00) >> 8;
133 if (size > 0 && mdata != NULL)
134 memcpy((data+3), mdata, size);
136 if (operation == MW_NVAL_OPERATION_READ || operation == MW_NVAL_OPERATION_WRITE) {
137 return mw_send_frame(mwdevice, MW_NVAL_OPERATION, operation, data, 3+size);
142 int mw_set_vibrate_mode(mwdevice_t *mwdevice, unsigned char enable, unsigned short on_time, unsigned short off_time, unsigned char cycles)
144 unsigned char mdata[7];
147 *(unsigned short *)(mdata+1) = on_time; /* miliseconds */
148 *(unsigned short *)(mdata+3) = off_time; /* miliseconds */
151 return mw_send_frame(mwdevice, MW_SET_VIBRATE_MODE, 0, mdata, 6);
154 int mw_configure_watch_mode(mwdevice_t *mwdevice, unsigned char mode, unsigned char save, unsigned char timeout, unsigned char invert)
156 unsigned char mdata[3];
158 mdata[0] = timeout; /* seconds */
159 mdata[1] = invert; /* 0=normal, 1=invert */
161 return mw_send_frame(mwdevice, MW_CONFIGURE_MODE, (mode & 0x0f) | ((save & 0x01) << 4), mdata, 2);
164 int mw_update_display(mwdevice_t *mwdevice, unsigned char mode, unsigned char copy)
166 mwdevice->screen_mode = (mode & 0x0f);
167 return mw_send_frame(mwdevice, MW_UPDATE_DISPLAY, (mode & 0x0f) | ((copy & 0x01) << 4), NULL, 0);
170 int mw_load_template(mwdevice_t *mwdevice, unsigned char mode, unsigned char template_select)
172 return mw_send_frame(mwdevice, MW_LOAD_TEMPLATE, (mode & 0x0f), &template_select, 1);
176 * send line for screen-mode mode from *buffer to watch, starting at display row row_offset
177 * this is only for digital LCD watch
179 int mw_write_buffer(mwdevice_t *mwdevice,
181 unsigned char numlines, /* number of lines, 0=two lines or 1=one line */
182 unsigned char row_offset, /* start at row_offset in display, e.g. lower part in idle @31 */
183 unsigned char *buffer, int buflen)
185 unsigned char mdata[32];
187 if (mwdevice->devtype != MW_DEVICE_TYPE_DIGITAL && mwdevice->devtype != MW_DEVICE_TYPE_DEVB_DIGI)
190 buflen = 12 * (buflen / 12); /* crop to 12 bytes */
191 if ((numlines == 0 && buflen < 12) || (numlines == 1 && buflen < 24)) {
192 fprintf(stderr, "mw_write_buffer: bufferlen does not match number of lines\n");
195 memset(mdata, 0, 32);
196 mdata[0] = row_offset;
197 memcpy((mdata+1), buffer, 12);
199 mdata[13] = row_offset+1;
200 memcpy((mdata+14), (buffer+12), 12);
203 return mw_send_frame(mwdevice, MW_WRITE_BUFFER, (mode & 0x0f) | (((numlines & 0x01)<< 4) & 0x10), mdata, numlines ? 13 : 26);
208 B0 : row select, 0 first row, 1 second row
209 B1 : display select, 0 upper OLED, 1 lower OLED
210 B2 : if 1 send an event upon completion
214 B0: First buffer in a chain of scroll buffers
215 B1: Any buffer except first or last
216 B2: Last buffer of a chain
217 B3: reserved / unused
222 int mw_write_oled_buffer(mwdevice_t *mwdevice,
223 unsigned char mode, /* idle or scroll */
224 unsigned char oled, /* which OLED */
225 unsigned char numcols,
226 unsigned char col_index, /* starting index */
227 unsigned char *buffer, int buflen)
229 unsigned char mdata[32];
232 if (mwdevice->devtype != MW_DEVICE_TYPE_ANA_DIGI && mwdevice->devtype != MW_DEVICE_TYPE_DEVB_ANA_DIGI)
235 fprintf(stderr, "write oled buf len = %d\n", buflen);
236 /* lower row first since display wil be updated after completion of upper row */
238 for (i=80; i<buflen; i+=20) {
240 memcpy((mdata+1), (buffer+i), 20);
241 mw_send_frame(mwdevice, MW_WRITE_OLED_IDLE_DISPLAY_MSG, 0 | (oled ? 2 : 0), mdata, 21);
244 for (i=0; i<80; i+=20) {
246 memcpy((mdata+1), (buffer+i), 20);
247 mw_send_frame(mwdevice, MW_WRITE_OLED_IDLE_DISPLAY_MSG, 1 | (oled ? 2 : 0), mdata, 21);
253 int mw_enable_button(mwdevice_t *mwdevice,
255 unsigned char button_index,
256 unsigned char press_type,
257 unsigned char callback_type,
258 unsigned char callback_option)
260 unsigned char mdata[32];
262 memset(mdata, 0, 32);
264 mdata[1] = button_index;
265 mdata[2] = press_type;
266 mdata[3] = callback_type;
267 mdata[4] = callback_option;
269 return mw_send_frame(mwdevice, MW_ENABLE_BUTTON, 0, mdata, 5);
272 int mw_disable_button(mwdevice_t *mwdevice,
274 unsigned char button_index,
275 unsigned char press_type)
277 unsigned char mdata[32];
279 memset(mdata, 0, 32);
281 mdata[1] = button_index;
282 mdata[2] = press_type;
284 return mw_send_frame(mwdevice, MW_ENABLE_BUTTON, 0, mdata, 3);
287 int mw_advance_watch_hands(mwdevice_t *mwdevice, unsigned char hours, unsigned char minutes, unsigned char seconds)
289 unsigned char mdata[4];
302 return mw_send_frame(mwdevice, MW_ADVANCE_WATCH_HANDS, 0, mdata, 3);
305 int mw_battery_configuration(mwdevice_t *mwdevice, unsigned char warn_lvl, unsigned char bt_off_lvl)
307 unsigned char mdata[4];
309 if (warn_lvl < 28 || warn_lvl > 42)
311 if (bt_off_lvl < 28 || bt_off_lvl > 42)
315 mdata[1] = bt_off_lvl;
317 return mw_send_frame(mwdevice, MW_BATTERY_CONFIG_MSG, 0, mdata, 2);
321 /* ----------------------------------------------------------------------
322 * Watch responses, events or notifications
323 * ---------------------------------------------------------------------- */
325 int mw_get_device_type_response(mwdevice_t *mwdevice, unsigned char devtype)
328 fprintf(stderr, "Got device type ");
331 fprintf(stderr, "Reserved\n");
334 fprintf(stderr, "Ana-Digi\n");
337 fprintf(stderr, "Digital\n");
340 fprintf(stderr, "Development Board Digital\n");
343 fprintf(stderr, "Development Board Ana-Digi\n");
346 fprintf(stderr, "unknown %d\n", devtype);
350 mwdevice->devtype = devtype;
351 if (mwdevice->mw_get_device_type_response_cb != NULL)
352 mwdevice->mw_get_device_type_response_cb(mwdevice, devtype, mwdevice->mw_gdtypersp_data);
356 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)
358 if (mw_get_device_type_response_cb != NULL)
359 mwdevice->mw_get_device_type_response_cb = mw_get_device_type_response_cb;
360 if (user_data != NULL)
361 mwdevice->mw_gdtypersp_data = user_data;
364 int mw_nval_operation_response(mwdevice_t *mwdevice, unsigned char operation, unsigned short identifier, unsigned char size, void *mdata)
369 int mw_get_real_time_clock_response(mwdevice_t *mwdevice, unsigned char *rtcrsp, int len)
375 fprintf(stderr, "get real time clock response length wrong %d != 10\n", len);
379 year = *(unsigned short *)rtcrsp;
380 mtm.tm_year = year - 1900;
381 mtm.tm_mon = rtcrsp[2] - 1;
382 mtm.tm_mday = rtcrsp[3];
383 mtm.tm_wday = rtcrsp[4];
384 mtm.tm_hour = rtcrsp[5];
385 mtm.tm_min = rtcrsp[6];
386 mtm.tm_sec = rtcrsp[7];
389 fprintf(stderr, "watch RTC is %s\n", asctime(&mtm));
391 if (mwdevice->mw_get_real_time_clock_response_cb != NULL)
392 mwdevice->mw_get_real_time_clock_response_cb(mwdevice, &mtm, mwdevice->mw_grtcrsp_data);
397 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)
399 if (mw_get_real_time_clock_response_cb != NULL)
400 mwdevice->mw_get_real_time_clock_response_cb = mw_get_real_time_clock_response_cb;
401 if (user_data != NULL)
402 mwdevice->mw_grtcrsp_data = user_data;
406 int mw_get_battery_voltage_response(mwdevice_t *mwdevice, unsigned char *batrsp, int len)
408 unsigned char power_good = batrsp[0];
409 unsigned char bat_charging = batrsp[1];
410 unsigned short voltage = *(unsigned short *)(batrsp+2);
411 unsigned short voltage_avg = *(unsigned short *)(batrsp+4);
414 fprintf(stderr, "battery is at %dmV (average is %dmV), %s and %s\n", voltage, voltage_avg, power_good ? "power is good" : "power fault", bat_charging ? "charging" : "not charging");
417 if (mwdevice->mw_get_battery_voltage_response_cb != NULL)
418 mwdevice->mw_get_battery_voltage_response_cb(mwdevice, &voltage, &voltage_avg, &power_good, &bat_charging, mwdevice->mw_gbatvrsp_data);
423 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 short *voltage_avg, unsigned char *pgood, unsigned char *charging, void *user_data), void *user_data)
425 if (mw_get_battery_voltage_response_cb != NULL)
426 mwdevice->mw_get_battery_voltage_response_cb = mw_get_battery_voltage_response_cb;
427 if (user_data != NULL)
428 mwdevice->mw_gbatvrsp_data = user_data;
431 int mw_read_button_config_response(mwdevice_t *mwdevice, unsigned char *btnrsp, int len)
434 fprintf(stderr, "read button config response\n");
435 fprintf(stderr, "screen mode : 0x%02x\n", btnrsp[0]);
436 fprintf(stderr, "button index : 0x%02x\n", btnrsp[1]);
437 fprintf(stderr, "mask table : 0x%02x (", btnrsp[2]);
438 fprintf(stderr, "%s ", (btnrsp[2] & 0x01) ? "Absolute, " : "");
439 fprintf(stderr, "%s ", (btnrsp[2] & 0x02) ? "Press&Release, " : "");
440 fprintf(stderr, "%s ", (btnrsp[2] & 0x04) ? "Press&Hold, " : "");
441 fprintf(stderr, "%s ", (btnrsp[2] & 0x08) ? "Press&LongHold, " : "");
442 fprintf(stderr, "%s ", (btnrsp[2] & 0x10) ? "Immediate" : "");
443 fprintf(stderr, ")\n");
444 fprintf(stderr, "callback msg type: 0x%02x\n", btnrsp[3]);
445 fprintf(stderr, "callback msg opts: 0x%02d\n", btnrsp[4]);
451 void mw_set_read_button_config_response_cb(mwdevice_t *mwdevice, void (*mw_read_button_config_response_cb) (mwdevice_t *mwdevice, void *user_data), void *user_data)
453 if (mw_read_button_config_response_cb != NULL)
454 mwdevice->mw_read_button_config_response_cb = mw_read_button_config_response_cb;
455 if (user_data != NULL)
456 mwdevice->mw_rbtncnfrsp_data = user_data;
459 int mw_button_event_message(mwdevice_t *mwdevice, unsigned char *btnevt, int len, unsigned char opts)
462 fprintf(stderr, " button %d options %d\n", btnevt[0], opts);
465 if (mwdevice->mw_button_event_message_cb != NULL)
466 mwdevice->mw_button_event_message_cb(mwdevice, btnevt[0], opts, mwdevice->mw_btnevmsg_data);
471 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)
473 if (mw_button_event_message_cb != NULL)
474 mwdevice->mw_button_event_message_cb = mw_button_event_message_cb;
475 if (user_data != NULL)
476 mwdevice->mw_btnevmsg_data = user_data;
479 int mw_read_light_sensor_response(mwdevice_t *mwdevice, unsigned char *lightrsp, int len)
481 unsigned short light_level = *(unsigned short *)(lightrsp);
482 unsigned short light_level_avg = *(unsigned short *)(lightrsp+2);
485 fprintf(stderr, "light sensor is at %d, average at %d\n", light_level, light_level_avg);
488 if (mwdevice->mw_read_light_sensor_response_cb != NULL)
489 mwdevice->mw_read_light_sensor_response_cb(mwdevice, &light_level, &light_level_avg, mwdevice->mw_rlsrsp_data);
494 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, unsigned short *light_level_avg, void *user_data), void *user_data)
496 if (mw_read_light_sensor_response_cb != NULL)
497 mwdevice->mw_read_light_sensor_response_cb = mw_read_light_sensor_response_cb;
498 if (user_data != NULL)
499 mwdevice->mw_rlsrsp_data = user_data;
502 int mw_status_change_event(mwdevice_t *mwdevice, unsigned char option, unsigned char *statrsp, int len)
504 unsigned char mode = (option & 0x0f);
505 unsigned char status = statrsp[0];
507 fprintf(stderr, "Status change event for mode %s: %s\n", mw_screen_mode_names[mode], mw_status_string[status]);
510 // mwdevice->screen_mode = mode;
511 if (mwdevice->mw_status_change_event_cb != NULL)
512 mwdevice->mw_status_change_event_cb(mwdevice, &mode, &status, mwdevice->mw_stchev_data);
517 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)
519 if (mw_status_change_event_cb != NULL)
520 mwdevice->mw_status_change_event_cb = mw_status_change_event_cb;
521 if (user_data != NULL)
522 mwdevice->mw_stchev_data = user_data;
525 int mw_low_battery_warning_message(mwdevice_t *mwdevice, unsigned char option, unsigned char *statrsp, int len)
527 if (mwdevice->mw_low_battery_warning_message_cb != NULL)
528 mwdevice->mw_low_battery_warning_message_cb(mwdevice, mwdevice->mw_lbatwarnmsg_data);
533 void mw_set_low_battery_warning_message_cb(mwdevice_t *mwdevice, void (*mw_low_battery_warning_message_cb) (mwdevice_t *mwdevice, void *user_data), void *user_data)
535 if (mw_low_battery_warning_message_cb != NULL)
536 mwdevice->mw_low_battery_warning_message_cb = mw_low_battery_warning_message_cb;
537 if (user_data != NULL)
538 mwdevice->mw_lbatwarnmsg_data = user_data;
541 int mw_low_battery_bt_off_message(mwdevice_t *mwdevice, unsigned char option, unsigned char *statrsp, int len)
543 if (mwdevice->mw_low_battery_bt_off_message_cb != NULL)
544 mwdevice->mw_low_battery_bt_off_message_cb(mwdevice, mwdevice->mw_lbatbtoff_data);
549 void mw_set_low_battery_bt_off_message_cb(mwdevice_t *mwdevice, void (*mw_low_battery_bt_off_message_cb) (mwdevice_t *mwdevice, void *user_data), void *user_data)
551 if (mw_low_battery_bt_off_message_cb != NULL)
552 mwdevice->mw_low_battery_bt_off_message_cb = mw_low_battery_bt_off_message_cb;
553 if (user_data != NULL)
554 mwdevice->mw_lbatbtoff_data = user_data;
557 /* ----------------------------------------------------------------------
559 * ---------------------------------------------------------------------- */
561 int mw_decode_frame(mwdevice_t *mwdevice, unsigned char *buf, int len)
564 unsigned char msglen;
565 unsigned char msgtype;
566 unsigned char msgopt;
567 unsigned char *msgdata;
568 unsigned char msgdatalen;
571 crc = *(unsigned short *)(buf+len-2);
572 if (crc != crc16ccitt(buf, len-2)) {
573 fprintf(stderr, "decode frame CRC error\n");
576 if (buf[0] != MW_SOF) {
577 fprintf(stderr, "decode frame SOF not found\n");
585 msgdatalen = msglen - 4 - 2;
588 case MW_GET_DEVICE_TYPE_RSP:
589 mw_get_device_type_response(mwdevice, msgdata[0]);
591 case MW_GET_INFORMATION_STRING_RSP:
593 fprintf(stderr, "Got info string '%s'\n", msgdata);
595 case MW_GET_REAL_TIME_CLOCK_RSP:
596 mw_get_real_time_clock_response(mwdevice, msgdata, msgdatalen);
598 case MW_READ_BATTERY_VOLTAGE_RSP:
599 mw_get_battery_voltage_response(mwdevice, msgdata, msgdatalen);
601 case MW_READ_LIGHT_SENSOR_RSP:
602 mw_read_light_sensor_response(mwdevice, msgdata, msgdatalen);
604 case MW_READ_BUTTON_CONFIG_RSP:
605 mw_read_button_config_response(mwdevice, msgdata, msgdatalen);
607 case MW_BUTTON_EVENT_MESSAGE:
608 fprintf(stderr, "Button event message\n");
609 mw_button_event_message(mwdevice, msgdata, msgdatalen, msgopt);
611 case MW_LOW_BATTERY_WARNING_MSG:
612 fprintf(stderr, "Watch battery low, please connect charger\n");
614 case MW_LOW_BATTERY_BT_OFF_MSG:
615 fprintf(stderr, "Watch battery extremely low - radio will turn off\n");
617 case MW_NVAL_OPERATION_RSP:
618 fprintf(stderr, "NVAL operation response - ");
621 fprintf(stderr, "success\n");
624 fprintf(stderr, "failure!\n");
627 fprintf(stderr, "Item Not initialized (Identifier Not found\n");
630 fprintf(stderr, "Operation failed\n");
633 fprintf(stderr, "Bad Item length\n");
636 fprintf(stderr, "unknown status 0x%02x\n", msgopt);
640 case MW_STATUS_CHANGE_EVENT:
641 mw_status_change_event(mwdevice, msgopt, msgdata, msgdatalen);
644 fprintf(stderr, "Unkown msgtype 0x%02x\n", msgtype);
652 int mw_feed_msg_buffer(mwdevice_t *mwdevice, unsigned char *buf, int len)
660 memcpy((mwdevice->pbuf+mwdevice->pbuf_len), buf, len);
661 mwdevice->pbuf_len += len;
663 while (mwdevice->pbuf_len > 0) {
664 /* scan for MW_SOF */
665 while (mwdevice->pbuf[0] != MW_SOF) {
666 memmove(mwdevice->pbuf, (mwdevice->pbuf+1), --mwdevice->pbuf_len);
668 tlen = mwdevice->pbuf[1];
669 /* OK, there is an SOF but the message is too short */
670 if (tlen > mwdevice->pbuf_len) {
671 /* we have to wait for more data to come in */
674 /* here we have a complete msg */
675 memcpy(msgbuf, mwdevice->pbuf, tlen);
676 mw_decode_frame(mwdevice, (unsigned char *)msgbuf, tlen);
677 memmove(mwdevice->pbuf, (mwdevice->pbuf+tlen), tlen);
678 mwdevice->pbuf_len -= tlen;
684 /* ----------------------------------------------------------------------
686 * ---------------------------------------------------------------------- */
688 int mw_init(mwdevice_t *mwdevice, int mw_fd)
690 memset(mwdevice, 0, sizeof(mwdevice_t));
691 mwdevice->mw_fd = mw_fd;
692 memset(mwdevice->pbuf, 0, MW_PBUF_LEN);
693 mwdevice->pbuf_len = 0;
695 /* figure out which device we run with */
696 mw_send_frame(mwdevice, MW_GET_DEVICE_TYPE, 0, NULL, 0);
701 /* ----------------------------------------------------------------------
702 * Convenience functions not strictly part of the protocol
703 * ---------------------------------------------------------------------- */
705 int mw_get_resolution(mwdevice_t *mwdevice, unsigned int *width, unsigned int *height)
707 if (width == NULL || height == NULL)
710 switch (mwdevice->devtype) {
711 case MW_DEVICE_TYPE_RESERVED:
713 case MW_DEVICE_TYPE_ANA_DIGI:
714 case MW_DEVICE_TYPE_DEVB_ANA_DIGI:
718 case MW_DEVICE_TYPE_DIGITAL:
719 case MW_DEVICE_TYPE_DEVB_DIGI:
731 /* if flip=1 bits in each byte are inverted 7->1, 6->2, 5->3,...
732 if invert=1 each byte is inverted
734 void bmap_buffer_flipinvert(unsigned char flip, unsigned char invert, unsigned char *buf, int len)
743 tmp |= ((*buf & (1<<i)) >> i) << (7-i);
744 // fprintf(stderr, "0x%02x -> 0x%02x\n", *buf, tmp);
747 *buf = invert ? ~tmp : tmp;
753 void mw_send_bitmap(mwdevice_t *mwdevice, unsigned char mode, int width, int height, int offset, unsigned char *bmapbuf, int buflen)
758 unsigned int y, rowlength;
759 unsigned char mw_buf[24];
761 rowlength = (((width-1) / 8) + 1);
762 if ((height + offset) > 96)
763 height = 96 - offset;
766 fprintf(stderr, "row length = %d bytes\n", rowlength);
767 fprintf(stderr, "bitmap resolution is %d x %d\n", width, height);
768 fprintf(stderr, "\n");
769 for (y=0; y<height; y++) {
770 for (x=0; x<rowlength; x++) {
772 fprintf(stderr, "%c", (bmapbuf[(y*rowlength)+x] & (1<<(7-i))) ? '.' : ' ');
774 fprintf(stderr, "\n");
776 fprintf(stderr, "\n");
779 for (y=0; y<height; y+=2) {
780 memset(mw_buf, 0, 24);
781 memcpy(mw_buf, (bmapbuf+(y*rowlength)), (rowlength > 12) ? 12 : rowlength);
782 memcpy((mw_buf+12), (bmapbuf+((y+1)*rowlength)), (rowlength > 12) ? 12 : rowlength);
783 mw_write_buffer(mwdevice, mode, 0, offset+y, mw_buf, 24);