• R/O
  • HTTP
  • SSH
  • HTTPS

MiMicSDK: 提交

MiMicSDK


Commit MetaInfo

修订版2ec17656b62ce9c5a512adce536daa3410697245 (tree)
时间2014-06-22 01:13:09
作者nyatla <nyatla@4719...>
Commiternyatla

Log Message

mbed.jsの更新

git-svn-id: http://svn.osdn.jp/svnroot/mimic/trunk@364 47198e57-cb75-475f-84c4-a814cd6f29e0

更改概述

差异

--- a/misc/MiMicVM/mbed.js/mimic/MiMicCore.js
+++ b/misc/MiMicVM/mbed.js/mimic/MiMicCore.js
@@ -15,6 +15,60 @@ var MiMicJS={};
1515 */
1616 NS.VERSION="MiMicJsAPI/2.0.0";
1717 /**
18+ * @name MiMicJS.assertInt
19+ * @function
20+ * 配列要素、又は値がすべてInt値でない場合に例外を起こします。
21+ * @params {[array]} v
22+ * テストする配列
23+ */
24+ NS.assertInt=function assertInt(v){
25+ if(!NS.isArray(v)){
26+ if(!NS.isInt(v)){throw new NS.MiMicException();}
27+ }
28+ for(var i=0;i<v.length;i++){
29+ if(NS.isInt(v[i])){
30+ continue;
31+ }
32+ throw new NS.MiMicException('"'+v[i]+'" is not integer.');
33+ }
34+ }
35+ /**
36+ * @name MiMicJS.assertNumber
37+ * @function
38+ * 配列要素、、又は値がすべて数値でない場合に例外を起こします。
39+ * @params {[array]} v
40+ * テストする配列
41+ */
42+ NS.assertNumber=function assertNumber(v){
43+ if(!NS.isArray(v)){
44+ if(!NS.isNumber(v)){ throw new NS.MiMicException();}
45+ }else{
46+ for(var i=0;i<v.length;i++){
47+ if(NS.isNumber(v[i])){
48+ continue;
49+ }
50+ throw new NS.MiMicException('"'+v[i]+'" is not number.');
51+ }
52+ }
53+ };
54+ /**
55+ * @private
56+ * 数値であるかを確認します。
57+ */
58+ NS.isNumber=function isNumber(o)
59+ {
60+ return (typeof o=='number');
61+ };
62+ /**
63+ * @private
64+ * 整数であるかを確認します。
65+ */
66+ NS.isInt=function isInt(o)
67+ {
68+ return (typeof o=='number') && (o-Math.round(o)==0);
69+ };
70+
71+ /**
1872 * @private
1973 * オブジェクトがジェネレータクラスであるかを返します。
2074 */
@@ -38,6 +92,13 @@ var MiMicJS={};
3892 return a instanceof Array;
3993 };
4094 /**
95+ * @private
96+ * aが配列であるかを返します。
97+ */
98+ NS.isHashArray=function isHashArray(a){
99+ return (!(a instanceof Array)) && (typeof a == "object");
100+ };
101+ /**
41102 * 連想配列をシャローコピーして複製します。
42103 * @private
43104 */
--- a/misc/MiMicVM/mbed.js/mimic/mbed.AnalogIn.js
+++ b/misc/MiMicVM/mbed.js/mimic/mbed.AnalogIn.js
@@ -38,21 +38,26 @@ var MI=MiMicJS;
3838 * @return {mbedJS.AnalogIn}
3939 * @example
4040 */
41-var CLASS=function DigitalIn(i_mcu,i_params,i_handler)
41+var CLASS=function AnalogIn(i_mcu,i_params,i_handler)
4242 {
43- var _t=this;
44- _t._mcu=i_mcu;
45- _t._lc=CLASS;
46- if(MI.isGenerator(i_handler)){_t._gen=i_handler;}
47- else if(i_handler){_t._event=i_handler}
48- function cb(j)
49- {
50- _t._oid=j.result[0];
51- if(_t._event.onNew){_t._event.onNew();}
52- if(_t._gen){_t._gen.next(_t);}
53- _t._lc=null;
54- }
55- return _t._mcu.rpc(_t.RPC_NS+":_new1",i_params,cb);
43+ try{
44+ var _t=this;
45+ _t._mcu=i_mcu;
46+ _t._lc=CLASS;
47+ if(MI.isGenerator(i_handler)){_t._gen=i_handler;}
48+ else if(i_handler){_t._event=i_handler}
49+ function cb(j)
50+ {
51+ _t._oid=j.result[0];
52+ if(_t._event.onNew){_t._event.onNew();}
53+ if(_t._gen){_t._gen.next(_t);}
54+ _t._lc=null;
55+ }
56+ MI.assertInt(i_params);
57+ return _t._mcu.rpc(_t.RPC_NS+":_new1",i_params,cb);
58+ }catch(e){
59+ throw new MI.MiMicException(e);
60+ }
5661 }
5762 CLASS.prototype=
5863 {
@@ -72,9 +77,14 @@ CLASS.prototype=
7277 * Generatorモードのときに使用する関数です。
7378 * Generatorモードの時は、yieldと併用してnew AnalogIn()の完了を待ちます。
7479 */
75- waitForNew:function AnalogIn_waitForNew(){
76- if(this._lc!=CLASS){throw new MI.MiMicException(MI.Error.NG_ILLEGAL_CALL);}
77- this._lc=CLASS.waitForNew;
80+ waitForNew:function AnalogIn_waitForNew()
81+ {
82+ try{
83+ if(this._lc!=CLASS){throw new MI.MiMicException(MI.Error.NG_ILLEGAL_CALL);}
84+ this._lc=CLASS.waitForNew;
85+ }catch(e){
86+ throw new MI.MiMicException(e);
87+ }
7888 },
7989 /**
8090 * @name mbedJS.AnalogIn#read
@@ -88,43 +98,51 @@ CLASS.prototype=
8898 */
8999 read:function AnalogIn_read()
90100 {
91- var _t=this;
92- if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
93- _t._lc=CLASS.read;
94- return _t._mcu.rpc(_t.RPC_NS+":read_fx",_t._oid,
95- function (j)
96- {
97- var v=j.result[0]/10000;
98- if(_t._event.onRead){_t._event.onRead(v);}
99- if(_t._gen){_t._gen.next(v);}
100- _t._lc=null;
101- }
102- );
101+ try{
102+ var _t=this;
103+ if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
104+ _t._lc=CLASS.read;
105+ return _t._mcu.rpc(_t.RPC_NS+":read_fx",_t._oid,
106+ function (j)
107+ {
108+ var v=j.result[0]/10000;
109+ if(_t._event.onRead){_t._event.onRead(v);}
110+ if(_t._gen){_t._gen.next(v);}
111+ _t._lc=null;
112+ }
113+ );
114+ }catch(e){
115+ throw new MI.MiMicException(e);
116+ }
103117 },
104118 /**
105119 * @name mbedJS.AnalogIn#read_u16
106120 * @function
107121 * ピンから値を読み込みます。
108- * 関数の完了時にonReadイベントが発生します。
122+ * 関数の完了時にonRead_u16イベントが発生します。
109123 * Generatorモードの時は、yieldと併用して完了を待機できます。
110124 * @return {int|int}
111125 * <p>Callbackモードの時はRPCメソッドのインデクスを返します。</p>
112126 * <p>Generatorモードの時はピンの値を返します。</p>
113127 */
114- read_u16:function AnalogIn_read_u16(i_value)
128+ read_u16:function AnalogIn_read_u16()
115129 {
116- var _t=this;
117- if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
118- _t._lc=CLASS.read_u16;
119- return _t._mcu.rpc(_t.RPC_NS+":read_u16",_t._oid,
120- function (j)
121- {
122- var v=j.result[0];
123- if(_t._event.onRead_u16){_t._event.onRead_u16(v);}
124- if(_t._gen){_t._gen.next(v);}
125- _t._lc=null;
126- }
127- );
130+ try{
131+ var _t=this;
132+ if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
133+ _t._lc=CLASS.read_u16;
134+ return _t._mcu.rpc(_t.RPC_NS+":read_u16",_t._oid,
135+ function (j)
136+ {
137+ var v=j.result[0];
138+ if(_t._event.onRead_u16){_t._event.onRead_u16(v);}
139+ if(_t._gen){_t._gen.next(v);}
140+ _t._lc=null;
141+ }
142+ );
143+ }catch(e){
144+ throw new MI.MiMicException(e);
145+ }
128146 }
129147 }
130148 NS.AnalogIn=CLASS;
--- a/misc/MiMicVM/mbed.js/mimic/mbed.AnalogOut.js
+++ b/misc/MiMicVM/mbed.js/mimic/mbed.AnalogOut.js
@@ -40,19 +40,23 @@ var MI=MiMicJS;
4040 */
4141 var CLASS=function AnalogOut(i_mcu,i_params,i_handler)
4242 {
43- var _t=this;
44- _t._mcu=i_mcu;
45- _t._lc=CLASS;
46- if(MI.isGenerator(i_handler)){_t._gen=i_handler;}
47- else if(i_handler){_t._event=i_handler}
48- function cb(j)
49- {
50- _t._oid=j.result[0];
51- if(_t._event.onNew){_t._event.onNew();}
52- if(_t._gen){_t._gen.next(_t);}
53- _t._lc=null;
54- }
55- return _t._mcu.rpc(_t.RPC_NS+":_new1",i_params,cb);
43+ try{
44+ var _t=this;
45+ _t._mcu=i_mcu;
46+ _t._lc=CLASS;
47+ if(MI.isGenerator(i_handler)){_t._gen=i_handler;}
48+ else if(i_handler){_t._event=i_handler}
49+ function cb(j)
50+ {
51+ _t._oid=j.result[0];
52+ if(_t._event.onNew){_t._event.onNew();}
53+ if(_t._gen){_t._gen.next(_t);}
54+ _t._lc=null;
55+ }
56+ MI.assertInt(i_params);
57+ return _t._mcu.rpc(_t.RPC_NS+":_new1",i_params,cb);
58+ }catch(e){
59+ throw new MI.MiMicException(e);
5660 }
5761 }
5862 CLASS.prototype=
@@ -73,9 +77,14 @@ CLASS.prototype=
7377 * Generatorモードのときに使用する関数です。
7478 * Generatorモードの時は、yieldと併用してnew AnalogOut()の完了を待ちます。
7579 */
76- waitForNew:function AnalogOut_waitForNew(){
77- if(this._lc!=CLASS){throw new MI.MiMicException(MI.Error.NG_ILLEGAL_CALL);}
78- this._lc=CLASS.waitForNew;
80+ waitForNew:function AnalogOut_waitForNew()
81+ {
82+ try{
83+ if(this._lc!=CLASS){throw new MI.MiMicException(MI.Error.NG_ILLEGAL_CALL);}
84+ this._lc=CLASS.waitForNew;
85+ }catch(e){
86+ throw new MI.MiMicException(e);
87+ }
7988 },
8089 /**
8190 * @name mbedJS.AnalogOut#write
@@ -84,22 +93,27 @@ CLASS.prototype=
8493 * 関数の完了時にonWriteイベントが発生します。
8594 * Generatorモードの時は、yieldと併用して完了を待機できます。
8695 * @param {float} i_value
87- * [0,1]の値を指定します。
96+ * [0,1]の範囲で値を指定します。
8897 * @return {int|none}
8998 * <p>Callbackモードの時はRPCメソッドのインデクスを返します。</p>
9099 * <p>Generatorモードの時は戻り値はありません。</p>
91100 */
92101 write:function AnalogOut_write(i_value)
93102 {
94- var _t=this;
95- if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
96- _t._lc=CLASS.write;
97- return _t._mcu.rpc(_t.RPC_NS+":write_fx",_t._oid+","+Math.round(i_value*10000),
98- function(j){
99- if(_t._event.onWrite){_t._event.onWrite();}
100- if(_t._gen){_t._gen.next();}
101- _t._lc=null;
102- });
103+ try{
104+ var _t=this;
105+ if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
106+ _t._lc=CLASS.write;
107+ MI.assertNumber(i_value);
108+ return _t._mcu.rpc(_t.RPC_NS+":write_fx",_t._oid+","+Math.round(i_value*10000),
109+ function(j){
110+ if(_t._event.onWrite){_t._event.onWrite();}
111+ if(_t._gen){_t._gen.next();}
112+ _t._lc=null;
113+ });
114+ }catch(e){
115+ throw new MI.MiMicException(e);
116+ }
103117 },
104118 /**
105119 * @name mbedJS.AnalogOut#write_u16
@@ -115,15 +129,20 @@ CLASS.prototype=
115129 */
116130 write_u16:function AnalogOut_write_u16(i_value)
117131 {
118- var _t=this;
119- if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
120- _t._lc=CLASS.write;
121- return _t._mcu.rpc(_t.RPC_NS+":write_fx",_t._oid+","+Math.round(i_value*10000),
122- function(j){
123- if(_t._event.onWrite_u16){_t._event.onWrite_u16();}
124- if(_t._gen){_t._gen.next();}
125- _t._lc=null;
126- });
132+ try{
133+ var _t=this;
134+ if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
135+ _t._lc=CLASS.write;
136+ MI.assertInt(i_value);
137+ return _t._mcu.rpc(_t.RPC_NS+":write_fx",_t._oid+","+i_value,
138+ function(j){
139+ if(_t._event.onWrite_u16){_t._event.onWrite_u16();}
140+ if(_t._gen){_t._gen.next();}
141+ _t._lc=null;
142+ });
143+ }catch(e){
144+ throw new MI.MiMicException(e);
145+ }
127146 },
128147 /**
129148 * @name mbedJS.AnalogOut#read
@@ -137,18 +156,22 @@ CLASS.prototype=
137156 */
138157 read:function AnalogOut_read()
139158 {
140- var _t=this;
141- if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
142- _t._lc=CLASS.read;
143- return _t._mcu.rpc(_t.RPC_NS+":read_fx",_t._oid,
144- function (j)
145- {
146- var v=j.result[0]/10000;
147- if(_t._event.onRead){_t._event.onRead(v);}
148- if(_t._gen){_t._gen.next(v);}
149- _t._lc=null;
159+ try{
160+ var _t=this;
161+ if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
162+ _t._lc=CLASS.read;
163+ return _t._mcu.rpc(_t.RPC_NS+":read_fx",_t._oid,
164+ function (j)
165+ {
166+ var v=j.result[0]/10000;
167+ if(_t._event.onRead){_t._event.onRead(v);}
168+ if(_t._gen){_t._gen.next(v);}
169+ _t._lc=null;
170+ }
171+ );
172+ }catch(e){
173+ throw new MI.MiMicException(e);
150174 }
151- );
152175 }
153176 }
154177 NS.AnalogOut=CLASS;
--- a/misc/MiMicVM/mbed.js/mimic/mbed.BusIn.js
+++ b/misc/MiMicVM/mbed.js/mimic/mbed.BusIn.js
@@ -37,32 +37,38 @@ var MI=MiMicJS;
3737 */
3838 var CLASS=function BusIn(i_mcu,i_params,i_handler)
3939 {
40- var _t=this;
41- _t._mcu=i_mcu;
42- _t._lc=CLASS;
43- if(MI.isGenerator(i_handler)){_t._gen=i_handler;}
44- else if(i_handler){_t._event=i_handler}
45- function cb(j)
46- {
47- _t._oid=j.result[0];
48- if(_t._event.onNew){_t._event.onNew();}
49- if(_t._gen){_t._gen.next(_t);}
50- _t._lc=null;
51- }
52- //Pin配列の正規化
53- var ap=i_params;
54- if(ap.length<1 ||ap.length>16){
55- throw new MI.MiMicException(MI.NG_INVALID_ARG);
56- }
57- var i=0;
58- var pins=ap[0];
59- for(;i<i_params.length;i++){
60- pins+=","+ap[i];
61- }
62- for(;i<16;i++){
63- pins+=","+NS.PinName.NC;
40+ try{
41+ var _t=this;
42+ _t._mcu=i_mcu;
43+ _t._lc=CLASS;
44+ if(MI.isGenerator(i_handler)){_t._gen=i_handler;}
45+ else if(i_handler){_t._event=i_handler}
46+ function cb(j)
47+ {
48+ _t._oid=j.result[0];
49+ if(_t._event.onNew){_t._event.onNew();}
50+ if(_t._gen){_t._gen.next(_t);}
51+ _t._lc=null;
52+ }
53+ //Pin配列の正規化
54+ var ap=i_params;
55+ if(ap.length<1 ||ap.length>16){
56+ throw new MI.MiMicException(MI.NG_INVALID_ARG);
57+ }
58+ //数値のみの配列かな?
59+ MI.assertInt(ap);
60+ var pins=ap[0];
61+ var i=1;
62+ for(;i<i_params.length;i++){
63+ pins+=","+ap[i];
64+ }
65+ for(;i<16;i++){
66+ pins+=","+NS.PinName.NC;
67+ }
68+ return _t._mcu.rpc(_t.RPC_NS+":_new1",pins,cb);
69+ }catch(e){
70+ throw new MI.MiMicException(e);
6471 }
65- return _t._mcu.rpc(_t.RPC_NS+":_new1",pins,cb);
6672 }
6773 CLASS.prototype=
6874 {
@@ -82,9 +88,14 @@ CLASS.prototype=
8288 * Generatorモードのときに使用する関数です。
8389 * Generatorモードの時は、yieldと併用してnew BusIn()の完了を待ちます。
8490 */
85- waitForNew:function BusIn_waitForNew(){
86- if(this._lc!=CLASS){throw new MI.MiMicException(MI.Error.NG_ILLEGAL_CALL);}
87- this._lc=CLASS.waitForNew;
91+ waitForNew:function BusIn_waitForNew()
92+ {
93+ try{
94+ if(this._lc!=CLASS){throw new MI.MiMicException(MI.Error.NG_ILLEGAL_CALL);}
95+ this._lc=CLASS.waitForNew;
96+ }catch(e){
97+ throw new MI.MiMicException(e);
98+ }
8899 },
89100 /**
90101 * @name mbedJS.BusIn#read
@@ -98,18 +109,22 @@ CLASS.prototype=
98109 */
99110 read:function BusIn_read()
100111 {
101- var _t=this;
102- if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
103- _t._lc=CLASS.read;
104- return _t._mcu.rpc(_t.RPC_NS+":read",_t._oid,
105- function (j)
106- {
107- var v=j.result[0];
108- if(_t._event.onRead){_t._event.onRead(v);}
109- if(_t._gen){_t._gen.next(v);}
110- _t._lc=null;
112+ try{
113+ var _t=this;
114+ if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
115+ _t._lc=CLASS.read;
116+ return _t._mcu.rpc(_t.RPC_NS+":read",_t._oid,
117+ function (j)
118+ {
119+ var v=j.result[0];
120+ if(_t._event.onRead){_t._event.onRead(v);}
121+ if(_t._gen){_t._gen.next(v);}
122+ _t._lc=null;
123+ }
124+ );
125+ }catch(e){
126+ throw new MI.MiMicException(e);
111127 }
112- );
113128 },
114129 /**
115130 * @name mbedJS.BusIn#mode
@@ -124,18 +139,23 @@ CLASS.prototype=
124139 */
125140 mode:function BusIn_mode(i_value)
126141 {
127- var _t=this;
128- if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
129- _t._lc=CLASS.mode;
130- return _t._mcu.rpc(_t.RPC_NS+":mode",_t._oid+","+i_value,
131- function (j)
132- {
133- var v=j.result[0];
134- if(_t._event.onMode){_t._event.onMode(v);}
135- if(_t._gen){_t._gen.next(v);}
136- _t._lc=null;
137- }
138- );
142+ try{
143+ var _t=this;
144+ if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
145+ _t._lc=CLASS.mode;
146+ MI.assertInt(i_value);
147+ return _t._mcu.rpc(_t.RPC_NS+":mode",_t._oid+","+i_value,
148+ function (j)
149+ {
150+ var v=j.result[0];
151+ if(_t._event.onMode){_t._event.onMode(v);}
152+ if(_t._gen){_t._gen.next(v);}
153+ _t._lc=null;
154+ }
155+ );
156+ }catch(e){
157+ throw new MI.MiMicException(e);
158+ }
139159 }
140160 }
141161 NS.BusIn=CLASS;
--- a/misc/MiMicVM/mbed.js/mimic/mbed.BusInOut.js
+++ b/misc/MiMicVM/mbed.js/mimic/mbed.BusInOut.js
@@ -4,7 +4,7 @@ var MI=MiMicJS;
44
55 /**
66 * @name mbedJS.BusInOut
7- * BusOutクラスです。
7+ * BusInOutクラスです。
88 * <a href="https://mbed.org/handbook/BusInOut">mbed::BusInOut</a>と同等の機能を持ちます。
99 * @constructor
1010 * @param {mbedJS.Mcu} i_mcu
@@ -47,32 +47,38 @@ var MI=MiMicJS;
4747 */
4848 var CLASS=function BusInOut(i_mcu,i_params,i_handler)
4949 {
50- var _t=this;
51- _t._mcu=i_mcu;
52- _t._lc=CLASS;
53- if(MI.isGenerator(i_handler)){_t._gen=i_handler;}
54- else if(i_handler){_t._event=i_handler}
55- function cb(j)
56- {
57- _t._oid=j.result[0];
58- if(_t._event.onNew){_t._event.onNew();}
59- if(_t._gen){_t._gen.next(_t);}
60- _t._lc=null;
61- }
62- //Pin配列の正規化
63- var ap=i_params;
64- if(ap.length<1 ||ap.length>16){
65- throw new MI.MiMicException(MI.NG_INVALID_ARG);
66- }
67- var i=0;
68- var pins=ap[0];
69- for(;i<i_params.length;i++){
70- pins+=","+ap[i];
71- }
72- for(;i<16;i++){
73- pins+=","+NS.PinName.NC;
50+ try{
51+ var _t=this;
52+ _t._mcu=i_mcu;
53+ _t._lc=CLASS;
54+ if(MI.isGenerator(i_handler)){_t._gen=i_handler;}
55+ else if(i_handler){_t._event=i_handler}
56+ function cb(j)
57+ {
58+ _t._oid=j.result[0];
59+ if(_t._event.onNew){_t._event.onNew();}
60+ if(_t._gen){_t._gen.next(_t);}
61+ _t._lc=null;
62+ }
63+ //Pin配列の正規化
64+ var ap=i_params;
65+ //数値のみの配列かな?
66+ MI.assertInt(ap);
67+ if(ap.length<1 ||ap.length>16){
68+ throw new MI.MiMicException(MI.NG_INVALID_ARG);
69+ }
70+ var pins=ap[0];
71+ var i=1;
72+ for(;i<i_params.length;i++){
73+ pins+=","+ap[i];
74+ }
75+ for(;i<16;i++){
76+ pins+=","+NS.PinName.NC;
77+ }
78+ return _t._mcu.rpc(_t.RPC_NS+":_new1",pins,cb);
79+ }catch(e){
80+ throw new MI.MiMicException(e);
7481 }
75- return _t._mcu.rpc(_t.RPC_NS+":_new1",pins,cb);
7682 }
7783 CLASS.prototype=
7884 {
@@ -92,9 +98,14 @@ CLASS.prototype=
9298 * Generatorモードのときに使用する関数です。
9399 * Generatorモードの時は、yieldと併用してnew BusInOut()の完了を待ちます。
94100 */
95- waitForNew:function BusInOut_waitForNew(){
96- if(this._lc!=CLASS){throw new MI.MiMicException(MI.Error.NG_ILLEGAL_CALL);}
97- this._lc=CLASS.waitForNew;
101+ waitForNew:function BusInOut_waitForNew()
102+ {
103+ try{
104+ if(this._lc!=CLASS){throw new MI.MiMicException(MI.Error.NG_ILLEGAL_CALL);}
105+ this._lc=CLASS.waitForNew;
106+ }catch(e){
107+ throw new MI.MiMicException(e);
108+ }
98109 },
99110 /**
100111 * @name mbedJS.BusInOut#write
@@ -109,15 +120,20 @@ CLASS.prototype=
109120 */
110121 write:function BusInOut_write(i_value)
111122 {
112- var _t=this;
113- if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
114- _t._lc=CLASS.write;
115- return _t._mcu.rpc(_t.RPC_NS+":write",_t._oid+","+i_value,
116- function(j){
117- if(_t._event.onWrite){_t._event.onWrite();}
118- if(_t._gen){_t._gen.next();}
119- _t._lc=null;
120- });
123+ try{
124+ var _t=this;
125+ if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
126+ _t._lc=CLASS.write;
127+ MI.assertInt(i_value);
128+ return _t._mcu.rpc(_t.RPC_NS+":write",_t._oid+","+i_value,
129+ function(j){
130+ if(_t._event.onWrite){_t._event.onWrite();}
131+ if(_t._gen){_t._gen.next();}
132+ _t._lc=null;
133+ });
134+ }catch(e){
135+ throw new MI.MiMicException(e);
136+ }
121137 },
122138 /**
123139 * @name mbedJS.BusInOut#read
@@ -131,18 +147,22 @@ CLASS.prototype=
131147 */
132148 read:function BusInOut_read()
133149 {
134- var _t=this;
135- if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
136- _t._lc=CLASS.read;
137- return _t._mcu.rpc(_t.RPC_NS+":read",_t._oid,
138- function (j)
139- {
140- var v=j.result[0];
141- if(_t._event.onRead){_t._event.onRead(v);}
142- if(_t._gen){_t._gen.next(v);}
143- _t._lc=null;
150+ try{
151+ var _t=this;
152+ if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
153+ _t._lc=CLASS.read;
154+ return _t._mcu.rpc(_t.RPC_NS+":read",_t._oid,
155+ function (j)
156+ {
157+ var v=j.result[0];
158+ if(_t._event.onRead){_t._event.onRead(v);}
159+ if(_t._gen){_t._gen.next(v);}
160+ _t._lc=null;
161+ }
162+ );
163+ }catch(e){
164+ throw new MI.MiMicException(e);
144165 }
145- );
146166 },
147167 /**
148168 * @name mbedJS.BusInOut#mode
@@ -157,18 +177,22 @@ CLASS.prototype=
157177 */
158178 mode:function BusInOut_mode(i_value)
159179 {
160- var _t=this;
161- if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
162- _t._lc=CLASS.mode;
163- return _t._mcu.rpc(_t.RPC_NS+":mode",_t._oid+","+i_value,
164- function (j)
165- {
166- var v=j.result[0];
167- if(_t._event.onMode){_t._event.onMode(v);}
168- if(_t._gen){_t._gen.next(v);}
169- _t._lc=null;
180+ try{
181+ var _t=this;
182+ if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
183+ _t._lc=CLASS.mode;
184+ MI.assertInt(i_value);
185+ return _t._mcu.rpc(_t.RPC_NS+":mode",_t._oid+","+i_value,
186+ function (j)
187+ {
188+ var v=j.result[0];
189+ if(_t._event.onMode){_t._event.onMode(v);}
190+ if(_t._gen){_t._gen.next(v);}
191+ _t._lc=null;
192+ });
193+ }catch(e){
194+ throw new MI.MiMicException(e);
170195 }
171- );
172196 },
173197 /**
174198 * @name mbedJS.BusInOut#input
@@ -181,17 +205,20 @@ CLASS.prototype=
181205 */
182206 input:function BusInOut_input()
183207 {
184- var _t=this;
185- if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
186- _t._lc=CLASS.input;
187- return _t._mcu.rpc(_t.RPC_NS+":input",_t._oid,
188- function (j)
189- {
190- if(_t._event.onInput){_t._event.onInput();}
191- if(_t._gen){_t._gen.next(v);}
192- _t._lc=null;
208+ try{
209+ var _t=this;
210+ if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
211+ _t._lc=CLASS.input;
212+ return _t._mcu.rpc(_t.RPC_NS+":input",_t._oid,
213+ function (j)
214+ {
215+ if(_t._event.onInput){_t._event.onInput();}
216+ if(_t._gen){_t._gen.next();}
217+ _t._lc=null;
218+ });
219+ }catch(e){
220+ throw new MI.MiMicException(e);
193221 }
194- );
195222 },
196223 /**
197224 * @name mbedJS.BusInOut#output
@@ -204,20 +231,21 @@ CLASS.prototype=
204231 */
205232 output:function BusInOut_output()
206233 {
207- var _t=this;
208- if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
209- _t._lc=CLASS.mode;
210- return _t._mcu.rpc(_t.RPC_NS+":output",_t._oid,
211- function (j)
212- {
213- if(_t._event.onOutput){_t._event.onOutput();}
214- if(_t._gen){_t._gen.next(v);}
215- _t._lc=null;
234+ try{
235+ var _t=this;
236+ if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
237+ _t._lc=CLASS.mode;
238+ return _t._mcu.rpc(_t.RPC_NS+":output",_t._oid,
239+ function (j)
240+ {
241+ if(_t._event.onOutput){_t._event.onOutput();}
242+ if(_t._gen){_t._gen.next();}
243+ _t._lc=null;
244+ });
245+ }catch(e){
246+ throw new MI.MiMicException(e);
216247 }
217- );
218248 }
219249 }
220-NS.BusInOut=CLASS;
221-}
222250 NS.BusInOut=CLASS;
223251 }());
\ No newline at end of file
--- a/misc/MiMicVM/mbed.js/mimic/mbed.BusOut.js
+++ b/misc/MiMicVM/mbed.js/mimic/mbed.BusOut.js
@@ -3,7 +3,7 @@ var NS=mbedJS;
33 var MI=MiMicJS;
44
55 /**
6- * @name mbedJS.BusIn
6+ * @name mbedJS.BusOut
77 * BusOutクラスです。
88 * <a href="https://mbed.org/handbook/BusOut">mbed::BusOut</a>と同等の機能を持ちます。
99 * @constructor
@@ -32,37 +32,44 @@ var MI=MiMicJS;
3232 * <p>
3333 * Generatorを指定した場合、コールバック関数の引数はyiledの戻り値として取得できます。
3434 * <p>
35- * @return {mbedJS.BusIn}
35+ * @return {mbedJS.BusOut}
3636 * @example
3737 */
3838 var CLASS=function BusOut(i_mcu,i_params,i_handler)
3939 {
40- var _t=this;
41- _t._mcu=i_mcu;
42- _t._lc=CLASS;
43- if(MI.isGenerator(i_handler)){_t._gen=i_handler;}
44- else if(i_handler){_t._event=i_handler}
45- function cb(j)
46- {
47- _t._oid=j.result[0];
48- if(_t._event.onNew){_t._event.onNew();}
49- if(_t._gen){_t._gen.next(_t);}
50- _t._lc=null;
51- }
52- //Pin配列の正規化
53- var ap=i_params;
54- if(ap.length<1 ||ap.length>16){
55- throw new MI.MiMicException(MI.NG_INVALID_ARG);
56- }
57- var i=0;
58- var pins=ap[0];
59- for(;i<i_params.length;i++){
60- pins+=","+ap[i];
61- }
62- for(;i<16;i++){
63- pins+=","+NS.PinName.NC;
40+ try{
41+ var _t=this;
42+ _t._mcu=i_mcu;
43+ _t._lc=CLASS;
44+ if(MI.isGenerator(i_handler)){_t._gen=i_handler;}
45+ else if(i_handler){_t._event=i_handler}
46+ function cb(j)
47+ {
48+ _t._oid=j.result[0];
49+ if(_t._event.onNew){_t._event.onNew();}
50+ if(_t._gen){_t._gen.next(_t);}
51+ _t._lc=null;
52+ }
53+ //Pin配列の正規化
54+ var ap=i_params;
55+ if(ap.length<1 ||ap.length>16){
56+ throw new MI.MiMicException(MI.NG_INVALID_ARG);
57+ }
58+ //数値のみの配列かな?
59+ MI.assertInt(ap);
60+ var pins=ap[0];
61+ var i=1;
62+ for(;i<i_params.length;i++){
63+ pins+=","+ap[i];
64+ }
65+ for(;i<16;i++){
66+ pins+=","+NS.PinName.NC;
67+ }
68+ return _t._mcu.rpc(_t.RPC_NS+":_new1",pins,cb);
69+ }catch(e){
70+ throw new MI.MiMicException(e);
6471 }
65- return _t._mcu.rpc(_t.RPC_NS+":_new1",pins,cb);
72+
6673 }
6774 CLASS.prototype=
6875 {
@@ -82,9 +89,14 @@ CLASS.prototype=
8289 * Generatorモードのときに使用する関数です。
8390 * Generatorモードの時は、yieldと併用してnew BusOut()の完了を待ちます。
8491 */
85- waitForNew:function BusOut_waitForNew(){
86- if(this._lc!=CLASS){throw new MI.MiMicException(MI.Error.NG_ILLEGAL_CALL);}
87- this._lc=CLASS.waitForNew;
92+ waitForNew:function BusOut_waitForNew()
93+ {
94+ try{
95+ if(this._lc!=CLASS){throw new MI.MiMicException(MI.Error.NG_ILLEGAL_CALL);}
96+ this._lc=CLASS.waitForNew;
97+ }catch(e){
98+ throw new MI.MiMicException(e);
99+ }
88100 },
89101 /**
90102 * @name mbedJS.BusOut#write
@@ -99,15 +111,20 @@ CLASS.prototype=
99111 */
100112 write:function BusOut_write(i_value)
101113 {
102- var _t=this;
103- if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
104- _t._lc=CLASS.write;
105- return _t._mcu.rpc(_t.RPC_NS+":write",_t._oid+","+i_value,
106- function(j){
107- if(_t._event.onWrite){_t._event.onWrite();}
108- if(_t._gen){_t._gen.next();}
109- _t._lc=null;
110- });
114+ try{
115+ var _t=this;
116+ if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
117+ _t._lc=CLASS.write;
118+ MI.assertInt(i_value);
119+ return _t._mcu.rpc(_t.RPC_NS+":write",_t._oid+","+i_value,
120+ function(j){
121+ if(_t._event.onWrite){_t._event.onWrite();}
122+ if(_t._gen){_t._gen.next();}
123+ _t._lc=null;
124+ });
125+ }catch(e){
126+ throw new MI.MiMicException(e);
127+ }
111128 },
112129 /**
113130 * @name mbedJS.BusOut#read
@@ -121,18 +138,21 @@ CLASS.prototype=
121138 */
122139 read:function BusOut_read()
123140 {
124- var _t=this;
125- if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
126- _t._lc=CLASS.read;
127- return _t._mcu.rpc(_t.RPC_NS+":read",_t._oid,
128- function (j)
129- {
130- var v=j.result[0];
131- if(_t._event.onRead){_t._event.onRead(v);}
132- if(_t._gen){_t._gen.next(v);}
133- _t._lc=null;
141+ try{
142+ var _t=this;
143+ if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
144+ _t._lc=CLASS.read;
145+ return _t._mcu.rpc(_t.RPC_NS+":read",_t._oid,
146+ function (j)
147+ {
148+ var v=j.result[0];
149+ if(_t._event.onRead){_t._event.onRead(v);}
150+ if(_t._gen){_t._gen.next(v);}
151+ _t._lc=null;
152+ });
153+ }catch(e){
154+ throw new MI.MiMicException(e);
134155 }
135- );
136156 }
137157 }
138158 NS.BusOut=CLASS;
--- a/misc/MiMicVM/mbed.js/mimic/mbed.DigitalIn.js
+++ b/misc/MiMicVM/mbed.js/mimic/mbed.DigitalIn.js
@@ -37,19 +37,24 @@ var MI=MiMicJS;
3737 */
3838 var CLASS=function DigitalIn(i_mcu,i_params,i_handler)
3939 {
40- var _t=this;
41- _t._mcu=i_mcu;
42- _t._lc=CLASS;
43- if(MI.isGenerator(i_handler)){_t._gen=i_handler;}
44- else if(i_handler){_t._event=i_handler}
45- function cb(j)
46- {
47- _t._oid=j.result[0];
48- if(_t._event.onNew){_t._event.onNew();}
49- if(_t._gen){_t._gen.next(_t);}
50- _t._lc=null;
40+ try{
41+ var _t=this;
42+ _t._mcu=i_mcu;
43+ _t._lc=CLASS;
44+ if(MI.isGenerator(i_handler)){_t._gen=i_handler;}
45+ else if(i_handler){_t._event=i_handler}
46+ function cb(j)
47+ {
48+ _t._oid=j.result[0];
49+ if(_t._event.onNew){_t._event.onNew();}
50+ if(_t._gen){_t._gen.next(_t);}
51+ _t._lc=null;
52+ }
53+ MI.assertInt(i_params);
54+ return _t._mcu.rpc(_t.RPC_NS+":_new1",i_params,cb);
55+ }catch(e){
56+ throw new MI.MiMicException(e);
5157 }
52- return _t._mcu.rpc(_t.RPC_NS+":_new1",i_params,cb);
5358 }
5459 CLASS.prototype=
5560 {
@@ -69,14 +74,19 @@ CLASS.prototype=
6974 * Generatorモードのときに使用する関数です。
7075 * Generatorモードの時は、yieldと併用してnew DigitalIn()の完了を待ちます。
7176 */
72- waitForNew:function DigitalIn_waitForNew(){
73- if(this._lc!=CLASS){throw new MI.MiMicException(MI.Error.NG_ILLEGAL_CALL);}
74- this._lc=CLASS.waitForNew;
77+ waitForNew:function DigitalIn_waitForNew()
78+ {
79+ try{
80+ if(this._lc!=CLASS){throw new MI.MiMicException(MI.Error.NG_ILLEGAL_CALL);}
81+ this._lc=CLASS.waitForNew;
82+ }catch(e){
83+ throw new MI.MiMicException(e);
84+ }
7585 },
7686 /**
7787 * @name mbedJS.DigitalIn#read
7888 * @function
79- * ピンから値を読み込みます。
89+ * ピンからアナログ値を読み込みます。
8090 * 関数の完了時にonReadイベントが発生します。
8191 * Generatorモードの時は、yieldと併用して完了を待機できます。
8292 * @return {int|int}
@@ -85,18 +95,22 @@ CLASS.prototype=
8595 */
8696 read:function DigitalIn_read()
8797 {
88- var _t=this;
89- if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
90- _t._lc=CLASS.read;
91- return _t._mcu.rpc(_t.RPC_NS+":read",_t._oid,
92- function (j)
93- {
94- var v=j.result[0];
95- if(_t._event.onRead){_t._event.onRead(v);}
96- if(_t._gen){_t._gen.next(v);}
97- _t._lc=null;
98+ try{
99+ var _t=this;
100+ if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
101+ _t._lc=CLASS.read;
102+ return _t._mcu.rpc(_t.RPC_NS+":read",_t._oid,
103+ function (j)
104+ {
105+ var v=j.result[0];
106+ if(_t._event.onRead){_t._event.onRead(v);}
107+ if(_t._gen){_t._gen.next(v);}
108+ _t._lc=null;
109+ }
110+ );
111+ }catch(e){
112+ throw new MI.MiMicException(e);
98113 }
99- );
100114 },
101115 /**
102116 * @name mbedJS.DigitalIn#mode
@@ -111,18 +125,23 @@ CLASS.prototype=
111125 */
112126 mode:function DigitalIn_mode(i_value)
113127 {
114- var _t=this;
115- if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
116- _t._lc=CLASS.mode;
117- return _t._mcu.rpc(_t.RPC_NS+":mode",_t._oid+","+i_value,
118- function (j)
119- {
120- var v=j.result[0];
121- if(_t._event.onMode){_t._event.onMode(v);}
122- if(_t._gen){_t._gen.next(v);}
123- _t._lc=null;
128+ try{
129+ var _t=this;
130+ if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
131+ _t._lc=CLASS.mode;
132+ MI.assertInt(i_value);
133+ return _t._mcu.rpc(_t.RPC_NS+":mode",_t._oid+","+i_value,
134+ function (j)
135+ {
136+ var v=j.result[0];
137+ if(_t._event.onMode){_t._event.onMode(v);}
138+ if(_t._gen){_t._gen.next(v);}
139+ _t._lc=null;
140+ }
141+ );
142+ }catch(e){
143+ throw new MI.MiMicException(e);
124144 }
125- );
126145 }
127146 }
128147 NS.DigitalIn=CLASS;
--- a/misc/MiMicVM/mbed.js/mimic/mbed.DigitalOut.js
+++ b/misc/MiMicVM/mbed.js/mimic/mbed.DigitalOut.js
@@ -9,8 +9,8 @@ var MI=MiMicJS;
99 * @constructor
1010 * @param {mbedJS.Mcu} i_mcu
1111 * インスタンスをバインドするMCUオブジェクトです。
12- * @param {PinName|HashMap} i_params
13- * PinName又はコンストラクタの引数を格納した連想配列です。
12+ * @param {PinName|HashMap|Array} i_params
13+ * PinName又はコンストラクタの引数を格納した連想配列、配列です。
1414 * 複数のパラメータを指定する場合は連想配列を使用してください。
1515 * <p>PinNameの場合は制御するPinIDを指定します。</p>
1616 * <p>
@@ -22,10 +22,14 @@ var MI=MiMicJS;
2222 * ピンの初期値を指定します。</li>
2323 * </ul>
2424 * </p>
25+ * <p>配列の場合は次の順番でパラメータを指定します。
26+ * <pre>{pin,value}</pre>
27+ * </p>
2528 * @param {HashMap|Generator} i_event
2629 * 非同期イベントハンドラの連想配列、又はGeneratorです。
2730 * <p>
2831 * 非同期イベントハンドラの場合、関数はイベントハンドラで結果を通知します。
32+ *
2933 * <ul>
3034 * <li>{function()} onNew -
3135 * インスタンスが使用可能になった時に呼び出されます。
@@ -48,22 +52,37 @@ var MI=MiMicJS;
4852 */
4953 var CLASS=function DigitalOut(i_mcu,i_params,i_handler)
5054 {
51- var _t=this;
52- _t._mcu=i_mcu;
53- _t._lc=CLASS;
54- if(MI.isGenerator(i_handler)){_t._gen=i_handler;}
55- else if(i_handler){_t._event=i_handler}
56- function cb(j)
57- {
58- _t._oid=j.result[0];
59- if(_t._event.onNew){_t._event.onNew();}
60- if(_t._gen){_t._gen.next(_t);}
61- _t._lc=null;
62- }
63- if(!MI.isArray(i_params)){
64- return _t._mcu.rpc(_t.RPC_NS+":_new1",i_params,cb);
65- }else{
66- return _t._mcu.rpc(_t.RPC_NS+":_new2",i_params.pin+","+i_params.value,cb);
55+ try{
56+ var _t=this;
57+ _t._mcu=i_mcu;
58+ _t._lc=CLASS;
59+ if(MI.isGenerator(i_handler)){_t._gen=i_handler;}
60+ else if(i_handler){_t._event=i_handler}
61+ function cb(j)
62+ {
63+ _t._oid=j.result[0];
64+ if(_t._event.onNew){_t._event.onNew();}
65+ if(_t._gen){_t._gen.next(_t);}
66+ _t._lc=null;
67+ }
68+ //パラメタ生成
69+ var pr;
70+ if(MI.isHashArray(i_params)){
71+ pr=[i_params.pin,i_params.value];
72+ }else if(MI.isArray(i_params)){
73+ pr=[i_params[0],null];
74+ }else{
75+ pr=[i_params,null];
76+ }
77+ MI.assertInt(pr[0]);
78+ if(pr[1]){
79+ MI.assertInt(pr[1]);
80+ return _t._mcu.rpc(_t.RPC_NS+":_new2",pr[0]+","+pr[1],cb);
81+ }else{
82+ return _t._mcu.rpc(_t.RPC_NS+":_new1",pr[0],cb);
83+ }
84+ }catch(e){
85+ throw new MI.MiMicException(e);
6786 }
6887 }
6988 CLASS.prototype=
@@ -84,9 +103,14 @@ CLASS.prototype=
84103 * Generatorモードのときに使用する関数です。
85104 * Generatorモードの時は、yieldと併用してnew DigitalOut()の完了を待ちます。
86105 */
87- waitForNew:function DigitalOut_waitForNew(){
88- if(this._lc!=CLASS){throw new MI.MiMicException(MI.Error.NG_ILLEGAL_CALL);}
89- this._lc=CLASS.waitForNew;
106+ waitForNew:function DigitalOut_waitForNew()
107+ {
108+ try{
109+ if(this._lc!=CLASS){throw new MI.MiMicException(MI.Error.NG_ILLEGAL_CALL);}
110+ this._lc=CLASS.waitForNew;
111+ }catch(e){
112+ throw new MI.MiMicException(e);
113+ }
90114 },
91115 /**
92116 * @name mbedJS.DigitalOut#write
@@ -101,15 +125,20 @@ CLASS.prototype=
101125 */
102126 write:function DigitalOut_write(i_value)
103127 {
104- var _t=this;
105- if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
106- _t._lc=CLASS.write;
107- return _t._mcu.rpc(_t.RPC_NS+":write",_t._oid+","+i_value,
108- function(j){
109- if(_t._event.onWrite){_t._event.onWrite();}
110- if(_t._gen){_t._gen.next();}
111- _t._lc=null;
112- });
128+ try{
129+ var _t=this;
130+ if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
131+ _t._lc=CLASS.write;
132+ MI.assertInt(i_value);
133+ return _t._mcu.rpc(_t.RPC_NS+":write",_t._oid+","+i_value,
134+ function(j){
135+ if(_t._event.onWrite){_t._event.onWrite();}
136+ if(_t._gen){_t._gen.next();}
137+ _t._lc=null;
138+ });
139+ }catch(e){
140+ throw new MI.MiMicException(e);
141+ }
113142 },
114143 /**
115144 * @name mbedJS.DigitalOut#read
@@ -123,18 +152,22 @@ CLASS.prototype=
123152 */
124153 read:function DigitalOut_read()
125154 {
126- var _t=this;
127- if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
128- _t._lc=CLASS.read;
129- return _t._mcu.rpc(_t.RPC_NS+":read",_t._oid,
130- function (j)
131- {
132- var v=j.result[0];
133- if(_t._event.onRead){_t._event.onRead(v);}
134- if(_t._gen){_t._gen.next(v);}
135- _t._lc=null;
155+ try{
156+ var _t=this;
157+ if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
158+ _t._lc=CLASS.read;
159+ return _t._mcu.rpc(_t.RPC_NS+":read",_t._oid,
160+ function (j)
161+ {
162+ var v=j.result[0];
163+ if(_t._event.onRead){_t._event.onRead(v);}
164+ if(_t._gen){_t._gen.next(v);}
165+ _t._lc=null;
166+ }
167+ );
168+ }catch(e){
169+ throw new MI.MiMicException(e);
136170 }
137- );
138171 }
139172 }
140173 NS.DigitalOut=CLASS;
--- a/misc/MiMicVM/mbed.js/mimic/mbed.PortIn.js
+++ b/misc/MiMicVM/mbed.js/mimic/mbed.PortIn.js
@@ -9,14 +9,19 @@ var MI=MiMicJS;
99 * @constructor
1010 * @param {mbedJS.Mcu} i_mcu
1111 * インスタンスをバインドするMCUオブジェクトです。
12- * @param {HashMap} i_params
13- * パラメータを格納したHashMapを設定します。
12+ * @param {HashMap|Array} i_params
13+ * <p>
14+ * HashNapの場合は以下のメンバを指定できます。
1415 * <ul>
1516 * <li>{PortName} port -
1617 * ポート名を指定します。</li>
1718 * <li>{uint32} mask -
1819 * ポートマスクを指定します。</li>
1920 * </ul>
21+ * </p>
22+ * <p>配列の場合は次の順番でパラメータを指定します。
23+ * <pre>{port,mask}</pre>
24+ * </p>
2025 * @param {HashMap|Generator} i_event
2126 * 非同期イベントハンドラの連想配列、又はGeneratorです。
2227 * <p>
@@ -40,19 +45,31 @@ var MI=MiMicJS;
4045 */
4146 var CLASS=function PortIn(i_mcu,i_params,i_handler)
4247 {
43- var _t=this;
44- _t._mcu=i_mcu;
45- _t._lc=CLASS;
46- if(MI.isGenerator(i_handler)){_t._gen=i_handler;}
47- else if(i_handler){_t._event=i_handler}
48- function cb(j)
49- {
50- _t._oid=j.result[0];
51- if(_t._event.onNew){_t._event.onNew();}
52- if(_t._gen){_t._gen.next(_t);}
53- _t._lc=null;
54- }
55- return _t._mcu.rpc(_t.RPC_NS+":_new1",i_params.port+","+i_params.mask,cb);
48+ try{
49+ var _t=this;
50+ _t._mcu=i_mcu;
51+ _t._lc=CLASS;
52+ if(MI.isGenerator(i_handler)){_t._gen=i_handler;}
53+ else if(i_handler){_t._event=i_handler}
54+ function cb(j)
55+ {
56+ _t._oid=j.result[0];
57+ if(_t._event.onNew){_t._event.onNew();}
58+ if(_t._gen){_t._gen.next(_t);}
59+ _t._lc=null;
60+ }
61+ //引数の正規化
62+ var pr;
63+ if(MI.isHashArray(i_params)){
64+ pr=[i_params.port,i_params.mask];
65+ }else if(MI.isArray(i_params)){
66+ pr=i_params;
67+ }
68+ MI.assertInt(pr);
69+ return _t._mcu.rpc(_t.RPC_NS+":_new1",pr[0]+","+pr[1],cb);
70+ }catch(e){
71+ throw new MI.MiMicException(e);
72+ }
5673 }
5774 CLASS.prototype=
5875 {
@@ -72,9 +89,14 @@ CLASS.prototype=
7289 * Generatorモードのときに使用する関数です。
7390 * Generatorモードの時は、yieldと併用してnew PortIn()の完了を待ちます。
7491 */
75- waitForNew:function PortIn_waitForNew(){
76- if(this._lc!=CLASS){throw new MI.MiMicException(MI.Error.NG_ILLEGAL_CALL);}
77- this._lc=CLASS.waitForNew;
92+ waitForNew:function PortIn_waitForNew()
93+ {
94+ try{
95+ if(this._lc!=CLASS){throw new MI.MiMicException(MI.Error.NG_ILLEGAL_CALL);}
96+ this._lc=CLASS.waitForNew;
97+ }catch(e){
98+ throw new MI.MiMicException(e);
99+ }
78100 },
79101 /**
80102 * @name mbedJS.PortIn#read
@@ -82,24 +104,27 @@ CLASS.prototype=
82104 * ピンから値を読み込みます。
83105 * 関数の完了時にonReadイベントが発生します。
84106 * Generatorモードの時は、yieldと併用して完了を待機できます。
85- * @return {int|float}
107+ * @return {int|int}
86108 * <p>Callbackモードの時はRPCメソッドのインデクスを返します。</p>
87109 * <p>Generatorモードの時はポートの値を返します。</p>
88110 */
89111 read:function PortIn_read()
90112 {
91- var _t=this;
92- if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
93- _t._lc=CLASS.read;
94- return _t._mcu.rpc(_t.RPC_NS+":read",_t._oid,
95- function (j)
96- {
97- var v=j.result[0];
98- if(_t._event.onRead){_t._event.onRead(v);}
99- if(_t._gen){_t._gen.next(v);}
100- _t._lc=null;
101- }
102- );
113+ try{
114+ var _t=this;
115+ if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
116+ _t._lc=CLASS.read;
117+ return _t._mcu.rpc(_t.RPC_NS+":read",_t._oid,
118+ function (j)
119+ {
120+ var v=j.result[0];
121+ if(_t._event.onRead){_t._event.onRead(v);}
122+ if(_t._gen){_t._gen.next(v);}
123+ _t._lc=null;
124+ });
125+ }catch(e){
126+ throw new MI.MiMicException(e);
127+ }
103128 }
104129 }
105130 NS.PortIn=CLASS;
--- a/misc/MiMicVM/mbed.js/mimic/mbed.PortOut.js
+++ b/misc/MiMicVM/mbed.js/mimic/mbed.PortOut.js
@@ -9,14 +9,19 @@ var MI=MiMicJS;
99 * @constructor
1010 * @param {mbedJS.Mcu} i_mcu
1111 * インスタンスをバインドするMCUオブジェクトです。
12- * @param {HashMap} i_params
13- * パラメータを格納したHashMapを設定します。
12+ * @param {HashMap|Array} i_params
13+ * <p>
14+ * HashNapの場合は以下のメンバを指定できます。
1415 * <ul>
1516 * <li>{PortName} port -
1617 * ポート名を指定します。</li>
1718 * <li>{uint32} mask -
1819 * ポートマスクを指定します。</li>
1920 * </ul>
21+ * </p>
22+ * <p>配列の場合は次の順番でパラメータを指定します。
23+ * <pre>{port,mask}</pre>
24+ * </p>
2025 * @param {HashMap|Generator} i_event
2126 * 非同期イベントハンドラの連想配列、又はGeneratorです。
2227 * <p>
@@ -43,19 +48,31 @@ var MI=MiMicJS;
4348 */
4449 var CLASS=function PortOut(i_mcu,i_params,i_handler)
4550 {
46- var _t=this;
47- _t._mcu=i_mcu;
48- _t._lc=CLASS;
49- if(MI.isGenerator(i_handler)){_t._gen=i_handler;}
50- else if(i_handler){_t._event=i_handler}
51- function cb(j)
52- {
53- _t._oid=j.result[0];
54- if(_t._event.onNew){_t._event.onNew();}
55- if(_t._gen){_t._gen.next(_t);}
56- _t._lc=null;
51+ try{
52+ var _t=this;
53+ _t._mcu=i_mcu;
54+ _t._lc=CLASS;
55+ if(MI.isGenerator(i_handler)){_t._gen=i_handler;}
56+ else if(i_handler){_t._event=i_handler}
57+ function cb(j)
58+ {
59+ _t._oid=j.result[0];
60+ if(_t._event.onNew){_t._event.onNew();}
61+ if(_t._gen){_t._gen.next(_t);}
62+ _t._lc=null;
63+ }
64+ //引数の正規化
65+ var pr;
66+ if(MI.isHashArray(i_params)){
67+ pr=[i_params.port,i_params.mask];
68+ }else if(MI.isArray(i_params)){
69+ pr=i_params;
70+ }
71+ MI.assertInt(pr);
72+ return _t._mcu.rpc(_t.RPC_NS+":_new1",pr[0]+","+pr[1],cb);
73+ }catch(e){
74+ throw new MI.MiMicException(e);
5775 }
58- return _t._mcu.rpc(_t.RPC_NS+":_new2",i_params.port+","+i_params.mask,cb);
5976 }
6077 CLASS.prototype=
6178 {
@@ -75,14 +92,19 @@ CLASS.prototype=
7592 * Generatorモードのときに使用する関数です。
7693 * Generatorモードの時は、yieldと併用してnew PortOut()の完了を待ちます。
7794 */
78- waitForNew:function DigitalOut_waitForNew(){
79- if(this._lc!=CLASS){throw new MI.MiMicException(MI.Error.NG_ILLEGAL_CALL);}
80- this._lc=CLASS.waitForNew;
81- },
95+ waitForNew:function DigitalOut_waitForNew()
96+ {
97+ try{
98+ if(this._lc!=CLASS){throw new MI.MiMicException(MI.Error.NG_ILLEGAL_CALL);}
99+ this._lc=CLASS.waitForNew;
100+ }catch(e){
101+ throw new MI.MiMicException(e);
102+ }
103+ },
82104 /**
83105 * @name mbedJS.PortOut#write
84106 * @function
85- * ピンに値を出力します。
107+ * ポートへ値を出力します。
86108 * 関数の完了時にonWriteイベントが発生します。
87109 * Generatorモードの時は、yieldと併用して完了を待機できます。
88110 * @param {int} i_value
@@ -92,20 +114,25 @@ CLASS.prototype=
92114 */
93115 write:function PortOut_write(i_value)
94116 {
95- var _t=this;
96- if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
97- _t._lc=CLASS.write;
98- return _t._mcu.rpc(_t.RPC_NS+":write",_t._oid+","+i_value,
99- function(j){
100- if(_t._event.onWrite){_t._event.onWrite();}
101- if(_t._gen){_t._gen.next();}
102- _t._lc=null;
103- });
117+ try{
118+ var _t=this;
119+ if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
120+ _t._lc=CLASS.write;
121+ MI.assertInt(i_value);
122+ return _t._mcu.rpc(_t.RPC_NS+":write",_t._oid+","+i_value,
123+ function(j){
124+ if(_t._event.onWrite){_t._event.onWrite();}
125+ if(_t._gen){_t._gen.next();}
126+ _t._lc=null;
127+ });
128+ }catch(e){
129+ throw new MI.MiMicException(e);
130+ }
104131 },
105132 /**
106133 * @name mbedJS.PortOut#write
107134 * @function
108- * ピンから値を読み込みます。
135+ * ポートから値を読み込みます。
109136 * 関数の完了時にonReadイベントが発生します。
110137 * Generatorモードの時は、yieldと併用して完了を待機できます。
111138 * @return {int|int}
@@ -114,19 +141,22 @@ CLASS.prototype=
114141 */
115142 read:function PortOut_read()
116143 {
117- var _t=this;
118- if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
119- _t._lc=CLASS.read;
120- return _t._mcu.rpc(_t.RPC_NS+":read",_t._oid,
121- function (j)
122- {
123- var v=j.result[0];
124- if(_t._event.onRead){_t._event.onRead(v);}
125- if(_t._gen){_t._gen.next(v);}
126- _t._lc=null;
144+ try{
145+ var _t=this;
146+ if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
147+ _t._lc=CLASS.read;
148+ return _t._mcu.rpc(_t.RPC_NS+":read",_t._oid,
149+ function (j)
150+ {
151+ var v=j.result[0];
152+ if(_t._event.onRead){_t._event.onRead(v);}
153+ if(_t._gen){_t._gen.next(v);}
154+ _t._lc=null;
155+ });
156+ }catch(e){
157+ throw new MI.MiMicException(e);
127158 }
128- );
129159 }
130160 }
131-NS.DigitalOut=CLASS;
161+NS.PortOut=CLASS;
132162 }());
\ No newline at end of file
--- a/misc/MiMicVM/mbed.js/mimic/mbed.PwmOut.js
+++ b/misc/MiMicVM/mbed.js/mimic/mbed.PwmOut.js
@@ -5,7 +5,7 @@ var MI=MiMicJS;
55 /**
66 * @name mbedJS.PwmOut
77 * PwmOutクラスです。
8- * <a href="https://mbed.org/handbook/AnalogOut">mbed::PwmOut</a>と同等の機能を持ちます。
8+ * <a href="https://mbed.org/handbook/PwmOut">mbed::PwmOut</a>と同等の機能を持ちます。
99 * @constructor
1010 * @param {mbedJS.Mcu} i_mcu
1111 * インスタンスをバインドするMCUオブジェクトです。
@@ -55,19 +55,23 @@ var MI=MiMicJS;
5555 */
5656 var CLASS=function PwmOut(i_mcu,i_params,i_handler)
5757 {
58- var _t=this;
59- _t._mcu=i_mcu;
60- _t._lc=CLASS;
61- if(MI.isGenerator(i_handler)){_t._gen=i_handler;}
62- else if(i_handler){_t._event=i_handler}
63- function cb(j)
64- {
65- _t._oid=j.result[0];
66- if(_t._event.onNew){_t._event.onNew();}
67- if(_t._gen){_t._gen.next(_t);}
68- _t._lc=null;
69- }
70- return _t._mcu.rpc(_t.RPC_NS+":_new1",i_params,cb);
58+ try{
59+ var _t=this;
60+ _t._mcu=i_mcu;
61+ _t._lc=CLASS;
62+ if(MI.isGenerator(i_handler)){_t._gen=i_handler;}
63+ else if(i_handler){_t._event=i_handler}
64+ function cb(j)
65+ {
66+ _t._oid=j.result[0];
67+ if(_t._event.onNew){_t._event.onNew();}
68+ if(_t._gen){_t._gen.next(_t);}
69+ _t._lc=null;
70+ }
71+ MI.assertInt(i_params);
72+ return _t._mcu.rpc(_t.RPC_NS+":_new1",i_params,cb);
73+ }catch(e){
74+ throw new MI.MiMicException(e);
7175 }
7276 }
7377 CLASS.prototype=
@@ -88,17 +92,22 @@ CLASS.prototype=
8892 * Generatorモードのときに使用する関数です。
8993 * Generatorモードの時は、yieldと併用してnew PwmOut()の完了を待ちます。
9094 */
91- waitForNew:function PwmOut_waitForNew(){
92- if(this._lc!=CLASS){throw new MI.MiMicException(MI.Error.NG_ILLEGAL_CALL);}
93- this._lc=CLASS.waitForNew;
94- },
95+ waitForNew:function PwmOut_waitForNew()
96+ {
97+ try{
98+ if(this._lc!=CLASS){throw new MI.MiMicException(MI.Error.NG_ILLEGAL_CALL);}
99+ this._lc=CLASS.waitForNew;
100+ }catch(e){
101+ throw new MI.MiMicException(e);
102+ }
103+ },
95104 /**
96105 * @name mbedJS.PwmOut#write
97106 * @function
98107 * ピンに値を出力します。
99108 * 関数の完了時にonWriteイベントが発生します。
100109 * Generatorモードの時は、yieldと併用して完了を待機できます。
101- * @param {int} i_value
110+ * @param {float} i_value
102111 * [0,1]の値を指定します。
103112 * @return {int|none}
104113 * <p>Callbackモードの時はRPCメソッドのインデクスを返します。</p>
@@ -106,15 +115,20 @@ CLASS.prototype=
106115 */
107116 write:function PwmOut_write(i_value)
108117 {
109- var _t=this;
110- if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
111- _t._lc=CLASS.write;
112- return _t._mcu.rpc(_t.RPC_NS+":write_fx",_t._oid+","+Math.round(i_value*10000),
113- function(j){
114- if(_t._event.onWrite){_t._event.onWrite();}
115- if(_t._gen){_t._gen.next();}
116- _t._lc=null;
117- });
118+ try{
119+ var _t=this;
120+ if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
121+ _t._lc=CLASS.write;
122+ MI.assertNumber(i_value);
123+ return _t._mcu.rpc(_t.RPC_NS+":write_fx",_t._oid+","+Math.round(i_value*10000),
124+ function(j){
125+ if(_t._event.onWrite){_t._event.onWrite();}
126+ if(_t._gen){_t._gen.next();}
127+ _t._lc=null;
128+ });
129+ }catch(e){
130+ throw new MI.MiMicException(e);
131+ }
118132 },
119133 /**
120134 * @name mbedJS.PwmOut#read
@@ -128,18 +142,21 @@ CLASS.prototype=
128142 */
129143 read:function PwmOut_read()
130144 {
131- var _t=this;
132- if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
133- _t._lc=CLASS.read;
134- return _t._mcu.rpc(_t.RPC_NS+":read_fx",_t._oid,
135- function (j)
136- {
137- var v=j.result[0]/10000;
138- if(_t._event.onRead){_t._event.onRead(v);}
139- if(_t._gen){_t._gen.next(v);}
140- _t._lc=null;
141- }
142- );
145+ try{
146+ var _t=this;
147+ if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
148+ _t._lc=CLASS.read;
149+ return _t._mcu.rpc(_t.RPC_NS+":read_fx",_t._oid,
150+ function (j)
151+ {
152+ var v=j.result[0]/10000;
153+ if(_t._event.onRead){_t._event.onRead(v);}
154+ if(_t._gen){_t._gen.next(v);}
155+ _t._lc=null;
156+ });
157+ }catch(e){
158+ throw new MI.MiMicException(e);
159+ }
143160 },
144161 /**
145162 * @name mbedJS.PwmOut#period
@@ -155,15 +172,20 @@ CLASS.prototype=
155172 */
156173 period:function PwmOut_period(i_value)
157174 {
158- var _t=this;
159- if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
160- _t._lc=CLASS.period;
161- return _t._mcu.rpc(_t.RPC_NS+":period_fx",_t._oid+","+Math.round(i_value*10000),
162- function(j){
163- if(_t._event.onPeriod){_t._event.onPeriod();}
164- if(_t._gen){_t._gen.next();}
165- _t._lc=null;
166- });
175+ try{
176+ var _t=this;
177+ if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
178+ _t._lc=CLASS.period;
179+ MI.assertInt(i_value);
180+ return _t._mcu.rpc(_t.RPC_NS+":period_fx",_t._oid+","+Math.round(i_value*10000),
181+ function(j){
182+ if(_t._event.onPeriod){_t._event.onPeriod();}
183+ if(_t._gen){_t._gen.next();}
184+ _t._lc=null;
185+ });
186+ }catch(e){
187+ throw new MI.MiMicException(e);
188+ }
167189 },
168190 /**
169191 * @name mbedJS.PwmOut#period_ms
@@ -179,15 +201,20 @@ CLASS.prototype=
179201 */
180202 period_ms:function PwmOut_period_ms(i_value)
181203 {
182- var _t=this;
183- if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
184- _t._lc=CLASS.period_ms;
185- return _t._mcu.rpc(_t.RPC_NS+":period_ms",_t._oid+","+Math.round(i_value),
186- function(j){
187- if(_t._event.onPeriod_ms){_t._event.onPeriod_ms();}
188- if(_t._gen){_t._gen.next();}
189- _t._lc=null;
190- });
204+ try{
205+ var _t=this;
206+ if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
207+ _t._lc=CLASS.period_ms;
208+ MI.assertInt(i_value);
209+ return _t._mcu.rpc(_t.RPC_NS+":period_ms",_t._oid+","+Math.round(i_value),
210+ function(j){
211+ if(_t._event.onPeriod_ms){_t._event.onPeriod_ms();}
212+ if(_t._gen){_t._gen.next();}
213+ _t._lc=null;
214+ });
215+ }catch(e){
216+ throw new MI.MiMicException(e);
217+ }
191218 },
192219 /**
193220 * @name mbedJS.PwmOut#period_us
@@ -201,17 +228,22 @@ CLASS.prototype=
201228 * <p>Callbackモードの時はRPCメソッドのインデクスを返します。</p>
202229 * <p>Generatorモードの時は戻り値はありません。</p>
203230 */
204- period_ns:function PwmOut_period_us(i_value)
231+ period_us:function PwmOut_period_us(i_value)
205232 {
206- var _t=this;
207- if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
208- _t._lc=CLASS.period_us;
209- return _t._mcu.rpc(_t.RPC_NS+":period_ns",_t._oid+","+Math.round(i_value),
210- function(j){
211- if(_t._event.onPeriod_us){_t._event.onPeriod_us();}
212- if(_t._gen){_t._gen.next();}
213- _t._lc=null;
214- });
233+ try{
234+ var _t=this;
235+ if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
236+ _t._lc=CLASS.period_us;
237+ MI.assertInt(i_value);
238+ return _t._mcu.rpc(_t.RPC_NS+":period_us",_t._oid+","+Math.round(i_value),
239+ function(j){
240+ if(_t._event.onPeriod_us){_t._event.onPeriod_us();}
241+ if(_t._gen){_t._gen.next();}
242+ _t._lc=null;
243+ });
244+ }catch(e){
245+ throw new MI.MiMicException(e);
246+ }
215247 },
216248 /**
217249 * @name mbedJS.PwmOut#pulsewidth
@@ -227,15 +259,20 @@ CLASS.prototype=
227259 */
228260 pulsewidth:function PwmOut_pulsewidth(i_value)
229261 {
230- var _t=this;
231- if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
232- _t._lc=CLASS.pulsewidth;
233- return _t._mcu.rpc(_t.RPC_NS+":pulsewidth_fx",_t._oid+","+Math.round(i_value*10000),
234- function(j){
235- if(_t._event.onPulsewidth){_t._event.onPulsewidth();}
236- if(_t._gen){_t._gen.next();}
237- _t._lc=null;
238- });
262+ try{
263+ var _t=this;
264+ if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
265+ _t._lc=CLASS.pulsewidth;
266+ MI.assertInt(i_value);
267+ return _t._mcu.rpc(_t.RPC_NS+":pulsewidth_fx",_t._oid+","+Math.round(i_value*10000),
268+ function(j){
269+ if(_t._event.onPulsewidth){_t._event.onPulsewidth();}
270+ if(_t._gen){_t._gen.next();}
271+ _t._lc=null;
272+ });
273+ }catch(e){
274+ throw new MI.MiMicException(e);
275+ }
239276 },
240277 /**
241278 * @name mbedJS.PwmOut#pulsewidth_ms
@@ -251,15 +288,20 @@ CLASS.prototype=
251288 */
252289 pulsewidth_ms:function PwmOut_pulsewidth_ms(i_value)
253290 {
254- var _t=this;
255- if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
256- _t._lc=CLASS.pulsewidth_ms;
257- return _t._mcu.rpc(_t.RPC_NS+":pulsewidth_ms",_t._oid+","+Math.round(i_value),
258- function(j){
259- if(_t._event.onPulsewidth_ms){_t._event.onPulsewidth_ms();}
260- if(_t._gen){_t._gen.next();}
261- _t._lc=null;
262- });
291+ try{
292+ var _t=this;
293+ if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
294+ _t._lc=CLASS.pulsewidth_ms;
295+ MI.assertInt(i_value);
296+ return _t._mcu.rpc(_t.RPC_NS+":pulsewidth_ms",_t._oid+","+Math.round(i_value),
297+ function(j){
298+ if(_t._event.onPulsewidth_ms){_t._event.onPulsewidth_ms();}
299+ if(_t._gen){_t._gen.next();}
300+ _t._lc=null;
301+ });
302+ }catch(e){
303+ throw new MI.MiMicException(e);
304+ }
263305 },
264306 /**
265307 * @name mbedJS.PwmOut#pulsewidth_us
@@ -275,15 +317,20 @@ CLASS.prototype=
275317 */
276318 pulsewidth_us:function PwmOut_pulsewidth_us(i_value)
277319 {
278- var _t=this;
279- if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
280- _t._lc=CLASS.pulsewidth_us;
281- return _t._mcu.rpc(_t.RPC_NS+":pulsewidth_us",_t._oid+","+Math.round(i_value),
282- function(j){
283- if(_t._event.onPulsewidth_us){_t._event.onPulsewidth_us();}
284- if(_t._gen){_t._gen.next();}
285- _t._lc=null;
286- });
320+ try{
321+ var _t=this;
322+ if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
323+ _t._lc=CLASS.pulsewidth_us;
324+ MI.assertInt(i_value);
325+ return _t._mcu.rpc(_t.RPC_NS+":pulsewidth_us",_t._oid+","+Math.round(i_value),
326+ function(j){
327+ if(_t._event.onPulsewidth_us){_t._event.onPulsewidth_us();}
328+ if(_t._gen){_t._gen.next();}
329+ _t._lc=null;
330+ });
331+ }catch(e){
332+ throw new MI.MiMicException(e);
333+ }
287334 }
288335 }
289336 NS.PwmOut=CLASS;
--- a/misc/MiMicVM/mbed.js/mimic/mbed.SPI.js
+++ b/misc/MiMicVM/mbed.js/mimic/mbed.SPI.js
@@ -40,19 +40,25 @@ var MI=MiMicJS;
4040 */
4141 var CLASS=function SPI(i_mcu,i_params,i_handler)
4242 {
43- var _t=this;
44- _t._mcu=i_mcu;
45- _t._lc=CLASS;
46- if(MI.isGenerator(i_handler)){_t._gen=i_handler;}
47- else if(i_handler){_t._event=i_handler}
48- function cb(j)
49- {
50- _t._oid=j.result[0];
51- if(_t._event.onNew){_t._event.onNew();}
52- if(_t._gen){_t._gen.next(_t);}
53- _t._lc=null;
43+ try{
44+ var _t=this;
45+ _t._mcu=i_mcu;
46+ _t._lc=CLASS;
47+ if(MI.isGenerator(i_handler)){_t._gen=i_handler;}
48+ else if(i_handler){_t._event=i_handler}
49+ function cb(j)
50+ {
51+ _t._oid=j.result[0];
52+ if(_t._event.onNew){_t._event.onNew();}
53+ if(_t._gen){_t._gen.next(_t);}
54+ _t._lc=null;
55+ }
56+ MI.assertInt(i_params);
57+ return _t._mcu.rpc(_t.RPC_NS+":_new1",i_params[0]+","+i_params[1]+","+i_params[2]+","+NS.PinName.NC,cb);
58+ }catch(e){
59+ throw new MI.MiMicException(e);
5460 }
55- return _t._mcu.rpc(_t.RPC_NS+":_new1",i_params[0]+","+i_params[1]+","+i_params[2]+","+NS.PinName.NC,cb);
61+
5662 }
5763 CLASS.prototype=
5864 {
@@ -72,9 +78,14 @@ CLASS.prototype=
7278 * Generatorモードのときに使用する関数です。
7379 * Generatorモードの時は、yieldと併用してnew SPI()の完了を待ちます。
7480 */
75- waitForNew:function SPI_waitForNew(){
76- if(this._lc!=CLASS){throw new MI.MiMicException(MI.Error.NG_ILLEGAL_CALL);}
77- this._lc=CLASS.waitForNew;
81+ waitForNew:function SPI_waitForNew()
82+ {
83+ try{
84+ if(this._lc!=CLASS){throw new MI.MiMicException(MI.Error.NG_ILLEGAL_CALL);}
85+ this._lc=CLASS.waitForNew;
86+ }catch(e){
87+ throw new MI.MiMicException(e);
88+ }
7889 },
7990 /**
8091 * @name mbedJS.SPI#write
@@ -89,16 +100,21 @@ CLASS.prototype=
89100 */
90101 write:function SPI_write(i_value)
91102 {
92- var _t=this;
93- if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
94- _t._lc=CLASS.write;
95- return _t._mcu.rpc(_t.RPC_NS+":write",_t._oid+","+i_value,
96- function(j){
97- var v=j.result[0];
98- if(_t._event.onWrite){_t._event.onWrite(v);}
99- if(_t._gen){_t._gen.next();}
100- _t._lc=null;
101- });
103+ try{
104+ var _t=this;
105+ if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
106+ _t._lc=CLASS.write;
107+ MI.assertInt(i_value);
108+ return _t._mcu.rpc(_t.RPC_NS+":write",_t._oid+","+i_value,
109+ function(j){
110+ var v=j.result[0];
111+ if(_t._event.onWrite){_t._event.onWrite(v);}
112+ if(_t._gen){_t._gen.next(v);}
113+ _t._lc=null;
114+ });
115+ }catch(e){
116+ throw new MI.MiMicException(e);
117+ }
102118 },
103119 /**
104120 * @name mbedJS.SPI#frequency
@@ -114,15 +130,20 @@ CLASS.prototype=
114130 */
115131 frequency:function SPI_frequency(i_value)
116132 {
117- var _t=this;
118- if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
119- _t._lc=CLASS.frequency;
120- return _t._mcu.rpc(_t.RPC_NS+":frequency",_t._oid+","+i_value,
121- function(j){
122- if(_t._event.onFrequency){_t._event.onFrequency();}
123- if(_t._gen){_t._gen.next();}
124- _t._lc=null;
125- });
133+ try{
134+ var _t=this;
135+ if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
136+ _t._lc=CLASS.frequency;
137+ MI.assertInt(i_value);
138+ return _t._mcu.rpc(_t.RPC_NS+":frequency",_t._oid+","+i_value,
139+ function(j){
140+ if(_t._event.onFrequency){_t._event.onFrequency();}
141+ if(_t._gen){_t._gen.next();}
142+ _t._lc=null;
143+ });
144+ }catch(e){
145+ throw new MI.MiMicException(e);
146+ }
126147 },
127148 /**
128149 * @name mbedJS.SPI#format
@@ -139,16 +160,21 @@ CLASS.prototype=
139160 */
140161 format:function SPI_format(i_bits,i_mode)
141162 {
142- var _t=this;
143- if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
144- _t._lc=CLASS.format;
145- var mode=i_mode?i_mode:0;
146- return _t._mcu.rpc(_t.RPC_NS+":format",_t._oid+","+i_value+","+mode,
147- function(j){
148- if(_t._event.onFormat){_t._event.onFormat();}
149- if(_t._gen){_t._gen.next();}
150- _t._lc=null;
151- });
163+ try{
164+ var _t=this;
165+ if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
166+ _t._lc=CLASS.format;
167+ var mode=i_mode?i_mode:0;
168+ MI.assertInt([i_bits,mode]);
169+ return _t._mcu.rpc(_t.RPC_NS+":format",_t._oid+","+i_bits+","+mode,
170+ function(j){
171+ if(_t._event.onFormat){_t._event.onFormat();}
172+ if(_t._gen){_t._gen.next();}
173+ _t._lc=null;
174+ });
175+ }catch(e){
176+ throw new MI.MiMicException(e);
177+ }
152178 }
153179 }
154180 NS.SPI=CLASS;
--- a/misc/MiMicVM/mbed.js/mimic/mbed.SPISlave.js
+++ b/misc/MiMicVM/mbed.js/mimic/mbed.SPISlave.js
@@ -27,10 +27,10 @@ var MI=MiMicJS;
2727 * format関数のコールバック関数です。
2828 * </li>
2929 * <li>{function(v)} onReceive -
30- * format関数のコールバック関数です。
30+ * receive関数のコールバック関数です。
3131 * </li>
3232 * <li>{function(v)} onRead -
33- * format関数のコールバック関数です。
33+ * read関数のコールバック関数です。
3434 * <ul>
3535 * <li>{int} v - 受信した8BIT値です。</li>
3636 * </ul>
@@ -47,19 +47,24 @@ var MI=MiMicJS;
4747 */
4848 var CLASS=function SPISlave(i_mcu,i_params,i_handler)
4949 {
50- var _t=this;
51- _t._mcu=i_mcu;
52- _t._lc=CLASS;
53- if(MI.isGenerator(i_handler)){_t._gen=i_handler;}
54- else if(i_handler){_t._event=i_handler}
55- function cb(j)
56- {
57- _t._oid=j.result[0];
58- if(_t._event.onNew){_t._event.onNew();}
59- if(_t._gen){_t._gen.next(_t);}
60- _t._lc=null;
61- }
62- return _t._mcu.rpc(_t.RPC_NS+":_new1",i_params[0]+","+i_params[1]+","+i_params[2]+","+i_params[3],cb);
50+ try{
51+ var _t=this;
52+ _t._mcu=i_mcu;
53+ _t._lc=CLASS;
54+ if(MI.isGenerator(i_handler)){_t._gen=i_handler;}
55+ else if(i_handler){_t._event=i_handler}
56+ function cb(j)
57+ {
58+ _t._oid=j.result[0];
59+ if(_t._event.onNew){_t._event.onNew();}
60+ if(_t._gen){_t._gen.next(_t);}
61+ _t._lc=null;
62+ }
63+ MI.assertInt(i_params);
64+ return _t._mcu.rpc(_t.RPC_NS+":_new1",i_params[0]+","+i_params[1]+","+i_params[2]+","+i_params[3],cb);
65+ }catch(e){
66+ throw new MI.MiMicException(e);
67+ }
6368 }
6469 CLASS.prototype=
6570 {
@@ -79,9 +84,14 @@ CLASS.prototype=
7984 * Generatorモードのときに使用する関数です。
8085 * Generatorモードの時は、yieldと併用してnew SPISlave()の完了を待ちます。
8186 */
82- waitForNew:function SPISlave_waitForNew(){
83- if(this._lc!=CLASS){throw new MI.MiMicException(MI.Error.NG_ILLEGAL_CALL);}
84- this._lc=CLASS.waitForNew;
87+ waitForNew:function SPISlave_waitForNew()
88+ {
89+ try{
90+ if(this._lc!=CLASS){throw new MI.MiMicException(MI.Error.NG_ILLEGAL_CALL);}
91+ this._lc=CLASS.waitForNew;
92+ }catch(e){
93+ throw new MI.MiMicException(e);
94+ }
8595 },
8696
8797 /**
@@ -98,15 +108,20 @@ CLASS.prototype=
98108 */
99109 frequency:function SPISlave_frequency(i_value)
100110 {
101- var _t=this;
102- if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
103- _t._lc=CLASS.frequency;
104- return _t._mcu.rpc(_t.RPC_NS+":frequency",_t._oid+","+i_value,
105- function(j){
106- if(_t._event.onFrequency){_t._event.onFrequency();}
107- if(_t._gen){_t._gen.next();}
108- _t._lc=null;
109- });
111+ try{
112+ var _t=this;
113+ if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
114+ _t._lc=CLASS.frequency;
115+ MI.assertInt(i_value);
116+ return _t._mcu.rpc(_t.RPC_NS+":frequency",_t._oid+","+i_value,
117+ function(j){
118+ if(_t._event.onFrequency){_t._event.onFrequency();}
119+ if(_t._gen){_t._gen.next();}
120+ _t._lc=null;
121+ });
122+ }catch(e){
123+ throw new MI.MiMicException(e);
124+ }
110125 },
111126 /**
112127 * @name mbedJS.SPISlave#format
@@ -123,16 +138,21 @@ CLASS.prototype=
123138 */
124139 format:function SPISlave_format(i_bits,i_mode)
125140 {
126- var _t=this;
127- if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
128- _t._lc=CLASS.format;
129- var mode=i_mode?i_mode:0;
130- return _t._mcu.rpc(_t.RPC_NS+":format",_t._oid+","+i_value+","+mode,
131- function(j){
132- if(_t._event.onFormat){_t._event.onFormat();}
133- if(_t._gen){_t._gen.next();}
134- _t._lc=null;
135- });
141+ try{
142+ var _t=this;
143+ if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
144+ _t._lc=CLASS.format;
145+ var mode=i_mode?i_mode:0;
146+ MI.assertInt([i_bits,mode]);
147+ return _t._mcu.rpc(_t.RPC_NS+":format",_t._oid+","+i_bits+","+mode,
148+ function(j){
149+ if(_t._event.onFormat){_t._event.onFormat();}
150+ if(_t._gen){_t._gen.next();}
151+ _t._lc=null;
152+ });
153+ }catch(e){
154+ throw new MI.MiMicException(e);
155+ }
136156 },
137157 /**
138158 * @name mbedJS.SPISlave#read
@@ -146,18 +166,21 @@ CLASS.prototype=
146166 */
147167 read:function SPISlave_read()
148168 {
149- var _t=this;
150- if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
151- _t._lc=CLASS.read;
152- return _t._mcu.rpc(_t.RPC_NS+":read",_t._oid,
153- function (j)
154- {
155- var v=j.result[0];
156- if(_t._event.onRead){_t._event.onRead(v);}
157- if(_t._gen){_t._gen.next(v);}
158- _t._lc=null;
159- }
160- );
169+ try{
170+ var _t=this;
171+ if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
172+ _t._lc=CLASS.read;
173+ return _t._mcu.rpc(_t.RPC_NS+":read",_t._oid,
174+ function (j)
175+ {
176+ var v=j.result[0];
177+ if(_t._event.onRead){_t._event.onRead(v);}
178+ if(_t._gen){_t._gen.next(v);}
179+ _t._lc=null;
180+ });
181+ }catch(e){
182+ throw new MI.MiMicException(e);
183+ }
161184 },
162185 /**
163186 * @name mbedJS.SPISlave#receive
@@ -171,43 +194,50 @@ CLASS.prototype=
171194 */
172195 receive:function SPISlave_receive()
173196 {
174- var _t=this;
175- if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
176- _t._lc=CLASS.receive;
177- return _t._mcu.rpc(_t.RPC_NS+":receive",_t._oid,
178- function (j)
179- {
180- var v=j.result[0];
181- if(_t._event.onReceive){_t._event.onReceive(v);}
182- if(_t._gen){_t._gen.next(v);}
183- _t._lc=null;
184- }
185- );
197+ try{
198+ var _t=this;
199+ if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
200+ _t._lc=CLASS.receive;
201+ return _t._mcu.rpc(_t.RPC_NS+":receive",_t._oid,
202+ function (j)
203+ {
204+ var v=j.result[0];
205+ if(_t._event.onReceive){_t._event.onReceive(v);}
206+ if(_t._gen){_t._gen.next(v);}
207+ _t._lc=null;
208+ });
209+ }catch(e){
210+ throw new MI.MiMicException(e);
211+ }
186212 },
187213 /**
188214 * @name mbedJS.SPISlave#reply
189215 * @function
190216 * ピンモードを設定します。
191- * 関数の完了時にonModeイベントが発生します。
217+ * 関数の完了時にonReplyイベントが発生します。
192218 * Generatorモードの時は、yieldと併用して完了を待機できます。
193- * @param {PinMode} i_value
219+ * @param {int} i_value
194220 * 次に送る8bitの値です。
195221 * @return {int|none}
196222 * <p>Callbackモードの時はRPCメソッドのインデクスを返します。</p>
197223 */
198224 reply:function SPISlave_reply(i_value)
199225 {
200- var _t=this;
201- if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
202- _t._lc=CLASS.reply;
203- return _t._mcu.rpc(_t.RPC_NS+":mode",_t._oid+","+i_value,
204- function (j)
205- {
206- if(_t._event.onReply){_t._event.onReply();}
207- if(_t._gen){_t._gen.next();}
208- _t._lc=null;
209- }
210- );
226+ try{
227+ var _t=this;
228+ if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
229+ _t._lc=CLASS.reply;
230+ MI.assertInt(i_value);
231+ return _t._mcu.rpc(_t.RPC_NS+":reply",_t._oid+","+i_value,
232+ function (j)
233+ {
234+ if(_t._event.onReply){_t._event.onReply();}
235+ if(_t._gen){_t._gen.next();}
236+ _t._lc=null;
237+ });
238+ }catch(e){
239+ throw new MI.MiMicException(e);
240+ }
211241 }
212242 }
213243 NS.SPISlave=CLASS;
--- a/misc/MiMicVM/mbed.js/mimic/mbed.types.js
+++ b/misc/MiMicVM/mbed.js/mimic/mbed.types.js
@@ -16,7 +16,7 @@ NS.PinName=function(){
1616 }
1717 }
1818 // mbed DIP Pin Names p5 - p40
19- B=0x00010000;
19+ B=0x00020000;
2020 for(var i=5;i<=40;i++){
2121 D['p'+i]=B+i;
2222 }
@@ -49,7 +49,28 @@ NS.PinName=function(){
4949 // メンバの追加
5050 return D;
5151 }();
52-
52+/**
53+ * @name mbedJS.PinMode
54+ * ピンモード値です。
55+ * mbedSDKのピンモード値です。
56+ */
57+NS.PinMode={
58+ PullUp: 0x00010000,
59+ PullDown: 0x00010001,
60+ PullNone: 0x00010002,
61+ OpenDrain: 0x00010003,
62+ PullDefault:0x00010004};
63+/**
64+ * @name mbed.JS.PinName
65+ * ポート識別子です。
66+ * mbedSDKのポート名と同一です。
67+ */
68+NS.PortName={
69+ Port0: 0x00010000,
70+ Port1: 0x00010001,
71+ Port2: 0x00010002,
72+ Port3: 0x00010003,
73+ Port4: 0x00010004};
5374
5475
5576 }());
\ No newline at end of file
--- /dev/null
+++ b/misc/MiMicVM/mbed.js/test.AnalogIn.html
@@ -0,0 +1,106 @@
1+
2+<html>
3+<head>
4+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5+<script type="text/javascript" src="mimic/mbed.types.js"></script>
6+<script type="text/javascript" src="mimic/MiMicCore.js"></script>
7+<script type="text/javascript" src="mimic/mbed.Mcu.js"></script>
8+<script type="text/javascript" src="mimic/mbed.DigitalOut.js"></script>
9+<script type="text/javascript" src="mimic/mbed.DigitalIn.js"></script>
10+<script type="text/javascript" src="mimic/mbed.AnalogOut.js"></script>
11+<script type="text/javascript" src="mimic/mbed.AnalogIn.js"></script>
12+<script type="text/javascript" src="mimic/mbed.BusOut.js"></script>
13+<script type="text/javascript" src="mimic/mbed.BusIn.js"></script>
14+<script type="text/javascript" src="mimic/mbed.BusInOut.js"></script>
15+<script type="text/javascript" src="mimic/mbed.PortOut.js"></script>
16+<script type="text/javascript" src="mimic/mbed.Portin.js"></script>
17+<script type="text/javascript" src="mimic/mbed.PwmOut.js"></script>
18+<script type="text/javascript" src="mimic/mbed.SPI.js"></script>
19+<script type="text/javascript" src="mimic/mbed.SPISlave.js"></script>
20+<script type="text/javascript">
21+
22+
23+
24+function log(v)
25+{
26+ if(v===undefined){
27+ document.getElementById("console").value='';
28+ }else{
29+ document.getElementById("console").value+='['+(new Date())+']'+v+'\n';
30+ }
31+}
32+
33+/**ASYNCAPIのテスト*/
34+function async()
35+{
36+ log();
37+ log("ASYNC");
38+ var mcu=new mbedJS.Mcu("ws://192.168.128.39/rpc/",
39+ {
40+ onNew:function(){
41+ var pin=new mbedJS.AnalogIn(mcu,mbedJS.PinName.A0,{
42+ onNew:function(){
43+ log("[PASS]onNew");
44+ pin.read();
45+ },
46+ onRead:function(v)
47+ {
48+ log("[PASS]onread:"+v);
49+ pin.read_u16();
50+ },
51+ onRead_u16:function(v){
52+ log("[PASS]onRead_u16:"+v);
53+ mcu.close();
54+ }});
55+ },
56+ onClose:function(){
57+ log("[PASS]onClose");
58+ },
59+ onError:function(){
60+ alert("Error");
61+ }
62+ });
63+}
64+
65+/**
66+ * 誤った使用方法でExceptionが出た場合にシャットダウンできるかのテスト
67+ */
68+function sync()
69+{
70+ log();
71+ var g=function*(){
72+ try{
73+ var mcu=new mbedJS.Mcu("ws://192.168.128.39/rpc/",g);
74+ yield mcu.waitForNew();
75+ var pin=new mbedJS.AnalogIn(mcu,mbedJS.PinName.A0,g);
76+ log("new");
77+ yield pin.waitForNew();
78+ log("waitfor");
79+ var v=yield pin.read();
80+ log("read:"+v);
81+ v=yield pin.read_u16();
82+ log("read:"+v);
83+ yield mcu.close();
84+ log("close");
85+ }catch(e){
86+ mcu.shutdown();
87+ alert(e);
88+ throw e;
89+ }
90+ }();
91+ g.next();
92+ return;
93+
94+}
95+
96+
97+
98+</script>
99+</head>
100+<body>
101+<h1>AnalogIn test</h1>
102+<hr/>
103+<button onclick="async();">ASYNC</button>
104+<button onclick="sync();">SYNC</button>
105+<textarea id="console" rows="15" cols="80"></textarea>
106+</body>
\ No newline at end of file
--- /dev/null
+++ b/misc/MiMicVM/mbed.js/test.AnalogOut.html
@@ -0,0 +1,118 @@
1+
2+<html>
3+<head>
4+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5+<script type="text/javascript" src="mimic/mbed.types.js"></script>
6+<script type="text/javascript" src="mimic/MiMicCore.js"></script>
7+<script type="text/javascript" src="mimic/mbed.Mcu.js"></script>
8+<script type="text/javascript" src="mimic/mbed.DigitalOut.js"></script>
9+<script type="text/javascript" src="mimic/mbed.DigitalIn.js"></script>
10+<script type="text/javascript" src="mimic/mbed.AnalogOut.js"></script>
11+<script type="text/javascript" src="mimic/mbed.AnalogIn.js"></script>
12+<script type="text/javascript" src="mimic/mbed.BusOut.js"></script>
13+<script type="text/javascript" src="mimic/mbed.BusIn.js"></script>
14+<script type="text/javascript" src="mimic/mbed.BusInOut.js"></script>
15+<script type="text/javascript" src="mimic/mbed.PortOut.js"></script>
16+<script type="text/javascript" src="mimic/mbed.Portin.js"></script>
17+<script type="text/javascript" src="mimic/mbed.PwmOut.js"></script>
18+<script type="text/javascript" src="mimic/mbed.SPI.js"></script>
19+<script type="text/javascript" src="mimic/mbed.SPISlave.js"></script>
20+<script type="text/javascript">
21+
22+
23+
24+function log(v)
25+{
26+ if(v===undefined){
27+ document.getElementById("console").value='';
28+ }else{
29+ document.getElementById("console").value+='['+(new Date())+']'+v+'\n';
30+ }
31+}
32+
33+/**ASYNCAPIのテスト*/
34+function async()
35+{
36+ log();
37+ log("ASYNC");
38+ var mcu=new mbedJS.Mcu("ws://192.168.128.39/rpc/",
39+ {
40+ onNew:function(){
41+ var pin=new mbedJS.AnalogOut(mcu,mbedJS.PinName.p18,{
42+ onNew:function(){
43+ log("[PASS]onNew");
44+ pin.write(0.5);
45+ },
46+ onWrite:function()
47+ {
48+ log("[PASS]onWrite");
49+ pin.read();
50+
51+ },
52+ onRead:function(v)
53+ {
54+ log("[PASS]onread:"+v);
55+ pin.write_u16(0);
56+ },
57+ onWrite_u16:function()
58+ {
59+ log("[PASS]onWrite_u16:");
60+ mcu.close();
61+ }
62+ });
63+ },
64+ onClose:function(){
65+ log("[PASS]onClose");
66+ },
67+ onError:function(){
68+ alert("Error");
69+ }
70+ });
71+}
72+
73+/**
74+ * 誤った使用方法でExceptionが出た場合にシャットダウンできるかのテスト
75+ */
76+function sync()
77+{
78+ log();
79+ var g=function*(){
80+ try{
81+ var mcu=new mbedJS.Mcu("ws://192.168.128.39/rpc/",g);
82+ yield mcu.waitForNew();
83+ var pin=new mbedJS.AnalogOut(mcu,mbedJS.PinName.p18,g);
84+ log("new");
85+ yield pin.waitForNew();
86+ log("waitfor");
87+ v=yield pin.write(0.3);
88+ log("write");
89+ var v=yield pin.read();
90+ log("read:"+v);
91+ v=yield pin.write_u16(1000);
92+ log("write16");
93+ var v=yield pin.read();
94+ log("read:"+v);
95+ yield mcu.close();
96+ log("close");
97+ }catch(e){
98+ mcu.shutdown();
99+ alert(e);
100+ throw e;
101+ }
102+ }();
103+ g.next();
104+ return;
105+
106+}
107+
108+
109+
110+</script>
111+</head>
112+<body>
113+<h1>Analogout test</h1>
114+<hr/>
115+<button onclick="async();">ASYNC</button>
116+<button onclick="sync();">SYNC</button>
117+<textarea id="console" rows="15" cols="80"></textarea>
118+</body>
\ No newline at end of file
--- /dev/null
+++ b/misc/MiMicVM/mbed.js/test.BusIn.html
@@ -0,0 +1,106 @@
1+
2+<html>
3+<head>
4+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5+<script type="text/javascript" src="mimic/mbed.types.js"></script>
6+<script type="text/javascript" src="mimic/MiMicCore.js"></script>
7+<script type="text/javascript" src="mimic/mbed.Mcu.js"></script>
8+<script type="text/javascript" src="mimic/mbed.DigitalOut.js"></script>
9+<script type="text/javascript" src="mimic/mbed.DigitalIn.js"></script>
10+<script type="text/javascript" src="mimic/mbed.AnalogOut.js"></script>
11+<script type="text/javascript" src="mimic/mbed.AnalogIn.js"></script>
12+<script type="text/javascript" src="mimic/mbed.BusOut.js"></script>
13+<script type="text/javascript" src="mimic/mbed.BusIn.js"></script>
14+<script type="text/javascript" src="mimic/mbed.BusInOut.js"></script>
15+<script type="text/javascript" src="mimic/mbed.PortOut.js"></script>
16+<script type="text/javascript" src="mimic/mbed.Portin.js"></script>
17+<script type="text/javascript" src="mimic/mbed.PwmOut.js"></script>
18+<script type="text/javascript" src="mimic/mbed.SPI.js"></script>
19+<script type="text/javascript" src="mimic/mbed.SPISlave.js"></script>
20+<script type="text/javascript">
21+
22+
23+
24+function log(v)
25+{
26+ if(v===undefined){
27+ document.getElementById("console").value='';
28+ }else{
29+ document.getElementById("console").value+='['+(new Date())+']'+v+'\n';
30+ }
31+}
32+
33+/**ASYNCAPIのテスト*/
34+function async()
35+{
36+ log();
37+ log("ASYNC");
38+ var mcu=new mbedJS.Mcu("ws://192.168.128.39/rpc/",
39+ {
40+ onNew:function(){
41+ var pin=new mbedJS.BusIn(mcu,[mbedJS.PinName.P0_21,mbedJS.PinName.P0_22],{
42+ onNew:function(){
43+ log("[PASS]onNew");
44+ pin.read();
45+ },
46+ onRead:function(v)
47+ {
48+ log("[PASS]onread:"+v);
49+ pin.mode(mbedJS.PinMode.PullDown);
50+ },
51+ onMode:function(v){
52+ log("[PASS]onMode:");
53+ mcu.close();
54+ }});
55+ },
56+ onClose:function(){
57+ log("[PASS]onClose");
58+ },
59+ onError:function(){
60+ alert("Error");
61+ }
62+ });
63+}
64+
65+/**
66+ * 誤った使用方法でExceptionが出た場合にシャットダウンできるかのテスト
67+ */
68+function sync()
69+{
70+ log();
71+ var g=function*(){
72+ try{
73+ var mcu=new mbedJS.Mcu("ws://192.168.128.39/rpc/",g);
74+ yield mcu.waitForNew();
75+ var bus=new mbedJS.BusIn(mcu,[mbedJS.PinName.P0_21,mbedJS.PinName.P0_22],g);
76+ log("new");
77+ yield bus.waitForNew();
78+ log("waitfor");
79+ var v=yield bus.read();
80+ log("read:"+v);
81+ v=yield bus.mode(mbedJS.PinMode.PullUp);
82+ log("mode:");
83+ yield mcu.close();
84+ log("close");
85+ }catch(e){
86+ mcu.shutdown();
87+ alert(e);
88+ throw e;
89+ }
90+ }();
91+ g.next();
92+ return;
93+
94+}
95+
96+
97+
98+</script>
99+</head>
100+<body>
101+<h1>BusIn test</h1>
102+<hr/>
103+<button onclick="async();">ASYNC</button>
104+<button onclick="sync();">SYNC</button>
105+<textarea id="console" rows="15" cols="80"></textarea>
106+</body>
\ No newline at end of file
--- /dev/null
+++ b/misc/MiMicVM/mbed.js/test.BusInOut.html
@@ -0,0 +1,125 @@
1+
2+<html>
3+<head>
4+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5+<script type="text/javascript" src="mimic/mbed.types.js"></script>
6+<script type="text/javascript" src="mimic/MiMicCore.js"></script>
7+<script type="text/javascript" src="mimic/mbed.Mcu.js"></script>
8+<script type="text/javascript" src="mimic/mbed.DigitalOut.js"></script>
9+<script type="text/javascript" src="mimic/mbed.DigitalIn.js"></script>
10+<script type="text/javascript" src="mimic/mbed.AnalogOut.js"></script>
11+<script type="text/javascript" src="mimic/mbed.AnalogIn.js"></script>
12+<script type="text/javascript" src="mimic/mbed.BusOut.js"></script>
13+<script type="text/javascript" src="mimic/mbed.BusIn.js"></script>
14+<script type="text/javascript" src="mimic/mbed.BusInOut.js"></script>
15+<script type="text/javascript" src="mimic/mbed.PortOut.js"></script>
16+<script type="text/javascript" src="mimic/mbed.Portin.js"></script>
17+<script type="text/javascript" src="mimic/mbed.PwmOut.js"></script>
18+<script type="text/javascript" src="mimic/mbed.SPI.js"></script>
19+<script type="text/javascript" src="mimic/mbed.SPISlave.js"></script>
20+<script type="text/javascript">
21+
22+
23+
24+function log(v)
25+{
26+ if(v===undefined){
27+ document.getElementById("console").value='';
28+ }else{
29+ document.getElementById("console").value+='['+(new Date())+']'+v+'\n';
30+ }
31+}
32+
33+/**ASYNCAPIのテスト*/
34+function async()
35+{
36+ log();
37+ log("ASYNC");
38+ var mcu=new mbedJS.Mcu("ws://192.168.128.39/rpc/",
39+ {
40+ onNew:function(){
41+ var bus=new mbedJS.BusInOut(mcu,[mbedJS.PinName.P0_21,mbedJS.PinName.P0_22],{
42+ onNew:function(){
43+ log("[PASS]onNew");
44+ bus.mode(mbedJS.PinMode.PullDown);
45+ },
46+ onMode:function()
47+ {
48+ log("[PASS]onMode");
49+ bus.output();
50+ },
51+ onOutput:function()
52+ {
53+ log("[PASS]onOutput:");
54+ bus.write(1);
55+ },
56+ onWrite:function()
57+ {
58+ log("[PASS]onWrite:");
59+ bus.input();
60+ },
61+ onInput:function(){
62+ log("[PASS]onInput:");
63+ bus.read();
64+ },
65+ onRead:function(v)
66+ {
67+ log("[PASS]onRead:"+v);
68+ mcu.close();
69+ }});
70+ },
71+ onClose:function(){
72+ log("[PASS]onClose");
73+ },
74+ onError:function(){
75+ alert("Error");
76+ }
77+ });
78+}
79+
80+/**
81+ * 誤った使用方法でExceptionが出た場合にシャットダウンできるかのテスト
82+ */
83+function sync()
84+{
85+ log();
86+ var g=function*(){
87+ try{
88+ var mcu=new mbedJS.Mcu("ws://192.168.128.39/rpc/",g);
89+ yield mcu.waitForNew();
90+ var bus=new mbedJS.BusInOut(mcu,[mbedJS.PinName.P0_21,mbedJS.PinName.P0_22],g);
91+ yield bus.waitForNew();
92+ yield bus.mode(mbedJS.PinMode.PullDown);
93+ log("[PASS]mode");
94+ yield bus.output();
95+ log("[PASS]output:");
96+ yield bus.write(1);
97+ log("[PASS]write:");
98+ yield bus.input();
99+ log("[PASS]input:");
100+ var v=yield bus.read();
101+ log("[PASS]read:"+v);
102+ yield mcu.close();
103+ log("close");
104+ }catch(e){
105+ mcu.shutdown();
106+ alert(e);
107+ throw e;
108+ }
109+ }();
110+ g.next();
111+ return;
112+
113+}
114+
115+
116+
117+</script>
118+</head>
119+<body>
120+<h1>BusInOut test</h1>
121+<hr/>
122+<button onclick="async();">ASYNC</button>
123+<button onclick="sync();">SYNC</button>
124+<textarea id="console" rows="15" cols="80"></textarea>
125+</body>
\ No newline at end of file
--- /dev/null
+++ b/misc/MiMicVM/mbed.js/test.BusOut.html
@@ -0,0 +1,105 @@
1+
2+<html>
3+<head>
4+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5+<script type="text/javascript" src="mimic/mbed.types.js"></script>
6+<script type="text/javascript" src="mimic/MiMicCore.js"></script>
7+<script type="text/javascript" src="mimic/mbed.Mcu.js"></script>
8+<script type="text/javascript" src="mimic/mbed.DigitalOut.js"></script>
9+<script type="text/javascript" src="mimic/mbed.DigitalIn.js"></script>
10+<script type="text/javascript" src="mimic/mbed.AnalogOut.js"></script>
11+<script type="text/javascript" src="mimic/mbed.AnalogIn.js"></script>
12+<script type="text/javascript" src="mimic/mbed.BusOut.js"></script>
13+<script type="text/javascript" src="mimic/mbed.BusIn.js"></script>
14+<script type="text/javascript" src="mimic/mbed.BusInOut.js"></script>
15+<script type="text/javascript" src="mimic/mbed.PortOut.js"></script>
16+<script type="text/javascript" src="mimic/mbed.Portin.js"></script>
17+<script type="text/javascript" src="mimic/mbed.PwmOut.js"></script>
18+<script type="text/javascript" src="mimic/mbed.SPI.js"></script>
19+<script type="text/javascript" src="mimic/mbed.SPISlave.js"></script>
20+<script type="text/javascript">
21+
22+
23+
24+function log(v)
25+{
26+ if(v===undefined){
27+ document.getElementById("console").value='';
28+ }else{
29+ document.getElementById("console").value+='['+(new Date())+']'+v+'\n';
30+ }
31+}
32+
33+/**ASYNCAPIのテスト*/
34+function async()
35+{
36+ log();
37+ log("ASYNC");
38+ var mcu=new mbedJS.Mcu("ws://192.168.128.39/rpc/",
39+ {
40+ onNew:function(){
41+ var bus=new mbedJS.BusOut(mcu,[mbedJS.PinName.P0_21,mbedJS.PinName.P0_22],{
42+ onNew:function(){
43+ log("[PASS]onNew");
44+ bus.write(2);
45+ },
46+ onWrite:function()
47+ {
48+ log("[PASS]onWrite:");
49+ bus.read();
50+ },
51+ onRead:function(v){
52+ log("[PASS]onRead:"+v);
53+ mcu.close();
54+ },
55+ });
56+ },
57+ onClose:function(){
58+ log("[PASS]onClose");
59+ },
60+ onError:function(){
61+ alert("Error");
62+ }
63+ });
64+}
65+
66+/**
67+ * 誤った使用方法でExceptionが出た場合にシャットダウンできるかのテスト
68+ */
69+function sync()
70+{
71+ log();
72+ var g=function*(){
73+ try{
74+ var mcu=new mbedJS.Mcu("ws://192.168.128.39/rpc/",g);
75+ yield mcu.waitForNew();
76+ var bus=new mbedJS.BusOut(mcu,[mbedJS.PinName.P0_21,mbedJS.PinName.P0_22],g);
77+ yield bus.waitForNew();
78+ yield bus.write(1);
79+ log("[PASS]write:");
80+ var v=yield bus.read();
81+ log("[PASS]read:"+v);
82+ yield mcu.close();
83+ log("close");
84+ }catch(e){
85+ mcu.shutdown();
86+ alert(e);
87+ throw e;
88+ }
89+ }();
90+ g.next();
91+ return;
92+
93+}
94+
95+
96+
97+</script>
98+</head>
99+<body>
100+<h1>BusOut test</h1>
101+<hr/>
102+<button onclick="async();">ASYNC</button>
103+<button onclick="sync();">SYNC</button>
104+<textarea id="console" rows="15" cols="80"></textarea>
105+</body>
\ No newline at end of file
--- /dev/null
+++ b/misc/MiMicVM/mbed.js/test.DigitalIn.html
@@ -0,0 +1,106 @@
1+
2+<html>
3+<head>
4+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5+<script type="text/javascript" src="mimic/mbed.types.js"></script>
6+<script type="text/javascript" src="mimic/MiMicCore.js"></script>
7+<script type="text/javascript" src="mimic/mbed.Mcu.js"></script>
8+<script type="text/javascript" src="mimic/mbed.DigitalOut.js"></script>
9+<script type="text/javascript" src="mimic/mbed.DigitalIn.js"></script>
10+<script type="text/javascript" src="mimic/mbed.AnalogOut.js"></script>
11+<script type="text/javascript" src="mimic/mbed.AnalogIn.js"></script>
12+<script type="text/javascript" src="mimic/mbed.BusOut.js"></script>
13+<script type="text/javascript" src="mimic/mbed.BusIn.js"></script>
14+<script type="text/javascript" src="mimic/mbed.BusInOut.js"></script>
15+<script type="text/javascript" src="mimic/mbed.PortOut.js"></script>
16+<script type="text/javascript" src="mimic/mbed.Portin.js"></script>
17+<script type="text/javascript" src="mimic/mbed.PwmOut.js"></script>
18+<script type="text/javascript" src="mimic/mbed.SPI.js"></script>
19+<script type="text/javascript" src="mimic/mbed.SPISlave.js"></script>
20+<script type="text/javascript">
21+
22+
23+
24+function log(v)
25+{
26+ if(v===undefined){
27+ document.getElementById("console").value='';
28+ }else{
29+ document.getElementById("console").value+='['+(new Date())+']'+v+'\n';
30+ }
31+}
32+
33+/**ASYNCAPIのテスト*/
34+function async()
35+{
36+ log();
37+ log("ASYNC");
38+ var mcu=new mbedJS.Mcu("ws://192.168.128.39/rpc/",
39+ {
40+ onNew:function(){
41+ var pin=new mbedJS.DigitalIn(mcu,mbedJS.PinName.P0_22,{
42+ onNew:function(){
43+ log("[PASS]onNew");
44+ pin.mode(mbedJS.PinMode.PullUp);
45+ },
46+ onMode:function()
47+ {
48+ log("[PASS]onMode:");
49+ pin.read();
50+ },
51+ onRead:function(v){
52+ log("[PASS]onRead:"+v);
53+ mcu.close();
54+ }});
55+ },
56+ onClose:function(){
57+ log("[PASS]onClose");
58+ },
59+ onError:function(){
60+ alert("Error");
61+ }
62+ });
63+}
64+
65+/**
66+ * 誤った使用方法でExceptionが出た場合にシャットダウンできるかのテスト
67+ */
68+function sync()
69+{
70+ log();
71+ var g=function*(){
72+ try{
73+ var mcu=new mbedJS.Mcu("ws://192.168.128.39/rpc/",g);
74+ yield mcu.waitForNew();
75+ var pin=new mbedJS.DigitalIn(mcu,mbedJS.PinName.P0_22,g);
76+ log(1);
77+ yield pin.waitForNew();
78+ log(2);
79+ var v=yield pin.read();
80+ log(3);
81+ yield pin.mode(mbedJS.PinMode.PullDown);
82+ log(4);
83+ yield mcu.close();
84+ log(5);
85+ }catch(e){
86+ mcu.shutdown();
87+ alert(e);
88+ throw e;
89+ }
90+ }();
91+ g.next();
92+ return;
93+
94+}
95+
96+
97+
98+</script>
99+</head>
100+<body>
101+<h1>DigitalIn test</h1>
102+<hr/>
103+<button onclick="async();">ASYNC</button>
104+<button onclick="sync();">SYNC</button>
105+<textarea id="console" rows="15" cols="80"></textarea>
106+</body>
\ No newline at end of file
--- a/misc/MiMicVM/mbed.js/test.DigitalOut.html
+++ b/misc/MiMicVM/mbed.js/test.DigitalOut.html
@@ -27,7 +27,7 @@ function async()
2727 var mcu=new mbedJS.Mcu("ws://192.168.128.39/rpc/",
2828 {
2929 onNew:function(){
30- var pin=new mbedJS.DigitalOut(mcu,[mbedJS.PinName.P0_22,1],{
30+ var pin=new mbedJS.DigitalOut(mcu,mbedJS.PinName.P0_22,{
3131 onNew:function(){
3232 log("[PASS]onNew");
3333 pin.read();
@@ -60,7 +60,8 @@ function sync()
6060 try{
6161 var mcu=new mbedJS.Mcu("ws://192.168.128.39/rpc/",g);
6262 yield mcu.waitForNew();
63- var pin=new mbedJS.DigitalOut(mcu,[mbedJS.PinName.P0_22,0],g);
63+ var pin=new mbedJS.DigitalOut(mcu,{pin:mbedJS.PinName.P0_22,value:0},g);
64+// var pin=new mbedJS.DigitalOut(mcu,[mbedJS.PinName.P0_22,0],g);
6465 log(1);
6566 yield pin.waitForNew();
6667 log(2);
@@ -89,7 +90,7 @@ function sync()
8990 </script>
9091 </head>
9192 <body>
92-<h1>MCU test</h1>
93+<h1>Digitalout test</h1>
9394 <hr/>
9495 <button onclick="async();">ASYNC</button>
9596 <button onclick="sync();">SYNC</button>
--- a/misc/MiMicVM/mbed.js/test.MCU.html
+++ b/misc/MiMicVM/mbed.js/test.MCU.html
@@ -61,24 +61,6 @@ log(3);
6161 return;
6262
6363 }
64-/***/
65-function sync2()
66-{
67- var g=function*(){
68-
69- log(4);
70- var mcu=new mbedJS.Mcu("ws://192.168.128.39/rpc/",g);
71- log(5);
72- yield mcu.waitForNew();
73- log(6);
74- yield mcu.close();
75- log(7);
76-
77-
78- }();
79- g.next();
80- return;
81-}
8264
8365
8466 </script>
--- /dev/null
+++ b/misc/MiMicVM/mbed.js/test.PortIn.html
@@ -0,0 +1,101 @@
1+
2+<html>
3+<head>
4+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5+<script type="text/javascript" src="mimic/mbed.types.js"></script>
6+<script type="text/javascript" src="mimic/MiMicCore.js"></script>
7+<script type="text/javascript" src="mimic/mbed.Mcu.js"></script>
8+<script type="text/javascript" src="mimic/mbed.DigitalOut.js"></script>
9+<script type="text/javascript" src="mimic/mbed.DigitalIn.js"></script>
10+<script type="text/javascript" src="mimic/mbed.AnalogOut.js"></script>
11+<script type="text/javascript" src="mimic/mbed.AnalogIn.js"></script>
12+<script type="text/javascript" src="mimic/mbed.BusOut.js"></script>
13+<script type="text/javascript" src="mimic/mbed.BusIn.js"></script>
14+<script type="text/javascript" src="mimic/mbed.BusInOut.js"></script>
15+<script type="text/javascript" src="mimic/mbed.PortOut.js"></script>
16+<script type="text/javascript" src="mimic/mbed.Portin.js"></script>
17+<script type="text/javascript" src="mimic/mbed.PwmOut.js"></script>
18+<script type="text/javascript" src="mimic/mbed.SPI.js"></script>
19+<script type="text/javascript" src="mimic/mbed.SPISlave.js"></script>
20+<script type="text/javascript">
21+
22+
23+
24+function log(v)
25+{
26+ if(v===undefined){
27+ document.getElementById("console").value='';
28+ }else{
29+ document.getElementById("console").value+='['+(new Date())+']'+v+'\n';
30+ }
31+}
32+
33+/**ASYNCAPIのテスト*/
34+function async()
35+{
36+ log();
37+ log("ASYNC");
38+ var mcu=new mbedJS.Mcu("ws://192.168.128.39/rpc/",
39+ {
40+ onNew:function(){
41+ var pin=new mbedJS.PortIn(mcu,[mbedJS.PortName.Port0,0xffffffff],{
42+ onNew:function(){
43+ log("[PASS]onNew");
44+ pin.read();
45+ },
46+ onRead:function(v)
47+ {
48+ log("[PASS]read:"+v);
49+ mcu.close();
50+ }});
51+ },
52+ onClose:function(){
53+ log("[PASS]onClose");
54+ },
55+ onError:function(){
56+ alert("Error");
57+ }
58+ });
59+}
60+
61+/**
62+ * Sync
63+ */
64+
65+function sync()
66+{
67+ log();
68+ var g=function*(){
69+ try{
70+ var mcu=new mbedJS.Mcu("ws://192.168.128.39/rpc/",g);
71+ yield mcu.waitForNew();
72+ var port=new mbedJS.PortIn(mcu,[mbedJS.PortName.Port0,0xffffffff],g);
73+ log("new");
74+ yield port.waitForNew();
75+ log("waitfor");
76+ var v=yield port.read();
77+ log("read:"+v);
78+ yield mcu.close();
79+ log("close");
80+ }catch(e){
81+ mcu.shutdown();
82+ alert(e);
83+ throw e;
84+ }
85+ }();
86+ g.next();
87+ return;
88+
89+}
90+
91+
92+
93+</script>
94+</head>
95+<body>
96+<h1>PortIn test</h1>
97+<hr/>
98+<button onclick="async();">ASYNC</button>
99+<button onclick="sync();">SYNC</button>
100+<textarea id="console" rows="15" cols="80"></textarea>
101+</body>
\ No newline at end of file
--- /dev/null
+++ b/misc/MiMicVM/mbed.js/test.PortOut.html
@@ -0,0 +1,108 @@
1+
2+<html>
3+<head>
4+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5+<script type="text/javascript" src="mimic/mbed.types.js"></script>
6+<script type="text/javascript" src="mimic/MiMicCore.js"></script>
7+<script type="text/javascript" src="mimic/mbed.Mcu.js"></script>
8+<script type="text/javascript" src="mimic/mbed.DigitalOut.js"></script>
9+<script type="text/javascript" src="mimic/mbed.DigitalIn.js"></script>
10+<script type="text/javascript" src="mimic/mbed.AnalogOut.js"></script>
11+<script type="text/javascript" src="mimic/mbed.AnalogIn.js"></script>
12+<script type="text/javascript" src="mimic/mbed.BusOut.js"></script>
13+<script type="text/javascript" src="mimic/mbed.BusIn.js"></script>
14+<script type="text/javascript" src="mimic/mbed.BusInOut.js"></script>
15+<script type="text/javascript" src="mimic/mbed.PortOut.js"></script>
16+<script type="text/javascript" src="mimic/mbed.Portin.js"></script>
17+<script type="text/javascript" src="mimic/mbed.PwmOut.js"></script>
18+<script type="text/javascript" src="mimic/mbed.SPI.js"></script>
19+<script type="text/javascript" src="mimic/mbed.SPISlave.js"></script>
20+<script type="text/javascript">
21+
22+
23+
24+function log(v)
25+{
26+ if(v===undefined){
27+ document.getElementById("console").value='';
28+ }else{
29+ document.getElementById("console").value+='['+(new Date())+']'+v+'\n';
30+ }
31+}
32+
33+/**ASYNCAPIのテスト*/
34+function async()
35+{
36+ log();
37+ log("ASYNC");
38+ var mcu=new mbedJS.Mcu("ws://192.168.128.39/rpc/",
39+ {
40+ onNew:function(){
41+ var pin=new mbedJS.PortOut(mcu,[mbedJS.PortName.Port0,0xffffffff],{
42+ onNew:function(){
43+ log("[PASS]onNew");
44+ pin.write(1234);
45+ },
46+ onWrite:function()
47+ {
48+ log("[PASS]write:");
49+ pin.read();
50+ },
51+ onRead:function(v)
52+ {
53+ log("[PASS]read:"+v);
54+ mcu.close();
55+ }});
56+ },
57+ onClose:function(){
58+ log("[PASS]onClose");
59+ },
60+ onError:function(){
61+ alert("Error");
62+ }
63+ });
64+}
65+
66+/**
67+ * Sync
68+ */
69+
70+function sync()
71+{
72+ log();
73+ var g=function*(){
74+ try{
75+ var mcu=new mbedJS.Mcu("ws://192.168.128.39/rpc/",g);
76+ yield mcu.waitForNew();
77+ var port=new mbedJS.PortOut(mcu,{port:mbedJS.PortName.Port0,mask:0xffffffff},g);
78+ log("new");
79+ yield port.waitForNew();
80+ log("waitfor");
81+ yield port.write(5678);
82+ log("write:");
83+ var v=yield port.read();
84+ log("read:"+v);
85+ yield mcu.close();
86+ log("close");
87+ }catch(e){
88+ mcu.shutdown();
89+ alert(e);
90+ throw e;
91+ }
92+ }();
93+ g.next();
94+ return;
95+
96+}
97+
98+
99+
100+</script>
101+</head>
102+<body>
103+<h1>PortOut test</h1>
104+<hr/>
105+<button onclick="async();">ASYNC</button>
106+<button onclick="sync();">SYNC</button>
107+<textarea id="console" rows="15" cols="80"></textarea>
108+</body>
\ No newline at end of file
--- /dev/null
+++ b/misc/MiMicVM/mbed.js/test.PwmOut.html
@@ -0,0 +1,143 @@
1+
2+<html>
3+<head>
4+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5+<script type="text/javascript" src="mimic/mbed.types.js"></script>
6+<script type="text/javascript" src="mimic/MiMicCore.js"></script>
7+<script type="text/javascript" src="mimic/mbed.Mcu.js"></script>
8+<script type="text/javascript" src="mimic/mbed.DigitalOut.js"></script>
9+<script type="text/javascript" src="mimic/mbed.DigitalIn.js"></script>
10+<script type="text/javascript" src="mimic/mbed.AnalogOut.js"></script>
11+<script type="text/javascript" src="mimic/mbed.AnalogIn.js"></script>
12+<script type="text/javascript" src="mimic/mbed.BusOut.js"></script>
13+<script type="text/javascript" src="mimic/mbed.BusIn.js"></script>
14+<script type="text/javascript" src="mimic/mbed.BusInOut.js"></script>
15+<script type="text/javascript" src="mimic/mbed.PortOut.js"></script>
16+<script type="text/javascript" src="mimic/mbed.Portin.js"></script>
17+<script type="text/javascript" src="mimic/mbed.PwmOut.js"></script>
18+<script type="text/javascript" src="mimic/mbed.SPI.js"></script>
19+<script type="text/javascript" src="mimic/mbed.SPISlave.js"></script>
20+<script type="text/javascript">
21+
22+
23+
24+function log(v)
25+{
26+ if(v===undefined){
27+ document.getElementById("console").value='';
28+ }else{
29+ document.getElementById("console").value+='['+(new Date())+']'+v+'\n';
30+ }
31+}
32+
33+/**ASYNCAPIのテスト*/
34+function async()
35+{
36+ log();
37+ log("ASYNC");
38+ var mcu=new mbedJS.Mcu("ws://192.168.128.39/rpc/",
39+ {
40+ onNew:function(){
41+ var pin=new mbedJS.PwmOut(mcu,mbedJS.PinName.p21,{
42+ onNew:function(){
43+ log("[PASS]onNew");
44+ pin.write(0.33);
45+ },
46+ onWrite:function()
47+ {
48+ log("[PASS]onwrite:");
49+ pin.read();
50+ },
51+ onRead:function(v)
52+ {
53+ log("[PASS]onread:"+v);
54+ pin.period(1.0);
55+ },
56+ onPeriod:function(){
57+ log("[PASS]onPeriod:");
58+ pin.period_ms(1);
59+ },
60+ onPeriod_ms:function(){
61+ log("[PASS]onPeriod_ms:");
62+ pin.period_us(10);
63+ },
64+ onPeriod_us:function(){
65+ log("[PASS]onPeriod_us:");
66+ pin.pulsewidth(3);
67+ },
68+ onPulsewidth:function(){
69+ log("[PASS]onPulseWidth:");
70+ pin.pulsewidth_ms(30);
71+ },
72+ onPulsewidth_ms:function(){
73+ log("[PASS]onPulseWidth_ms:");
74+ pin.pulsewidth_us(40);
75+ },
76+ onPulsewidth_us:function(){
77+ log("[PASS]onPulseWidth_us:");
78+ mcu.close();
79+ }
80+ });
81+ },
82+ onClose:function(){
83+ log("[PASS]onClose");
84+ },
85+ onError:function(){
86+ alert("Error");
87+ }
88+ });
89+}
90+
91+/**
92+ * Sync
93+ */
94+function sync()
95+{
96+ log();
97+ var g=function*(){
98+ try{
99+ var mcu=new mbedJS.Mcu("ws://192.168.128.39/rpc/",g);
100+ yield mcu.waitForNew();
101+ var pin=new mbedJS.PwmOut(mcu,mbedJS.PinName.p21,g);
102+ log("new");
103+ yield pin.waitForNew();
104+ log("waitfor");
105+ yield pin.write(0.33);
106+ log("[PASS]write:");
107+ var v=yield pin.read();
108+ log("[PASS]read:"+v);
109+ yield pin.period(1.0);
110+ log("[PASS]period:");
111+ yield pin.period_ms(1);
112+ log("[PASS]period_ms:");
113+ yield pin.period_us(10);
114+ log("[PASS]period_us:");
115+ yield pin.pulsewidth(3);
116+ log("[PASS]pulseWidth:");
117+ yield pin.pulsewidth_ms(30);
118+ log("[PASS]pulseWidth_ms:");
119+ yield pin.pulsewidth_us(40);
120+ log("[PASS]pulseWidth_us:");
121+ yield mcu.close();
122+ }catch(e){
123+ mcu.shutdown();
124+ alert(e);
125+ throw e;
126+ }
127+ }();
128+ g.next();
129+ return;
130+
131+}
132+
133+
134+
135+</script>
136+</head>
137+<body>
138+<h1>Pwm test</h1>
139+<hr/>
140+<button onclick="async();">ASYNC</button>
141+<button onclick="sync();">SYNC</button>
142+<textarea id="console" rows="15" cols="80"></textarea>
143+</body>
\ No newline at end of file
--- /dev/null
+++ b/misc/MiMicVM/mbed.js/test.SPI.html
@@ -0,0 +1,112 @@
1+
2+<html>
3+<head>
4+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5+<script type="text/javascript" src="mimic/mbed.types.js"></script>
6+<script type="text/javascript" src="mimic/MiMicCore.js"></script>
7+<script type="text/javascript" src="mimic/mbed.Mcu.js"></script>
8+<script type="text/javascript" src="mimic/mbed.DigitalOut.js"></script>
9+<script type="text/javascript" src="mimic/mbed.DigitalIn.js"></script>
10+<script type="text/javascript" src="mimic/mbed.AnalogOut.js"></script>
11+<script type="text/javascript" src="mimic/mbed.AnalogIn.js"></script>
12+<script type="text/javascript" src="mimic/mbed.BusOut.js"></script>
13+<script type="text/javascript" src="mimic/mbed.BusIn.js"></script>
14+<script type="text/javascript" src="mimic/mbed.BusInOut.js"></script>
15+<script type="text/javascript" src="mimic/mbed.PortOut.js"></script>
16+<script type="text/javascript" src="mimic/mbed.Portin.js"></script>
17+<script type="text/javascript" src="mimic/mbed.PwmOut.js"></script>
18+<script type="text/javascript" src="mimic/mbed.SPI.js"></script>
19+<script type="text/javascript" src="mimic/mbed.SPISlave.js"></script>
20+<script type="text/javascript">
21+
22+
23+
24+function log(v)
25+{
26+ if(v===undefined){
27+ document.getElementById("console").value='';
28+ }else{
29+ document.getElementById("console").value+='['+(new Date())+']'+v+'\n';
30+ }
31+}
32+
33+/**ASYNCAPIのテスト*/
34+function async()
35+{
36+ log();
37+ log("ASYNC");
38+ var mcu=new mbedJS.Mcu("ws://192.168.128.39/rpc/",
39+ {
40+ onNew:function(){
41+ var pin=new mbedJS.SPI(mcu,[mbedJS.PinName.p5,mbedJS.PinName.p6,mbedJS.PinName.p7],{
42+ onNew:function(){
43+ log("[PASS]onNew");
44+ pin.frequency(1000000);
45+ },
46+ onFrequency:function()
47+ {
48+ log("[PASS]onFrequency:");
49+ pin.format(8,3);
50+ },
51+ onFormat:function()
52+ {
53+ log("[PASS]onFormat:");
54+ pin.write(39);
55+ },
56+ onWrite:function(v){
57+ log("[PASS]onWrite:"+v);
58+ mcu.close();
59+ }});
60+ },
61+ onClose:function(){
62+ log("[PASS]onClose");
63+ },
64+ onError:function(){
65+ alert("Error");
66+ }
67+ });
68+}
69+
70+/**
71+ * 誤った使用方法でExceptionが出た場合にシャットダウンできるかのテスト
72+ */
73+function sync()
74+{
75+ log();
76+ var g=function*(){
77+ try{
78+ var mcu=new mbedJS.Mcu("ws://192.168.128.39/rpc/",g);
79+ yield mcu.waitForNew();
80+ var pin=new mbedJS.SPI(mcu,[mbedJS.PinName.p5,mbedJS.PinName.p6,mbedJS.PinName.p7],g);
81+ yield pin.waitForNew();
82+ log("[PASS]New");
83+ yield pin.frequency(1000000);
84+ log("[PASS]Frequency:");
85+ yield pin.format(8,3);
86+ log("[PASS]Format:");
87+ v=yield pin.write(39);
88+ log("[PASS]Write:"+v);
89+ yield mcu.close();
90+ log("close");
91+ }catch(e){
92+ mcu.shutdown();
93+ alert(e);
94+ throw e;
95+ }
96+ }();
97+ g.next();
98+ return;
99+
100+}
101+
102+
103+
104+</script>
105+</head>
106+<body>
107+<h1>SPI test</h1>
108+<hr/>
109+<button onclick="async();">ASYNC</button>
110+<button onclick="sync();">SYNC</button>
111+<textarea id="console" rows="15" cols="80"></textarea>
112+</body>
\ No newline at end of file
--- /dev/null
+++ b/misc/MiMicVM/mbed.js/test.SPISlave.html
@@ -0,0 +1,127 @@
1+
2+<html>
3+<head>
4+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5+<script type="text/javascript" src="mimic/mbed.types.js"></script>
6+<script type="text/javascript" src="mimic/MiMicCore.js"></script>
7+<script type="text/javascript" src="mimic/mbed.Mcu.js"></script>
8+<script type="text/javascript" src="mimic/mbed.DigitalOut.js"></script>
9+<script type="text/javascript" src="mimic/mbed.DigitalIn.js"></script>
10+<script type="text/javascript" src="mimic/mbed.AnalogOut.js"></script>
11+<script type="text/javascript" src="mimic/mbed.AnalogIn.js"></script>
12+<script type="text/javascript" src="mimic/mbed.BusOut.js"></script>
13+<script type="text/javascript" src="mimic/mbed.BusIn.js"></script>
14+<script type="text/javascript" src="mimic/mbed.BusInOut.js"></script>
15+<script type="text/javascript" src="mimic/mbed.PortOut.js"></script>
16+<script type="text/javascript" src="mimic/mbed.Portin.js"></script>
17+<script type="text/javascript" src="mimic/mbed.PwmOut.js"></script>
18+<script type="text/javascript" src="mimic/mbed.SPI.js"></script>
19+<script type="text/javascript" src="mimic/mbed.SPISlave.js"></script>
20+<script type="text/javascript">
21+
22+
23+
24+function log(v)
25+{
26+ if(v===undefined){
27+ document.getElementById("console").value='';
28+ }else{
29+ document.getElementById("console").value+='['+(new Date())+']'+v+'\n';
30+ }
31+}
32+
33+/**ASYNCAPIのテスト*/
34+function async()
35+{
36+ log();
37+ log("ASYNC");
38+ var mcu=new mbedJS.Mcu("ws://192.168.128.39/rpc/",
39+ {
40+ onNew:function(){
41+ var pin=new mbedJS.SPISlave(mcu,[mbedJS.PinName.p5,mbedJS.PinName.p6,mbedJS.PinName.p7,mbedJS.PinName.p8],{
42+ onNew:function(){
43+ log("[PASS]onNew");
44+ pin.frequency(1000000);
45+ },
46+ onFrequency:function()
47+ {
48+ log("[PASS]onFrequency:");
49+ pin.format(8,3);
50+ },
51+ onFormat:function()
52+ {
53+ log("[PASS]onFormat:");
54+ pin.read();
55+ },
56+ onRead:function(v){
57+ log("[PASS]onread:"+v);
58+ pin.receive();
59+ },
60+ onReceive:function(v)
61+ {
62+ log("[PASS]onReceive:"+v);
63+ pin.reply(1);
64+ },
65+ onReply:function(){
66+ log("[PASS]onReply:");
67+ mcu.close();
68+ }
69+
70+ });
71+ },
72+ onClose:function(){
73+ log("[PASS]onClose");
74+ },
75+ onError:function(){
76+ alert("Error");
77+ }
78+ });
79+}
80+
81+/**
82+ *
83+ */
84+function sync()
85+{
86+ log();
87+ var g=function*(){
88+ try{
89+ var mcu=new mbedJS.Mcu("ws://192.168.128.39/rpc/",g);
90+ yield mcu.waitForNew();
91+ var pin=new mbedJS.SPISlave(mcu,[mbedJS.PinName.p5,mbedJS.PinName.p6,mbedJS.PinName.p7,mbedJS.PinName.p8],g);
92+ yield pin.waitForNew();
93+ log("[PASS]New");
94+ yield pin.frequency(1000000);
95+ log("[PASS]Frequency:");
96+ yield pin.format(8,3);
97+ log("[PASS]Format:");
98+ var v=yield pin.read();
99+ log("[PASS]Read:"+v);
100+ v=yield pin.receive();
101+ log("[PASS]Receive:"+v);
102+ yield pin.reply(1);
103+ log("[PASS]Reply:");
104+ yield mcu.close();
105+ log("close");
106+ }catch(e){
107+ mcu.shutdown();
108+ alert(e);
109+ throw e;
110+ }
111+ }();
112+ g.next();
113+ return;
114+
115+}
116+
117+
118+
119+</script>
120+</head>
121+<body>
122+<h1>SPISlave test</h1>
123+<hr/>
124+<button onclick="async();">ASYNC</button>
125+<button onclick="sync();">SYNC</button>
126+<textarea id="console" rows="15" cols="80"></textarea>
127+</body>
\ No newline at end of file
Show on old repository browser