--made with help of raidersky,s lua (THANK YOU)

local M = {}

local function onInit()
    for i = 1, 40 do
        electrics.values['RPM_led'..i] = 0
    end
    electrics.values['RPM_green_led'] = 0
    electrics.values['RPM_red_led'] = 0
    electrics.values['RPM_blue_led'] = 0
    electrics.values['THROTTLE_ipas_blue'] = 0
end

local function onReset()
    onInit()
end

local function updateGFX(dt)
    local rpm = electrics.values['rpm'] or 0

    for i = 1, 40 do
        if rpm > i * 240 and rpm < 12000 then
            electrics.values['RPM_led'..i] = 1
        else
            electrics.values['RPM_led'..i] = 0
        end
    end

    if rpm > 7000 and rpm < 12000 then
        electrics.values['RPM_green_led'] = 1
    else
        electrics.values['RPM_green_led'] = 0
    end

    if rpm > 7750 and rpm < 12000 then
        electrics.values['RPM_red_led'] = 1
    else
        electrics.values['RPM_red_led'] = 0
    end

    if rpm > 8200 and rpm < 12000 then
        electrics.values['RPM_blue_led'] = 1
    else
        electrics.values['RPM_blue_led'] = 0
    end

    if rpm > 4000 and rpm < 12000 then
        electrics.values['THROTTLE_ipas_blue'] = 1
    else
        electrics.values['THROTTLE_ipas_blue'] = 0
    end

    if rpm < 500 then
        electrics.values['RPM_ledoff'] = 1
    else
        electrics.values['RPM_ledoff'] = 0
    end
end

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

return M
