local fuelConsumption = 0.00050 -- Fetch this from car.ini/[FUEL] section (couldn't figure out ac.readDataFile())
local currentLitersAvailable = car.fuel
local maxMiles = 440.96 -- Maximum range for the car to drive with a full tank (in miles) 
local bg = "updatedcluster_test_2.dds"

function RenderBG()
  display.image{ image = bg, pos = vec2(0,0), size = vec2(1024,1024), uvStart = vec2(0,0), uvEnd = vec2(1, 1) }
end

currentLiters100 = (car.rpm * car.gas * fuelConsumption)/1000 --Fuel consumption. In one second the consumption is (rpm*gas*CONSUMPTION)/1000 litres
currentLitersAvailable = car.fuel - currentLiters100 --Current liters available in the tank
currentRange = math.max(0,currentLitersAvailable * maxMiles/90) --Current mileage range


function update(dt)
-----------------------------------------FUEL RANGE

    display.text{
      text = "mph",
      pos = vec2(735,368),
      letter = vec2(30,30),
      font = "e92_big",
      color = rgbm(1,1,1,1), 
      width = 0.5,
      spacing = 1,
      alignment = -1.0
    }
    display.text{   -------------------------------CAR SPEED IN MPH
    text = math.floor(car.speedKmh / 1.609344),
    pos = vec2(575,260),
    letter = vec2(160,120),
    font = "ks_corvette_c7",
    color = rgbm(1,1,1,1), 
    width = 400,
    spacing = -60,
    alignment = .5,
    lag = 50,
  }

------------------------------MI TEXT FOR TRIP AND ODOMETER
    display.text{
        text = "mi",
        pos = vec2(861,415),
        letter = vec2(12,34),
        font = "ks_corvette_c7",
        color = rgbm(1,1,1,1), 
        width = 0.5,
        spacing = 1,
        alignment = -1.0
    }
-----------------------------------MUSIC TEXT
  
    local playing = ac.currentlyPlaying()
  display.text {
    text = string.format(string.sub(playing.title,1,13) .. "..."),
    pos = vec2(525,503),
    letter = vec2(30,35),
    color = rgbm(1,1,1,1),
    font = "e92_big",
    width = 0.5,
    alignment = 0,
    spacing = 1.0
  }
--------------------------------------G METER 1.0 VALUES
  
    display.text{
      text = string.format("%05.0f", car.distanceDrivenTotalKm), -----------------------TOTAL DISTANCE
      pos = vec2(690,400),
      letter = vec2(40, 30),
      font = "ks_corvette_c7",
      color = rgbm(1,1,1,1), 
      width = 0.5,
      spacing = -10.0,
      alignment = -1.0
    }



  


--------------------------------------Local If Statements: Gear, M Display, Dynamic/Comfort

    local tcmode = tostring(car.tractionControlMode) -- Dynamic/Comfort based on Traction Level
    if car.tractionControlMode == 0 then
        tcmode = "T"
        display.text {
          text = tcmode,
          pos = vec2(1056,482),
          letter = vec2(60,40),
          color = rgbm(1,0,0,1),
          font = "ks_corvette_c7",
          width = 0.5,
          alignment = 0,
          spacing = 3.0
        }
    elseif car.tractionControlMode > 1 then
        tcmode = "S"
        display.text {
          text = tcmode,
          pos = vec2(1056,482),
          letter = vec2(60,40),
          color = rgbm(1,0,0,1),
          font = "ks_corvette_c7",
          width = 0.5,
          alignment = 0,
          spacing = 3.0
        }
    else tcmode = "C"
        display.text {
          text = tcmode,
          pos = vec2(1056,482),
          letter = vec2(60,40),
          color = rgbm(1,1,1,5),
          font = "ks_corvette_c7",
          width = 0.5,
          alignment = 0,
          spacing = 3.0
        }
    end

    

end