library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity LiFi_Transmiter is
Port ( 
        clkLiFi         :IN         STD_LOGIC;
        DataIn          :IN         STD_LOGIC_VECTOR(31 downto 0);
        
        Finished        :OUT        STD_LOGIC := '1';
        TX              :OUT        STD_LOGIC := '0';
        
        read_en         :out       std_logic:='0'
);
end LiFi_Transmiter;

architecture Behavioral of LiFi_Transmiter is
signal transmittingSignal : STD_LOGIC_VECTOR(39 downto 0) := "1111000000000000000000000000000000000000";

TYPE State_type IS (Idle, Sending, Reset);
SIGNAL State : State_Type := Idle;

begin


sendDataProc: process(clkLiFi)

variable counter : integer := 40;
begin
    if(rising_edge(clkLiFi)) then
        case State is
            when Idle =>
                counter := 40;
                read_en<='1';
               -- transmittingSignal(31 downto 0) <= DataIn;
                State <= Sending;
            when Sending =>
                Finished <= '0';
                 if(counter = 40) then
                    transmittingSignal(31 downto 0) <= DataIn;
                 end if;
                -- Reduce the counter
                counter := counter -1;
                read_en<='0';
                -- Send the symbol  
                TX <= transmittingSignal(counter);
                
                if(counter = 0) then
                    State <= Reset;
                end if;
            when Reset =>
                Finished <= '1';
                State <= Idle;
            end case;
    end if;
end process;

end Behavioral;
