Compare commits
7 commits
edidpatche
...
main
Author | SHA1 | Date | |
---|---|---|---|
0efaf19b40 | |||
6911afb6e0 | |||
30e90af276 | |||
59dbdf9eb0 | |||
f16b35f102 | |||
8b482cecd5 | |||
f79657afc2 |
45 changed files with 409 additions and 159 deletions
23
HACKING.md
Normal file
23
HACKING.md
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
# UnrealXR Development Documentation
|
||||||
|
|
||||||
|
## Dummies and You
|
||||||
|
|
||||||
|
The dummy/development build generally isn't recommended for use if you're developing headset or OS drivers. It's intended for development on the 3D environment itself only (ie. virtual display positioning, widgets, etc.)
|
||||||
|
|
||||||
|
To use it, all you need to do is run the Makefile with the `dev` target:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
make dev
|
||||||
|
```
|
||||||
|
|
||||||
|
In the code, this mode is typically referred to as "dummy mode" (`dummy_ar.go`) or "fake mode" (ie. `patching_tools_fake_patching.go`).
|
||||||
|
|
||||||
|
To control the X11 window, you can use the arrow keys to move the camera around. You **cannot** use the mouse due to the nature of this application. If you use the mouse for this, it would make development really difficult as you're using virtual displays and you need your mouse to interact with the desktop.
|
||||||
|
|
||||||
|
If you're adding new headset drivers, but you still want to test in a window, you still can. It's not the dummy mode, but you can compile UnrealXR without the DRM flags (`drm drm_leasing drm_disable_input`) manually. This may differ in the future, but for now, the command is:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd app; go build -v -tags "headset_driver_goes_here noaudio" -o ../uxr .; cd ..
|
||||||
|
```
|
||||||
|
|
||||||
|
Replace `headset_driver_goes_here` with the name of your headset driver. For example, `xreal` is the Xreal driver.
|
3
Makefile
3
Makefile
|
@ -9,5 +9,8 @@ all: build
|
||||||
build:
|
build:
|
||||||
cd $(APP_DIR) && go build -v -tags '$(TAGS)' -o ../$(OUTPUT) .
|
cd $(APP_DIR) && go build -v -tags '$(TAGS)' -o ../$(OUTPUT) .
|
||||||
|
|
||||||
|
dev:
|
||||||
|
cd $(APP_DIR) && go build -v -tags 'noaudio dummy_ar fake_edid_patching' -o ../$(OUTPUT) .
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(OUTPUT)
|
rm -f $(OUTPUT)
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
# UnrealXR
|
# UnrealXR
|
||||||
|
[](https://git.terah.dev/UnrealXR/unrealxr/actions)
|
||||||
|
[](https://godoc.org/git.terah.dev/UnrealXR/unrealxr)
|
||||||
|
[](https://goreportcard.com/report/git.terah.dev/UnrealXR/unrealxr/app)
|
||||||
|
[](https://git.terah.dev/imterah/goevdi/src/branch/main/app/LICENSE)
|
||||||
|
|
||||||
UnrealXR is a spatial multi-display renderer for the Xreal line of devices, enabling immersive, simultaneous viewing of multiple desktops and applications in 3D space.
|
UnrealXR is a spatial multi-display renderer for the Xreal line of devices, enabling immersive, simultaneous viewing of multiple desktops and applications in 3D space.
|
||||||
|
|
||||||
|
@ -29,3 +33,7 @@ If you're using Nix/NixOS, all you need to do is use `nix-shell` to enter the de
|
||||||
## Building
|
## Building
|
||||||
|
|
||||||
Just run `make` in the root directory.
|
Just run `make` in the root directory.
|
||||||
|
|
||||||
|
## Development Guide
|
||||||
|
|
||||||
|
See [HACKING.md](https://git.terah.dev/UnrealXR/unrealxr/src/branch/main/HACKING.md).
|
||||||
|
|
|
@ -9,6 +9,8 @@ type DisplayConfig struct {
|
||||||
Angle *int `yaml:"angle"`
|
Angle *int `yaml:"angle"`
|
||||||
FOV *int `yaml:"fov"`
|
FOV *int `yaml:"fov"`
|
||||||
Spacing *float32 `yaml:"spacing"`
|
Spacing *float32 `yaml:"spacing"`
|
||||||
|
RadiusMultiplier *float32 `yaml:"circle_radius_multiplier"`
|
||||||
|
UseCircularSpacing *bool `yaml:"use_circular_spacing"`
|
||||||
Count *int `yaml:"count"`
|
Count *int `yaml:"count"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,6 +43,8 @@ var DefaultConfig = &Config{
|
||||||
Angle: getPtrToInt(45),
|
Angle: getPtrToInt(45),
|
||||||
FOV: getPtrToInt(45),
|
FOV: getPtrToInt(45),
|
||||||
Spacing: getPtrToFloat32(0.5),
|
Spacing: getPtrToFloat32(0.5),
|
||||||
|
RadiusMultiplier: getPtrToFloat32(2),
|
||||||
|
UseCircularSpacing: getPtrToBool(true),
|
||||||
Count: getPtrToInt(3),
|
Count: getPtrToInt(3),
|
||||||
},
|
},
|
||||||
Overrides: AppOverrides{
|
Overrides: AppOverrides{
|
||||||
|
|
|
@ -9,7 +9,9 @@
|
||||||
display:
|
display:
|
||||||
angle: 45 # Angle of the virtual displays
|
angle: 45 # Angle of the virtual displays
|
||||||
fov: 45 # FOV of the 3D camera
|
fov: 45 # FOV of the 3D camera
|
||||||
spacing: 0.5 # Spacing between virtual displays
|
spacing: 0.5 # Raw spacing between virtual displays. Does not use circles in the layout. Purely flat plane.
|
||||||
|
circle_radius_multiplier: 2 # Multiplier for the radius of the circle used to calculate the spacing between virtual displays. "Rounded" plane of sorts.
|
||||||
|
use_circular_spacing: true # If true, uses a circular layout for the virtual displays.
|
||||||
count: 3 # Count of virtual displays
|
count: 3 # Count of virtual displays
|
||||||
overrides:
|
overrides:
|
||||||
allow_unsupported_devices: false # If true, allows unsupported devices to be used as long as they're a compatible vendor (Xreal)
|
allow_unsupported_devices: false # If true, allows unsupported devices to be used as long as they're a compatible vendor (Xreal)
|
||||||
|
|
BIN
app/edidtools/bin/xreal-air-edid.bin
Normal file
BIN
app/edidtools/bin/xreal-air-edid.bin
Normal file
Binary file not shown.
42
app/edidtools/patching_tools_fake_patching.go
Normal file
42
app/edidtools/patching_tools_fake_patching.go
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
//go:build fake_edid_patching
|
||||||
|
// +build fake_edid_patching
|
||||||
|
|
||||||
|
package edidtools
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "embed"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/charmbracelet/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:embed bin/xreal-air-edid.bin
|
||||||
|
var edidFirmware []byte
|
||||||
|
|
||||||
|
// Attempts to fetch the EDID firmware for any supported XR glasses device
|
||||||
|
func FetchXRGlassEDID(allowUnsupportedDevices bool) (*DisplayMetadata, error) {
|
||||||
|
log.Warn("Not actually fetching EDID firmware in fake patching build -- using embedded firmware")
|
||||||
|
parsedEDID, err := ParseEDID(edidFirmware, allowUnsupportedDevices)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to parse embedded EDID firmware: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
parsedEDID.DeviceQuirks.ZVectorDisabled = false
|
||||||
|
parsedEDID.DeviceQuirks.SensorInitDelay = 0
|
||||||
|
parsedEDID.DeviceQuirks.UsesMouseMovement = true
|
||||||
|
|
||||||
|
return parsedEDID, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loads custom firmware for a supported XR glass device
|
||||||
|
func LoadCustomEDIDFirmware(displayMetadata *DisplayMetadata, edidFirmware []byte) error {
|
||||||
|
log.Warn("Not actually patching EDID firmware in fake patching build -- ignoring")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unloads custom firmware for a supported XR glass device
|
||||||
|
func UnloadCustomEDIDFirmware(displayMetadata *DisplayMetadata) error {
|
||||||
|
log.Warn("Not actually unloading EDID firmware in fake patching build -- ignoring")
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
//go:build linux
|
//go:build linux && !fake_edid_patching
|
||||||
// +build linux
|
// +build linux,!fake_edid_patching
|
||||||
|
|
||||||
package edidtools
|
package edidtools
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
//go:build darwin
|
//go:build darwin && !fake_edid_patching
|
||||||
// +build darwin
|
// +build darwin,!fake_edid_patching
|
||||||
|
|
||||||
package edidtools
|
package edidtools
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
//go:build windows
|
//go:build windows && !fake_edid_patching
|
||||||
// +build windows
|
// +build windows,!fake_edid_patching
|
||||||
|
|
||||||
package edidtools
|
package edidtools
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ type DisplayQuirks struct {
|
||||||
MaxRefreshRate int
|
MaxRefreshRate int
|
||||||
SensorInitDelay int
|
SensorInitDelay int
|
||||||
ZVectorDisabled bool
|
ZVectorDisabled bool
|
||||||
|
UsesMouseMovement bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type DisplayMetadata struct {
|
type DisplayMetadata struct {
|
||||||
|
|
|
@ -118,7 +118,7 @@ func mainEntrypoint(context.Context, *cli.Command) error {
|
||||||
bufio.NewReader(os.Stdin).ReadBytes('\n') // Wait for Enter key press before continuing
|
bufio.NewReader(os.Stdin).ReadBytes('\n') // Wait for Enter key press before continuing
|
||||||
|
|
||||||
log.Info("Initializing XR headset")
|
log.Info("Initializing XR headset")
|
||||||
rl.SetTargetFPS(int32(displayMetadata.MaxRefreshRate * 2))
|
rl.SetTargetFPS(int32(displayMetadata.MaxRefreshRate))
|
||||||
rl.InitWindow(int32(displayMetadata.MaxWidth), int32(displayMetadata.MaxHeight), "UnrealXR")
|
rl.InitWindow(int32(displayMetadata.MaxWidth), int32(displayMetadata.MaxHeight), "UnrealXR")
|
||||||
|
|
||||||
atexit.Register(func() {
|
atexit.Register(func() {
|
||||||
|
|
|
@ -35,6 +35,15 @@ func findOptimalHorizontalRes(verticalDisplayRes float32, horizontalDisplayRes f
|
||||||
return horizontalSize
|
return horizontalSize
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func findHfovFromVfov(vfovDeg, w, h float64) float64 {
|
||||||
|
vfovRad := vfovDeg * math.Pi / 180
|
||||||
|
|
||||||
|
ar := w / h
|
||||||
|
hfovRad := 2 * math.Atan(math.Tan(vfovRad/2)*ar)
|
||||||
|
|
||||||
|
return hfovRad * 180 / math.Pi
|
||||||
|
}
|
||||||
|
|
||||||
func EnterRenderLoop(config *libconfig.Config, displayMetadata *edidtools.DisplayMetadata, evdiCards []*EvdiDisplayMetadata) {
|
func EnterRenderLoop(config *libconfig.Config, displayMetadata *edidtools.DisplayMetadata, evdiCards []*EvdiDisplayMetadata) {
|
||||||
log.Info("Initializing AR driver")
|
log.Info("Initializing AR driver")
|
||||||
headset, err := ardriver.GetDevice()
|
headset, err := ardriver.GetDevice()
|
||||||
|
@ -99,7 +108,9 @@ func EnterRenderLoop(config *libconfig.Config, displayMetadata *edidtools.Displa
|
||||||
|
|
||||||
headset.RegisterEventListeners(arEventListner)
|
headset.RegisterEventListeners(arEventListner)
|
||||||
|
|
||||||
fovY := float32(45.0)
|
fovY := float32(*config.DisplayConfig.FOV)
|
||||||
|
fovX := findHfovFromVfov(float64(fovY), float64(displayMetadata.MaxWidth), float64(displayMetadata.MaxHeight))
|
||||||
|
|
||||||
verticalSize := findMaxVerticalSize(fovY, 5.0)
|
verticalSize := findMaxVerticalSize(fovY, 5.0)
|
||||||
|
|
||||||
camera := rl.NewCamera3D(
|
camera := rl.NewCamera3D(
|
||||||
|
@ -125,6 +136,21 @@ func EnterRenderLoop(config *libconfig.Config, displayMetadata *edidtools.Displa
|
||||||
horizontalSize := findOptimalHorizontalRes(float32(displayMetadata.MaxHeight), float32(displayMetadata.MaxWidth), verticalSize)
|
horizontalSize := findOptimalHorizontalRes(float32(displayMetadata.MaxHeight), float32(displayMetadata.MaxWidth), verticalSize)
|
||||||
coreMesh := rl.GenMeshPlane(horizontalSize, verticalSize, 1, 1)
|
coreMesh := rl.GenMeshPlane(horizontalSize, verticalSize, 1, 1)
|
||||||
|
|
||||||
|
var radius float32
|
||||||
|
|
||||||
|
if *config.DisplayConfig.UseCircularSpacing == true {
|
||||||
|
radiusX := (horizontalSize / 2) / float32(math.Tan((float64(fovX)*math.Pi/180.0)/2))
|
||||||
|
radiusY := (verticalSize / 2) / float32(math.Tan((float64(fovY)*math.Pi/180.0)/2))
|
||||||
|
|
||||||
|
if radiusY > radiusX {
|
||||||
|
radius = radiusY
|
||||||
|
} else {
|
||||||
|
radius = radiusX
|
||||||
|
}
|
||||||
|
|
||||||
|
radius *= *config.DisplayConfig.RadiusMultiplier
|
||||||
|
}
|
||||||
|
|
||||||
movementVector := rl.Vector3{
|
movementVector := rl.Vector3{
|
||||||
X: 0.0,
|
X: 0.0,
|
||||||
Y: 0.0,
|
Y: 0.0,
|
||||||
|
@ -171,6 +197,17 @@ func EnterRenderLoop(config *libconfig.Config, displayMetadata *edidtools.Displa
|
||||||
texture := rl.LoadTextureFromImage(image)
|
texture := rl.LoadTextureFromImage(image)
|
||||||
model := rl.LoadModelFromMesh(coreMesh)
|
model := rl.LoadModelFromMesh(coreMesh)
|
||||||
|
|
||||||
|
// spin up/down
|
||||||
|
pitchRad := float32(-90 * rl.Deg2rad)
|
||||||
|
// spin left/right
|
||||||
|
yawRad := currentAngle * rl.Deg2rad
|
||||||
|
|
||||||
|
rotX := rl.MatrixRotateX(pitchRad)
|
||||||
|
rotY := rl.MatrixRotateY(yawRad)
|
||||||
|
|
||||||
|
transform := rl.MatrixMultiply(rotX, rotY)
|
||||||
|
model.Transform = transform
|
||||||
|
|
||||||
rl.SetMaterialTexture(model.Materials, rl.MapAlbedo, texture)
|
rl.SetMaterialTexture(model.Materials, rl.MapAlbedo, texture)
|
||||||
|
|
||||||
rects[i] = &TextureModelPair{
|
rects[i] = &TextureModelPair{
|
||||||
|
@ -184,6 +221,7 @@ func EnterRenderLoop(config *libconfig.Config, displayMetadata *edidtools.Displa
|
||||||
eventTimeoutDuration := 0 * time.Millisecond
|
eventTimeoutDuration := 0 * time.Millisecond
|
||||||
|
|
||||||
for !rl.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
|
if !displayMetadata.DeviceQuirks.UsesMouseMovement {
|
||||||
if hasSensorInitDelayQuirk {
|
if hasSensorInitDelayQuirk {
|
||||||
if time.Now().Sub(sensorInitStartTime) > time.Duration(displayMetadata.DeviceQuirks.SensorInitDelay)*time.Second {
|
if time.Now().Sub(sensorInitStartTime) > time.Duration(displayMetadata.DeviceQuirks.SensorInitDelay)*time.Second {
|
||||||
log.Info("Movement is now enabled.")
|
log.Info("Movement is now enabled.")
|
||||||
|
@ -199,6 +237,9 @@ func EnterRenderLoop(config *libconfig.Config, displayMetadata *edidtools.Displa
|
||||||
|
|
||||||
rl.UpdateCameraPro(&camera, movementVector, lookVector, 0)
|
rl.UpdateCameraPro(&camera, movementVector, lookVector, 0)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
rl.UpdateCamera(&camera, rl.CameraFirstPerson)
|
||||||
|
}
|
||||||
|
|
||||||
rl.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
rl.ClearBackground(rl.Black)
|
rl.ClearBackground(rl.Black)
|
||||||
|
@ -231,20 +272,35 @@ func EnterRenderLoop(config *libconfig.Config, displayMetadata *edidtools.Displa
|
||||||
card.EvdiNode.RequestUpdate(card.Buffer)
|
card.EvdiNode.RequestUpdate(card.Buffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
rl.DrawModelEx(
|
worldPos := rl.Vector3{
|
||||||
rect.Model,
|
X: 0,
|
||||||
rl.Vector3{
|
|
||||||
X: rect.CurrentDisplaySpacing,
|
|
||||||
Y: verticalSize / 2,
|
Y: verticalSize / 2,
|
||||||
Z: 0,
|
Z: 0,
|
||||||
},
|
}
|
||||||
|
|
||||||
|
if *config.DisplayConfig.UseCircularSpacing == true {
|
||||||
|
yawRad := float32(rl.Deg2rad * rect.CurrentAngle)
|
||||||
|
|
||||||
|
// WTF?
|
||||||
|
posX := float32(math.Sin(float64(yawRad))) * radius
|
||||||
|
posZ := -float32(math.Cos(float64(yawRad))) * radius
|
||||||
|
|
||||||
|
worldPos.X = posX
|
||||||
|
worldPos.Z = posZ + radius
|
||||||
|
} else {
|
||||||
|
worldPos.X = rect.CurrentDisplaySpacing
|
||||||
|
}
|
||||||
|
|
||||||
|
rl.DrawModelEx(
|
||||||
|
rect.Model,
|
||||||
|
worldPos,
|
||||||
// rotate around X to make it vertical
|
// rotate around X to make it vertical
|
||||||
rl.Vector3{
|
rl.Vector3{
|
||||||
X: 1,
|
X: 0,
|
||||||
Y: 0,
|
Y: 0,
|
||||||
Z: 0,
|
Z: 0,
|
||||||
},
|
},
|
||||||
90,
|
0,
|
||||||
rl.Vector3{
|
rl.Vector3{
|
||||||
X: 1,
|
X: 1,
|
||||||
Y: 1,
|
Y: 1,
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.terah.dev/UnrealXR/unrealxr/ardriver/commons"
|
"git.terah.dev/UnrealXR/unrealxr/ardriver/commons"
|
||||||
|
"git.terah.dev/UnrealXR/unrealxr/ardriver/dummy"
|
||||||
"git.terah.dev/UnrealXR/unrealxr/ardriver/xreal"
|
"git.terah.dev/UnrealXR/unrealxr/ardriver/xreal"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -19,5 +20,16 @@ func GetDevice() (commons.ARDevice, error) {
|
||||||
return device, nil
|
return device, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if dummy.IsDummyDeviceEnabled {
|
||||||
|
device, err := dummy.New()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("failed to initialize dummy device: %w\n", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return device, nil
|
||||||
|
}
|
||||||
|
|
||||||
return nil, fmt.Errorf("failed to initialize any device")
|
return nil, fmt.Errorf("failed to initialize any device")
|
||||||
}
|
}
|
||||||
|
|
40
ardriver/dummy/dummy_ar.go
Normal file
40
ardriver/dummy/dummy_ar.go
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
//go:build dummy_ar
|
||||||
|
// +build dummy_ar
|
||||||
|
|
||||||
|
package dummy
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.terah.dev/UnrealXR/unrealxr/ardriver/commons"
|
||||||
|
)
|
||||||
|
|
||||||
|
var IsDummyDeviceEnabled = true
|
||||||
|
|
||||||
|
// Implements commons.ARDevice
|
||||||
|
type DummyDevice struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (device *DummyDevice) Initialize() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (device *DummyDevice) End() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (device *DummyDevice) IsPollingLibrary() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (device *DummyDevice) IsEventBasedLibrary() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (device *DummyDevice) Poll() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (device *DummyDevice) RegisterEventListeners(*commons.AREventListener) {}
|
||||||
|
|
||||||
|
func New() (*DummyDevice, error) {
|
||||||
|
return &DummyDevice{}, nil
|
||||||
|
}
|
42
ardriver/dummy/dummy_ar_disabled.go
Normal file
42
ardriver/dummy/dummy_ar_disabled.go
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
//go:build !dummy_ar
|
||||||
|
// +build !dummy_ar
|
||||||
|
|
||||||
|
package dummy
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"git.terah.dev/UnrealXR/unrealxr/ardriver/commons"
|
||||||
|
)
|
||||||
|
|
||||||
|
var IsDummyDeviceEnabled = false
|
||||||
|
|
||||||
|
// Implements commons.ARDevice
|
||||||
|
type DummyDevice struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (device *DummyDevice) Initialize() error {
|
||||||
|
return fmt.Errorf("dummy device is not enabled")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (device *DummyDevice) End() error {
|
||||||
|
return fmt.Errorf("dummy device is not enabled")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (device *DummyDevice) IsPollingLibrary() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (device *DummyDevice) IsEventBasedLibrary() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (device *DummyDevice) Poll() error {
|
||||||
|
return fmt.Errorf("dummy device is not enabled")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (device *DummyDevice) RegisterEventListeners(*commons.AREventListener) {}
|
||||||
|
|
||||||
|
func New() (*DummyDevice, error) {
|
||||||
|
return nil, fmt.Errorf("dummy device is not enabled")
|
||||||
|
}
|
|
@ -3,127 +3,21 @@
|
||||||
|
|
||||||
package xreal
|
package xreal
|
||||||
|
|
||||||
// #cgo CFLAGS: -w -I./Fusion/
|
|
||||||
// #cgo pkg-config: json-c libusb-1.0 hidapi-libusb
|
|
||||||
// #include "go_ffi.h"
|
|
||||||
// #include "device.h"
|
|
||||||
// #include "device_imu.h"
|
|
||||||
// #include "device_mcu.h"
|
|
||||||
import "C"
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
xreal "git.terah.dev/UnrealXR/unrealxr/ardriver/xreal/xrealsrc"
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"git.terah.dev/UnrealXR/unrealxr/ardriver/commons"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var IsXrealEnabled = true
|
||||||
IsXrealEnabled = true
|
|
||||||
deviceEventHandlerMutex = sync.Mutex{}
|
|
||||||
deviceEventListener *commons.AREventListener
|
|
||||||
)
|
|
||||||
|
|
||||||
//export goIMUEventHandler
|
|
||||||
func goIMUEventHandler(_ C.uint64_t, event_type C.device_imu_event_type, ahrs *C.struct_device_imu_ahrs_t) {
|
|
||||||
if deviceEventListener == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if event_type != C.DEVICE_IMU_EVENT_UPDATE {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
orientation := C.device_imu_get_orientation(ahrs)
|
|
||||||
euler := C.device_imu_get_euler(orientation)
|
|
||||||
|
|
||||||
deviceEventListener.PitchCallback(float32(euler.pitch))
|
|
||||||
deviceEventListener.RollCallback(float32(euler.roll))
|
|
||||||
deviceEventListener.YawCallback(float32(euler.yaw))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Implements commons.ARDevice
|
|
||||||
type XrealDevice struct {
|
type XrealDevice struct {
|
||||||
eventListener *commons.AREventListener
|
*xreal.XrealDevice
|
||||||
imuDevice *C.struct_device_imu_t
|
|
||||||
deviceIsOpen bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func (device *XrealDevice) Initialize() error {
|
|
||||||
if device.deviceIsOpen {
|
|
||||||
return fmt.Errorf("device is already open")
|
|
||||||
}
|
|
||||||
|
|
||||||
device.imuDevice = &C.struct_device_imu_t{}
|
|
||||||
|
|
||||||
// (*[0]byte) is a FUBAR way to cast a pointer to a function, but unsafe.Pointer doesn't work:
|
|
||||||
// cannot use unsafe.Pointer(_Cgo_ptr(_Cfpvar_fp_imuEventHandler)) (value of type unsafe.Pointer) as *[0]byte value in variable declaration
|
|
||||||
if C.DEVICE_IMU_ERROR_NO_ERROR != C.device_imu_open(device.imuDevice, (*[0]byte)(C.imuEventHandler)) {
|
|
||||||
return fmt.Errorf("failed to open IMU device")
|
|
||||||
}
|
|
||||||
|
|
||||||
C.device_imu_clear(device.imuDevice)
|
|
||||||
C.device_imu_calibrate(device.imuDevice, 1000, true, true, false)
|
|
||||||
|
|
||||||
device.deviceIsOpen = true
|
|
||||||
|
|
||||||
// let's hope this doesn't cause race conditions
|
|
||||||
go func() {
|
|
||||||
for device.eventListener == nil {
|
|
||||||
time.Sleep(time.Millisecond * 10)
|
|
||||||
}
|
|
||||||
|
|
||||||
for {
|
|
||||||
if !device.deviceIsOpen {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
// I'm sorry.
|
|
||||||
deviceEventHandlerMutex.Lock()
|
|
||||||
deviceEventListener = device.eventListener
|
|
||||||
status := C.device_imu_read(device.imuDevice, -1)
|
|
||||||
deviceEventHandlerMutex.Unlock()
|
|
||||||
|
|
||||||
if status != C.DEVICE_IMU_ERROR_NO_ERROR {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
device.deviceIsOpen = false
|
|
||||||
C.device_imu_close(device.imuDevice)
|
|
||||||
}()
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (device *XrealDevice) End() error {
|
|
||||||
if !device.deviceIsOpen {
|
|
||||||
return fmt.Errorf("device is not open")
|
|
||||||
}
|
|
||||||
|
|
||||||
C.device_imu_close(device.imuDevice)
|
|
||||||
device.deviceIsOpen = false
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (device *XrealDevice) IsPollingLibrary() bool {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (device *XrealDevice) IsEventBasedLibrary() bool {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (device *XrealDevice) Poll() error {
|
|
||||||
return fmt.Errorf("not supported")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (device *XrealDevice) RegisterEventListeners(listener *commons.AREventListener) {
|
|
||||||
device.eventListener = listener
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func New() (*XrealDevice, error) {
|
func New() (*XrealDevice, error) {
|
||||||
device := &XrealDevice{}
|
device := &XrealDevice{
|
||||||
|
XrealDevice: &xreal.XrealDevice{},
|
||||||
|
}
|
||||||
|
|
||||||
err := device.Initialize()
|
err := device.Initialize()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -35,9 +35,7 @@ func (device *XrealDevice) Poll() error {
|
||||||
return fmt.Errorf("xreal is not enabled")
|
return fmt.Errorf("xreal is not enabled")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (device *XrealDevice) RegisterEventListeners(*commons.AREventListener) error {
|
func (device *XrealDevice) RegisterEventListeners(*commons.AREventListener) {}
|
||||||
return fmt.Errorf("xreal is not enabled")
|
|
||||||
}
|
|
||||||
|
|
||||||
func New() (*XrealDevice, error) {
|
func New() (*XrealDevice, error) {
|
||||||
return nil, fmt.Errorf("xreal is not enabled")
|
return nil, fmt.Errorf("xreal is not enabled")
|
||||||
|
|
122
ardriver/xreal/xrealsrc/xreal_bindings.go
Normal file
122
ardriver/xreal/xrealsrc/xreal_bindings.go
Normal file
|
@ -0,0 +1,122 @@
|
||||||
|
//go:build xreal
|
||||||
|
// +build xreal
|
||||||
|
|
||||||
|
package xreal
|
||||||
|
|
||||||
|
// #cgo CFLAGS: -w
|
||||||
|
// #cgo pkg-config: json-c libusb-1.0 hidapi-libusb
|
||||||
|
// #include "go_ffi.h"
|
||||||
|
// #include "device.h"
|
||||||
|
// #include "device_imu.h"
|
||||||
|
// #include "device_mcu.h"
|
||||||
|
import "C"
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"git.terah.dev/UnrealXR/unrealxr/ardriver/commons"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
deviceEventHandlerMutex = sync.Mutex{}
|
||||||
|
deviceEventListener *commons.AREventListener
|
||||||
|
)
|
||||||
|
|
||||||
|
//export goIMUEventHandler
|
||||||
|
func goIMUEventHandler(_ C.uint64_t, event_type C.device_imu_event_type, ahrs *C.struct_device_imu_ahrs_t) {
|
||||||
|
if deviceEventListener == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if event_type != C.DEVICE_IMU_EVENT_UPDATE {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
orientation := C.device_imu_get_orientation(ahrs)
|
||||||
|
euler := C.device_imu_get_euler(orientation)
|
||||||
|
|
||||||
|
deviceEventListener.PitchCallback(float32(euler.pitch))
|
||||||
|
deviceEventListener.RollCallback(float32(euler.roll))
|
||||||
|
deviceEventListener.YawCallback(float32(euler.yaw))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Implements commons.ARDevice
|
||||||
|
type XrealDevice struct {
|
||||||
|
eventListener *commons.AREventListener
|
||||||
|
imuDevice *C.struct_device_imu_t
|
||||||
|
deviceIsOpen bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (device *XrealDevice) Initialize() error {
|
||||||
|
if device.deviceIsOpen {
|
||||||
|
return fmt.Errorf("device is already open")
|
||||||
|
}
|
||||||
|
|
||||||
|
device.imuDevice = &C.struct_device_imu_t{}
|
||||||
|
|
||||||
|
// (*[0]byte) is a FUBAR way to cast a pointer to a function, but unsafe.Pointer doesn't work:
|
||||||
|
// cannot use unsafe.Pointer(_Cgo_ptr(_Cfpvar_fp_imuEventHandler)) (value of type unsafe.Pointer) as *[0]byte value in variable declaration
|
||||||
|
if C.DEVICE_IMU_ERROR_NO_ERROR != C.device_imu_open(device.imuDevice, (*[0]byte)(C.imuEventHandler)) {
|
||||||
|
return fmt.Errorf("failed to open IMU device")
|
||||||
|
}
|
||||||
|
|
||||||
|
C.device_imu_clear(device.imuDevice)
|
||||||
|
C.device_imu_calibrate(device.imuDevice, 1000, true, true, false)
|
||||||
|
|
||||||
|
device.deviceIsOpen = true
|
||||||
|
|
||||||
|
// let's hope this doesn't cause race conditions
|
||||||
|
go func() {
|
||||||
|
for device.eventListener == nil {
|
||||||
|
time.Sleep(time.Millisecond * 10)
|
||||||
|
}
|
||||||
|
|
||||||
|
for {
|
||||||
|
if !device.deviceIsOpen {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
// I'm sorry.
|
||||||
|
deviceEventHandlerMutex.Lock()
|
||||||
|
deviceEventListener = device.eventListener
|
||||||
|
status := C.device_imu_read(device.imuDevice, -1)
|
||||||
|
deviceEventHandlerMutex.Unlock()
|
||||||
|
|
||||||
|
if status != C.DEVICE_IMU_ERROR_NO_ERROR {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
device.deviceIsOpen = false
|
||||||
|
C.device_imu_close(device.imuDevice)
|
||||||
|
}()
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (device *XrealDevice) End() error {
|
||||||
|
if !device.deviceIsOpen {
|
||||||
|
return fmt.Errorf("device is not open")
|
||||||
|
}
|
||||||
|
|
||||||
|
C.device_imu_close(device.imuDevice)
|
||||||
|
device.deviceIsOpen = false
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (device *XrealDevice) IsPollingLibrary() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (device *XrealDevice) IsEventBasedLibrary() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (device *XrealDevice) Poll() error {
|
||||||
|
return fmt.Errorf("not supported")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (device *XrealDevice) RegisterEventListeners(listener *commons.AREventListener) {
|
||||||
|
device.eventListener = listener
|
||||||
|
}
|
|
@ -27,12 +27,13 @@
|
||||||
xorg.libXinerama
|
xorg.libXinerama
|
||||||
xorg.libX11
|
xorg.libX11
|
||||||
|
|
||||||
|
# raylib X11 build dependencies (for dev-only non-XR builds)
|
||||||
|
libxkbcommon
|
||||||
|
|
||||||
# nreal driver build dependencies
|
# nreal driver build dependencies
|
||||||
hidapi
|
hidapi
|
||||||
json_c
|
json_c
|
||||||
udev
|
|
||||||
libusb1
|
libusb1
|
||||||
opencv
|
|
||||||
];
|
];
|
||||||
|
|
||||||
shellHook = ''
|
shellHook = ''
|
||||||
|
@ -40,5 +41,6 @@
|
||||||
mkdir -p "$PWD/data/config" "$PWD/data/data"
|
mkdir -p "$PWD/data/config" "$PWD/data/data"
|
||||||
export UNREALXR_CONFIG_PATH="$PWD/data/config"
|
export UNREALXR_CONFIG_PATH="$PWD/data/config"
|
||||||
export UNREALXR_DATA_PATH="$PWD/data/data"
|
export UNREALXR_DATA_PATH="$PWD/data/data"
|
||||||
|
export UNREALXR_LOG_LEVEL="debug"
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
1
unrealxr
1
unrealxr
|
@ -1 +1,2 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
sudo UNREALXR_LOG_LEVEL="$UNREALXR_LOG_LEVEL" LD_LIBRARY_PATH="$LD_LIBRARY_PATH" UNREALXR_CONFIG_PATH="$UNREALXR_CONFIG_PATH" UNREALXR_DATA_PATH="$UNREALXR_DATA_PATH" WAYLAND_DISPLAY="$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY" XDG_RUNTIME_DIR="/user/run/0" ./uxr
|
sudo UNREALXR_LOG_LEVEL="$UNREALXR_LOG_LEVEL" LD_LIBRARY_PATH="$LD_LIBRARY_PATH" UNREALXR_CONFIG_PATH="$UNREALXR_CONFIG_PATH" UNREALXR_DATA_PATH="$UNREALXR_DATA_PATH" WAYLAND_DISPLAY="$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY" XDG_RUNTIME_DIR="/user/run/0" ./uxr
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue