2 * @fileOverview BusOutクラスを定義します。
\r
10 * <a href="https://mbed.org/handbook/BusOut">mbed::BusOut</a>と同等の機能を持ちます。
\r
11 * @name mbedJS.BusOut
\r
13 * @param {mbedJS.Mcu} i_mcu
\r
14 * インスタンスをバインドするMCUオブジェクトです。
\r
15 * @param {[PinName...]} i_params
\r
16 * ピンIDの配列を指定します。要素数の最大値は16です。
\r
17 * @param {HashMap|Generator} i_event
\r
18 * 非同期イベントハンドラの連想配列、又はGeneratorです。
\r
20 * 非同期イベントハンドラの場合、関数はイベントハンドラで結果を通知します。
\r
22 * <li>{function()} onNew -
\r
23 * インスタンスが使用可能になった時に呼び出されます。
\r
25 * <li>{function(v)} onRead -
\r
26 * read関数のコールバック関数です。
\r
28 * <li>{int} v - 現在のピンの値です。</li>
\r
31 * <li>{function()} onWrite -
\r
32 * write関数のコールバック関数です。
\r
36 * Generatorを指定した場合、コールバック関数の引数はyiledの戻り値として取得できます。
\r
38 * @return {mbedJS.BusOut}
\r
39 * @example //Callback
\r
40 * var mcu=new mbedJS.Mcu("192.168.128.39",
\r
43 * var bus=new mbedJS.BusOut(mcu,[mbedJS.PinName.P0_21,mbedJS.PinName.P0_22],{
\r
47 * onWrite:function()
\r
51 * onRead:function(v){
\r
56 * onClose:function(){
\r
58 * onError:function(){
\r
61 * @example //Generator
\r
62 * var g=function*(){
\r
64 * var mcu=new mbedJS.Mcu("192.168.128.39",g);
\r
65 * yield mcu.waitForNew();
\r
66 * var bus=new mbedJS.BusOut(mcu,[mbedJS.PinName.P0_21,mbedJS.PinName.P0_22],g);
\r
67 * yield bus.waitForNew();
\r
68 * yield bus.write(1);
\r
69 * var v=yield bus.read();
\r
70 * yield mcu.close();
\r
77 var CLASS=function BusOut(i_mcu,i_params,i_handler)
\r
83 if(MI.isGenerator(i_handler)){_t._gen=i_handler;}
\r
84 else if(i_handler){_t._event=i_handler}
\r
87 _t._oid=j.result[0];
\r
88 if(_t._event.onNew){_t._event.onNew();}
\r
89 if(_t._gen){_t._gen.next(_t);}
\r
94 if(ap.length<1 ||ap.length>16){
\r
95 throw new MI.MiMicException(MI.NG_INVALID_ARG);
\r
101 for(;i<i_params.length;i++){
\r
105 pins+=","+NS.PinName.NC;
\r
107 return _t._mcu.rpc(_t.RPC_NS+":_new1",pins,cb);
\r
109 throw new MI.MiMicException(e);
\r
116 RPC_NS:"mbedJS:BusOut",
\r
117 /** @private 最後にコールしたAPIです。*/
\r
119 /** @private Generatorモードの場合にGeneratorオブジェクトを保持します。*/
\r
121 /** @private コールバック関数の連想配列です。要素はコンストラクタを参照してください。*/
\r
123 /** @private リモートインスタンスのオブジェクトIDです。*/
\r
126 * Generatorモードのときに使用する関数です。
\r
127 * Generatorモードの時は、yieldと併用してnew BusOut()の完了を待ちます。
\r
128 * @name mbedJS.BusOut#waitForNew
\r
131 waitForNew:function BusOut_waitForNew()
\r
134 if(this._lc!=CLASS){throw new MI.MiMicException(MI.Error.NG_ILLEGAL_CALL);}
\r
135 this._lc=CLASS.waitForNew;
\r
137 throw new MI.MiMicException(e);
\r
142 * 関数の完了時にonWriteイベントが発生します。
\r
143 * Generatorモードの時は、yieldと併用して完了を待機できます。
\r
144 * @name mbedJS.BusOut#write
\r
146 * @param {int} i_value
\r
148 * Callbackモードの時はRPCメソッドのインデクスを返します。
\r
150 write:function BusOut_write(i_value)
\r
154 if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
\r
155 _t._lc=CLASS.write;
\r
156 MI.assertInt(i_value);
\r
157 return _t._mcu.rpc(_t.RPC_NS+":write",_t._oid+","+i_value,
\r
159 if(_t._event.onWrite){_t._event.onWrite();}
\r
160 if(_t._gen){_t._gen.next();}
\r
164 throw new MI.MiMicException(e);
\r
169 * 関数の完了時にonReadイベントが発生します。
\r
170 * Generatorモードの時は、yieldと併用して完了を待機できます。
\r
171 * @name mbedJS.BusOut#read
\r
174 * Callbackモードの時はRPCメソッドのインデクスを返します。
\r
176 * Generatorモードの時はピンの値を返します。
\r
178 read:function BusOut_read()
\r
182 if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
\r
184 return _t._mcu.rpc(_t.RPC_NS+":read",_t._oid,
\r
188 if(_t._event.onRead){_t._event.onRead(v);}
\r
189 if(_t._gen){_t._gen.next(v);}
\r
193 throw new MI.MiMicException(e);
\r