preliminary-changes

Implemented toggle switches for each RGB component.
This commit is contained in:
Dmitriy Antipov
2023-05-09 17:27:05 +03:00
parent c37a5d3cc5
commit 73768bb236
4 changed files with 140 additions and 39 deletions

View File

@ -21,7 +21,9 @@ 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);
@ -32,8 +34,13 @@ namespace pxsim {
return DAL.DEVICE_TYPE_COLOR;
}
setColor(color: number) {
this.color = color;
setColors(colors: number[]) {
this.colors = colors;
this.setChangedState();
}
setColor(colors: number) {
this.colors = [colors];
this.setChangedState();
}
@ -41,10 +48,15 @@ namespace pxsim {
return this.color;
}
getValues() {
return this.colors;
}
setMode(mode: number) {
this.mode = mode;
if (this.mode == ColorSensorMode.RefRaw) this.color = 512;
else this.color = 50;
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
this.changed = true;
this.modeChanged = true;
}

View File

@ -59,6 +59,64 @@ namespace pxsim {
}
}
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() {
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 AnalogSensorNode extends SensorNode {
constructor(port: number) {
@ -84,4 +142,20 @@ namespace pxsim {
return this.changed;
}
}
export class UartSensorExtendedNode extends SensorNode {
constructor(port: number) {
super(port);
}
hasChanged() {
return this.changed;
}
public getValues() {
return [0];
}
}
}