Skip to content

Commit

Permalink
feat(controllers): add handset input support
Browse files Browse the repository at this point in the history
  • Loading branch information
nvsukhanov committed Aug 16, 2023
1 parent bb8cd3e commit ecaef58
Show file tree
Hide file tree
Showing 40 changed files with 398 additions and 230 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@ngrx/router-store": "^16.0.1",
"@ngrx/store": "^16.0.1",
"@ngrx/store-devtools": "^16.0.1",
"@nvsukhanov/rxpoweredup": "^0.0.33",
"@nvsukhanov/rxpoweredup": "^0.0.35",
"ngrx-store-localstorage": "^16.0.0",
"rxjs": "^7.8.1",
"tslib": "^2.5.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
<ng-container *ngIf="form">
<app-controller-select [controllerIdFormControl]="form.controls.controllerId"
[inputIdFormControl]="form.controls.inputId"
[operationMode]="linearHubIoOperationMode"
[inputTypeControl]="form.controls.inputType"
<app-controller-select [operationMode]="linearHubIoOperationMode"
[inputFormGroup]="form.controls.input"
[title]="'controlScheme.bindingGenericInputTitle' | transloco "
></app-controller-select>

<ng-container *ngIf="form.controls.controllerId.valid && form.controls.inputId.valid">
<ng-container *ngIf="form.controls.input.valid">
<app-binding-input-gain-select *ngIf="isInputGainConfigurable"
[control]="form.controls.inputGain"
[control]="form.controls.input.controls.gain"
></app-binding-input-gain-select>

<app-slider-control [min]="0"
Expand All @@ -23,7 +21,7 @@
[translocoTitle]="'controlScheme.outputPowerControlTitle'"
></app-slider-control>

<app-toggle-control *ngIf="form.controls.inputType.value === controllerInputButtonType"
<app-toggle-control *ngIf="isToggleable"
[translocoTitle]="'controlScheme.linearOutputConfigurationTreatAsSwitch'"
[control]="form.controls.isToggle"
></app-toggle-control>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,14 @@ export class BindingLinearEditComponent implements IBindingsDetailsEditComponent
) {
}

public get isToggleable(): boolean {
const inputType = this.form?.controls.input.controls.inputType.value;
return inputType === ControllerInputType.Button || inputType === ControllerInputType.ButtonGroup;
}

public get isInputGainConfigurable(): boolean {
return this.form?.controls.inputType.value === ControllerInputType.Axis
|| this.form?.controls.inputType.value === ControllerInputType.Trigger;
return this.form?.controls.input.controls.inputType.value === ControllerInputType.Axis
|| this.form?.controls.input.controls.inputType.value === ControllerInputType.Trigger;
}

