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

refactor: remove generic input actions usage in setAngle #485

Merged
merged 1 commit into from
Mar 5, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ReactiveFormsModule } from '@angular/forms';
import { AsyncPipe } from '@angular/common';
import { ControlSchemeBindingType, ValidationMessagesDirective } from '@app/shared-misc';
import { HideOnSmallScreenDirective, ToggleControlComponent } from '@app/shared-ui';
import { ControlSchemeInputAction, HubMotorPositionFacadeService } from '@app/store';
import { HubMotorPositionFacadeService, SetAngleInputAction } from '@app/store';
import { BindingControlSelectHubComponent, BindingControlSelectIoComponent, MotorPositionAdjustmentComponent } from '@app/shared-control-schemes';

import { IBindingsDetailsEditComponent } from '../i-bindings-details-edit-component';
Expand Down Expand Up @@ -103,9 +103,9 @@ export class BindingSetAngleEditComponent implements IBindingsDetailsEditCompone

this._setAngleControlBindingComponentData = {
bindingType: ControlSchemeBindingType.SetAngle,
inputFormGroup: form.controls.inputs.controls[ControlSchemeInputAction.SetAngle],
inputAction: ControlSchemeInputAction.SetAngle,
inputName$: this.l10nService.getBasicInputName(ControlSchemeInputAction.SetAngle)
inputFormGroup: form.controls.inputs.controls[SetAngleInputAction.SetAngle],
inputAction: SetAngleInputAction.SetAngle,
inputName$: this.l10nService.getBasicInputName(SetAngleInputAction.SetAngle)
};

const hubAndPortChanges = form.controls.hubId.valueChanges.pipe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
import { FormBuilder } from '@angular/forms';
import { MotorServoEndState } from 'rxpoweredup';
import { DeepPartial } from '@app/shared-misc';
import { ControlSchemeInputAction, ControlSchemeSetAngleBinding } from '@app/store';
import { ControlSchemeSetAngleBinding, SetAngleInputAction } from '@app/store';
import { ControlSchemeFormBuilderService } from '@app/shared-control-schemes';

