From 333b487bb649710833d3665722cdcae115156912 Mon Sep 17 00:00:00 2001 From: Dmitriy Antipov Date: Sat, 13 May 2023 22:53:44 +0300 Subject: [PATCH] final-changes --- libs/color-sensor/color.ts | 21 ++++++++++++++++++++- libs/core/input.ts | 4 ++++ libs/screen/targetoverrides.ts | 9 ++++++++- sim/state/color.ts | 7 +++++-- sim/state/uart.ts | 12 +++++++----- sim/visuals/controls/colorRGBWheel.ts | 20 ++------------------ 6 files changed, 46 insertions(+), 27 deletions(-) diff --git a/libs/color-sensor/color.ts b/libs/color-sensor/color.ts index a6a7c626..43be7e8a 100644 --- a/libs/color-sensor/color.ts +++ b/libs/color-sensor/color.ts @@ -87,11 +87,18 @@ namespace sensors { || this.mode == ColorSensorMode.AmbientLightIntensity || this.mode == ColorSensorMode.ReflectedLightIntensity) return this.getNumber(NumberFormat.UInt8LE, 0) - if (this.mode == ColorSensorMode.RefRaw || this.mode == ColorSensorMode.RgbRaw) + if (this.mode == ColorSensorMode.RefRaw) return this.getNumber(NumberFormat.UInt16LE, 0) return 0 } + _queryArr(): number[] { + if (this.mode == ColorSensorMode.RgbRaw) { + return [this.getNumber(NumberFormat.UInt16LE, 0), this.getNumber(NumberFormat.UInt16LE, 2), this.getNumber(NumberFormat.UInt16LE, 4)]; + } + return [0, 0, 0]; + } + _info(): string { switch (this.mode) { case ColorSensorMode.Color: @@ -106,11 +113,23 @@ namespace sensors { case ColorSensorMode.AmbientLightIntensity: case ColorSensorMode.ReflectedLightIntensity: return `${this._query()}%`; + case ColorSensorMode.RgbRaw: + return "array"; default: return this._query().toString(); } } + _infoArr(): string[] { + switch (this.mode) { + case ColorSensorMode.RgbRaw: + const queryArr = this._queryArr().map(number => number.toString()); + return queryArr; + default: + return ["0", "0", "0"]; + } + } + _update(prev: number, curr: number) { if (this.calibrating) return; // simply ignore data updates while calibrating if (this.mode == ColorSensorMode.Color || this.mode == ColorSensorMode.RgbRaw || this.mode == ColorSensorMode.RefRaw) diff --git a/libs/core/input.ts b/libs/core/input.ts index dc4872df..9dc18e4d 100644 --- a/libs/core/input.ts +++ b/libs/core/input.ts @@ -400,6 +400,10 @@ void cUiUpdatePower(void) return this._query().toString(); } + _infoArr(): string[] { + return [this._query().toString()]; + } + _update(prev: number, curr: number) { } diff --git a/libs/screen/targetoverrides.ts b/libs/screen/targetoverrides.ts index 6f2e78ad..0d0005a9 100644 --- a/libs/screen/targetoverrides.ts +++ b/libs/screen/targetoverrides.ts @@ -272,7 +272,14 @@ namespace brick { const x = (si.port() - 1) * col + 2; const inf = si._info(); if (screenMode != ScreenMode.Ports) return; - if (inf) screen.print(inf, x, h - 2 * lineHeight8, 1, inf.length > 4 ? image.font5 : image.font8); + if (inf == "array") { + let infArr = si._infoArr(); + for (let data = 0, str = Math.min(infArr.length + 1, 4); data < Math.min(infArr.length, 3); data++, str--) { + screen.print(infArr[data], x, h - str * lineHeight8, 1, infArr[data].length > 4 ? image.font5 : image.font8); + } + } else if (inf) { + screen.print(inf, x, h - 2 * lineHeight8, 1, inf.length > 4 ? image.font5 : image.font8); + } } } diff --git a/sim/state/color.ts b/sim/state/color.ts index b7fc0422..b82d607f 100644 --- a/sim/state/color.ts +++ b/sim/state/color.ts @@ -43,8 +43,8 @@ namespace pxsim { this.setChangedState(); } - setColor(colors: number) { - this.color = colors; + setColor(color: number) { + this.color = color; this.setChangedState(); } @@ -60,12 +60,15 @@ namespace pxsim { this.mode = mode; if (this.mode == ColorSensorMode.RefRaw) { this.color = 512; + this.colors = [0, 0, 0]; this.modeReturnArr = false; } else if (this.mode == ColorSensorMode.RgbRaw) { + this.color = 0; this.colors = [128, 128, 128]; this.modeReturnArr = true; } else { // Reflection or ambiend light this.color = 50; + this.colors = [0, 0, 0]; this.modeReturnArr = false; } this.changed = true; diff --git a/sim/state/uart.ts b/sim/state/uart.ts index 70a3777f..7915664e 100644 --- a/sim/state/uart.ts +++ b/sim/state/uart.ts @@ -91,13 +91,15 @@ namespace pxsim { if (node && node.isUart()) { // Actual const index = 0; //UartOff.Actual + port * 2; - //console.log(node.isModeReturnArr()); // Узнать возвращает ли режим датчика массив значений - let value, values; if (!node.isModeReturnArr()) { - value = Math.floor(node.getValue()); + const 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); + } else { + const values = node.getValues(); + for (let i = 0, offset = 0; i < values.length; i++, offset += 2) { + util.map16Bit(data, UartOff.Raw + DAL.MAX_DEVICE_DATALENGTH * 300 * port + DAL.MAX_DEVICE_DATALENGTH * index + offset, Math.floor(values[i])); + } + } // 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 882c383a..aad52642 100644 --- a/sim/visuals/controls/colorRGBWheel.ts +++ b/sim/visuals/controls/colorRGBWheel.ts @@ -5,7 +5,6 @@ namespace pxsim.visuals { private colorGradient: SVGLinearGradientElement[] = []; private reporter: SVGTextElement[] = []; private rect: SVGElement[] = []; - private printOffsetH = 16; private rgbLetters: string[] = ["R", "G", "B"]; private rectNames: string[] = ["rectR", "rectG", "rectB"]; @@ -33,7 +32,7 @@ namespace pxsim.visuals { } private getMaxValue() { - return 511; + return 512; } private mapValue(x: number, inMin: number, inMax: number, outMin: number, outMax: number) { @@ -44,8 +43,6 @@ namespace pxsim.visuals { if (!this.visible) return; const node = this.state; const values = node.getValues(); - //console.log("values: "); - //console.log(values); let inverseValue: number[] = []; for (let i = 0; i < 3; i++) { inverseValue[i] = this.getMaxValue() - values[i]; @@ -56,13 +53,9 @@ namespace pxsim.visuals { } updateColorLevel(pt: SVGPoint, parent: SVGSVGElement, ev: MouseEvent) { - //console.log(ev); - //console.log(ev.target); if (!this.classVal) this.classVal = (ev.target as HTMLElement).classList.value; - //console.log("classVal: " + this.classVal); let cur = svg.cursorPoint(pt, parent, ev); let index = this.rectNames.findIndex(i => i == this.classVal); - //console.log("index: " + index); const bBox = this.rect[index].getBoundingClientRect(); const height = bBox.height; let t = Math.max(0, Math.min(1, (height + bBox.top / this.scaleFactor - cur.y / this.scaleFactor) / height)); @@ -84,18 +77,12 @@ namespace pxsim.visuals { svg.setGradientColors(this.colorGradient[i], "black", "yellow"); } - let pt = parent.createSVGPoint(); - let reporterGroup: SVGElement[] = []; for (let i = 0; i < 3; i++) { reporterGroup[i] = pxsim.svg.child(this.group, "g"); - //console.log(`reporterGroup[${i}]:`); - //console.log(reporterGroup[i]); reporterGroup[i].setAttribute("transform", `translate(${this.getWidth() / 2}, ${18 + this.printOffsetH * i})`); this.reporter[i] = pxsim.svg.child(reporterGroup[i], "text", { 'text-anchor': 'middle', 'class': 'sim-text number large inverted', 'style': 'font-size: 18px;' }) as SVGTextElement; - //console.log(`this.reporter[${i}]:`); - //console.log(this.reporter[0]); } let sliderGroup: SVGElement[] = []; @@ -103,8 +90,6 @@ namespace pxsim.visuals { sliderGroup[i] = pxsim.svg.child(this.group, "g"); const translateX = (this.getWidth() / 2 - this.getSliderWidth() / 2 - 36) + 36 * i; sliderGroup[i].setAttribute("transform", `translate(${translateX}, ${this.getReporterHeight()})`); - //console.log(`sliderGroup[${i}]:`); - //console.log(sliderGroup[i]); this.rect[i] = pxsim.svg.child(sliderGroup[i], "rect", { "width": this.getSliderWidth(), @@ -112,10 +97,9 @@ namespace pxsim.visuals { "style": `fill: url(#${gc + "-" + i})` } ); - //console.log(`this.rect[${i}]:`); - //console.log(this.rect[i]); } + let pt = parent.createSVGPoint(); for (let i = 0; i < 3; i++) { touchEvents(this.rect[i], ev => { if (this.captured && (ev as MouseEvent).clientY) {