More callbacks, further GUI work
[metawatch.git] / metawatch.c
index 08d5aca..5c5b73b 100644 (file)
@@ -222,6 +222,7 @@ int mw_write_oled_buffer(mwdevice_t *mwdevice,
        if (mwdevice->devtype != MW_DEVICE_TYPE_ANA_DIGI && mwdevice->devtype != MW_DEVICE_TYPE_DEVB_ANA_DIGI)
                return -1;
        
+       fprintf(stderr, "write oled buf len = %d\n", buflen);
        /* lower row first since display wil be updated after completion of upper row */
        if (buflen > 80) {
                for (i=80; i<buflen; i+=20) {
@@ -235,6 +236,7 @@ int mw_write_oled_buffer(mwdevice_t *mwdevice,
                memcpy((mdata+1), (buffer+i), 20);
                mw_send_frame(mwdevice, MW_WRITE_OLED_IDLE_DISPLAY_MSG, 1 | (oled ? 2 : 0), mdata, 21);
        }
+
        return 0;
 }
 
@@ -272,11 +274,69 @@ int mw_disable_button(mwdevice_t *mwdevice,
        return mw_send_frame(mwdevice, MW_ENABLE_BUTTON, 0, mdata, 3);
 }
 
+int mw_advance_watch_hands(mwdevice_t *mwdevice, unsigned char hours, unsigned char minutes, unsigned char seconds)
+{
+       unsigned char mdata[4];
+       
+       if (hours > 12)
+               return -1;
+       if (minutes > 60)
+               return -1;
+       if (seconds > 60)
+               return -1;
+
+       mdata[0] = hours;
+       mdata[1] = minutes;
+       mdata[2] = seconds;
+
+       return mw_send_frame(mwdevice, MW_ADVANCE_WATCH_HANDS, 0, mdata, 3);
+}
+
 /* ----------------------------------------------------------------------
  * Watch responses, events or notifications
  * ---------------------------------------------------------------------- */
 
 
+int mw_get_device_type_response(mwdevice_t *mwdevice, unsigned char devtype)
+{
+#ifdef DEBUG
+       fprintf(stderr, "Got device type ");
+       switch(devtype) {
+               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", devtype);
+                       break;
+       };
+#endif
+       mwdevice->devtype = devtype;
+       if (mwdevice->mw_get_device_type_response_cb != NULL)
+               mwdevice->mw_get_device_type_response_cb(mwdevice, devtype, mwdevice->mw_gdtypersp_data);
+       return 0;
+}
+
+void mw_set_get_device_type_response_cb(mwdevice_t *mwdevice, void (*mw_get_device_type_response_cb) (mwdevice_t *mwdevice, unsigned char devtype, void *user_data), void *user_data)
+{
+       if (mw_get_device_type_response_cb != NULL)
+               mwdevice->mw_get_device_type_response_cb = mw_get_device_type_response_cb;
+       if (user_data != NULL)
+               mwdevice->mw_gdtypersp_data = user_data;
+}
+
+
 int mw_get_real_time_clock_response(mwdevice_t *mwdevice, unsigned char *rtcrsp, int len)
 {
        struct tm mtm;
@@ -435,18 +495,10 @@ int decode_frame(mwdevice_t *mwdevice, unsigned char *buf, int len)
                fprintf(stderr, "decode frame CRC error\n");
                return -1;
        }
-#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;
        }
-#ifdef DEBUG
-        else
-       fprintf(stderr, "decode frame found SOF\n");
-#endif
 
        msglen = buf[1];
        msgtype = buf[2];
@@ -456,28 +508,7 @@ int decode_frame(mwdevice_t *mwdevice, unsigned char *buf, int len)
 
        switch (msgtype) {
                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;
-                       };
-                       mwdevice->devtype = msgdata[0];
+                       mw_get_device_type_response(mwdevice, msgdata[0]);
                        break;
                case MW_GET_INFORMATION_STRING_RSP:
                        msgdata[len-2] = 0;