classdef Prototypeinterfacederneriereversion < matlab.apps.AppBase

    % Properties that correspond to app components
    properties (Access = public)
        UIFigure                matlab.ui.Figure
        AideButton              matlab.ui.control.Button
        ConnLamp                matlab.ui.control.Lamp
        ConnectionButton        matlab.ui.control.Button
        ConnexionNucloPanel     matlab.ui.container.Panel
        GridLayout11            matlab.ui.container.GridLayout
        PortList                matlab.ui.control.DropDown
        PortLabel               matlab.ui.control.Label
        Refresh                 matlab.ui.control.Button
        LEDsList                matlab.ui.control.ListBox
        LEDsLabel               matlab.ui.control.Label
        TabGroup                matlab.ui.container.TabGroup
        DfinitionsdesLEDsTab    matlab.ui.container.Tab
        TypedeLED               matlab.ui.control.DropDown
        TypedeLEDDropDownLabel  matlab.ui.control.Label
        SupprimerButton         matlab.ui.control.Button
        AjouterLEDsButton       matlab.ui.control.Button
        NomLED                  matlab.ui.control.EditField
        NomEditFieldLabel       matlab.ui.control.Label
        AdresseLED              matlab.ui.control.NumericEditField
        AdresseLabel            matlab.ui.control.Label
        ParamtragesdesLEDsTab   matlab.ui.container.Tab
        RotationPanel           matlab.ui.container.Panel
        VitesseSpinner          matlab.ui.control.Spinner
        VitesseSpinnerLabel     matlab.ui.control.Label
        PanSpinner              matlab.ui.control.Spinner
        PanSpinnerLabel         matlab.ui.control.Label
        TiltSpinner             matlab.ui.control.Spinner
        TiltSpinnerLabel        matlab.ui.control.Label
        CouleurPanel            matlab.ui.container.Panel
        BlancSpinner            matlab.ui.control.Spinner
        BlancSpinnerLabel       matlab.ui.control.Label
        BleuSpinner             matlab.ui.control.Spinner
        BleuSpinnerLabel        matlab.ui.control.Label
        VertSpinner             matlab.ui.control.Spinner
        VertSpinnerLabel        matlab.ui.control.Label
        RougeSpinner            matlab.ui.control.Spinner
        RougeSpinnerLabel       matlab.ui.control.Label
        IntensitSpinner         matlab.ui.control.Spinner
        IntensitSpinnerLabel    matlab.ui.control.Label
        SquencesTab             matlab.ui.container.Tab
        BOUQUETFINALLabel       matlab.ui.control.Label
    end

    
    properties (Access = private)
          adresseLED = [];
          typeLED = [];
          is_connected = false;
          GREEN_COLOR = [0 1 0];
          RED_COLOR = [1 0 0];
          s % serial port

    end
    
    methods (Access = private)
        function resetApp(app, ~)
            % Communications
            app.is_connected = false;
            app.PortList.Items = serialportlist();


        end

        
        function canal = findcanal(app,TypedeLED, CC)
            %en entrée typeled('NOMdu type de la led', la nature de canal qu'on
            %souhaite: V pour vert, R pour rouge, B pour bleu, I pour
            %intensité)

            if TypedeLED=="Eurolite000" %teste de quel type de led il s'agit
                if CC=='R'%rouge
                    canal= 3; %retourne le canal codant pour le rouge

                end
                if CC=='B'%bleu
                    canal = 4; %retourne le canal codant pour bleu
                end

                if CC=='V'%vert
                    canal = 5; %retourne le canal codant pour le vert
                end

                if CC=='I'%intensite
                    canal = 2;
                end

            end


            if TypedeLED=="Leuchtkraft" %lyre Leuchtkraft WASH-42LED
                if CC=='R'
                    canal = 3;%retourne le canal codant pour le rouge

                end
                if CC=='B'
                    canal = 5;%retourne le canal codant pour le bleu
                end

                if CC=='V'%retourne le canal codant pour le vert
                    canal = 4;
                end
                                
                if CC=='W'%vitesse
                    canal = 6; %retourne le canal codant pour l'intensité
                end

                if CC=='I'%intensite
                    canal = 2; %retourne le canal codant pour l'intensité
                end
                                
                if CC=='T'%tilt
                    canal = 1; %retourne le canal codant pour l'intensité
                end
                               
                if CC=='P'%pan
                    canal = 0; %retourne le canal codant pour l'intensité
                end
                                
                if CC=='S'%vitesse
                    canal = 7; %retourne le canal codant pour l'intensité
                end

            end


            if TypedeLED=="Renkforce00"

                if CC=='R'
                    canal = 4;%retourne le canal codant pour le rouge

                end
                if CC=='B'
                    canal = 6;%retourne le canal codant pour le bleu
                end

                if CC=='V'%retourne le canal codant pour le vert
                    canal = 5;
                end

                if CC=='I'  %intensite
                    canal = 3; %retourne le canal codant pour l'intensité
                end
            end
            
        end
    end
    

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

        % Button pushed function: AjouterLEDsButton
        function AddLED(app, event)
            n = length(app.LEDsList.Items);
            % ajout du nom de la nouvelle LED dans la liste
            if isempty(app.LEDsList.Items)
                app.LEDsList.Items= {app.NomLED.Value};
                app.adresseLED = [app.AdresseLED.Value];
                app.typeLED = [app.TypedeLED.Value];
            else
                app.LEDsList.Items= {app.LEDsList.Items{1,1:n} ,app.NomLED.Value};
                app.adresseLED = [app.adresseLED, app.AdresseLED.Value];
                app.typeLED = [app.typeLED; app.TypedeLED.Value];

            end
