-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(control schemes): display current port tasks
- Loading branch information
1 parent
0e442b2
commit 6a9a0de
Showing
13 changed files
with
195 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './port-command-task-summary.pipe'; |
21 changes: 21 additions & 0 deletions
21
...rol-schemes/port-command-task-summary/linear-port-command-task-summary-builder.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Observable } from 'rxjs'; | ||
import { TranslocoService } from '@ngneat/transloco'; | ||
import { SetLinearSpeedTaskPayload } from '@app/store'; | ||
|
||
@Injectable({ providedIn: 'root' }) | ||
export class LinearPortCommandTaskSummaryBuilderService { | ||
constructor( | ||
private readonly translocoService: TranslocoService | ||
) { | ||
} | ||
|
||
public build( | ||
payload: SetLinearSpeedTaskPayload | ||
): Observable<string> { | ||
if (payload.power !== 0 && payload.speed === 0) { | ||
return this.translocoService.selectTranslate('controlScheme.linearBrakeTaskSummary'); | ||
} | ||
return this.translocoService.selectTranslate('controlScheme.linearTaskSummary', payload); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/app/control-schemes/port-command-task-summary/port-command-task-summary.pipe.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { Pipe, PipeTransform } from '@angular/core'; | ||
import { Observable, filter, switchMap } from 'rxjs'; | ||
import { Store } from '@ngrx/store'; | ||
import { ATTACHED_IO_PROPS_SELECTORS, AttachedIoPropsModel, PortCommandTask, PortCommandTaskType } from '@app/store'; | ||
|
||
import { LinearPortCommandTaskSummaryBuilderService } from './linear-port-command-task-summary-builder.service'; | ||
import { ServoPortCommandTaskSummaryBuilderService } from './servo-port-command-task-summary-builder.service'; | ||
import { SetAnglePortCommandTaskSummaryBuilderService } from './set-angle-port-command-task-summary-builder.service'; | ||
import { StepperPortCommandTaskSummaryBuilderService } from './stepper-port-command-task-summary-builder.service'; | ||
|
||
@Pipe({ | ||
standalone: true, | ||
name: 'portCommandTaskSummary', | ||
pure: true | ||
}) | ||
export class PortCommandTaskSummaryPipe implements PipeTransform { | ||
constructor( | ||
private readonly linearPortCommandTaskSummaryBuilder: LinearPortCommandTaskSummaryBuilderService, | ||
private readonly setAnglePortCommandTaskSummaryBuilder: SetAnglePortCommandTaskSummaryBuilderService, | ||
private readonly servoPortCommandTaskSummaryBuilder: ServoPortCommandTaskSummaryBuilderService, | ||
private readonly stepperPortCommandTaskSummaryBuilder: StepperPortCommandTaskSummaryBuilderService, | ||
private readonly store: Store | ||
) { | ||
} | ||
|
||
public transform( | ||
portCommandTask: PortCommandTask | ||
): Observable<string> { | ||
const payload = portCommandTask.payload; | ||
switch (payload.taskType) { | ||
case PortCommandTaskType.SetSpeed: | ||
return this.linearPortCommandTaskSummaryBuilder.build(payload); | ||
case PortCommandTaskType.SetAngle: | ||
return this.store.select(ATTACHED_IO_PROPS_SELECTORS.selectById(portCommandTask)).pipe( | ||
filter((ioProps): ioProps is AttachedIoPropsModel => !!ioProps), | ||
switchMap((ioProps) => this.setAnglePortCommandTaskSummaryBuilder.build( | ||
ioProps, | ||
payload | ||
)) | ||
); | ||
case PortCommandTaskType.Servo: | ||
return this.store.select(ATTACHED_IO_PROPS_SELECTORS.selectById(portCommandTask)).pipe( | ||
filter((ioProps): ioProps is AttachedIoPropsModel => !!ioProps), | ||
switchMap((ioProps) => this.servoPortCommandTaskSummaryBuilder.build( | ||
ioProps, | ||
payload | ||
)) | ||
); | ||
case PortCommandTaskType.Stepper: | ||
return this.stepperPortCommandTaskSummaryBuilder.build(payload); | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...trol-schemes/port-command-task-summary/servo-port-command-task-summary-builder.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Observable } from 'rxjs'; | ||
import { TranslocoService } from '@ngneat/transloco'; | ||
import { AttachedIoPropsModel, ServoTaskPayload } from '@app/store'; | ||
|
||
@Injectable({ providedIn: 'root' }) | ||
export class ServoPortCommandTaskSummaryBuilderService { | ||
constructor( | ||
private readonly translocoService: TranslocoService | ||
) { | ||
} | ||
|
||
public build( | ||
attachedIoProps: AttachedIoPropsModel, | ||
payload: ServoTaskPayload | ||
): Observable<string> { | ||
const angle = (attachedIoProps.motorEncoderOffset ?? 0) + payload.angle; | ||
return this.translocoService.selectTranslate('controlScheme.servoTaskSummary', { angle }); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...-schemes/port-command-task-summary/set-angle-port-command-task-summary-builder.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Observable } from 'rxjs'; | ||
import { TranslocoService } from '@ngneat/transloco'; | ||
import { AttachedIoPropsModel, SetAngleTaskPayload } from '@app/store'; | ||
|
||
@Injectable({ providedIn: 'root' }) | ||
export class SetAnglePortCommandTaskSummaryBuilderService { | ||
constructor( | ||
private readonly translocoService: TranslocoService | ||
) { | ||
} | ||
|
||
public build( | ||
attachedIoProps: AttachedIoPropsModel, | ||
payload: SetAngleTaskPayload | ||
): Observable<string> { | ||
const angle = (attachedIoProps.motorEncoderOffset ?? 0) + payload.angle; | ||
return this.translocoService.selectTranslate('controlScheme.setAngleTaskSummary', { angle }); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...ol-schemes/port-command-task-summary/stepper-port-command-task-summary-builder.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Observable } from 'rxjs'; | ||
import { TranslocoService } from '@ngneat/transloco'; | ||
import { StepperTaskPayload } from '@app/store'; | ||
|
||
@Injectable({ providedIn: 'root' }) | ||
export class StepperPortCommandTaskSummaryBuilderService { | ||
constructor( | ||
private readonly translocoService: TranslocoService | ||
) { | ||
} | ||
|
||
public build( | ||
payload: StepperTaskPayload | ||
): Observable<string> { | ||
return this.translocoService.selectTranslate('controlScheme.stepperTaskSummary', payload); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters