Skip to content

Commit

Permalink
Support PWM Outputs of Enclosure Plug-In (#1848)
Browse files Browse the repository at this point in the history
* Also support PWM outputs of Enclosure plug-in.

* Adjusted duty cycle variable to camel case.

* Fixed build error.

* Run lint:fix.
  • Loading branch information
ab-tools committed May 26, 2021
1 parent de10c16 commit 1f15885
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/app/model/octoprint/plugins/enclosure.model.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable camelcase */

export interface EnclosurePluginAPI {
/* eslint-disable camelcase */
controlled_io: string;
temp_sensor_address: string;
temp_sensor_navbar: boolean;
Expand Down Expand Up @@ -30,3 +31,7 @@ export interface EnclosureColorBody {
export interface EnclosureOutputBody {
status: boolean;
}

export interface EnclosurePWMBody {
duty_cycle: number;
}
20 changes: 20 additions & 0 deletions src/app/services/enclosure/enclosure.octoprint.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
EnclosureColorBody,
EnclosureOutputBody,
EnclosurePluginAPI,
EnclosurePWMBody,
PSUControlCommand,
TasmotaCommand,
TasmotaMqttCommand,
Expand Down Expand Up @@ -84,6 +85,25 @@ export class EnclosureOctoprintService implements EnclosureService {
.subscribe();
}

setPWM(identifier: number, dutyCycle: number): void {
const pwmBody: EnclosurePWMBody = {
/* eslint-disable camelcase */
duty_cycle: dutyCycle,
};
this.http
.patch(
this.configService.getApiURL('plugin/enclosure/pwm/' + identifier, false),
pwmBody,
this.configService.getHTTPHeaders(),
)
.pipe(
catchError(error =>
this.notificationService.setError($localize`:@@error-set-output:Can't set output!`, error.message),
),
)
.subscribe();
}

setPSUState(state: PSUState): void {
if (this.configService.usePSUControl()) {
this.setPSUStatePSUControl(state);
Expand Down
2 changes: 2 additions & 0 deletions src/app/services/enclosure/enclosure.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export abstract class EnclosureService {

abstract setOutput(identifier: number, status: boolean): void;

abstract setPWM(identifier: number, dutyCycle: number): void;

abstract setPSUState(state: PSUState): void;

abstract togglePSU(): void;
Expand Down

0 comments on commit 1f15885

Please sign in to comment.