-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
170 additions
and
22 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
56 changes: 56 additions & 0 deletions
56
src/IotBbq.App/IotBbq.JsApp/src/app/services/BtThermometer.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { IThermometerService, ITemps, ThermometerState } from './contracts/IThermometerService'; | ||
|
||
import * as noble from 'noble'; | ||
import { XPlatService } from './XPlatService'; | ||
|
||
export class BtThermometer implements IThermometerService { | ||
|
||
private initializing = false; | ||
|
||
constructor(private xplat: XPlatService) { | ||
} | ||
|
||
public async readThermometer(probeNumber: number): Promise<ITemps> { | ||
if (!this.initializing) { | ||
this.initializing = true; | ||
await this.initializeRemote(); | ||
} | ||
|
||
return { | ||
celcius: 0, | ||
farenheight: 0, | ||
kelvin: 0, | ||
state: ThermometerState.Disconnected | ||
}; | ||
} | ||
|
||
private async powerOn(): Promise<void> { | ||
new Promise((resolve, reject) => { | ||
noble.on('stateChange', (state) => { | ||
console.log(`State change ${state}`); | ||
if (state === 'poweredOn') { resolve(); } | ||
if (state === 'poweredOff') { reject(new Error('Bluetooth failed to initialize.')); } | ||
}); | ||
}); | ||
} | ||
|
||
private async startScanning(): Promise<void> { | ||
return new Promise((resolve, reject) => { | ||
noble.startScanning((err) => { | ||
if (err) { | ||
return reject(err); | ||
} | ||
|
||
resolve(); | ||
}); | ||
}); | ||
} | ||
|
||
private async initializeRemote(): Promise<void> { | ||
console.log('PowerOn'); | ||
await this.powerOn(); | ||
console.log('StartScanning'); | ||
await this.startScanning(); | ||
console.log('Done'); | ||
} | ||
} |
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
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
19 changes: 19 additions & 0 deletions
19
src/IotBbq.App/IotBbq.JsApp/src/app/services/contracts/IThermometerService.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { InjectionToken } from '@angular/core'; | ||
|
||
export const THERM_SVC_TOKEN = new InjectionToken<IThermometerService>('THERM_SVC_TOKEN'); | ||
|
||
export enum ThermometerState { | ||
Disconnected, | ||
Connected, | ||
} | ||
|
||
export interface ITemps { | ||
state: ThermometerState; | ||
kelvin: number; | ||
celcius: number; | ||
farenheight: number; | ||
} | ||
|
||
export interface IThermometerService { | ||
readThermometer(probeNumber: number): Promise<ITemps>; | ||
} |