More functions, changed license to LGPL
This commit is contained in:
parent
c8307dc90a
commit
8de8db41a6
1 changed files with 42 additions and 1 deletions
43
metawatch.c
43
metawatch.c
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* (c) 2011 Siegen, Germany by Nils Faerber
|
* (c) 2011 Siegen, Germany by Nils Faerber
|
||||||
*
|
*
|
||||||
* license GPL
|
* license LGPL
|
||||||
*/
|
*/
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
@ -17,6 +17,8 @@
|
||||||
#include "crc16ccitt.h"
|
#include "crc16ccitt.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define MW_FRAME_DELAY 0x00
|
||||||
|
|
||||||
void dump_frame(unsigned char *frame, int len)
|
void dump_frame(unsigned char *frame, int len)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
@ -50,6 +52,9 @@ int mw_send_frame(int mw_fd, unsigned char msg_type, unsigned char options, unsi
|
||||||
while (((ret = write(mw_fd, frame, tlen)) >= 0) && (tlen > 0))
|
while (((ret = write(mw_fd, frame, tlen)) >= 0) && (tlen > 0))
|
||||||
tlen -= ret;
|
tlen -= ret;
|
||||||
|
|
||||||
|
if (MW_FRAME_DELAY)
|
||||||
|
usleep(MW_FRAME_DELAY);
|
||||||
|
|
||||||
if (tlen == 0 && ret >= 0)
|
if (tlen == 0 && ret >= 0)
|
||||||
return 0;
|
return 0;
|
||||||
else
|
else
|
||||||
|
@ -110,6 +115,41 @@ void mw_update_display(int mw_fd, unsigned char mode, unsigned char copy)
|
||||||
mw_send_frame(mw_fd, MW_UPDATE_DISPLAY, (mode & 0x0f) | ((copy & 0x01) << 3), NULL, 0);
|
mw_send_frame(mw_fd, MW_UPDATE_DISPLAY, (mode & 0x0f) | ((copy & 0x01) << 3), NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void mw_load_template(int mw_fd, unsigned char mode, unsigned char template_select)
|
||||||
|
{
|
||||||
|
mw_send_frame(mw_fd, MW_LOAD_TEMPLATE, (mode & 0x0f), &template_select, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* send line for screen-mode mode from *buffer to watch, starting at display row row_offset
|
||||||
|
*/
|
||||||
|
void mw_write_buffer(int mw_fd,
|
||||||
|
unsigned char mode,
|
||||||
|
unsigned char numlines, /* number of lines, 0 or 1 */
|
||||||
|
unsigned char row_offset, /* start at row_offset in display, e.g. lower part in idle @31 */
|
||||||
|
unsigned char *buffer, int buflen)
|
||||||
|
{
|
||||||
|
unsigned char mdata[32];
|
||||||
|
|
||||||
|
buflen = 12 * (buflen / 12); /* crop to 12 bytes */
|
||||||
|
if ((numlines == 0 && buflen < 12) || (numlines == 1 && buflen < 24)) {
|
||||||
|
fprintf(stderr, "mw_write_buffer: bufferlen does not match number of lines\n");
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
memset(mdata, 0, 32);
|
||||||
|
mdata[0] = row_offset;
|
||||||
|
memcpy((mdata+1), buffer, 12);
|
||||||
|
if (numlines == 1) {
|
||||||
|
mdata[0] = row_offset+1;
|
||||||
|
memcpy((mdata+13), (buffer+12), 12);
|
||||||
|
};
|
||||||
|
mw_send_frame(mw_fd, MW_WRITE_BUFFER, (mode & 0x0f) | (((numlines & 0x01)<< 3) & 0x10), mdata, numlines ? 13 : 26);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------ */
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* watch responses, events or notifications
|
* watch responses, events or notifications
|
||||||
*/
|
*/
|
||||||
|
@ -147,6 +187,7 @@ 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");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
int decode_frame(int mw_fd, unsigned char *buf, int len)
|
int decode_frame(int mw_fd, unsigned char *buf, int len)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue