classdef referenceui < handle
    %REFERENCEUI Summary of this class goes here
    %   Detailed explanation goes here
    
    properties
        ui
        interface
        
        status
    end
    
    methods
        function obj = referenceui(interface)
            obj.ui = [];
            obj.interface = interface;
            obj.status = 0;
        end
        
        % This function is blank because we don't do anything with
        % responses to the commands we send.
        function receive(~, ~, ~)
        end
        
        function show(obj)
            if isempty(obj.ui)
                obj.ui = referencefig();
                set(obj.ui, 'UserData', obj);
            else
                set(obj.ui, 'Visible', 'on');
            end
        end
        
        function unpause(obj)
            if obj.status == 1
                obj.interface.sendmessage('Finished Dark Reference.');
                obj.reference();
            elseif obj.status == 2
                obj.interface.sendmessage('Finished Referencing');
                obj.status = 0;
            elseif obj.status == 3
                obj.interface.sendmessage('Finished Initializing');
            end
        end
        
        function justdark(obj)
            obj.status = 3;
            cd = commanddata();
            cd.Type = 'dark';
            obj.interface.sendcommand(command(cd, commandtype.acquire, obj));
            obj.interface.sendmessage('Initializing LED Level');
            obj.interface.serialpause(15, obj);
        end
        
        function dark(obj)
            obj.status = 1;
            cd = commanddata();
            cd.Type = 'dark';
            obj.interface.sendcommand(command(cd, commandtype.acquire, obj));
            obj.interface.sendmessage('Taking Dark Reference.');
            obj.interface.serialpause(15, obj);
        end
        
        function reference(obj)
            obj.status = 2;
            cd = commanddata();
            cd.Type = 'bg';
            obj.interface.sendcommand(command(cd, commandtype.acquire, obj));
            obj.interface.sendmessage('Taking High RI Reference.');
            obj.interface.serialpause(3, obj);
        end
        
        function delete(obj)
            try
                delete(obj.ui);
            catch err
            end
        end
    end
end
