local M = {}         --cody by Inn0centJok3r +added shit by jsze xD
M.type = 'auxilliary'
M.relevantDevice = nil

local blinkTimerThreshold_1 = 1 * 3/100
local blinkTimerThreshold_2 = 2 * 3/100
local blinkTimerThreshold_3 = 3 * 3/100
local blinkTimerThreshold_4 = 4 * 3/100
local blinkTimerThreshold_5 = 5 * 3/100
local blinkTimerThreshold_6 = 6 * 3/100
local blinkTimerThreshold_7 = 7 * 3/100
local blinkTimerThreshold_8 = 8 * 3/100
local blinkTimerThreshold_9 = 9 * 3/100
local blinkTimerThreshold_10 = 10*3/100
local blinkTimerThreshold_11 = 11*3/100
local blinkTimerThreshold_12 = 12*3/100
local blinkTimerThreshold_13 = 13*3/100
local blinkTimerThreshold_14 = 14*3/100
local blinkTimerThreshold_15 = 15*3/100
local blinkTimerThreshold_16 = 16*3/100
local blinkTimerThreshold_17 = 17*3/100
local blinkTimerThreshold_18 = 18*3/100
local blinkTimerThreshold_19 = 19*3/100
local blinkTimerThreshold_20 = 20*3/100
local blinkTimerThreshold_21 = 21*3/100
local blinkTimerThreshold_22 = 22*3/100
local blinkTimerThreshold_23 = 27*3/100

local blinkTimer = 0
local blinkPulse_1 = 0
local blinkPulse_2 = 0
local blinkPulse_3 = 0
local blinkPulse_4 = 0
local blinkPulse_5 = 0
local blinkPulse_6 = 0
local blinkPulse_7 = 0
local blinkPulse_8 = 0
local blinkPulse_9 = 0
local blinkPulse_10 = 0
local blinkPulse_11 = 0
local blinkPulse_12 = 0
local blinkPulse_13 = 0
local blinkPulse_14 = 0
local blinkPulse_15 = 0
local blinkPulse_16 = 0
local blinkPulse_17 = 0
local blinkPulse_18 = 0
local blinkPulse_19 = 0
local blinkPulse_20 = 0
local blinkPulse_21 = 0
local blinkPulse_22 = 0

local function init()
	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_L_15 = 0
	electrics.values.signal_L_16 = 0
	electrics.values.signal_L_17 = 0
	electrics.values.signal_L_18 = 0
	electrics.values.signal_L_19 = 0
	electrics.values.signal_L_20 = 0
	electrics.values.signal_L_21 = 0
	electrics.values.signal_L_22 = 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
	electrics.values.signal_R_15 = 0
	electrics.values.signal_R_16 = 0
	electrics.values.signal_R_17 = 0
	electrics.values.signal_R_18 = 0
	electrics.values.signal_R_19 = 0
	electrics.values.signal_R_20 = 0
	electrics.values.signal_R_21 = 0
	electrics.values.signal_R_22 = 0
end

