preliminary-changes-2

This commit is contained in:
Dmitriy Antipov 2023-05-10 10:43:28 +03:00
parent 73768bb236
commit d6d4479889
6 changed files with 33 additions and 82 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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];
}
}
}

View File

@ -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;
}

View File

@ -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];

View File

@ -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})`