Skip to content

Commit b347f0d

Browse files
committed
Merge branch 'master' into nuget-package
2 parents 0f1627d + 520c23c commit b347f0d

File tree

3 files changed

+76
-41
lines changed

3 files changed

+76
-41
lines changed

.github/workflows/dotnet-core.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: .NET Core
2+
3+
on:
4+
push:
5+
branches: '*'
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v2
15+
- name: Install .NET Core
16+
uses: actions/setup-dotnet@v1
17+
with:
18+
dotnet-version: 5.x
19+
- name: Build and package liblsl
20+
run: dotnet pack -c Release liblsl.csproj -o pkg
21+
- name: Build and package examples
22+
run: dotnet pack -c Release examples/LSLExamples.csproj -o pkg
23+
# - name: Run examples
24+
# run: dotnet run -p examples/LSLExamples.csproj
25+
- name: Upload build artifacts
26+
uses: actions/upload-artifact@v1
27+
with:
28+
name: nuget pkg
29+
path: pkg

LSL.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public static void check_error(int ec)
196196
case -1: throw new TimeoutException("The operation failed due to a timeout.");
197197
case -2: throw new LostException("The stream has been lost.");
198198
case -3: throw new ArgumentException("An argument was incorrectly specified (e.g., wrong format or wrong length).");
199-
case -4: throw new InternalException("An internal internal error has occurred.");
199+
case -4: throw new InternalException("An internal error has occurred.");
200200
default: throw new Exception("An unknown error has occurred.");
201201
}
202202
}
@@ -495,7 +495,7 @@ protected override void DestroyLSLObject(IntPtr obj)
495495
* Wait until some consumer shows up (without wasting resources).
496496
* @return True if the wait was successful, false if the timeout expired.
497497
*/
498-
public bool wait_for_consumers(double timeout = LSL.FOREVER) { return dll.lsl_wait_for_consumers(obj) > 0; }
498+
public bool wait_for_consumers(double timeout = LSL.FOREVER) { return dll.lsl_wait_for_consumers(obj, timeout) > 0; }
499499