local function generatePulse(dt)
	blinkTimer = blinkTimer + dt
	if blinkTimer > blinkTimerThreshold_1 then
	  	blinkPulse_1 = 1
	end
	if blinkTimer > blinkTimerThreshold_2 then
	  	blinkPulse_2 = 1
	end
	if blinkTimer > blinkTimerThreshold_3 then
	  	blinkPulse_3 = 1
	end
	if blinkTimer > blinkTimerThreshold_4 then
	  	blinkPulse_4 = 1
	end
	if blinkTimer > blinkTimerThreshold_5 then
	  	blinkPulse_5 = 1
	end
	if blinkTimer > blinkTimerThreshold_6 then
	  	blinkPulse_6 = 1
	end
	if blinkTimer > blinkTimerThreshold_7 then
	  	blinkPulse_7 = 1
	end
	if blinkTimer > blinkTimerThreshold_8 then
	  	blinkPulse_8 = 1
	end
	if blinkTimer > blinkTimerThreshold_9 then
	  	blinkPulse_9 = 1
	end
	if blinkTimer > blinkTimerThreshold_10 then
	  	blinkPulse_10 = 1
	end
	if blinkTimer > blinkTimerThreshold_11 then
	 	blinkPulse_11 = 1
	end
	if blinkTimer > blinkTimerThreshold_12 then
	  	blinkPulse_12 = 1
	end
	if blinkTimer > blinkTimerThreshold_13 then
	  	blinkPulse_13 = 1
	end
	if blinkTimer > blinkTimerThreshold_14 then
	  	blinkPulse_14 = 1
	end
	if blinkTimer > blinkTimerThreshold_15 then
	  	blinkPulse_15 = 1
	end
	if blinkTimer > blinkTimerThreshold_16 then
	  	blinkPulse_16 = 1
	end
	if blinkTimer > blinkTimerThreshold_17 then
	  	blinkPulse_17 = 1
	end
	if blinkTimer > blinkTimerThreshold_18 then
	  	blinkPulse_18 = 1
	end
	if blinkTimer > blinkTimerThreshold_19 then
	  	blinkPulse_19 = 1
	end
	if blinkTimer > blinkTimerThreshold_20 then
	  	blinkPulse_20 = 1
	end
	if blinkTimer > blinkTimerThreshold_21 then
	  	blinkPulse_21 = 1
	end
	if blinkTimer > blinkTimerThreshold_22 then
		blinkPulse_22 = 1
	end
	if blinkTimer > blinkTimerThreshold_23 then
		blinkTimer = 0
		blinkPulse_1 = 0
		blinkPulse_2 = 0
		blinkPulse_3 = 0
		blinkPulse_4 = 0
		blinkPulse_5 = 0
		blinkPulse_6 = 0
		blinkPulse_7 = 0
		blinkPulse_8 = 0
		blinkPulse_9 = 0
		blinkPulse_10 = 0
		blinkPulse_11 = 0
		blinkPulse_12 = 0
		blinkPulse_13 = 0
		blinkPulse_14 = 0
		blinkPulse_15 = 0
		blinkPulse_16 = 0
		blinkPulse_17 = 0
		blinkPulse_18 = 0
		blinkPulse_19 = 0
		blinkPulse_20 = 0
		blinkPulse_21 = 0
		blinkPulse_22 = 0
	end
end

