classdef MFC_GUI_final < matlab.apps.AppBase

    % Properties that correspond to app components
    properties (Access = public)
        MFCControlGUIUIFigure           matlab.ui.Figure
        SettingsPanel                   matlab.ui.container.Panel
        PortDropDownLabel               matlab.ui.control.Label
        PortDropDown                    matlab.ui.control.DropDown
        OpenButton                      matlab.ui.control.Button
        GraphPanel                      matlab.ui.container.Panel
        SamplesdisplayedEditFieldLabel  matlab.ui.control.Label
        SamplesdisplayedEditField       matlab.ui.control.NumericEditField
        UIAxes                          matlab.ui.control.UIAxes
        Chanel1CheckBox                 matlab.ui.control.CheckBox
        Chanel2CheckBox                 matlab.ui.control.CheckBox
        Chanel3CheckBox                 matlab.ui.control.CheckBox
        ResetYscaleButton               matlab.ui.control.Button
        MeasurmentsPanel                matlab.ui.container.Panel
        EditField_1                     matlab.ui.control.NumericEditField
        EditField_2                     matlab.ui.control.NumericEditField
        EditField_3                     matlab.ui.control.NumericEditField
        Chanel1Label                    matlab.ui.control.Label
        Chanel2Label                    matlab.ui.control.Label
        Chanel3Label                    matlab.ui.control.Label
        EditField_Polynom1              matlab.ui.control.EditField
        EditField_Polynom2              matlab.ui.control.EditField
        EditField_Polynom3              matlab.ui.control.EditField
        PolynomcoeficientsLabel         matlab.ui.control.Label
        StartButton                     matlab.ui.control.Button
        ExportdataPanel                 matlab.ui.container.Panel
        VoltageACheckBox_export         matlab.ui.control.CheckBox
        VoltageBCheckBox_export         matlab.ui.control.CheckBox
        Chanel3CheckBox_export          matlab.ui.control.CheckBox
        Chanel2CheckBox_export          matlab.ui.control.CheckBox
        Chanel1CheckBox_export          matlab.ui.control.CheckBox
        ExportButton                    matlab.ui.control.Button
        NameEditFieldLabel              matlab.ui.control.Label
        NameEditField                   matlab.ui.control.EditField
        ChanelBPanel                    matlab.ui.container.Panel
        EditField_B                     matlab.ui.control.NumericEditField
        MFCtypeDropDown_2Label          matlab.ui.control.Label
        MFCtypeDropDown_B               matlab.ui.control.DropDown
        Slider_B                        matlab.ui.control.Slider
        ChanelAPanel                    matlab.ui.container.Panel
        EditField_A                     matlab.ui.control.NumericEditField
        Slider_A                        matlab.ui.control.Slider
        MFCtypeDropDownLabel            matlab.ui.control.Label
        MFCtypeDropDown_A               matlab.ui.control.DropDown
    end


    properties (Access = private)
        port % serial port to be used
        period %
        casovac=timer()
        measurments=[0;0;0]
        Ymin=-1
        Ymax=1
        i=1
        t
        plotdata
        chanel1pol=[1 0];
        chanel2pol=[1 0];
        chanel3pol=[1 0];
        MFC=[0;0]
    end

    methods (Access = private)
    
        function str=readSerial(app)
            if app.port.BytesAvailable>5
                string=fgets(app.port);
                string=split(string,'|',2);
                str=[str2double(string{1}),str2double(string{2}),str2double(string{3})];
            else
                str=app.measurments(:,app.i)';
            end
        end
        
        function setVoltage(app,voltageA, voltageB)
            voltageA=round(voltageA);
            voltageB=round(voltageB);
            fprintf(app.port,[num2str(voltageA) '|' num2str(voltageB)]);
        end
        
        function s=openSerial(~,ser,bRate)
            s = serial(ser);
            set(s,'BaudRate',bRate);
            set(s, 'ByteOrder', 'bigEndian');
            fopen(s);
        end
        
        function closeSerial(~,ser)
            fclose(ser);
            delete(ser);
            clear port;
        end
        
        function updateValues(app, ~, ~)
            try

                
                data=readSerial(app);
                flushinput(app.port);
                
                data(1)=polyval(app.chanel1pol,data(1));
                data(2)=polyval(app.chanel1pol,data(2));
                data(3)=polyval(app.chanel1pol,data(3));
                app.EditField_1.Value=data(1);
                app.EditField_2.Value=data(2);
                app.EditField_3.Value=data(3); 

                
                app.measurments=[app.measurments data'];
                app.plotdata=app.measurments;
                
                napeti=[app.Slider_A.Value;app.Slider_B.Value];
                app.MFC=[app.MFC napeti];
                
                
                


                app.i=app.i+1;
                app.t=0.25:0.25:(app.i/4);
                
                updatePlot(app);
                   
                
                
                
                
            catch
            end
            
        end
        
        function updatePlot(app)
           app.UIAxes.YLim=[app.Ymin app.Ymax]*1.1;
           samples=app.SamplesdisplayedEditField.Value;
           if samples==0
               samples=app.i;
           end
           
           if not(app.Chanel1CheckBox.Value)
               app.plotdata(1,:)=NaN;
           end
           if not(app.Chanel2CheckBox.Value)
               app.plotdata(2,:)=NaN;
           end
           if not(app.Chanel3CheckBox.Value)
               app.plotdata(3,:)=NaN;
           end
            
            if app.Ymin>min(app.plotdata(:,app.i))
                app.Ymin=min(app.plotdata(:,app.i));
            end
            if app.Ymax<max(app.plotdata(:,app.i))
                app.Ymax=max(app.plotdata(:,app.i));
            end
           
           
           
           
           app.UIAxes.XLim=[app.i-samples app.i+samples*0.2]/4;
           plot(app.UIAxes, app.t, app.plotdata);
           %plot(app.UIAxes, app.t, app.MFC);
           
        end
        
        
    end


    methods (Access = private)

        % Code that executes after component creation
        function startupFcn(app)
            serials=cellstr(seriallist);
            app.PortDropDown.Items=serials;
            app.PortDropDown.ItemsData=1:length(serials);
            %fclose(instrfind);
            
            
        end

        % Value changed function: EditField_A
        function EditField_AValueChanged(app, event)
            value = app.EditField_A.Value;
            value=round(value);
            app.EditField_A.Value=value;
            app.Slider_A.Value=value;
            setVoltage(app,app.EditField_A.Value,app.EditField_B.Value);
        end

        % Value changed function: EditField_B
        function EditField_BValueChanged(app, event)
            value = app.EditField_B.Value;
            value=round(value);
            app.EditField_B.Value=value;
            app.Slider_B.Value=value;
            setVoltage(app,app.EditField_A.Value,app.EditField_B.Value);
        end

        % Value changed function: EditField_Polynom1
        function EditField_Polynom1ValueChanged(app, event)
            value = app.EditField_Polynom1.Value;
            app.chanel1pol=str2num(value);
            app.EditField_Polynom1.Value=['[' num2str(app.chanel1pol) ']'];
        end

        % Value changed function: EditField_Polynom2
        function EditField_Polynom2ValueChanged(app, event)
            value = app.EditField_Polynom2.Value;
            app.chanel2pol=str2num(value);
            app.EditField_Polynom2.Value=['[' num2str(app.chanel2pol) ']'];
        end

        % Value changed function: EditField_Polynom3
        function EditField_Polynom3ValueChanged(app, event)
            value = app.EditField_Polynom3.Value;
            app.chanel3pol=str2num(value);
            app.EditField_Polynom3.Value=['[' num2str(app.chanel3pol) ']'];
        end

        % Button pushed function: ExportButton
        function ExportButtonPushed(app, event)
            data=app.t;
            if app.VoltageACheckBox_export.Value==1
               data=[data; app.MFC(1,:)];
            end
            if app.VoltageBCheckBox_export.Value==1
               data=[data; app.MFC(2,:)];
            end
            
            if app.Chanel1CheckBox_export.Value==1
                data=[data; app.measurments(1,:)];
            end
            if app.Chanel2CheckBox_export.Value==1
                data=[data; app.measurments(2,:)];
            end
            if app.Chanel3CheckBox_export.Value==1
                data=[data; app.measurments(3,:)];
            end
            
            
            
            save(app.NameEditField.Value, 'data');
            
            uialert(app.MFCControlGUIUIFigure,['File saved as ' app.NameEditField.Value '.mat'],'Export','Icon','success');
            
        end

        % Close request function: MFCControlGUIUIFigure
        function MFCControlGUIUIFigureCloseRequest(app, event)
            if not(isa(app.port, 'double'))
                if isvalid(app.port)
                    fclose(app.port); 
                end
            end
            delete(app.port);
            if(isvalid(app.casovac))
                stop(app.casovac);
            end
            delete(app.casovac);
            delete(app);
            
        end

        % Value changed function: MFCtypeDropDown_A
        function MFCtypeDropDown_AValueChanged(app, event)
            val = app.MFCtypeDropDown_A.Value;
            if val == '1'
                app.Slider_A.Limits=[-500,1500];
                app.EditField_A.Limits=[-500,1500];
            else 
                app.Slider_A.Limits=[-60,360];
                app.EditField_A.Limits=[-60,360];
            end
            
            
        end

        % Value changed function: MFCtypeDropDown_B
        function MFCtypeDropDown_BValueChanged(app, event)
            val = app.MFCtypeDropDown_B.Value;
            if val == '1'
                app.Slider_B.Limits=[-500,1500];
                app.EditField_B.Limits=[-500,1500];
            else 
                app.Slider_B.Limits=[-60,360];
                app.EditField_B.Limits=[-60,360];
            end
            
        end

        % Button pushed function: OpenButton
        function OpenButtonPushed(app, event)
            if(app.OpenButton.Text(1,1)=='O')    %Open pressed
                app.OpenButton.Text='Close';
                app.PortDropDown.Enable='Off';
                app.EditField_A.Enable='On';
                app.EditField_B.Enable='On';
                app.Slider_A.Enable='On';
                app.Slider_B.Enable='On';
                app.StartButton.Enable='On';
                app.port=serial(app.PortDropDown.Items{app.PortDropDown.Value});
                %app.PortDropDownLabel.Text=app.PortDropDown.Items(1,app.PortDropDown.Value);
                set(app.port, 'BaudRate', 250000);
                set(app.port, 'ByteOrder', 'bigEndian');
                fopen(app.port);
            else                             %Close pressed
                app.OpenButton.Text='Open';
                app.PortDropDown.Enable='On';
                app.EditField_A.Enable='Off';
                app.EditField_B.Enable='Off';
                app.Slider_A.Enable='Off';
                app.Slider_B.Enable='Off';
                app.StartButton.Enable='Off';
                app.StartButton.Text='Start';
                stop(app.casovac);
                fclose(app.port);
                delete(app.port);
                
            end
        end

        % Button pushed function: ResetYscaleButton
        function ResetYscaleButtonPushed(app, event)
            app.Ymax=1;
            app.Ymin=-1;
        end

        % Value changed function: Slider_A
        function Slider_AValueChanged(app, event)
            value = app.Slider_A.Value;
            value=round(value);
            app.Slider_A.Value=value;
            app.EditField_A.Value = value;
            setVoltage(app,app.EditField_A.Value,app.EditField_B.Value);
        end

        % Value changed function: Slider_B
        function Slider_BValueChanged(app, event)
            value = app.Slider_B.Value;
            value=round(value);
            app.Slider_B.Value=value;
            app.EditField_B.Value = value;
            setVoltage(app,app.EditField_A.Value,app.EditField_B.Value);
        end

        % Button pushed function: StartButton
        function StartButtonPushed(app, event)
             if(app.StartButton.Text(1,1:3)=='Sta')
                app.casovac=timer('Period', 0.25,'ExecutionMode', 'fixedRate');
                app.casovac.TimerFcn={@app.updateValues};
                flushinput(app.port);
                start(app.casovac);
                app.StartButton.Text='Stop';
             else
                app.StartButton.Text='Start';
                stop(app.casovac);
                %delete(app.casovac);
             end
        end
    end

    % App initialization and construction
    methods (Access = private)

        % Create UIFigure and components
        function createComponents(app)

            % Create MFCControlGUIUIFigure
            app.MFCControlGUIUIFigure = uifigure;
            app.MFCControlGUIUIFigure.Position = [100 100 640 480];
            app.MFCControlGUIUIFigure.Name = 'MFC Control GUI';
            app.MFCControlGUIUIFigure.CloseRequestFcn = createCallbackFcn(app, @MFCControlGUIUIFigureCloseRequest, true);

            % Create SettingsPanel
            app.SettingsPanel = uipanel(app.MFCControlGUIUIFigure);
            app.SettingsPanel.Title = 'Settings';
            app.SettingsPanel.Position = [16 166 277 66];

            % Create PortDropDownLabel
            app.PortDropDownLabel = uilabel(app.SettingsPanel);
            app.PortDropDownLabel.HorizontalAlignment = 'right';
            app.PortDropDownLabel.Position = [9 14 57 15];
            app.PortDropDownLabel.Text = 'Port';

            % Create PortDropDown
            app.PortDropDown = uidropdown(app.SettingsPanel);
            app.PortDropDown.Position = [81 10 70 22];

            % Create OpenButton
            app.OpenButton = uibutton(app.SettingsPanel, 'push');
            app.OpenButton.ButtonPushedFcn = createCallbackFcn(app, @OpenButtonPushed, true);
            app.OpenButton.Position = [166 10 100 22];
            app.OpenButton.Text = 'Open';

            % Create GraphPanel
            app.GraphPanel = uipanel(app.MFCControlGUIUIFigure);
            app.GraphPanel.Title = 'Graph';
            app.GraphPanel.Position = [300 14 328 276];

            % Create SamplesdisplayedEditFieldLabel
            app.SamplesdisplayedEditFieldLabel = uilabel(app.GraphPanel);
            app.SamplesdisplayedEditFieldLabel.HorizontalAlignment = 'right';
            app.SamplesdisplayedEditFieldLabel.Position = [204 40 109 15];
            app.SamplesdisplayedEditFieldLabel.Text = 'Samples displayed';

            % Create SamplesdisplayedEditField
            app.SamplesdisplayedEditField = uieditfield(app.GraphPanel, 'numeric');
            app.SamplesdisplayedEditField.Limits = [0 Inf];
            app.SamplesdisplayedEditField.Position = [232 13 54 22];
            app.SamplesdisplayedEditField.Value = 20;

            % Create UIAxes
            app.UIAxes = uiaxes(app.GraphPanel);
            xlabel(app.UIAxes, 'Time(s)')
            app.UIAxes.Box = 'on';
            app.UIAxes.XGrid = 'on';
            app.UIAxes.YGrid = 'on';
            app.UIAxes.Position = [16 63 300 185];

            % Create Chanel1CheckBox
            app.Chanel1CheckBox = uicheckbox(app.GraphPanel);
            app.Chanel1CheckBox.Text = 'Chanel 1';
            app.Chanel1CheckBox.Position = [21 49 72 15];
            app.Chanel1CheckBox.Value = true;

            % Create Chanel2CheckBox
            app.Chanel2CheckBox = uicheckbox(app.GraphPanel);
            app.Chanel2CheckBox.Text = 'Chanel 2';
            app.Chanel2CheckBox.Position = [21 31 72 15];

            % Create Chanel3CheckBox
            app.Chanel3CheckBox = uicheckbox(app.GraphPanel);
            app.Chanel3CheckBox.Text = 'Chanel 3';
            app.Chanel3CheckBox.Position = [21 13 72 15];

            % Create ResetYscaleButton
            app.ResetYscaleButton = uibutton(app.GraphPanel, 'push');
            app.ResetYscaleButton.ButtonPushedFcn = createCallbackFcn(app, @ResetYscaleButtonPushed, true);
            app.ResetYscaleButton.Position = [121 16 69 36];
            app.ResetYscaleButton.Text = {'Reset'; 'Y scale'};

            % Create MeasurmentsPanel
            app.MeasurmentsPanel = uipanel(app.MFCControlGUIUIFigure);
            app.MeasurmentsPanel.Title = 'Measurments';
            app.MeasurmentsPanel.Position = [300 297 328 170];

            % Create EditField_1
            app.EditField_1 = uieditfield(app.MeasurmentsPanel, 'numeric');
            app.EditField_1.Editable = 'off';
            app.EditField_1.Position = [14 102 85 22];

            % Create EditField_2
            app.EditField_2 = uieditfield(app.MeasurmentsPanel, 'numeric');
            app.EditField_2.Editable = 'off';
            app.EditField_2.Position = [121 102 85 22];

            % Create EditField_3
            app.EditField_3 = uieditfield(app.MeasurmentsPanel, 'numeric');
            app.EditField_3.Editable = 'off';
            app.EditField_3.Position = [228 102 85 22];

            % Create Chanel1Label
            app.Chanel1Label = uilabel(app.MeasurmentsPanel);
            app.Chanel1Label.Position = [31 128 55 15];
            app.Chanel1Label.Text = 'Chanel 1';

            % Create Chanel2Label
            app.Chanel2Label = uilabel(app.MeasurmentsPanel);
            app.Chanel2Label.Position = [138 129 55 15];
            app.Chanel2Label.Text = 'Chanel 2';

            % Create Chanel3Label
            app.Chanel3Label = uilabel(app.MeasurmentsPanel);
            app.Chanel3Label.Position = [245 129 55 15];
            app.Chanel3Label.Text = 'Chanel 3';

            % Create EditField_Polynom1
            app.EditField_Polynom1 = uieditfield(app.MeasurmentsPanel, 'text');
            app.EditField_Polynom1.ValueChangedFcn = createCallbackFcn(app, @EditField_Polynom1ValueChanged, true);
            app.EditField_Polynom1.HorizontalAlignment = 'right';
            app.EditField_Polynom1.Position = [7 18 100 22];
            app.EditField_Polynom1.Value = '[1 0]';

            % Create EditField_Polynom2
            app.EditField_Polynom2 = uieditfield(app.MeasurmentsPanel, 'text');
            app.EditField_Polynom2.ValueChangedFcn = createCallbackFcn(app, @EditField_Polynom2ValueChanged, true);
            app.EditField_Polynom2.HorizontalAlignment = 'right';
            app.EditField_Polynom2.Position = [114 18 100 22];
            app.EditField_Polynom2.Value = '[1 0]';

            % Create EditField_Polynom3
            app.EditField_Polynom3 = uieditfield(app.MeasurmentsPanel, 'text');
            app.EditField_Polynom3.ValueChangedFcn = createCallbackFcn(app, @EditField_Polynom3ValueChanged, true);
            app.EditField_Polynom3.HorizontalAlignment = 'right';
            app.EditField_Polynom3.Position = [219 18 100 22];
            app.EditField_Polynom3.Value = '[1 0]';

            % Create PolynomcoeficientsLabel
            app.PolynomcoeficientsLabel = uilabel(app.MeasurmentsPanel);
            app.PolynomcoeficientsLabel.Position = [107 47 114 15];
            app.PolynomcoeficientsLabel.Text = 'Polynom coeficients';

            % Create StartButton
            app.StartButton = uibutton(app.MeasurmentsPanel, 'push');
            app.StartButton.ButtonPushedFcn = createCallbackFcn(app, @StartButtonPushed, true);
            app.StartButton.Enable = 'off';
            app.StartButton.Position = [114 69 100 22];
            app.StartButton.Text = 'Start';

            % Create ExportdataPanel
            app.ExportdataPanel = uipanel(app.MFCControlGUIUIFigure);
            app.ExportdataPanel.Title = 'Export data';
            app.ExportdataPanel.Position = [16 14 277 143];

            % Create VoltageACheckBox_export
            app.VoltageACheckBox_export = uicheckbox(app.ExportdataPanel);
            app.VoltageACheckBox_export.Text = 'Voltage A';
            app.VoltageACheckBox_export.Position = [29 92 74.34375 15];

            % Create VoltageBCheckBox_export
            app.VoltageBCheckBox_export = uicheckbox(app.ExportdataPanel);
            app.VoltageBCheckBox_export.Text = 'Voltage B';
            app.VoltageBCheckBox_export.Position = [29 70 74.34375 15];

            % Create Chanel3CheckBox_export
            app.Chanel3CheckBox_export = uicheckbox(app.ExportdataPanel);
            app.Chanel3CheckBox_export.Text = 'Chanel 3';
            app.Chanel3CheckBox_export.Position = [184 54 72 15];

            % Create Chanel2CheckBox_export
            app.Chanel2CheckBox_export = uicheckbox(app.ExportdataPanel);
            app.Chanel2CheckBox_export.Text = 'Chanel 2';
            app.Chanel2CheckBox_export.Position = [184 72 72 15];

            % Create Chanel1CheckBox_export
            app.Chanel1CheckBox_export = uicheckbox(app.ExportdataPanel);
            app.Chanel1CheckBox_export.Text = 'Chanel 1';
            app.Chanel1CheckBox_export.Position = [184 90 72 15];

            % Create ExportButton
            app.ExportButton = uibutton(app.ExportdataPanel, 'push');
            app.ExportButton.ButtonPushedFcn = createCallbackFcn(app, @ExportButtonPushed, true);
            app.ExportButton.Position = [184 13 66 22];
            app.ExportButton.Text = 'Export';

            % Create NameEditFieldLabel
            app.NameEditFieldLabel = uilabel(app.ExportdataPanel);
            app.NameEditFieldLabel.HorizontalAlignment = 'right';
            app.NameEditFieldLabel.Position = [10 17 38 15];
            app.NameEditFieldLabel.Text = 'Name';

            % Create NameEditField
            app.NameEditField = uieditfield(app.ExportdataPanel, 'text');
            app.NameEditField.Position = [56 13 111 22];
            app.NameEditField.Value = 'MFC_measurment';

            % Create ChanelBPanel
            app.ChanelBPanel = uipanel(app.MFCControlGUIUIFigure);
            app.ChanelBPanel.Title = 'Chanel B';
            app.ChanelBPanel.Position = [16 239 277 120];

            % Create EditField_B
            app.EditField_B = uieditfield(app.ChanelBPanel, 'numeric');
            app.EditField_B.ValueChangedFcn = createCallbackFcn(app, @EditField_BValueChanged, true);
            app.EditField_B.Limits = [-500 1500];
            app.EditField_B.ValueDisplayFormat = '%.0f';
            app.EditField_B.Enable = 'off';
            app.EditField_B.Position = [184 8 63 22];

            % Create MFCtypeDropDown_2Label
            app.MFCtypeDropDown_2Label = uilabel(app.ChanelBPanel);
            app.MFCtypeDropDown_2Label.HorizontalAlignment = 'right';
            app.MFCtypeDropDown_2Label.Position = [10 12 57 15];
            app.MFCtypeDropDown_2Label.Text = 'MFC type';

            % Create MFCtypeDropDown_B
            app.MFCtypeDropDown_B = uidropdown(app.ChanelBPanel);
            app.MFCtypeDropDown_B.Items = {'P1', 'P2'};
            app.MFCtypeDropDown_B.ItemsData = {'1', '2'};
            app.MFCtypeDropDown_B.ValueChangedFcn = createCallbackFcn(app, @MFCtypeDropDown_BValueChanged, true);
            app.MFCtypeDropDown_B.Position = [82 8 48 22];
            app.MFCtypeDropDown_B.Value = '1';

            % Create Slider_B
            app.Slider_B = uislider(app.ChanelBPanel);
            app.Slider_B.Limits = [-500 1500];
            app.Slider_B.ValueChangedFcn = createCallbackFcn(app, @Slider_BValueChanged, true);
            app.Slider_B.Enable = 'off';
            app.Slider_B.Position = [15 77 247 3];

            % Create ChanelAPanel
            app.ChanelAPanel = uipanel(app.MFCControlGUIUIFigure);
            app.ChanelAPanel.Title = 'Chanel A';
            app.ChanelAPanel.Position = [16 366 277 101];

            % Create EditField_A
            app.EditField_A = uieditfield(app.ChanelAPanel, 'numeric');
            app.EditField_A.ValueChangedFcn = createCallbackFcn(app, @EditField_AValueChanged, true);
            app.EditField_A.Limits = [-500 1500];
            app.EditField_A.ValueDisplayFormat = '%.0f';
            app.EditField_A.Enable = 'off';
            app.EditField_A.Position = [184 6 63 22];

            % Create Slider_A
            app.Slider_A = uislider(app.ChanelAPanel);
            app.Slider_A.Limits = [-500 1500];
            app.Slider_A.ValueChangedFcn = createCallbackFcn(app, @Slider_AValueChanged, true);
            app.Slider_A.Enable = 'off';
            app.Slider_A.Position = [17 68 247 3];

            % Create MFCtypeDropDownLabel
            app.MFCtypeDropDownLabel = uilabel(app.ChanelAPanel);
            app.MFCtypeDropDownLabel.HorizontalAlignment = 'right';
            app.MFCtypeDropDownLabel.Position = [12 10 57 15];
            app.MFCtypeDropDownLabel.Text = 'MFC type';

            % Create MFCtypeDropDown_A
            app.MFCtypeDropDown_A = uidropdown(app.ChanelAPanel);
            app.MFCtypeDropDown_A.Items = {'P1', 'P2'};
            app.MFCtypeDropDown_A.ItemsData = {'1', '2'};
            app.MFCtypeDropDown_A.ValueChangedFcn = createCallbackFcn(app, @MFCtypeDropDown_AValueChanged, true);
            app.MFCtypeDropDown_A.Position = [84 6 48 22];
            app.MFCtypeDropDown_A.Value = '1';
        end
    end

    methods (Access = public)

        % Construct app
        function app = MFC_GUI_final

            % Create and configure components
            createComponents(app)

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

            % 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.MFCControlGUIUIFigure)
        end
    end
end