correctly implemented IHandler

This commit is contained in:
shinichi
2020-09-30 15:26:34 +02:00
parent bd8994ad5b
commit 599b79ceee
4 changed files with 38 additions and 53 deletions

View File

@@ -98,32 +98,7 @@ namespace Hardware.Simulators
return hartByte;
}
//Generate an ANT message for resistance
public byte[] GenerateResistance(float percentage)
{
byte[] antMessage = new byte[13];
antMessage[0] = 0x4A;
antMessage[1] = 0x09;
antMessage[2] = 0x4E;
antMessage[3] = 0x05;
antMessage[4] = 0x30;
for (int i = 5; i < 11; i++)
{
antMessage[i] = 0xFF;
}
antMessage[11] = (byte)Math.Max(Math.Min(Math.Round(percentage / 0.5), 255), 0);
//antMessage[11] = 50; //hardcoded for testing
byte checksum = 0;
for (int i = 0; i < 12; i++)
{
checksum ^= antMessage[i];
}
antMessage[12] = checksum;//reminder that i am dumb :P
return antMessage;
}
//Calculates the needed variables
//Input perlin value
@@ -143,20 +118,11 @@ namespace Hardware.Simulators
}
//Set resistance in simulated bike
public void setResistance(byte[] bytes)
public void setResistance(float percentage)
{
//TODO check if message is correct
if (bytes.Length == 13)
{
this.resistance = Convert.ToDouble(bytes[11]) / 2;
}
this.resistance = (byte)Math.Max(Math.Min(Math.Round(percentage / 0.5), 255), 0);
}
}
//Interface for receiving a message on the simulated bike
interface IHandler
{
void setResistance(byte[] bytes);
}
}