|
|
|
@ -18,12 +18,22 @@ interface ApiStatus {
|
|
|
|
|
|
|
|
|
|
export class MonitorApi { |
|
|
|
|
private mockServer: boolean; |
|
|
|
|
private lastStatus: Status = null; |
|
|
|
|
private static api: MonitorApi = null; |
|
|
|
|
|
|
|
|
|
constructor() { |
|
|
|
|
this.mockServer = window.location.protocol == "file:"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async getStatus(): Promise<Status> { |
|
|
|
|
static get() { |
|
|
|
|
if(MonitorApi.api == null) |
|
|
|
|
MonitorApi.api = new MonitorApi(); |
|
|
|
|
return MonitorApi.api; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
getStatus() { return this.lastStatus; } |
|
|
|
|
|
|
|
|
|
async fetchStatus(): Promise<Status> { |
|
|
|
|
let apiStatus: ApiStatus; |
|
|
|
|
|
|
|
|
|
if(this.mockServer) { |
|
|
|
@ -43,12 +53,14 @@ export class MonitorApi {
|
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
this.lastStatus = { |
|
|
|
|
batteryVoltage: apiStatus.v / 1000, |
|
|
|
|
motorCurrent: apiStatus.c / 1000, |
|
|
|
|
speed: apiStatus.s / 1000, |
|
|
|
|
temperature: apiStatus.t / 10, |
|
|
|
|
altitude: apiStatus.alt / 1000 |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
return this.lastStatus; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|