Fix ultrasonic value to use cm instead of 0.1 cm units (#110)
* Fix simulator * use 250 instead of 255
This commit is contained in:
committed by
Peli de Halleux
parent
b07f157181
commit
0529759a80
@ -38,7 +38,7 @@ namespace pxsim {
|
||||
data[AnalogOff.InConn + port] = node.isUart() ? DAL.CONN_INPUT_UART : DAL.CONN_INPUT_DUMB;
|
||||
if (node.isAnalog() && node.hasData()) {
|
||||
//data[AnalogOff.InPin6 + 2 * port] = node.getValue();
|
||||
util.map16Bit(data, AnalogOff.InPin6 + 2 * port, node.getValue())
|
||||
util.map16Bit(data, AnalogOff.InPin6 + 2 * port, Math.floor(node.getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ namespace pxsim {
|
||||
if (node) {
|
||||
// Actual
|
||||
const index = 0; //UartOff.Actual + port * 2;
|
||||
data[UartOff.Raw + DAL.MAX_DEVICE_DATALENGTH * 300 * port + DAL.MAX_DEVICE_DATALENGTH * index] = node.getValue();
|
||||
util.map16Bit(data, UartOff.Raw + DAL.MAX_DEVICE_DATALENGTH * 300 * port + DAL.MAX_DEVICE_DATALENGTH * index, Math.floor(node.getValue()))
|
||||
// Status
|
||||
data[UartOff.Status + port] = node.valueChange() ? UartStatus.UART_PORT_CHANGED : UartStatus.UART_DATA_READY;
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ namespace pxsim {
|
||||
export class UltrasonicSensorNode extends UartSensorNode {
|
||||
id = NodeType.UltrasonicSensor;
|
||||
|
||||
private distance: number = 50;
|
||||
private distance: number = 127; // in cm
|
||||
|
||||
constructor(port: number) {
|
||||
super(port);
|
||||
@ -25,7 +25,7 @@ namespace pxsim {
|
||||
}
|
||||
|
||||
getValue() {
|
||||
return this.distance;
|
||||
return this.distance * 10; // convert to 0.1 cm
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
namespace pxsim.util {
|
||||
|
||||
export function map16Bit(buffer: Uint8Array, index: number, value: number) {
|
||||
buffer[index] = (value >> 8) & 0xff;
|
||||
buffer[index+1] = value & 0xff;
|
||||
buffer[index] = value & 0xFF;
|
||||
buffer[index + 1] = (value >> 8) & 0xFF;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user