#include <pebble.h>
static Window *s_main_window;
static TextLayer *s_connection_layer;
static GFont s_time_fontss;
static void bluetoothhyouji(bool connected){
// text_layer_set_text(s_connection_layer, connected ? "connected" : "disconnected");
text_layer_set_text(s_connection_layer, connected ? "+" : "X");
}
static void handle_bluetooth(bool connected) {
bluetoothhyouji(connected);
}
static void tick_handler(struct tm *tick_time, TimeUnits units_changed) {
//ここに時計の表示などを記載する。
}
static void main_window_load(Window *window) {
Layer *window_layer = window_get_root_layer(window);
GRect bounds = layer_get_frame(window_layer);
s_time_fontss = fonts_get_system_font(FONT_KEY_GOTHIC_18);
s_connection_layer = text_layer_create(GRect(bounds.size.w*2/4-33, bounds.size.h/2+54, 20, bounds.size.h));
text_layer_set_font(s_connection_layer, s_time_fontss);
text_layer_set_text_alignment(s_connection_layer, GTextAlignmentCenter);
handle_bluetooth(bluetooth_connection_service_peek());
//ブルートゥースに変化があったらhandle_bluetoothが呼びだされる
bluetooth_connection_service_subscribe(handle_bluetooth);
//ブルートゥースの初期値表示
bool connected = bluetooth_connection_service_peek();
//ブルートゥースの初期値表示
bluetoothhyouji(connected);
layer_add_child(window_layer, text_layer_get_layer(s_connection_layer));
}
static void main_window_unload(Window *window) {
// Destroy TextLayer
text_layer_destroy(s_connection_layer);
// 解放
bluetooth_connection_service_unsubscribe();
}
static void init() {
// Create main Window element and assign to pointer
s_main_window = window_create();
// Set handlers to manage the elements inside the Window
window_set_window_handlers(s_main_window, (WindowHandlers) {
.load = main_window_load,
.unload = main_window_unload
});
// Show the Window on the watch, with animated=true
window_stack_push(s_main_window, true);
// Register with TickTimerService
tick_timer_service_subscribe(SECOND_UNIT, tick_handler);
}
static void deinit() {
// Destroy Window
window_destroy(s_main_window);
}
int main(void) {
init();
app_event_loop();
deinit();
}