Added controls for the diffs
This commit is contained in:
@@ -71,5 +71,29 @@
|
||||
"onDown": "extensions.use('ESBtnBoxDrivetrain').toggleLowFour()",
|
||||
"title": "ESBtnBox Bindings: Toggle Low 4",
|
||||
"desc": "Set the range box to low four"
|
||||
},
|
||||
"bb_turn_front_diff_lock": {
|
||||
"cat": "vehicle",
|
||||
"order": 54337,
|
||||
"ctx": "vlua",
|
||||
"onDown": "extensions.use('ESBtnBoxDrivetrain').toggleFrontDiffLock()",
|
||||
"title": "ESBtnBox Bindings: Toggle Front Diff Lock",
|
||||
"desc": "Lock the front diff"
|
||||
},
|
||||
"bb_turn_rear_diff_lock": {
|
||||
"cat": "vehicle",
|
||||
"order": 54338,
|
||||
"ctx": "vlua",
|
||||
"onDown": "extensions.use('ESBtnBoxDrivetrain').toggleRearDiffLock()",
|
||||
"title": "ESBtnBox Bindings: Toggle Rear Diff Lock",
|
||||
"desc": "Lock the rear diff"
|
||||
},
|
||||
"bb_turn_both_diff_locks": {
|
||||
"cat": "vehicle",
|
||||
"order": 54339,
|
||||
"ctx": "vlua",
|
||||
"onDown": "extensions.use('ESBtnBoxDrivetrain').toggleBothDiffLock()",
|
||||
"title": "ESBtnBox Bindings: Toggle Both Diff Locks",
|
||||
"desc": "Lock front and rear diffs"
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,8 @@ local rangeMode4lo = "4lo"
|
||||
local rangeMode2hi = "2hi"
|
||||
local curRangeMode = rangeMode2hi
|
||||
|
||||
local function changeMode(tfc, mode)
|
||||
-- changeMode changes the instance of transfercaseControl `tfc` to the mode `mode`
|
||||
local function changeTransfercaseMode(tfc, mode)
|
||||
if curRangeMode == mode then
|
||||
mode = rangeMode2hi
|
||||
end
|
||||
@@ -25,7 +26,7 @@ local function toggleHighFour()
|
||||
return
|
||||
end
|
||||
|
||||
changeMode(transferCase, rangeMode4hi)
|
||||
changeTransfercaseMode(transferCase, rangeMode4hi)
|
||||
end
|
||||
|
||||
local function toggleLowFour()
|
||||
@@ -36,10 +37,104 @@ local function toggleLowFour()
|
||||
return
|
||||
end
|
||||
|
||||
changeMode(transferCase, rangeMode4lo)
|
||||
changeTransfercaseMode(transferCase, rangeMode4lo)
|
||||
end
|
||||
|
||||
M.toggleHighFour = toggleHighFour
|
||||
M.toggleLowFour = toggleLowFour
|
||||
|
||||
----------------------------------------------------------------------------------------------------
|
||||
-- Locking Diffs
|
||||
----------------------------------------------------------------------------------------------------
|
||||
|
||||
local lockedMode = "locked"
|
||||
local openMode = "open"
|
||||
local frontDiff = {
|
||||
name = "differential_F",
|
||||
locked = false,
|
||||
}
|
||||
local rearDiff = {
|
||||
name = "differential_R",
|
||||
locked = false,
|
||||
}
|
||||
|
||||
local function diffNotFoundMsg(diffName)
|
||||
guihooks.trigger('toastrMsg', {
|
||||
type = "error",
|
||||
title = "404 Diff",
|
||||
msg = "No diff named " .. diffName,
|
||||
config = {timeOut = 5000}
|
||||
})
|
||||
end
|
||||
|
||||
local function getDiff(diffObj)
|
||||
local diff = powertrain.getDevice(diffObj.name)
|
||||
if diff == nil or next(diff) == nil then
|
||||
diffNotFoundMsg(diffObj.name)
|
||||
return {}
|
||||
end
|
||||
|
||||
return diff
|
||||
end
|
||||
|
||||
local function openDiff(diffObj)
|
||||
print("Opening diff")
|
||||
local diff = getDiff(diffObj)
|
||||
if next(diff) == nil then
|
||||
return {}
|
||||
end
|
||||
|
||||
powertrain.setDeviceMode(diff.name, openMode)
|
||||
diffObj.locked = false
|
||||
end
|
||||
|
||||
local function lockDiff(diffObj)
|
||||
print("Locking diff")
|
||||
local diff = getDiff(diffObj)
|
||||
if next(diff) == nil then
|
||||
return
|
||||
end
|
||||
powertrain.setDeviceMode(diff.name, lockedMode)
|
||||
diffObj.locked = true
|
||||
end
|
||||
|
||||
|
||||
local function toggleDiff(diffObj)
|
||||
if diffObj.locked then
|
||||
openDiff(diffObj)
|
||||
else
|
||||
lockDiff(diffObj)
|
||||
end
|
||||
end
|
||||
|
||||
local function toggleFrontDiffLock()
|
||||
toggleDiff(frontDiff)
|
||||
end
|
||||
|
||||
local function toggleRearDiffLock()
|
||||
toggleDiff(rearDiff)
|
||||
end
|
||||
|
||||
local function toggleBothDiffLock()
|
||||
toggleFrontDiffLock()
|
||||
toggleRearDiffLock()
|
||||
end
|
||||
|
||||
M.toggleFrontDiffLock = toggleFrontDiffLock
|
||||
M.toggleRearDiffLock = toggleRearDiffLock
|
||||
M.toggleBothDiffLock = toggleBothDiffLock
|
||||
|
||||
local function onReset()
|
||||
-- We need to set the things to the state they were in
|
||||
for _, diffObj in ipairs({frontDiff, rearDiff}) do
|
||||
if diffObj.locked then
|
||||
lockDiff(diffObj)
|
||||
else
|
||||
openDiff(diffObj)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
M.onReset = onReset
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user