2 * @fileOverview PwmOutクラスを定義します。
\r
10 * <a href="https://mbed.org/handbook/PwmOut">mbed::PwmOut</a>と同等の機能を持ちます。
\r
11 * @name mbedJS.PwmOut
\r
13 * @param {mbedJS.Mcu} i_mcu
\r
14 * インスタンスをバインドするMCUオブジェクトです。
\r
15 * @param {PinName} i_params
\r
17 * @param {HashMap|Generator} i_event
\r
18 * 非同期イベントハンドラの連想配列、又はGeneratorです。
\r
20 * 非同期イベントハンドラの場合、関数はイベントハンドラで結果を通知します。
\r
22 * <li>{function()} onNew -
\r
23 * インスタンスが使用可能になった時に呼び出されます。
\r
25 * <li>{function()} onWrite -
\r
26 * write関数のコールバック関数です。
\r
28 * <li>{function(v)} onRead -
\r
29 * read関数のコールバック関数です。
\r
31 * <li>{int} v - 現在のピンの値です。</li>
\r
34 * <li>{function()} onPeriod -
\r
35 * period関数のコールバック関数です。
\r
37 * <li>{function()} onPeriod_ms -
\r
38 * period_ms関数のコールバック関数です。
\r
40 * <li>{function()} onPeriod_us -
\r
41 * period_ns関数のコールバック関数です。
\r
43 * <li>{function()} onPulsewidth -
\r
44 * pulswidth関数のコールバック関数です。
\r
46 * <li>{function()} onPulsewidth_ms -
\r
47 * pulswidth_ms関数のコールバック関数です。
\r
49 * <li>{function()} onPulsewidth_us -
\r
50 * pulswidth_us関数のコールバック関数です。
\r
54 * Generatorを指定した場合、コールバック関数の引数はyiledの戻り値として取得できます。
\r
56 * @return {mbedJS.PwmOut}
\r
57 * @example //Callback
\r
58 * var mcu=new mbedJS.Mcu("192.168.128.39",
\r
61 * var pin=new mbedJS.PwmOut(mcu,mbedJS.PinName.p21,{
\r
65 * onWrite:function()
\r
69 * onRead:function(v)
\r
73 * onPeriod:function(){
\r
76 * onPeriod_ms:function(){
\r
77 * pin.period_us(10);
\r
79 * onPeriod_us:function(){
\r
80 * pin.pulsewidth(3);
\r
82 * onPulsewidth:function(){
\r
83 * pin.pulsewidth_ms(30);
\r
85 * onPulsewidth_ms:function(){
\r
86 * pin.pulsewidth_us(40);
\r
88 * onPulsewidth_us:function(){
\r
93 * onClose:function(){
\r
95 * onError:function(){
\r
98 * @example //Generator
\r
99 * var g=function*(){
\r
101 * var mcu=new mbedJS.Mcu("192.168.128.39",g);
\r
102 * yield mcu.waitForNew();
\r
103 * var pin=new mbedJS.PwmOut(mcu,mbedJS.PinName.p21,g);
\r
104 * yield pin.waitForNew();
\r
105 * yield pin.write(0.33);
\r
106 * var v=yield pin.read();
\r
107 * yield pin.period(1.0);
\r
108 * yield pin.period_ms(1);
\r
109 * yield pin.period_us(10);
\r
110 * yield pin.pulsewidth(3);
\r
111 * yield pin.pulsewidth_ms(30);
\r
112 * yield pin.pulsewidth_us(40);
\r
113 * yield mcu.close();
\r
119 var CLASS=function PwmOut(i_mcu,i_params,i_handler)
\r
125 if(MI.isGenerator(i_handler)){_t._gen=i_handler;}
\r
126 else if(i_handler){_t._event=i_handler}
\r
129 _t._oid=j.result[0];
\r
130 if(_t._event.onNew){_t._event.onNew();}
\r
131 if(_t._gen){_t._gen.next(_t);}
\r
134 MI.assertInt(i_params);
\r
135 return _t._mcu.rpc(_t.RPC_NS+":_new1",i_params,cb);
\r
137 throw new MI.MiMicException(e);
\r
143 RPC_NS:"mbedJS:PwmOut",
\r
144 /** @private 最後にコールしたAPIです。*/
\r
146 /** @private Generatorモードの場合にGeneratorオブジェクトを保持します。*/
\r
148 /** @private コールバック関数の連想配列です。要素はコンストラクタを参照してください。*/
\r
150 /** @private リモートインスタンスのオブジェクトIDです。*/
\r
153 * Generatorモードのときに使用する関数です。
\r
154 * Generatorモードの時は、yieldと併用してnew PwmOut()の完了を待ちます。
\r
155 * @name mbedJS.PwmOut#waitForNew
\r
158 waitForNew:function PwmOut_waitForNew()
\r
161 if(this._lc!=CLASS){throw new MI.MiMicException(MI.Error.NG_ILLEGAL_CALL);}
\r
162 this._lc=CLASS.waitForNew;
\r
164 throw new MI.MiMicException(e);
\r
169 * 関数の完了時にonWriteイベントが発生します。
\r
170 * Generatorモードの時は、yieldと併用して完了を待機できます。
\r
171 * @name mbedJS.PwmOut#write
\r
173 * @param {float} i_value
\r
175 * @return {int|none}
\r
176 * <p>Callbackモードの時はRPCメソッドのインデクスを返します。</p>
\r
177 * <p>Generatorモードの時は戻り値はありません。</p>
\r
179 write:function PwmOut_write(i_value)
\r
183 if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
\r
184 _t._lc=CLASS.write;
\r
185 MI.assertNumber(i_value);
\r
186 return _t._mcu.rpc(_t.RPC_NS+":write_fx",_t._oid+","+Math.round(i_value*10000),
\r
188 if(_t._event.onWrite){_t._event.onWrite();}
\r
189 if(_t._gen){_t._gen.next();}
\r
193 throw new MI.MiMicException(e);
\r
198 * 関数の完了時にonReadイベントが発生します。
\r
199 * Generatorモードの時は、yieldと併用して完了を待機できます。
\r
200 * @name mbedJS.PwmOut#read
\r
202 * @return {int|float}
\r
203 * <p>Callbackモードの時はRPCメソッドのインデクスを返します。</p>
\r
204 * <p>Generatorモードの時はピンの値を返します。</p>
\r
206 read:function PwmOut_read()
\r
210 if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
\r
212 return _t._mcu.rpc(_t.RPC_NS+":read_fx",_t._oid,
\r
215 var v=j.result[0]/10000;
\r
216 if(_t._event.onRead){_t._event.onRead(v);}
\r
217 if(_t._gen){_t._gen.next(v);}
\r
221 throw new MI.MiMicException(e);
\r
226 * 関数の完了時にonPeriodイベントが発生します。
\r
227 * Generatorモードの時は、yieldと併用して完了を待機できます。
\r
228 * @name mbedJS.PwmOut#period
\r
230 * @param {float} i_value
\r
232 * @return {int|none}
\r
233 * <p>Callbackモードの時はRPCメソッドのインデクスを返します。</p>
\r
234 * <p>Generatorモードの時は戻り値はありません。</p>
\r
236 period:function PwmOut_period(i_value)
\r
240 if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
\r
241 _t._lc=CLASS.period;
\r
242 MI.assertInt(i_value);
\r
243 return _t._mcu.rpc(_t.RPC_NS+":period_fx",_t._oid+","+Math.round(i_value*10000),
\r
245 if(_t._event.onPeriod){_t._event.onPeriod();}
\r
246 if(_t._gen){_t._gen.next();}
\r
250 throw new MI.MiMicException(e);
\r
255 * 関数の完了時にonPeriod_msイベントが発生します。
\r
256 * Generatorモードの時は、yieldと併用して完了を待機できます。
\r
257 * @name mbedJS.PwmOut#period_ms
\r
259 * @param {int} i_value
\r
261 * @return {int|none}
\r
262 * <p>Callbackモードの時はRPCメソッドのインデクスを返します。</p>
\r
263 * <p>Generatorモードの時は戻り値はありません。</p>
\r
265 period_ms:function PwmOut_period_ms(i_value)
\r
269 if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
\r
270 _t._lc=CLASS.period_ms;
\r
271 MI.assertInt(i_value);
\r
272 return _t._mcu.rpc(_t.RPC_NS+":period_ms",_t._oid+","+Math.round(i_value),
\r
274 if(_t._event.onPeriod_ms){_t._event.onPeriod_ms();}
\r
275 if(_t._gen){_t._gen.next();}
\r
279 throw new MI.MiMicException(e);
\r
284 * 関数の完了時にonPeriod_usイベントが発生します。
\r
285 * Generatorモードの時は、yieldと併用して完了を待機できます。
\r
286 * @name mbedJS.PwmOut#period_us
\r
288 * @param {int} i_value
\r
290 * @return {int|none}
\r
291 * <p>Callbackモードの時はRPCメソッドのインデクスを返します。</p>
\r
292 * <p>Generatorモードの時は戻り値はありません。</p>
\r
294 period_us:function PwmOut_period_us(i_value)
\r
298 if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
\r
299 _t._lc=CLASS.period_us;
\r
300 MI.assertInt(i_value);
\r
301 return _t._mcu.rpc(_t.RPC_NS+":period_us",_t._oid+","+Math.round(i_value),
\r
303 if(_t._event.onPeriod_us){_t._event.onPeriod_us();}
\r
304 if(_t._gen){_t._gen.next();}
\r
308 throw new MI.MiMicException(e);
\r
313 * 関数の完了時にonPeriodイベントが発生します。
\r
314 * Generatorモードの時は、yieldと併用して完了を待機できます。
\r
315 * @name mbedJS.PwmOut#pulsewidth
\r
317 * @param {float} i_value
\r
319 * @return {int|none}
\r
320 * <p>Callbackモードの時はRPCメソッドのインデクスを返します。</p>
\r
321 * <p>Generatorモードの時は戻り値はありません。</p>
\r
323 pulsewidth:function PwmOut_pulsewidth(i_value)
\r
327 if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
\r
328 _t._lc=CLASS.pulsewidth;
\r
329 MI.assertInt(i_value);
\r
330 return _t._mcu.rpc(_t.RPC_NS+":pulsewidth_fx",_t._oid+","+Math.round(i_value*10000),
\r
332 if(_t._event.onPulsewidth){_t._event.onPulsewidth();}
\r
333 if(_t._gen){_t._gen.next();}
\r
337 throw new MI.MiMicException(e);
\r
342 * 関数の完了時にonPulsewidth_msイベントが発生します。
\r
343 * Generatorモードの時は、yieldと併用して完了を待機できます。
\r
344 * @name mbedJS.PwmOut#pulsewidth_ms
\r
346 * @param {int} i_value
\r
349 * Callbackモードの時はRPCメソッドのインデクスを返します。
\r
351 pulsewidth_ms:function PwmOut_pulsewidth_ms(i_value)
\r
355 if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
\r
356 _t._lc=CLASS.pulsewidth_ms;
\r
357 MI.assertInt(i_value);
\r
358 return _t._mcu.rpc(_t.RPC_NS+":pulsewidth_ms",_t._oid+","+Math.round(i_value),
\r
360 if(_t._event.onPulsewidth_ms){_t._event.onPulsewidth_ms();}
\r
361 if(_t._gen){_t._gen.next();}
\r
365 throw new MI.MiMicException(e);
\r
370 * 関数の完了時にonPulsewidth_usイベントが発生します。
\r
371 * Generatorモードの時は、yieldと併用して完了を待機できます。
\r
372 * @name mbedJS.PwmOut#pulsewidth_us
\r
374 * @param {int} i_value
\r
377 * Callbackモードの時はRPCメソッドのインデクスを返します。
\r
379 pulsewidth_us:function PwmOut_pulsewidth_us(i_value)
\r
383 if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
\r
384 _t._lc=CLASS.pulsewidth_us;
\r
385 MI.assertInt(i_value);
\r
386 return _t._mcu.rpc(_t.RPC_NS+":pulsewidth_us",_t._oid+","+Math.round(i_value),
\r
388 if(_t._event.onPulsewidth_us){_t._event.onPulsewidth_us();}
\r
389 if(_t._gen){_t._gen.next();}
\r
393 throw new MI.MiMicException(e);
\r