Add GamePad support for Live Grid+
+ add Sequence Button Number press to Generic Controller + Higher Read rate for Generic Controllerpatrol-onvif-ptz-gamepad
parent
7cd0d10066
commit
5a78561c86
|
@ -28,14 +28,17 @@ $(document).ready(function() {
|
||||||
var buttonsPressed = {}
|
var buttonsPressed = {}
|
||||||
var hasGP = false;
|
var hasGP = false;
|
||||||
var repGP;
|
var repGP;
|
||||||
|
var reportInterval = 200
|
||||||
var stickBase = 2048
|
var stickBase = 2048
|
||||||
var stickMax = 4096
|
var stickMax = 4096
|
||||||
var deadZoneThreshold = 0.35
|
var deadZoneThreshold = 0.35
|
||||||
var outerDeadZone = 1.01
|
var outerDeadZone = 1.01
|
||||||
var selectedMonitor = dashboardOptions().gamepadMonitorSelection;
|
var selectedMonitor = dashboardOptions().gamepadMonitorSelection;
|
||||||
var monitorKeys = {};
|
var monitorKeys = {};
|
||||||
var gp = null;
|
|
||||||
var onMonitorOpenForGamepad = () => {}
|
var onMonitorOpenForGamepad = () => {}
|
||||||
|
var sequenceButtonPressList = []
|
||||||
|
var sequenceButtonPressTimeout = null
|
||||||
|
var buttonPressAction = null;
|
||||||
window.setGamepadMonitorSelection = (monitorId) => {
|
window.setGamepadMonitorSelection = (monitorId) => {
|
||||||
dashboardOptions('gamepadMonitorSelection', monitorId);
|
dashboardOptions('gamepadMonitorSelection', monitorId);
|
||||||
selectedMonitor = `${monitorId}`;
|
selectedMonitor = `${monitorId}`;
|
||||||
|
@ -94,9 +97,9 @@ $(document).ready(function() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function setCameraFromButtonCode(buttonCode){
|
function setCameraFromButtonCode(buttonCode, preAdded){
|
||||||
try{
|
try{
|
||||||
const addedOneToButtonCode = parseInt(buttonCode) + 1
|
const addedOneToButtonCode = preAdded ? buttonCode : parseInt(buttonCode) + 1
|
||||||
const monitor = loadedMonitors[monitorKeys[addedOneToButtonCode]];
|
const monitor = loadedMonitors[monitorKeys[addedOneToButtonCode]];
|
||||||
const isFullscreened = !!document.fullscreenElement;
|
const isFullscreened = !!document.fullscreenElement;
|
||||||
if(isFullscreened) {
|
if(isFullscreened) {
|
||||||
|
@ -227,7 +230,7 @@ $(document).ready(function() {
|
||||||
document.exitFullscreen()
|
document.exitFullscreen()
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
setCameraFromButtonCode(buttonCode)
|
buttonPressAction(buttonCode)
|
||||||
}
|
}
|
||||||
}, function(buttonCode){
|
}, function(buttonCode){
|
||||||
if(buttonCode == 6){
|
if(buttonCode == 6){
|
||||||
|
@ -258,7 +261,7 @@ $(document).ready(function() {
|
||||||
closeSnapshot()
|
closeSnapshot()
|
||||||
openSnapshot()
|
openSnapshot()
|
||||||
}else{
|
}else{
|
||||||
setCameraFromButtonCode(buttonCode)
|
buttonPressAction(buttonCode)
|
||||||
}
|
}
|
||||||
},function(buttonCode){
|
},function(buttonCode){
|
||||||
|
|
||||||
|
@ -291,13 +294,11 @@ $(document).ready(function() {
|
||||||
$.confirm.e.modal('hide')
|
$.confirm.e.modal('hide')
|
||||||
}
|
}
|
||||||
|
|
||||||
var reportOnGamepad = reportOnXboxGamepad;
|
|
||||||
|
|
||||||
function startReporting(){
|
function startReporting(){
|
||||||
if(hasGP){
|
if(hasGP){
|
||||||
console.log('Reading Gamepad')
|
console.log('Reading Gamepad')
|
||||||
var gp = navigator.getGamepads()[0];
|
repGP = window.setInterval(reportOnGamepad, reportInterval);
|
||||||
repGP = window.setInterval(reportOnGamepad,200);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -321,10 +322,29 @@ $(document).ready(function() {
|
||||||
function setControllerType(gamepadId){
|
function setControllerType(gamepadId){
|
||||||
switch(true){
|
switch(true){
|
||||||
case gamepadId.includes('Xbox'):
|
case gamepadId.includes('Xbox'):
|
||||||
|
reportInterval = 200;
|
||||||
reportOnGamepad = reportOnXboxGamepad
|
reportOnGamepad = reportOnXboxGamepad
|
||||||
|
buttonPressAction = setCameraFromButtonCode
|
||||||
|
console.log('Xbox Controller found!', buttonPressAction)
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
reportInterval = 50;
|
||||||
|
reportOnGamepad = reportOnGenericGamepad
|
||||||
|
buttonPressAction = sequenceButtonPress
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var reportOnGamepad = reportOnXboxGamepad;
|
||||||
|
|
||||||
|
function sequenceButtonPress(buttonCode){
|
||||||
|
sequenceButtonPressList.push(buttonCode)
|
||||||
|
clearTimeout(sequenceButtonPressTimeout)
|
||||||
|
sequenceButtonPressTimeout = setTimeout(() => {
|
||||||
|
const newButtonCode = parseInt(sequenceButtonPressList.map(item => `${parseInt(item) + 1}`).join(''))
|
||||||
|
setCameraFromButtonCode(newButtonCode, true)
|
||||||
|
sequenceButtonPressList = []
|
||||||
|
},300)
|
||||||
|
}
|
||||||
|
|
||||||
if(canGame()) {
|
if(canGame()) {
|
||||||
$(window).on("gamepadconnected", function(e) {
|
$(window).on("gamepadconnected", function(e) {
|
||||||
|
|
Loading…
Reference in New Issue