当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript ionic-native.BLE类代码示例

本文整理汇总了TypeScript中ionic-native.BLE的典型用法代码示例。如果您正苦于以下问题:TypeScript BLE类的具体用法?TypeScript BLE怎么用?TypeScript BLE使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了BLE类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: bleToggleMobileBLE

 bleToggleMobileBLE(value) {
   if (value) {
     if (this.bledevice) {
       BLE.disconnect(this.bledevice).then(() => {
         this.datastream.push('Disconnected');
         console.log('Disconnected');
       });
     }
     BLE.startScan([]).subscribe(
       device => {
         console.log(device.json());
         this.datastream.push("subscribe ok:" + JSON.stringify(device.json()));
         this.devices.push(device.json());
       },
       err => {
         this.datastream.push("subscribe err:" + JSON.stringify(err));
         console.error(err);
       }
     );
     setTimeout(() => {
       BLE.stopScan().then(() => { 
         this.blescan = false;
         this.datastream.push('scan stopped');
         console.log('scan stopped'); 
       });
     }, 60000);
   } else {
     BLE.stopScan().then(() => { 
       this.datastream.push('scan stopped');
       console.log('scan stopped'); 
     });
   }
 }
开发者ID:maxamillion32,项目名称:fleetany-mobile,代码行数:33,代码来源:bluetooth.ts

示例2: checkExistingBluetooth

    /* On page load, we want the status to reflect if the device is connected already */
    checkExistingBluetooth() {
	if (this.peripheral) {
            return BLE.isConnected(this.peripheral.id);
	}
	/* Should always be a rejected Promise */
	else return BLE.isConnected(null);
    }
开发者ID:mdash-ursi2016,项目名称:ionic_code_typescript,代码行数:8,代码来源:blservice.ts

