Skip to content

Commit

Permalink
Fix/filament amount (#21)
Browse files Browse the repository at this point in the history
* Created testing config

* Calculation Filament Amount from Length
  • Loading branch information
UnchartedBull authored Jul 12, 2019
1 parent 75aab63 commit 208d4f6
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 6 deletions.
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

0 comments on commit 208d4f6

Please sign in to comment.