-- This Source Code Form is subject to the terms of the bCDDL, v. 1.1.
-- If a copy of the bCDDL was not distributed with this
-- file, You can obtain one at http://beamng.com/bCDDL-1.1.txt

local M = {}

local function onInit()
  electrics.values.altitudeFT = 0
  electrics.values.altitudeMT = 0
end

local function onReset()
	onInit()
end

local function updateGFX(dt)
  local position = obj:getPosition()
  
  --get adjustment
  local altimeterAdjustFT = electrics.values.altimeterAdjust or 0
  local altimeterAdjustMT = altimeterAdjustFT * 0.3048
  
  --set electrics
  electrics.values.altitudeFT = (position.z * 3.28084) + altimeterAdjustFT
  electrics.values.altitudeMT = position.z + altimeterAdjustMT
end

-- public interface
M.onInit      = onInit
M.onReset     = onReset
M.updateGFX = updateGFX

return M