示例3: alert

	    BLE.isConnected(periphID).then(() => {

		/* Reset subscriptions so if anything requests them they are null */
		this.HRSubscription = this.EKGSubscription = this.HRBundleSubscription =
		    this.dateCheckSubscription = this.stepSubscription = null;
		
		BLE.stopNotification(periphID, this.scanInfo.service, this.scanInfo.heartrate).then();
		BLE.stopNotification(periphID, this.scanInfo.service, this.scanInfo.ekg).then();
		BLE.stopNotification(periphID, this.scanInfo.service, this.scanInfo.heartratebundle).then();

		BLE.disconnect(periphID).then(() => {
		}, () => {
		    /* Never seems to fire with current version of BLE... */
		    alert("Unsuccessful disconnect");
		});
	    }, () => {
开发者ID:mdash-ursi2016,项目名称:ionic_code_typescript,代码行数:16,代码来源:blservice.ts

示例4: setTimeout

 setTimeout(() => {
   BLE.stopScan().then(() => { 
     this.blescan = false;
     this.datastream.push('scan stopped');
     console.log('scan stopped'); 
   });
 }, 60000);
开发者ID:maxamillion32,项目名称:fleetany-mobile,代码行数:7,代码来源:bluetooth.ts

示例5: connect

    /* Connect to the given device, and set the peripheral for later */
    connect(peripheral) {
	Vibration.vibrate(100);
	let connectSub = BLE.connect(peripheral.id).subscribe(result => {
	    this.storage.storePeripheral(peripheral.id);
	    this.peripheral = peripheral;
            this.connected(peripheral);
        }, error => {
	    console.log("Peripheral was disconnected.");
	    this.disconnect();
	});
    }
开发者ID:mdash-ursi2016,项目名称:ionic_code_typescript,代码行数:12,代码来源:blservice.ts

示例6: sendDate

    /* Inform the peripheral of the current date */
    sendDate(peripheral) {

	/* Data must be sent through the BLE plugin as an ArrayBuffer */
	let uint8 = new Uint8Array(4);

	/* Grab the current time without milliseconds */
	let time = Math.floor((new Date).getTime() / 1000);

	/* Store the time in 4 byte increments */
	uint8[0] = time & 0xFF;
	uint8[1] = (time & 0xFF00) >>> 8;
	uint8[2] = (time & 0xFF0000) >>> 16;
	uint8[3] = (time & 0xFF000000) >>> 24;

	//console.log("Time sent: " + uint8);
	
	/* Write the data to the peripheral */
	BLE.write(peripheral.id, this.scanInfo.service, this.scanInfo.datecheck, uint8.buffer).then(
	    succ => console.log("Time written successfully"),
	    fail => console.log("Time not written successfully")
	);

    }
开发者ID:mdash-ursi2016,项目名称:ionic_code_typescript,代码行数:24,代码来源:blservice.ts

示例7: Uint8Array

	this.dateCheckSubscription.subscribe(buffer => {
	    let data = new Uint8Array(buffer);
	    
	    let curDate = this.calcDate(data[3],data[2],data[1],data[0]);
	    if (!this.lastDate)
		return;
	    
	    let uint8 = new Uint8Array(4);

	    let caughtUp = 0;
	    if (this.lastDate >= curDate)
		caughtUp = 1;

	    /* Send back an array of the boolean result */
	    for (let i = 0; i < 4; i++) {
		uint8[i] = caughtUp;
	    }

	    BLE.write(peripheral.id, this.scanInfo.service, this.scanInfo.datecheck, uint8.buffer).then(
		succ => {console.log("wrote back: " + uint8);},
		fail => {console.log("did not write back");}
	    );
	});
开发者ID:mdash-ursi2016,项目名称:ionic_code_typescript,代码行数:23,代码来源:blservice.ts

示例8: connected

    /* Record incoming data in storage */
    connected(peripheral) {

	/* Inform the peripheral of the current date */
	this.sendDate(peripheral);
	/* Subscription for the heart rate (BPM) */
	this.HRSubscription = BLE.startNotification(peripheral.id, this.scanInfo.service, this.scanInfo.heartrate);
	/* Subscription for the EKG data */
	this.EKGSubscription = BLE.startNotification(peripheral.id, this.scanInfo.service, this.scanInfo.ekg);
	/* Subscription for the bundle data */
	this.HRBundleSubscription = BLE.startNotification(peripheral.id, this.scanInfo.service, this.scanInfo.heartratebundle);
	/* Subscription for date verification */
	this.dateCheckSubscription = BLE.startNotification(peripheral.id, this.scanInfo.service, this.scanInfo.datecheck);
	/* Subscription for step count packages */
	this.stepSubscription = BLE.startNotification(peripheral.id, this.scanInfo.service, this.scanInfo.steps);
	/* Subscription for live step count */
	this.liveStepSubscription = BLE.startNotification(peripheral.id, this.scanInfo.service, this.scanInfo.livesteps);

	
	/* Subscribe to the BPM */
	this.HRSubscription.subscribe(buffer => {
	    let data = new Uint8Array(buffer);
	    
	    /* The bytes are in reverse order, so we bit shift them to form the date */
	    let date = this.calcDate(data[3],data[2],data[1],data[0]);

	    /* Record the last timestamp for data checking with peripheral */
	    this.lastDate = date;

	    console.log("Received a bpm package: " + date);

	    /* Store data (date * 1000 to account for milliseconds) */
	    this.storage.storeBPM(new Date(date * 1000),data[4]);
	    
	    /* Republish the data for the home page */
	    this.events.publish('bpm',data[4]);
	    
	    /* Post the data to the server */
	    //this.httpservice.makePostRequest(data[0],new Date(data[1] * 1000));
        });

	/* Subscribe to the EKG */
	this.EKGSubscription.subscribe(buffer => {
	    let data = new Uint8Array(buffer);
	    
	    /* Republish the data for the home page */
	    this.events.publish('ekg',data);
	});

	this.HRBundleSubscription.subscribe(buffer => {
	    let data = new Uint8Array(buffer);

	    /* BPMs are located every 5 indices */
	    let bpmArray = [data[4],data[9],data[14],data[19]];

	    /* Dates must be calculated in reverse order */
	    let dateArray = [
		this.calcDate(data[3],data[2],data[1],data[0]),
		this.calcDate(data[8],data[7],data[6],data[5]),
		this.calcDate(data[13],data[12],data[11],data[10]),
		this.calcDate(data[18],data[17],data[16],data[15])
	    ];

	    //console.log("Received a group data package: " + dateArray[0]);

	    /* Push all data points to storage 
	       (dates * 1000 for ms format ) */
	    for (let i=0; i < bpmArray.length; i++) {
		this.storage.storeBPM(new Date(dateArray[i] * 1000),bpmArray[i]);
	    }
	});

	/* Periodically, the peripheral may request a comparison from the last date
	   received to the current date to check if all data has arrived */
	this.dateCheckSubscription.subscribe(buffer => {
	    let data = new Uint8Array(buffer);
	    
	    let curDate = this.calcDate(data[3],data[2],data[1],data[0]);
	    if (!this.lastDate)
		return;
	    
	    let uint8 = new Uint8Array(4);

	    let caughtUp = 0;
	    if (this.lastDate >= curDate)
		caughtUp = 1;

	    /* Send back an array of the boolean result */
	    for (let i = 0; i < 4; i++) {
		uint8[i] = caughtUp;
	    }

	    BLE.write(peripheral.id, this.scanInfo.service, this.scanInfo.datecheck, uint8.buffer).then(
		succ => {console.log("wrote back: " + uint8);},
		fail => {console.log("did not write back");}
	    );
	});

	/* Step subscription contains a date, a time offset, and a number of steps */
	this.stepSubscription.subscribe(buffer => {
//.........这里部分代码省略.........
开发者ID:mdash-ursi2016,项目名称:ionic_code_typescript,代码行数:101,代码来源:blservice.ts

示例9: stopScan

    /* Stop scanning */
    stopScan() {
	BLE.stopScan().then(() => {});
    }
开发者ID:mdash-ursi2016,项目名称:ionic_code_typescript,代码行数:4,代码来源:blservice.ts

示例10: startScan

 /* Return the scan subscription */
 startScan() {
     return BLE.startScan([this.scanInfo.service]);
 }
开发者ID:mdash-ursi2016,项目名称:ionic_code_typescript,代码行数:4,代码来源:blservice.ts

示例11: enable

    /* Return a Promise for if Bluetooth was enabled or not */
    enable() {
	return BLE.enable();
    }
开发者ID:mdash-ursi2016,项目名称:ionic_code_typescript,代码行数:4,代码来源:blservice.ts

示例12: isEnabled

    /* Return a Promise for if Bluetooth is enabled or not */
    isEnabled() {
	return BLE.isEnabled();
    }
开发者ID:mdash-ursi2016,项目名称:ionic_code_typescript,代码行数:4,代码来源:blservice.ts

示例13: connectDevice

 public static connectDevice(deviceAddress:string):Observable<BLE> {
   alert("Connecting to device address: " + deviceAddress);
   return BLE.connect(deviceAddress);
 }
开发者ID:asyncsrc,项目名称:BLEChild,代码行数:4,代码来源:bluetooth.ts

示例14: scanDevices

 public static scanDevices() {
   return BLE.scan([], 1);
 }
开发者ID:asyncsrc,项目名称:BLEChild,代码行数:3,代码来源:bluetooth.ts


注:本文中的ionic-native.BLE类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。