-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
518 additions
and
5 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { PositionalTracking } from "./positionalTracking.js"; | ||
import { RotationalTracking } from "./rotationalTracking.js"; | ||
import { SocketManager } from "./socketScript.js"; | ||
|
||
class ControllerTracking { | ||
constructor() { | ||
this.rotation = { error: "Starting" }; | ||
this.position = { error: "Starting" }; | ||
|
||
this.socket = new SocketManager(); | ||
this.PositionalTracking = new PositionalTracking(this); | ||
this.RotationalTracking = new RotationalTracking(this); | ||
}; | ||
|
||
connect(id) { | ||
var scope = this; | ||
|
||
//this.socket.connect(id); | ||
|
||
setInterval(() => { | ||
scope.send(scope); | ||
}, 200); | ||
}; | ||
|
||
send(scope) { | ||
/*this.socket.send(JSON.stringify({ | ||
position: scope.position, | ||
rotation: scope.rotation | ||
}));*/ | ||
|
||
console.log({ | ||
position: scope.position, | ||
rotation: scope.rotation | ||
}); | ||
}; | ||
}; | ||
|
||
export { ControllerTracking }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { ControllerBluetoothInterface } from "../utils/ControllerBluetoothInterface.js"; | ||
|
||
class RotationalTracking { | ||
constructor(root) { | ||
this.root = root; | ||
var scope = this; | ||
|
||
this.dataUpdate = false; | ||
|
||
this.controllerBluetoothInterface = new ControllerBluetoothInterface((e) => { | ||
scope.data(scope, e); | ||
}); | ||
|
||
this.start(); | ||
}; | ||
|
||
async start() { | ||
await this.controllerBluetoothInterface.pair(); | ||
|
||
var scope = this; | ||
|
||
setInterval(() => { | ||
this.tick(scope) | ||
}, 1000); | ||
}; | ||
|
||
async tick(scope) { | ||
if(scope.dataUpdate == false) { | ||
await this.controllerBluetoothInterface.runCommand(ControllerBluetoothInterface.CMD_VR_MODE); | ||
await this.controllerBluetoothInterface.runCommand(ControllerBluetoothInterface.CMD_SENSOR); | ||
} else { | ||
scope.dataUpdate = false; | ||
}; | ||
}; | ||
|
||
data(scope, event) { | ||
scope.dataUpdate = true; | ||
|
||
scope.root.rotation = event; | ||
|
||
//console.log(event); | ||
}; | ||
}; | ||
|
||
export { RotationalTracking }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { PositionalTracking } from "./positionalTracking.js"; | ||
import { ControllerTracking } from "./controllerTracking.js"; | ||
|
||
async function setupController() { | ||
window.positionTracking = new PositionalTracking(); | ||
window.controllerTracking = new ControllerTracking(); | ||
}; | ||
|
||
document.querySelector(".setupController").addEventListener("click", setupController); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Peer } from "../libraries/peerjs.esm.js"; | ||
|
||
class SocketManager { | ||
constructor() { | ||
console.log("Waiting for Peer connection"); | ||
|
||
this.peer = new Peer(); | ||
this.conn = null; | ||
}; | ||
|
||
connect(id) { | ||
if(this.conn !== null) return false; | ||
|
||
this.conn = this.peer.connect(id); | ||
|
||
var scope = this; | ||
|
||
this.conn.on('open', function(){ | ||
console.log("Peer connected"); | ||
}); | ||
|
||
this.conn.on('data', function(data){ | ||
scope.data(data, scope); | ||
}); | ||
|
||
return true; | ||
}; | ||
|
||
data(data, scope) { | ||
if(this.conn == null) return false; | ||
|
||
console.log("Data recieved: " + data); | ||
return true; | ||
}; | ||
|
||
send(data) { | ||
if(this.conn == null) return false; | ||
|
||
this.conn.send(data); | ||
return true; | ||
}; | ||
}; | ||
|
||
export { SocketManager }; |
Oops, something went wrong.