X-Git-Url: https://git.kernelconcepts.de/?p=metawatch.git;a=blobdiff_plain;f=mw_main.c;h=17b52adcaaeb8167b378c16d7c821801e8775568;hp=406e09c832017124a59b624df32dba0d0f8a8727;hb=b11171caa5c6ef0a685c134ea01b89a8330bd74e;hpb=9dfd9948629cef149bc4d3ff7f4d949072959e64;ds=sidebyside diff --git a/mw_main.c b/mw_main.c index 406e09c..17b52ad 100644 --- a/mw_main.c +++ b/mw_main.c @@ -25,6 +25,11 @@ #include #include +#include + +#include +#include + /* #include #include @@ -44,6 +49,8 @@ typedef struct { int con_fd; /* console input fd */ char cmdline[128]; int cmdline_pos; + SoupSession *msoup; + SoupMessage *smsg; } mwdata_t; void bitmap_test(mwdevice_t *mwdevice) @@ -430,6 +437,32 @@ void test_oled(mwdevice_t *mwdevice, unsigned char oled) 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) { } @@ -535,6 +568,18 @@ void process_cmd(char *cmdline, int clinep, mwdata_t *mwdata) if (strncmp(cmdline, "cal", 3) == 0) { 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); + } }