+
+/*
+ * Bluetooth screen
+ */
+typedef struct {
+ u8t pos;
+ boolean bt_en;
+ boolean on;
+} bluetooth_data_t;
+static bluetooth_data_t bluetooth_screen = {
+ 0,
+ FALSE,
+ TRUE
+};
+
+void draw_bluetooth_screen(bluetooth_data_t *sdata)
+{
+ char bstr[20];
+ uint8_t *bd_addr;
+
+ hal_lcd_clear_display();
+
+ oswald_draw_bitmap(36, 0, Bluetooth_icon_width, Bluetooth_icon_height, Bluetooth_icon_bits);
+
+ oswald_draw_bitmap(81, 6, upbutton_icon_width, upbutton_icon_height, upbutton_icon_bits);
+ oswald_draw_bitmap(81, 38, downbutton_icon_width, downbutton_icon_height, downbutton_icon_bits);
+
+ SetFont(MetaWatch5);
+ WriteLcdString(2, 30, "Enable:");
+ if ((sdata->pos == 0 && sdata->on) || sdata->pos != 0) {
+ WriteLcdCharacter(45, 30, bluetooth_screen.bt_en ? 'x' : '_');
+ }
+ WriteLcdString(2, 39, "State:");
+ switch (hal_bluetooth_get_state()) {
+ case BLUETOOTH_OFF:
+ WriteLcdString(45, 39, "off");
+ break;
+ case BLUETOOTH_ON:
+ WriteLcdString(45, 39, "on");
+ break;
+ case BLUETOOTH_CONNECTED:
+ WriteLcdString(45, 39, "conn.");
+ break;
+ default:
+ break;
+ };
+ if (hal_bluetooth_get_state() >= BLUETOOTH_ON) {
+ bd_addr = hal_bluetooth_get_local_bdaddr();
+ snprintf(bstr, 20, "%02x:%02x:%02x:%02x:%02x:%02x", bd_addr[5], bd_addr[4], bd_addr[3], bd_addr[2], bd_addr[1], bd_addr[0]);
+ WriteLcdString(2, 48, bstr);
+ } else {
+ }
+ WriteLcdString(2, 57, "Visible:");
+ if ((sdata->pos == 1 && sdata->on) || sdata->pos != 1) {
+ WriteLcdCharacter(45, 57, hal_bluetooth_get_visible() ? 'x' : '_');
+ }
+
+ hal_lcd_update_display();
+}
+
+void bluetooth_handle_updown(u8t pos, s8t incr)
+{
+ switch (pos) {
+ case 0:
+ if (hal_bluetooth_get_state() >= BLUETOOTH_ON) {
+ hal_bluetooth_set_state(BLUETOOTH_OFF);
+ bluetooth_screen.bt_en = FALSE;
+ } else {
+ hal_bluetooth_set_state(BLUETOOTH_ON);
+ bluetooth_screen.bt_en = TRUE;
+ }
+ break;
+ case 1:
+ if (hal_bluetooth_get_state() >= BLUETOOTH_ON && !hal_bluetooth_get_visible()) {
+ hal_bluetooth_set_visible(TRUE);
+ } else {
+ hal_bluetooth_set_visible(FALSE);
+ }
+ break;
+ case 2:
+ break;
+ case 3:
+ break;
+ case 4:
+ break;
+ case 5:
+ break;
+ case 6:
+ break;
+ case 7:
+ break;
+ case 8:
+ break;
+ default:
+ break;
+ };
+}
+
+void handle_bluetooth_buttons(watch_button button, bluetooth_data_t *sdata)
+{
+ switch (button) {
+ case BUTTON_A:
+ bluetooth_handle_updown(sdata->pos, 1);
+ break;
+ case BUTTON_B:
+ bluetooth_handle_updown(sdata->pos, -1);
+ break;
+ case BUTTON_F:
+ sdata->pos++;
+ sdata->pos %= 2;
+ break;
+ default:
+ break;
+ }
+ draw_bluetooth_screen(sdata);
+}
+
+void bluetooth_screen_events(u16t event, void *data)
+{
+ switch (event) {
+ case EVENT_SCREEN_VISIBLE:
+ bluetooth_screen.pos = 0;
+ bluetooth_screen.bt_en = (hal_bluetooth_get_state() > 0);
+ draw_bluetooth_screen(&bluetooth_screen);
+ hal_enable_halfsecond_timer();
+ break;
+ case EVENT_SCREEN_DESTROY:
+ hal_disable_halfsecond_timer();
+ break;
+ case EVENT_USER_BUTTONS:
+ dbg_out("button event %d\n", *(int *)data);
+ handle_bluetooth_buttons(*(watch_button *)data, &bluetooth_screen);
+ break;
+ case EVENT_HALF_SEC_TIMER:
+ if (bluetooth_screen.on)
+ bluetooth_screen.on = FALSE;
+ else
+ bluetooth_screen.on = TRUE;
+ draw_bluetooth_screen(&bluetooth_screen);
+ break;
+ default:
+ break;
+ };
+}
+