アットウィキロゴ
#blognavi
bluetooth_connection_service

Pebble timeの時計を開発メモ

以下、bluetooth表示用のプログラムの記述セット

そのままコピーして、貼り付ければ、動くようにしています。

追記:bluetooth_connection_service_subscribe(handle_bluetooth);だけだと、bluetooth情報に変化がないと表示が切り替わらない。window_load時にバッテリーの初期値をゲットして表示さるとキビキビ表示されるようになる。(2016/09/18)


  1. #include <pebble.h>
  2.  
  3. static Window *s_main_window;
  4. static TextLayer *s_connection_layer;
  5. static GFont s_time_fontss;
  6.  
  7. static void bluetoothhyouji(bool connected){
  8. // text_layer_set_text(s_connection_layer, connected ? "connected" : "disconnected");
  9. text_layer_set_text(s_connection_layer, connected ? "+" : "X");
  10. }
  11.  
  12. static void handle_bluetooth(bool connected) {
  13. bluetoothhyouji(connected);
  14. }
  15.  
  16. static void tick_handler(struct tm *tick_time, TimeUnits units_changed) {
  17. //ここに時計の表示などを記載する。
  18. }
  19.  
  20. static void main_window_load(Window *window) {
  21. Layer *window_layer = window_get_root_layer(window);
  22. GRect bounds = layer_get_frame(window_layer);
  23. s_time_fontss = fonts_get_system_font(FONT_KEY_GOTHIC_18);
  24. s_connection_layer = text_layer_create(GRect(bounds.size.w*2/4-33, bounds.size.h/2+54, 20, bounds.size.h));
  25. text_layer_set_font(s_connection_layer, s_time_fontss);
  26. text_layer_set_text_alignment(s_connection_layer, GTextAlignmentCenter);
  27. handle_bluetooth(bluetooth_connection_service_peek());
  28. //ブルートゥースに変化があったらhandle_bluetoothが呼びだされる
  29. bluetooth_connection_service_subscribe(handle_bluetooth);
  30. //ブルートゥースの初期値表示
  31. bool connected = bluetooth_connection_service_peek();
  32. //ブルートゥースの初期値表示
  33. bluetoothhyouji(connected);
  34. layer_add_child(window_layer, text_layer_get_layer(s_connection_layer));
  35. }
  36.  
  37. static void main_window_unload(Window *window) {
  38. // Destroy TextLayer
  39. text_layer_destroy(s_connection_layer);
  40.  
  41. // 解放
  42. bluetooth_connection_service_unsubscribe();
  43. }
  44.  
  45. static void init() {
  46. // Create main Window element and assign to pointer
  47. s_main_window = window_create();
  48. // Set handlers to manage the elements inside the Window
  49. window_set_window_handlers(s_main_window, (WindowHandlers) {
  50. .load = main_window_load,
  51. .unload = main_window_unload
  52. });
  53. // Show the Window on the watch, with animated=true
  54. window_stack_push(s_main_window, true);
  55. // Register with TickTimerService
  56. tick_timer_service_subscribe(SECOND_UNIT, tick_handler);
  57. }
  58.  
  59. static void deinit() {
  60. // Destroy Window
  61. window_destroy(s_main_window);
  62. }
  63.  
  64. int main(void) {
  65. init();
  66. app_event_loop();
  67. deinit();
  68. }
  69.  
  70.  
  71.  







カテゴリ: [開発] - &trackback() - 2016年04月18日 22:26:42
名前: コメント:
#blognavi
最終更新:2016年11月23日 23:58