Start to make cmd functions for future API

This commit is contained in:
Nils Faerber 2011-07-23 18:26:16 +02:00
parent 33ec672c8d
commit c8307dc90a
2 changed files with 42 additions and 17 deletions

View file

@ -27,7 +27,7 @@ void dump_frame(unsigned char *frame, int len)
} }
int mw_send_packet(int mw_fd, unsigned char msg_type, unsigned char options, unsigned char *data, unsigned char len) int mw_send_frame(int mw_fd, unsigned char msg_type, unsigned char options, unsigned char *data, unsigned char len)
{ {
unsigned short crc; unsigned short crc;
unsigned char frame[64]; unsigned char frame[64];
@ -82,7 +82,32 @@ void mw_set_rtc(int mw_fd, unsigned char clk1224, unsigned char date_fmt)
data[8] = clk1224; data[8] = clk1224;
data[9] = date_fmt; data[9] = date_fmt;
mw_send_packet(mw_fd, MW_SET_REAL_TIME_CLOCK, 0, data, 10); mw_send_frame(mw_fd, MW_SET_REAL_TIME_CLOCK, 0, data, 10);
}
void mw_set_vibrate_mode(int mw_fd, unsigned char enable, unsigned short on_time, unsigned short off_time, unsigned char cycles)
{
unsigned char mdata[7];
mdata[0] = enable;
*(unsigned short *)(mdata+1) = on_time; /* miliseconds */
*(unsigned short *)(mdata+3) = off_time; /* miliseconds */
mdata[5] = cycles;
mw_send_frame(mw_fd, MW_SET_VIBRATE_MODE, 0, mdata, 6);
}
void mw_configure_watch_mode(int mw_fd, unsigned char mode, unsigned char save, unsigned char timeout, unsigned char invert)
{
unsigned char mdata[3];
mdata[0] = timeout; /* seconds */
mdata[1] = invert; /* 0=normal, 1=invert */
mw_send_frame(mw_fd, MW_CONFIGURE_MODE, (mode & 0x0f) | ((save & 0x01) << 3), mdata, 2);
}
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);
} }
/* /*
@ -122,6 +147,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)
{ {
unsigned short crc; unsigned short crc;
@ -177,7 +203,6 @@ int decode_frame(int mw_fd, unsigned char *buf, int len)
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 char *mdatap = mdata;
fprintf(stderr, "command: '%s'\n", cmdline); fprintf(stderr, "command: '%s'\n", cmdline);
@ -192,23 +217,21 @@ void process_cmd(char *cmdline, int clinep, int mw_fd)
fprintf(stderr, "OK\n"); fprintf(stderr, "OK\n");
} }
if (strncmp(cmdline, "grtc", 4) == 0) { if (strncmp(cmdline, "grtc", 4) == 0) {
mw_send_packet(mw_fd, MW_GET_REAL_TIME_CLOCK, 0, NULL, 0); mw_send_frame(mw_fd, MW_GET_REAL_TIME_CLOCK, 0, NULL, 0);
} }
if (strncmp(cmdline, "gistr", 5) == 0) { if (strncmp(cmdline, "gistr", 5) == 0) {
mdata[0] = 0; mdata[0] = 0;
mw_send_packet(mw_fd, MW_GET_INFORMATION_STRING, 0, mdata, 1); mw_send_frame(mw_fd, MW_GET_INFORMATION_STRING, 0, mdata, 1);
} }
if (strncmp(cmdline, "gdtype", 6) == 0) { if (strncmp(cmdline, "gdtype", 6) == 0) {
mw_send_packet(mw_fd, MW_GET_DEVICE_TYPE, 0, NULL, 0); mw_send_frame(mw_fd, MW_GET_DEVICE_TYPE, 0, NULL, 0);
} }
if (strncmp(cmdline, "rvbat", 5) == 0) { if (strncmp(cmdline, "rvbat", 5) == 0) {
mw_send_packet(mw_fd, MW_READ_BATTERY_VOLTAGE_MSG, 0, NULL, 0); mw_send_frame(mw_fd, MW_READ_BATTERY_VOLTAGE_MSG, 0, NULL, 0);
} }
if (strncmp(cmdline, "modecfg", 6) == 0) { if (strncmp(cmdline, "modecfg", 6) == 0) {
memset(mdata, 0, 32); mw_configure_watch_mode(mw_fd, MW_SCREEN_MODE_IDLE, 0, 4, 1);
mdata[0] = 4; /* timeout */ mw_update_display(mw_fd, MW_SCREEN_MODE_IDLE, 0);
mdata[1] = 1; /* invert display */
mw_send_packet(mw_fd, MW_CONFIGURE_MODE, 0, mdata, 27);
} }
if (strncmp(cmdline, "rbtcfg", 6) == 0) { if (strncmp(cmdline, "rbtcfg", 6) == 0) {
mdata[0] = 0; /* idle screen */ mdata[0] = 0; /* idle screen */
@ -216,17 +239,14 @@ void process_cmd(char *cmdline, int clinep, int mw_fd)
mdata[2] = 2; /* button press type */ mdata[2] = 2; /* button press type */
mdata[3] = 3; /* callback message type */ mdata[3] = 3; /* callback message type */
mdata[4] = 4; /* callback message option */ mdata[4] = 4; /* callback message option */
mw_send_packet(mw_fd, MW_READ_BUTTON_CONFIG, 0, NULL, 0); mw_send_frame(mw_fd, MW_READ_BUTTON_CONFIG, 0, NULL, 0);
} }
if (strncmp(cmdline, "svib", 4) == 0) { if (strncmp(cmdline, "svib", 4) == 0) {
mdata[0] = 1; /* enable */ mw_set_vibrate_mode(mw_fd, 1, 300, 300, 5);
*(unsigned short *)(mdatap+1) = 500; /* on miliseconds */
*(unsigned short *)(mdatap+3) = 500; /* off miliseconds */
mdata[5] = 10;
mw_send_packet(mw_fd, MW_SET_VIBRATE_MODE, 0, mdata, 6);
} }
} }
int menu(int mw_fd) int menu(int mw_fd)
{ {
fd_set mfds; fd_set mfds;

View file

@ -45,5 +45,10 @@
#define MW_ACCELEROMETER 0xea #define MW_ACCELEROMETER 0xea
#define MW_SCREEN_MODE_IDLE 0x00
#define MW_SCREEN_MODE_APPLICATION 0x01
#define MW_SCREEN_MODE_NOTIFICATION 0x02
#define MW_SCREEN_MODE_SCROLL 0x03
#endif #endif