-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
17 changed files
with
5,435 additions
and
0 deletions.
There are no files selected for viewing
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,5 @@ | ||
# Disclaimer of Warranty | ||
|
||
This Work is provided "AS IS." Any express or implied warranties, including but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. In no event shall the repository Creator or Contributors be liable for any direct, indirect, incidental, special, exemplary or consequential damages (including, but not limited to, procurement of substitute goods or services, loss of use, data or profits, or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this Work, even if advised of the possibility of such damage. | ||
|
||
The User of this Work agrees to hold harmless and indemnify the repository Creator and it's Contributors, its agents and employees from every claim or liability (whether in tort or in contract), including attorney's fees, court costs, and expenses, arising in direct consequence of Recipient's use of the item, including, but not limited to, claims or liabilities made for injury to or death of personnel of User or third parties, damage to or destruction of property of User or third parties, and infringement or other violations of intellectual property or technical data rights. |
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,21 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIDhDCCAmwCCQD2xSDyQCMEuTANBgkqhkiG9w0BAQsFADCBgzELMAkGA1UEBhMC | ||
dXMxEzARBgNVBAgMCmNhbGlmb3JuaWExCzAJBgNVBAcMAmxhMQswCQYDVQQKDAJj | ||
bzEQMA4GA1UECwwHc2VjdGlvbjESMBAGA1UEAwwJMTI3LjAuMC4xMR8wHQYJKoZI | ||
hvcNAQkBFhBtZUBqYWtlZG93bnMuY29tMB4XDTIyMTEyNDA3MDcxN1oXDTMyMTEy | ||
MTA3MDcxN1owgYMxCzAJBgNVBAYTAnVzMRMwEQYDVQQIDApjYWxpZm9ybmlhMQsw | ||
CQYDVQQHDAJsYTELMAkGA1UECgwCY28xEDAOBgNVBAsMB3NlY3Rpb24xEjAQBgNV | ||
BAMMCTEyNy4wLjAuMTEfMB0GCSqGSIb3DQEJARYQbWVAamFrZWRvd25zLmNvbTCC | ||
ASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAL79eV4MifDgLHjIriewR9ri | ||
k+vVpzgaefEs2LYtGuT2il26uxQIUBn/nNoDPtEM4F4PD0MulINEonbh5ipih1YQ | ||
VDSZhFcdYt6nm+ew1T7kMm++y0HrhojsXiA3kpab3XzSCFqZ2o/ae3xDxjxIEq4F | ||
XrED5h5budcCSwAez/2NS5GLTH8xHlDg1djTl+Y1h4mOwnR18PmOFP+9sOAg6ZzO | ||
/jLbxwx+AoE0OnO/ldbvLvytdmB8k/mi79+OtS6w53jqIggvTkPK/yQss82EaWTm | ||
XJyEJ9BTB0jcRItS0Y2ck0tRUI7QifdY8Q+exQwO0kRpyA/EtE/BK5PwMY10LnkC | ||
AwEAATANBgkqhkiG9w0BAQsFAAOCAQEAhN2x+yfItai4ozVvdXKlvECsdlQzmKEe | ||
aXfPuDTdYLuOBPnpPRALM9ewML2xiwX4TVGltTWIIxWubRIGyVT8RzdwYY6lOx0w | ||
UhQz9MUK2MqJM7hAwjeEnKTMned5PTtm6Jd+HBU9o9FBEhi4LuFrFrVa2vZLzfGp | ||
kJoq7tKFcotHEQ5aQ1OfsOwcHEBeqv+yM7RMjl1B1hlU5z0OtmOU8RLlSe5xLT9X | ||
/m9YmrAlJwslqtBBcaAgP1TMJeCEL14ezp0Z4CFakX+1TuopqPyp5F4h97i6spER | ||
kzH5kfp0E99OwAmooI+++CSEm+/2NQKWOEZ98qa7rLaEWp8Q6lmEAw== | ||
-----END CERTIFICATE----- |
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,178 @@ | ||
|
||
// air light 在 检查设备 => 连接设备 => 获取实例 => 判断设备类型 进行整合 | ||
// 不同类型升级提供俩个接口,通过判断设备类型分别调用不同的SDK包,再进行升级后续操作 | ||
let curGlasses = null; | ||
const DEBUG = true; | ||
|
||
import GlassesLight from './js_light/glasses.js'; | ||
import * as managerLight from './js_light/manager.js' | ||
import GlassesAir from './js_air/glasses.js' | ||
import * as managerAir from './js_air/manager.js' | ||
|
||
// ******************* | ||
|
||
export function isNrealDevice(device) { | ||
// 涉及俩种设备的区分协议(符合 air 和 light 俩种Nreal设备) | ||
// console.log({ | ||
// pid_hex: device.productId.toString(16), | ||
// pid_dec: device.productId | ||
// }) | ||
return device.productId == 0x0423 | ||
|| device.productId == 0x573C | ||
|| device.productId == 0x0424; | ||
} | ||
|
||
export function addHidListener() { | ||
navigator.hid.onconnect = function (event) { | ||
let device = event.device; | ||
if (device.productId == 1059 || device.productId == 1060) { | ||
console.log('connected',{device}); | ||
managerAir.canCommand(device).then(result => { | ||
if (result) { | ||
curGlasses = new GlassesAir(device); | ||
} | ||
}); | ||
} | ||
if (device.productId == 22332 || device.productId == 22336) { | ||
managerLight.canCommand(device).then(result => { | ||
if (result) { | ||
curGlasses = new GlassesLight(device); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
navigator.hid.ondisconnect = function (event) { | ||
if (curGlasses && curGlasses.device == event.device) { | ||
curGlasses = null; | ||
} | ||
} | ||
|
||
} | ||
|
||
window.curGlassesArray = []; | ||
|
||
export function checkConnection() { | ||
if (curGlasses) { | ||
return curGlasses; | ||
} | ||
|
||
return navigator.hid.getDevices().then(devices => { | ||
// console.warn('filtering', devices); | ||
// filters out devices that are nreal devices. | ||
return devices.filter(isNrealDevice); | ||
}).then(async devices => { | ||
console.log('filtered:', devices) | ||
|
||
for (let device of devices) { | ||
// if(curGlasses){ | ||
// console.warn('skipping',device) | ||
// continue; | ||
// } | ||
if (device.productId == 1059 || device.productId == 1060) { | ||
console.log({air:device}); | ||
if (await managerAir.canCommand(device)) { | ||
curGlasses = new GlassesAir(device); | ||
curGlassesArray.push(curGlasses); | ||
return curGlasses; | ||
} | ||
} | ||
if (device.productId == 22332 || device.productId == 22336) { | ||
if (await managerLight.canCommand(device)) { | ||
curGlasses = new GlassesLight(device); | ||
return curGlasses; | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
|
||
export function requestDevice() { | ||
return navigator.hid.requestDevice({ | ||
filters: [{ | ||
vendorId: 0x0486, // ? ASUS Computers Inc. ? | ||
}, { | ||
vendorId: 0x0483, // STMicroelectronics ? | ||
}, { | ||
vendorId: 0x0482, // Kyocera Corporation ? | ||
}, { | ||
vendorId: 0x3318, // Gleaming Reality (Wuxi) Technology Co., LTD ? | ||
}] | ||
}).then(async devices => { | ||
for (let device of devices) { | ||
if (deviceIsAir(device)) { | ||
// can command checks isMcu | ||
// air shows up as 3 separate HID devices | ||
// but we only select 1 that can be commanded | ||
// this code was originally from their activation/update page | ||
// so, maybe devices OTHER than MCU can be communicated with via JS? | ||
// I'm not sure yet... | ||
if (await managerAir.canCommand(device)) { | ||
curGlasses = new GlassesAir(device); | ||
return curGlasses; | ||
} | ||
} else if (deviceIsLight(device)) { | ||
// NOTE i don't have a Light to test with, | ||
// so all my work is focusedd on the Air Protocol for now... | ||
if (await managerLight.canCommand(device)) { | ||
curGlasses = new GlassesLight(device); | ||
return curGlasses; | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
|
||
export async function connectDevice() { | ||
let glasses = await checkConnection(); | ||
if (glasses) { | ||
return glasses; | ||
} | ||
return await requestDevice(); | ||
} | ||
|
||
export async function disconnectDevice() { | ||
if(curGlasses){ | ||
curGlasses._device.close() | ||
curGlasses = null; | ||
} | ||
} | ||
|
||
export function deviceIsAir(device){ | ||
// 0x423 || 0x424 | ||
return device.productId == 1059 || device.productId == 1060 | ||
} | ||
|
||
export function deviceIsLight(device){ | ||
// 0x573C || 0x5740 | ||
return device.productId == 22332 || device.productId == 22336 | ||
} | ||
|
||
// check glasses is air or light? | ||
export function isAirOrLight() { | ||
if (!curGlasses) { | ||
return 'not found device'; | ||
} | ||
if (deviceIsAir(curGlasses.device)) { | ||
return 1 | ||
} | ||
if (deviceIsLight(curGlasses.device)) { | ||
return 2 | ||
} | ||
return null | ||
} | ||
|
||
export function hexStream2int8Array(captureString){ | ||
return new Uint8Array(captureString.match(/.{1,2}/g).map((b)=>{ | ||
// console.log(b); | ||
return b //.parseInt(16) | ||
})) | ||
} | ||
|
||
export function parseHexString(captureString){ | ||
return glasses.protocol.parse_rsp(hexStream2int8Array(captureString)) | ||
} | ||
|
||
export { | ||
curGlasses | ||
} |
Oops, something went wrong.