This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component } from '@angular/core'; | |
@Component({ | |
moduleId: module.id, | |
selector: 'ns-bulb-control', | |
templateUrl: 'bulb-control.component.html', | |
styleUrls: ['bulb-control.component.css'] | |
}) | |
export class BulbControlComponent { | |
maxValue = 255; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<StackLayout> | |
<Label text="Magic Blue"></Label> | |
<Button (tap)="connectToMagicBlue()" | |
text="Connect"> | |
</Button> | |
<Slider [minValue]="minValue" | |
[maxValue]="maxValue" | |
[(ngModel)]="redValue"> | |
</Slider> | |
<Slider [minValue]="minValue" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class BleDevice { | |
constructor(public UUID: string, | |
public name: string, | |
public state: string) { } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fixPermission(): void { | |
bluetooth.hasCoarseLocationPermission() | |
.then((granted) => { | |
if (!granted) { | |
bluetooth.requestCoarseLocationPermission() | |
.then(() => console.log("Location permission requested")); | |
} | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scan(): Promise<any> { | |
return bluetooth.startScanning({ | |
serviceUUIDs: [], | |
seconds: 3, | |
onDiscovered: (device) => { | |
const bleDevice = new BleDevice(device.UUID, device.name, device.state); | |
this.bleDevicesAround.push(bleDevice); | |
} | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getMagicBlue(): BleDevice { | |
return this.bluetoothService.bleDevicesAround | |
.filter(d => d.name && d.name.indexOf('LEDBLE') > -1)[0]; | |
} | |
connectToMagicBlue() { | |
this.bluetoothService.scan().then(() => { | |
this.magicBlue = this.getMagicBlue(); | |
if (this.magicBlue) { | |
this.bluetoothService.connect(this.magicBlue.UUID) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
update(red: number, green: number, blue: number, white: number) { | |
const color = [86, red, green, blue, white, 240, 170].map(param => { | |
return this.convertToHexString(param); | |
}).join(","); | |
const updateMessage = this.getMessage(this.magicBlue.UUID, color); | |
this.bluetoothService.write(updateMessage); | |
} | |
getMessage(UUID: string, value: string): any { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
connectToMagicBlue() { | |
this.lightBulbCommandService.connectToMagicBlue(); | |
} | |
updateLightBulb() { | |
this.lightBulbCommandService.update(this.redValue, | |
this.greenValue, | |
this.blueValue, | |
this.whiteValue); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
detectChanges(title: string, name: string) { | |
if (title !== this.title) { | |
this.title = title; | |
this.myComponent.title = title; | |
} | |
if (name !== this.name) { | |
this.name = name; | |
this.myComponent.name = name; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let myStream$ = Rx.Observable.from([1, 2, 3]); | |
myStream$.subscribe(value => console.log(value)); | |
let newStream$ = Rx.Observable.interval(1000); | |
newStream$.subscribe(value => console.log(value)); | |
// Use .take to stop it | |
let foo$ = Rx.Observable.range(5, 10); | |
foo$.subscribe(value => console.log(value)); |
OlderNewer