final-changes

This commit is contained in:
Dmitriy Antipov 2023-05-13 22:53:44 +03:00
parent d6d4479889
commit 333b487bb6
6 changed files with 46 additions and 27 deletions

View File

@ -87,11 +87,18 @@ namespace sensors {
|| this.mode == ColorSensorMode.AmbientLightIntensity || this.mode == ColorSensorMode.AmbientLightIntensity
|| this.mode == ColorSensorMode.ReflectedLightIntensity) || this.mode == ColorSensorMode.ReflectedLightIntensity)
return this.getNumber(NumberFormat.UInt8LE, 0) 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 this.getNumber(NumberFormat.UInt16LE, 0)
return 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 { _info(): string {
switch (this.mode) { switch (this.mode) {
case ColorSensorMode.Color: case ColorSensorMode.Color:
@ -106,11 +113,23 @@ namespace sensors {
case ColorSensorMode.AmbientLightIntensity: case ColorSensorMode.AmbientLightIntensity:
case ColorSensorMode.ReflectedLightIntensity: case ColorSensorMode.ReflectedLightIntensity:
return `${this._query()}%`; return `${this._query()}%`;
case ColorSensorMode.RgbRaw:
return "array";
default: default:
return this._query().toString(); 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) { _update(prev: number, curr: number) {
if (this.calibrating) return; // simply ignore data updates while calibrating if (this.calibrating) return; // simply ignore data updates while calibrating
if (this.mode == ColorSensorMode.Color || this.mode == ColorSensorMode.RgbRaw || this.mode == ColorSensorMode.RefRaw) if (this.mode == ColorSensorMode.Color || this.mode == ColorSensorMode.RgbRaw || this.mode == ColorSensorMode.RefRaw)

View File

@ -400,6 +400,10 @@ void cUiUpdatePower(void)
return this._query().toString(); return this._query().toString();
} }
_infoArr(): string[] {
return [this._query().toString()];
}
_update(prev: number, curr: number) { _update(prev: number, curr: number) {
} }

View File

@ -272,7 +272,14 @@ namespace brick {
const x = (si.port() - 1) * col + 2; const x = (si.port() - 1) * col + 2;
const inf = si._info(); const inf = si._info();
if (screenMode != ScreenMode.Ports) return; 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);
}
} }
} }

View File