local function updateGFX(dt)
    generatePulse(dt)

	electrics.values.signal_L_1 = (electrics.values.signal_left_input == 1 and blinkPulse_1)
	electrics.values.signal_L_2 = (electrics.values.signal_left_input == 1 and blinkPulse_2)
	electrics.values.signal_L_3 = (electrics.values.signal_left_input == 1 and blinkPulse_3)
	electrics.values.signal_L_4 = (electrics.values.signal_left_input == 1 and blinkPulse_4)
	electrics.values.signal_L_5 = (electrics.values.signal_left_input == 1 and blinkPulse_5)
	electrics.values.signal_L_6 = (electrics.values.signal_left_input == 1 and blinkPulse_6)
	electrics.values.signal_L_7 = (electrics.values.signal_left_input == 1 and blinkPulse_7)
	electrics.values.signal_L_8 = (electrics.values.signal_left_input == 1 and blinkPulse_8)
	electrics.values.signal_L_9 = (electrics.values.signal_left_input == 1 and blinkPulse_9)
	electrics.values.signal_L_10 = (electrics.values.signal_left_input == 1 and blinkPulse_10)
	electrics.values.signal_L_11 = (electrics.values.signal_left_input == 1 and blinkPulse_11)
	electrics.values.signal_L_12 = (electrics.values.signal_left_input == 1 and blinkPulse_12)
	electrics.values.signal_L_13 = (electrics.values.signal_left_input == 1 and blinkPulse_13)
	electrics.values.signal_L_14 = (electrics.values.signal_left_input == 1 and blinkPulse_14)
	electrics.values.signal_L_15 = (electrics.values.signal_left_input == 1 and blinkPulse_15)
	electrics.values.signal_L_16 = (electrics.values.signal_left_input == 1 and blinkPulse_16)
	electrics.values.signal_L_17 = (electrics.values.signal_left_input == 1 and blinkPulse_17)
	electrics.values.signal_L_18 = (electrics.values.signal_left_input == 1 and blinkPulse_18)
	electrics.values.signal_L_19 = (electrics.values.signal_left_input == 1 and blinkPulse_19)
	electrics.values.signal_L_20 = (electrics.values.signal_left_input == 1 and blinkPulse_20)
	electrics.values.signal_L_21 = (electrics.values.signal_left_input == 1 and blinkPulse_21)
	electrics.values.signal_L_22 = (electrics.values.signal_left_input == 1 and blinkPulse_22)

	electrics.values.signal_R_1 = (electrics.values.signal_right_input == 1 and blinkPulse_1)
	electrics.values.signal_R_2 = (electrics.values.signal_right_input == 1 and blinkPulse_2)
	electrics.values.signal_R_3 = (electrics.values.signal_right_input == 1 and blinkPulse_3)
	electrics.values.signal_R_4 = (electrics.values.signal_right_input == 1 and blinkPulse_4)
	electrics.values.signal_R_5 = (electrics.values.signal_right_input == 1 and blinkPulse_5)
	electrics.values.signal_R_6 = (electrics.values.signal_right_input == 1 and blinkPulse_6)
	electrics.values.signal_R_7 = (electrics.values.signal_right_input == 1 and blinkPulse_7)
	electrics.values.signal_R_8 = (electrics.values.signal_right_input == 1 and blinkPulse_8)
	electrics.values.signal_R_9 = (electrics.values.signal_right_input == 1 and blinkPulse_9)
	electrics.values.signal_R_10 = (electrics.values.signal_right_input == 1 and blinkPulse_10)
	electrics.values.signal_R_11 = (electrics.values.signal_right_input == 1 and blinkPulse_11)
	electrics.values.signal_R_12 = (electrics.values.signal_right_input == 1 and blinkPulse_12)
	electrics.values.signal_R_13 = (electrics.values.signal_right_input == 1 and blinkPulse_13)
	electrics.values.signal_R_14 = (electrics.values.signal_right_input == 1 and blinkPulse_14)
	electrics.values.signal_R_15 = (electrics.values.signal_right_input == 1 and blinkPulse_15)
	electrics.values.signal_R_16 = (electrics.values.signal_right_input == 1 and blinkPulse_16)
	electrics.values.signal_R_17 = (electrics.values.signal_right_input == 1 and blinkPulse_17)
	electrics.values.signal_R_18 = (electrics.values.signal_right_input == 1 and blinkPulse_18)
	electrics.values.signal_R_19 = (electrics.values.signal_right_input == 1 and blinkPulse_19)
	electrics.values.signal_R_20 = (electrics.values.signal_right_input == 1 and blinkPulse_20)
	electrics.values.signal_R_21 = (electrics.values.signal_right_input == 1 and blinkPulse_21)
	electrics.values.signal_R_22 = (electrics.values.signal_right_input == 1 and blinkPulse_22)

	if electrics.values.signal_right_input == 0 and electrics.values.signal_left_input == 0 then
		blinkTimer = 0
		blinkTimer = 0
		blinkPulse_1 = 0
		blinkPulse_2 = 0
		blinkPulse_3 = 0
		blinkPulse_4 = 0
		blinkPulse_5 = 0
		blinkPulse_6 = 0
		blinkPulse_7 = 0
		blinkPulse_8 = 0
		blinkPulse_9 = 0
		blinkPulse_10 = 0
		blinkPulse_11 = 0
		blinkPulse_12 = 0
		blinkPulse_13 = 0
		blinkPulse_14 = 0
		blinkPulse_15 = 0
		blinkPulse_16 = 0
		blinkPulse_17 = 0
		blinkPulse_18 = 0
		blinkPulse_19 = 0
		blinkPulse_20 = 0
		blinkPulse_21 = 0
		blinkPulse_22 = 0
	end
end

M.init = init
M.updateGFX = updateGFX

return M