Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/filament amount #21

Merged
merged 2 commits into from
Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ testem.log
.DS_Store
Thumbs.db

.vscode
.vscode

**/config.testing.json
9 changes: 8 additions & 1 deletion src/app/config/config.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { environment } from '../../environments/environment';

@Injectable({
providedIn: 'root'
Expand All @@ -8,13 +9,14 @@ export class ConfigService {
public config: Config;

constructor(private _http: HttpClient) {
this._http.get("assets/config.json").subscribe((config: Config) => this.config = config)
this._http.get(environment.config).subscribe((config: Config) => this.config = config)
}
}

export interface Config {
octoprint: Octoprint;
printer: Printer;
filament: Filament;
}

interface Octoprint {
Expand All @@ -25,4 +27,9 @@ interface Octoprint {

interface Printer {
name: string;
}

interface Filament {
thickness: number;
density: number;
}
8 changes: 6 additions & 2 deletions src/app/job-status.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class JobStatusService {
job = {
filename: data["job"]["file"]["display"].replace(".gcode", ""),
progress: Math.round((data["progress"]["filepos"] / data["job"]["file"]["size"]) * 100),
filamentAmount: data["job"]["filament"]["tool0"]["volume"],
filamentAmount: this.filamentLengthToAmount(data["job"]["filament"]["tool0"]["length"]),
timeLeft: {
value: this.timeConvert(data["progress"]["printTimeLeft"]),
unit: "h"
Expand Down Expand Up @@ -64,13 +64,17 @@ export class JobStatusService {
return this.layerProgress
}

public timeConvert(input: number): string {
private timeConvert(input: number): string {
let hours = (input / 60 / 60);
let rhours = Math.floor(hours);
let minutes = (hours - rhours) * 60;
let rminutes = Math.round(minutes);
return rhours + ":" + ("0" + rminutes).slice(-2)
}

private filamentLengthToAmount(filamentLength: number): number {
return Math.round((Math.PI * (this._configService.config.filament.thickness / 2) * filamentLength) * this._configService.config.filament.density / 100) / 10
}
}

interface Duration {
Expand Down
4 changes: 4 additions & 0 deletions src/assets/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@
},
"printer": {
"name": "NAME HERE"
},
"filament": {
"thickness": 0,
"density": 0
}
}
3 changes: 2 additions & 1 deletion src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const environment = {
production: true
production: true,
config: "assets/config.json"
};
3 changes: 2 additions & 1 deletion src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
// The list of file replacements can be found in `angular.json`.

export const environment = {
production: false
production: false,
config: "assets/config.testing.json"
};

/*
Expand Down