diff --git a/fieldeditors/field_speed.ts b/fieldeditors/field_speed.ts index 62300de5..727928f5 100644 --- a/fieldeditors/field_speed.ts +++ b/fieldeditors/field_speed.ts @@ -76,9 +76,12 @@ export class FieldSpeed extends Blockly.FieldSlider implements Blockly.FieldCust }; setReadout_(readout: Element, value: string) { - this.updateSpeed(parseFloat(value)); + let x = parseFloat(value) || 0; + // snap on multiple of 5 + x = Math.round(x / 5) * 5; + this.updateSpeed(x); // Update reporter - this.reporter.textContent = `${value}%`; + this.reporter.textContent = `${x}%`; } private updateSpeed(speed: number) { diff --git a/libs/core/output.ts b/libs/core/output.ts index e220ba2a..18fc38db 100644 --- a/libs/core/output.ts +++ b/libs/core/output.ts @@ -301,9 +301,17 @@ namespace motors { case MoveUnit.Rotations: scale = 360; r.useSteps = true; + if (r.steps[1] < 0) { + r.speed = -r.speed; + r.steps[1] = -r.steps[1]; + } break; case MoveUnit.Degrees: r.useSteps = true; + if (r.steps[1] < 0) { + r.speed = -r.speed; + r.steps[1] = -r.steps[1]; + } break; case MoveUnit.Seconds: scale = 1000; @@ -416,28 +424,28 @@ namespace motors { temp = Math.max(0, (value * 360) | 0); if (phase == MovePhase.Acceleration) this._accelerationSteps = temp; - else + else this._decelerationSteps = temp; break; case MoveUnit.Degrees: temp = Math.max(0, value | 0); if (phase == MovePhase.Acceleration) this._accelerationSteps = temp; - else + else this._decelerationSteps = temp; break; case MoveUnit.Seconds: temp = Math.max(0, (value * 1000) | 0); if (phase == MovePhase.Acceleration) this._accelerationTime = temp; - else + else this._decelerationTime = temp; break; case MoveUnit.MilliSeconds: temp = Math.max(0, value | 0); if (phase == MovePhase.Acceleration) this._accelerationTime = temp; - else + else this._decelerationTime = temp; break; } @@ -741,10 +749,18 @@ namespace motors { let stepsOrTime: number; switch (unit) { case MoveUnit.Rotations: + if (value < 0) { + value = -value; + speed = -speed; + } stepsOrTime = (value * 360) >> 0; useSteps = true; break; case MoveUnit.Degrees: + if (value < 0) { + value = -value; + speed = -speed; + } stepsOrTime = value >> 0; useSteps = true; break;