Implement battery warning and bt-off message handlers and callbacks
authorNils Faerber <nils.faerber@kernelconcepts.de>
Fri, 11 Nov 2011 22:56:13 +0000 (23:56 +0100)
committerNils Faerber <nils.faerber@kernelconcepts.de>
Fri, 11 Nov 2011 22:56:13 +0000 (23:56 +0100)
metawatch.c
metawatch.h

index 2bf028c..d1d6d2b 100644 (file)
@@ -302,6 +302,21 @@ 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);
 }
 
+int mw_battery_configuration(mwdevice_t *mwdevice, unsigned char warn_lvl, unsigned char bt_off_lvl)
+{
+       unsigned char mdata[4];
+       
+       if (warn_lvl < 28 || warn_lvl > 42)
+               return -1;
+       if (bt_off_lvl < 28 || bt_off_lvl > 42)
+               return -1;
+
+       mdata[0] = warn_lvl;
+       mdata[1] = bt_off_lvl;
+
+       return mw_send_frame(mwdevice, MW_BATTERY_CONFIG_MSG, 0, mdata, 2);
+}
+
 
 /* ----------------------------------------------------------------------
  * Watch responses, events or notifications
@@ -507,6 +522,37 @@ void mw_set_status_change_event_cb(mwdevice_t *mwdevice, void (*mw_status_change
                mwdevice->mw_stchev_data = user_data;
 }
 
+int mw_low_battery_warning_message(mwdevice_t *mwdevice, unsigned char option, unsigned char *statrsp, int len)
+{
+       if (mwdevice->mw_low_battery_warning_message_cb != NULL)
+               mwdevice->mw_low_battery_warning_message_cb(mwdevice, mwdevice->mw_lbatwarnmsg_data);
+
+       return 0;
+}
+
+void mw_set_low_battery_warning_message_cb(mwdevice_t *mwdevice, void (*mw_low_battery_warning_message_cb) (mwdevice_t *mwdevice, void *user_data), void *user_data)
+{
+       if (mw_low_battery_warning_message_cb != NULL)
+               mwdevice->mw_low_battery_warning_message_cb = mw_low_battery_warning_message_cb;
+       if (user_data != NULL)
+               mwdevice->mw_lbatwarnmsg_data = user_data;
+}
+
+int mw_low_battery_bt_off_message(mwdevice_t *mwdevice, unsigned char option, unsigned char *statrsp, int len)
+{
+       if (mwdevice->mw_low_battery_bt_off_message_cb != NULL)
+               mwdevice->mw_low_battery_bt_off_message_cb(mwdevice, mwdevice->mw_lbatbtoff_data);
+
+       return 0;
+}
+
+void mw_set_low_battery_bt_off_message_cb(mwdevice_t *mwdevice, void (*mw_low_battery_bt_off_message_cb) (mwdevice_t *mwdevice, void *user_data), void *user_data)
+{
+       if (mw_low_battery_bt_off_message_cb != NULL)
+               mwdevice->mw_low_battery_bt_off_message_cb = mw_low_battery_bt_off_message_cb;
+       if (user_data != NULL)
+               mwdevice->mw_lbatbtoff_data = user_data;
+}
 
 /* ----------------------------------------------------------------------
  * Protocol handling
@@ -555,9 +601,6 @@ int mw_decode_frame(mwdevice_t *mwdevice, unsigned char *buf, int len)
                case MW_READ_LIGHT_SENSOR_RSP:
                        mw_read_light_sensor_response(mwdevice, msgdata, msgdatalen);
                        break;
-               case MW_LOW_BATTERY_WARNING_MSG:
-                       fprintf(stderr, "Watch battery low, please connect charger\n");
-                       break;
                case MW_READ_BUTTON_CONFIG_RSP:
                        mw_read_button_config_response(mwdevice, msgdata, msgdatalen);
                        break;
@@ -565,6 +608,9 @@ int mw_decode_frame(mwdevice_t *mwdevice, unsigned char *buf, int len)
                        fprintf(stderr, "Button event message\n");
                        mw_button_event_message(mwdevice, msgdata, msgdatalen, msgopt);
                        break;
+               case MW_LOW_BATTERY_WARNING_MSG:
+                       fprintf(stderr, "Watch battery low, please connect charger\n");
+                       break;
                case MW_LOW_BATTERY_BT_OFF_MSG:
                        fprintf(stderr, "Watch battery extremely low - radio will turn off\n");
                        break;
index bedaa4e..2c50571 100644 (file)
@@ -33,6 +33,10 @@ typedef struct _mwdevice_t {
        void *mw_rlsrsp_data;
        void (*mw_status_change_event_cb) (struct _mwdevice_t *mwdevice, unsigned char *scrmode, unsigned char *status, void *user_data);
        void *mw_stchev_data;
+       void (*mw_low_battery_warning_message_cb) (struct _mwdevice_t *mwdevice, void *user_data);
+       void *mw_lbatwarnmsg_data;
+       void (*mw_low_battery_bt_off_message_cb) (struct _mwdevice_t *mwdevice, void *user_data);
+       void *mw_lbatbtoff_data;
 } mwdevice_t;
 
 void dump_frame(unsigned char *frame, int len);
@@ -85,12 +89,20 @@ void mw_set_read_light_sensor_response_cb(mwdevice_t *mwdevice, void (*mw_read_l
 int mw_status_change_event(mwdevice_t *mwdevice, unsigned char option, unsigned char *statrsp, int len);
 void mw_set_status_change_event_cb(mwdevice_t *mwdevice, void (*mw_status_change_event_cb) (mwdevice_t *mwdevice, unsigned char *scrmode, unsigned char *status, void *user_data), void *user_data);
 
+int mw_low_battery_warning_message(mwdevice_t *mwdevice, unsigned char option, unsigned char *statrsp, int len);
+void mw_set_low_battery_warning_message_cb(mwdevice_t *mwdevice, void (*mw_low_battery_warning_message_cb) (mwdevice_t *mwdevice, void *user_data), void *user_data);
+
+int mw_low_battery_bt_off_message(mwdevice_t *mwdevice, unsigned char option, unsigned char *statrsp, int len);
+void mw_set_low_battery_bt_off_message_cb(mwdevice_t *mwdevice, void (*mw_low_battery_bt_off_message_cb) (mwdevice_t *mwdevice, void *user_data), void *user_data);
+
 int mw_enable_button(mwdevice_t *mwdevice, unsigned char mode, unsigned char button_index, unsigned char press_type, unsigned char callback_type, unsigned char callback_option);
 
 int mw_disable_button(mwdevice_t *mwdevice, unsigned char mode, unsigned char button_index, unsigned char press_type);
 
 int mw_advance_watch_hands(mwdevice_t *mwdevice, unsigned char hours, unsigned char minutes, unsigned char seconds);
 
+int mw_battery_configuration(mwdevice_t *mwdevice, unsigned char warn_lvl, unsigned char bt_off_lvl);
+
 int mw_decode_frame(mwdevice_t *mwdevice, unsigned char *buf, int len);
 
 int mw_feed_msg_buffer(mwdevice_t *mwdevice, unsigned char *buf, int len);