From f1a34aabf691ea938759c784f65055b4374feac3 Mon Sep 17 00:00:00 2001
From: nyatla
* éåæã¤ãã³ããã³ãã©ã®å ´åãé¢æ°ã¯ã¤ãã³ããã³ãã©ã§çµæãéç¥ãã¾ãã
*
* Generatorãæå®ããå ´åãã³ã¼ã«ããã¯é¢æ°ã®å¼æ°ã¯yiledã®æ»ãå¤ã¨ãã¦åå¾ã§ãã¾ãã
+ *
+ * ã³ã¼ã«ããã¯é¢æ°ãæå®ããå ´åãRPCãå®äºããã¨ãã«å¼ã³åºããã¾ããã¡ã³ãé¢æ°ã®ã¤ãã³ããã³ãã©ã¯åå¥ã«è¨å®ããå¿
è¦ãããã¾ãã
+ *
* éåæã¤ãã³ããã³ãã©ã®å ´åãé¢æ°ã¯ã¤ãã³ããã³ãã©ã§çµæãéç¥ãã¾ãã
*
* Generatorãæå®ããå ´åãã³ã¼ã«ããã¯é¢æ°ã®å¼æ°ã¯yiledã®æ»ãå¤ã¨ãã¦åå¾ã§ãã¾ãã
+ *
+ * ã³ã¼ã«ããã¯é¢æ°ãæå®ããå ´åãRPCãå®äºããã¨ãã«å¼ã³åºããã¾ããã¡ã³ãé¢æ°ã®ã¤ãã³ããã³ãã©ã¯åå¥ã«è¨å®ããå¿
è¦ãããã¾ãã
+ *
* éåæã¤ãã³ããã³ãã©ã®å ´åãé¢æ°ã¯ã¤ãã³ããã³ãã©ã§çµæãéç¥ãã¾ãã
*
* Generatorãæå®ããå ´åãã³ã¼ã«ããã¯é¢æ°ã®å¼æ°ã¯yiledã®æ»ãå¤ã¨ãã¦åå¾ã§ãã¾ãã
+ *
+ * ã³ã¼ã«ããã¯é¢æ°ãæå®ããå ´åãRPCãå®äºããã¨ãã«å¼ã³åºããã¾ããã¡ã³ãé¢æ°ã®ã¤ãã³ããã³ãã©ã¯åå¥ã«è¨å®ããå¿
è¦ãããã¾ãã
+ *
* éåæã¤ãã³ããã³ãã©ã®å ´åãé¢æ°ã¯ã¤ãã³ããã³ãã©ã§çµæãéç¥ãã¾ãã
*
* Generatorãæå®ããå ´åãã³ã¼ã«ããã¯é¢æ°ã®å¼æ°ã¯yiledã®æ»ãå¤ã¨ãã¦åå¾ã§ãã¾ãã
+ *
+ * ã³ã¼ã«ããã¯é¢æ°ãæå®ããå ´åãRPCãå®äºããã¨ãã«å¼ã³åºããã¾ããã¡ã³ãé¢æ°ã®ã¤ãã³ããã³ãã©ã¯åå¥ã«è¨å®ããå¿
è¦ãããã¾ãã
+ *
* éåæã¤ãã³ããã³ãã©ã®å ´åãé¢æ°ã¯ã¤ãã³ããã³ãã©ã§çµæãéç¥ãã¾ãã
*
* Generatorãæå®ããå ´åãã³ã¼ã«ããã¯é¢æ°ã®å¼æ°ã¯yiledã®æ»ãå¤ã¨ãã¦åå¾ã§ãã¾ãã
+ *
+ * ã³ã¼ã«ããã¯é¢æ°ãæå®ããå ´åãRPCãå®äºããã¨ãã«å¼ã³åºããã¾ããã¡ã³ãé¢æ°ã®ã¤ãã³ããã³ãã©ã¯åå¥ã«è¨å®ããå¿
è¦ãããã¾ãã
+ *
* éåæã¤ãã³ããã³ãã©ã®å ´åãé¢æ°ã¯ã¤ãã³ããã³ãã©ã§çµæãéç¥ãã¾ãã
*
* Generatorãæå®ããå ´åãã³ã¼ã«ããã¯é¢æ°ã®å¼æ°ã¯yiledã®æ»ãå¤ã¨ãã¦åå¾ã§ãã¾ãã
+ *
+ * ã³ã¼ã«ããã¯é¢æ°ãæå®ããå ´åãRPCãå®äºããã¨ãã«å¼ã³åºããã¾ããã¡ã³ãé¢æ°ã®ã¤ãã³ããã³ãã©ã¯åå¥ã«è¨å®ããå¿
è¦ãããã¾ãã
+ * é
åã®å ´åã¯æ¬¡ã®é çªã§ãã©ã¡ã¼ã¿ãæå®ãã¾ãã
*
@@ -37,7 +37,10 @@ var MI=MiMicJS;
*
*
@@ -37,7 +37,10 @@ var MI=MiMicJS;
*
*
@@ -34,7 +34,10 @@ var MI=MiMicJS;
*
*
@@ -44,7 +44,10 @@ var MI=MiMicJS;
*
*
@@ -34,7 +34,10 @@ var MI=MiMicJS;
*
*
@@ -34,7 +34,10 @@ var MI=MiMicJS;
*
* {pin,value}
*
* éåæã¤ãã³ããã³ãã©ã®å ´åãé¢æ°ã¯ã¤ãã³ããã³ãã©ã§çµæãéç¥ãã¾ãã * @@ -49,7 +49,10 @@ var MI=MiMicJS; * *
* Generatorãæå®ããå ´åãã³ã¼ã«ããã¯é¢æ°ã®å¼æ°ã¯yiledã®æ»ãå¤ã¨ãã¦åå¾ã§ãã¾ãã + *
*+ * ã³ã¼ã«ããã¯é¢æ°ãæå®ããå ´åãRPCãå®äºããã¨ãã«å¼ã³åºããã¾ããã¡ã³ãé¢æ°ã®ã¤ãã³ããã³ãã©ã¯åå¥ã«è¨å®ããå¿ è¦ãããã¾ãã + *
* @return {mbedJS.DigitalOut} * @example //Callback * var mcu=new mbedJS.Mcu("192.168.128.39", @@ -95,12 +98,11 @@ var CLASS=function DigitalOut(i_mcu,i_params,i_handler) var _t=this; _t._mcu=i_mcu; _t._lc=CLASS; - if(MI.isGenerator(i_handler)){_t._gen=i_handler;} - else if(i_handler){_t._event=i_handler} - function cb(j) + var cb=MI._initHandler.call(_t,i_handler); + function rcb(j) { _t._oid=j.result[0]; - if(_t._event.onNew){_t._event.onNew();} + if(cb){cb();} if(_t._gen){_t._gen.next(_t);} _t._lc=null; } @@ -116,9 +118,9 @@ var CLASS=function DigitalOut(i_mcu,i_params,i_handler) MI.assertInt(pr[0]); if(pr[1]){ MI.assertInt(pr[1]); - return _t._mcu.rpc(_t.RPC_NS+":_new2",pr[0]+","+pr[1],cb); + _t._mcu.rpc(_t.RPC_NS+":_new2",pr[0]+","+pr[1],rcb); }else{ - return _t._mcu.rpc(_t.RPC_NS+":_new1",pr[0],cb); + _t._mcu.rpc(_t.RPC_NS+":_new1",pr[0],rcb); } }catch(e){ throw new MI.MiMicException(e); @@ -165,12 +167,13 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + var cb=MI._getCb(arguments,_t._event.onWrite); + MI._assertYield.call(_t); _t._lc=CLASS.write; MI.assertInt(i_value); return _t._mcu.rpc(_t.RPC_NS+":write",_t._oid+","+i_value, function(j){ - if(_t._event.onWrite){_t._event.onWrite();} + if(cb){cb();} if(_t._gen){_t._gen.next();} _t._lc=null; }); @@ -193,13 +196,14 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + var cb=MI._getCb(arguments,_t._event.onRead); + MI._assertYield.call(_t); _t._lc=CLASS.read; return _t._mcu.rpc(_t.RPC_NS+":read",_t._oid, function (j) { var v=j.result[0]; - if(_t._event.onRead){_t._event.onRead(v);} + if(cb){cb(v);} if(_t._gen){_t._gen.next(v);} _t._lc=null; } diff --git a/misc/mbedJS/mbddJS.API/mbedJS/mbed.I2C.js b/misc/mbedJS/mbddJS.API/mbedJS/mbed.I2C.js index 39ce756..0d7dd37 100644 --- a/misc/mbedJS/mbddJS.API/mbedJS/mbed.I2C.js +++ b/misc/mbedJS/mbddJS.API/mbedJS/mbed.I2C.js @@ -14,8 +14,8 @@ var MI=MiMicJS; * ã¤ã³ã¹ã¿ã³ã¹ããã¤ã³ãããMCUãªãã¸ã§ã¯ãã§ãã * @param {[PinName,PinName]} i_params * i2Cãã¹ãæ§æãããã³IDãæå®ãã¾ããsda,sclã®é çªã§ãã - * @param {HashMap|Generator} i_event - * éåæã¤ãã³ããã³ãã©ã®é£æ³é åãåã¯Generatorã§ãã + * @param {HashMap|Generator|function} i_handler + * éåæã¤ãã³ããã³ãã©ã®é£æ³é åãGeneratorãã³ã¼ã«ããã¯é¢æ°ã®ä½ãããæå®ãã¾ãã ** éåæã¤ãã³ããã³ãã©ã®å ´åãé¢æ°ã¯ã¤ãã³ããã³ãã©ã§çµæãéç¥ãã¾ãã *
* Generatorãæå®ããå ´åãã³ã¼ã«ããã¯é¢æ°ã®å¼æ°ã¯yiledã®æ»ãå¤ã¨ãã¦åå¾ã§ãã¾ãã + *
*+ * ã³ã¼ã«ããã¯é¢æ°ãæå®ããå ´åãRPCãå®äºããã¨ãã«å¼ã³åºããã¾ããã¡ã³ãé¢æ°ã®ã¤ãã³ããã³ãã©ã¯åå¥ã«è¨å®ããå¿ è¦ãããã¾ãã + *
* @return {mbedJS.I2C} * @example //Callback * var st=0; @@ -126,17 +129,17 @@ var CLASS=function I2C(i_mcu,i_params,i_handler) var _t=this; _t._mcu=i_mcu; _t._lc=CLASS; - if(MI.isGenerator(i_handler)){_t._gen=i_handler;} - else if(i_handler){_t._event=i_handler} - function cb(j) - { - _t._oid=j.result[0]; - if(_t._event.onNew){_t._event.onNew();} - if(_t._gen){_t._gen.next(_t);} - _t._lc=null; - } + var cb=MI._initHandler.call(_t,i_handler); MI.assertInt(i_params); - return _t._mcu.rpc(_t.RPC_NS+":_new1",i_params[0]+","+i_params[1],cb); + _t._mcu.rpc(_t.RPC_NS+":_new1",i_params[0]+","+i_params[1], + function (j) + { + _t._oid=j.result[0]; + if(cb){cb();} + if(_t._gen){_t._gen.next(_t);} + _t._lc=null; + } + ); }catch(e){ throw new MI.MiMicException(e); } @@ -183,16 +186,17 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + var cb=MI._getCb(arguments,_t._event.onFrequency); + MI._assertYield.call(_t); _t._lc=CLASS.frequency; MI.assertInt(i_hz); return _t._mcu.rpc(_t.RPC_NS+":frequency",_t._oid+","+i_hz, - function (j) - { - if(_t._event.onFrequency){_t._event.onFrequency();} - if(_t._gen){_t._gen.next();} - _t._lc=null; - } + function (j) + { + if(cb){cb();} + if(_t._gen){_t._gen.next();} + _t._lc=null; + } ); }catch(e){ throw new MI.MiMicException(e); @@ -243,21 +247,23 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + var cb=MI._getCb(arguments,_t._event.onRead); + MI._assertYield.call(_t); _t._lc=CLASS.read; - function cb(j){ + function rcb(j){ var v=j.result.length>1?{ret:j.result[0],data:MI.bstr2byteArray(j.result[1])}:j.result[0]; - if(_t._event.onRead){_t._event.onRead(v);} + if(cb){cb(v);} if(_t._gen){_t._gen.next(v);} _t._lc=null; } - if(arguments.length==1){ + //ãã¼ã¹å¼æ°ã®æ°ã§å¦çã®åãæ¿ã + if(MI._getBaseArgsLen(arguments)==1){ MI.assertInt(arguments[0]); - return _t._mcu.rpc(_t.RPC_NS+":read2",_t._oid+","+arguments[0],cb); + return _t._mcu.rpc(_t.RPC_NS+":read2",_t._oid+","+arguments[0],rcb); }else{ var a=arguments; MI.assertInt([a[0],a[1]]); - return _t._mcu.rpc(_t.RPC_NS+":read1",_t._oid+","+a[0]+","+a[1]+","+(a[2]?1:0),cb); + return _t._mcu.rpc(_t.RPC_NS+":read1",_t._oid+","+a[0]+","+a[1]+","+(a[2]?1:0),rcb); } }catch(e){ throw new MI.MiMicException(e); @@ -303,21 +309,22 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + var cb=MI._getCb(arguments,_t._event.onWrite); + MI._assertYield.call(_t); _t._lc=CLASS.write; - function cb(j){ + function rcb(j){ var v=j.result[0]; - if(_t._event.onWrite){_t._event.onWrite(v);} + if(cb){cb(v);} if(_t._gen){_t._gen.next(v);} _t._lc=null; } - if(arguments.length==1){ + if(MI._getBaseArgsLen(arguments)==1){ MI.assertInt(arguments[0]); - return _t._mcu.rpc(_t.RPC_NS+":write2",_t._oid+","+arguments[0],cb); + return _t._mcu.rpc(_t.RPC_NS+":write2",_t._oid+","+arguments[0],rcb); }else{ var a=arguments; MI.assertInt(a[0]); - return _t._mcu.rpc(_t.RPC_NS+":write1",_t._oid+","+a[0]+",\""+MI.byteArray2bstr(a[1])+"\","+(a[2]?1:0),cb); + return _t._mcu.rpc(_t.RPC_NS+":write1",_t._oid+","+a[0]+",\""+MI.byteArray2bstr(a[1])+"\","+(a[2]?1:0),rcb); } }catch(e){ throw new MI.MiMicException(e); @@ -336,15 +343,16 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + var cb=MI._getCb(arguments,_t._event.onStart); + MI._assertYield.call(_t); _t._lc=CLASS.start; return _t._mcu.rpc(_t.RPC_NS+":start",_t._oid, - function (j) - { - if(_t._event.onStart){_t._event.onStart();} - if(_t._gen){_t._gen.next();} - _t._lc=null; - } + function (j) + { + if(cb){cb();} + if(_t._gen){_t._gen.next();} + _t._lc=null; + } ); }catch(e){ throw new MI.MiMicException(e); @@ -363,15 +371,16 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} - _t._lc=CLASS.stop; + var cb=MI._getCb(arguments,_t._event.onStop); + MI._assertYield.call(_t); + _t._lc=CLASS.stop; return _t._mcu.rpc(_t.RPC_NS+":stop",_t._oid, - function (j) - { - if(_t._event.onStop){_t._event.onStop();} - if(_t._gen){_t._gen.next();} - _t._lc=null; - } + function (j) + { + if(cb){cb();} + if(_t._gen){_t._gen.next();} + _t._lc=null; + } ); }catch(e){ throw new MI.MiMicException(e); diff --git a/misc/mbedJS/mbddJS.API/mbedJS/mbed.I2CSlave.js b/misc/mbedJS/mbddJS.API/mbedJS/mbed.I2CSlave.js index 7ab644f..572e634 100644 --- a/misc/mbedJS/mbddJS.API/mbedJS/mbed.I2CSlave.js +++ b/misc/mbedJS/mbddJS.API/mbedJS/mbed.I2CSlave.js @@ -14,8 +14,8 @@ var MI=MiMicJS; * ã¤ã³ã¹ã¿ã³ã¹ããã¤ã³ãããMCUãªãã¸ã§ã¯ãã§ãã * @param {[PinName,PinName]} i_params * i2Cãã¹ãæ§æãããã³IDãæå®ãã¾ããsda,sclã®é çªã§ãã - * @param {HashMap|Generator} i_event - * éåæã¤ãã³ããã³ãã©ã®é£æ³é åãåã¯Generatorã§ãã + * @param {HashMap|Generator|function} i_handler + * éåæã¤ãã³ããã³ãã©ã®é£æ³é åãGeneratorãã³ã¼ã«ããã¯é¢æ°ã®ä½ãããæå®ãã¾ãã ** éåæã¤ãã³ããã³ãã©ã®å ´åãé¢æ°ã¯ã¤ãã³ããã³ãã©ã§çµæãéç¥ãã¾ãã *
* Generatorãæå®ããå ´åãã³ã¼ã«ããã¯é¢æ°ã®å¼æ°ã¯yiledã®æ»ãå¤ã¨ãã¦åå¾ã§ãã¾ãã + *
*+ * ã³ã¼ã«ããã¯é¢æ°ãæå®ããå ´åãRPCãå®äºããã¨ãã«å¼ã³åºããã¾ããã¡ã³ãé¢æ°ã®ã¤ãã³ããã³ãã©ã¯åå¥ã«è¨å®ããå¿ è¦ãããã¾ãã + *
* @return {mbedJS.I2CSlave} * @example //Callback * var mcu=new mbedJS.Mcu("192.168.128.39", @@ -138,17 +141,17 @@ var CLASS=function I2CSlave(i_mcu,i_params,i_handler) var _t=this; _t._mcu=i_mcu; _t._lc=CLASS; - if(MI.isGenerator(i_handler)){_t._gen=i_handler;} - else if(i_handler){_t._event=i_handler} - function cb(j) - { - _t._oid=j.result[0]; - if(_t._event.onNew){_t._event.onNew();} - if(_t._gen){_t._gen.next(_t);} - _t._lc=null; - } - MI.assertInt(i_params); - return _t._mcu.rpc(_t.RPC_NS+":_new1",i_params[0]+","+i_params[1],cb); + var cb=MI._initHandler.call(_t,i_handler); + MI.assertInt(i_params); + _t._mcu.rpc(_t.RPC_NS+":_new1",i_params[0]+","+i_params[1], + function(j) + { + _t._oid=j.result[0]; + if(cb){cb();} + if(_t._gen){_t._gen.next(_t);} + _t._lc=null; + } + ); }catch(e){ throw new MI.MiMicException(e); } @@ -202,15 +205,17 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + var cb=MI._getCb(arguments,_t._event.onAddress); + MI._assertYield.call(_t); _t._lc=CLASS.write; MI.assertInt(i_value); return _t._mcu.rpc(_t.RPC_NS+":address",_t._oid+","+i_value, - function(j){ - if(_t._event.onAddress){_t._event.onAddress();} - if(_t._gen){_t._gen.next();} - _t._lc=null; - }); + function(j){ + if(cb){cb();} + if(_t._gen){_t._gen.next();} + _t._lc=null; + } + ); }catch(e){ throw new MI.MiMicException(e); } @@ -230,16 +235,17 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + var cb=MI._getCb(arguments,_t._event.onFrequency); + MI._assertYield.call(_t); _t._lc=CLASS.frequency; MI.assertInt(i_hz); return _t._mcu.rpc(_t.RPC_NS+":frequency",_t._oid+","+i_hz, - function (j) - { - if(_t._event.onFrequency){_t._event.onFrequency();} - if(_t._gen){_t._gen.next();} - _t._lc=null; - } + function (j) + { + if(cb){cb();} + if(_t._gen){_t._gen.next();} + _t._lc=null; + } ); }catch(e){ throw new MI.MiMicException(e); @@ -283,19 +289,20 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + var cb=MI._getCb(arguments,_t._event.onRead); + MI._assertYield.call(_t); _t._lc=CLASS.read; - function cb(j){ + function rcb(j){ var v=j.result.length>1?{ret:j.result[0],data:MI.bstr2byteArray(j.result[1])}:j.result[0]; - if(_t._event.onRead){_t._event.onRead(v);} + if(cb){cb(v);} if(_t._gen){_t._gen.next(v);} _t._lc=null; } - if(arguments.length==0){ - return _t._mcu.rpc(_t.RPC_NS+":read2",_t._oid,cb); + if(MI._getBaseArgsLen(arguments)==0){ + return _t._mcu.rpc(_t.RPC_NS+":read2",_t._oid,rcb); }else{ MI.assertInt(arguments[0]); - return _t._mcu.rpc(_t.RPC_NS+":read1",_t._oid+","+arguments[0],cb); + return _t._mcu.rpc(_t.RPC_NS+":read1",_t._oid+","+arguments[0],rcb); } }catch(e){ throw new MI.MiMicException(e); @@ -316,16 +323,17 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + var cb=MI._getCb(arguments,_t._event.onReceive); + MI._assertYield.call(_t); _t._lc=CLASS.start; return _t._mcu.rpc(_t.RPC_NS+":receive",_t._oid, - function (j) - { - var v=j.result[0]; - if(_t._event.onReceive){_t._event.onReceive(v);} - if(_t._gen){_t._gen.next(v);} - _t._lc=null; - } + function (j) + { + var v=j.result[0]; + if(cb){cb(v);} + if(_t._gen){_t._gen.next(v);} + _t._lc=null; + } ); }catch(e){ throw new MI.MiMicException(e); @@ -335,8 +343,6 @@ CLASS.prototype= * å¼æ°ã3åã®å ´å * @name mbedJS.I2CSlave#write.1 * @function - * @param {int} address - * 8ãããã®I2CSlaveSlaveã¢ãã¬ã¹ã§ãã * @param {byte[]} data * éä¿¡ãããã¼ã¿ãæ ¼ç´ãããã¤ãé åã§ãã * @return {int} @@ -368,20 +374,21 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + var cb=MI._getCb(arguments,_t._event.onWrite); + MI._assertYield.call(_t); _t._lc=CLASS.write; - function cb(j){ + function rcb(j){ var v=j.result[0]; - if(_t._event.onWrite){_t._event.onWrite(v);} + if(cb){cb(v);} if(_t._gen){_t._gen.next(v);} _t._lc=null; } if(!MI.isArray(arguments[0])){ MI.assertInt(arguments[0]); - return _t._mcu.rpc(_t.RPC_NS+":write2",_t._oid+","+arguments[0],cb); + return _t._mcu.rpc(_t.RPC_NS+":write2",_t._oid+","+arguments[0],rcb); }else{ var a=arguments; - return _t._mcu.rpc(_t.RPC_NS+":write1",_t._oid+",\""+MI.byteArray2bstr(a[0])+"\"",cb); + return _t._mcu.rpc(_t.RPC_NS+":write1",_t._oid+",\""+MI.byteArray2bstr(a[0])+"\"",rcb); } }catch(e){ throw new MI.MiMicException(e); @@ -400,15 +407,16 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + var cb=MI._getCb(arguments,_t._event.onStop); + MI._assertYield.call(_t); _t._lc=CLASS.stop; return _t._mcu.rpc(_t.RPC_NS+":stop",_t._oid, - function (j) - { - if(_t._event.onStop){_t._event.onStop();} - if(_t._gen){_t._gen.next();} - _t._lc=null; - } + function (j) + { + if(cb){cb();} + if(_t._gen){_t._gen.next();} + _t._lc=null; + } ); }catch(e){ throw new MI.MiMicException(e); diff --git a/misc/mbedJS/mbddJS.API/mbedJS/mbed.Mcu.js b/misc/mbedJS/mbddJS.API/mbedJS/mbed.Mcu.js index 6f1346b..af20836 100644 --- a/misc/mbedJS/mbddJS.API/mbedJS/mbed.Mcu.js +++ b/misc/mbedJS/mbddJS.API/mbedJS/mbed.Mcu.js @@ -157,6 +157,7 @@ CLASS.prototype= }, /** * ã³ã¼ã«ããã¯é¢æ°ãå ¨ã¦ãã£ã³ã»ã«ãã¦ãMcuã¨ã®æ¥ç¶ãã·ã£ãããã¦ã³ãã¾ãã + * ãã®é¢æ°ã¯å³åº§ã«å®äºãã¾ãã * @name mbedJS.Mcu#shutdown * @function */ @@ -220,6 +221,9 @@ CLASS.prototype= * æå®idã®ãªãã¸ã§ã¯ããMCUã®ã¡ã¢ãªããåé¤ãã¾ãã * @name mbedJS.Mcu#disposeObject * @function + * @param {int} i_oid + * ãªãã¸ã§ã¯ãIDã + * mbedJSãªãã¸ã§ã¯ããææãããªã¢ã¼ããªãã¸ã§ã¯ãã®IDãæå®ãã¾ãã * @return {boolean} * çµæãè¿ãã¾ãã */ diff --git a/misc/mbedJS/mbddJS.API/mbedJS/mbed.Memory.js b/misc/mbedJS/mbddJS.API/mbedJS/mbed.Memory.js index e230b64..aedda29 100644 --- a/misc/mbedJS/mbddJS.API/mbedJS/mbed.Memory.js +++ b/misc/mbedJS/mbddJS.API/mbedJS/mbed.Memory.js @@ -12,8 +12,8 @@ var MI=MiMicJS; * @constructor * @param {mbedJS.Mcu} i_mcu * ã¤ã³ã¹ã¿ã³ã¹ããã¤ã³ãããMCUãªãã¸ã§ã¯ãã§ãã - * @param {HashMap|Generator} i_event - * éåæã¤ãã³ããã³ãã©ã®é£æ³é åãåã¯Generatorã§ãã + * @param {HashMap|Generator|function} i_handler + * éåæã¤ãã³ããã³ãã©ã®é£æ³é åãGeneratorãã³ã¼ã«ããã¯é¢æ°ã®ä½ãããæå®ãã¾ãã ** éåæã¤ãã³ããã³ãã©ã®å ´åãé¢æ°ã¯ã¤ãã³ããã³ãã©ã§çµæãéç¥ãã¾ãã *
* Generatorãæå®ããå ´åãã³ã¼ã«ããã¯é¢æ°ã®å¼æ°ã¯yiledã®æ»ãå¤ã¨ãã¦åå¾ã§ãã¾ãã + *
*+ * ã³ã¼ã«ããã¯é¢æ°ãæå®ããå ´åãRPCãå®äºããã¨ãã«å¼ã³åºããã¾ããã¡ã³ãé¢æ°ã®ã¤ãã³ããã³ãã©ã¯åå¥ã«è¨å®ããå¿ è¦ãããã¾ãã + *
* @return {mbedJS.Memory} * @example //Callback * var s=0; @@ -166,15 +169,15 @@ var CLASS=function Memory(i_mcu,i_handler) var _t=this; _t._mcu=i_mcu; _t._lc=CLASS; - if(MI.isGenerator(i_handler)){_t._gen=i_handler;} - else if(i_handler){_t._event=i_handler} - function cb(j) - { - if(_t._event.onNew){_t._event.onNew();} - if(_t._gen){_t._gen.next(_t);} - _t._lc=null; - } - return _t._mcu.rpc(_t.RPC_NS+":init","",cb); + var cb=MI._initHandler.call(_t,i_handler); + _t._mcu.rpc(_t.RPC_NS+":init","", + function(j) + { + if(cb){cb();} + if(_t._gen){_t._gen.next(_t);} + _t._lc=null; + } + ); }catch(e){ throw new MI.MiMicException(e); } @@ -225,15 +228,16 @@ CLASS.prototype= //read(i_addr,i_len) try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + var cb=MI._getCb(arguments,_t._event.onRead); + MI._assertYield.call(_t); _t._lc=CLASS.read; - var a=[i_addr,MI.isUndefined(i_size,1)]; + var a=[i_addr,(MI._getBaseArgsLen(arguments)==1)?i_size:1]; MI.assertInt(a); return _t._mcu.rpc(_t.RPC_NS+":read",a[0]+","+a[1], function (j) { var v=MI.bstr2byteArray(j.result[0]); - if(_t._event.onRead){_t._event.onRead(v);} + if(cb){cb(v);} if(_t._gen){_t._gen.next(v);} _t._lc=null; }); @@ -259,17 +263,18 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + var cb=MI._getCb(arguments,_t._event.onWrite); + MI._assertYield.call(_t); _t._lc=CLASS.write; MI.assertInt(i_addr); MI.assertInt(i_v); return _t._mcu.rpc(_t.RPC_NS+":write",i_addr+",\""+MI.byteArray2bstr(i_v)+"\"", - function (j) - { - if(_t._event.onWrite){_t._event.onWrite();} - if(_t._gen){_t._gen.next();} - _t._lc=null; - } + function (j) + { + if(cb){cb();} + if(_t._gen){_t._gen.next();} + _t._lc=null; + } ); }catch(e){ throw new MI.MiMicException(e); @@ -296,21 +301,24 @@ CLASS.prototype= //read(i_addr,i_len) try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + var cb=MI._getCb(arguments,_t._event.onRead32); + MI._assertYield.call(_t); _t._lc=CLASS.read32; - var a=[i_addr,MI.isUndefined(i_size,4)]; + + var a=[i_addr,(MI._getBaseArgsLen(arguments)==1)?4:i_size]; if(a[1]%4!=0){ throw new MI.MiMicException(MI.Error.NG_INVALID_ARG); } MI.assertInt(a); return _t._mcu.rpc(_t.RPC_NS+":read",a[0]+","+a[1], - function (j) - { - var v=MI.bstr2uintArray(j.result[0]); - if(_t._event.onRead32){_t._event.onRead32(v);} - if(_t._gen){_t._gen.next(v);} - _t._lc=null; - }); + function (j) + { + var v=MI.bstr2uintArray(j.result[0]); + if(cb){cb(v);} + if(_t._gen){_t._gen.next(v);} + _t._lc=null; + } + ); }catch(e){ throw new MI.MiMicException(e); } @@ -333,17 +341,18 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + var cb=MI._getCb(arguments,_t._event.onWrite32); + MI._assertYield.call(_t); _t._lc=CLASS.write32; MI.assertInt(i_addr); MI.assertInt(i_v); return _t._mcu.rpc(_t.RPC_NS+":write",i_addr+",\""+MI.uintArray2bstr(i_v)+"\"", - function (j) - { - if(_t._event.onWrite){_t._event.onWrite32();} - if(_t._gen){_t._gen.next();} - _t._lc=null; - } + function (j) + { + if(cb){cb();} + if(_t._gen){_t._gen.next();} + _t._lc=null; + } ); }catch(e){ throw new MI.MiMicException(e); diff --git a/misc/mbedJS/mbddJS.API/mbedJS/mbed.PortIn.js b/misc/mbedJS/mbddJS.API/mbedJS/mbed.PortIn.js index f83268f..3b89626 100644 --- a/misc/mbedJS/mbddJS.API/mbedJS/mbed.PortIn.js +++ b/misc/mbedJS/mbddJS.API/mbedJS/mbed.PortIn.js @@ -25,8 +25,8 @@ var MI=MiMicJS; *é åã®å ´åã¯æ¬¡ã®é çªã§ãã©ã¡ã¼ã¿ãæå®ãã¾ãã *
{port,mask}* - * @param {HashMap|Generator} i_event - * éåæã¤ãã³ããã³ãã©ã®é£æ³é åãåã¯Generatorã§ãã + * @param {HashMap|Generator|function} i_handler + * éåæã¤ãã³ããã³ãã©ã®é£æ³é åãGeneratorãã³ã¼ã«ããã¯é¢æ°ã®ä½ãããæå®ãã¾ãã *
* éåæã¤ãã³ããã³ãã©ã®å ´åãé¢æ°ã¯ã¤ãã³ããã³ãã©ã§çµæãéç¥ãã¾ãã *
* Generatorãæå®ããå ´åãã³ã¼ã«ããã¯é¢æ°ã®å¼æ°ã¯yiledã®æ»ãå¤ã¨ãã¦åå¾ã§ãã¾ãã + *
*+ * ã³ã¼ã«ããã¯é¢æ°ãæå®ããå ´åãRPCãå®äºããã¨ãã«å¼ã³åºããã¾ããã¡ã³ãé¢æ°ã®ã¤ãã³ããã³ãã©ã¯åå¥ã«è¨å®ããå¿ è¦ãããã¾ãã + *
* @return {mbedJS.PortIn} * @example //Callback * var mcu=new mbedJS.Mcu("192.168.128.39", @@ -87,15 +90,7 @@ var CLASS=function PortIn(i_mcu,i_params,i_handler) var _t=this; _t._mcu=i_mcu; _t._lc=CLASS; - if(MI.isGenerator(i_handler)){_t._gen=i_handler;} - else if(i_handler){_t._event=i_handler} - function cb(j) - { - _t._oid=j.result[0]; - if(_t._event.onNew){_t._event.onNew();} - if(_t._gen){_t._gen.next(_t);} - _t._lc=null; - } + var cb=MI._initHandler.call(_t,i_handler); //å¼æ°ã®æ£è¦å var pr; if(MI.isHashArray(i_params)){ @@ -104,7 +99,15 @@ var CLASS=function PortIn(i_mcu,i_params,i_handler) pr=i_params; } MI.assertInt(pr); - return _t._mcu.rpc(_t.RPC_NS+":_new1",pr[0]+","+pr[1],cb); + _t._mcu.rpc(_t.RPC_NS+":_new1",pr[0]+","+pr[1], + function(j) + { + _t._oid=j.result[0]; + if(cb){cb();} + if(_t._gen){_t._gen.next(_t);} + _t._lc=null; + } + ); }catch(e){ throw new MI.MiMicException(e); } @@ -151,16 +154,18 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + var cb=MI._getCb(arguments,_t._event.onRead); + MI._assertYield.call(_t); _t._lc=CLASS.read; return _t._mcu.rpc(_t.RPC_NS+":read",_t._oid, - function (j) - { - var v=j.result[0]; - if(_t._event.onRead){_t._event.onRead(v);} - if(_t._gen){_t._gen.next(v);} - _t._lc=null; - }); + function (j) + { + var v=j.result[0]; + if(cb){cb(v);} + if(_t._gen){_t._gen.next(v);} + _t._lc=null; + } + ); }catch(e){ throw new MI.MiMicException(e); } diff --git a/misc/mbedJS/mbddJS.API/mbedJS/mbed.PortOut.js b/misc/mbedJS/mbddJS.API/mbedJS/mbed.PortOut.js index 8a4eecc..0f460ea 100644 --- a/misc/mbedJS/mbddJS.API/mbedJS/mbed.PortOut.js +++ b/misc/mbedJS/mbddJS.API/mbedJS/mbed.PortOut.js @@ -25,8 +25,8 @@ var MI=MiMicJS; *é åã®å ´åã¯æ¬¡ã®é çªã§ãã©ã¡ã¼ã¿ãæå®ãã¾ãã *
{port,mask}* - * @param {HashMap|Generator} i_event - * éåæã¤ãã³ããã³ãã©ã®é£æ³é åãåã¯Generatorã§ãã + * @param {HashMap|Generator|function} i_handler + * éåæã¤ãã³ããã³ãã©ã®é£æ³é åãGeneratorãã³ã¼ã«ããã¯é¢æ°ã®ä½ãããæå®ãã¾ãã *
* éåæã¤ãã³ããã³ãã©ã®å ´åãé¢æ°ã¯ã¤ãã³ããã³ãã©ã§çµæãéç¥ãã¾ãã *
* Generatorãæå®ããå ´åãã³ã¼ã«ããã¯é¢æ°ã®å¼æ°ã¯yiledã®æ»ãå¤ã¨ãã¦åå¾ã§ãã¾ãã + *
*+ * ã³ã¼ã«ããã¯é¢æ°ãæå®ããå ´åãRPCãå®äºããã¨ãã«å¼ã³åºããã¾ããã¡ã³ãé¢æ°ã®ã¤ãã³ããã³ãã©ã¯åå¥ã«è¨å®ããå¿ è¦ãããã¾ãã + *
* @return {mbedJS.PortOut} * @example //Callback * var mcu=new mbedJS.Mcu("192.168.128.39", @@ -91,15 +94,7 @@ var CLASS=function PortOut(i_mcu,i_params,i_handler) var _t=this; _t._mcu=i_mcu; _t._lc=CLASS; - if(MI.isGenerator(i_handler)){_t._gen=i_handler;} - else if(i_handler){_t._event=i_handler} - function cb(j) - { - _t._oid=j.result[0]; - if(_t._event.onNew){_t._event.onNew();} - if(_t._gen){_t._gen.next(_t);} - _t._lc=null; - } + var cb=MI._initHandler.call(_t,i_handler); //å¼æ°ã®æ£è¦å var pr; if(MI.isHashArray(i_params)){ @@ -108,7 +103,15 @@ var CLASS=function PortOut(i_mcu,i_params,i_handler) pr=i_params; } MI.assertInt(pr); - return _t._mcu.rpc(_t.RPC_NS+":_new1",pr[0]+","+pr[1],cb); + _t._mcu.rpc(_t.RPC_NS+":_new1",pr[0]+","+pr[1], + function(j) + { + _t._oid=j.result[0]; + if(cb){cb();} + if(_t._gen){_t._gen.next(_t);} + _t._lc=null; + } + ); }catch(e){ throw new MI.MiMicException(e); } @@ -154,15 +157,17 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + var cb=MI._getCb(arguments,_t._event.onWrite); + MI._assertYield.call(_t); _t._lc=CLASS.write; MI.assertInt(i_value); return _t._mcu.rpc(_t.RPC_NS+":write",_t._oid+","+i_value, - function(j){ - if(_t._event.onWrite){_t._event.onWrite();} - if(_t._gen){_t._gen.next();} - _t._lc=null; - }); + function(j){ + if(cb){cb();} + if(_t._gen){_t._gen.next();} + _t._lc=null; + } + ); }catch(e){ throw new MI.MiMicException(e); } @@ -182,16 +187,18 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + var cb=MI._getCb(arguments,_t._event.onRead); + MI._assertYield.call(_t); _t._lc=CLASS.read; return _t._mcu.rpc(_t.RPC_NS+":read",_t._oid, - function (j) - { - var v=j.result[0]; - if(_t._event.onRead){_t._event.onRead(v);} - if(_t._gen){_t._gen.next(v);} - _t._lc=null; - }); + function (j) + { + var v=j.result[0]; + if(cb){cb(v);} + if(_t._gen){_t._gen.next(v);} + _t._lc=null; + } + ); }catch(e){ throw new MI.MiMicException(e); } diff --git a/misc/mbedJS/mbddJS.API/mbedJS/mbed.PwmOut.js b/misc/mbedJS/mbddJS.API/mbedJS/mbed.PwmOut.js index 10d9aec..6fe758d 100644 --- a/misc/mbedJS/mbddJS.API/mbedJS/mbed.PwmOut.js +++ b/misc/mbedJS/mbddJS.API/mbedJS/mbed.PwmOut.js @@ -14,8 +14,8 @@ var MI=MiMicJS; * ã¤ã³ã¹ã¿ã³ã¹ããã¤ã³ãããMCUãªãã¸ã§ã¯ãã§ãã * @param {PinName} i_params * ãã³IDãæå®ãã¾ãã - * @param {HashMap|Generator} i_event - * éåæã¤ãã³ããã³ãã©ã®é£æ³é åãåã¯Generatorã§ãã + * @param {HashMap|Generator|function} i_handler + * éåæã¤ãã³ããã³ãã©ã®é£æ³é åãGeneratorãã³ã¼ã«ããã¯é¢æ°ã®ä½ãããæå®ãã¾ãã ** éåæã¤ãã³ããã³ãã©ã®å ´åãé¢æ°ã¯ã¤ãã³ããã³ãã©ã§çµæãéç¥ãã¾ãã *
* Generatorãæå®ããå ´åãã³ã¼ã«ããã¯é¢æ°ã®å¼æ°ã¯yiledã®æ»ãå¤ã¨ãã¦åå¾ã§ãã¾ãã + *
*+ * ã³ã¼ã«ããã¯é¢æ°ãæå®ããå ´åãRPCãå®äºããã¨ãã«å¼ã³åºããã¾ããã¡ã³ãé¢æ°ã®ã¤ãã³ããã³ãã©ã¯åå¥ã«è¨å®ããå¿ è¦ãããã¾ãã + *
* @return {mbedJS.PwmOut} * @example //Callback * var mcu=new mbedJS.Mcu("192.168.128.39", @@ -122,17 +125,17 @@ var CLASS=function PwmOut(i_mcu,i_params,i_handler) var _t=this; _t._mcu=i_mcu; _t._lc=CLASS; - if(MI.isGenerator(i_handler)){_t._gen=i_handler;} - else if(i_handler){_t._event=i_handler} - function cb(j) - { - _t._oid=j.result[0]; - if(_t._event.onNew){_t._event.onNew();} - if(_t._gen){_t._gen.next(_t);} - _t._lc=null; - } + var cb=MI._initHandler.call(_t,i_handler); MI.assertInt(i_params); - return _t._mcu.rpc(_t.RPC_NS+":_new1",i_params,cb); + _t._mcu.rpc(_t.RPC_NS+":_new1",i_params, + function(j) + { + _t._oid=j.result[0]; + if(cb){cb();} + if(_t._gen){_t._gen.next(_t);} + _t._lc=null; + } + ); }catch(e){ throw new MI.MiMicException(e); } @@ -180,12 +183,13 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + var cb=MI._getCb(arguments,_t._event.onWrite); + MI._assertYield.call(_t); _t._lc=CLASS.write; MI.assertNumber(i_value); return _t._mcu.rpc(_t.RPC_NS+":write_fx",_t._oid+","+Math.round(i_value*10000), function(j){ - if(_t._event.onWrite){_t._event.onWrite();} + if(cb){cb();} if(_t._gen){_t._gen.next();} _t._lc=null; }); @@ -207,13 +211,14 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + var cb=MI._getCb(arguments,_t._event.onRead); + MI._assertYield.call(_t); _t._lc=CLASS.read; return _t._mcu.rpc(_t.RPC_NS+":read_fx",_t._oid, function (j) { var v=j.result[0]/10000; - if(_t._event.onRead){_t._event.onRead(v);} + if(cb){cb(v);} if(_t._gen){_t._gen.next(v);} _t._lc=null; }); @@ -237,12 +242,13 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + var cb=MI._getCb(arguments,_t._event.onPeriod); + MI._assertYield.call(_t); _t._lc=CLASS.period; MI.assertInt(i_value); return _t._mcu.rpc(_t.RPC_NS+":period_fx",_t._oid+","+Math.round(i_value*10000), function(j){ - if(_t._event.onPeriod){_t._event.onPeriod();} + if(cb){cb();} if(_t._gen){_t._gen.next();} _t._lc=null; }); @@ -266,12 +272,13 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + var cb=MI._getCb(arguments,_t._event.onPeriod_ms); + MI._assertYield.call(_t); _t._lc=CLASS.period_ms; MI.assertInt(i_value); return _t._mcu.rpc(_t.RPC_NS+":period_ms",_t._oid+","+Math.round(i_value), function(j){ - if(_t._event.onPeriod_ms){_t._event.onPeriod_ms();} + if(cb){cb();} if(_t._gen){_t._gen.next();} _t._lc=null; }); @@ -295,12 +302,13 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + var cb=MI._getCb(arguments,_t._event.onPeriod_us); + MI._assertYield.call(_t); _t._lc=CLASS.period_us; MI.assertInt(i_value); return _t._mcu.rpc(_t.RPC_NS+":period_us",_t._oid+","+Math.round(i_value), function(j){ - if(_t._event.onPeriod_us){_t._event.onPeriod_us();} + if(cb){cb();} if(_t._gen){_t._gen.next();} _t._lc=null; }); @@ -324,12 +332,13 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + var cb=MI._getCb(arguments,_t._event.onPulsewidth); + MI._assertYield.call(_t); _t._lc=CLASS.pulsewidth; MI.assertInt(i_value); return _t._mcu.rpc(_t.RPC_NS+":pulsewidth_fx",_t._oid+","+Math.round(i_value*10000), function(j){ - if(_t._event.onPulsewidth){_t._event.onPulsewidth();} + if(cb){cb();} if(_t._gen){_t._gen.next();} _t._lc=null; }); @@ -352,15 +361,17 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + var cb=MI._getCb(arguments,_t._event.onPulsewidth_ms); + MI._assertYield.call(_t); _t._lc=CLASS.pulsewidth_ms; MI.assertInt(i_value); return _t._mcu.rpc(_t.RPC_NS+":pulsewidth_ms",_t._oid+","+Math.round(i_value), - function(j){ - if(_t._event.onPulsewidth_ms){_t._event.onPulsewidth_ms();} - if(_t._gen){_t._gen.next();} - _t._lc=null; - }); + function(j){ + if(cb){cb();} + if(_t._gen){_t._gen.next();} + _t._lc=null; + } + ); }catch(e){ throw new MI.MiMicException(e); } @@ -380,15 +391,17 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + var cb=MI._getCb(arguments,_t._event.onPulsewidth_us); + MI._assertYield.call(_t); _t._lc=CLASS.pulsewidth_us; MI.assertInt(i_value); return _t._mcu.rpc(_t.RPC_NS+":pulsewidth_us",_t._oid+","+Math.round(i_value), - function(j){ - if(_t._event.onPulsewidth_us){_t._event.onPulsewidth_us();} - if(_t._gen){_t._gen.next();} - _t._lc=null; - }); + function(j){ + if(cb){cb();} + if(_t._gen){_t._gen.next();} + _t._lc=null; + } + ); }catch(e){ throw new MI.MiMicException(e); } diff --git a/misc/mbedJS/mbddJS.API/mbedJS/mbed.SPI.js b/misc/mbedJS/mbddJS.API/mbedJS/mbed.SPI.js index bafe1e8..81ab64a 100644 --- a/misc/mbedJS/mbddJS.API/mbedJS/mbed.SPI.js +++ b/misc/mbedJS/mbddJS.API/mbedJS/mbed.SPI.js @@ -14,8 +14,8 @@ var MI=MiMicJS; * ã¤ã³ã¹ã¿ã³ã¹ããã¤ã³ãããMCUãªãã¸ã§ã¯ãã§ãã * @param {[PinName,PinName,PinName]} i_params * SPIãæ§æãã3ã¤ã®PinNameãæ ¼ç´ããé åã§ããmosi,miso,sclkã®é çªã§ãã - * @param {HashMap|Generator} i_event - * éåæã¤ãã³ããã³ãã©ã®é£æ³é åãåã¯Generatorã§ãã + * @param {HashMap|Generator|function} i_handler + * éåæã¤ãã³ããã³ãã©ã®é£æ³é åãGeneratorãã³ã¼ã«ããã¯é¢æ°ã®ä½ãããæå®ãã¾ãã ** éåæã¤ãã³ããã³ãã©ã®å ´åãé¢æ°ã¯ã¤ãã³ããã³ãã©ã§çµæãéç¥ãã¾ãã *
* Generatorãæå®ããå ´åãã³ã¼ã«ããã¯é¢æ°ã®å¼æ°ã¯yiledã®æ»ãå¤ã¨ãã¦åå¾ã§ãã¾ãã + *
*+ * ã³ã¼ã«ããã¯é¢æ°ãæå®ããå ´åãRPCãå®äºããã¨ãã«å¼ã³åºããã¾ããã¡ã³ãé¢æ°ã®ã¤ãã³ããã³ãã©ã¯åå¥ã«è¨å®ããå¿ è¦ãããã¾ãã + *
* @return {mbedJS.SPI} * @exampleã//Callback * var mcu=new mbedJS.Mcu("192.168.128.39", @@ -87,17 +90,17 @@ var CLASS=function SPI(i_mcu,i_params,i_handler) var _t=this; _t._mcu=i_mcu; _t._lc=CLASS; - if(MI.isGenerator(i_handler)){_t._gen=i_handler;} - else if(i_handler){_t._event=i_handler} - function cb(j) - { - _t._oid=j.result[0]; - if(_t._event.onNew){_t._event.onNew();} - if(_t._gen){_t._gen.next(_t);} - _t._lc=null; - } + var cb=MI._initHandler.call(_t,i_handler); MI.assertInt(i_params); - return _t._mcu.rpc(_t.RPC_NS+":_new1",i_params[0]+","+i_params[1]+","+i_params[2]+","+NS.PinName.NC,cb); + _t._mcu.rpc(_t.RPC_NS+":_new1",i_params[0]+","+i_params[1]+","+i_params[2]+","+NS.PinName.NC, + function(j) + { + _t._oid=j.result[0]; + if(cb){cb();} + if(_t._gen){_t._gen.next(_t);} + _t._lc=null; + } + ); }catch(e){ throw new MI.MiMicException(e); } @@ -144,16 +147,18 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + MI._assertYield.call(_t); + var cb=MI._getCb(arguments,_t._event.onWrite); _t._lc=CLASS.write; MI.assertInt(i_value); return _t._mcu.rpc(_t.RPC_NS+":write",_t._oid+","+i_value, - function(j){ - var v=j.result[0]; - if(_t._event.onWrite){_t._event.onWrite(v);} - if(_t._gen){_t._gen.next(v);} - _t._lc=null; - }); + function(j){ + var v=j.result[0]; + if(cb){cb(v);} + if(_t._gen){_t._gen.next(v);} + _t._lc=null; + } + ); }catch(e){ throw new MI.MiMicException(e); } @@ -173,15 +178,17 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + MI._assertYield.call(_t); + var cb=MI._getCb(arguments,_t._event.onFrequency); _t._lc=CLASS.frequency; MI.assertInt(i_value); return _t._mcu.rpc(_t.RPC_NS+":frequency",_t._oid+","+i_value, - function(j){ - if(_t._event.onFrequency){_t._event.onFrequency();} - if(_t._gen){_t._gen.next();} - _t._lc=null; - }); + function(j){ + if(cb){cb();} + if(_t._gen){_t._gen.next();} + _t._lc=null; + } + ); }catch(e){ throw new MI.MiMicException(e); } @@ -202,16 +209,18 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + MI._assertYield.call(_t); + var cb=MI._getCb(arguments,_t._event.onFormat); _t._lc=CLASS.format; var mode=i_mode?i_mode:0; MI.assertInt([i_bits,mode]); return _t._mcu.rpc(_t.RPC_NS+":format",_t._oid+","+i_bits+","+mode, - function(j){ - if(_t._event.onFormat){_t._event.onFormat();} - if(_t._gen){_t._gen.next();} - _t._lc=null; - }); + function(j){ + if(cb){cb();} + if(_t._gen){_t._gen.next();} + _t._lc=null; + } + ); }catch(e){ throw new MI.MiMicException(e); } diff --git a/misc/mbedJS/mbddJS.API/mbedJS/mbed.SPISlave.js b/misc/mbedJS/mbddJS.API/mbedJS/mbed.SPISlave.js index 97a2f4d..04578c0 100644 --- a/misc/mbedJS/mbddJS.API/mbedJS/mbed.SPISlave.js +++ b/misc/mbedJS/mbddJS.API/mbedJS/mbed.SPISlave.js @@ -15,8 +15,8 @@ var MI=MiMicJS; * @param {[PinName,PinName,PinName]} i_params * SPIãæ§æãã4ã¤ã®PinNameãæ ¼ç´ããé åã§ãã * mosi, miso, sclkã®é çªã§è¨å®ãã¾ãã - * @param {HashMap|Generator} i_event - * éåæã¤ãã³ããã³ãã©ã®é£æ³é åãåã¯Generatorã§ãã + * @param {HashMap|Generator|function} i_handler + * éåæã¤ãã³ããã³ãã©ã®é£æ³é åãGeneratorãã³ã¼ã«ããã¯é¢æ°ã®ä½ãããæå®ãã¾ãã ** éåæã¤ãã³ããã³ãã©ã®å ´åãé¢æ°ã¯ã¤ãã³ããã³ãã©ã§çµæãéç¥ãã¾ãã *
* Generatorãæå®ããå ´åãã³ã¼ã«ããã¯é¢æ°ã®å¼æ°ã¯yiledã®æ»ãå¤ã¨ãã¦åå¾ã§ãã¾ãã + *
*+ * ã³ã¼ã«ããã¯é¢æ°ãæå®ããå ´åãRPCãå®äºããã¨ãã«å¼ã³åºããã¾ããã¡ã³ãé¢æ°ã®ã¤ãã³ããã³ãã©ã¯åå¥ã«è¨å®ããå¿ è¦ãããã¾ãã + *
* @return {mbedJS.SPI} * @example //Callback * var mcu=new mbedJS.Mcu("192.168.128.39", @@ -104,17 +107,17 @@ var CLASS=function SPISlave(i_mcu,i_params,i_handler) var _t=this; _t._mcu=i_mcu; _t._lc=CLASS; - if(MI.isGenerator(i_handler)){_t._gen=i_handler;} - else if(i_handler){_t._event=i_handler} - function cb(j) - { - _t._oid=j.result[0]; - if(_t._event.onNew){_t._event.onNew();} - if(_t._gen){_t._gen.next(_t);} - _t._lc=null; - } + var cb=MI._initHandler.call(_t,i_handler); MI.assertInt(i_params); - return _t._mcu.rpc(_t.RPC_NS+":_new1",i_params[0]+","+i_params[1]+","+i_params[2]+","+i_params[3],cb); + _t._mcu.rpc(_t.RPC_NS+":_new1",i_params[0]+","+i_params[1]+","+i_params[2]+","+i_params[3], + function(j) + { + _t._oid=j.result[0]; + if(cb){cb();} + if(_t._gen){_t._gen.next(_t);} + _t._lc=null; + } + ); }catch(e){ throw new MI.MiMicException(e); } @@ -162,12 +165,13 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + MI._assertYield.call(_t); + var cb=MI._getCb(arguments,_t._event.onFrequency); _t._lc=CLASS.frequency; MI.assertInt(i_value); return _t._mcu.rpc(_t.RPC_NS+":frequency",_t._oid+","+i_value, function(j){ - if(_t._event.onFrequency){_t._event.onFrequency();} + if(cb){cb();} if(_t._gen){_t._gen.next();} _t._lc=null; }); @@ -191,13 +195,14 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + MI._assertYield.call(_t); + var cb=MI._getCb(arguments,_t._event.onFormat); _t._lc=CLASS.format; var mode=i_mode?i_mode:0; MI.assertInt([i_bits,mode]); return _t._mcu.rpc(_t.RPC_NS+":format",_t._oid+","+i_bits+","+mode, function(j){ - if(_t._event.onFormat){_t._event.onFormat();} + if(cb){cb();} if(_t._gen){_t._gen.next();} _t._lc=null; }); @@ -220,13 +225,14 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + MI._assertYield.call(_t); + var cb=MI._getCb(arguments,_t._event.onRead); _t._lc=CLASS.read; return _t._mcu.rpc(_t.RPC_NS+":read",_t._oid, function (j) { var v=j.result[0]; - if(_t._event.onRead){_t._event.onRead(v);} + if(cb){cb(v);} if(_t._gen){_t._gen.next(v);} _t._lc=null; }); @@ -249,13 +255,14 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + MI._assertYield.call(_t); + var cb=MI._getCb(arguments,_t._event.onReceive); _t._lc=CLASS.receive; return _t._mcu.rpc(_t.RPC_NS+":receive",_t._oid, function (j) { var v=j.result[0]; - if(_t._event.onReceive){_t._event.onReceive(v);} + if(cb){cb(v);} if(_t._gen){_t._gen.next(v);} _t._lc=null; }); @@ -278,13 +285,14 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + MI._assertYield.call(_t); + var cb=MI._getCb(arguments,_t._event.onReply); _t._lc=CLASS.reply; MI.assertInt(i_value); return _t._mcu.rpc(_t.RPC_NS+":reply",_t._oid+","+i_value, function (j) { - if(_t._event.onReply){_t._event.onReply();} + if(cb){cb();} if(_t._gen){_t._gen.next();} _t._lc=null; }); diff --git a/misc/mbedJS/mbddJS.API/mbedJS/mbed.Serial.js b/misc/mbedJS/mbddJS.API/mbedJS/mbed.Serial.js index 0f6e0fb..84d1ed0 100644 --- a/misc/mbedJS/mbddJS.API/mbedJS/mbed.Serial.js +++ b/misc/mbedJS/mbddJS.API/mbedJS/mbed.Serial.js @@ -14,8 +14,8 @@ var MI=MiMicJS; * ã¤ã³ã¹ã¿ã³ã¹ããã¤ã³ãããMCUãªãã¸ã§ã¯ãã§ãã * @param {[PinName,PinName]} i_params * UARTãæ§æããï¼æ¬ã®ãã³ãæå®ãã¾ããtx,rxã®é ã§è¨å®ãã¾ãã - * @param {HashMap|Generator} i_event - * éåæã¤ãã³ããã³ãã©ã®é£æ³é åãåã¯Generatorã§ãã + * @param {HashMap|Generator|function} i_handler + * éåæã¤ãã³ããã³ãã©ã®é£æ³é åãGeneratorãã³ã¼ã«ããã¯é¢æ°ã®ä½ãããæå®ãã¾ãã ** éåæã¤ãã³ããã³ãã©ã®å ´åãé¢æ°ã¯ã¤ãã³ããã³ãã©ã§çµæãéç¥ãã¾ãã *
* Generatorãæå®ããå ´åãã³ã¼ã«ããã¯é¢æ°ã®å¼æ°ã¯yiledã®æ»ãå¤ã¨ãã¦åå¾ã§ãã¾ãã + *
*+ * ã³ã¼ã«ããã¯é¢æ°ãæå®ããå ´åãRPCãå®äºããã¨ãã«å¼ã³åºããã¾ããã¡ã³ãé¢æ°ã®ã¤ãã³ããã³ãã©ã¯åå¥ã«è¨å®ããå¿ è¦ãããã¾ãã + *
* @return {mbedJS.Serial} * @example //Callback * var mcu=new mbedJS.Mcu("192.168.128.39", @@ -146,19 +149,21 @@ var CLASS=function Serial(i_mcu,i_params,i_handler) { try{ var _t=this; + var cb; _t._mcu=i_mcu; _t._lc=CLASS; - if(MI.isGenerator(i_handler)){_t._gen=i_handler;} - else if(i_handler){_t._event=i_handler} - function cb(j) - { - _t._oid=j.result[0]; - if(_t._event.onNew){_t._event.onNew();} - if(_t._gen){_t._gen.next(_t);} - _t._lc=null; - } + //ãã³ãã©ã®åæå + var cb=MI._initHandler.call(_t,i_handler); MI.assertInt(i_params); - _t._mcu.rpc(_t.RPC_NS+":_new1",i_params[0]+","+i_params[1],cb); + _t._mcu.rpc(_t.RPC_NS+":_new1",i_params[0]+","+i_params[1], + function(j) + { + _t._oid=j.result[0]; + if(cb){cb();} + if(_t._gen){_t._gen.next(_t);} + _t._lc=null; + } + ); }catch(e){ throw new MI.MiMicException(e); } @@ -218,17 +223,18 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + MI._assertYield.call(_t); + var cb=MI._getCb(arguments,_t._event.onFormat); _t._lc=CLASS.format; var p=[MI.isUndefined(i_bits,8),MI.isUndefined(i_parity,_t.Parity.None),MI.isUndefined(i_stop_bits,1)]; MI.assertInt(p); return _t._mcu.rpc(_t.RPC_NS+":format",_t._oid+","+p[0]+","+p[1]+","+p[2], - function (j) - { - if(_t._event.onFormat){_t._event.onFormat();} - if(_t._gen){_t._gen.next();} - _t._lc=null; - } + function (j) + { + if(cb){cb();} + if(_t._gen){_t._gen.next();} + _t._lc=null; + } ); }catch(e){ throw new MI.MiMicException(e); @@ -249,16 +255,17 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + MI._assertYield.call(_t); + var cb=MI._getCb(arguments,_t._event.onReadable); _t._lc=CLASS.readable; return _t._mcu.rpc(_t.RPC_NS+":readable",_t._oid, - function (j) - { - var v=j.result[0]; - if(_t._event.onReadable){_t._event.onReadable(v);} - if(_t._gen){_t._gen.next(v);} - _t._lc=null; - } + function (j) + { + var v=j.result[0]; + if(cb){cb(v);} + if(_t._gen){_t._gen.next(v);} + _t._lc=null; + } ); }catch(e){ throw new MI.MiMicException(e); @@ -279,16 +286,17 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + MI._assertYield.call(_t); + var cb=MI._getCb(arguments,_t._event.onWriteable); _t._lc=CLASS.writeable; return _t._mcu.rpc(_t.RPC_NS+":writeable",_t._oid, - function (j) - { - var v=j.result[0]?true:false; - if(_t._event.onWriteable){_t._event.onWriteable(v);} - if(_t._gen){_t._gen.next(v);} - _t._lc=null; - } + function (j) + { + var v=j.result[0]?true:false; + if(cb){cb(v);} + if(_t._gen){_t._gen.next(v);} + _t._lc=null; + } ); }catch(e){ throw new MI.MiMicException(e); @@ -307,15 +315,16 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + MI._assertYield.call(_t); + var cb=MI._getCb(arguments,_t._event.onSend_break); _t._lc=CLASS.send_break; return _t._mcu.rpc(_t.RPC_NS+":send_break",_t._oid, - function (j) - { - if(_t._event.onSend_break){_t._event.onSend_break();} - if(_t._gen){_t._gen.next();} - _t._lc=null; - } + function (j) + { + if(cb){cb();} + if(_t._gen){_t._gen.next();} + _t._lc=null; + } ); }catch(e){ throw new MI.MiMicException(e); @@ -336,17 +345,18 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + MI._assertYield.call(_t); + var cb=MI._getCb(arguments,_t._event.onPutc); _t._lc=CLASS.putc; MI.assertInt(i_c); return _t._mcu.rpc(_t.RPC_NS+":putc",_t._oid+","+i_c, - function (j) - { - var v=j.result[0]; - if(_t._event.onPutc){_t._event.onPutc(v);} - if(_t._gen){_t._gen.next(v);} - _t._lc=null; - } + function (j) + { + var v=j.result[0]; + if(cb){cb(v);} + if(_t._gen){_t._gen.next(v);} + _t._lc=null; + } ); }catch(e){ throw new MI.MiMicException(e); @@ -367,16 +377,17 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + MI._assertYield.call(_t); + var cb=MI._getCb(arguments,_t._event.onPuts); _t._lc=CLASS.puts; return _t._mcu.rpc(_t.RPC_NS+":puts",_t._oid+",\""+i_s+"\"", - function (j) - { - var v=j.result[0]; - if(_t._event.onPuts){_t._event.onPuts(v);} - if(_t._gen){_t._gen.next(v);} - _t._lc=null; - } + function (j) + { + var v=j.result[0]; + if(cb){cb(v);} + if(_t._gen){_t._gen.next(v);} + _t._lc=null; + } ); }catch(e){ throw new MI.MiMicException(e); @@ -397,16 +408,17 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + MI._assertYield.call(_t); + var cb=MI._getCb(arguments,_t._event.onGetc); _t._lc=CLASS.getc; return _t._mcu.rpc(_t.RPC_NS+":getc",_t._oid, - function (j) - { - var v=j.result[0]; - if(_t._event.onGetc){_t._event.onGetc(v);} - if(_t._gen){_t._gen.next(v);} - _t._lc=null; - } + function (j) + { + var v=j.result[0]; + if(cb){cb(v);} + if(_t._gen){_t._gen.next(v);} + _t._lc=null; + } ); }catch(e){ throw new MI.MiMicException(e); @@ -429,17 +441,18 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + MI._assertYield.call(_t); + var cb=MI._getCb(arguments,_t._event.onGets); _t._lc=CLASS.gets; MI.assertInt(i_len); return _t._mcu.rpc(_t.RPC_NS+":gets",_t._oid+","+i_len, - function (j) - { - var v=j.result[0]; - if(_t._event.onGets){_t._event.onGets(v);} - if(_t._gen){_t._gen.next(v);} - _t._lc=null; - } + function (j) + { + var v=j.result[0]; + if(cb){cb(v);} + if(_t._gen){_t._gen.next(v);} + _t._lc=null; + } ); }catch(e){ throw new MI.MiMicException(e); @@ -460,16 +473,17 @@ CLASS.prototype= { try{ var _t=this; - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} + MI._assertYield.call(_t); + var cb=MI._getCb(arguments,_t._event.onBaud); _t._lc=CLASS.baud; MI.assertInt(i_baudrate); return _t._mcu.rpc(_t.RPC_NS+":baud",_t._oid+","+i_baudrate, - function (j) - { - if(_t._event.onBaud){_t._event.onBaud();} - if(_t._gen){_t._gen.next();} - _t._lc=null; - } + function (j) + { + if(cb){cb();} + if(_t._gen){_t._gen.next();} + _t._lc=null; + } ); }catch(e){ throw new MI.MiMicException(e); diff --git a/misc/mbedJS/mbddJS.API/test.AnalogIn.html b/misc/mbedJS/mbddJS.API/test.AnalogIn.html index 75d281e..d45c695 100644 --- a/misc/mbedJS/mbddJS.API/test.AnalogIn.html +++ b/misc/mbedJS/mbddJS.API/test.AnalogIn.html @@ -62,6 +62,35 @@ function async() }); } +function async2() +{ + log(); + log("ASYNC2"); + var mcu=new mbedJS.Mcu("192.168.128.39", + { + onNew:function(){ + var pin=new mbedJS.AnalogIn(mcu,mbedJS.PinName.A0, + function(){ + log("[PASS]onNew"); + pin.read(function(v) + { + log("[PASS]onread:"+v); + pin.read_u16(function(v){ + log("[PASS]onRead_u16:"+v); + mcu.close(); + }); + }); + }); + }, + onClose:function(){ + log("[PASS]onClose"); + }, + onError:function(){ + alert("Error"); + } + }); +} + /** * 誤ã£ã使ç¨æ¹æ³ã§Exceptionãåºãå ´åã«ã·ã£ãããã¦ã³ã§ãããã®ãã¹ã */ @@ -101,6 +130,7 @@ function sync()