500500
/**
501501
* Retrieve the stream info provided by this outlet.
@@ -1023,7 +1023,7 @@ class dll
10231023
public static extern int lsl_have_consumers(IntPtr obj);
10241024

10251025
[DllImport(libname, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ExactSpelling = true)]
1026-
public static extern int lsl_wait_for_consumers(IntPtr obj);
1026+
public static extern int lsl_wait_for_consumers(IntPtr obj, double timeout);
10271027

10281028
[DllImport(libname, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ExactSpelling = true)]
10291029
public static extern IntPtr lsl_get_info(IntPtr obj);

README-Unity.md

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ LSL.cs includes a Unity interface to liblsl as a [Unity native plug-in](https://
2020
1. When the cube is selected, in the Inspector click on "Add Component", and create a new script called LSLInput.
2121
1. In the Project viewer, double click on LSLInput.cs. This should launch Visual Studio or another IDE.
2222
1. Fill in the script. Use [LSL4Unity AInlet](https://github.com/labstreaminglayer/LSL4Unity/blob/master/Scripts/AInlet.cs) for inspiration.
23-
* There is [currently a bug](https://github.com/sccn/liblsl/issues/29) that prevents liblsl in Unity from resolving streams from _other_ computers while running in editor, and also the built product but only when using `ContinuousResolver`. For this reason we recommend using `liblsl.resolve_stream` instead.
23+
* There is [currently a bug](https://github.com/sccn/liblsl/issues/29) that prevents liblsl in Unity from resolving streams from _other_ computers while running in editor, and also the built product but only when using `ContinuousResolver`. For this reason we recommend using `LSL.resolve_stream` instead.
2424

2525
```cs
2626
using System.Collections;
@@ -32,19 +32,22 @@ public class LSLInput : MonoBehaviour
3232
{
3333
public string StreamType = "EEG";
3434
public float scaleInput = 0.1f;
35-
liblsl.StreamInfo[] streamInfos;
36-
liblsl.StreamInlet streamInlet;
35+
36+
StreamInfo[] streamInfos;
37+
StreamInlet streamInlet;
38+
3739
float[] sample;
3840
private int channelCount = 0;
3941

4042
void Update()
4143
{
4244
if (streamInlet == null)
4345
{
44-
streamInfos = liblsl.resolve_stream("type", StreamType, 1, 0.0);
46+
47+
streamInfos = LSL.resolve_stream("type", StreamType, 1, 0.0);
4548
if (streamInfos.Length > 0)
4649
{
47-
streamInlet = new liblsl.StreamInlet(streamInfos[0]);
50+
streamInlet = new StreamInlet(streamInfos[0]);
4851
channelCount = streamInlet.info().channel_count();
4952
streamInlet.open_stream();
5053
}
@@ -79,41 +82,44 @@ public class LSLInput : MonoBehaviour
7982

8083
1. Attach a new component called LSLPosOutput to the cube.
8184
1. Edit it as follows:
82-
```cs
83-
using System.Collections;
84-
using System.Collections.Generic;
85-
using UnityEngine;
86-
using LSL;
85+
```cs
86+
using System.Collections;
87+
using System.Collections.Generic;
88+
using UnityEngine;
89+
using LSL;
8790

88-
public class LSLOutput : MonoBehaviour
89-
{
90-
private liblsl.StreamOutlet outlet;
91-
private float[] currentSample;
91+
public class LSLOutput : MonoBehaviour
92+
{
93+
private StreamOutlet outlet;
94+
private float[] currentSample;
9295

93-
public string StreamName = "Unity.ExampleStream";
94-
public string StreamType = "Unity.StreamType";
95-
public string StreamId = "MyStreamID-Unity1234";
9696

97-
// Start is called before the first frame update
98-
void Start()
99-
{
100-
liblsl.StreamInfo streamInfo = new liblsl.StreamInfo(StreamName, StreamType, 3, Time.fixedDeltaTime * 1000, liblsl.channel_format_t.cf_float32);
101-
liblsl.XMLElement chans = streamInfo.desc().append_child("channels");
102-
chans.append_child("channel").append_child_value("label", "X");
103-
chans.append_child("channel").append_child_value("label", "Y");
104-
chans.append_child("channel").append_child_value("label", "Z");
105-
outlet = new liblsl.StreamOutlet(streamInfo);
106-
currentSample = new float[3];
107-
}
97+
public string StreamName = "Unity.ExampleStream";
98+
public string StreamType = "Unity.StreamType";
99+
public string StreamId = "MyStreamID-Unity1234";
108100

109-
// Update is called once per frame
110-
void FixedUpdate()
111-
{
112-
Vector3 pos = gameObject.transform.position;
113-
currentSample[0] = pos.x;
114-
currentSample[1] = pos.y;
115-
currentSample[2] = pos.z;
116-
outlet.push_sample(currentSample);
117-
}
101+
// Start is called before the first frame update
102+
void Start()
103+
{
104+
StreamInfo streamInfo = new StreamInfo(StreamName, StreamType, 3, Time.fixedDeltaTime * 1000, LSL.channel_format_t.cf_float32);
105+
XMLElement chans = streamInfo.desc().append_child("channels");
106+
chans.append_child("channel").append_child_value("label", "X");
107+
chans.append_child("channel").append_child_value("label", "Y");
108+
chans.append_child("channel").append_child_value("label", "Z");
109+
outlet = new StreamOutlet(streamInfo);
110+
currentSample = new float[3];
118111
}
119-
```
112+
113+
114+
// FixedUpdate is a good hook for objects that are governed mostly by physics (gravity, momentum).
115+
// Update might be better for objects that are governed by code (stimulus, event).
116+
void FixedUpdate()
117+
{
118+
Vector3 pos = gameObject.transform.position;
119+
currentSample[0] = pos.x;
120+
currentSample[1] = pos.y;
121+
currentSample[2] = pos.z;
122+
outlet.push_sample(currentSample);
123+
}
124+
}
125+
```

0 commit comments

Comments
 (0)