present by WoT たまごクラブ
| 時間 | 内容 |
|---|---|
| 13:00 - 13:05 | あいさつ |
| 13:05 - 15:00 | セッション1 |
| 15:00 - 15:30 | 休憩 / ブース展示 |
| 15:30 - 17:30 | セッション2 |
| 17:30 - 18:00 | ブース展示 |
| 19:00 - 21:00 | 懇親会 |
- 配布物と環境を確認
- 開発環境構築
- 簡単なFirefoxOS
- ハンズオン開始
- バイブレーション API
- 近接センサ API (proximity sensor)
- 光センサ API (ambient light sensor)
- バッテリー API
- オリエンテーション API
- 通知 API (Notification API)
- Web Socket(エクストララウンド)
- ???
- 各OS毎のadb-helper
- 各OS毎のFirefox OS 2.0シュミレータ―
- 初回環境構築マニュアル.pdf
- Firefox OS実機接続マニュアル.pdf
- ハンズオン内容.pdf
- サンプルプロジェクト
- Firefox 最新版インストーラー
- Windows用Flameドライバ(Windowsの方のみ)
- ドライバーのインストール(Windows)
- Firefoxのインストール
- adb-helperのインストール
- Firefox OS 2.0シュミレータ―のインストール
- シミュレーターの起動確認
- 実機接続の確認
既に完了してる方は10分ほどお待ちください。
Vibration
(バイブレーション)
manifast.webapp
最初なので、manifaset.webappについて簡単に説明
{
// アプリケーション名
"name": "Vibration",
// アプリケーションの説明
"description": "Web API Test",
// アプリのタイプ、web, privileged,certifiedがある
"type": "web",
// アプリケーションで最初に読むファイル
"launch_path": "/index.html", // 開発者情報
"developer": {
"name": "masap",
"url": "https://github.com/masap/fxos_samples"
},
// アイコン、左に解像度、右にその解像度のファイルを指定する。
"icons": {
"128": "/style/icons/html5.png"
}
}// ボタンが押される時のイベント定義
document.getElementById('vibrationButton').onclick = function() {
// バイブレーションが既に動いている場合止める
navigator.vibrate(0);
// 引数は配列で渡す
// 配列ごとに「振動する」「振動をやめる」ミリ秒を交互に指定
navigator.vibrate([1000, 500, 2000]);
};Proximity Sensor
(近接センサー)
// userproximity イベントの動き
window.addEventListener('userproximity', function(e) {
// 近接センサーに感知すると「near」、感知外になると「far」を表示する。
document.getElementById('userProximity').innerHTML = e.near ? 'near' : 'far';
});
// deviceproximity イベントの動き
window.addEventListener('deviceproximity', function(e) {
// deviceproximityでは距離が取れるのでその値を常に表示
document.getElementById('deviceProximity').innerHTML = e.value + ' (' + e.min + '-' + e.max + ')';
});Ambient Light Sensors
(照度センサー)
// 光量の変化を常に伝える
// 光量が変化したタイミングで動く
window.addEventListener('devicelight', function(e) {
// `e.value` には光量が入ってるので、画面に表示する。
document.getElementById('deviceLight').innerHTML = e.value;
});Battery
(バッテリー)
// バッテリーの量を確認する処理
function levelchange()
{
var battery = navigator.battery;
document.getElementById('batteryLevel').innerHTML =
(battery.level * 100.0) + '%';
}// 充電中かそうじゃないか判断する処理
function chargingchange()
{
var battery = navigator.battery;
document.getElementById('chargingchange').innerHTML =
battery.charging ? 'connected' : 'disconnected';
} // バッテリーAPIを取得
var battery = navigator.battery;
// 上で作った処理をイベントに設定する。
battery.addEventListener('levelchange', levelchange);
battery.addEventListener('chargingchange', chargingchange);
// 最初は明示的に動かす。
levelchange();
chargingchange();Orientation
(傾き検知)
// 傾きを検知したら動く処理
function orientationchange()
{
document.getElementById('screenOrientation').innerHTML =
window.screen.mozOrientation;
} var screen = window.screen;
// 上で定義した「orientationchange」処理をイベントに設定する
screen.onmozorientationchange = orientationchange;
orientationchange();
// 傾き検知をやめる
document.getElementById('lockOrientationButton').onclick = function() {
document.getElementById('lockState').innerHTML =
screen.mozLockOrientation(screen.mozOrientation) ?
'locked' : 'lock failed';
};
// 傾き検知を開始する
document.getElementById('unlockOrientationButton').onclick = function() {
screen.mozUnlockOrientation();
document.getElementById('lockState').innerHTML = 'unlocked';
};(おまけ)アプリの傾きを固定できる。
manifest.webapp に以下を追加してみよう。
{
"name": "Screen Orientation",
"description": "Web API Test",
"launch_path": "/index.html",
"developer": {
"name": "masap",
"url": "https://github.com/masap/fxos_samples"
},
// この行を追加
"orientation": [ "portrait-primary" ],
"icons": {
"128": "/style/icons/html5.png"
}
}
Notification
(通知機能)
manifest.webapp
{
"name": "Web Notification",
"description": "Web API Test",
"launch_path": "/index.html",
"developer": {
"name": "masap",
"url": "https://github.com/masap/fxos_samples"
},
// 権限を設定する必要が有る。
"permissions": {
// desktop-notification使うよ!という宣言
"desktop-notification":{}
},
"icons": {
"128": "/style/icons/html5.png"
}
} // 通知する許可があるかを確認します
if (Notification && Notification.permission !== 'granted') {
// 許可を得ていないので、許可を求めます
Notification.requestPermission(function (status) {
if (Notification.permission !== status) {
Notification.permission = status;
}
});
} // 通知する許可がある場合に通知をします
if (Notification.permission === 'granted') {
var n = new Notification('Hello');
return;
}
// まだ許可を得ていないので許可を求めます
Notification.requestPermission(function (status) {
if (Notification.permission !== status) {
Notification.permission = status;
}
if (status === 'granted') {
var n = new Notification('Hello');
} else {
alert('通知機能が許可されていません');
}
});WebSocket & GPIO
// ラズベリーパイマシンのipを指示する
var wsUri = 'ws://[ラズパイのIP]:8000/';
var output = document.getElementById('output');
var slider = document.getElementById('slider');
var brightness = document.getElementById('brightness');
// WebSocketを定義する
var websocket = new WebSocket(wsUri); slider.value = 0.0;
slider.addEventListener('change', function() {
// スライダーの値が変化すると、websocketを使ってサーバに情報を送る
brightness.innerHTML = slider.value;
// 指示する内容はgpioのportとbrightness(スライダーの値)
websocket.send('{ "port": "18", "brightness": "' + slider.value + '"}');
}); // ラズベリーパイと接続が出来たときの処理
websocket.addEventListener('open', function(evt) {
output.innerHTML = 'CONNECTED';
}); // ラズベリーパイと接続が切れたときの処理
websocket.addEventListener('close', function(evt) {
output.innerHTML = 'DISCONNECTED';
}); // ラズベリーパイに指示を出したときの処理
websocket.addEventListener('message', function(evt) {
output.innerHTML = evt.data;
}); //エラーが起こったときの処理
websocket.addEventListener('error', function(evt) {
var str = '';
for (var i in evt) {
str += i + '=' + evt[i] + '<br/>';
}
for (var i in evt.target) {
str += i + '=' + evt.target[i] + '<br/>';
}
output.innerHTML = str;
});