Skip to content

Commit

Permalink
Display layer progress api (#22)
Browse files Browse the repository at this point in the history
* Layers now working

* Fan Speed now working

* AppComponent config needs to be public
  • Loading branch information
UnchartedBull committed Jul 12, 2019
1 parent 737f5d1 commit 393a482
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 51 deletions.
2 changes: 1 addition & 1 deletion src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div *ngIf="_configService.config" class="container">
<div *ngIf="configService.config" class="container">
<app-job-status></app-job-status>
<app-printer-status></app-printer-status>
<app-layer-progress></app-layer-progress>
Expand Down
2 changes: 1 addition & 1 deletion src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { map } from 'rxjs/operators'
})

export class AppComponent {
constructor(private _configService: ConfigService) {
constructor(public configService: ConfigService) {
}
}

4 changes: 2 additions & 2 deletions src/app/bottom-bar/bottom-bar.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, OnInit } from '@angular/core';
import { ConfigService } from '../config/config.service';
import { PrinterStatusService, PrinterStatus } from '../printer-status.service';
import { PrinterStatusService, PrinterStatusAPI } from '../printer-status.service';

@Component({
selector: 'app-bottom-bar',
Expand All @@ -14,7 +14,7 @@ export class BottomBarComponent implements OnInit {


constructor(private _printerStatusService: PrinterStatusService, private _configService: ConfigService) {
this._printerStatusService.getPrinterStatusObservable().subscribe((printerStatus: PrinterStatus) => this.printer.status = printerStatus.status)
this._printerStatusService.getObservable().subscribe((printerStatus: PrinterStatusAPI) => this.printer.status = printerStatus.status)
}

ngOnInit() {
Expand Down
12 changes: 12 additions & 0 deletions src/app/display-layer-progress.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { TestBed } from '@angular/core/testing';

import { DisplayLayerProgressService } from './display-layer-progress.service';

describe('DisplayLayerProgressService', () => {
beforeEach(() => TestBed.configureTestingModule({}));

it('should be created', () => {
const service: DisplayLayerProgressService = TestBed.get(DisplayLayerProgressService);
expect(service).toBeTruthy();
});
});
49 changes: 49 additions & 0 deletions src/app/display-layer-progress.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Injectable } from '@angular/core';
import { Observable, Observer, timer } from 'rxjs';
import { HttpHeaders, HttpErrorResponse, HttpClient } from '@angular/common/http';
import { ConfigService } from './config/config.service';
import { share } from 'rxjs/operators';

@Injectable({
providedIn: 'root'
})
export class DisplayLayerProgressService {

observable: Observable<Object>

constructor(private _configService: ConfigService, private _http: HttpClient) {
this.observable = Observable.create((observer: Observer<any>) => {
timer(750, this._configService.config.octoprint.apiInterval).subscribe(_ => {
if (this._configService.config) {
const httpHeaders = {
headers: new HttpHeaders({
'x-api-key': this._configService.config.octoprint.accessToken
})
}
this._http.get(this._configService.config.octoprint.url + "plugin/DisplayLayerProgress", httpHeaders).subscribe(
(data: JSON) => {
observer.next({
current: data["layer"]["current"] === "-" ? 0 : data["layer"]["current"],
total: data["layer"]["total"] === "-" ? 0 : data["layer"]["total"],
fanSpeed: data["fanSpeed"] === "-" ? 0 : data["fanSpeed"]
})
}, (error: HttpErrorResponse) => {
console.error("Can't retrieve layerProgress! " + error.message)
})
}
})
}).pipe(share())
}


public getObservable(): Observable<Object> {
return this.observable
}

}

export interface DisplayLayerProgressAPI {
current: number;
total: number;
fanSpeed: number;
}
36 changes: 9 additions & 27 deletions src/app/job-status.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import { Injectable } from '@angular/core';
import { Observable, Observer, timer } from 'rxjs';
import { ConfigService } from './config/config.service';
import { HttpHeaders, HttpClient, HttpErrorResponse } from '@angular/common/http';
import { share } from 'rxjs/operators';

@Injectable({
providedIn: 'root'
})
export class JobStatusService {

jobInformation: Observable<Object>
layerProgress: Observable<Object>
observable: Observable<Object>

constructor(private _configService: ConfigService, private _http: HttpClient) {
this.jobInformation = Observable.create((observer: Observer<any>) => {
this.observable = Observable.create((observer: Observer<any>) => {
timer(1000, this._configService.config.octoprint.apiInterval).subscribe(_ => {
if (this._configService.config) {
const httpHeaders = {
Expand All @@ -39,29 +39,16 @@ export class JobStatusService {
}
}
observer.next(job);
}, ((error: HttpErrorResponse) => {
observer.next(null);
}))
}, (error: HttpErrorResponse) => {
console.log("Can't retrieve jobs! " + error.message)
})
}
})
})

this.layerProgress = Observable.create((observer: Observer<any>) => {
// TODO
let layerProgress = {
current: 0,
total: 0
}
observer.next(layerProgress)
})
}

public getJobInformationObservable(): Observable<Object> {
return this.jobInformation
}).pipe(share())
}

