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

add custom action for LED Strip #1044

Merged
merged 1 commit into from
Oct 5, 2020
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
9 changes: 9 additions & 0 deletions src/app/control/control.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Router } from '@angular/router';
import { ConfigService } from '../config/config.service';
import { OctoprintPrinterProfileAPI } from '../octoprint-api/printerProfileAPI';
import { OctoprintService } from '../octoprint.service';
import { EnclosureService } from '../plugin-service/enclosure.service';
import { PsuControlService } from '../plugin-service/psu-control.service';
import { PrinterService } from '../printer.service';
import { PrinterProfileService } from '../printerprofile.service';
Expand All @@ -29,6 +30,7 @@ export class ControlComponent {
private octoprintService: OctoprintService,
private configService: ConfigService,
private psuControlService: PsuControlService,
private enclosureService: EnclosureService,
private router: Router,
) {
this.printerProfile = {
Expand Down Expand Up @@ -121,6 +123,9 @@ export class ControlComponent {
default: {
if (command.includes('[!WEB]')) {
this.openIFrame(command.replace('[!WEB]', ''));
} else if (command.includes('[!NEOPIXEL]')) {
const values = command.replace('[!NEOPIXEL]', '').split(',');
this.setLEDColor(values[0], values[1], values[2], values[3]);
} else {
this.printerService.executeGCode(command);
}
Expand Down Expand Up @@ -178,6 +183,10 @@ export class ControlComponent {
this.iFrameURL = 'about:blank';
}, 500);
}

public setLEDColor(identifier: string, red: string, green: string, blue: string): void {
this.enclosureService.setLEDColor(Number(identifier), Number(red), Number(green), Number(blue));
}
}

interface ActionToConfirm {
Expand Down
36 changes: 36 additions & 0 deletions src/app/plugin-service/enclosure.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { NotificationService } from '../notification/notification.service';
})
export class EnclosureService {
private httpGETRequest: Subscription;
private httpPOSTRequest: Subscription;
private observable: Observable<TemperatureReading>;
private initialRequest = true;

Expand Down Expand Up @@ -56,6 +57,35 @@ export class EnclosureService {
public getObservable(): Observable<TemperatureReading> {
return this.observable;
}

public setLEDColor(identifier: number, red: number, green: number, blue: number): Promise<void> {
return new Promise((resolve, reject): void => {
const colorBody: EnclosureColorBody = {
red,
green,
blue,
};
if (this.httpPOSTRequest) {
this.httpPOSTRequest.unsubscribe();
}
console.log(colorBody);
console.log(identifier);
this.httpPOSTRequest = this.http
.patch(
this.configService.getURL('plugin/enclosure/neopixel/' + identifier).replace('/api', ''),
colorBody,
this.configService.getHTTPHeaders(),
)
.subscribe(
(): void => resolve(),
(error: HttpErrorResponse): void => {
console.log(error.message);
this.notificationService.setError("Can't set LED color!", error.message);
reject();
},
);
});
}
}

interface EnclosurePluginAPI {
Expand All @@ -80,3 +110,9 @@ interface EnclosurePluginAPI {
use_fahrenheit: boolean;
gpio_pin: string;
}

interface EnclosureColorBody {
red: number;
green: number;
blue: number;
}
3 changes: 3 additions & 0 deletions src/app/plugin-service/filament-manager.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ export class FilamentManagerService {
spool: spool,
},
};
if (this.httpPOSTRequest) {
this.httpPOSTRequest.unsubscribe();
}
this.httpPOSTRequest = this.http
.patch(
this.configService.getURL('plugin/filamentmanager/selections/0').replace('/api', ''),
Expand Down