classdef exfo_control_app < matlab.apps.AppBase

    % Properties that correspond to app components
    properties (Access = public)
        UIFigure                  matlab.ui.Figure
        EXFOLASERLabel            matlab.ui.control.Label
        SAFETYMODECheckBox        matlab.ui.control.CheckBox
        PowerEditField            matlab.ui.control.EditField
        PowerEditFieldLabel       matlab.ui.control.Label
        WavelengthEditField       matlab.ui.control.EditField
        WavelengthEditFieldLabel  matlab.ui.control.Label
        ENABLEButton              matlab.ui.control.Button
        DISABLEButton             matlab.ui.control.Button
    end

    
    properties (Access = private)
        laser % Description
    end
    

    % Callbacks that handle component events
    methods (Access = private)

        % Code that executes after component creation
        function startupFcn(app)
            app.laser = Exfo_laser("mainframe_channel",1,"safety_mode",1,"connection_id",'10','lab_interface','gpib');
        end

        % Button pushed function: ENABLEButton
        function ENABLEButtonPushed(app, event)
            app.laser.enableLaser();
        end

        % Button pushed function: DISABLEButton
        function DISABLEButtonPushed(app, event)
            app.laser.disableLaser();
        end

        % Value changed function: WavelengthEditField
        function WavelengthEditFieldValueChanged(app, event)
            value = app.WavelengthEditField.Value;
            app.laser.setWavelength(value);
        end

        % Value changed function: PowerEditField
        function PowerEditFieldValueChanged(app, event)
            value = app.PowerEditField.Value;
            app.laser.setPower(value);
        end
    end

    % Component initialization
    methods (Access = private)

        % Create UIFigure and components
        function createComponents(app)

            % Create UIFigure and hide until all components are created
            app.UIFigure = uifigure('Visible', 'off');
            app.UIFigure.Position = [100 100 301 275];
            app.UIFigure.Name = 'MATLAB App';

            % Create DISABLEButton
            app.DISABLEButton = uibutton(app.UIFigure, 'push');
            app.DISABLEButton.ButtonPushedFcn = createCallbackFcn(app, @DISABLEButtonPushed, true);
            app.DISABLEButton.Position = [177 35 100 41];
            app.DISABLEButton.Text = 'DISABLE';

            % Create ENABLEButton
            app.ENABLEButton = uibutton(app.UIFigure, 'push');
            app.ENABLEButton.ButtonPushedFcn = createCallbackFcn(app, @ENABLEButtonPushed, true);
            app.ENABLEButton.Position = [33 34 100 42];
            app.ENABLEButton.Text = 'ENABLE';

            % Create WavelengthEditFieldLabel
            app.WavelengthEditFieldLabel = uilabel(app.UIFigure);
            app.WavelengthEditFieldLabel.HorizontalAlignment = 'right';
            app.WavelengthEditFieldLabel.Position = [21 197 68 22];
            app.WavelengthEditFieldLabel.Text = 'Wavelength';

            % Create WavelengthEditField
            app.WavelengthEditField = uieditfield(app.UIFigure, 'text');
            app.WavelengthEditField.ValueChangedFcn = createCallbackFcn(app, @WavelengthEditFieldValueChanged, true);
            app.WavelengthEditField.Position = [104 197 100 22];

            % Create PowerEditFieldLabel
            app.PowerEditFieldLabel = uilabel(app.UIFigure);
            app.PowerEditFieldLabel.HorizontalAlignment = 'right';
            app.PowerEditFieldLabel.Position = [49 163 39 22];
            app.PowerEditFieldLabel.Text = 'Power';

            % Create PowerEditField
            app.PowerEditField = uieditfield(app.UIFigure, 'text');
            app.PowerEditField.ValueChangedFcn = createCallbackFcn(app, @PowerEditFieldValueChanged, true);
            app.PowerEditField.Position = [103 163 100 22];

            % Create SAFETYMODECheckBox
            app.SAFETYMODECheckBox = uicheckbox(app.UIFigure);
            app.SAFETYMODECheckBox.Text = 'SAFETY MODE';
            app.SAFETYMODECheckBox.Position = [105 127 108 22];

            % Create EXFOLASERLabel
            app.EXFOLASERLabel = uilabel(app.UIFigure);
            app.EXFOLASERLabel.Position = [25 239 80 22];
            app.EXFOLASERLabel.Text = 'EXFO LASER';

            % Show the figure after all components are created
            app.UIFigure.Visible = 'on';
        end
    end

    % App creation and deletion
    methods (Access = public)

        % Construct app
        function app = exfo_control_app

            % Create UIFigure and components
            createComponents(app)

            % Register the app with App Designer
            registerApp(app, app.UIFigure)

            % Execute the startup function
            runStartupFcn(app, @startupFcn)

            if nargout == 0
                clear app
            end
        end

        % Code that executes before app deletion
        function delete(app)

            % Delete UIFigure when app is deleted
            delete(app.UIFigure)
        end
    end
end