public getLayerProgressObservable(): Observable<Object> {
return this.layerProgress
public getObservable(): Observable<Object> {
return this.observable
}

private timeConvert(input: number): string {
Expand Down Expand Up @@ -89,8 +76,3 @@ export interface Job {
timeLeft: Duration;
timePrinted: Duration;
}

export interface LayerProgress {
current: number;
total: number;
}
2 changes: 1 addition & 1 deletion src/app/job-status/job-status.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ export class JobStatusComponent implements OnInit {
constructor(private _jobStatusService: JobStatusService) { }

ngOnInit() {
this._jobStatusService.getJobInformationObservable().subscribe((job: Job) => this.job = job);
this._jobStatusService.getObservable().subscribe((job: Job) => this.job = job);
}
}
18 changes: 15 additions & 3 deletions src/app/layer-progress/layer-progress.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, OnInit } from '@angular/core';
import { LayerProgress, JobStatusService } from '../job-status.service';
import { DisplayLayerProgressService, DisplayLayerProgressAPI } from '../display-layer-progress.service';

@Component({
selector: 'app-layer-progress',
Expand All @@ -10,11 +10,23 @@ export class LayerProgressComponent implements OnInit {

layerProgress: LayerProgress

constructor(private _jobStatusService: JobStatusService) {
this._jobStatusService.getLayerProgressObservable().subscribe((layerProgress: LayerProgress) => this.layerProgress = layerProgress);
constructor(private _displayLayerProgressService: DisplayLayerProgressService) {
this.layerProgress = {
current: 0,
total: 0
}
this._displayLayerProgressService.getObservable().subscribe((layerProgress: DisplayLayerProgressAPI) => {
this.layerProgress.current = layerProgress.current;
this.layerProgress.total = layerProgress.total;
});
}

ngOnInit() {
}

}

export interface LayerProgress {
current: number;
total: number;
}
20 changes: 8 additions & 12 deletions src/app/printer-status.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class PrinterStatusService {
}
this._http.get(this._configService.config.octoprint.url + "printer", httpHeaders).subscribe(
(data: JSON) => {
const printerStatus: PrinterStatus = {
const printerStatus: PrinterStatusAPI = {
status: data["state"]["text"].toLowerCase(),
nozzle: {
current: Math.round(data["temperature"]["tool0"]["actual"]),
Expand All @@ -31,12 +31,11 @@ export class PrinterStatusService {
heatbed: {
current: Math.round(data["temperature"]["bed"]["actual"]),
set: Math.round(data["temperature"]["bed"]["target"])
},
fan: 100
}
}
observer.next(printerStatus)
}, (error: HttpErrorResponse) => {
const printerStatus: PrinterStatus = {
const printerStatus: PrinterStatusAPI = {
status: `error (${error.status})`,
nozzle: {
current: 0,
Expand All @@ -45,8 +44,7 @@ export class PrinterStatusService {
heatbed: {
current: 0,
set: 0
},
fan: 0
}
}
observer.next(printerStatus)
})
Expand All @@ -55,20 +53,18 @@ export class PrinterStatusService {
}).pipe(share())
}

getPrinterStatusObservable(): Observable<Object> {
getObservable(): Observable<Object> {
return this.observable
}
}


export interface PrinterStatus {
status: string,
export interface PrinterStatusAPI {
status: string;
nozzle: PrinterValue;
heatbed: PrinterValue;
fan: number;
}

interface PrinterValue {
export interface PrinterValue {
current: number;
set: number;
}
33 changes: 29 additions & 4 deletions src/app/printer-status/printer-status.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component, OnInit } from '@angular/core';
import { PrinterStatusService, PrinterStatus } from '../printer-status.service';
import { PrinterStatusService, PrinterStatusAPI, PrinterValue } from '../printer-status.service';
import { DisplayLayerProgressService, DisplayLayerProgressAPI } from '../display-layer-progress.service';

@Component({
selector: 'app-printer-status',
Expand All @@ -8,12 +9,36 @@ import { PrinterStatusService, PrinterStatus } from '../printer-status.service';
})
export class PrinterStatusComponent implements OnInit {

printerStatus: PrinterStatus;
printerStatus: PrinterStatus

constructor(private _printerStatusService: PrinterStatusService) {
this._printerStatusService.getPrinterStatusObservable().subscribe((printerStatus: PrinterStatus) => this.printerStatus = printerStatus)
constructor(private _printerStatusService: PrinterStatusService, private _displayLayerProgressService: DisplayLayerProgressService) {
this.printerStatus = {
nozzle: {
current: 0,
set: 0
},
heatbed: {
current: 0,
set: 0
},
fan: 0
};
this._printerStatusService.getObservable().subscribe((printerStatus: PrinterStatusAPI) => {
this.printerStatus.nozzle = printerStatus.nozzle;
this.printerStatus.heatbed = printerStatus.heatbed;
})

this._displayLayerProgressService.getObservable().subscribe((layerProgress: DisplayLayerProgressAPI) => {
this.printerStatus.fan = layerProgress.fanSpeed
})
}

ngOnInit() { }

}

export interface PrinterStatus {
nozzle: PrinterValue;
heatbed: PrinterValue;
fan: number;
}

0 comments on commit 393a482

Please sign in to comment.