修订版 | 2ec17656b62ce9c5a512adce536daa3410697245 (tree) |
---|---|
时间 | 2014-06-22 01:13:09 |
作者 | nyatla <nyatla@4719...> |
Commiter | nyatla |
mbed.jsの更新
git-svn-id: http://svn.osdn.jp/svnroot/mimic/trunk@364 47198e57-cb75-475f-84c4-a814cd6f29e0
@@ -15,6 +15,60 @@ var MiMicJS={}; | ||
15 | 15 | */ |
16 | 16 | NS.VERSION="MiMicJsAPI/2.0.0"; |
17 | 17 | /** |
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 | + /** | |
18 | 72 | * @private |
19 | 73 | * オブジェクトがジェネレータクラスであるかを返します。 |
20 | 74 | */ |
@@ -38,6 +92,13 @@ var MiMicJS={}; | ||
38 | 92 | return a instanceof Array; |
39 | 93 | }; |
40 | 94 | /** |
95 | + * @private | |
96 | + * aが配列であるかを返します。 | |
97 | + */ | |
98 | + NS.isHashArray=function isHashArray(a){ | |
99 | + return (!(a instanceof Array)) && (typeof a == "object"); | |
100 | + }; | |
101 | + /** | |
41 | 102 | * 連想配列をシャローコピーして複製します。 |
42 | 103 | * @private |
43 | 104 | */ |
@@ -38,21 +38,26 @@ var MI=MiMicJS; | ||
38 | 38 | * @return {mbedJS.AnalogIn} |
39 | 39 | * @example |
40 | 40 | */ |
41 | -var CLASS=function DigitalIn(i_mcu,i_params,i_handler) | |
41 | +var CLASS=function AnalogIn(i_mcu,i_params,i_handler) | |
42 | 42 | { |
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 | + } | |
56 | 61 | } |
57 | 62 | CLASS.prototype= |
58 | 63 | { |
@@ -72,9 +77,14 @@ CLASS.prototype= | ||
72 | 77 | * Generatorモードのときに使用する関数です。 |
73 | 78 | * Generatorモードの時は、yieldと併用してnew AnalogIn()の完了を待ちます。 |
74 | 79 | */ |
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 | + } | |
78 | 88 | }, |
79 | 89 | /** |
80 | 90 | * @name mbedJS.AnalogIn#read |
@@ -88,43 +98,51 @@ CLASS.prototype= | ||
88 | 98 | */ |
89 | 99 | read:function AnalogIn_read() |
90 | 100 | { |
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 | + } | |
103 | 117 | }, |
104 | 118 | /** |
105 | 119 | * @name mbedJS.AnalogIn#read_u16 |
106 | 120 | * @function |
107 | 121 | * ピンから値を読み込みます。 |
108 | - * 関数の完了時にonReadイベントが発生します。 | |
122 | + * 関数の完了時にonRead_u16イベントが発生します。 | |
109 | 123 | * Generatorモードの時は、yieldと併用して完了を待機できます。 |
110 | 124 | * @return {int|int} |
111 | 125 | * <p>Callbackモードの時はRPCメソッドのインデクスを返します。</p> |
112 | 126 | * <p>Generatorモードの時はピンの値を返します。</p> |
113 | 127 | */ |
114 | - read_u16:function AnalogIn_read_u16(i_value) | |
128 | + read_u16:function AnalogIn_read_u16() | |
115 | 129 | { |
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 | + } | |
128 | 146 | } |
129 | 147 | } |
130 | 148 | NS.AnalogIn=CLASS; |
@@ -40,19 +40,23 @@ var MI=MiMicJS; | ||
40 | 40 | */ |
41 | 41 | var CLASS=function AnalogOut(i_mcu,i_params,i_handler) |
42 | 42 | { |
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); | |
56 | 60 | } |
57 | 61 | } |
58 | 62 | CLASS.prototype= |
@@ -73,9 +77,14 @@ CLASS.prototype= | ||
73 | 77 | * Generatorモードのときに使用する関数です。 |
74 | 78 | * Generatorモードの時は、yieldと併用してnew AnalogOut()の完了を待ちます。 |
75 | 79 | */ |
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 | + } | |
79 | 88 | }, |
80 | 89 | /** |
81 | 90 | * @name mbedJS.AnalogOut#write |
@@ -84,22 +93,27 @@ CLASS.prototype= | ||
84 | 93 | * 関数の完了時にonWriteイベントが発生します。 |
85 | 94 | * Generatorモードの時は、yieldと併用して完了を待機できます。 |
86 | 95 | * @param {float} i_value |
87 | - * [0,1]の値を指定します。 | |
96 | + * [0,1]の範囲で値を指定します。 | |
88 | 97 | * @return {int|none} |
89 | 98 | * <p>Callbackモードの時はRPCメソッドのインデクスを返します。</p> |
90 | 99 | * <p>Generatorモードの時は戻り値はありません。</p> |
91 | 100 | */ |
92 | 101 | write:function AnalogOut_write(i_value) |
93 | 102 | { |
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 | + } | |
103 | 117 | }, |
104 | 118 | /** |
105 | 119 | * @name mbedJS.AnalogOut#write_u16 |
@@ -115,15 +129,20 @@ CLASS.prototype= | ||
115 | 129 | */ |
116 | 130 | write_u16:function AnalogOut_write_u16(i_value) |
117 | 131 | { |
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 | + } | |
127 | 146 | }, |
128 | 147 | /** |
129 | 148 | * @name mbedJS.AnalogOut#read |
@@ -137,18 +156,22 @@ CLASS.prototype= | ||
137 | 156 | */ |
138 | 157 | read:function AnalogOut_read() |
139 | 158 | { |
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); | |
150 | 174 | } |
151 | - ); | |
152 | 175 | } |
153 | 176 | } |
154 | 177 | NS.AnalogOut=CLASS; |
@@ -37,32 +37,38 @@ var MI=MiMicJS; | ||
37 | 37 | */ |
38 | 38 | var CLASS=function BusIn(i_mcu,i_params,i_handler) |
39 | 39 | { |
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); | |
64 | 71 | } |
65 | - return _t._mcu.rpc(_t.RPC_NS+":_new1",pins,cb); | |
66 | 72 | } |
67 | 73 | CLASS.prototype= |
68 | 74 | { |
@@ -82,9 +88,14 @@ CLASS.prototype= | ||
82 | 88 | * Generatorモードのときに使用する関数です。 |
83 | 89 | * Generatorモードの時は、yieldと併用してnew BusIn()の完了を待ちます。 |
84 | 90 | */ |
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 | + } | |
88 | 99 | }, |
89 | 100 | /** |
90 | 101 | * @name mbedJS.BusIn#read |
@@ -98,18 +109,22 @@ CLASS.prototype= | ||
98 | 109 | */ |
99 | 110 | read:function BusIn_read() |
100 | 111 | { |
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); | |
111 | 127 | } |
112 | - ); | |
113 | 128 | }, |
114 | 129 | /** |
115 | 130 | * @name mbedJS.BusIn#mode |
@@ -124,18 +139,23 @@ CLASS.prototype= | ||
124 | 139 | */ |
125 | 140 | mode:function BusIn_mode(i_value) |
126 | 141 | { |
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 | + } | |
139 | 159 | } |
140 | 160 | } |
141 | 161 | NS.BusIn=CLASS; |
@@ -4,7 +4,7 @@ var MI=MiMicJS; | ||
4 | 4 | |
5 | 5 | /** |
6 | 6 | * @name mbedJS.BusInOut |
7 | - * BusOutクラスです。 | |
7 | + * BusInOutクラスです。 | |
8 | 8 | * <a href="https://mbed.org/handbook/BusInOut">mbed::BusInOut</a>と同等の機能を持ちます。 |
9 | 9 | * @constructor |
10 | 10 | * @param {mbedJS.Mcu} i_mcu |
@@ -47,32 +47,38 @@ var MI=MiMicJS; | ||
47 | 47 | */ |
48 | 48 | var CLASS=function BusInOut(i_mcu,i_params,i_handler) |
49 | 49 | { |
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); | |
74 | 81 | } |
75 | - return _t._mcu.rpc(_t.RPC_NS+":_new1",pins,cb); | |
76 | 82 | } |
77 | 83 | CLASS.prototype= |
78 | 84 | { |
@@ -92,9 +98,14 @@ CLASS.prototype= | ||
92 | 98 | * Generatorモードのときに使用する関数です。 |
93 | 99 | * Generatorモードの時は、yieldと併用してnew BusInOut()の完了を待ちます。 |
94 | 100 | */ |
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 | + } | |
98 | 109 | }, |
99 | 110 | /** |
100 | 111 | * @name mbedJS.BusInOut#write |
@@ -109,15 +120,20 @@ CLASS.prototype= | ||
109 | 120 | */ |
110 | 121 | write:function BusInOut_write(i_value) |
111 | 122 | { |
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 | + } | |
121 | 137 | }, |
122 | 138 | /** |
123 | 139 | * @name mbedJS.BusInOut#read |
@@ -131,18 +147,22 @@ CLASS.prototype= | ||
131 | 147 | */ |
132 | 148 | read:function BusInOut_read() |
133 | 149 | { |
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); | |
144 | 165 | } |
145 | - ); | |
146 | 166 | }, |
147 | 167 | /** |
148 | 168 | * @name mbedJS.BusInOut#mode |
@@ -157,18 +177,22 @@ CLASS.prototype= | ||
157 | 177 | */ |
158 | 178 | mode:function BusInOut_mode(i_value) |
159 | 179 | { |
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); | |
170 | 195 | } |
171 | - ); | |
172 | 196 | }, |
173 | 197 | /** |
174 | 198 | * @name mbedJS.BusInOut#input |
@@ -181,17 +205,20 @@ CLASS.prototype= | ||
181 | 205 | */ |
182 | 206 | input:function BusInOut_input() |
183 | 207 | { |
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); | |
193 | 221 | } |
194 | - ); | |
195 | 222 | }, |
196 | 223 | /** |
197 | 224 | * @name mbedJS.BusInOut#output |
@@ -204,20 +231,21 @@ CLASS.prototype= | ||
204 | 231 | */ |
205 | 232 | output:function BusInOut_output() |
206 | 233 | { |
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); | |
216 | 247 | } |
217 | - ); | |
218 | 248 | } |
219 | 249 | } |
220 | -NS.BusInOut=CLASS; | |
221 | -} | |
222 | 250 | NS.BusInOut=CLASS; |
223 | 251 | }()); |
\ No newline at end of file |
@@ -3,7 +3,7 @@ var NS=mbedJS; | ||
3 | 3 | var MI=MiMicJS; |
4 | 4 | |
5 | 5 | /** |
6 | - * @name mbedJS.BusIn | |
6 | + * @name mbedJS.BusOut | |
7 | 7 | * BusOutクラスです。 |
8 | 8 | * <a href="https://mbed.org/handbook/BusOut">mbed::BusOut</a>と同等の機能を持ちます。 |
9 | 9 | * @constructor |
@@ -32,37 +32,44 @@ var MI=MiMicJS; | ||
32 | 32 | * <p> |
33 | 33 | * Generatorを指定した場合、コールバック関数の引数はyiledの戻り値として取得できます。 |
34 | 34 | * <p> |
35 | - * @return {mbedJS.BusIn} | |
35 | + * @return {mbedJS.BusOut} | |
36 | 36 | * @example |
37 | 37 | */ |
38 | 38 | var CLASS=function BusOut(i_mcu,i_params,i_handler) |
39 | 39 | { |
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); | |
64 | 71 | } |
65 | - return _t._mcu.rpc(_t.RPC_NS+":_new1",pins,cb); | |
72 | + | |
66 | 73 | } |
67 | 74 | CLASS.prototype= |
68 | 75 | { |
@@ -82,9 +89,14 @@ CLASS.prototype= | ||
82 | 89 | * Generatorモードのときに使用する関数です。 |
83 | 90 | * Generatorモードの時は、yieldと併用してnew BusOut()の完了を待ちます。 |
84 | 91 | */ |
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 | + } | |
88 | 100 | }, |
89 | 101 | /** |
90 | 102 | * @name mbedJS.BusOut#write |
@@ -99,15 +111,20 @@ CLASS.prototype= | ||
99 | 111 | */ |
100 | 112 | write:function BusOut_write(i_value) |
101 | 113 | { |
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 | + } | |
111 | 128 | }, |
112 | 129 | /** |
113 | 130 | * @name mbedJS.BusOut#read |
@@ -121,18 +138,21 @@ CLASS.prototype= | ||
121 | 138 | */ |
122 | 139 | read:function BusOut_read() |
123 | 140 | { |
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); | |
134 | 155 | } |
135 | - ); | |
136 | 156 | } |
137 | 157 | } |
138 | 158 | NS.BusOut=CLASS; |
@@ -37,19 +37,24 @@ var MI=MiMicJS; | ||
37 | 37 | */ |
38 | 38 | var CLASS=function DigitalIn(i_mcu,i_params,i_handler) |
39 | 39 | { |
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); | |
51 | 57 | } |
52 | - return _t._mcu.rpc(_t.RPC_NS+":_new1",i_params,cb); | |
53 | 58 | } |
54 | 59 | CLASS.prototype= |
55 | 60 | { |
@@ -69,14 +74,19 @@ CLASS.prototype= | ||
69 | 74 | * Generatorモードのときに使用する関数です。 |
70 | 75 | * Generatorモードの時は、yieldと併用してnew DigitalIn()の完了を待ちます。 |
71 | 76 | */ |
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 | + } | |
75 | 85 | }, |
76 | 86 | /** |
77 | 87 | * @name mbedJS.DigitalIn#read |
78 | 88 | * @function |
79 | - * ピンから値を読み込みます。 | |
89 | + * ピンからアナログ値を読み込みます。 | |
80 | 90 | * 関数の完了時にonReadイベントが発生します。 |
81 | 91 | * Generatorモードの時は、yieldと併用して完了を待機できます。 |
82 | 92 | * @return {int|int} |
@@ -85,18 +95,22 @@ CLASS.prototype= | ||
85 | 95 | */ |
86 | 96 | read:function DigitalIn_read() |
87 | 97 | { |
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); | |
98 | 113 | } |
99 | - ); | |
100 | 114 | }, |
101 | 115 | /** |
102 | 116 | * @name mbedJS.DigitalIn#mode |
@@ -111,18 +125,23 @@ CLASS.prototype= | ||
111 | 125 | */ |
112 | 126 | mode:function DigitalIn_mode(i_value) |
113 | 127 | { |
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); | |
124 | 144 | } |
125 | - ); | |
126 | 145 | } |
127 | 146 | } |
128 | 147 | NS.DigitalIn=CLASS; |
@@ -9,8 +9,8 @@ var MI=MiMicJS; | ||
9 | 9 | * @constructor |
10 | 10 | * @param {mbedJS.Mcu} i_mcu |
11 | 11 | * インスタンスをバインドするMCUオブジェクトです。 |
12 | - * @param {PinName|HashMap} i_params | |
13 | - * PinName又はコンストラクタの引数を格納した連想配列です。 | |
12 | + * @param {PinName|HashMap|Array} i_params | |
13 | + * PinName又はコンストラクタの引数を格納した連想配列、配列です。 | |
14 | 14 | * 複数のパラメータを指定する場合は連想配列を使用してください。 |
15 | 15 | * <p>PinNameの場合は制御するPinIDを指定します。</p> |
16 | 16 | * <p> |
@@ -22,10 +22,14 @@ var MI=MiMicJS; | ||
22 | 22 | * ピンの初期値を指定します。</li> |
23 | 23 | * </ul> |
24 | 24 | * </p> |
25 | + * <p>配列の場合は次の順番でパラメータを指定します。 | |
26 | + * <pre>{pin,value}</pre> | |
27 | + * </p> | |
25 | 28 | * @param {HashMap|Generator} i_event |
26 | 29 | * 非同期イベントハンドラの連想配列、又はGeneratorです。 |
27 | 30 | * <p> |
28 | 31 | * 非同期イベントハンドラの場合、関数はイベントハンドラで結果を通知します。 |
32 | + * | |
29 | 33 | * <ul> |
30 | 34 | * <li>{function()} onNew - |
31 | 35 | * インスタンスが使用可能になった時に呼び出されます。 |
@@ -48,22 +52,37 @@ var MI=MiMicJS; | ||
48 | 52 | */ |
49 | 53 | var CLASS=function DigitalOut(i_mcu,i_params,i_handler) |
50 | 54 | { |
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); | |
67 | 86 | } |
68 | 87 | } |
69 | 88 | CLASS.prototype= |
@@ -84,9 +103,14 @@ CLASS.prototype= | ||
84 | 103 | * Generatorモードのときに使用する関数です。 |
85 | 104 | * Generatorモードの時は、yieldと併用してnew DigitalOut()の完了を待ちます。 |
86 | 105 | */ |
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 | + } | |
90 | 114 | }, |
91 | 115 | /** |
92 | 116 | * @name mbedJS.DigitalOut#write |
@@ -101,15 +125,20 @@ CLASS.prototype= | ||
101 | 125 | */ |
102 | 126 | write:function DigitalOut_write(i_value) |
103 | 127 | { |
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 | + } | |
113 | 142 | }, |
114 | 143 | /** |
115 | 144 | * @name mbedJS.DigitalOut#read |
@@ -123,18 +152,22 @@ CLASS.prototype= | ||
123 | 152 | */ |
124 | 153 | read:function DigitalOut_read() |
125 | 154 | { |
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); | |
136 | 170 | } |
137 | - ); | |
138 | 171 | } |
139 | 172 | } |
140 | 173 | NS.DigitalOut=CLASS; |
@@ -9,14 +9,19 @@ var MI=MiMicJS; | ||
9 | 9 | * @constructor |
10 | 10 | * @param {mbedJS.Mcu} i_mcu |
11 | 11 | * インスタンスをバインドするMCUオブジェクトです。 |
12 | - * @param {HashMap} i_params | |
13 | - * パラメータを格納したHashMapを設定します。 | |
12 | + * @param {HashMap|Array} i_params | |
13 | + * <p> | |
14 | + * HashNapの場合は以下のメンバを指定できます。 | |
14 | 15 | * <ul> |
15 | 16 | * <li>{PortName} port - |
16 | 17 | * ポート名を指定します。</li> |
17 | 18 | * <li>{uint32} mask - |
18 | 19 | * ポートマスクを指定します。</li> |
19 | 20 | * </ul> |
21 | + * </p> | |
22 | + * <p>配列の場合は次の順番でパラメータを指定します。 | |
23 | + * <pre>{port,mask}</pre> | |
24 | + * </p> | |
20 | 25 | * @param {HashMap|Generator} i_event |
21 | 26 | * 非同期イベントハンドラの連想配列、又はGeneratorです。 |
22 | 27 | * <p> |
@@ -40,19 +45,31 @@ var MI=MiMicJS; | ||
40 | 45 | */ |
41 | 46 | var CLASS=function PortIn(i_mcu,i_params,i_handler) |
42 | 47 | { |
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 | + } | |
56 | 73 | } |
57 | 74 | CLASS.prototype= |
58 | 75 | { |
@@ -72,9 +89,14 @@ CLASS.prototype= | ||
72 | 89 | * Generatorモードのときに使用する関数です。 |
73 | 90 | * Generatorモードの時は、yieldと併用してnew PortIn()の完了を待ちます。 |
74 | 91 | */ |
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 | + } | |
78 | 100 | }, |
79 | 101 | /** |
80 | 102 | * @name mbedJS.PortIn#read |
@@ -82,24 +104,27 @@ CLASS.prototype= | ||
82 | 104 | * ピンから値を読み込みます。 |
83 | 105 | * 関数の完了時にonReadイベントが発生します。 |
84 | 106 | * Generatorモードの時は、yieldと併用して完了を待機できます。 |
85 | - * @return {int|float} | |
107 | + * @return {int|int} | |
86 | 108 | * <p>Callbackモードの時はRPCメソッドのインデクスを返します。</p> |
87 | 109 | * <p>Generatorモードの時はポートの値を返します。</p> |
88 | 110 | */ |
89 | 111 | read:function PortIn_read() |
90 | 112 | { |
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 | + } | |
103 | 128 | } |
104 | 129 | } |
105 | 130 | NS.PortIn=CLASS; |
@@ -9,14 +9,19 @@ var MI=MiMicJS; | ||
9 | 9 | * @constructor |
10 | 10 | * @param {mbedJS.Mcu} i_mcu |
11 | 11 | * インスタンスをバインドするMCUオブジェクトです。 |
12 | - * @param {HashMap} i_params | |
13 | - * パラメータを格納したHashMapを設定します。 | |
12 | + * @param {HashMap|Array} i_params | |
13 | + * <p> | |
14 | + * HashNapの場合は以下のメンバを指定できます。 | |
14 | 15 | * <ul> |
15 | 16 | * <li>{PortName} port - |
16 | 17 | * ポート名を指定します。</li> |
17 | 18 | * <li>{uint32} mask - |
18 | 19 | * ポートマスクを指定します。</li> |
19 | 20 | * </ul> |
21 | + * </p> | |
22 | + * <p>配列の場合は次の順番でパラメータを指定します。 | |
23 | + * <pre>{port,mask}</pre> | |
24 | + * </p> | |
20 | 25 | * @param {HashMap|Generator} i_event |
21 | 26 | * 非同期イベントハンドラの連想配列、又はGeneratorです。 |
22 | 27 | * <p> |
@@ -43,19 +48,31 @@ var MI=MiMicJS; | ||
43 | 48 | */ |
44 | 49 | var CLASS=function PortOut(i_mcu,i_params,i_handler) |
45 | 50 | { |
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); | |
57 | 75 | } |
58 | - return _t._mcu.rpc(_t.RPC_NS+":_new2",i_params.port+","+i_params.mask,cb); | |
59 | 76 | } |
60 | 77 | CLASS.prototype= |
61 | 78 | { |
@@ -75,14 +92,19 @@ CLASS.prototype= | ||
75 | 92 | * Generatorモードのときに使用する関数です。 |
76 | 93 | * Generatorモードの時は、yieldと併用してnew PortOut()の完了を待ちます。 |
77 | 94 | */ |
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 | + }, | |
82 | 104 | /** |
83 | 105 | * @name mbedJS.PortOut#write |
84 | 106 | * @function |
85 | - * ピンに値を出力します。 | |
107 | + * ポートへ値を出力します。 | |
86 | 108 | * 関数の完了時にonWriteイベントが発生します。 |
87 | 109 | * Generatorモードの時は、yieldと併用して完了を待機できます。 |
88 | 110 | * @param {int} i_value |
@@ -92,20 +114,25 @@ CLASS.prototype= | ||
92 | 114 | */ |
93 | 115 | write:function PortOut_write(i_value) |
94 | 116 | { |
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 | + } | |
104 | 131 | }, |
105 | 132 | /** |
106 | 133 | * @name mbedJS.PortOut#write |
107 | 134 | * @function |
108 | - * ピンから値を読み込みます。 | |
135 | + * ポートから値を読み込みます。 | |
109 | 136 | * 関数の完了時にonReadイベントが発生します。 |
110 | 137 | * Generatorモードの時は、yieldと併用して完了を待機できます。 |
111 | 138 | * @return {int|int} |
@@ -114,19 +141,22 @@ CLASS.prototype= | ||
114 | 141 | */ |
115 | 142 | read:function PortOut_read() |
116 | 143 | { |
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); | |
127 | 158 | } |
128 | - ); | |
129 | 159 | } |
130 | 160 | } |
131 | -NS.DigitalOut=CLASS; | |
161 | +NS.PortOut=CLASS; | |
132 | 162 | }()); |
\ No newline at end of file |
@@ -5,7 +5,7 @@ var MI=MiMicJS; | ||
5 | 5 | /** |
6 | 6 | * @name mbedJS.PwmOut |
7 | 7 | * PwmOutクラスです。 |
8 | - * <a href="https://mbed.org/handbook/AnalogOut">mbed::PwmOut</a>と同等の機能を持ちます。 | |
8 | + * <a href="https://mbed.org/handbook/PwmOut">mbed::PwmOut</a>と同等の機能を持ちます。 | |
9 | 9 | * @constructor |
10 | 10 | * @param {mbedJS.Mcu} i_mcu |
11 | 11 | * インスタンスをバインドするMCUオブジェクトです。 |
@@ -55,19 +55,23 @@ var MI=MiMicJS; | ||
55 | 55 | */ |
56 | 56 | var CLASS=function PwmOut(i_mcu,i_params,i_handler) |
57 | 57 | { |
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); | |
71 | 75 | } |
72 | 76 | } |
73 | 77 | CLASS.prototype= |
@@ -88,17 +92,22 @@ CLASS.prototype= | ||
88 | 92 | * Generatorモードのときに使用する関数です。 |
89 | 93 | * Generatorモードの時は、yieldと併用してnew PwmOut()の完了を待ちます。 |
90 | 94 | */ |
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 | + }, | |
95 | 104 | /** |
96 | 105 | * @name mbedJS.PwmOut#write |
97 | 106 | * @function |
98 | 107 | * ピンに値を出力します。 |
99 | 108 | * 関数の完了時にonWriteイベントが発生します。 |
100 | 109 | * Generatorモードの時は、yieldと併用して完了を待機できます。 |
101 | - * @param {int} i_value | |
110 | + * @param {float} i_value | |
102 | 111 | * [0,1]の値を指定します。 |
103 | 112 | * @return {int|none} |
104 | 113 | * <p>Callbackモードの時はRPCメソッドのインデクスを返します。</p> |
@@ -106,15 +115,20 @@ CLASS.prototype= | ||
106 | 115 | */ |
107 | 116 | write:function PwmOut_write(i_value) |
108 | 117 | { |
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 | + } | |
118 | 132 | }, |
119 | 133 | /** |
120 | 134 | * @name mbedJS.PwmOut#read |
@@ -128,18 +142,21 @@ CLASS.prototype= | ||
128 | 142 | */ |
129 | 143 | read:function PwmOut_read() |
130 | 144 | { |
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 | + } | |
143 | 160 | }, |
144 | 161 | /** |
145 | 162 | * @name mbedJS.PwmOut#period |
@@ -155,15 +172,20 @@ CLASS.prototype= | ||
155 | 172 | */ |
156 | 173 | period:function PwmOut_period(i_value) |
157 | 174 | { |
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 | + } | |
167 | 189 | }, |
168 | 190 | /** |
169 | 191 | * @name mbedJS.PwmOut#period_ms |
@@ -179,15 +201,20 @@ CLASS.prototype= | ||
179 | 201 | */ |
180 | 202 | period_ms:function PwmOut_period_ms(i_value) |
181 | 203 | { |
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 | + } | |
191 | 218 | }, |
192 | 219 | /** |
193 | 220 | * @name mbedJS.PwmOut#period_us |
@@ -201,17 +228,22 @@ CLASS.prototype= | ||
201 | 228 | * <p>Callbackモードの時はRPCメソッドのインデクスを返します。</p> |
202 | 229 | * <p>Generatorモードの時は戻り値はありません。</p> |
203 | 230 | */ |
204 | - period_ns:function PwmOut_period_us(i_value) | |
231 | + period_us:function PwmOut_period_us(i_value) | |
205 | 232 | { |
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 | + } | |
215 | 247 | }, |
216 | 248 | /** |
217 | 249 | * @name mbedJS.PwmOut#pulsewidth |
@@ -227,15 +259,20 @@ CLASS.prototype= | ||
227 | 259 | */ |
228 | 260 | pulsewidth:function PwmOut_pulsewidth(i_value) |
229 | 261 | { |
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 | + } | |
239 | 276 | }, |
240 | 277 | /** |
241 | 278 | * @name mbedJS.PwmOut#pulsewidth_ms |
@@ -251,15 +288,20 @@ CLASS.prototype= | ||
251 | 288 | */ |
252 | 289 | pulsewidth_ms:function PwmOut_pulsewidth_ms(i_value) |
253 | 290 | { |
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 | + } | |
263 | 305 | }, |
264 | 306 | /** |
265 | 307 | * @name mbedJS.PwmOut#pulsewidth_us |
@@ -275,15 +317,20 @@ CLASS.prototype= | ||
275 | 317 | */ |
276 | 318 | pulsewidth_us:function PwmOut_pulsewidth_us(i_value) |
277 | 319 | { |
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 | + } | |
287 | 334 | } |
288 | 335 | } |
289 | 336 | NS.PwmOut=CLASS; |
@@ -40,19 +40,25 @@ var MI=MiMicJS; | ||
40 | 40 | */ |
41 | 41 | var CLASS=function SPI(i_mcu,i_params,i_handler) |
42 | 42 | { |
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); | |
54 | 60 | } |
55 | - return _t._mcu.rpc(_t.RPC_NS+":_new1",i_params[0]+","+i_params[1]+","+i_params[2]+","+NS.PinName.NC,cb); | |
61 | + | |
56 | 62 | } |
57 | 63 | CLASS.prototype= |
58 | 64 | { |
@@ -72,9 +78,14 @@ CLASS.prototype= | ||
72 | 78 | * Generatorモードのときに使用する関数です。 |
73 | 79 | * Generatorモードの時は、yieldと併用してnew SPI()の完了を待ちます。 |
74 | 80 | */ |
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 | + } | |
78 | 89 | }, |
79 | 90 | /** |
80 | 91 | * @name mbedJS.SPI#write |
@@ -89,16 +100,21 @@ CLASS.prototype= | ||
89 | 100 | */ |
90 | 101 | write:function SPI_write(i_value) |
91 | 102 | { |
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 | + } | |
102 | 118 | }, |
103 | 119 | /** |
104 | 120 | * @name mbedJS.SPI#frequency |
@@ -114,15 +130,20 @@ CLASS.prototype= | ||
114 | 130 | */ |
115 | 131 | frequency:function SPI_frequency(i_value) |
116 | 132 | { |
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 | + } | |
126 | 147 | }, |
127 | 148 | /** |
128 | 149 | * @name mbedJS.SPI#format |
@@ -139,16 +160,21 @@ CLASS.prototype= | ||
139 | 160 | */ |
140 | 161 | format:function SPI_format(i_bits,i_mode) |
141 | 162 | { |
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 | + } | |
152 | 178 | } |
153 | 179 | } |
154 | 180 | NS.SPI=CLASS; |
@@ -27,10 +27,10 @@ var MI=MiMicJS; | ||
27 | 27 | * format関数のコールバック関数です。 |
28 | 28 | * </li> |
29 | 29 | * <li>{function(v)} onReceive - |
30 | - * format関数のコールバック関数です。 | |
30 | + * receive関数のコールバック関数です。 | |
31 | 31 | * </li> |
32 | 32 | * <li>{function(v)} onRead - |
33 | - * format関数のコールバック関数です。 | |
33 | + * read関数のコールバック関数です。 | |
34 | 34 | * <ul> |
35 | 35 | * <li>{int} v - 受信した8BIT値です。</li> |
36 | 36 | * </ul> |
@@ -47,19 +47,24 @@ var MI=MiMicJS; | ||
47 | 47 | */ |
48 | 48 | var CLASS=function SPISlave(i_mcu,i_params,i_handler) |
49 | 49 | { |
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 | + } | |
63 | 68 | } |
64 | 69 | CLASS.prototype= |
65 | 70 | { |
@@ -79,9 +84,14 @@ CLASS.prototype= | ||
79 | 84 | * Generatorモードのときに使用する関数です。 |
80 | 85 | * Generatorモードの時は、yieldと併用してnew SPISlave()の完了を待ちます。 |
81 | 86 | */ |
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 | + } | |
85 | 95 | }, |
86 | 96 | |
87 | 97 | /** |
@@ -98,15 +108,20 @@ CLASS.prototype= | ||
98 | 108 | */ |
99 | 109 | frequency:function SPISlave_frequency(i_value) |
100 | 110 | { |
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 | + } | |
110 | 125 | }, |
111 | 126 | /** |
112 | 127 | * @name mbedJS.SPISlave#format |
@@ -123,16 +138,21 @@ CLASS.prototype= | ||
123 | 138 | */ |
124 | 139 | format:function SPISlave_format(i_bits,i_mode) |
125 | 140 | { |
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 | + } | |
136 | 156 | }, |
137 | 157 | /** |
138 | 158 | * @name mbedJS.SPISlave#read |
@@ -146,18 +166,21 @@ CLASS.prototype= | ||
146 | 166 | */ |
147 | 167 | read:function SPISlave_read() |
148 | 168 | { |
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 | + } | |
161 | 184 | }, |
162 | 185 | /** |
163 | 186 | * @name mbedJS.SPISlave#receive |
@@ -171,43 +194,50 @@ CLASS.prototype= | ||
171 | 194 | */ |
172 | 195 | receive:function SPISlave_receive() |
173 | 196 | { |
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 | + } | |
186 | 212 | }, |
187 | 213 | /** |
188 | 214 | * @name mbedJS.SPISlave#reply |
189 | 215 | * @function |
190 | 216 | * ピンモードを設定します。 |
191 | - * 関数の完了時にonModeイベントが発生します。 | |
217 | + * 関数の完了時にonReplyイベントが発生します。 | |
192 | 218 | * Generatorモードの時は、yieldと併用して完了を待機できます。 |
193 | - * @param {PinMode} i_value | |
219 | + * @param {int} i_value | |
194 | 220 | * 次に送る8bitの値です。 |
195 | 221 | * @return {int|none} |
196 | 222 | * <p>Callbackモードの時はRPCメソッドのインデクスを返します。</p> |
197 | 223 | */ |
198 | 224 | reply:function SPISlave_reply(i_value) |
199 | 225 | { |
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 | + } | |
211 | 241 | } |
212 | 242 | } |
213 | 243 | NS.SPISlave=CLASS; |
@@ -16,7 +16,7 @@ NS.PinName=function(){ | ||
16 | 16 | } |
17 | 17 | } |
18 | 18 | // mbed DIP Pin Names p5 - p40 |
19 | - B=0x00010000; | |
19 | + B=0x00020000; | |
20 | 20 | for(var i=5;i<=40;i++){ |
21 | 21 | D['p'+i]=B+i; |
22 | 22 | } |
@@ -49,7 +49,28 @@ NS.PinName=function(){ | ||
49 | 49 | // メンバの追加 |
50 | 50 | return D; |
51 | 51 | }(); |
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}; | |
53 | 74 | |
54 | 75 | |
55 | 76 | }()); |
\ No newline at end of file |
@@ -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 |
@@ -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 |
@@ -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 |
@@ -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 |
@@ -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 |
@@ -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 |
@@ -27,7 +27,7 @@ function async() | ||
27 | 27 | var mcu=new mbedJS.Mcu("ws://192.168.128.39/rpc/", |
28 | 28 | { |
29 | 29 | 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,{ | |
31 | 31 | onNew:function(){ |
32 | 32 | log("[PASS]onNew"); |
33 | 33 | pin.read(); |
@@ -60,7 +60,8 @@ function sync() | ||
60 | 60 | try{ |
61 | 61 | var mcu=new mbedJS.Mcu("ws://192.168.128.39/rpc/",g); |
62 | 62 | 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); | |
64 | 65 | log(1); |
65 | 66 | yield pin.waitForNew(); |
66 | 67 | log(2); |
@@ -89,7 +90,7 @@ function sync() | ||
89 | 90 | </script> |
90 | 91 | </head> |
91 | 92 | <body> |
92 | -<h1>MCU test</h1> | |
93 | +<h1>Digitalout test</h1> | |
93 | 94 | <hr/> |
94 | 95 | <button onclick="async();">ASYNC</button> |
95 | 96 | <button onclick="sync();">SYNC</button> |
@@ -61,24 +61,6 @@ log(3); | ||
61 | 61 | return; |
62 | 62 | |
63 | 63 | } |
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 | -} | |
82 | 64 | |
83 | 65 | |
84 | 66 | </script> |
@@ -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 |
@@ -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 |
@@ -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 |
@@ -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 |
@@ -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 |