%           Les caractéristiques de la nouvelle LED sont stockées dans la variable app.LED 
            %app.AdresseLED.Value
            app.TypedeLED.Value
            app.typeLED
            %app.LED = [app.LED; [app.AdresseLED.Value, app.NbcanauxLED.Value]];
            %adresses = app.LED(:,1)
            app.NomLED.Value = '';
            app.AdresseLED.Value =0;
            app.LEDsList.Multiselect= true;




        end

        % Button pushed function: SupprimerButton
        function supprimerLED(app, event)
            [~, idx] = ismember(app.LEDsList.Value,app.LEDsList.Items);
            app.LEDsList.Items(idx)=[];

            app.adresseLED(idx)=[];
            app.typeLED(idx)= [];

        end

        % Value changed function: RougeSpinner
        function redcolor(app, event)
            red = app.RougeSpinner.Value; %valeur à envoyer
            [~, idx] = ismember(app.LEDsList.Value,app.LEDsList.Items); %récupération de la LED 
            for k=idx
                adresse = app.adresseLED(k);
                type = app.typeLED(k,:);
                port = adresse+findcanal(app,type,'R');
                if type ~= "Leuchtkraft"
                    message = strcat('a',sprintf('%03d',adresse),sprintf('001'))
                    writeline(app.s, message);
                    pause(0.3);
                end
                message = strcat('a',sprintf('%03d',port),sprintf('%03d',red))
                writeline(app.s, message);  
            end
