#include <dbus/dbus-glib.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_lib.h>
int con_fd; /* console input fd */
char cmdline[128];
int cmdline_pos;
+ SoupSession *msoup;
+ SoupMessage *smsg;
} mwdata_t;
void bitmap_test(mwdevice_t *mwdevice)
mw_set_vibrate_mode(mwdevice, 1, 300, 300, 3);
}
+int days(int m1, int y1)
+{
+ int d;
+ if(m1==1 || m1==3 || m1==5 || m1==7 || m1==8 || m1==10 || m1==12)
+ d=31;
+ else if(m1==4 || m1==6 || m1==9 || m1==11)
+ d=30;
+ else if((y1%100!=0 && y1%4==0) || y1%400==0)
+ d=29;
+ else
+ d=28;
+ return d;
+}
+
+void draw_idle_calendar(mwdevice_t *mwdevice)
+{
+ long unsigned int t;
+ unsigned int y,y1,m,m1,d,da,i,j,k;
+ const char a[12][20]={"January","February","March","April","May","June","July","August","September","October","November","December"};
+ const char dnames[7][3] = { "Mo", "Di", "Mi", "Do", "Fr", "Sa", "So" };
+ mw_buffer *mwbuf;
+ unsigned char *bbuf;
+ int len, px, py;
+ char pnum[32];
+ int today;
+ time_t mtime;
+ struct tm mtm;
+
+ mtime = time(NULL);
+ localtime_r(&mtime, &mtm);
+
+ today = mtm.tm_mday;
+ y = mtm.tm_year + 1900;
+ m = mtm.tm_mon + 1;
+
+ mwbuf = mw_alloc_pbuffer(96, 66, 1);
+ mw_buf_clear(mwbuf, MW_BLACK);
+
+ if (y < 0)
+ y = -y;
+ if (m <= 0 || m >= 13)
+ m = 1;
+ y1 = 0;
+ t = 0;
+ while (y1 < y) {
+ if (((y1 % 100) != 0 && (y1 % 4) == 0) || (y1 % 400) == 0)
+ t += 366;
+ else
+ t += 365;
+ y1++;
+ }
+ m1 = 1;
+ while (m1 < m) {
+ d = days(m1, y);
+ t = t + d;
+ m1++;
+ };
+#if 0
+ printf("Year: '%u'\n",y);
+ printf("Month: '%s'\n",a[m-1]);
+
+ printf("%6s%6s%6s%6s%6s%6s%6s\n","Sun","Mon","Tue","Wed","Thu","Fri","Sat");
+#endif
+
+ k = 1;
+ /* 0 = 1st day is Monday, 1 = 1st day is Sunday */
+ d = (t % 7)-1;
+ px=0;
+ py=3;
+ for (i=0; i<7; i++) {
+ snprintf(pnum, 3, dnames[i]);
+ mw_buf_print(mwbuf, px, py, pnum, 0, MW_WHITE, MW_BLACK);
+ px += 14;
+ };
+ px = 0;
+ py += 10;
+ for (i = 1; i <= days(m,y); i++, k++) {
+ if (i == 1) {
+ if (d == 0) {
+ for (j = 1; j < 7; j++, k++) {
+ printf("+--"); //printf("%3s","");
+ px += 14;
+ }
+ } else {
+ for (j = 1; j < d; j++, k++) {
+ px += 14;
+ printf("--+"); //printf("%3s","");
+ }
+ }
+ }
+ snprintf(pnum, 8, "%2d", i);
+ if (i == today)
+ mw_buf_print(mwbuf, px, py, pnum, 0, MW_BLACK, MW_WHITE);
+ else
+ mw_buf_print(mwbuf, px, py, pnum, 0, MW_WHITE, MW_BLACK);
+ px += 12;
+ printf("%2d", i);
+ if ((k % 7) == 0) {
+ printf("\n");
+ px = 0;
+ py += 10;
+ } else {
+ printf("+");
+ px += 2;
+ }
+ }
+ // printf("\n");
+
+ //mw_buf_print(mwbuf, 1, 10, "Font 0", 0, MW_WHITE, MW_BLACK);
+
+ bbuf = mw_make_mw_buffer(mwbuf, &len);
+ mw_send_bitmap(mwdevice, MW_SCREEN_MODE_IDLE, 96, 65, 31, bbuf, len);
+ mw_update_display(mwdevice, MW_SCREEN_MODE_IDLE, 1);
+ mw_free_pbuffer(mwbuf);
+}
+
void mw_send_notify(mwdevice_t *mwdevice, char *header, char *body)
{
mw_buffer *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)
{
}
}
if (strncmp(cmdline, "srtc", 4) == 0) {
fprintf(stderr, "Setting RTC from system time...");
- mw_set_rtc(&mwdata->mwdevice, MW_RTC_CLOCK_12HR, MW_RTC_DATE_MMDD);
+ mw_set_rtc(&mwdata->mwdevice, MW_RTC_CLOCK_24HR, MW_RTC_DATE_DDMM);
fprintf(stderr, "OK\n");
}
if (strncmp(cmdline, "grtc", 4) == 0) {
//mw_write_oled_buffer(mwdevice, 0, 80, 0, mdata, 10);
//mw_send_frame(mwdevice, MW_UPDATE_OLED_DISPLAY_MSG, 0, NULL, 0);
}
+ 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);
+ }
}