Espruino/libs/js/rak/RAK8212.min.js
2023-06-13 09:22:21 +01:00

5 lines
2.4 KiB
JavaScript

var p=D2,q=D3,r=D4,t=D5,k=D6,u=D7,v=D9,w=D10,x=D11,y=D13,l=D15,z=D16,m=D17,A=D18,B=D19,C=D26,D=D22,F=D23,G=D25;exports.setEnvOn=function(a,b){this.BME280&&this.BME280.setPower(!1);delete this.BME280;if(a)return a=new SPI,a.setup({miso:t,mosi:q,sck:r}),b&&setTimeout(b,100,this.BME280),this.BME280=require("BME280").connectSPI(a,p)};exports.setMagOn=function(a,b){this.LIS2MDL&&this.LIS2MDL.off();delete this.LIS2MDL;if(a)return a=new I2C,a.setup({sda:y,scl:x}),b&&setTimeout(b,
100,this.LIS2MDL),this.LIS2MDL=require("LIS2MDL").connectI2C(a,{int:z})};exports.setAccelOn=function(a,b){this.LIS3DH&&this.LIS3DH.off();delete this.LIS3DH;if(a)return a=new I2C,a.setup({sda:B,scl:A}),b&&setTimeout(b,100,this.LIS3DH),this.LIS3DH=require("LIS3DH").connectI2C(a,{int:G})};exports.setOptoOn=function(a,b){this.OPT3001&&this.OPT3001.off();delete this.OPT3001;if(a)return a=new I2C,a.setup({sda:C,scl:F,bitrate:4E5}),b&&setTimeout(b,1E3,this.OPT3001),this.OPT3001=require("OPT3001").connectI2C(a,
{int:D})};exports.setCellOn=function(a,b){if(a)if(this.cellOn)setTimeout(b,10,Serial1);else return(new Promise(function(e){Serial1.removeAllListeners();Serial1.on("data",function(f){});Serial1.setup(115200,{tx:v,rx:u,cts:w});k.reset();setTimeout(e,200)})).then(function(){k.set();return new Promise(function(e){setTimeout(e,200)})}).then(function(){l.set();return new Promise(function(e){setTimeout(e,2E3)})}).then(function(){l.reset();return new Promise(function(e){setTimeout(e,5E3)})}).then(function(){this.cellOn=
!0;Serial1.removeAllListeners();b&&setTimeout(b,10,Serial1)});else this.cellOn=!1,k.reset(),b&&setTimeout(b,1E3)};exports.setCharging=function(a){m.write(!a)};exports.setCharging=function(a){m.write(!a)};exports.setGPSOn=function(a,b){a?this.setCellOn(a,function(e){var f=require("AT").connect(e),n={at:f,on:function(d){d=d||function(){};f.cmd("AT+QGPS=1\r\n",1E3,function g(c){if(c&&c.startsWith("AT+"))return g;d("OK"==c?null:c)})},off:function(d){d=d||function(){};f.cmd("AT+QGPSEND\r\n",1E3,function g(c){if(c&&
c.startsWith("AT+"))return g;d("OK"==c?null:c)})},get:function(d){d=d||function(){};f.cmd("AT+QGPSLOC=2\r\n",1E3,function g(c){if(c){if(c.startsWith("AT+"))return g;if(c.startsWith("+CME ERROR:"))d({error:c.substr(5)});else if(c.startsWith("+QGPSLOC:")){c=c.substr(9).trim();var h=c.split(",");d({raw:c,UTC:h[0],lat:+h[1],lon:+h[2],alt:+h[4]})}else d({error:c})}else d({error:"Timeout"})})}};n.on(function(d){b(d,d?void 0:n)})}):this.setCellOn(!1,b)}