Touch sensor improvements
This commit is contained in:
parent
28d3a98bea
commit
f9103758e2
@ -21,6 +21,9 @@ namespace Passer.RoboidControl {
|
|||||||
/// The ID of the thing
|
/// The ID of the thing
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public byte thingId;
|
public byte thingId;
|
||||||
|
|
||||||
|
public Thing thing;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The binary data
|
/// The binary data
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -45,7 +48,8 @@ namespace Passer.RoboidControl {
|
|||||||
public BinaryMsg(byte networkId, Thing thing) : base() {
|
public BinaryMsg(byte networkId, Thing thing) : base() {
|
||||||
this.networkId = networkId;
|
this.networkId = networkId;
|
||||||
this.thingId = thing.id;
|
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)
|
/// @copydoc Passer::RoboidControl::IMessage::IMessage(byte[] buffer)
|
||||||
public BinaryMsg(byte[] buffer) {
|
public BinaryMsg(byte[] buffer) {
|
||||||
@ -59,7 +63,7 @@ namespace Passer.RoboidControl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// @copydoc Passer::RoboidControl::IMessage::Serialize
|
/// @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)
|
if (buffer.Length < BinaryMsg.length + this.bytes.Length || this.bytes.Length == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ namespace Passer.RoboidControl {
|
|||||||
/// Create a porticiapnt
|
/// Create a porticiapnt
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Participant() {
|
public Participant() {
|
||||||
senders.Add(this);
|
//senders.Add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -77,7 +77,7 @@ namespace Passer.RoboidControl {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
public RemoteParticipant AddParticipant(string ipAddress, int port) {
|
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) {
|
RemoteParticipant participant = new RemoteParticipant(ipAddress, port) {
|
||||||
networkId = (byte)this.senders.Count
|
networkId = (byte)this.senders.Count
|
||||||
};
|
};
|
||||||
@ -144,8 +144,12 @@ namespace Passer.RoboidControl {
|
|||||||
int n = this.things.Count;
|
int n = this.things.Count;
|
||||||
for (int ix = 0; ix < n; ix++) {
|
for (int ix = 0; ix < n; ix++) {
|
||||||
Thing thing = this.things[ix];
|
Thing thing = this.things[ix];
|
||||||
if (thing != null) // && thing.parent == null) // update only root things
|
if (thing != null) {
|
||||||
thing.Update(currentTimeMS);
|
thing.Update(currentTimeMS);
|
||||||
|
BinaryMsg binaryMsg = new(this.networkId, thing);
|
||||||
|
foreach (RemoteParticipant sender in this.senders)
|
||||||
|
this.Send(sender, binaryMsg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,15 @@ namespace Passer.RoboidControl {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Value which is true when the sensor is touching something, false otherwise
|
/// Value which is true when the sensor is touching something, false otherwise
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool touchedSomething = false;
|
//public bool touchedSomething = false;
|
||||||
|
private bool _touchedSomething = false;
|
||||||
|
public bool touchedSomething {
|
||||||
|
get { return _touchedSomething; }
|
||||||
|
set {
|
||||||
|
_touchedSomething = value;
|
||||||
|
//SendBinary();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a touch sensor
|
/// Create a touch sensor
|
||||||
@ -30,5 +38,10 @@ namespace Passer.RoboidControl {
|
|||||||
this.component.core = this;
|
this.component.core = this;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
public override byte[] GenerateBinary() {
|
||||||
|
byte[] buffer = new byte[1];
|
||||||
|
buffer[0] = (byte)(touchedSomething ? 1 : 0);
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user