Skip to content

Commit

Permalink
Add support for Spool Manager (#2147)
Browse files Browse the repository at this point in the history
* Spool Manager Working

* add beta to spool manager
  • Loading branch information
UnchartedBull committed Aug 11, 2021
1 parent e762285 commit c7c6a0c
Show file tree
Hide file tree
Showing 18 changed files with 220 additions and 21 deletions.
4 changes: 2 additions & 2 deletions helper/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ function getConfigErrors() {
const errors = [];
validate.errors?.forEach(error => {
if (error.keyword === 'type') {
errors.push(`${error.dataPath} ${error.message}`);
errors.push(`${error.instancePath} ${error.message}`);
} else {
errors.push(`${error.dataPath === '' ? '.' : error.dataPath} ${error.message}`);
errors.push(`${error.instancePath === '' ? '/' : error.instancePath} ${error.message}`);
}
});
return errors;
Expand Down
12 changes: 12 additions & 0 deletions helper/config.schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ const configSchema = {
'displayLayerProgress',
'enclosure',
'filamentManager',
'spoolManager',
'preheatButton',
'printTimeGenius',
'psuControl',
Expand Down Expand Up @@ -166,6 +167,17 @@ const configSchema = {
},
},
},
spoolManager: {
$id: '#/properties/plugins/properties/spoolManager',
type: 'object',
required: ['enabled'],
properties: {
enabled: {
$id: '#/properties/plugins/properties/spoolManager/properties/enabled',
type: 'boolean',
},
},
},
preheatButton: {
$id: '#/properties/plugins/properties/preheatButton',
type: 'object',
Expand Down
5 changes: 4 additions & 1 deletion scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ elif [ ! -d $DIRECTORY ]; then
fi;

if [ $DIRECTORY != "-" ]; then
plugins=( 'OctoDash Companion' 'Display Layer Progress (mandatory)' 'Filament Manager' 'Preheat Button' 'Enclosure' 'Print Time Genius' 'Ultimaker Format Package' 'PrusaSlicer Thumbnails' 'TPLinkSmartPlug' 'Tasmota' 'TasmotaMQTT')
plugins=( 'OctoDash Companion' 'Display Layer Progress (mandatory)' 'Filament Manager' 'Spool Manager' 'Preheat Button' 'Enclosure' 'Print Time Genius' 'Ultimaker Format Package' 'PrusaSlicer Thumbnails' 'TPLinkSmartPlug' 'Tasmota' 'TasmotaMQTT')
checkbox_input "Which plugins should I install (you can also install them via the Octoprint UI)?" plugins selected_plugins
echo "Installing Plugins..."

Expand All @@ -716,6 +716,9 @@ if [ $DIRECTORY != "-" ]; then
if [[ " ${selected_plugins[@]} " =~ "Filament Manager" ]]; then
"$DIRECTORY"/bin/pip install -q --disable-pip-version-check "https://github.com/OllisGit/OctoPrint-FilamentManager/releases/latest/download/master.zip"
fi;
if [[ " ${selected_plugins[@]} " =~ "Spool Manager" ]]; then
"$DIRECTORY"/bin/pip install -q --disable-pip-version-check "https://github.com/OllisGit/OctoPrint-SpoolManager/releases/latest/download/master.zip"
fi;
if [[ " ${selected_plugins[@]} " =~ "Preheat Button" ]]; then
"$DIRECTORY"/bin/pip install -q --disable-pip-version-check "https://github.com/marian42/octoprint-preheat/archive/master.zip"
fi;
Expand Down
4 changes: 4 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import { EnclosureOctoprintService } from './services/enclosure/enclosure.octopr
import { EnclosureService } from './services/enclosure/enclosure.service';
import { FilamentManagerOctoprintService } from './services/filament/filament-manager.octoprint.service';
import { FilamentPluginService } from './services/filament/filament-plugin.service';
import { SpoolManagerOctoprintService } from './services/filament/spool-manager.octoprint.service';
import { FilesOctoprintService } from './services/files/files.octoprint.service';
import { FilesService } from './services/files/files.service';
import { JobOctoprintService } from './services/job/job.octoprint.service';
Expand Down Expand Up @@ -194,6 +195,9 @@ export function playerFactory(): LottiePlayer {
provide: FilamentPluginService,
deps: [ConfigService, HttpClient],
useFactory: (configService: ConfigService, httpClient: HttpClient) => {
if (configService.isSpoolManagerPluginEnabled()) {
return new SpoolManagerOctoprintService(configService, httpClient);
}
return new FilamentManagerOctoprintService(configService, httpClient);
},
},
Expand Down
22 changes: 12 additions & 10 deletions src/app/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,29 @@ export class AppService {

// list of all error following an upgrade
this.updateError = {
".printer should have required property 'zBabystepGCode'": config => (config.printer.zBabystepGCode = 'M290 Z'),
".plugins should have required property 'tpLinkSmartPlug'": config =>
"/printer should have required property 'zBabystepGCode'": config => (config.printer.zBabystepGCode = 'M290 Z'),
"/plugins should have required property 'tpLinkSmartPlug'": config =>
(config.plugins.tpLinkSmartPlug = { enabled: false, smartPlugIP: '127.0.0.1' }),
".plugins should have required property 'tasmota'": config =>
"/plugins should have required property 'tasmota'": config =>
(config.plugins.tasmota = { enabled: false, ip: '127.0.0.1', index: null }),
".plugins should have required property 'tasmotaMqtt'": config =>
"/plugins should have required property 'tasmotaMqtt'": config =>
(config.plugins.tasmotaMqtt = { enabled: false, topic: 'topic', relayNumber: null }),
".octodash should have required property 'previewProgressCircle'": config =>
"/octodash should have required property 'previewProgressCircle'": config =>
(config.octodash.previewProgressCircle = false),
".octodash should have required property 'turnOnPrinterWhenExitingSleep'": config => {
"/octodash should have required property 'turnOnPrinterWhenExitingSleep'": config => {
config.octodash.turnOnPrinterWhenExitingSleep = config.plugins.psuControl.turnOnPSUWhenExitingSleep ?? false;
delete config.plugins.psuControl.turnOnPSUWhenExitingSleep;
},
".octodash should have required property 'screenSleepCommand'": config =>
"/octodash should have required property 'screenSleepCommand'": config =>
(config.octodash.screenSleepCommand = 'xset dpms force standby'),
".octodash should have required property 'screenWakeupCommand'": config =>
"/octodash should have required property 'screenWakeupCommand'": config =>
(config.octodash.screenWakeupCommand = 'xset s off && xset -dpms && xset s noblank'),
".octodash should have required property 'invertAxisControl'": config =>
"/octodash should have required property 'invertAxisControl'": config =>
(config.octodash.invertAxisControl = { x: false, y: false, z: false }),
".printer should have required property 'disableExtruderGCode'": config =>
"/printer should have required property 'disableExtruderGCode'": config =>
(config.printer.disableExtruderGCode = 'M18 E'),
"/plugins must have required property 'spoolManager'": config =>
(config.plugins.spoolManager = { enabled: false }),
};
}

Expand Down
3 changes: 3 additions & 0 deletions src/app/config/config.default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export const defaultConfig: Config = {
filamentManager: {
enabled: true,
},
spoolManager: {
enabled: false,
},
preheatButton: {
enabled: true,
},
Expand Down
1 change: 1 addition & 0 deletions src/app/config/config.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ interface Plugins {
displayLayerProgress: Plugin;
enclosure: EnclosurePlugin;
filamentManager: Plugin;
spoolManager: Plugin;
preheatButton: Plugin;
printTimeGenius: Plugin;
psuControl: PSUControlPlugin;
Expand Down
8 changes: 6 additions & 2 deletions src/app/config/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,12 @@ export class ConfigService {
return this.config.plugins.preheatButton.enabled;
}

public isFilamentManagerEnabled(): boolean {
return this.config.plugins.filamentManager.enabled;
public isFilamentManagerUsed(): boolean {
return this.config.plugins.filamentManager.enabled || this.config.plugins.spoolManager.enabled;
}

public isSpoolManagerPluginEnabled(): boolean {
return this.config.plugins.spoolManager.enabled;
}

public getFeedLength(): number {
Expand Down
4 changes: 2 additions & 2 deletions src/app/config/invalid/invalid.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@

&__error-list {
margin-left: 2vw;
font-size: 3.6vw;
margin-top: 5vh;
list-style-type: disc;
font-family: 'Cousine', monospace;

& li {
margin-top: 2vh;
font-size: 2.8vw;
font-family: 'Cousine', monospace;

&::before {
content: '-';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
font-size: 0.8rem;
opacity: 0.7;
display: block;
text-overflow: ellipsis;
white-space: nowrap;
}

&-weight {
Expand Down
4 changes: 2 additions & 2 deletions src/app/filament/filament.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class FilamentComponent implements OnInit, OnDestroy {
}

public ngOnInit(): void {
if (this.configService.isFilamentManagerEnabled()) {
if (this.configService.isFilamentManagerUsed()) {
this.setPage(0);
} else {
this.setPage(1);
Expand All @@ -66,7 +66,7 @@ export class FilamentComponent implements OnInit, OnDestroy {
public decreasePage(): void {
if (this.page === 0) {
this.router.navigate(['/main-screen']);
} else if (this.page === 1 && this.configService.isFilamentManagerEnabled()) {
} else if (this.page === 1 && this.configService.isFilamentManagerUsed()) {
this.setPage(0);
} else if (this.page === 1) {
this.router.navigate(['/main-screen']);
Expand Down
2 changes: 1 addition & 1 deletion src/app/filament/heat-nozzle/heat-nozzle.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
>{{ selectedSpool.material }}</span
>
</div>
<span class="heating__information-name">{{ selectedSpool.displayName.split(' - ')[1] }}</span>
<span class="heating__information-name">{{ selectedSpool.name }}</span>
<span class="heating__information-vendor">{{ selectedSpool.vendor }}</span>
<div class="heating__information-offset-wrapper">
<span class="heating__information-offset-value">
Expand Down
2 changes: 2 additions & 0 deletions src/app/filament/heat-nozzle/heat-nozzle.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
font-size: 0.8rem;
opacity: 0.7;
display: block;
text-overflow: ellipsis;
white-space: nowrap;
}

&-vendor {
Expand Down
1 change: 1 addition & 0 deletions src/app/model/octoprint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export * from './socket.model';
export * from './plugins/display-layer-progress.model';
export * from './plugins/enclosure.model';
export * from './plugins/filament-manager.model';
export * from './plugins/spool-manager.model';
export * from './plugins/psucontrol.model';
export * from './plugins/tp-link.model';
export * from './plugins/tasmota.model';
Expand Down
66 changes: 66 additions & 0 deletions src/app/model/octoprint/plugins/spool-manager.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
export interface SpoolManagerSpoolList {
allSpools: Array<SpoolManagerSpool>;
selectedSpools: Array<SpoolManagerSpool>;
catalogs: SpoolManagerCatalogs;
templateSpool: SpoolManagerSpool;
totalItemCount: string;
}

interface SpoolManagerCatalogs {
labels: Array<string>;
materials: Array<string>;
vendors: Array<string>;
}

export interface SpoolManagerSelectionPut {
databaseId: number;
toolIndex: number;
}

export interface SpoolManagerSpool {
bedTemperature: number;
code: unknown;
color: string;
colorName: string;
cost: number;
costUnit: string;
created: string;
databaseId: number;
density: number;
diameter: number;
diameterTolerance: number;
displayName: string;
enclosureTemperature: number;
firstUse: string;
flowRateCompensation: number;
isActive: boolean;
isTemplate: boolean;
labels: string;
lastUse: string;
material: string;
materialCharacteristic: unknown;
noteDeltaFormat: string;
noteHtml: string;
noteText: string;
offsetBedTemperature: number;
offsetEnclosureTemperature: number;
offsetTemperature: number;
originator: unknown;
purchasedFrom: string;
purchasedOn: string;
remainingLength: string;
remainingLengthPercentage: string;
remainingPercentage: string;
remainingWeight: string;
spoolWeight: string;
temperature: number;
totalLength: number;
totalWeight: number;
updated: string;
usedLength: number;
usedLengthPercentage: string;
usedPercentage: string;
usedWeight: string;
vendor: string;
version: number;
}
2 changes: 1 addition & 1 deletion src/app/services/filament/filament.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class FilamentService {
private configService: ConfigService,
private filamentPluginService: FilamentPluginService,
) {
if (this.configService.isFilamentManagerEnabled()) {
if (this.configService.isFilamentManagerUsed()) {
this.loadSpools();
}
}
Expand Down
87 changes: 87 additions & 0 deletions src/app/services/filament/spool-manager.octoprint.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';

import { ConfigService } from '../../config/config.service';
import { FilamentSpool } from '../../model';
import { SpoolManagerSelectionPut, SpoolManagerSpool, SpoolManagerSpoolList } from '../../model/octoprint';
import { FilamentPluginService } from './filament-plugin.service';

@Injectable()
export class SpoolManagerOctoprintService implements FilamentPluginService {
public constructor(private configService: ConfigService, private http: HttpClient) {}

public getSpools(): Observable<Array<FilamentSpool>> {
return this.callSpoolManagerAPI('hideInactiveSpools', 0, 3000, 'lastUse', 'desc').pipe(
map((spools: SpoolManagerSpoolList): Array<FilamentSpool> => {
return spools.allSpools.map((spool: SpoolManagerSpool): FilamentSpool => {
return this.convertFilamentManagerSpool(spool);
});
}),
);
}

public getCurrentSpool(): Observable<FilamentSpool> {
return this.callSpoolManagerAPI('hideInactiveSpools', 0, 3000, 'lastUse', 'desc').pipe(
map((spools: SpoolManagerSpoolList): FilamentSpool => {
if (spools.selectedSpools.length > 0) {
return this.convertFilamentManagerSpool(spools.selectedSpools[0]);
} else {
return null;
}
}),
);
}

private callSpoolManagerAPI(
filterName: string,
from: number,
to: number,
sortColumn: string,
sortOrder: string,
): Observable<SpoolManagerSpoolList> {
return this.http.get<SpoolManagerSpoolList>(
this.configService.getApiURL('plugin/SpoolManager/loadSpoolsByQuery', false),
{
...this.configService.getHTTPHeaders(),
params: {
filterName,
from,
to,
sortColumn,
sortOrder,
},
},
);
}

private convertFilamentManagerSpool(spool: SpoolManagerSpool): FilamentSpool {
return {
color: spool.color ?? '#f5f6fa',
density: spool.density,
diameter: spool.diameter,
displayName: `${spool.vendor} - ${spool.displayName}`,
id: spool.databaseId,
material: spool.material,
name: spool.displayName,
temperatureOffset: spool.offsetTemperature ?? 0,
used: Number(spool.usedWeight),
vendor: spool.vendor,
weight: spool.totalWeight,
};
}

public setSpool(spool: FilamentSpool): Observable<void> {
const setSpoolBody: SpoolManagerSelectionPut = {
databaseId: spool.id,
toolIndex: 0,
};

return this.http.put<void>(
this.configService.getApiURL('plugin/SpoolManager/selectSpool', false),
setSpoolBody,
this.configService.getHTTPHeaders(),
);
}
}
12 changes: 12 additions & 0 deletions src/app/settings/settings.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,18 @@
</span>
<span class="settings__checkbox-descriptor" i18n="@@settings-filament-manager-enabled">enabled</span>
</div>

<span class="settings__heading-2" i18n="@@settings-spool-manager">Spool Manager (Beta)</span>
<div
class="settings__checkbox-container"
(click)="config.plugins.spoolManager.enabled = !config.plugins.spoolManager.enabled"
>
<span class="settings__checkbox">
<span class="settings__checkbox-checked" *ngIf="config.plugins.spoolManager.enabled"></span>
</span>
<span class="settings__checkbox-descriptor" i18n="@@settings-spool-manager-enabled">enabled</span>
</div>

<span class="settings__heading-2" i18n="@@settings-preheat-button">Preheat Button</span>
<div
class="settings__checkbox-container"
Expand Down

0 comments on commit c7c6a0c

Please sign in to comment.