9. Copyright ? 2016 Uhuru Corporation, All Right Reserved.
javascript on mbed
10. Copyright ? 2016 Uhuru Corporation, All Right Reserved. 10
Jan Jongboom: Run Your JS App For Years On A Single Coin Cell -
JSConf.Asia 2016
https://youtu.be/3HLRwcVqgFE
11. Copyright ? 2016 Uhuru Corporation, All Right Reserved.
? 世はIoTの時代
? しかし、Web系、クラウド系の人はC/C++を扱えない
? Python, Ruby, PHP, Perl, javascriptなどスクリプト言語が主流
? それらをマイコン上でコイン電池で数年間持つぐらいの消費電力で動かすこと
ができないか?
11
Challenge
12. Copyright ? 2016 Uhuru Corporation, All Right Reserved.
? 元々javascriptには2種類ある
– クライアントサイドjavascript(Webブラウザで動いているもの)
– サーバーサイドjavascript(ほぼイコールNode.js)
? javascriptはイベント駆動型の処理が得意
? Node.jsはシングルスレッドでノンブロッキングI/Oを活用して複数のイベント
を見かけ上同時に処理する
? 組み込み向けでも、イベント駆動型のプログラミングならできるのでは?
– リアルタイム制御への適用は期待できないけど。。。
12
組み込みでjavascript?
13. Copyright ? 2016 Uhuru Corporation, All Right Reserved. 13
色々な組み込み向けjavascript実装
15. Copyright ? 2016 Uhuru Corporation, All Right Reserved.
? Runs on > 40 boards already
? Drivers, OS, critical paths in C++
? Deep sleep build-in
? Big library ecosystem, and many connectivity methods
? Application code can run in JS, and interop with C++
15
JS on mbed – Best of both worlds
16. Copyright ? 2016 Uhuru Corporation, All Right Reserved. 16
Sample Application Code
var blink = require('./blink_leds');
setInterval(function() {
blink();
}, 2000);
main.js
var led = DigitalOut(LED1);
var blink = function() {
led.write(led.read() ? 0 : 1);
print("blink! LED is now " + led.read());
};
module.exports = blink;
blink_led.js
すごーい!簡単だね!
17. Copyright ? 2016 Uhuru Corporation, All Right Reserved.
? スレッドの管理
? 割り込みの扱い
? コンテキストスイッチ
? 電源管理
など、
17
しかし抽象度が高いと???
ローレベルの管理ができなくなるのでは?
18. Copyright ? 2016 Uhuru Corporation, All Right Reserved.
? イベントループで自動的にスリープするようにすることで
? JS on mbed Beaconでは7年間動作できる計算
– nRF52-DK
– 1sec interval
– lowest power mode
18
Jan曰く
これは試してみなければ
19. Copyright ? 2016 Uhuru Corporation, All Right Reserved. 19
手順
mbed DevelopperサイトのNotebootで公開