@ -43,8 +43,8 @@ namespace pxsim {
this.setChangedState(); this.setChangedState();
} }
setColor(colors: number) { setColor(color: number) {
this.color = colors; this.color = color;
this.setChangedState(); this.setChangedState();
} }
@ -60,12 +60,15 @@ namespace pxsim {
this.mode = mode; this.mode = mode;
if (this.mode == ColorSensorMode.RefRaw) { if (this.mode == ColorSensorMode.RefRaw) {
this.color = 512; this.color = 512;
this.colors = [0, 0, 0];
this.modeReturnArr = false; this.modeReturnArr = false;
} else if (this.mode == ColorSensorMode.RgbRaw) { } else if (this.mode == ColorSensorMode.RgbRaw) {
this.color = 0;
this.colors = [128, 128, 128]; this.colors = [128, 128, 128];
this.modeReturnArr = true; this.modeReturnArr = true;
} else { // Reflection or ambiend light } else { // Reflection or ambiend light
this.color = 50; this.color = 50;
this.colors = [0, 0, 0];
this.modeReturnArr = false; this.modeReturnArr = false;
} }
this.changed = true; this.changed = true;

View File

@ -91,13 +91,15 @@ namespace pxsim {
if (node && node.isUart()) { if (node && node.isUart()) {
// Actual // Actual
const index = 0; //UartOff.Actual + port * 2; const index = 0; //UartOff.Actual + port * 2;
//console.log(node.isModeReturnArr()); // Узнать возвращает ли режим датчика массив значений
let value, values;
if (!node.isModeReturnArr()) { 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); util.map16Bit(data, UartOff.Raw + DAL.MAX_DEVICE_DATALENGTH * 300 * port + DAL.MAX_DEVICE_DATALENGTH * index, value);
} else values = node.getValues(); } else {
//util.map16Bit(data, UartOff.Raw + DAL.MAX_DEVICE_DATALENGTH * 300 * port + DAL.MAX_DEVICE_DATALENGTH * index, value); 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 // Status
data[UartOff.Status + port] = node.valueChange() ? UartStatus.UART_PORT_CHANGED : UartStatus.UART_DATA_READY; data[UartOff.Status + port] = node.valueChange() ? UartStatus.UART_PORT_CHANGED : UartStatus.UART_DATA_READY;
} }

View File

@ -5,7 +5,6 @@ namespace pxsim.visuals {
private colorGradient: SVGLinearGradientElement[] = []; private colorGradient: SVGLinearGradientElement[] = [];
private reporter: SVGTextElement[] = []; private reporter: SVGTextElement[] = [];
private rect: SVGElement[] = []; private rect: SVGElement[] = [];
private printOffsetH = 16; private printOffsetH = 16;
private rgbLetters: string[] = ["R", "G", "B"]; private rgbLetters: string[] = ["R", "G", "B"];
private rectNames: string[] = ["rectR", "rectG", "rectB"]; private rectNames: string[] = ["rectR", "rectG", "rectB"];
@ -33,7 +32,7 @@ namespace pxsim.visuals {
} }
private getMaxValue() { private getMaxValue() {
return 511; return 512;
} }
private mapValue(x: number, inMin: number, inMax: number, outMin: number, outMax: number) { private mapValue(x: number, inMin: number, inMax: number, outMin: number, outMax: number) {
@ -44,8 +43,6 @@ namespace pxsim.visuals {
if (!this.visible) return; if (!this.visible) return;
const node = this.state; const node = this.state;
const values = node.getValues(); const values = node.getValues();
//console.log("values: ");
//console.log(values);
let inverseValue: number[] = []; let inverseValue: number[] = [];
for (let i = 0; i < 3; i++) { for (let i = 0; i < 3; i++) {
inverseValue[i] = this.getMaxValue() - values[i]; inverseValue[i] = this.getMaxValue() - values[i];
@ -56,13 +53,9 @@ namespace pxsim.visuals {
} }
updateColorLevel(pt: SVGPoint, parent: SVGSVGElement, ev: MouseEvent) { 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; if (!this.classVal) this.classVal = (ev.target as HTMLElement).classList.value;
//console.log("classVal: " + this.classVal);
let cur = svg.cursorPoint(pt, parent, ev); let cur = svg.cursorPoint(pt, parent, ev);
let index = this.rectNames.findIndex(i => i == this.classVal); let index = this.rectNames.findIndex(i => i == this.classVal);
//console.log("index: " + index);
const bBox = this.rect[index].getBoundingClientRect(); const bBox = this.rect[index].getBoundingClientRect();
const height = bBox.height; const height = bBox.height;
let t = Math.max(0, Math.min(1, (height + bBox.top / this.scaleFactor - cur.y / this.scaleFactor) / 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"); svg.setGradientColors(this.colorGradient[i], "black", "yellow");
} }
let pt = parent.createSVGPoint();
let reporterGroup: SVGElement[] = []; let reporterGroup: SVGElement[] = [];
for (let i = 0; i < 3; i++) { for (let i = 0; i < 3; i++) {
reporterGroup[i] = pxsim.svg.child(this.group, "g"); 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})`); 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; 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[] = []; let sliderGroup: SVGElement[] = [];
@ -103,8 +90,6 @@ namespace pxsim.visuals {
sliderGroup[i] = pxsim.svg.child(this.group, "g"); sliderGroup[i] = pxsim.svg.child(this.group, "g");
const translateX = (this.getWidth() / 2 - this.getSliderWidth() / 2 - 36) + 36 * i; const translateX = (this.getWidth() / 2 - this.getSliderWidth() / 2 - 36) + 36 * i;
sliderGroup[i].setAttribute("transform", `translate(${translateX}, ${this.getReporterHeight()})`); 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", { this.rect[i] = pxsim.svg.child(sliderGroup[i], "rect", {
"width": this.getSliderWidth(), "width": this.getSliderWidth(),
@ -112,10 +97,9 @@ namespace pxsim.visuals {
"style": `fill: url(#${gc + "-" + i})` "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++) { for (let i = 0; i < 3; i++) {
touchEvents(this.rect[i], ev => { touchEvents(this.rect[i], ev => {
if (this.captured && (ev as MouseEvent).clientY) { if (this.captured && (ev as MouseEvent).clientY) {