Skip to content

Instantly share code, notes, and snippets.

@planset
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save planset/9202187 to your computer and use it in GitHub Desktop.
Save planset/9202187 to your computer and use it in GitHub Desktop.
memo pebble

Pebble Memo

Mac&iphoneの場合の内容です。

TODO

  • PebbleとJavaScript間でのメッセージ交換を色々試す。
  • SETTINGSのページを作って、設定を保存できるようにする。window.localStorageがつかえる?
  • JavaScriptから何かのWEB APIを叩いてアプリ側で反映される何かを試す。
  • デザインガイドを読む。

ドキュメント

開発方法

  1. SDKを使って自分でがんばる
  2. CloudPebble <https://cloudpebble.net/> で作る。

いつもプログラムを作る人でなければ、 CloudPebble <https://cloudpebble.net/> を使のがよい。

SDKのインストール

ターミナルを開いて実行:

curl -sSL http://developer.getpebble.com/install.sh | sh 

こんなのが出たら成功:

========================================================
Results:
========================================================
Install of PebbleSDK-2.0.1 into /Users/daisuke/pebble-dev was successful!

You are using a non-standard shell (IE, not bash).

To get the 'pebble' command into your path, you'll need to add /Users/daisuke/pebble-dev/PebbleSDK-current/bin to your $PATH.

For reference: with bash, we would have done this by typing
echo export PATH='/Users/daisuke/pebble-dev/PebbleSDK-current/bin:$PATH' >> ~/.bash_profile

最後の方に書いてあるように、.bash_profileの最後か、適当なところにパスを設定する。:

echo export PATH='/Users/daisuke/pebble-dev/PebbleSDK-current/bin:$PATH' >> ~/.bash_profile

Hello World!

pebble new-project hello_world
cd hello_world
pebble build
'build' finished successfully (0.514s)

アプリのインストール(iphone)

iphoneのPebbleアプリ経由でインストールをする。 (直接Bluetoothペアリングしてもできるっぽい)

  • iphoneのWiFiをONにする
  • 設定から下にスクロールして、Pebbleアプリを選択、DEVELOPERをオンにする。
  • Pebbleアプリを開いて、下にあるDEVELOPERをオンにする。
  • IPアドレスが書いてあるので、pebble installコマンドでインストールする。
pebble install --phone iphoneのIPアドレス

WiFi経由で接続するわけですが、試した環境ではWiFi経由ではできなかった。

そんな場合は、MacのWiFiのメニューからCreate Networkを選んで適当な名前でネットワークを作成し、iphone側がWiFiでそのネットワークに接続する。

そうすると、PebbleアプリのDEVELOPERのIPのところが変わるので、そっちのIPでインストールしてやるとできる。

また、:

export PEBBLE_PHONE=169.254.159.185

としておくと、:

pebble install

だけでインストールできる。

pebble コマンド

使いそうなやつ:

new-project         新しいプロジェクトを作成
build               ビルド
clean               ビルドファイルの削除
install             アプリを時計にインストール
logs                アプリのログを表示
repl                pythonインタプリタを起動。 
                    pebbleオブジェクトを使ってpebbleを操作できる。
screenshot          スクリーンショットを撮る

pebble new-project

新しくプロジェクトを作成するときに使う。

options:

--javascript   javascriptのひな形ができる。

pebble build

ビルドする。

pebble clean

ビルドファイルの削除

pebble install

ビルドしたファイルをpebble watchにインストールする。

options:

--phone  対象のpebbleアプリがインストールされたスマホのipを指定する。環境変数の PEBBLE_PHONE に設定しておくと毎回していしなくてもよい。
--logs   インストールしてログ表示する。

peble logs

アプリの中で出力したログを表示できる。

js:

console.log("hogehoge");

c:

APP_LOG(APP_LOG_LEVEL_DEBUG, "hogehoge");

pebble repl

pythonインタプリタを起動してその中でpebbleオブジェクトを操作できる。

これはいいね!

が、特に触ることもなさそう。

>>> see(pebble)
hash()                        help()                        repr()
str()                         .AutodetectDevice()
.app_log_disable()            .app_log_enable()
.app_message_send_byte_array()
.app_message_send_int()       .app_message_send_string()
.app_message_send_tuple()     .app_message_send_uint()
.connect_via_lightblue()      .connect_via_serial()
.connect_via_websocket()      .current_running_uuid()
.describe_app_by_uuid()       .disconnect()                 .dump_logs()
.endpoints                    .get_appbank_status()
.get_phone_info()             .get_time()
.get_versions()               .id                           .init_reader()
.install_app()                .install_app_pebble_protocol()
.install_bundle_ws()          .install_firmware()
.is_phone_info_available()    .launcher_message()
.list_apps_by_uuid()          .log_levels
.notification_email()         .notification_sms()           .ping()
.print_pbl_logs               .register_endpoint()          .remove_app()
.remove_app_by_uuid()         .reset()                      .screenshot()
.set_nowplaying_metadata()    .set_print_pbl_logs()         .set_time()
.system_message()

例えば、時刻を見るときとか。

jst.py:

import datetime

