Fixes and enhancements

This commit is contained in:
Nils Faerber 2011-07-30 17:22:05 +02:00
parent a69eb10937
commit 8f684d091f
4 changed files with 75 additions and 18 deletions

View file

@ -1,7 +1,8 @@
# Copyright (C) 2011 Nils Faerber <nils.faerber@kernelconcepts.de>
# prefix for installation and search path (like icons)
PREFIX = /usr/local/
CFLAGS = -DDEBUG -Wall -O2 $(CCFLAGS)
#CFLAGS = -DDEBUG -Wall -O2 $(CCFLAGS)
CFLAGS = -Wall -O2 $(CCFLAGS)
PRGNAME = metawatch

View file

@ -209,9 +209,20 @@ 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");
}
void mw_read_light_sensor_response(int mw_fd, unsigned char *lightrsp, int len)
{
unsigned char power_good = lightrsp[0];
unsigned char bat_charging = lightrsp[1];
unsigned short voltage = *(unsigned short *)(lightrsp+2);
fprintf(stderr, "light sensor is at %d, power stat: %s and %s\n", voltage, power_good ? "power is good" : "power fault", bat_charging ? "charging" : "not charging");
}
void mw_status_change_event(int mw_fd, unsigned char option, unsigned char *statrsp, int len)
{
#ifdef DEBUG
fprintf(stderr, "Status change event for mode %s: %s\n", mw_screen_mode_names[option&0x0f], mw_status_string[statrsp[0]]);
#endif
}
@ -233,13 +244,19 @@ int decode_frame(int mw_fd, unsigned char *buf, int len)
if (crc != crc16ccitt(buf, len-2)) {
fprintf(stderr, "decode frame CRC error\n");
return 1;
} else
}
#ifdef DEBUG
else
fprintf(stderr, "decode frame CRC OK\n");
#endif
if (buf[0] != MW_SOF) {
fprintf(stderr, "decode frame SOF not found\n");
return 1;
} else
}
#ifdef DEBUG
else
fprintf(stderr, "decode frame found SOF\n");
#endif
msglen = buf[1];
msgtype = buf[2];
@ -247,15 +264,41 @@ int decode_frame(int mw_fd, unsigned char *buf, int len)
msgdata = (buf+4);
switch (msgtype) {
case MW_GET_REAL_TIME_CLOCK_RSP:
mw_get_real_time_clock_response(mw_fd, msgdata, len-4-2);
case MW_GET_DEVICE_TYPE_RSP:
fprintf(stderr, "Got device type ");
switch(msgdata[0]) {
case 0:
fprintf(stderr, "Reserved\n");
break;
case 1:
fprintf(stderr, "Ana-Digi\n");
break;
case 2:
fprintf(stderr, "Digital\n");
break;
case 3:
fprintf(stderr, "Development Board Digital\n");
break;
case 4:
fprintf(stderr, "Development Board Ana-Digi\n");
break;
default:
fprintf(stderr, "unknown %d\n", msgdata[0]);
break;
};
break;
case MW_GET_INFORMATION_STRING_RSP:
msgdata[len-4-2] = 0;
fprintf(stderr, "Got info string '%s'\n", (msgdata+4));
msgdata[len-2] = 0;
fprintf(stderr, "Got info string '%s'\n", msgdata);
break;
case MW_GET_REAL_TIME_CLOCK_RSP:
mw_get_real_time_clock_response(mw_fd, msgdata, len-2);
break;
case MW_READ_BATTERY_VOLTAGE_RSP:
mw_get_battery_voltage_response(mw_fd, msgdata, len-4-2);
mw_get_battery_voltage_response(mw_fd, msgdata, len-2);
break;
case MW_READ_LIGHT_SENSOR_RSP:
mw_read_light_sensor_response(mw_fd, msgdata, len-2);
break;
case MW_LOW_BATTERY_WARNING_MSG:
fprintf(stderr, "Watch battery low, please connect charger\n");
@ -264,7 +307,7 @@ int decode_frame(int mw_fd, unsigned char *buf, int len)
fprintf(stderr, "Watch battery extremely low - radio will turn off\n");
break;
case MW_STATUS_CHANGE_EVENT:
mw_status_change_event(mw_fd, msgopt, msgdata, len-4-2);
mw_status_change_event(mw_fd, msgopt, msgdata, len-2);
break;
default:
fprintf(stderr, "Unkown msgtype 0x%02x\n", msgtype);
@ -303,9 +346,10 @@ void bmap_buffer_flipinvert(unsigned char flip, unsigned char invert, unsigned c
void mw_send_bitmap(int mw_fd, unsigned char mode, int width, int height, int offset, unsigned char *bmapbuf, int buflen)
{
char rbuf[256];
unsigned int i, x, y;
unsigned int rowlength;
#ifdef DEBUG
unsigned int i, x;
#endif
unsigned int y, rowlength;
unsigned char mw_buf[24];
rowlength = ((width / 8) + 1);

View file

@ -47,7 +47,8 @@
#define MW_LOW_BATTERY_BT_OFF_MSG 0x55
#define MW_READ_BATTERY_VOLTAGE_MSG 0x56
#define MW_READ_BATTERY_VOLTAGE_RSP 0x57
#define MW_READ_LIGHT_SENSOR_MSG 0x58
#define MW_READ_LIGHT_SENSOR_RSP 0x59
#define MW_ACCELEROMETER 0xea

View file

@ -51,7 +51,10 @@ void bitmap_read(int mw_fd)
{
int ffd, ret;
char rbuf[256];
unsigned int width, height, i, x, y;
unsigned int width, height, i;
#ifdef DEBUG
unsigned int x, y;
#endif
unsigned int rowlength;
unsigned char *bmapbuf;
// unsigned char mw_buf[24];
@ -103,7 +106,7 @@ void bitmap_read(int mw_fd)
#endif
/* reverse bits and invert the bmap */
bmap_buffer_flipinvert(1, 0, bmapbuf, rowlength * height);
bmap_buffer_flipinvert(1, 1, bmapbuf, rowlength * height);
/* send the buffer to the watch */
mw_send_bitmap(mw_fd, MW_SCREEN_MODE_IDLE, width, height, 31, bmapbuf, rowlength * height);
/* update the display */
@ -138,8 +141,7 @@ void process_cmd(char *cmdline, int clinep, int mw_fd)
mw_send_frame(mw_fd, MW_GET_REAL_TIME_CLOCK, 0, NULL, 0);
}
if (strncmp(cmdline, "gistr", 5) == 0) {
mdata[0] = 0;
mw_send_frame(mw_fd, MW_GET_INFORMATION_STRING, 0, mdata, 1);
mw_send_frame(mw_fd, MW_GET_INFORMATION_STRING, 0, NULL, 0);
}
if (strncmp(cmdline, "gdtype", 6) == 0) {
mw_send_frame(mw_fd, MW_GET_DEVICE_TYPE, 0, NULL, 0);
@ -147,6 +149,9 @@ void process_cmd(char *cmdline, int clinep, int mw_fd)
if (strncmp(cmdline, "rvbat", 5) == 0) {
mw_send_frame(mw_fd, MW_READ_BATTERY_VOLTAGE_MSG, 0, NULL, 0);
}
if (strncmp(cmdline, "rlight", 6) == 0) {
mw_send_frame(mw_fd, MW_READ_LIGHT_SENSOR_MSG, 0, NULL, 0);
}
if (strncmp(cmdline, "modecfg", 6) == 0) {
mw_configure_watch_mode(mw_fd, MW_SCREEN_MODE_IDLE, 0, 4, 1);
mw_update_display(mw_fd, MW_SCREEN_MODE_IDLE, 0);
@ -203,9 +208,13 @@ int menu(int mw_fd)
if (select(mw_fd+1, &mfds, NULL, NULL, NULL) > 0) {
if (FD_ISSET(mw_fd, &mfds)) {
rcvd = read(mw_fd, msg_buf, 64);
#ifdef DEBUG
fprintf(stderr, "read %d bytes:\n", rcvd);
#endif
if (rcvd > 0) {
#ifdef DEBUG
dump_frame(msg_buf, rcvd);
#endif
decode_frame(mw_fd, msg_buf, rcvd);
}
};
@ -241,7 +250,7 @@ int open_socket(bdaddr_t *bdaddr, uint8_t channel)
{
struct sockaddr_rc addr;
int sk, opt;
int f;
//int f;
sk = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
if (sk < 0) {
@ -375,6 +384,8 @@ int main(int argc, char **argv)
mw_fd = open_socket(&btaddr, 1);
if (mw_fd < 0) {
return 1;
} else {
fprintf(stderr, "connected to %s\n", argv[1]);
};
#endif