diff --git a/src/app/control-schemes/port-command-task-summary/port-command-task-summary.pipe.ts b/src/app/control-schemes/port-command-task-summary/port-command-task-summary.pipe.ts index e56823c3..491e0be8 100644 --- a/src/app/control-schemes/port-command-task-summary/port-command-task-summary.pipe.ts +++ b/src/app/control-schemes/port-command-task-summary/port-command-task-summary.pipe.ts @@ -1,7 +1,8 @@ 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 { ATTACHED_IO_PROPS_SELECTORS, AttachedIoPropsModel, PortCommandTask } from '@app/store'; +import { ControlSchemeBindingType } from '@app/shared'; import { LinearPortCommandTaskSummaryBuilderService } from './linear-port-command-task-summary-builder.service'; import { ServoPortCommandTaskSummaryBuilderService } from './servo-port-command-task-summary-builder.service'; @@ -29,10 +30,10 @@ export class PortCommandTaskSummaryPipe implements PipeTransform { portCommandTask: PortCommandTask ): Observable { const payload = portCommandTask.payload; - switch (payload.taskType) { - case PortCommandTaskType.SetSpeed: + switch (payload.bindingType) { + case ControlSchemeBindingType.Linear: return this.linearPortCommandTaskSummaryBuilder.build(payload); - case PortCommandTaskType.SetAngle: + case ControlSchemeBindingType.SetAngle: return this.store.select(ATTACHED_IO_PROPS_SELECTORS.selectById(portCommandTask)).pipe( filter((ioProps): ioProps is AttachedIoPropsModel => !!ioProps), switchMap((ioProps) => this.setAnglePortCommandTaskSummaryBuilder.build( @@ -40,7 +41,7 @@ export class PortCommandTaskSummaryPipe implements PipeTransform { payload )) ); - case PortCommandTaskType.Servo: + case ControlSchemeBindingType.Servo: return this.store.select(ATTACHED_IO_PROPS_SELECTORS.selectById(portCommandTask)).pipe( filter((ioProps): ioProps is AttachedIoPropsModel => !!ioProps), switchMap((ioProps) => this.servoPortCommandTaskSummaryBuilder.build( @@ -48,9 +49,9 @@ export class PortCommandTaskSummaryPipe implements PipeTransform { payload )) ); - case PortCommandTaskType.Stepper: + case ControlSchemeBindingType.Stepper: return this.stepperPortCommandTaskSummaryBuilder.build(payload); - case PortCommandTaskType.SpeedStepper: + case ControlSchemeBindingType.SpeedStepper: return this.speedStepperPortCommandTaskSummaryBuilder.build(payload); } } diff --git a/src/app/store/effects/controllers/capture-input/capture-gamepad-input.effect.ts b/src/app/store/effects/controllers/capture-input/capture-gamepad-input.effect.ts index 9d951910..f00becdf 100644 --- a/src/app/store/effects/controllers/capture-input/capture-gamepad-input.effect.ts +++ b/src/app/store/effects/controllers/capture-input/capture-gamepad-input.effect.ts @@ -2,9 +2,11 @@ import { concatLatestFrom, createEffect } from '@ngrx/effects'; import { NEVER, Observable, animationFrames, filter, from, map, merge, share, switchMap } from 'rxjs'; import { Action, Store } from '@ngrx/store'; import { inject } from '@angular/core'; -import { CONTROLLER_CONNECTION_SELECTORS, CONTROLLER_INPUT_ACTIONS, CONTROLLER_INPUT_SELECTORS, controllerInputIdFn } from '@app/store'; import { APP_CONFIG, ControllerInputType, ControllerType, IAppConfig, WINDOW } from '@app/shared'; +import { CONTROLLER_CONNECTION_SELECTORS, CONTROLLER_INPUT_SELECTORS } from '../../../selectors'; +import { CONTROLLER_INPUT_ACTIONS } from '../../../actions'; +import { controllerInputIdFn } from '../../../reducers'; import { GamepadValueTransformService } from '../../../../controller-profiles'; function readGamepads( diff --git a/src/app/store/effects/tasks-processing/payload-hash/payload-hash.ts b/src/app/store/effects/tasks-processing/payload-hash/payload-hash.ts index a883906c..e2eaeb67 100644 --- a/src/app/store/effects/tasks-processing/payload-hash/payload-hash.ts +++ b/src/app/store/effects/tasks-processing/payload-hash/payload-hash.ts @@ -1,4 +1,6 @@ -import { PortCommandTaskPayload, PortCommandTaskType } from '../../../models'; +import { ControlSchemeBindingType } from '@app/shared'; + +import { PortCommandTaskPayload } from '../../../models'; import { servoPayloadHash } from './servo-payload-hash'; import { setAnglePayloadHash } from './set-angle-payload-hash'; import { setSpeedPayloadHash } from './set-speed-payload-hash'; @@ -8,16 +10,16 @@ import { speedStepperPayloadHash } from './speed-stepper-payload-hash'; export function payloadHash( payload: PortCommandTaskPayload ): string { - switch (payload.taskType) { - case PortCommandTaskType.Servo: + switch (payload.bindingType) { + case ControlSchemeBindingType.Servo: return servoPayloadHash(payload); - case PortCommandTaskType.SetAngle: + case ControlSchemeBindingType.SetAngle: return setAnglePayloadHash(payload); - case PortCommandTaskType.SetSpeed: + case ControlSchemeBindingType.Linear: return setSpeedPayloadHash(payload); - case PortCommandTaskType.Stepper: + case ControlSchemeBindingType.Stepper: return stepperPayloadHash(payload); - case PortCommandTaskType.SpeedStepper: + case ControlSchemeBindingType.SpeedStepper: return speedStepperPayloadHash(payload); } } diff --git a/src/app/store/effects/tasks-processing/payload-hash/servo-payload-hash.ts b/src/app/store/effects/tasks-processing/payload-hash/servo-payload-hash.ts index db5c79b3..b7b2ca35 100644 --- a/src/app/store/effects/tasks-processing/payload-hash/servo-payload-hash.ts +++ b/src/app/store/effects/tasks-processing/payload-hash/servo-payload-hash.ts @@ -4,7 +4,7 @@ export function servoPayloadHash( payload: ServoTaskPayload ): string { return [ - payload.taskType, + payload.bindingType, payload.angle, payload.speed, payload.power, diff --git a/src/app/store/effects/tasks-processing/payload-hash/set-speed-payload-hash.ts b/src/app/store/effects/tasks-processing/payload-hash/set-speed-payload-hash.ts index f9b4e678..bd19808a 100644 --- a/src/app/store/effects/tasks-processing/payload-hash/set-speed-payload-hash.ts +++ b/src/app/store/effects/tasks-processing/payload-hash/set-speed-payload-hash.ts @@ -4,7 +4,7 @@ export function setSpeedPayloadHash( payload: SetLinearSpeedTaskPayload ): string { return [ - payload.taskType, + payload.bindingType, payload.speed, payload.power, ].join('_'); diff --git a/src/app/store/effects/tasks-processing/payload-hash/speed-stepper-payload-hash.ts b/src/app/store/effects/tasks-processing/payload-hash/speed-stepper-payload-hash.ts index b0d6dfb3..772bf009 100644 --- a/src/app/store/effects/tasks-processing/payload-hash/speed-stepper-payload-hash.ts +++ b/src/app/store/effects/tasks-processing/payload-hash/speed-stepper-payload-hash.ts @@ -1,10 +1,10 @@ -import { SpeedStepperTaskPayload } from '@app/store'; +import { SpeedStepperTaskPayload } from '../../../models'; export function speedStepperPayloadHash( payload: SpeedStepperTaskPayload ): string { return [ - payload.taskType, + payload.bindingType, payload.level, payload.nextSpeedActiveInput, payload.prevSpeedActiveInput diff --git a/src/app/store/effects/tasks-processing/payload-hash/stepper-payload-hash.ts b/src/app/store/effects/tasks-processing/payload-hash/stepper-payload-hash.ts index 8fbecf13..b6d71c8d 100644 --- a/src/app/store/effects/tasks-processing/payload-hash/stepper-payload-hash.ts +++ b/src/app/store/effects/tasks-processing/payload-hash/stepper-payload-hash.ts @@ -4,7 +4,7 @@ export function stepperPayloadHash( payload: StepperTaskPayload ): string { return [ - payload.taskType, + payload.bindingType, payload.degree, payload.speed, payload.power, diff --git a/src/app/store/effects/tasks-processing/task-builder/servo-task-builder.ts b/src/app/store/effects/tasks-processing/task-builder/servo-task-builder.ts index 3f355a24..10e8cf9b 100644 --- a/src/app/store/effects/tasks-processing/task-builder/servo-task-builder.ts +++ b/src/app/store/effects/tasks-processing/task-builder/servo-task-builder.ts @@ -4,7 +4,7 @@ import { ControlSchemeBindingType, getTranslationArcs } from '@app/shared'; import { controllerInputIdFn } from '@app/store'; import { BaseTaskBuilder } from './base-task-builder'; -import { ControlSchemeBinding, ControllerInputModel, PortCommandTask, PortCommandTaskPayload, PortCommandTaskType, ServoTaskPayload } from '../../../models'; +import { ControlSchemeBinding, ControllerInputModel, PortCommandTask, PortCommandTaskPayload, ServoTaskPayload } from '../../../models'; import { calcInputGain } from './calc-input-gain'; export class ServoTaskBuilder extends BaseTaskBuilder { @@ -35,7 +35,7 @@ export class ServoTaskBuilder extends BaseTaskBuilder { const snappedAngle = this.snapAngle(targetAngle, resultingCenter, minAngle, maxAngle); const payload: ServoTaskPayload = { - taskType: PortCommandTaskType.Servo, + bindingType: ControlSchemeBindingType.Servo, angle: Math.round(snappedAngle), speed: Math.round(binding.speed), power: binding.power, @@ -49,11 +49,11 @@ export class ServoTaskBuilder extends BaseTaskBuilder { protected buildCleanupPayload( previousTask: PortCommandTask ): PortCommandTaskPayload | null { - if (previousTask.payload.taskType !== PortCommandTaskType.Servo) { + if (previousTask.payload.bindingType !== ControlSchemeBindingType.Servo) { return null; } return { - taskType: PortCommandTaskType.SetSpeed, + bindingType: ControlSchemeBindingType.Linear, speed: 0, power: 0, activeInput: false, diff --git a/src/app/store/effects/tasks-processing/task-builder/set-angle-task-builder.ts b/src/app/store/effects/tasks-processing/task-builder/set-angle-task-builder.ts index 00a0e529..00402097 100644 --- a/src/app/store/effects/tasks-processing/task-builder/set-angle-task-builder.ts +++ b/src/app/store/effects/tasks-processing/task-builder/set-angle-task-builder.ts @@ -1,9 +1,9 @@ import { Dictionary } from '@ngrx/entity'; import { ControlSchemeBindingType } from '@app/shared'; -import { controllerInputIdFn } from '@app/store'; +import { controllerInputIdFn } from '../../../reducers'; import { BaseTaskBuilder } from './base-task-builder'; -import { ControlSchemeBinding, ControllerInputModel, PortCommandTask, PortCommandTaskPayload, PortCommandTaskType, SetAngleTaskPayload } from '../../../models'; +import { ControlSchemeBinding, ControllerInputModel, PortCommandTask, PortCommandTaskPayload, SetAngleTaskPayload } from '../../../models'; export class SetAngleTaskBuilder extends BaseTaskBuilder { private readonly inputValueThreshold = 0.5; @@ -23,7 +23,7 @@ export class SetAngleTaskBuilder extends BaseTaskBuilder { return null; } const payload: SetAngleTaskPayload = { - taskType: PortCommandTaskType.SetAngle, + bindingType: ControlSchemeBindingType.SetAngle, angle: binding.angle, speed: binding.speed, power: binding.power, @@ -38,11 +38,11 @@ export class SetAngleTaskBuilder extends BaseTaskBuilder { protected buildCleanupPayload( previousTask: PortCommandTask ): PortCommandTaskPayload | null { - if (previousTask.payload.taskType !== PortCommandTaskType.SetAngle) { + if (previousTask.payload.bindingType !== ControlSchemeBindingType.SetAngle) { return null; } return { - taskType: PortCommandTaskType.SetSpeed, + bindingType: ControlSchemeBindingType.Linear, speed: 0, power: 0, activeInput: false, diff --git a/src/app/store/effects/tasks-processing/task-builder/set-speed-task-builder.ts b/src/app/store/effects/tasks-processing/task-builder/set-speed-task-builder.ts index 9c16e8da..9c89d4ff 100644 --- a/src/app/store/effects/tasks-processing/task-builder/set-speed-task-builder.ts +++ b/src/app/store/effects/tasks-processing/task-builder/set-speed-task-builder.ts @@ -10,7 +10,6 @@ import { ControllerInputModel, PortCommandTask, PortCommandTaskPayload, - PortCommandTaskType, SetLinearSpeedTaskPayload } from '../../../models'; import { calcInputGain } from './calc-input-gain'; @@ -58,7 +57,7 @@ export class SetSpeedTaskBuilder extends BaseTaskBuilder { ); const payload: SetLinearSpeedTaskPayload = { - taskType: PortCommandTaskType.SetSpeed, + bindingType: ControlSchemeBindingType.Linear, speed: targetSpeed, power: this.calculatePower(targetSpeed, brakeInputValue, binding.power), activeInput: accelerateInputValue !== 0, @@ -72,11 +71,11 @@ export class SetSpeedTaskBuilder extends BaseTaskBuilder { protected buildCleanupPayload( previousTask: PortCommandTask ): PortCommandTaskPayload | null { - if (previousTask.payload.taskType !== PortCommandTaskType.SetSpeed) { + if (previousTask.payload.bindingType !== ControlSchemeBindingType.Linear) { return null; } return { - taskType: PortCommandTaskType.SetSpeed, + bindingType: ControlSchemeBindingType.Linear, speed: 0, power: 0, activeInput: false, @@ -107,7 +106,7 @@ export class SetSpeedTaskBuilder extends BaseTaskBuilder { binding.inputs.accelerate.gain ); return { - taskType: PortCommandTaskType.SetSpeed, + bindingType: ControlSchemeBindingType.Linear, speed, power: this.calculatePower(speed, assumedBrakeInput, binding.power), activeInput: true, @@ -117,7 +116,7 @@ export class SetSpeedTaskBuilder extends BaseTaskBuilder { } return { - taskType: PortCommandTaskType.SetSpeed, + bindingType: ControlSchemeBindingType.Linear, speed: 0, power: this.calculatePower(0, assumedBrakeInput, binding.power), activeInput: true, diff --git a/src/app/store/effects/tasks-processing/task-builder/speed-stepper-task-builder.ts b/src/app/store/effects/tasks-processing/task-builder/speed-stepper-task-builder.ts index 34663fcc..992f49d9 100644 --- a/src/app/store/effects/tasks-processing/task-builder/speed-stepper-task-builder.ts +++ b/src/app/store/effects/tasks-processing/task-builder/speed-stepper-task-builder.ts @@ -5,7 +5,6 @@ import { ControllerInputModel, PortCommandTask, PortCommandTaskPayload, - PortCommandTaskType, SpeedStepperTaskPayload, controllerInputIdFn } from '@app/store'; @@ -30,11 +29,11 @@ export class SpeedStepperTaskBuilder extends BaseTaskBuilder { const isPrevSpeedInputActive = !!binding.inputs.prevSpeed && (inputsState[controllerInputIdFn(binding.inputs.prevSpeed)]?.value ?? 0) > this.inputThreshold; const isStopInputActive = !!binding.inputs.stop && (inputsState[controllerInputIdFn(binding.inputs.stop)]?.value ?? 0) > this.inputThreshold; - + if (isStopInputActive) { return { payload: { - taskType: PortCommandTaskType.SpeedStepper, + bindingType: ControlSchemeBindingType.SpeedStepper, nextSpeedActiveInput: isNextSpeedInputActive, prevSpeedActiveInput: isPrevSpeedInputActive, speed: 0, @@ -64,7 +63,7 @@ export class SpeedStepperTaskBuilder extends BaseTaskBuilder { } const payload: SpeedStepperTaskPayload = { - taskType: PortCommandTaskType.SpeedStepper, + bindingType: ControlSchemeBindingType.SpeedStepper, level: nextLevel, speed: binding.steps[nextLevel], power: binding.power, @@ -79,11 +78,11 @@ export class SpeedStepperTaskBuilder extends BaseTaskBuilder { protected buildCleanupPayload( previousTask: PortCommandTask ): PortCommandTaskPayload | null { - if (previousTask.payload.taskType !== PortCommandTaskType.SetAngle) { + if (previousTask.payload.bindingType !== ControlSchemeBindingType.SetAngle) { return null; } return { - taskType: PortCommandTaskType.SetSpeed, + bindingType: ControlSchemeBindingType.Linear, speed: 0, power: 0, activeInput: false, diff --git a/src/app/store/effects/tasks-processing/task-builder/stepper-task-builder.ts b/src/app/store/effects/tasks-processing/task-builder/stepper-task-builder.ts index 2ac3eca6..4d8778cf 100644 --- a/src/app/store/effects/tasks-processing/task-builder/stepper-task-builder.ts +++ b/src/app/store/effects/tasks-processing/task-builder/stepper-task-builder.ts @@ -1,9 +1,9 @@ import { Dictionary } from '@ngrx/entity'; import { ControlSchemeBindingType } from '@app/shared'; -import { controllerInputIdFn } from '@app/store'; +import { ControlSchemeBinding, ControllerInputModel, PortCommandTask, PortCommandTaskPayload, StepperTaskPayload } from '../../../models'; +import { controllerInputIdFn } from '../../../reducers'; import { BaseTaskBuilder } from './base-task-builder'; -import { ControlSchemeBinding, ControllerInputModel, PortCommandTask, PortCommandTaskPayload, PortCommandTaskType, StepperTaskPayload } from '../../../models'; export class StepperTaskBuilder extends BaseTaskBuilder { protected buildPayload( @@ -22,7 +22,7 @@ export class StepperTaskBuilder extends BaseTaskBuilder { } const payload: StepperTaskPayload = { - taskType: PortCommandTaskType.Stepper, + bindingType: ControlSchemeBindingType.Stepper, degree: binding.degree, speed: binding.speed, power: binding.power, @@ -37,11 +37,11 @@ export class StepperTaskBuilder extends BaseTaskBuilder { protected buildCleanupPayload( previousTask: PortCommandTask ): PortCommandTaskPayload | null { - if (previousTask.payload.taskType !== PortCommandTaskType.Stepper) { + if (previousTask.payload.bindingType !== ControlSchemeBindingType.Stepper) { return null; } return { - taskType: PortCommandTaskType.SetSpeed, + bindingType: ControlSchemeBindingType.Linear, speed: 0, power: 0, activeInput: false, diff --git a/src/app/store/effects/tasks-processing/task-filter/servo-task-filter.ts b/src/app/store/effects/tasks-processing/task-filter/servo-task-filter.ts index 3be0c2e5..c06e12ac 100644 --- a/src/app/store/effects/tasks-processing/task-filter/servo-task-filter.ts +++ b/src/app/store/effects/tasks-processing/task-filter/servo-task-filter.ts @@ -1,12 +1,14 @@ -import { PortCommandTask, PortCommandTaskType } from '../../../models'; +import { ControlSchemeBindingType } from '@app/shared'; + +import { PortCommandTask } from '../../../models'; const SERVO_DEGREES_THRESHOLD = 10; export function servoTaskFilter( - task: PortCommandTask, + task: PortCommandTask, lastExecutedTask: PortCommandTask | null ): boolean { - if (!lastExecutedTask || lastExecutedTask.payload.taskType !== PortCommandTaskType.Servo) { + if (!lastExecutedTask || lastExecutedTask.payload.bindingType !== ControlSchemeBindingType.Servo) { return true; } diff --git a/src/app/store/effects/tasks-processing/task-filter/set-angle-task-filter.ts b/src/app/store/effects/tasks-processing/task-filter/set-angle-task-filter.ts index 960b4e87..8f79cee5 100644 --- a/src/app/store/effects/tasks-processing/task-filter/set-angle-task-filter.ts +++ b/src/app/store/effects/tasks-processing/task-filter/set-angle-task-filter.ts @@ -1,10 +1,12 @@ -import { PortCommandTask, PortCommandTaskType } from '../../../models'; +import { ControlSchemeBindingType } from '@app/shared'; + +import { PortCommandTask } from '../../../models'; export function setAngleTaskFilter( - task: PortCommandTask, + task: PortCommandTask, lastExecutedTask: PortCommandTask | null ): boolean { - if (!lastExecutedTask || lastExecutedTask.payload.taskType !== PortCommandTaskType.SetAngle) { + if (!lastExecutedTask || lastExecutedTask.payload.bindingType !== ControlSchemeBindingType.SetAngle) { return true; } diff --git a/src/app/store/effects/tasks-processing/task-filter/set-speed-task-filter.ts b/src/app/store/effects/tasks-processing/task-filter/set-speed-task-filter.ts index 226eeefa..b30e8b34 100644 --- a/src/app/store/effects/tasks-processing/task-filter/set-speed-task-filter.ts +++ b/src/app/store/effects/tasks-processing/task-filter/set-speed-task-filter.ts @@ -1,10 +1,12 @@ -import { PortCommandTask, PortCommandTaskType } from '../../../models'; +import { ControlSchemeBindingType } from '@app/shared'; + +import { PortCommandTask } from '../../../models'; export function setSpeedTaskFilter( - task: PortCommandTask, + task: PortCommandTask, lastExecutedTask: PortCommandTask | null ): boolean { - if (!lastExecutedTask || lastExecutedTask.payload.taskType !== PortCommandTaskType.SetSpeed) { + if (!lastExecutedTask || lastExecutedTask.payload.bindingType !== ControlSchemeBindingType.Linear) { return task.payload.activeInput; } diff --git a/src/app/store/effects/tasks-processing/task-filter/speed-stepper-task-filter.ts b/src/app/store/effects/tasks-processing/task-filter/speed-stepper-task-filter.ts index 096668c9..7b37f672 100644 --- a/src/app/store/effects/tasks-processing/task-filter/speed-stepper-task-filter.ts +++ b/src/app/store/effects/tasks-processing/task-filter/speed-stepper-task-filter.ts @@ -1,10 +1,12 @@ -import { PortCommandTask, PortCommandTaskType } from '@app/store'; +import { ControlSchemeBindingType } from '@app/shared'; + +import { PortCommandTask } from '../../../models'; export function speedStepperTaskFilter( - task: PortCommandTask, + task: PortCommandTask, lastExecutedTask: PortCommandTask | null ): boolean { - if (!lastExecutedTask || lastExecutedTask.payload.taskType !== PortCommandTaskType.SpeedStepper) { + if (!lastExecutedTask || lastExecutedTask.payload.bindingType !== ControlSchemeBindingType.SpeedStepper) { return true; } diff --git a/src/app/store/effects/tasks-processing/task-filter/task-filter.ts b/src/app/store/effects/tasks-processing/task-filter/task-filter.ts index 88328955..98c8fb2b 100644 --- a/src/app/store/effects/tasks-processing/task-filter/task-filter.ts +++ b/src/app/store/effects/tasks-processing/task-filter/task-filter.ts @@ -1,4 +1,6 @@ -import { PortCommandTask, PortCommandTaskType } from '../../../models'; +import { ControlSchemeBindingType } from '@app/shared'; + +import { PortCommandTask } from '../../../models'; import { setSpeedTaskFilter } from './set-speed-task-filter'; import { servoTaskFilter } from './servo-task-filter'; import { setAngleTaskFilter } from './set-angle-task-filter'; @@ -8,15 +10,15 @@ export function taskFilter( task: PortCommandTask, lastExecutedTask: PortCommandTask | null ): boolean { - switch (task.payload.taskType) { - case PortCommandTaskType.SetSpeed: - return setSpeedTaskFilter(task as PortCommandTask, lastExecutedTask); - case PortCommandTaskType.Servo: - return servoTaskFilter(task as PortCommandTask, lastExecutedTask); - case PortCommandTaskType.SetAngle: - return setAngleTaskFilter(task as PortCommandTask, lastExecutedTask); - case PortCommandTaskType.SpeedStepper: - return speedStepperTaskFilter(task as PortCommandTask, lastExecutedTask); + switch (task.payload.bindingType) { + case ControlSchemeBindingType.Linear: + return setSpeedTaskFilter(task as PortCommandTask, lastExecutedTask); + case ControlSchemeBindingType.Servo: + return servoTaskFilter(task as PortCommandTask, lastExecutedTask); + case ControlSchemeBindingType.SetAngle: + return setAngleTaskFilter(task as PortCommandTask, lastExecutedTask); + case ControlSchemeBindingType.SpeedStepper: + return speedStepperTaskFilter(task as PortCommandTask, lastExecutedTask); default: return true; } diff --git a/src/app/store/effects/tasks-processing/task-queue-compressor/accumulating-task-compressor.ts b/src/app/store/effects/tasks-processing/task-queue-compressor/accumulating-task-compressor.ts index 9632e625..cdd8d2e2 100644 --- a/src/app/store/effects/tasks-processing/task-queue-compressor/accumulating-task-compressor.ts +++ b/src/app/store/effects/tasks-processing/task-queue-compressor/accumulating-task-compressor.ts @@ -1,16 +1,18 @@ +import { ControlSchemeBindingType } from '@app/shared'; + import { ITaskQueueCompressor } from '../i-task-queue-compressor'; -import { PortCommandTask, PortCommandTaskPayload, PortCommandTaskType } from '../../../models'; +import { PortCommandTask, PortCommandTaskPayload } from '../../../models'; import { payloadHash } from '../payload-hash'; -export abstract class AccumulatingTaskCompressor implements ITaskQueueCompressor { +export abstract class AccumulatingTaskCompressor implements ITaskQueueCompressor { protected constructor( - private readonly taskType: TPortCommandTaskType + private readonly taskType: TBindingType ) { } protected abstract buildPayloadChanges( - accumulatedTasks: Array> - ): Partial['payload']>; + accumulatedTasks: Array> + ): Partial['payload']>; /** * Compresses tasks into one task with accumulated payload @@ -19,14 +21,14 @@ export abstract class AccumulatingTaskCompressor | null = null; + let firstTaskOfType: PortCommandTask | null = null; let taskOfTypeCount = 0; - const accumulatedTasks: Array> = []; + const accumulatedTasks: Array> = []; for (let index = 0; index < queue.length; index++) { const command = queue[index]; - if (command.payload.taskType === this.taskType) { - const task = command as PortCommandTask; + if (command.payload.bindingType === this.taskType) { + const task = command as PortCommandTask; if (taskOfTypeCount === 0) { firstTaskOfType = task; } @@ -38,17 +40,17 @@ export abstract class AccumulatingTaskCompressor 1) { return queue.map((task) => { if (task === firstTaskOfType) { - const updatedFirstTask: PortCommandTask = { + const updatedFirstTask: PortCommandTask = { ...firstTaskOfType, payload: { ...firstTaskOfType.payload, ...this.buildPayloadChanges(accumulatedTasks) - } as PortCommandTaskPayload & { taskType: TPortCommandTaskType }, + } as PortCommandTaskPayload & { bindingType: TBindingType }, }; updatedFirstTask.hash = payloadHash(updatedFirstTask.payload); return updatedFirstTask; } - if (task.payload.taskType === this.taskType) { + if (task.payload.bindingType === this.taskType) { return null; } return task; diff --git a/src/app/store/effects/tasks-processing/task-queue-compressor/last-of-type-task-compressor.ts b/src/app/store/effects/tasks-processing/task-queue-compressor/last-of-type-task-compressor.ts index 94bf5046..f3f05762 100644 --- a/src/app/store/effects/tasks-processing/task-queue-compressor/last-of-type-task-compressor.ts +++ b/src/app/store/effects/tasks-processing/task-queue-compressor/last-of-type-task-compressor.ts @@ -1,9 +1,11 @@ +import { ControlSchemeBindingType } from '@app/shared'; + import { ITaskQueueCompressor } from '../i-task-queue-compressor'; -import { PortCommandTask, PortCommandTaskType } from '../../../models'; +import { PortCommandTask } from '../../../models'; export class LastOfTypeTaskCompressor implements ITaskQueueCompressor { constructor( - protected readonly taskType: PortCommandTaskType + protected readonly taskType: ControlSchemeBindingType ) { } @@ -14,7 +16,7 @@ export class LastOfTypeTaskCompressor implements ITaskQueueCompressor { for (let index = queue.length - 1; index >= 0; index--) { const command = queue[index]; - if (command.payload.taskType === this.taskType) { + if (command.payload.bindingType === this.taskType) { lastCommandsOfType = command; break; } @@ -24,6 +26,6 @@ export class LastOfTypeTaskCompressor implements ITaskQueueCompressor { return queue; } - return queue.filter((command) => command.payload.taskType !== this.taskType || command === lastCommandsOfType); + return queue.filter((command) => command.payload.bindingType !== this.taskType || command === lastCommandsOfType); } } diff --git a/src/app/store/effects/tasks-processing/task-queue-compressor/queue-compressor-factory.ts b/src/app/store/effects/tasks-processing/task-queue-compressor/queue-compressor-factory.ts index 78632132..23993e8f 100644 --- a/src/app/store/effects/tasks-processing/task-queue-compressor/queue-compressor-factory.ts +++ b/src/app/store/effects/tasks-processing/task-queue-compressor/queue-compressor-factory.ts @@ -1,16 +1,17 @@ +import { ControlSchemeBindingType } from '@app/shared'; + import { ITaskQueueCompressor } from '../i-task-queue-compressor'; import { ComposingTaskQueueCompressor } from './composing-task-queue-compressor'; import { LastOfTypeTaskCompressor } from './last-of-type-task-compressor'; -import { PortCommandTaskType } from '../../../models'; import { StepperTaskCompressor } from './stepper-task-compressor'; import { SetSpeedQueueCompressor } from './set-speed-queue-compressor'; export function queueCompressorFactory(): ITaskQueueCompressor { return new ComposingTaskQueueCompressor([ - new LastOfTypeTaskCompressor(PortCommandTaskType.Servo), - new LastOfTypeTaskCompressor(PortCommandTaskType.SetAngle), + new LastOfTypeTaskCompressor(ControlSchemeBindingType.Servo), + new LastOfTypeTaskCompressor(ControlSchemeBindingType.SetAngle), new StepperTaskCompressor(), new SetSpeedQueueCompressor(), - new LastOfTypeTaskCompressor(PortCommandTaskType.SpeedStepper) + new LastOfTypeTaskCompressor(ControlSchemeBindingType.SpeedStepper) ]); } diff --git a/src/app/store/effects/tasks-processing/task-queue-compressor/set-speed-queue-compressor.ts b/src/app/store/effects/tasks-processing/task-queue-compressor/set-speed-queue-compressor.ts index b54224b3..5d2fa0c7 100644 --- a/src/app/store/effects/tasks-processing/task-queue-compressor/set-speed-queue-compressor.ts +++ b/src/app/store/effects/tasks-processing/task-queue-compressor/set-speed-queue-compressor.ts @@ -1,4 +1,5 @@ -import { PortCommandTask, PortCommandTaskType } from '@app/store'; +import { PortCommandTask } from '@app/store'; +import { ControlSchemeBindingType } from '@app/shared'; import { ITaskQueueCompressor } from '../i-task-queue-compressor'; @@ -6,20 +7,20 @@ export class SetSpeedQueueCompressor implements ITaskQueueCompressor { public compress( queue: PortCommandTask[] ): PortCommandTask[] { - let lastSpeedTask: PortCommandTask | null = null; + let lastSpeedTask: PortCommandTask | null = null; // create new array with same length as queue (to avoid array resizing) const resultingQueue: PortCommandTask[] = new Array(queue.length); for (let index = queue.length - 1; index >= 0; index--) { const task = queue[index]; - if (task.payload.taskType !== PortCommandTaskType.SetSpeed) { + if (task.payload.bindingType !== ControlSchemeBindingType.Linear) { resultingQueue[index] = task; continue; } if (!lastSpeedTask) { - lastSpeedTask = task as PortCommandTask; + lastSpeedTask = task as PortCommandTask; resultingQueue[index] = task; continue; } diff --git a/src/app/store/effects/tasks-processing/task-queue-compressor/stepper-task-compressor.ts b/src/app/store/effects/tasks-processing/task-queue-compressor/stepper-task-compressor.ts index cd594961..49d169e3 100644 --- a/src/app/store/effects/tasks-processing/task-queue-compressor/stepper-task-compressor.ts +++ b/src/app/store/effects/tasks-processing/task-queue-compressor/stepper-task-compressor.ts @@ -1,14 +1,16 @@ -import { PortCommandTask, PortCommandTaskPayload, PortCommandTaskType } from '../../../models'; +import { ControlSchemeBindingType } from '@app/shared'; + +import { PortCommandTask, PortCommandTaskPayload } from '../../../models'; import { AccumulatingTaskCompressor } from './accumulating-task-compressor'; -export class StepperTaskCompressor extends AccumulatingTaskCompressor { +export class StepperTaskCompressor extends AccumulatingTaskCompressor { constructor() { - super(PortCommandTaskType.Stepper); + super(ControlSchemeBindingType.Stepper); } protected buildPayloadChanges( - accumulatedTasks: ReadonlyArray> - ): Partial { + accumulatedTasks: ReadonlyArray> + ): Partial { return { degree: accumulatedTasks.reduce((acc, task) => acc + task.payload.degree, 0) }; diff --git a/src/app/store/effects/tasks-processing/task-runner/runners/servo-task-runner.ts b/src/app/store/effects/tasks-processing/task-runner/runners/servo-task-runner.ts index 55b6747f..696c55e4 100644 --- a/src/app/store/effects/tasks-processing/task-runner/runners/servo-task-runner.ts +++ b/src/app/store/effects/tasks-processing/task-runner/runners/servo-task-runner.ts @@ -1,8 +1,9 @@ import { IHub, PortCommandExecutionStatus } from '@nvsukhanov/rxpoweredup'; import { Observable } from 'rxjs'; +import { ControlSchemeBindingType } from '@app/shared'; import { TaskRunner } from '../task-runner'; -import { PortCommandTask, PortCommandTaskType } from '../../../../models'; +import { PortCommandTask } from '../../../../models'; import { mapUseProfile } from '../map-use-profile'; export class ServoTaskRunner extends TaskRunner { @@ -10,7 +11,7 @@ export class ServoTaskRunner extends TaskRunner { task: PortCommandTask, hub: IHub ): Observable | null { - if (task.payload.taskType === PortCommandTaskType.Servo) { + if (task.payload.bindingType === ControlSchemeBindingType.Servo) { return hub.motors.goToPosition( task.portId, task.payload.angle, diff --git a/src/app/store/effects/tasks-processing/task-runner/runners/set-angle-task-runner.ts b/src/app/store/effects/tasks-processing/task-runner/runners/set-angle-task-runner.ts index 2f1df399..2f4de645 100644 --- a/src/app/store/effects/tasks-processing/task-runner/runners/set-angle-task-runner.ts +++ b/src/app/store/effects/tasks-processing/task-runner/runners/set-angle-task-runner.ts @@ -1,8 +1,9 @@ import { Observable } from 'rxjs'; import { IHub, PortCommandExecutionStatus } from '@nvsukhanov/rxpoweredup'; +import { ControlSchemeBindingType } from '@app/shared'; import { TaskRunner } from '../task-runner'; -import { PortCommandTask, PortCommandTaskType } from '../../../../models'; +import { PortCommandTask } from '../../../../models'; import { mapUseProfile } from '../map-use-profile'; export class SetAngleTaskRunner extends TaskRunner { @@ -10,7 +11,7 @@ export class SetAngleTaskRunner extends TaskRunner { task: PortCommandTask, hub: IHub ): Observable | null { - if (task.payload.taskType === PortCommandTaskType.SetAngle) { + if (task.payload.bindingType === ControlSchemeBindingType.SetAngle) { return hub.motors.goToPosition( task.portId, task.payload.angle, diff --git a/src/app/store/effects/tasks-processing/task-runner/runners/set-speed-task-runner.ts b/src/app/store/effects/tasks-processing/task-runner/runners/set-speed-task-runner.ts index fc208adf..a76cbd68 100644 --- a/src/app/store/effects/tasks-processing/task-runner/runners/set-speed-task-runner.ts +++ b/src/app/store/effects/tasks-processing/task-runner/runners/set-speed-task-runner.ts @@ -1,8 +1,9 @@ import { IHub, PortCommandExecutionStatus } from '@nvsukhanov/rxpoweredup'; import { Observable } from 'rxjs'; +import { ControlSchemeBindingType } from '@app/shared'; import { TaskRunner } from '../task-runner'; -import { PortCommandTask, PortCommandTaskType } from '../../../../models'; +import { PortCommandTask } from '../../../../models'; import { mapUseProfile } from '../map-use-profile'; export class SetSpeedTaskRunner extends TaskRunner { @@ -10,7 +11,7 @@ export class SetSpeedTaskRunner extends TaskRunner { task: PortCommandTask, hub: IHub ): Observable | null { - if (task.payload.taskType === PortCommandTaskType.SetSpeed) { + if (task.payload.bindingType === ControlSchemeBindingType.Linear) { return hub.motors.setSpeed( task.portId, task.payload.speed, diff --git a/src/app/store/effects/tasks-processing/task-runner/runners/speed-stepper-task-runner.ts b/src/app/store/effects/tasks-processing/task-runner/runners/speed-stepper-task-runner.ts index 990c6a00..398bf3e8 100644 --- a/src/app/store/effects/tasks-processing/task-runner/runners/speed-stepper-task-runner.ts +++ b/src/app/store/effects/tasks-processing/task-runner/runners/speed-stepper-task-runner.ts @@ -1,7 +1,8 @@ import { IHub, PortCommandExecutionStatus } from '@nvsukhanov/rxpoweredup'; import { Observable } from 'rxjs'; -import { PortCommandTask, PortCommandTaskType } from '@app/store'; +import { ControlSchemeBindingType } from '@app/shared'; +import { PortCommandTask } from '../../../../models'; import { TaskRunner } from '../task-runner'; import { mapUseProfile } from '../map-use-profile'; @@ -10,7 +11,7 @@ export class SpeedStepperTaskRunner extends TaskRunner { task: PortCommandTask, hub: IHub ): Observable | null { - if (task.payload.taskType === PortCommandTaskType.SpeedStepper) { + if (task.payload.bindingType === ControlSchemeBindingType.SpeedStepper) { return hub.motors.setSpeed( task.portId, task.payload.speed, diff --git a/src/app/store/effects/tasks-processing/task-runner/runners/stepper-task-runner.ts b/src/app/store/effects/tasks-processing/task-runner/runners/stepper-task-runner.ts index 154652c9..20819134 100644 --- a/src/app/store/effects/tasks-processing/task-runner/runners/stepper-task-runner.ts +++ b/src/app/store/effects/tasks-processing/task-runner/runners/stepper-task-runner.ts @@ -1,8 +1,9 @@ import { IHub, PortCommandExecutionStatus } from '@nvsukhanov/rxpoweredup'; import { Observable, last } from 'rxjs'; +import { ControlSchemeBindingType } from '@app/shared'; import { TaskRunner } from '../task-runner'; -import { PortCommandTask, PortCommandTaskType } from '../../../../models'; +import { PortCommandTask } from '../../../../models'; import { mapUseProfile } from '../map-use-profile'; export class StepperTaskRunner extends TaskRunner { @@ -10,7 +11,7 @@ export class StepperTaskRunner extends TaskRunner { task: PortCommandTask, hub: IHub ): Observable | null { - if (task.payload.taskType === PortCommandTaskType.Stepper) { + if (task.payload.bindingType === ControlSchemeBindingType.Stepper) { return hub.motors.rotateByDegree( task.portId, task.payload.degree, diff --git a/src/app/store/models/port-command-task.ts b/src/app/store/models/port-command-task.ts index fed49934..7a16e56b 100644 --- a/src/app/store/models/port-command-task.ts +++ b/src/app/store/models/port-command-task.ts @@ -1,15 +1,8 @@ import { MotorServoEndState } from '@nvsukhanov/rxpoweredup'; - -export enum PortCommandTaskType { - SetSpeed = 'SetSpeed', - Servo = 'Servo', - SetAngle = 'SetAngle', - Stepper = 'Stepper', - SpeedStepper = 'SpeedStepper' -} +import { ControlSchemeBindingType } from '@app/shared'; export type SetLinearSpeedTaskPayload = { - taskType: PortCommandTaskType.SetSpeed; + bindingType: ControlSchemeBindingType.Linear; activeInput: boolean; speed: number; power: number; @@ -18,7 +11,7 @@ export type SetLinearSpeedTaskPayload = { }; export type ServoTaskPayload = { - taskType: PortCommandTaskType.Servo; + bindingType: ControlSchemeBindingType.Servo; angle: number; speed: number; power: number; @@ -28,7 +21,7 @@ export type ServoTaskPayload = { }; export type SetAngleTaskPayload = { - taskType: PortCommandTaskType.SetAngle; + bindingType: ControlSchemeBindingType.SetAngle; angle: number; speed: number; power: number; @@ -38,7 +31,7 @@ export type SetAngleTaskPayload = { }; export type StepperTaskPayload = { - taskType: PortCommandTaskType.Stepper; + bindingType: ControlSchemeBindingType.Stepper; degree: number; speed: number; power: number; @@ -48,7 +41,7 @@ export type StepperTaskPayload = { }; export type SpeedStepperTaskPayload = { - taskType: PortCommandTaskType.SpeedStepper; + bindingType: ControlSchemeBindingType.SpeedStepper; nextSpeedActiveInput: boolean; prevSpeedActiveInput: boolean; speed: number; @@ -64,11 +57,11 @@ export type PortCommandTaskPayload = SetLinearSpeedTaskPayload | StepperTaskPayload | SpeedStepperTaskPayload; -export type PortCommandTask = { +export type PortCommandTask = { hubId: string; portId: number; bindingId: string; - payload: PortCommandTaskPayload & { taskType: TPayloadType }; + payload: PortCommandTaskPayload & { bindingType: TPayloadType }; hash: string; inputTimestamp: number; }; diff --git a/src/app/store/provide-store.ts b/src/app/store/provide-store.ts index 7b55919d..0235590a 100644 --- a/src/app/store/provide-store.ts +++ b/src/app/store/provide-store.ts @@ -41,7 +41,7 @@ import { HubStorageService } from './hub-storage.service'; import { RoutesBuilderService } from '../routing'; import { HUB_STATS_ACTIONS } from './actions'; -const STORAGE_VERSION = '13'; +const STORAGE_VERSION = '14'; const REDUCERS: ActionReducerMap = { bluetoothAvailability: BLUETOOTH_AVAILABILITY_FEATURE.reducer,