Touch sensor improvements

This commit is contained in:
Pascal Serrarens 2025-02-25 16:45:29 +01:00
parent 28d3a98bea
commit f9103758e2
3 changed files with 27 additions and 6 deletions

View File

@ -21,6 +21,9 @@ namespace Passer.RoboidControl {
/// The ID of the thing
/// </summary>
public byte thingId;
public Thing thing;
/// <summary>
/// The binary data
/// </summary>
@ -45,7 +48,8 @@ namespace Passer.RoboidControl {
public BinaryMsg(byte networkId, Thing thing) : base() {
this.networkId = networkId;
this.thingId = thing.id;
this.bytes = System.Array.Empty<byte>();
this.thing = thing;
this.bytes = this.thing.GenerateBinary();
}
/// @copydoc Passer::RoboidControl::IMessage::IMessage(byte[] buffer)
public BinaryMsg(byte[] buffer) {
@ -59,7 +63,7 @@ namespace Passer.RoboidControl {
}
/// @copydoc Passer::RoboidControl::IMessage::Serialize
public override byte Serialize(ref byte[] buffer) {
public override byte Serialize(ref byte[] buffer) {
if (buffer.Length < BinaryMsg.length + this.bytes.Length || this.bytes.Length == 0)
return 0;

View File

@ -27,7 +27,7 @@ namespace Passer.RoboidControl {
/// Create a porticiapnt
/// </summary>
public Participant() {
senders.Add(this);
//senders.Add(this);
}
/// <summary>
@ -77,7 +77,7 @@ namespace Passer.RoboidControl {
return null;
}
public RemoteParticipant AddParticipant(string ipAddress, int port) {
// Console.WriteLine($"New Participant {ipAddress}:{port}");
Console.WriteLine($"New Participant {ipAddress}:{port}");
RemoteParticipant participant = new RemoteParticipant(ipAddress, port) {
networkId = (byte)this.senders.Count
};
@ -144,8 +144,12 @@ namespace Passer.RoboidControl {
int n = this.things.Count;
for (int ix = 0; ix < n; ix++) {
Thing thing = this.things[ix];
if (thing != null) // && thing.parent == null) // update only root things
if (thing != null) {
thing.Update(currentTimeMS);
BinaryMsg binaryMsg = new(this.networkId, thing);
foreach (RemoteParticipant sender in this.senders)
this.Send(sender, binaryMsg);
}
}
}

View File

@ -7,7 +7,15 @@ namespace Passer.RoboidControl {
/// <summary>
/// Value which is true when the sensor is touching something, false otherwise
/// </summary>
public bool touchedSomething = false;
//public bool touchedSomething = false;
private bool _touchedSomething = false;
public bool touchedSomething {
get { return _touchedSomething; }
set {
_touchedSomething = value;
//SendBinary();
}
}
/// <summary>
/// Create a touch sensor
@ -30,5 +38,10 @@ namespace Passer.RoboidControl {
this.component.core = this;
}
#endif
public override byte[] GenerateBinary() {
byte[] buffer = new byte[1];
buffer[0] = (byte)(touchedSomething ? 1 : 0);
return buffer;
}
}
}