%             adresse = app.LED(idx,1)
%             port = adresse+4;
%             message = strcat(sprintf('%03d',port),sprintf('%03d',red))
%             writeline(app.s, message);  

        end

        % Value changed function: VertSpinner
        function greencolor(app, event)
            green = app.VertSpinner.Value; %valeur à envoyer
            [~, idx] = ismember(app.LEDsList.Value,app.LEDsList.Items); %récupération de la LED 
            for k=idx
                adresse = app.adresseLED(k);
                type = app.typeLED(k,:);
                port = adresse+findcanal(app,type,'V');
                if type ~= "Leuchtkraft"
                    message = strcat('a',sprintf('%03d',adresse),sprintf('001'))
                    writeline(app.s, message);
                    pause(0.3);
                end
                message = strcat('a',sprintf('%03d',port),sprintf('%03d',green))
                writeline(app.s, message);  
            end

        end

        % Value changed function: BleuSpinner
        function bluecolor(app, event)
            blue = app.BleuSpinner.Value; %valeur à envoyer
            [~, idx] = ismember(app.LEDsList.Value,app.LEDsList.Items); %récupération de la LED 
            for k=idx
                adresse = app.adresseLED(k);
                type = app.typeLED(k,:);
                port = adresse+findcanal(app,type,'B');
                if type ~= "Leuchtkraft"
                    message = strcat('a',sprintf('%03d',adresse),sprintf('001'))
                    writeline(app.s, message);
                    pause(0.3);
                end
                message = strcat('a',sprintf('%03d',port),sprintf('%03d',blue))
                writeline(app.s, message);  
            end

        end

        % Button pushed function: Refresh
        function rafraichirpush(app, event)
            app.PortList.Items = serialportlist("available");
        end

        % Button pushed function: ConnectionButton
        function connectionpush(app, event)
            % on connect open serial port, start timer and change lamp color to green

            if not(app.is_connected)
                try
                    app.s = serialport(app.PortList.Value, 115200);
                    configureTerminator(app.s, "CR/LF");
                    %configureCallback(app.s, "terminator", @app.boardCommIT);
                catch
                    warning('Problem using serial.');
                end
                flush(app.s);
                app.is_connected = true;
                app.Refresh.Enable = false;
                drawnow;
                app.ConnLamp.Color = app.GREEN_COLOR; 
                app.ConnectionButton.Text = 'Déconnexion';
            else
                delete(app.s);
                app.is_connected = false;
                app.Refresh.Enable = true;
                drawnow;
                app.ConnLamp.Color = app.RED_COLOR;
                app.ConnectionButton.Text = 'Connexion';
              
            end

        end

        % Value changed function: IntensitSpinner
        function Intensite(app, event)
            intensite = app.IntensitSpinner.Value;
            [~, idx] = ismember(app.LEDsList.Value,app.LEDsList.Items); %récupération de la LED 
            for k=idx
                adresse = app.adresseLED(k);
                type = app.typeLED(k,:);
                port = adresse+findcanal(app,type,'I');
                if type ~= "Leuchtkraft"
                    message = strcat('a',sprintf('%03d',adresse),sprintf('001'))
                    writeline(app.s, message);
                    pause(0.3);
                end
               
                message = strcat('a',sprintf('%03d',port),sprintf('%03d',intensite))
                writeline(app.s, message); 
            end
        end

        % Value changed function: TiltSpinner
        function tilt1(app, event)
            tilt1 = app.TiltSpinner.Value;
            [~, idx] = ismember(app.LEDsList.Value,app.LEDsList.Items); %récupération de la LED 
            for k=idx
                adresse = app.adresseLED(k);
                type = app.typeLED(k,:);
                port = adresse+findcanal(app,type,'T');
                message = strcat('a',sprintf('%03d',port),sprintf('%03d',tilt1))
                writeline(app.s, message); 
            end
        end

        % Value changed function: VitesseSpinner
        function vitesse(app, event)
            vitesse = app.VitesseSpinner.Value;
            [~, idx] = ismember(app.LEDsList.Value,app.LEDsList.Items); %récupération de la LED 
            for k=idx
                adresse = app.adresseLED(k);
                type = app.typeLED(k,:);
                port = adresse+findcanal(app,type,'S');
                message = strcat('a',sprintf('%03d',port),sprintf('%03d',vitesse))
                writeline(app.s, message); 
            end
        end

        % Value changed function: PanSpinner
        function Pan(app, event)
            pan = app.PanSpinner.Value;
            [~, idx] = ismember(app.LEDsList.Value,app.LEDsList.Items); %récupération de la LED 
            for k=idx
                adresse = app.adresseLED(k);
                type = app.typeLED(k,:);
                port = adresse+findcanal(app,type,'P');
                message = strcat('a',sprintf('%03d',port),sprintf('%03d',pan))
                writeline(app.s, message); 
            end
        end

        % Value changed function: BlancSpinner
        function blanc(app, event)
            blanc = app.BlancSpinner.Value;
            [~, idx] = ismember(app.LEDsList.Value,app.LEDsList.Items); %récupération de la LED 
            for k=idx
                adresse = app.adresseLED(k);
                type = app.typeLED(k,:);
                port = adresse+findcanal(app,type,'W');
                message = strcat('a',sprintf('%03d',port),sprintf('%03d',blanc))
                writeline(app.s, message); 
            end
        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 640 480];
            app.UIFigure.Name = 'MATLAB App';

            % Create TabGroup
            app.TabGroup = uitabgroup(app.UIFigure);
            app.TabGroup.Position = [206 29 415 427];

            % Create DfinitionsdesLEDsTab
            app.DfinitionsdesLEDsTab = uitab(app.TabGroup);
            app.DfinitionsdesLEDsTab.Title = 'Définitions des LEDs';

            % Create AdresseLabel
            app.AdresseLabel = uilabel(app.DfinitionsdesLEDsTab);
            app.AdresseLabel.HorizontalAlignment = 'center';
            app.AdresseLabel.Position = [20 299 50 22];
            app.AdresseLabel.Text = 'Adresse';

            % Create AdresseLED
            app.AdresseLED = uieditfield(app.DfinitionsdesLEDsTab, 'numeric');
            app.AdresseLED.Position = [93 299 300 22];

            % Create NomEditFieldLabel
            app.NomEditFieldLabel = uilabel(app.DfinitionsdesLEDsTab);
            app.NomEditFieldLabel.HorizontalAlignment = 'right';
            app.NomEditFieldLabel.Position = [22 331 34 22];
            app.NomEditFieldLabel.Text = 'Nom ';

            % Create NomLED
            app.NomLED = uieditfield(app.DfinitionsdesLEDsTab, 'text');
            app.NomLED.Position = [93 331 300 22];

            % Create AjouterLEDsButton
            app.AjouterLEDsButton = uibutton(app.DfinitionsdesLEDsTab, 'push');
            app.AjouterLEDsButton.ButtonPushedFcn = createCallbackFcn(app, @AddLED, true);
            app.AjouterLEDsButton.Position = [39 176 135 53];
            app.AjouterLEDsButton.Text = 'Ajouter LEDs';

            % Create SupprimerButton
            app.SupprimerButton = uibutton(app.DfinitionsdesLEDsTab, 'push');
            app.SupprimerButton.ButtonPushedFcn = createCallbackFcn(app, @supprimerLED, true);
            app.SupprimerButton.Position = [226 176 122 53];
            app.SupprimerButton.Text = 'Supprimer';

            % Create TypedeLEDDropDownLabel
            app.TypedeLEDDropDownLabel = uilabel(app.DfinitionsdesLEDsTab);
            app.TypedeLEDDropDownLabel.HorizontalAlignment = 'center';
            app.TypedeLEDDropDownLabel.Position = [11 269 86 22];
            app.TypedeLEDDropDownLabel.Text = 'Type de LED';

            % Create TypedeLED
            app.TypedeLED = uidropdown(app.DfinitionsdesLEDsTab);
            app.TypedeLED.Items = {'Eurolite000', 'Renkforce00', 'Leuchtkraft'};
            app.TypedeLED.Position = [93 269 300 22];
            app.TypedeLED.Value = 'Eurolite000';

            % Create ParamtragesdesLEDsTab
            app.ParamtragesdesLEDsTab = uitab(app.TabGroup);
            app.ParamtragesdesLEDsTab.Title = 'Paramétrages des LEDs';

            % Create IntensitSpinnerLabel
            app.IntensitSpinnerLabel = uilabel(app.ParamtragesdesLEDsTab);
            app.IntensitSpinnerLabel.HorizontalAlignment = 'right';
            app.IntensitSpinnerLabel.Position = [20 350 51 22];
            app.IntensitSpinnerLabel.Text = 'Intensité';

            % Create IntensitSpinner
            app.IntensitSpinner = uispinner(app.ParamtragesdesLEDsTab);
            app.IntensitSpinner.Limits = [0 255];
            app.IntensitSpinner.ValueChangedFcn = createCallbackFcn(app, @Intensite, true);
            app.IntensitSpinner.Position = [86 350 285 22];

            % Create CouleurPanel
            app.CouleurPanel = uipanel(app.ParamtragesdesLEDsTab);
            app.CouleurPanel.Title = 'Couleur';
            app.CouleurPanel.Position = [21 176 372 155];

            % Create RougeSpinnerLabel
            app.RougeSpinnerLabel = uilabel(app.CouleurPanel);
            app.RougeSpinnerLabel.HorizontalAlignment = 'right';
            app.RougeSpinnerLabel.Position = [8 104 41 22];
            app.RougeSpinnerLabel.Text = 'Rouge';

            % Create RougeSpinner
            app.RougeSpinner = uispinner(app.CouleurPanel);
            app.RougeSpinner.Limits = [0 255];
            app.RougeSpinner.ValueChangedFcn = createCallbackFcn(app, @redcolor, true);
            app.RougeSpinner.Position = [64 104 285 22];

            % Create VertSpinnerLabel
            app.VertSpinnerLabel = uilabel(app.CouleurPanel);
            app.VertSpinnerLabel.HorizontalAlignment = 'center';
            app.VertSpinnerLabel.Position = [8 72 41 22];
            app.VertSpinnerLabel.Text = 'Vert';

            % Create VertSpinner
            app.VertSpinner = uispinner(app.CouleurPanel);
            app.VertSpinner.Limits = [0 255];
            app.VertSpinner.ValueChangedFcn = createCallbackFcn(app, @greencolor, true);
            app.VertSpinner.Position = [64 72 285 22];

            % Create BleuSpinnerLabel
            app.BleuSpinnerLabel = uilabel(app.CouleurPanel);
            app.BleuSpinnerLabel.HorizontalAlignment = 'center';
            app.BleuSpinnerLabel.Position = [14 43 30 22];
            app.BleuSpinnerLabel.Text = 'Bleu';

            % Create BleuSpinner
            app.BleuSpinner = uispinner(app.CouleurPanel);
            app.BleuSpinner.Limits = [0 255];
            app.BleuSpinner.ValueChangedFcn = createCallbackFcn(app, @bluecolor, true);
            app.BleuSpinner.Position = [64 43 285 22];

            % Create BlancSpinnerLabel
            app.BlancSpinnerLabel = uilabel(app.CouleurPanel);
            app.BlancSpinnerLabel.HorizontalAlignment = 'center';
            app.BlancSpinnerLabel.Position = [11 15 36 22];
            app.BlancSpinnerLabel.Text = 'Blanc';

            % Create BlancSpinner
            app.BlancSpinner = uispinner(app.CouleurPanel);
            app.BlancSpinner.Limits = [0 255];
            app.BlancSpinner.ValueChangedFcn = createCallbackFcn(app, @blanc, true);
            app.BlancSpinner.Position = [64 15 285 22];

            % Create RotationPanel
            app.RotationPanel = uipanel(app.ParamtragesdesLEDsTab);
            app.RotationPanel.Title = 'Rotation';
            app.RotationPanel.Position = [22 16 372 139];

            % Create TiltSpinnerLabel
            app.TiltSpinnerLabel = uilabel(app.RotationPanel);
            app.TiltSpinnerLabel.HorizontalAlignment = 'center';
            app.TiltSpinnerLabel.Position = [20 88 25 22];
            app.TiltSpinnerLabel.Text = 'Tilt';

            % Create TiltSpinner
            app.TiltSpinner = uispinner(app.RotationPanel);
            app.TiltSpinner.Limits = [0 255];
            app.TiltSpinner.ValueChangedFcn = createCallbackFcn(app, @tilt1, true);
            app.TiltSpinner.Position = [64 88 285 22];

            % Create PanSpinnerLabel
            app.PanSpinnerLabel = uilabel(app.RotationPanel);
            app.PanSpinnerLabel.HorizontalAlignment = 'center';
            app.PanSpinnerLabel.Position = [13 56 41 22];
            app.PanSpinnerLabel.Text = 'Pan';

            % Create PanSpinner
            app.PanSpinner = uispinner(app.RotationPanel);
            app.PanSpinner.Limits = [0 255];
            app.PanSpinner.ValueChangedFcn = createCallbackFcn(app, @Pan, true);
            app.PanSpinner.Position = [64 56 285 22];

            % Create VitesseSpinnerLabel
            app.VitesseSpinnerLabel = uilabel(app.RotationPanel);
            app.VitesseSpinnerLabel.HorizontalAlignment = 'center';
            app.VitesseSpinnerLabel.Position = [11 25 45 22];
            app.VitesseSpinnerLabel.Text = 'Vitesse';

            % Create VitesseSpinner
            app.VitesseSpinner = uispinner(app.RotationPanel);
            app.VitesseSpinner.Limits = [0 255];
            app.VitesseSpinner.ValueChangedFcn = createCallbackFcn(app, @vitesse, true);
            app.VitesseSpinner.Position = [64 25 285 22];

            % Create SquencesTab
            app.SquencesTab = uitab(app.TabGroup);
            app.SquencesTab.Title = 'Séquences';

            % Create BOUQUETFINALLabel
            app.BOUQUETFINALLabel = uilabel(app.SquencesTab);
            app.BOUQUETFINALLabel.HorizontalAlignment = 'center';
            app.BOUQUETFINALLabel.Position = [99 105 263 227];
            app.BOUQUETFINALLabel.Text = 'BOUQUET FINAL';

            % Create LEDsLabel
            app.LEDsLabel = uilabel(app.UIFigure);
            app.LEDsLabel.HorizontalAlignment = 'center';
            app.LEDsLabel.FontSize = 15;
            app.LEDsLabel.FontWeight = 'bold';
            app.LEDsLabel.Position = [20 328 163 22];
            app.LEDsLabel.Text = 'LEDs';

            % Create LEDsList
            app.LEDsList = uilistbox(app.UIFigure);
            app.LEDsList.Items = {};
            app.LEDsList.Position = [20 30 163 299];
            app.LEDsList.Value = {};

            % Create ConnexionNucloPanel
            app.ConnexionNucloPanel = uipanel(app.UIFigure);
            app.ConnexionNucloPanel.AutoResizeChildren = 'off';
            app.ConnexionNucloPanel.Title = 'Connexion Nucléo';
            app.ConnexionNucloPanel.BackgroundColor = [0.6784 0.8314 0.9529];
            app.ConnexionNucloPanel.Position = [6 349 189 93];

            % Create GridLayout11
            app.GridLayout11 = uigridlayout(app.ConnexionNucloPanel);
            app.GridLayout11.ColumnWidth = {'1x', '3x'};
            app.GridLayout11.Padding = [5 5 5 5];

            % Create Refresh
            app.Refresh = uibutton(app.GridLayout11, 'push');
            app.Refresh.ButtonPushedFcn = createCallbackFcn(app, @rafraichirpush, true);
            app.Refresh.BackgroundColor = [0.3961 0.6039 0.7412];
            app.Refresh.Layout.Row = 2;
            app.Refresh.Layout.Column = [1 2];
            app.Refresh.Text = 'Rafraichir';

            % Create PortLabel
            app.PortLabel = uilabel(app.GridLayout11);
            app.PortLabel.HorizontalAlignment = 'center';
            app.PortLabel.Layout.Row = 1;
            app.PortLabel.Layout.Column = 1;
            app.PortLabel.Text = 'Port';

            % Create PortList
            app.PortList = uidropdown(app.GridLayout11);
            app.PortList.Items = {'COM?'};
            app.PortList.Editable = 'on';
            app.PortList.BackgroundColor = [0.9373 0.9529 0.9608];
            app.PortList.Layout.Row = 1;
            app.PortList.Layout.Column = 2;
            app.PortList.Value = 'COM?';

            % Create ConnectionButton
            app.ConnectionButton = uibutton(app.UIFigure, 'push');
            app.ConnectionButton.ButtonPushedFcn = createCallbackFcn(app, @connectionpush, true);
            app.ConnectionButton.BackgroundColor = [0.3961 0.6039 0.7412];
            app.ConnectionButton.Position = [53 452 73 20];
            app.ConnectionButton.Text = 'Connection';

            % Create ConnLamp
            app.ConnLamp = uilamp(app.UIFigure);
            app.ConnLamp.Position = [12 452 20 20];
            app.ConnLamp.Color = [1 0 0];

            % Create AideButton
            app.AideButton = uibutton(app.UIFigure, 'push');
            app.AideButton.BackgroundColor = [0.3961 0.6039 0.7412];
            app.AideButton.Position = [141 452 42 20];
            app.AideButton.Text = 'Aide';

            % 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 = Prototypeinterfacederneriereversion

            % Create UIFigure and components
            createComponents(app)

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

            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