Skip to content

Commit

Permalink
reduce latency by using efficient vjoy feeder
Browse files Browse the repository at this point in the history
  • Loading branch information
teamclouday committed Aug 21, 2021
1 parent 076daff commit 059574a
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class Connection
{
static class MyBuffer
{
private final int MAX_SIZE = 20;
private final int MAX_SIZE = 10;
private final ArrayList<Motion.MyMove> buff = new ArrayList<>();
private boolean running = false;
private boolean updatePitch = true;
Expand All @@ -49,7 +49,7 @@ public synchronized void addData(float pitch, float roll)
if(updatePitch) buff.add(new Motion.MyMove(false, 0, pitch));
if(updateRoll) buff.add(new Motion.MyMove(false, 1, roll));
int idx = 0;
while(buff.size() > MAX_SIZE)
while(buff.size() > MAX_SIZE && idx < buff.size())
{
if(buff.get(idx).MotionButton)
{
Expand All @@ -65,7 +65,7 @@ public synchronized void addData(int status, float val)
if(!running) return;
buff.add(new Motion.MyMove(false, status, val));
int idx = 0;
while(buff.size() > MAX_SIZE)
while(buff.size() > MAX_SIZE && idx < buff.size())
{
if(buff.get(idx).MotionButton)
{
Expand All @@ -81,7 +81,7 @@ public synchronized void addData(MotionButton button)
if(!running) return;
buff.add(new Motion.MyMove(true, button.getVal(), 0.0f));
int idx = 0;
while(buff.size() > MAX_SIZE)
while(buff.size() > MAX_SIZE && idx < buff.size())
{
if(buff.get(idx).MotionButton)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ private void update()
updateRoll(roll);

globalBuffer.addData(readPitch(), readRoll());

Log.d(mainActivity.getString(R.string.logTagMotion), "Sensor data update");
}

// update pitch
Expand Down
39 changes: 31 additions & 8 deletions Windows/SteeringWheel/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,57 @@ namespace SteeringWheel
/// </summary>
public class SharedBuffer
{
private const int MAX_SIZE = 50;
private readonly Queue<MotionData> buffer = new Queue<MotionData>();
private const int MAX_SIZE = 20;
private readonly List<MotionData> buffer = new List<MotionData>();
public void AddData(bool v1, int v2, float v3)
{
lock(buffer)
{
buffer.Enqueue(new MotionData()
buffer.Add(new MotionData()
{
IsButton = v1,
Status = v2,
Value = v3
});
while (buffer.Count > MAX_SIZE) buffer.Dequeue();
int idx = 0;
while (buffer.Count > MAX_SIZE && idx < buffer.Count)
{
if (buffer[idx].IsButton)
{
idx++;
continue;
}
buffer.RemoveAt(idx);
}
}
}
public void AddData(MotionData data)
{
lock(buffer)
{
buffer.Enqueue(data);
while (buffer.Count > MAX_SIZE) buffer.Dequeue();
buffer.Add(data);
int idx = 0;
while (buffer.Count > MAX_SIZE && idx < buffer.Count)
{
if (buffer[idx].IsButton)
{
idx++;
continue;
}
buffer.RemoveAt(idx);
}
}
}
public MotionData GetData()
{
lock(buffer)
{
if (buffer.Count > 0) return buffer.Dequeue();
if (buffer.Count > 0)
{
MotionData data = buffer[0];
buffer.RemoveAt(0);
return data;
}
else return null;
}
}
Expand Down Expand Up @@ -82,7 +105,7 @@ class Connection

private readonly int MAX_WAIT_TIME = 1500;
private readonly int DATA_SEPARATOR = 10086;
private readonly int BUFFER_SIZE = 13 * 10; // 10 data packs each time
private readonly int BUFFER_SIZE = 13 * 5; // 5 data packs each time
private readonly int DEVICE_CHECK_EXPECTED = 123456;
private readonly int DEVICE_CHECK_DATA = 654321;
private bool isConnectionAllowed = false;
Expand Down
Loading

0 comments on commit 059574a

Please sign in to comment.