public setForm(
Expand All @@ -50,9 +55,9 @@ export class BindingLinearEditComponent implements IBindingsDetailsEditComponent
if (outputBinding !== this.form) {
this.form = outputBinding;
merge(
outputBinding.controls.controllerId.valueChanges,
outputBinding.controls.inputId.valueChanges,
outputBinding.controls.inputType.valueChanges,
outputBinding.controls.input.controls.controllerId.valueChanges,
outputBinding.controls.input.controls.inputId.valueChanges,
outputBinding.controls.input.controls.inputType.valueChanges,
).subscribe(() => {
this.cd.markForCheck();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
<ng-container *ngIf="form">
<app-controller-select [controllerIdFormControl]="form.controls.controllerId"
[inputIdFormControl]="form.controls.inputId"
[operationMode]="servoOperationMode"
[inputTypeControl]="form.controls.inputType"
<app-controller-select [operationMode]="servoOperationMode"
[inputFormGroup]="form.controls.input"
[title]="'controlScheme.bindingGenericInputTitle' | transloco "
></app-controller-select>

<ng-container *ngIf="form.controls.controllerId.valid && form.controls.inputId.valid">
<ng-container *ngIf="form.controls.input.valid">
<app-binding-input-gain-select *ngIf="isInputGainConfigurable"
[control]="form.controls.inputGain"
[control]="form.controls.input.controls.gain"
></app-binding-input-gain-select>

<button mat-raised-button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ export class BindingServoEditComponent implements IBindingsDetailsEditComponent<
}

public get isInputGainConfigurable(): boolean {
return this.form?.controls.inputType.value === ControllerInputType.Axis
|| this.form?.controls.inputType.value === ControllerInputType.Trigger;
return this.form?.controls.input.controls.inputType.value === ControllerInputType.Axis
|| this.form?.controls.input.controls.inputType.value === ControllerInputType.Trigger;
}

public get canCalibrate$(): Observable<boolean> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<ng-container *ngIf="form">
<app-controller-select [controllerIdFormControl]="form.controls.controllerId"
[inputIdFormControl]="form.controls.inputId"
[operationMode]="setAngleHubIoOperationMode"
[inputTypeControl]="form.controls.inputType"
<app-controller-select [operationMode]="setAngleHubIoOperationMode"
[inputFormGroup]="form.controls.input"
[title]="'controlScheme.bindingGenericInputTitle' | transloco "
></app-controller-select>

<ng-container *ngIf="form.controls.controllerId.valid && form.controls.inputId.valid">
<ng-container *ngIf="form.controls.input.valid">
<app-binding-control-num-input [translocoTitle]="'controlScheme.setAngleOutputConfigurationAngle'"
[control]="form.controls.angle"
[min]="motorLimits.minRawAngle"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<ng-container *ngIf="form">
<app-controller-select [controllerIdFormControl]="form.controls.controllerId"
[inputIdFormControl]="form.controls.inputId"
[operationMode]="stepperHubIoOperationMode"
[inputTypeControl]="form.controls.inputType"
<app-controller-select [operationMode]="stepperHubIoOperationMode"
[inputFormGroup]="form.controls.input"
[title]="'controlScheme.bindingGenericInputTitle' | transloco "
></app-controller-select>

<ng-container *ngIf="form.controls.controllerId.valid && form.controls.inputId.valid">
<ng-container *ngIf="form.controls.input.valid">
<app-binding-control-num-input [translocoTitle]="'controlScheme.stepperOutputConfigurationDegree'"
[control]="form.controls.degree"
[min]="minStepperDegree"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<ng-container *ngIf="controllerIdFormControl && inputIdFormControl && inputTypeControl">
<div *ngIf="controllerIdFormControl.valid && inputIdFormControl.valid && inputTypeControl.valid; else assignControl"
<ng-container *ngIf="inputFormGroup">
<div *ngIf="inputFormGroup.valid; else assignControl"
class="control-info">
<mat-label class="title">
{{ title }}:
</mat-label>
<app-full-controller-input-name class="control-info__control-name"
[controllerId]="controllerIdFormControl.value"
[inputId]="inputIdFormControl.value"
[inputType]="inputTypeControl.value"
[inputData]="controllerData"
></app-full-controller-input-name>

<button mat-raised-button
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input } from '@angular/core';
import { FormControl } from '@angular/forms';
import { NgIf } from '@angular/common';
import { MatDialog, MatDialogModule } from '@angular/material/dialog';
import { MatButtonModule } from '@angular/material/button';
import { MatIconModule } from '@angular/material/icon';
import { TranslocoModule } from '@ngneat/transloco';
import { MatInputModule } from '@angular/material/input';
import { ControllerInputModel } from '@app/store';
import { ControllerInputType, HubIoOperationMode } from '@app/shared';
import { ControlSchemeInput, ControllerInputModel } from '@app/store';
import { HubIoOperationMode, ToFormGroup } from '@app/shared';

import { IWaitingForInputDialogData, WaitForControllerInputDialogComponent } from '../wait-for-controller-input-dialog';
import { FullControllerInputNameComponent } from '../../full-controller-input-name';

@Component({
standalone: true,
selector: 'app-controller-select[operationMode][controllerIdFormControl][inputIdFormControl][inputTypeControl][title]',
selector: 'app-controller-select',
templateUrl: './binding-control-select-controller.component.html',
styleUrls: [ './binding-control-select-controller.component.scss' ],
imports: [
Expand All @@ -31,11 +30,7 @@ import { FullControllerInputNameComponent } from '../../full-controller-input-na
export class BindingControlSelectControllerComponent {
@Input() public operationMode?: HubIoOperationMode;

@Input() public controllerIdFormControl?: FormControl<string>;

@Input() public inputIdFormControl?: FormControl<string>;

@Input() public inputTypeControl?: FormControl<ControllerInputType>;
@Input() public inputFormGroup?: ToFormGroup<ControlSchemeInput>;

@Input() public title = '';

Expand All @@ -45,6 +40,10 @@ export class BindingControlSelectControllerComponent {
) {
}

public get controllerData(): ControlSchemeInput | undefined {
return this.inputFormGroup?.getRawValue();
}

public onBind(): void {
if (this.operationMode === undefined) {
return;
Expand All @@ -60,24 +59,14 @@ export class BindingControlSelectControllerComponent {
}
);
dialog.afterClosed().subscribe((result) => {
if (result && this.controllerIdFormControl && this.inputIdFormControl && this.inputTypeControl) {
if (this.controllerIdFormControl.value !== result.controllerId) {
this.controllerIdFormControl.markAsTouched();
this.controllerIdFormControl.markAsDirty();
this.controllerIdFormControl.setValue(result.controllerId);
}
if (this.inputIdFormControl.value !== result.inputId) {
this.inputIdFormControl.markAsTouched();
this.inputIdFormControl.markAsDirty();
this.inputIdFormControl.setValue(result.inputId);
}
if (this.inputTypeControl.value !== result.inputType) {
this.inputTypeControl.markAsTouched();
this.inputTypeControl.markAsDirty();
this.inputTypeControl.setValue(result.inputType);
}
this.cd.detectChanges();
if (!result || !this.inputFormGroup) {
return;
}
this.inputFormGroup.patchValue(result);
this.inputFormGroup.markAsDirty();
this.inputFormGroup.markAsTouched();
this.inputFormGroup.updateValueAndValidity();
this.cd.detectChanges();
});
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Inject, Injectable } from '@angular/core';
import { FormBuilder, FormControl, Validators } from '@angular/forms';
import { MOTOR_LIMITS, MotorServoEndState } from '@nvsukhanov/rxpoweredup';
import { ControllerInputType, WINDOW } from '@app/shared';
import { InputGain } from '@app/store';
import { ButtonGroupButtonId, MOTOR_LIMITS, MotorServoEndState } from '@nvsukhanov/rxpoweredup';
import { ControllerInputType, ToFormGroup, WINDOW } from '@app/shared';
import { ControlSchemeInput, InputGain } from '@app/store';

@Injectable({ providedIn: 'root' })
export class CommonFormControlsBuilderService {
Expand All @@ -16,20 +16,6 @@ export class CommonFormControlsBuilderService {
return this.formBuilder.control<string>(this.window.crypto.randomUUID(), { nonNullable: true });
}

public controllerIdControl(): FormControl<string> {
return this.formBuilder.control<string>('', {
nonNullable: true,
validators: [ Validators.required ]
});
}

public inputIdControl(): FormControl<string> {
return this.formBuilder.control<string>('', {
nonNullable: true,
validators: [ Validators.required ]
});
}

public hubIdControl(): FormControl<string> {
return this.formBuilder.control<string>('', {
nonNullable: true,
Expand Down Expand Up @@ -81,21 +67,28 @@ export class CommonFormControlsBuilderService {
});
}

public controllerInputTypeControl(
initialValue: ControllerInputType
): FormControl<ControllerInputType> {
return this.formBuilder.control<ControllerInputType>(initialValue, {
nonNullable: true,
validators: [ Validators.required ]
});
}

public axialInputFunctionControl(
initialValue: InputGain
): FormControl<InputGain> {
return this.formBuilder.control<InputGain>(initialValue, {
nonNullable: true,
validators: [ Validators.required ]
public inputFormGroup(
initialValue?: Partial<ControlSchemeInput>
): ToFormGroup<ControlSchemeInput> {
return this.formBuilder.group({
controllerId: this.formBuilder.control<string>(initialValue?.controllerId ?? '', {
nonNullable: true,
validators: [ Validators.required ]
}),
inputType: this.formBuilder.control<ControllerInputType>(initialValue?.inputType ?? ControllerInputType.Button, {
nonNullable: true,
validators: [ Validators.required ]
}),
inputId: this.formBuilder.control<string>(initialValue?.inputId ?? '', {
nonNullable: true,
validators: [ Validators.required ]
}),
gain: this.formBuilder.control<InputGain>(initialValue?.gain ?? InputGain.None, {
nonNullable: true,
validators: [ Validators.required ]
}),
buttonId: this.formBuilder.control<ButtonGroupButtonId | null>(initialValue?.portId ?? null),
portId: this.formBuilder.control<number | null>(initialValue?.portId ?? null)
});
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { Injectable } from '@angular/core';
import { FormBuilder } from '@angular/forms';
import { ControllerInputType } from '@app/shared';
import { InputGain } from '@app/store';

import { LinearBindingForm } from '../types';
import { CommonFormControlsBuilderService } from './common-form-controls-builder.service';
Expand All @@ -17,10 +15,7 @@ export class LinearOutputControlFormBuilderService {
public build(): LinearBindingForm {
return this.formBuilder.group({
id: this.commonFormControlBuilder.schemeIdControl(),
controllerId: this.commonFormControlBuilder.controllerIdControl(),
inputId: this.commonFormControlBuilder.inputIdControl(),
inputType: this.commonFormControlBuilder.controllerInputTypeControl(ControllerInputType.Button),
inputGain: this.commonFormControlBuilder.axialInputFunctionControl(InputGain.None),
input: this.commonFormControlBuilder.inputFormGroup(),
hubId: this.commonFormControlBuilder.hubIdControl(),
portId: this.commonFormControlBuilder.portIdControl(),
maxSpeed: this.commonFormControlBuilder.speedControl(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { MOTOR_LIMITS } from '@nvsukhanov/rxpoweredup';
import { FormBuilder, Validators } from '@angular/forms';
import { Injectable } from '@angular/core';
import { ControllerInputType } from '@app/shared';
import { InputGain } from '@app/store';

import { ServoBindingForm } from '../types';
import { CommonFormControlsBuilderService } from './common-form-controls-builder.service';
Expand All @@ -18,10 +16,7 @@ export class ServoOutputControlFormBuilderService {
public build(): ServoBindingForm {
return this.formBuilder.group({
id: this.commonFormControlBuilder.schemeIdControl(),
controllerId: this.commonFormControlBuilder.controllerIdControl(),
inputId: this.commonFormControlBuilder.inputIdControl(),
inputType: this.commonFormControlBuilder.controllerInputTypeControl(ControllerInputType.Button),
inputGain: this.commonFormControlBuilder.axialInputFunctionControl(InputGain.None),
input: this.commonFormControlBuilder.inputFormGroup(),
hubId: this.commonFormControlBuilder.hubIdControl(),
portId: this.commonFormControlBuilder.portIdControl(),
range: this.formBuilder.control<number>(MOTOR_LIMITS.maxServoDegreesRange, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Injectable } from '@angular/core';
import { FormBuilder, Validators } from '@angular/forms';
import { ControllerInputType } from '@app/shared';

import { SetAngleBindingForm } from '../types';
import { CommonFormControlsBuilderService } from './common-form-controls-builder.service';
Expand All @@ -16,9 +15,7 @@ export class SetAngleOutputControlFormBuilderService {
public build(): SetAngleBindingForm {
return this.formBuilder.group({
id: this.commonFormControlBuilder.schemeIdControl(),
controllerId: this.commonFormControlBuilder.controllerIdControl(),
inputId: this.commonFormControlBuilder.inputIdControl(),
inputType: this.commonFormControlBuilder.controllerInputTypeControl(ControllerInputType.Button),
input: this.commonFormControlBuilder.inputFormGroup(),
hubId: this.commonFormControlBuilder.hubIdControl(),
portId: this.commonFormControlBuilder.portIdControl(),
angle: this.formBuilder.control<number>(0, {
Expand Down
Loading

0 comments on commit ecaef58

Please sign in to comment.