import { CommonBindingsFormControlsBuilderService } from '../common';
Expand All @@ -20,7 +20,7 @@ export class SetAngleBindingFormBuilderService {
public build(): SetAngleBindingForm {
return this.formBuilder.group({
inputs: this.formBuilder.group({
[ControlSchemeInputAction.SetAngle]: this.commonFormControlBuilder.inputFormGroup()
[SetAngleInputAction.SetAngle]: this.commonFormControlBuilder.inputFormGroup()
}),
hubId: this.controlSchemeFormBuilder.hubIdControl(),
portId: this.controlSchemeFormBuilder.portIdControl(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
import { ControlSchemeBindingType } from '@app/shared-misc';
import { ControlSchemeBinding, ControlSchemeInputAction, ControlSchemeSetAngleBinding } from '@app/store';
import { ControlSchemeBinding, ControlSchemeSetAngleBinding, SetAngleInputAction } from '@app/store';

import { CommonFormMapperService } from '../common';
import { SetAngleBindingForm } from './set-angle-binding-form';
Expand Down Expand Up @@ -28,8 +28,8 @@ export class SetAngleBindingFormMapperService {
hubId,
portId,
inputs: {
[ControlSchemeInputAction.SetAngle]: this.commonFormMapperService.mapInputFormToSchemeInput(
form.controls.inputs.controls[ControlSchemeInputAction.SetAngle]
[SetAngleInputAction.SetAngle]: this.commonFormMapperService.mapInputFormToSchemeInput(
form.controls.inputs.controls[SetAngleInputAction.SetAngle]
)
}
};
Expand Down
4 changes: 2 additions & 2 deletions modules/bindings/src/lib/set-angle/set-angle-binding-form.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { FormControl, FormGroup } from '@angular/forms';
import { MotorServoEndState } from 'rxpoweredup';
import { ControlSchemeInputAction } from '@app/store';
import { SetAngleInputAction } from '@app/store';

import { InputFormGroup } from '../common';

export type SetAngleBindingForm = FormGroup<{
inputs: FormGroup<{
[ControlSchemeInputAction.SetAngle]: InputFormGroup;
[SetAngleInputAction.SetAngle]: InputFormGroup;
}>;
hubId: FormControl<string | null>;
portId: FormControl<number | null>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Dictionary } from '@ngrx/entity';
import { Injectable } from '@angular/core';
import { ControlSchemeBindingType } from '@app/shared-misc';
import { ControlSchemeInputAction, ControlSchemeSetAngleBinding, ControllerInputModel, controllerInputIdFn } from '@app/store';
import { ControlSchemeSetAngleBinding, ControllerInputModel, SetAngleInputAction, controllerInputIdFn } from '@app/store';

import { BindingInputExtractionResult, IBindingTaskInputExtractor } from '../i-binding-task-input-extractor';

Expand All @@ -11,18 +11,18 @@ export class SetAngleInputExtractorService implements IBindingTaskInputExtractor
binding: ControlSchemeSetAngleBinding,
globalInput: Dictionary<ControllerInputModel>
): BindingInputExtractionResult<ControlSchemeBindingType.SetAngle> {
const setAngleInputId = controllerInputIdFn(binding.inputs[ControlSchemeInputAction.SetAngle]);
const setAngleInputId = controllerInputIdFn(binding.inputs[SetAngleInputAction.SetAngle]);
const setAngleInputResult = globalInput[setAngleInputId];
return {
[ControlSchemeInputAction.SetAngle]: setAngleInputResult ?? null
[SetAngleInputAction.SetAngle]: setAngleInputResult ?? null
};
}

public isInputChanged(
prevInput: BindingInputExtractionResult<ControlSchemeBindingType.SetAngle>,
nextInput: BindingInputExtractionResult<ControlSchemeBindingType.SetAngle>
): boolean {
return prevInput[ControlSchemeInputAction.SetAngle] !== nextInput[ControlSchemeInputAction.SetAngle];
return prevInput[SetAngleInputAction.SetAngle] !== nextInput[SetAngleInputAction.SetAngle];
}

}
10 changes: 5 additions & 5 deletions modules/bindings/src/lib/set-angle/set-angle-l10n.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import {
AttachedIoPropsModel,
ControlSchemeBindingInputs,
ControlSchemeInput,
ControlSchemeInputAction,
ControlSchemeSetAngleBinding,
PortCommandTask
PortCommandTask,
SetAngleInputAction
} from '@app/store';
import { ControlSchemeBindingType } from '@app/shared-misc';

Expand All @@ -19,7 +19,7 @@ import { ControllerInputNameService } from '../common';
@Injectable()
export class SetAngleL10nService implements IBindingL10n<ControlSchemeBindingType.SetAngle> {
public readonly bindingTypeL10nKey = 'controlScheme.setAngleBinding.operationMode';

constructor(
private readonly translocoService: TranslocoService,
private readonly store: Store,
Expand Down Expand Up @@ -51,7 +51,7 @@ export class SetAngleL10nService implements IBindingL10n<ControlSchemeBindingTyp
actionType: keyof ControlSchemeBindingInputs<ControlSchemeBindingType.SetAngle>
): Observable<string> {
switch (actionType) {
case ControlSchemeInputAction.SetAngle:
case SetAngleInputAction.SetAngle:
return this.transloco.selectTranslate('controlScheme.setAngleBinding.basicInputAction');
}
}
Expand All @@ -61,7 +61,7 @@ export class SetAngleL10nService implements IBindingL10n<ControlSchemeBindingTyp
inputConfig: ControlSchemeInput
): Observable<string> {
switch (actionType) {
case ControlSchemeInputAction.SetAngle:
case SetAngleInputAction.SetAngle:
return this.controllerNameProvider.getFullControllerInputNameData(inputConfig);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { Injectable } from '@angular/core';
import { ControlSchemeBindingType } from '@app/shared-misc';
import {
AttachedIoPropsModel,
ControlSchemeInputAction,
ControlSchemeSetAngleBinding,
PortCommandTask,
PortCommandTaskPayload,
SetAngleInputAction,
SetAngleTaskPayload
} from '@app/store';

Expand All @@ -20,8 +20,8 @@ export class SetAngleTaskPayloadBuilderService implements ITaskPayloadBuilder<Co
previousInput: BindingInputExtractionResult<ControlSchemeBindingType.SetAngle>,
ioProps: Omit<AttachedIoPropsModel, 'hubId' | 'portId'> | null,
): { payload: SetAngleTaskPayload; inputTimestamp: number } | null {
const currentSetAngleInput = currentInput[ControlSchemeInputAction.SetAngle];
const previousSetAngleInput = previousInput[ControlSchemeInputAction.SetAngle];
const currentSetAngleInput = currentInput[SetAngleInputAction.SetAngle];
const previousSetAngleInput = previousInput[SetAngleInputAction.SetAngle];

if (currentSetAngleInput?.isActivated && !previousSetAngleInput?.isActivated) {
const resultingAngle = binding.angle - (ioProps?.motorEncoderOffset ?? 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const INPUT_TREE_NODE_VIEW_MODEL_SELECTOR = (
ioHasNoRequiredCapabilities,
controlData: Object.entries(binding.inputs).map(([ action, input ]): InputActionTreeNodeRecord => {
return {
action: +action as keyof ControlSchemeBinding['inputs'],
action: action as keyof ControlSchemeBinding['inputs'],
isControllerConnected: !!controllerConnectionEntities[(input as ControlSchemeInput).controllerId]
};
}),
Expand Down
8 changes: 7 additions & 1 deletion modules/store/src/lib/migrations/v29-v30/v29-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,18 @@ export type V29ServoBinding = Override<V30ServoBinding, {
};
}>;

export type V29SetAngleBinding = Override<V30SetAngleBinding, {
inputs: {
[OldInputAction.SetAngle]: ControlSchemeInput;
};
}>;

export type V29Bindings = V29SetSpeedBinding
| V29ServoBinding
| V30StepperBinding
| V30TrainControlBinding
| V30GearboxControlBinding
| V30SetAngleBinding;
| V29SetAngleBinding;
export type V29ControlSchemesEntitiesState = Omit<V30ControlSchemesEntitiesState, 'bindings'> & { bindings: V29Bindings[] };

export type V29Store = Override<V30Store, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ControllerType, GamepadProfile, GamepadProfileFactoryService, GamepadSe
import { DeepPartial } from '@app/shared-misc';

import { AppStoreVersion } from '../../app-store-version';
import { InputDirection, ServoInputAction, SetSpeedInputAction } from '../../models';
import { InputDirection, ServoInputAction, SetAngleInputAction, SetSpeedInputAction } from '../../models';
import { V21ToV22MigrationService } from '../v21-v22';
import { V21_STORE_SAMPLE } from '../v21';
import { V23ToV24MigrationService } from '../v23-v24';
Expand All @@ -16,7 +16,7 @@ import { ensureStorePropsNotChanged } from '../ensure-props-not-changed';
import { V22ToV23MigrationService } from '../v22-v23';
import { V26ToV27MigrationService } from '../v26-v27';
import { V30Store } from '../v30';
import { V29ServoBinding, V29Store, V30ServoBinding, V30SetSpeedBinding } from './v29-store';
import { V29ServoBinding, V29SetAngleBinding, V29Store, V30ServoBinding, V30SetAngleBinding, V30SetSpeedBinding } from './v29-store';
import { OldInputAction } from '../old-input-actions';

describe('v29 to v30 migration', () => {
Expand Down Expand Up @@ -104,6 +104,12 @@ describe('v29 to v30 migration', () => {
expect(v30servoBinding.inputs[ServoInputAction.Ccw]).toEqual(v29ServoBinding.inputs[OldInputAction.ServoCcw]);
});

it('should migrate set angle binding input', () => {
const v30setAngleBinding = v30Store.controlSchemes?.entities?.['Set angle']?.bindings[0] as V30SetAngleBinding;
const v29setAngleBinding = v29Store.controlSchemes?.entities?.['Set angle']?.bindings[0] as V29SetAngleBinding;
expect(v30setAngleBinding.inputs[SetAngleInputAction.SetAngle]).toEqual(v29setAngleBinding.inputs[OldInputAction.SetAngle]);
});

it('should update store version', () => {
expect(v30Store.storeVersion).toEqual(AppStoreVersion.v30);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ControlSchemeBindingType, DeepPartial } from '@app/shared-misc';

import { AppStoreVersion } from '../../app-store-version';
import { IMigration } from '../i-migration';
import { InputDirection, ServoInputAction, SetSpeedInputAction } from '../../models';
import { InputDirection, ServoInputAction, SetAngleInputAction, SetSpeedInputAction } from '../../models';
import { V29ControlSchemesEntitiesState, V29Store, V30Binding, V30ServoBinding, V30SetSpeedBinding } from './v29-store';
import { V30Store } from '../v30';
import { OldInputAction } from '../old-input-actions';
Expand Down Expand Up @@ -86,6 +86,16 @@ export class V29ToV30MigrationService implements IMigration<V29Store, V30Store>
};
}
return bindingResult;
} else if (b.bindingType === ControlSchemeBindingType.SetAngle) {
const bindingResult: V30Binding = {
...b,
inputs: {
[SetAngleInputAction.SetAngle]: {
...b.inputs[OldInputAction.SetAngle]
}
}
};
return bindingResult;
}
return b;
});
Expand Down
18 changes: 11 additions & 7 deletions modules/store/src/lib/models/control-scheme.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export enum ControlSchemeInputAction {
OldSetSpeedBrake,
// @deprecated
OldServo,
SetAngle,
OldSetAngle,
Step,
NextLevel,
PrevLevel,
Expand All @@ -64,9 +64,9 @@ export enum ControlSchemeInputAction {
}

export enum SetSpeedInputAction {
Forwards,
Backwards,
Brake
Forwards = 'Forwards',
Backwards = 'Backwards',
Brake = 'Brake'
}

export type ControlSchemeSetSpeedBinding = {
Expand All @@ -85,8 +85,8 @@ export type ControlSchemeSetSpeedBinding = {
} & AccelerationProfileMixin & DecelerationProfileMixin;

export enum ServoInputAction {
Cw,
Ccw
Cw = 'Cw',
Ccw = 'Ccw'
}

export type ControlSchemeServoBinding = {
Expand All @@ -105,11 +105,15 @@ export type ControlSchemeServoBinding = {
power: number;
} & AccelerationProfileMixin & DecelerationProfileMixin;

export enum SetAngleInputAction {
SetAngle = 'SetAngle'
}

export type ControlSchemeSetAngleBinding = {
id: number;
bindingType: ControlSchemeBindingType.SetAngle;
inputs: {
[ControlSchemeInputAction.SetAngle]: ControlSchemeInput;
[SetAngleInputAction.SetAngle]: ControlSchemeInput;
};
hubId: string;
portId: number;
Expand Down
Loading