class JST(datetime.tzinfo):
    def utcoffset(self, dt):
        return datetime.timedelta(hours=9)
    def dst(self, dt): 
        return datetime.timedelta(0)
    def tzname(self, dt):
        return 'JST'
>>> import sys
>>> sys.path.append('jst.pyがあるディレクトリのパス')
>>> from jst import JST
>>> from datetime import datetime
>>> d = datetime.fromtimestamp(pebble.get_time(), JST())
>>> print d
2014-02-25 07:22:03

やっぱり使わなそう。

pebble screenshot

アプリのスクリーンショットを撮る。いい感じ!

外部(?)との通信方法

他の任意の情報が欲しい場合には通信する必要がある。 通信対象としては作れるのは、

  • iOSのアプリ
  • Androidのアプリ
  • JavaScriptプログラム

となるのかな?

外部のサーバーと通信して何かするような処理はJavaScriptで十分な感じ。

スマホ側の情報、再生中の音楽やバッテリー情報など、はスマホアプリじゃないと取得できない感じですかね。せっかくJavascriptでかけるのであれば、Pebbleアプリ用のJSライブラリがほしいですね。そういうのを作れるのかは知りませんが・・・。

JavaScriptアプリ

PebbleKit JavaScript Framework for Pebble OS

javascriptのひな形

javascriptのひな形付きでプロジェクト作成は次のようにする。:

pebble new-project --javascript sample1

メッセージ交換の仕様

  • Each message is a dictionary containing key-value pairs.
  • Each key must be an integer.
  • Values can be integers, strings or byte arrays. Values cannot be other dictionaries or arrays.
  • The size of messages is limited to 124 bytes once transformed in binary format.

javascriptとpebble間のAppMessageの変換規則

  • A Pebble AppMessage is a JavaScript object (also known as a hash or dictionary: {}). It must conform to the JSON specifications.
  • Keys are strings of integers (JavaScript only allows key-valued strings)
  • Values are either integers, strings or byte arrays.
  • All integers will be transformed into 32 bits signed integers.
  • Byte arrays in JavaScript are represented as an array of integers (for example: [ 0, 1, 2, 3, 4, 5] is a 6 bytes long byte-array). Each byte is in the range 0..255.
  • When sending data, byte arrays can contain strings. For example: [ 0, 1, 2, “hello” , “01” ] is a 10 bytes long byte-array.

AppMessageのキー

javascriptのキーとpebble側のキーを変換する定義をappinfo.jsonに記述する。:

"appKeys": {
    "firstKey":  0,
    "secondKey": 1
},

appKeysを設定しておくと、sendAppMessageのキーにfirstKeyを使えるようになる。:

Pebble.sendAppMessage({ "0":        "A value" });
Pebble.sendAppMessage({ "firstKey": "A value" });

アプリ開始時イベント

Pebble.addEventListener("ready",
    function(e) {
        console.log("JavaScript app ready and running!");
    }
);

メッセージの送信

var transactionId = Pebble.sendAppMessage( { "0": 42, "1": "String value" },
    function(e) {
        console.log("Successfully delivered message with transactionId="
        + e.data.transactionId);
    },
    function(e) {
        console.log("Unable to deliver message with transactionId="
        + e.data.transactionId
        + " Error is: " + e.error.message);
    }
);

メッセージの受信

Pebble.addEventListener("appmessage",
    function(e) {
        console.log("Received message: " + e.payload);
    }
);

Pebbleへの通知の送信

Pebble.showSimpleNotificationOnPebble(title, text);

設定画面

設定画面のサンプルはこれ pebble-hacks/js-configure-demo

設定画面を使えるようにするにはappinfo.jsonに設定する:

"capabilities": ["configurable"],

データの保存はwindow.localStorageを通して使える(未確認

Persistent Storage for Pebble OS

MY PEBBLE画面からSETTINGSをおした時、showConfigurationイベントが通知される。:

Pebble.addEventListener("showConfiguration",
                        function(e) {
                            console.log("showConfiguration");
                        });

この処理の中で、Pebble.openURL()を呼び出し、設定画面を開く。

設定が終わった場合には、次のURLをセットする:

window.location.href = "pebblejs://close#success"

coseが完了すると、webviewclosedが通知される:

Pebble.addEventListener("webviewclosed",
    function(e) {
        console.log("Configuration window returned: " + e.response);
    }
);

pebblejs://close#successの#以降はwebviewclosedのe.responseとして返される。

もし、データを渡したい場合には、次のようにする:

window.location.href = "pebblejs://close#" + encodeURIComponent(JSON.stringify(configuration));
Pebble.addEventListener("webviewclosed",
    function(e) {
        var configuration = JSON.parse(decodeURIComponent(e.response));
        console.log("Configuration window returned: ", JSON.stringify(configuration));
    }
);

iOSアプリ

iOS appからのメッセージ送信

  • uuidをappinfo.jsonのuuidとあわせる。

UI Design

TIPS

ディスプレイのサイズ

width

144

height

168

加速度計

Xが時計に向かって左右の動き。左に傾けるとマイナス、右に傾けるとプラス?
  • accel_data: GPoint(0, 0) GSize(144, 10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment