Skip to content

Commit

Permalink
refactor: shorten input actions enum values
Browse files Browse the repository at this point in the history
  • Loading branch information
nvsukhanov committed Mar 6, 2024
1 parent 2260b1b commit 16cf8da
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,14 @@ function getTaskComposingData$(

const bindingWithInputsStreams: Array<Observable<BindingWithInputData>> = samePortBindings.map((binding) => {
return inputComposer.composeInput(binding, inputStream).pipe(
distinctUntilChanged((a, b) => !inputComposer.isInputChanged(binding.bindingType, a, b)),
startWith(inputComposer.composeInput(binding, inputStream)),
pairwise(),
map(([prevInput, nextInput]) => ({ binding, prevInput, nextInput })),
switchMap((initialValue) => {
return of(initialValue).pipe(
distinctUntilChanged((a, b) => !inputComposer.isInputChanged(binding.bindingType, a, b)),
startWith(initialValue),
pairwise(),
map(([prevInput, nextInput]) => ({ binding, prevInput, nextInput })),
);
})
);
});

Expand Down
29 changes: 15 additions & 14 deletions modules/store/src/lib/models/control-scheme.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ export type ControlSchemeInput = {
inputDirection: InputDirection;
};

// Using string enum for input actions to avoid issues with object keys conversion to string
export enum SpeedBindingInputAction {
Forwards = 'Forwards',
Backwards = 'Backwards',
Brake = 'Brake'
Forwards = '0',
Backwards = '1',
Brake = '2'
}

export type ControlSchemeSpeedBinding = {
Expand All @@ -66,8 +67,8 @@ export type ControlSchemeSpeedBinding = {
} & AccelerationProfileMixin & DecelerationProfileMixin;

export enum ServoBindingInputAction {
Cw = 'Cw',
Ccw = 'Ccw'
Cw = '0',
Ccw = '1'
}

export type ControlSchemeServoBinding = {
Expand All @@ -87,7 +88,7 @@ export type ControlSchemeServoBinding = {
} & AccelerationProfileMixin & DecelerationProfileMixin;

export enum SetAngleBindingInputAction {
SetAngle = 'SetAngle'
SetAngle = '0'
}

export type ControlSchemeSetAngleBinding = {
Expand All @@ -105,8 +106,8 @@ export type ControlSchemeSetAngleBinding = {
} & AccelerationProfileMixin & DecelerationProfileMixin;

export enum StepperBindingInputAction {
Cw = 'Cw',
Ccw = 'Ccw'
Cw = '0',
Ccw = '1'
}

export type ControlSchemeStepperBinding = {
Expand All @@ -125,9 +126,9 @@ export type ControlSchemeStepperBinding = {
} & AccelerationProfileMixin & DecelerationProfileMixin;

export enum TrainBindingInputAction {
NextSpeed = 'NextSpeed',
PrevSpeed = 'PrevSpeed',
Reset = 'ResetSpeed'
NextSpeed = '0',
PrevSpeed = '1',
Reset = '2'
}

export type ControlSchemeTrainBinding = {
Expand All @@ -147,9 +148,9 @@ export type ControlSchemeTrainBinding = {
} & AccelerationProfileMixin & DecelerationProfileMixin;

export enum GearboxBindingInputAction {
NextGear = 'NextGear',
PrevGear = 'PrevGear',
Reset = 'ResetGear'
NextGear = '0',
PrevGear = '1',
Reset = '2'
}

export type ControlSchemeGearboxBinding = {
Expand Down

0 comments on commit 16cf8da

Please sign in to comment.