From d6d4479889ff345d986f6504b399928920bf8fdb Mon Sep 17 00:00:00 2001 From: Dmitriy Antipov Date: Wed, 10 May 2023 10:43:28 +0300 Subject: [PATCH] preliminary-changes-2 --- sim/dalboard.ts | 3 +- sim/state/color.ts | 21 ++++++-- sim/state/sensor.ts | 77 +++------------------------ sim/state/uart.ts | 8 ++- sim/visuals/controls/colorRGBWheel.ts | 4 +- sim/visuals/controls/colorWheel.ts | 2 - 6 files changed, 33 insertions(+), 82 deletions(-) diff --git a/sim/dalboard.ts b/sim/dalboard.ts index 8a1dcf7e..c778866c 100644 --- a/sim/dalboard.ts +++ b/sim/dalboard.ts @@ -151,7 +151,7 @@ namespace pxsim { return !!this.inputNodes[port]; } - getSensor(port: number, type: number): SensorNode | SensorExtendedNode { + getSensor(port: number, type: number): SensorNode { if (!this.inputNodes[port]) { switch (type) { case DAL.DEVICE_TYPE_GYRO: this.inputNodes[port] = new GyroSensorNode(port); break; @@ -189,7 +189,6 @@ namespace pxsim { } export function inHighcontrastMode(): boolean { - /// return ev3board().highcontrastMode; } diff --git a/sim/state/color.ts b/sim/state/color.ts index e453c0b7..b7fc0422 100644 --- a/sim/state/color.ts +++ b/sim/state/color.ts @@ -21,26 +21,30 @@ namespace pxsim { export class ColorSensorNode extends UartSensorNode { id = NodeType.ColorSensor; - //private colors: number[] = [0]; private color: number = 0; private colors: number[] = [0, 0, 0]; constructor(port: number) { super(port); this.mode = -1; + this.modeReturnArr = false; } getDeviceType() { return DAL.DEVICE_TYPE_COLOR; } + isModeReturnArr() { + return this.modeReturnArr; + } + setColors(colors: number[]) { this.colors = colors; this.setChangedState(); } setColor(colors: number) { - this.colors = [colors]; + this.color = colors; this.setChangedState(); } @@ -54,9 +58,16 @@ namespace pxsim { setMode(mode: number) { this.mode = mode; - if (this.mode == ColorSensorMode.RefRaw) this.color = 512; - else if (this.mode == ColorSensorMode.RgbRaw) this.colors = [128, 128, 128]; - else this.color = 50; // Reflection or ambiend light + if (this.mode == ColorSensorMode.RefRaw) { + this.color = 512; + this.modeReturnArr = false; + } else if (this.mode == ColorSensorMode.RgbRaw) { + this.colors = [128, 128, 128]; + this.modeReturnArr = true; + } else { // Reflection or ambiend light + this.color = 50; + this.modeReturnArr = false; + } this.changed = true; this.modeChanged = true; } diff --git a/sim/state/sensor.ts b/sim/state/sensor.ts index 23d853ea..42e2df01 100644 --- a/sim/state/sensor.ts +++ b/sim/state/sensor.ts @@ -6,6 +6,7 @@ namespace pxsim { protected mode: number; protected valueChanged: boolean; protected modeChanged: boolean; + protected modeReturnArr: boolean; constructor(port: number) { super(port); @@ -19,65 +20,15 @@ namespace pxsim { return false; } + public isModeReturnArr() { + return this.modeReturnArr; + } + public getValue() { return 0; } - setMode(mode: number) { - this.mode = mode; - this.changed = true; - this.modeChanged = true; - } - - getMode() { - return this.mode; - } - - getDeviceType() { - return DAL.DEVICE_TYPE_NONE; - } - - public hasData() { - return true; - } - - valueChange() { - const res = this.valueChanged; - this.valueChanged = false; - return res; - } - - modeChange() { - const res = this.modeChanged; - this.modeChanged = false; - return res; - } - - setChangedState() { - this.changed = true; - this.valueChanged = false; - } - } - - export class SensorExtendedNode extends BaseNode { - - protected mode: number; - protected valueChanged: boolean; - protected modeChanged: boolean; - - constructor(port: number) { - super(port); - } - - public isUart() { - return true; - } - - public isAnalog() { - return false; - } - - public getValue() { + public getValues() { return [0]; } @@ -85,6 +36,7 @@ namespace pxsim { this.mode = mode; this.changed = true; this.modeChanged = true; + this.modeReturnArr = false; } getMode() { @@ -143,19 +95,4 @@ namespace pxsim { } } - export class UartSensorExtendedNode extends SensorNode { - - constructor(port: number) { - super(port); - } - - hasChanged() { - return this.changed; - } - - public getValues() { - return [0]; - } - } - } \ No newline at end of file diff --git a/sim/state/uart.ts b/sim/state/uart.ts index 70247b9a..70a3777f 100644 --- a/sim/state/uart.ts +++ b/sim/state/uart.ts @@ -91,7 +91,13 @@ namespace pxsim { if (node && node.isUart()) { // Actual const index = 0; //UartOff.Actual + port * 2; - util.map16Bit(data, UartOff.Raw + DAL.MAX_DEVICE_DATALENGTH * 300 * port + DAL.MAX_DEVICE_DATALENGTH * index, Math.floor(node.getValue())) + //console.log(node.isModeReturnArr()); // Узнать возвращает ли режим датчика массив значений + let value, values; + if (!node.isModeReturnArr()) { + value = Math.floor(node.getValue()); + util.map16Bit(data, UartOff.Raw + DAL.MAX_DEVICE_DATALENGTH * 300 * port + DAL.MAX_DEVICE_DATALENGTH * index, value); + } else values = node.getValues(); + //util.map16Bit(data, UartOff.Raw + DAL.MAX_DEVICE_DATALENGTH * 300 * port + DAL.MAX_DEVICE_DATALENGTH * index, value); // Status data[UartOff.Status + port] = node.valueChange() ? UartStatus.UART_PORT_CHANGED : UartStatus.UART_DATA_READY; } diff --git a/sim/visuals/controls/colorRGBWheel.ts b/sim/visuals/controls/colorRGBWheel.ts index badad5d6..882c383a 100644 --- a/sim/visuals/controls/colorRGBWheel.ts +++ b/sim/visuals/controls/colorRGBWheel.ts @@ -33,7 +33,7 @@ namespace pxsim.visuals { } private getMaxValue() { - return 512; + return 511; } private mapValue(x: number, inMin: number, inMax: number, outMin: number, outMax: number) { @@ -45,7 +45,7 @@ namespace pxsim.visuals { const node = this.state; const values = node.getValues(); //console.log("values: "); - console.log(values); + //console.log(values); let inverseValue: number[] = []; for (let i = 0; i < 3; i++) { inverseValue[i] = this.getMaxValue() - values[i]; diff --git a/sim/visuals/controls/colorWheel.ts b/sim/visuals/controls/colorWheel.ts index 0edb9a03..daf30738 100644 --- a/sim/visuals/controls/colorWheel.ts +++ b/sim/visuals/controls/colorWheel.ts @@ -74,8 +74,6 @@ namespace pxsim.visuals { const rect = pxsim.svg.child(sliderGroup, "rect", { - "x": 0, - "y": 0, "width": this.getSliderWidth(), "height": this.getSliderHeight(), "style": `fill: url(#${gc})`