UNPKG

@iotize/tap

Version:

IoTize Device client for Javascript

2 lines 7.21 kB
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("@iotize/tap/service/impl/variable"),require("@iotize/tap/service/impl/target"),require("@iotize/tap/service/impl/gpio"),require("@iotize/common/debug")):"function"==typeof define&&define.amd?define("@iotize/tap/gpio",["exports","@iotize/tap/service/impl/variable","@iotize/tap/service/impl/target","@iotize/tap/service/impl/gpio","@iotize/common/debug"],n):n(((e="undefined"!=typeof globalThis?globalThis:e||self).iotize=e.iotize||{},e.iotize.tap=e.iotize.tap||{},e.iotize.tap.gpio={}),e.iotize.tap.service.impl.variable,e.iotize.tap.service.impl.target,e.iotize.tap.service.impl.gpio,e.debug$1)}(this,(function(e,n,t,r,i){"use strict";var o=2147483648,a=64|n.VariableType.Data.INT8;function c(e,n){var t,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function c(o){return function(c){return function(o){if(t)throw new TypeError("Generator is already executing.");for(;a;)try{if(t=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,r=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=n.call(e,a)}catch(e){o=[6,e],r=0}finally{t=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,c])}}}Object.create;Object.create;var u=i.createDebugger("@iotize/tap/gpio"),s=[{index:0,name:"RST",connector:"Target.10"},{index:1,name:"TDI",connector:"Target.8"},{index:2,name:"TDO",connector:"Target.6"},{index:3,name:"SWDCK",connector:"Target.4"},{index:4,name:"SWDIO",connector:"Target.2"},{index:5,name:"SCL_FACTORYRST",connector:""},{index:6,name:"EXT_A2",connector:"PA1.2"},{index:7,name:"EXT_A3",connector:"PA1.3"},{index:8,name:"EXT_A4",connector:"PA1.4"},{index:9,name:"EXT_A5",connector:"PA1.5"},{index:10,name:"EXT_A6",connector:"PA1.6"},{index:11,name:"EXT_A7",connector:"PA1.7"},{index:12,name:"EXT_A8",connector:"PA1.8"},{index:13,name:"EXT_A9",connector:"PA1.9"},{index:14,name:"EXT_A10",connector:"PA1.10"},{index:15,name:"EXT_A11",connector:"PA1.11"},{index:16,name:"EXT_B2",connector:"PA2.2"},{index:17,name:"EXT_B3",connector:"PA2.3"},{index:18,name:"EXT_B4",connector:"PA2.4"},{index:19,name:"EXT_B5",connector:"PA2.5"},{index:20,name:"EXT_B6",connector:"PA2.6"},{index:21,name:"EXT_B7",connector:"PA2.7"},{index:22,name:"EXT_B8",connector:"PA2.8"},{index:23,name:"EXT_B9",connector:"PA2.9"},{index:24,name:"EXT_B10",connector:"PA2.10"},{index:25,name:"EXT_B11",connector:"PA2.11"}],d=function(e,n){return e-n};function f(e,n){void 0===n&&(n=!1);var t=(e=e.sort(d))[0],r=e[e.length-1];return{address:(n?o:0)|t,format:a,length:r-t+1}}function p(e){for(var n=e.map((function(e){return e.index})).sort(d),t=n[0],r=[],i=n[n.length-1],o=function(n,t){var i=e.find((function(e){return e.index==n}));r[t]=i?!0===i.value?1:!1===i.value?0:i.value:255},a=t,c=0;a<=i;a++,c++)o(a,c);return Uint8Array.from(r)}var l=this&&this.__awaiter||function(e,n,t,r){return new(t||(t=Promise))((function(i,o){function a(e){try{u(r.next(e))}catch(e){o(e)}}function c(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){var n;e.done?i(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(a,c)}u((r=r.apply(e,n||[])).next())}))},h=function(){function e(e){this.tap=e,this._cache={}}return e.prototype.getPinByIndex=function(e){return e in this._cache||(this._cache[e]=new v(this.tap,e)),this._cache[e]},e.prototype.readValues=function(e){return l(this,void 0,void 0,(function(){return c(this,(function(n){return[2,this._readMuliple(e||s.map((function(e){return e.index})),!1)]}))}))},e.prototype.readConfig=function(e){return l(this,void 0,void 0,(function(){return c(this,(function(n){return[2,this._readMuliple(e||s.map((function(e){return e.index})),!0)]}))}))},e.prototype._readMuliple=function(e,n){return l(this,void 0,void 0,(function(){var t,r;return c(this,(function(i){switch(i.label){case 0:return t=f(e,n),[4,this.tap.service.target.readAddress(t)];case 1:return r=i.sent().body(),[2,Array.from(r).map((function(e,r){return{index:t.address+r,value:n?e:!!e}}))]}}))}))},e.prototype.writeValues=function(e){return l(this,void 0,void 0,(function(){var n,t,r;return c(this,(function(i){switch(i.label){case 0:return"boolean"==typeof e&&(e=s.map((function(n){return{index:n.index,value:e}}))),n=e.map((function(e){return e.index})),t=f(n),r=p(e),[4,this.tap.service.target.writeAddress({data:r,info:t})];case 1:return i.sent().successful(),[2]}}))}))},e.prototype.writeConfig=function(e){return l(this,void 0,void 0,(function(){var n,t,r;return c(this,(function(i){switch(i.label){case 0:return"number"==typeof e&&(e=s.map((function(n){return{index:n.index,value:e}}))),n=e.map((function(e){return e.index})),t=f(n,!0),r=p(e),[4,this.tap.service.target.writeAddress({data:r,info:t})];case 1:return i.sent().successful(),[2]}}))}))},e}();function m(e){return(o|e)>>>0}var v=function(){function e(e,n){this.tap=e,this.index=n}return e.prototype.readConfig=function(){return l(this,void 0,void 0,(function(){return c(this,(function(e){switch(e.label){case 0:return u("Read config for pin="+this.index+"..."),[4,this.tap.service.target.readAddress({address:m(this.index),format:a,length:1})];case 1:return[2,e.sent().body()[0]]}}))}))},e.prototype.writeConfig=function(e){return l(this,void 0,void 0,(function(){return c(this,(function(n){switch(n.label){case 0:if(!(e.mode in r.GPIOMode))throw new Error("Unknown mode GPIO mode "+e.mode);return u("writeConfig on pin="+this.index,r.GPIOMode[e.mode]),[4,this.tap.service.target.writeAddress({data:Uint8Array.from([e.mode]),info:{address:m(this.index),format:a,length:1}})];case 1:return n.sent().successful(),[2]}}))}))},e.prototype.readValue=function(){return l(this,void 0,void 0,(function(){var e,n;return c(this,(function(t){switch(t.label){case 0:return[4,this.tap.service.target.readAddress({address:this.index,format:a,length:1})];case 1:if(1!==(e=t.sent().body()).length)throw new Error("Unexpected Tap response for read Address. Should be 1 byte but received "+e.length+" bytes");return n=!!e[0],u("Read value for pin="+this.index+" ==> "+n),[2,n]}}))}))},e.prototype.writeValue=function(e){return l(this,void 0,void 0,(function(){return c(this,(function(n){switch(n.label){case 0:return u("Write value on pin="+this.index+"; "+e),[4,this.tap.service.target.writeAddress({data:e?Uint8Array.from([1]):Uint8Array.from([0]),info:{address:this.index,format:a,length:1}})];case 1:return[2,n.sent().body()]}}))}))},e}();e.CONFIGURE_MASK=o,e.DIRECT_ACCESS_GPIO_FORMAT=a,e.GPIOManager=h,e.GPIOPin=v,e.GPIO_MAPPING=s,Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=iotize-tap-gpio.umd.min.js.map