Makefile cleanup, start implementation of nval commands (not working yet)
This commit is contained in:
parent
9dfd994862
commit
b11171caa5
5 changed files with 104 additions and 5 deletions
6
Makefile
6
Makefile
|
@ -1,13 +1,13 @@
|
||||||
# Copyright (C) 2011 Nils Faerber <nils.faerber@kernelconcepts.de>
|
# Copyright (C) 2011 Nils Faerber <nils.faerber@kernelconcepts.de>
|
||||||
|
|
||||||
$(pkg-config --libs --cflags glib-2.0) $(pkg-config --libs --cflags dbus-glib-1) $(pkg-config --libs --cflags dbus-1)
|
# $(pkg-config --libs --cflags glib-2.0) $(pkg-config --libs --cflags dbus-glib-1) $(pkg-config --libs --cflags dbus-1)
|
||||||
|
|
||||||
# prefix for installation and search path (like icons)
|
# prefix for installation and search path (like icons)
|
||||||
PREFIX = /usr/local/
|
PREFIX = /usr/local/
|
||||||
CFLAGS = -Wall -g -DDEBUG -O2 $(CCFLAGS) `pkg-config --cflags glib-2.0` `pkg-config --cflags dbus-glib-1` `pkg-config --cflags dbus-1`
|
CFLAGS = -Wall -g -DDEBUG -O2 $(CCFLAGS) `pkg-config --cflags glib-2.0` `pkg-config --cflags dbus-glib-1` `pkg-config --cflags dbus-1` `pkg-config --cflags libsoup-2.4`
|
||||||
#CFLAGS = -Wall -O2 $(CCFLAGS)
|
#CFLAGS = -Wall -O2 $(CCFLAGS)
|
||||||
|
|
||||||
LDFLAGS = `pkg-config --libs glib-2.0` `pkg-config --libs dbus-glib-1` `pkg-config --libs dbus-1`
|
LDFLAGS = `pkg-config --libs glib-2.0` `pkg-config --libs dbus-glib-1` `pkg-config --libs dbus-1` `pkg-config --libs libsoup-2.4`
|
||||||
|
|
||||||
PRGNAME = metawatch
|
PRGNAME = metawatch
|
||||||
|
|
||||||
|
|
47
metawatch.c
47
metawatch.c
|
@ -130,6 +130,22 @@ int mw_set_rtc(mwdevice_t *mwdevice, unsigned char clk1224, unsigned char date_f
|
||||||
return mw_send_frame(mwdevice, MW_SET_REAL_TIME_CLOCK, 0, data, 10);
|
return mw_send_frame(mwdevice, MW_SET_REAL_TIME_CLOCK, 0, data, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int mw_nval_operation(mwdevice_t *mwdevice, unsigned char operation, unsigned short identifier, unsigned char size, void *mdata)
|
||||||
|
{
|
||||||
|
unsigned char data[32];
|
||||||
|
|
||||||
|
data[0] = (identifier & 0xff00) >> 8;
|
||||||
|
data[1] = (identifier & 0x00ff);
|
||||||
|
data[2] = size;
|
||||||
|
if (size > 0 && mdata != NULL)
|
||||||
|
memcpy((data+3), mdata, size);
|
||||||
|
|
||||||
|
if (operation == MW_NVAL_OPERATION_READ || operation == MW_NVAL_OPERATION_WRITE) {
|
||||||
|
return mw_send_frame(mwdevice, MW_NVAL_OPERATION, operation, data, 3+size);
|
||||||
|
} else
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int mw_set_vibrate_mode(mwdevice_t *mwdevice, unsigned char enable, unsigned short on_time, unsigned short off_time, unsigned char cycles)
|
int mw_set_vibrate_mode(mwdevice_t *mwdevice, unsigned char enable, unsigned short on_time, unsigned short off_time, unsigned char cycles)
|
||||||
{
|
{
|
||||||
unsigned char mdata[7];
|
unsigned char mdata[7];
|
||||||
|
@ -292,11 +308,11 @@ int mw_advance_watch_hands(mwdevice_t *mwdevice, unsigned char hours, unsigned c
|
||||||
return mw_send_frame(mwdevice, MW_ADVANCE_WATCH_HANDS, 0, mdata, 3);
|
return mw_send_frame(mwdevice, MW_ADVANCE_WATCH_HANDS, 0, mdata, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
* Watch responses, events or notifications
|
* Watch responses, events or notifications
|
||||||
* ---------------------------------------------------------------------- */
|
* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
int mw_get_device_type_response(mwdevice_t *mwdevice, unsigned char devtype)
|
int mw_get_device_type_response(mwdevice_t *mwdevice, unsigned char devtype)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
@ -336,6 +352,10 @@ void mw_set_get_device_type_response_cb(mwdevice_t *mwdevice, void (*mw_get_devi
|
||||||
mwdevice->mw_gdtypersp_data = user_data;
|
mwdevice->mw_gdtypersp_data = user_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int mw_nval_operation_response(mwdevice_t *mwdevice, unsigned char operation, unsigned short identifier, unsigned char size, void *mdata)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int mw_get_real_time_clock_response(mwdevice_t *mwdevice, unsigned char *rtcrsp, int len)
|
int mw_get_real_time_clock_response(mwdevice_t *mwdevice, unsigned char *rtcrsp, int len)
|
||||||
{
|
{
|
||||||
|
@ -535,6 +555,29 @@ int mw_decode_frame(mwdevice_t *mwdevice, unsigned char *buf, int len)
|
||||||
case MW_LOW_BATTERY_BT_OFF_MSG:
|
case MW_LOW_BATTERY_BT_OFF_MSG:
|
||||||
fprintf(stderr, "Watch battery extremely low - radio will turn off\n");
|
fprintf(stderr, "Watch battery extremely low - radio will turn off\n");
|
||||||
break;
|
break;
|
||||||
|
case MW_NVAL_OPERATION_RSP:
|
||||||
|
fprintf(stderr, "NVAL operation response - ");
|
||||||
|
switch (msgopt) {
|
||||||
|
case 0x00:
|
||||||
|
fprintf(stderr, "success\n");
|
||||||
|
break;
|
||||||
|
case 0x01:
|
||||||
|
fprintf(stderr, "failure!\n");
|
||||||
|
break;
|
||||||
|
case 0x09:
|
||||||
|
fprintf(stderr, "Item Not initialized (Identifier Not found\n");
|
||||||
|
break;
|
||||||
|
case 0x0a:
|
||||||
|
fprintf(stderr, "Operation failed\n");
|
||||||
|
break;
|
||||||
|
case 0x0c:
|
||||||
|
fprintf(stderr, "Bad Item length\n");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fprintf(stderr, "unknown status 0x%02x\n", msgopt);
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
break;
|
||||||
case MW_STATUS_CHANGE_EVENT:
|
case MW_STATUS_CHANGE_EVENT:
|
||||||
mw_status_change_event(mwdevice, msgopt, msgdata, msgdatalen);
|
mw_status_change_event(mwdevice, msgopt, msgdata, msgdatalen);
|
||||||
break;
|
break;
|
||||||
|
@ -571,7 +614,7 @@ int mw_feed_msg_buffer(mwdevice_t *mwdevice, unsigned char *buf, int len)
|
||||||
}
|
}
|
||||||
/* here we have a complete msg */
|
/* here we have a complete msg */
|
||||||
memcpy(msgbuf, mwdevice->pbuf, tlen);
|
memcpy(msgbuf, mwdevice->pbuf, tlen);
|
||||||
mw_decode_frame(mwdevice, msgbuf, tlen);
|
mw_decode_frame(mwdevice, (unsigned char *)msgbuf, tlen);
|
||||||
memmove(mwdevice->pbuf, (mwdevice->pbuf+tlen), tlen);
|
memmove(mwdevice->pbuf, (mwdevice->pbuf+tlen), tlen);
|
||||||
mwdevice->pbuf_len -= tlen;
|
mwdevice->pbuf_len -= tlen;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,8 @@ int mw_send_frame(mwdevice_t *mwdevice, unsigned char msg_type, unsigned char op
|
||||||
|
|
||||||
int mw_set_rtc(mwdevice_t *mwdevice, unsigned char clk1224, unsigned char date_fmt);
|
int mw_set_rtc(mwdevice_t *mwdevice, unsigned char clk1224, unsigned char date_fmt);
|
||||||
|
|
||||||
|
int mw_nval_operation(mwdevice_t *mwdevice, unsigned char operation, unsigned short identifier, unsigned char size, void *mdata);
|
||||||
|
|
||||||
int mw_set_vibrate_mode(mwdevice_t *mwdevice, unsigned char enable, unsigned short on_time, unsigned short off_time, unsigned char cycles);
|
int mw_set_vibrate_mode(mwdevice_t *mwdevice, unsigned char enable, unsigned short on_time, unsigned short off_time, unsigned char cycles);
|
||||||
|
|
||||||
int mw_configure_watch_mode(mwdevice_t *mwdevice, unsigned char mode, unsigned char save, unsigned char timeout, unsigned char invert);
|
int mw_configure_watch_mode(mwdevice_t *mwdevice, unsigned char mode, unsigned char save, unsigned char timeout, unsigned char invert);
|
||||||
|
|
|
@ -53,6 +53,15 @@
|
||||||
#define MW_RTC_DATE_MMDD 0x00
|
#define MW_RTC_DATE_MMDD 0x00
|
||||||
#define MW_RTC_DATE_DDMM 0x01
|
#define MW_RTC_DATE_DDMM 0x01
|
||||||
|
|
||||||
|
#define MW_NVAL_OPERATION 0x30
|
||||||
|
#define MW_NVAL_OPERATION_RSP 0x31
|
||||||
|
|
||||||
|
#define MW_NVAL_OPERATION_READ 0x01
|
||||||
|
#define MW_NVAL_OPERATION_WRITE 0x02
|
||||||
|
#define MW_NVAL_TIME_FORMAT 0x2009
|
||||||
|
#define MW_NVAL_DATE_FORMAT 0x200a
|
||||||
|
|
||||||
|
|
||||||
#define MW_RESERVED 0x32
|
#define MW_RESERVED 0x32
|
||||||
#define MW_STATUS_CHANGE_EVENT 0x33
|
#define MW_STATUS_CHANGE_EVENT 0x33
|
||||||
#define MW_BUTTON_EVENT_MESSAGE 0x34
|
#define MW_BUTTON_EVENT_MESSAGE 0x34
|
||||||
|
|
45
mw_main.c
45
mw_main.c
|
@ -25,6 +25,11 @@
|
||||||
#include <dbus/dbus-glib.h>
|
#include <dbus/dbus-glib.h>
|
||||||
#include <dbus/dbus-glib-lowlevel.h>
|
#include <dbus/dbus-glib-lowlevel.h>
|
||||||
|
|
||||||
|
#include <libsoup/soup.h>
|
||||||
|
|
||||||
|
#include <libxml/tree.h>
|
||||||
|
#include <libxml/parser.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#include <bluetooth/sdp.h>
|
#include <bluetooth/sdp.h>
|
||||||
#include <bluetooth/sdp_lib.h>
|
#include <bluetooth/sdp_lib.h>
|
||||||
|
@ -44,6 +49,8 @@ typedef struct {
|
||||||
int con_fd; /* console input fd */
|
int con_fd; /* console input fd */
|
||||||
char cmdline[128];
|
char cmdline[128];
|
||||||
int cmdline_pos;
|
int cmdline_pos;
|
||||||
|
SoupSession *msoup;
|
||||||
|
SoupMessage *smsg;
|
||||||
} mwdata_t;
|
} mwdata_t;
|
||||||
|
|
||||||
void bitmap_test(mwdevice_t *mwdevice)
|
void bitmap_test(mwdevice_t *mwdevice)
|
||||||
|
@ -430,6 +437,32 @@ void test_oled(mwdevice_t *mwdevice, unsigned char oled)
|
||||||
mw_free_pbuffer(mwbuf);
|
mw_free_pbuffer(mwbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
weather_soup_callback (SoupSession *session, SoupMessage *msg, gpointer user_data)
|
||||||
|
{
|
||||||
|
xmlDocPtr xdoc;
|
||||||
|
|
||||||
|
/* Handle the response here */
|
||||||
|
if (msg->response_body->data != NULL && msg->response_body->length != 0) {
|
||||||
|
fprintf(stderr, "%s\n", msg->response_body->data);
|
||||||
|
xdoc = xmlReadMemory(msg->response_body->data, msg->response_body->length, "noname.xml", NULL, 0);
|
||||||
|
if (xdoc == NULL) {
|
||||||
|
fprintf(stderr, "Failed to parse document\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
xmlFreeDoc(xdoc);
|
||||||
|
xmlCleanupParser();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void do_weather(mwdata_t *mwdata)
|
||||||
|
{
|
||||||
|
mwdata->msoup = soup_session_async_new();
|
||||||
|
mwdata->smsg = soup_message_new ("GET", "http://www.google.com/ig/api?weather=siegen&hl=de");
|
||||||
|
soup_session_send_message (mwdata->msoup, mwdata->smsg);
|
||||||
|
soup_session_queue_message (mwdata->msoup, mwdata->smsg, weather_soup_callback, mwdata);
|
||||||
|
}
|
||||||
|
|
||||||
void print_help(void)
|
void print_help(void)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -535,6 +568,18 @@ void process_cmd(char *cmdline, int clinep, mwdata_t *mwdata)
|
||||||
if (strncmp(cmdline, "cal", 3) == 0) {
|
if (strncmp(cmdline, "cal", 3) == 0) {
|
||||||
draw_idle_calendar(&mwdata->mwdevice);
|
draw_idle_calendar(&mwdata->mwdevice);
|
||||||
}
|
}
|
||||||
|
if (strncmp(cmdline, "wet", 3) == 0) {
|
||||||
|
do_weather(mwdata);
|
||||||
|
}
|
||||||
|
if (strncmp(cmdline, "c24", 3) == 0) {
|
||||||
|
mdata[0] = MW_RTC_CLOCK_24HR;
|
||||||
|
mw_nval_operation(&mwdata->mwdevice, MW_NVAL_OPERATION_WRITE, MW_NVAL_TIME_FORMAT, 1, mdata);
|
||||||
|
}
|
||||||
|
if (strncmp(cmdline, "g24", 3) == 0) {
|
||||||
|
mdata[0] = 0;
|
||||||
|
mdata[1] = 0;
|
||||||
|
mw_nval_operation(&mwdata->mwdevice, MW_NVAL_OPERATION_READ, MW_NVAL_TIME_FORMAT, 2, mdata);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue