local M = {}		--by xNME
local timer = 0
local timer2 = 0
local timer3 = 0
local timer4 = 0
local cycleComplete = 0
local cycleStarting = 0
local cycle2Complete = 0
local cycle2Starting = 0

local function onInit()
    electrics.values["signal_L_1"] = 0
    electrics.values["signal_L_2"] = 0
    electrics.values["signal_L_3"] = 0
    electrics.values["signal_L_4"] = 0
    electrics.values["signal_L_5"] = 0
    electrics.values["signal_L_6"] = 0
    electrics.values["signal_L_7"] = 0
    electrics.values["signal_L_8"] = 0
    electrics.values["signal_L_9"] = 0
    electrics.values["signal_L_10"] = 0
    electrics.values["signal_L_11"] = 0
    electrics.values["signal_L_12"] = 0
    electrics.values["signal_L_13"] = 0
    electrics.values["signal_L_14"] = 0
	
	electrics.values["signal_R_1"] = 0
    electrics.values["signal_R_2"] = 0
    electrics.values["signal_R_3"] = 0
    electrics.values["signal_R_4"] = 0
    electrics.values["signal_R_5"] = 0
    electrics.values["signal_R_6"] = 0
    electrics.values["signal_R_7"] = 0
    electrics.values["signal_R_8"] = 0
    electrics.values["signal_R_9"] = 0
    electrics.values["signal_R_10"] = 0
    electrics.values["signal_R_11"] = 0
    electrics.values["signal_R_12"] = 0
    electrics.values["signal_R_13"] = 0
    electrics.values["signal_R_14"] = 0
	timer2 = 0
	timer = 0
	timer3 = 0
	timer4 = 0
	cycleStarting = 0
	cycleComplete = 0
	cycle2Starting = 0
	cycle2Complete = 0
--Running light starting sequence
    electrics.values["inno_running_1"] = 1
	electrics.values["inno_running_2"] = 1
    electrics.values["inno_running_3"] = 1
    electrics.values["inno_running_4"] = 1
    electrics.values["inno_running_5"] = 1
    electrics.values["inno_running_6"] = 1
    electrics.values["inno_running_7"] = 1
    electrics.values["inno_running_8"] = 1
    electrics.values["inno_running_9"] = 1
    electrics.values["inno_running_10"] = 1
    electrics.values["inno_running_11"] = 1
    electrics.values["inno_running_12"] = 1
    electrics.values["inno_running_13"] = 1
    electrics.values["inno_running_14"] = 1
	electrics.values["inno_running_15"] = 1
	electrics.values["inno_running_16"] = 1
    electrics.values["inno_running_17"] = 1
	electrics.values["inno_running_18"] = 1
	electrics.values["inno_running_19"] = 1
	electrics.values["inno_running_20"] = 1
	electrics.values["inno_running_21"] = 1
	electrics.values["inno_running_22"] = 1
	electrics.values["inno_running_23"] = 1
	electrics.values["inno_running_24"] = 1
	electrics.values["inno_running_25"] = 1
	electrics.values["inno_running_26"] = 1
	electrics.values["inno_running_27"] = 1
	electrics.values["inno_running_28"] = 1
	electrics.values["inno_running_29"] = 1
	electrics.values["inno_running_30"] = 1
end

local function onReset()
	electrics.values["signal_L_1"] = 0
    electrics.values["signal_L_2"] = 0
    electrics.values["signal_L_3"] = 0
    electrics.values["signal_L_4"] = 0
    electrics.values["signal_L_5"] = 0
    electrics.values["signal_L_6"] = 0
    electrics.values["signal_L_7"] = 0
    electrics.values["signal_L_8"] = 0
    electrics.values["signal_L_9"] = 0
    electrics.values["signal_L_10"] = 0
    electrics.values["signal_L_11"] = 0
    electrics.values["signal_L_12"] = 0
    electrics.values["signal_L_13"] = 0
    electrics.values["signal_L_14"] = 0
	
	electrics.values["signal_R_1"] = 0
    electrics.values["signal_R_2"] = 0
    electrics.values["signal_R_3"] = 0
    electrics.values["signal_R_4"] = 0
    electrics.values["signal_R_5"] = 0
    electrics.values["signal_R_6"] = 0
    electrics.values["signal_R_7"] = 0
    electrics.values["signal_R_8"] = 0
    electrics.values["signal_R_9"] = 0
    electrics.values["signal_R_10"] = 0
    electrics.values["signal_R_11"] = 0
    electrics.values["signal_R_12"] = 0
    electrics.values["signal_R_13"] = 0
    electrics.values["signal_R_14"] = 0
	timer2 = 0
	timer = 0
	timer3 = 0
	timer4 = 0
	cycleStarting = 0
	cycleComplete = 0
	cycle2Starting = 0
	cycle2Complete = 0
--Running light starting sequence
    electrics.values["inno_running_1"] = 1
	electrics.values["inno_running_2"] = 1
    electrics.values["inno_running_3"] = 1
    electrics.values["inno_running_4"] = 1
    electrics.values["inno_running_5"] = 1
    electrics.values["inno_running_6"] = 1
    electrics.values["inno_running_7"] = 1
    electrics.values["inno_running_8"] = 1
    electrics.values["inno_running_9"] = 1
    electrics.values["inno_running_10"] = 1
    electrics.values["inno_running_11"] = 1
    electrics.values["inno_running_12"] = 1
    electrics.values["inno_running_13"] = 1
    electrics.values["inno_running_14"] = 1
	electrics.values["inno_running_15"] = 1
	electrics.values["inno_running_16"] = 1
    electrics.values["inno_running_17"] = 1
	electrics.values["inno_running_18"] = 1
	electrics.values["inno_running_19"] = 1
	electrics.values["inno_running_20"] = 1
	electrics.values["inno_running_21"] = 1
	electrics.values["inno_running_22"] = 1
	electrics.values["inno_running_23"] = 1
	electrics.values["inno_running_24"] = 1
	electrics.values["inno_running_25"] = 1
	electrics.values["inno_running_26"] = 1
	electrics.values["inno_running_27"] = 1
	electrics.values["inno_running_28"] = 1
	electrics.values["inno_running_29"] = 1
	electrics.values["inno_running_30"] = 1
end

local function updateGFX(dt) 
  if electrics.values["signal_L"] == 1 then
	timer = timer + dt
	
	if timer >= 0.01 then
	electrics.values["signal_L_2"] = 1
	end
	if timer >= 0.0272 then
	electrics.values["signal_L_3"] = 1
	end
	if timer >= 0.0541 then
	electrics.values["signal_L_4"] = 1
	end
	if timer >= 0.081 then
	electrics.values["signal_L_5"] = 1
	end
	if timer >= 0.1079 then
	electrics.values["signal_L_6"] = 1
	end
	if timer >= 0.1348 then
	electrics.values["signal_L_7"] = 1
	end
	if timer >= 0.1617 then
	electrics.values["signal_L_8"] = 1
	end
	if timer >= 0.1886 then
	electrics.values["signal_L_9"] = 1
	end
	if timer >= 0.2155 then
	electrics.values["signal_L_10"] = 1
	end
	if timer >= 0.2424 then
	electrics.values["signal_L_11"] = 1
	end
	if timer >= 0.2693 then
	electrics.values["signal_L_12"] = 1
	end
	if timer >= 0.2962 then
	electrics.values["signal_L_13"] = 1
	end
	if timer >= 0.3231 then
	electrics.values["signal_L_14"] = 1
	end
	if timer >= 0.35 then
	electrics.values["signal_L_15"] = 1
	end
	
  else
	electrics.values["signal_L_2"] = 0
    electrics.values["signal_L_3"] = 0
    electrics.values["signal_L_4"] = 0
    electrics.values["signal_L_5"] = 0
    electrics.values["signal_L_6"] = 0
    electrics.values["signal_L_7"] = 0
    electrics.values["signal_L_8"] = 0
    electrics.values["signal_L_9"] = 0
    electrics.values["signal_L_10"] = 0
    electrics.values["signal_L_11"] = 0
    electrics.values["signal_L_12"] = 0
    electrics.values["signal_L_13"] = 0
    electrics.values["signal_L_14"] = 0
    electrics.values["signal_L_15"] = 0
	timer = 0	
  end
  
  if electrics.values["signal_R"] == 1 then
	timer2 = timer2 + dt
	
	if timer2 >= 0.01 then
	electrics.values["signal_R_2"] = 1
	end
	if timer2 >= 0.0272 then
	electrics.values["signal_R_3"] = 1
	end
	if timer2 >= 0.0541 then
	electrics.values["signal_R_4"] = 1
	end
	if timer2 >= 0.081 then
	electrics.values["signal_R_5"] = 1
	end
	if timer2 >= 0.1079 then
	electrics.values["signal_R_6"] = 1
	end
	if timer2 >= 0.1348 then
	electrics.values["signal_R_7"] = 1
	end
	if timer2 >= 0.1617 then
	electrics.values["signal_R_8"] = 1
	end
	if timer2 >= 0.1886 then
	electrics.values["signal_R_9"] = 1
	end
	if timer2 >= 0.2155 then
	electrics.values["signal_R_10"] = 1
	end
	if timer2 >= 0.2424 then
	electrics.values["signal_R_11"] = 1
	end
	if timer2 >= 0.2693 then
	electrics.values["signal_R_12"] = 1
	end
	if timer2 >= 0.2962 then
	electrics.values["signal_R_13"] = 1
	end
	if timer2 >= 0.3231 then
	electrics.values["signal_R_14"] = 1
	end
	if timer2 >= 0.35 then
	electrics.values["signal_R_15"] = 1
	end
	
  else
	electrics.values["signal_R_2"] = 0
    electrics.values["signal_R_3"] = 0
    electrics.values["signal_R_4"] = 0
    electrics.values["signal_R_5"] = 0
    electrics.values["signal_R_6"] = 0
    electrics.values["signal_R_7"] = 0
    electrics.values["signal_R_8"] = 0
    electrics.values["signal_R_9"] = 0
    electrics.values["signal_R_10"] = 0
    electrics.values["signal_R_11"] = 0
    electrics.values["signal_R_12"] = 0
    electrics.values["signal_R_13"] = 0
    electrics.values["signal_R_14"] = 0
    electrics.values["signal_R_15"] = 0
	timer2 = 0	
  end
  -- Обновленная проверка для работы с циклом для низкого света
if electrics.values["dho"] == 0 and cycleStarting == 0 then
    cycleStarting = 1
    cycleComplete = 0
elseif electrics.values["dho"] == 1 and cycleStarting == 1 then
    timer3 = timer3 + dt
    
    -- Добавление таймеров с небольшими коррективами времени для плавного включения
    if timer3 >= 0.05 then
        electrics.values["inno_running_1"] = 1
    end
    if timer3 >= 0.10 then
        electrics.values["inno_running_3"] = 1
    end
    if timer3 >= 0.15 then
        electrics.values["inno_running_5"] = 1
    end
    if timer3 >= 0.20 then
        electrics.values["inno_running_7"] = 1
    end
    if timer3 >= 0.25 then
        electrics.values["inno_running_9"] = 1
        cycleStarting = 0
        timer3 = 0
        cycleComplete = 1
    end
end

-- Обновленная проверка для работы с циклом двигателя
if electrics.values["engineRunning"] == 0 and cycle2Starting == 0 then
    cycle2Starting = 1
    cycle2Complete = 0
elseif electrics.values["engineRunning"] == 1 and cycle2Starting == 1 then
    timer4 = timer4 + dt
-- Добавление таймеров с небольшими коррективами времени для плавного включения
    if timer4 >= 1.05 then
        electrics.values["inno_running_1"] = 0
    end
    if timer4 >= 1.10 then
        electrics.values["inno_running_2"] = 0
    end
    if timer4 >= 1.15 then
        electrics.values["inno_running_3"] = 0
    end
    if timer4 >= 1.20 then
        electrics.values["inno_running_4"] = 0
    end
    if timer4 >= 1.25 then
        electrics.values["inno_running_5"] = 0
	end
    if timer4 >= 1.30 then
        electrics.values["inno_running_6"] = 0
    end
    if timer4 >= 1.35 then
        electrics.values["inno_running_7"] = 0
    end
    if timer4 >= 1.40 then
        electrics.values["inno_running_8"] = 0
    end
    if timer4 >= 1.45 then
        electrics.values["inno_running_9"] = 0
    end
    if timer4 >= 1.50 then
        electrics.values["inno_running_10"] = 0
    end
    if timer4 >= 1.55 then
        electrics.values["inno_running_11"] = 0
    end

	if timer4 >= 0.55 then
	electrics.values["inno_running_11"] = 1
	end
	if timer4 >= 0.65 then
	electrics.values["inno_running_10"] = 1
	end
	if timer4 >= 0.75 then
	electrics.values["inno_running_9"] = 1
	end
	if timer4 >= 0.85 then
	electrics.values["inno_running_8"] = 1
	end
	if timer4 >= 0.95 then
	electrics.values["inno_running_7"] = 1
	end
	if timer4 >= 1.05 then
	electrics.values["inno_running_6"] = 1
	end
	if timer4 >= 1.15 then
	electrics.values["inno_running_5"] = 1
	end
	if timer4 >= 1.25 then
	electrics.values["inno_running_4"] = 1
	end
	if timer4 >= 1.35 then
	electrics.values["inno_running_3"] = 1
	end
	if timer4 >= 1.45 then
	electrics.values["inno_running_2"] = 1
	end
	if timer4 >= 1.55 then
	electrics.values["inno_running_1"] = 1
    end

-- Добавление таймеров с небольшими коррективами времени для плавного включения
    if timer4 >= 0.05 then
        electrics.values["signal_R_2"] = 1
    end
    if timer4 >= 0.10 then
        electrics.values["signal_R_3"] = 1
    end
    if timer4 >= 0.15 then
        electrics.values["signal_R_4"] = 1
    end
    if timer4 >= 0.20 then
        electrics.values["signal_R_5"] = 1
    end
    if timer4 >= 0.25 then
        electrics.values["signal_R_6"] = 1
    end
    if timer4 >= 0.30 then
        electrics.values["signal_R_7"] = 1
    end
    if timer4 >= 0.35 then
        electrics.values["signal_R_8"] = 1
    end
    if timer4 >= 0.40 then
        electrics.values["signal_R_9"] = 1
    end
    if timer4 >= 0.45 then
        electrics.values["signal_R_10"] = 1
    end
    if timer4 >= 0.50 then
        electrics.values["signal_R_11"] = 1
    end

	if timer4 >= 0.60 then
	electrics.values["signal_R_11"] = 0
	end
	if timer4 >= 0.70 then
	electrics.values["signal_R_10"] = 0
	end
	if timer4 >= 0.80 then
	electrics.values["signal_R_9"] = 0
	end
	if timer4 >= 0.90 then
	electrics.values["signal_R_8"] = 0
	end
	if timer4 >= 1.00 then
	electrics.values["signal_R_7"] = 0
	end
	if timer4 >= 1.10 then
	electrics.values["signal_R_6"] = 0
	end
	if timer4 >= 1.20 then
	electrics.values["signal_R_5"] = 0
	end
	if timer4 >= 1.30 then
	electrics.values["signal_R_4"] = 0
	end
	if timer4 >= 1.40 then
	electrics.values["signal_R_3"] = 0
	end
	if timer4 >= 1.50 then
	electrics.values["signal_R_2"] = 0
	end
    -- Добавление таймеров с небольшими коррективами времени для плавного включения
    if timer4 >= 0.05 then
        electrics.values["signal_L_2"] = 1
    end
    if timer4 >= 0.10 then
        electrics.values["signal_L_3"] = 1
    end
    if timer4 >= 0.15 then
        electrics.values["signal_L_4"] = 1
    end
    if timer4 >= 0.20 then
        electrics.values["signal_L_5"] = 1
    end
    if timer4 >= 0.25 then
        electrics.values["signal_L_6"] = 1
    end
    if timer4 >= 0.30 then
        electrics.values["signal_L_7"] = 1
    end
    if timer4 >= 0.35 then
        electrics.values["signal_L_8"] = 1
    end
    if timer4 >= 0.40 then
        electrics.values["signal_L_9"] = 1
    end
    if timer4 >= 0.45 then
        electrics.values["signal_L_10"] = 1
    end
    if timer4 >= 0.50 then
        electrics.values["signal_L_11"] = 1
    end

	if timer4 >= 0.60 then
	electrics.values["signal_L_11"] = 0
	end
	if timer4 >= 0.70 then
	electrics.values["signal_L_10"] = 0
	end
	if timer4 >= 0.80 then
	electrics.values["signal_L_9"] = 0
	end
	if timer4 >= 0.90 then
	electrics.values["signal_L_8"] = 0
	end
	if timer4 >= 1.00 then
	electrics.values["signal_L_7"] = 0
	end
	if timer4 >= 1.10 then
	electrics.values["signal_L_6"] = 0
	end
	if timer4 >= 1.20 then
	electrics.values["signal_L_5"] = 0
	end
	if timer4 >= 1.30 then
	electrics.values["signal_L_4"] = 0
	end
	if timer4 >= 1.40 then
	electrics.values["signal_L_3"] = 0
	end
	if timer4 >= 1.50 then
	electrics.values["signal_L_2"] = 0
    
    
	cycle2Starting = 0
	timer4 = 0
	cycle2Complete = 1
	end
  end

-- Проверка состояний после завершения циклов
if electrics.values["engineRunning"] == 1 and cycleComplete == 0 and cycle2Complete == 1 then
    -- Выключаем все огни, если двигатель запущен
    electrics.values["inno_running_1"] = 1
    electrics.values["inno_running_2"] = 1
    electrics.values["inno_running_3"] = 1
    electrics.values["inno_running_4"] = 1
    electrics.values["inno_running_5"] = 1
    electrics.values["inno_running_6"] = 1
    electrics.values["inno_running_7"] = 1
    electrics.values["inno_running_8"] = 1
    electrics.values["inno_running_9"] = 1
    electrics.values["inno_running_10"] = 1
    electrics.values["inno_running_11"] = 1

elseif electrics.values["engineRunning"] == 0 and cycle2Complete == 0 then
    -- Выключаем все огни, если двигатель и ближний свет выключены
    electrics.values["inno_running_1"] = 0
    electrics.values["inno_running_2"] = 0
    electrics.values["inno_running_3"] = 0
    electrics.values["inno_running_4"] = 0
    electrics.values["inno_running_5"] = 0
    electrics.values["inno_running_6"] = 0
    electrics.values["inno_running_7"] = 0
    electrics.values["inno_running_8"] = 0
    electrics.values["inno_running_9"] = 0
    electrics.values["inno_running_10"] = 0
    electrics.values["inno_running_11"] = 0
end

end


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

return M