classdef LCD_I2C < matlab.System ...
        & coder.ExternalDependency ...
        & matlabshared.sensors.simulink.internal.BlockSampleTime

    % Dieser Block implementiert die LCD Logik für den Kugel-Balancierer
    %#codegen
    %#ok<*EMCA>

    properties

    end

    properties(Access = protected)
        Logo = 'IO Device Builder';
    end

    properties (Nontunable)

    end

    properties (Access = private)


    end

    methods
        % Constructor
        function obj = LCD_I2C(varargin)
            setProperties(obj,nargin,varargin{:});
        end
    end

    methods (Access=protected)
        function setupImpl(obj)
            if ~coder.target('MATLAB')
                coder.cinclude('LCD_I2C.h');
                coder.ceval('setupFunctionLCD_I2C');
            end
        end

        function validateInputsImpl(obj,varargin)
            %  Check the input size
            if nargin ~=0

                validateattributes(varargin{1},{'double'},{'2d','size',[1,1]},'','Kp');
                validateattributes(varargin{2},{'double'},{'2d','size',[1,1]},'','Ki');
                validateattributes(varargin{3},{'double'},{'2d','size',[1,1]},'','Kd');
                validateattributes(varargin{4},{'double'},{'2d','size',[1,1]},'','Modus');
                validateattributes(varargin{5},{'double'},{'2d','size',[1,1]},'','Sollwert');
                validateattributes(varargin{6},{'logical'},{'2d','size',[1,1]},'','WIN');

            end
        end

        function stepImpl(obj ,Kp,Ki,Kd,Modus,Sollwert,WIN)

            if isempty(coder.target)
            else
                coder.ceval('stepFunctionLCD_I2C', Kp,1, Ki,1, Kd,1, Modus,1, Sollwert,1, WIN,1);
            end
        end

        function releaseImpl(obj)
            if isempty(coder.target)
            else

            end
        end
    end

    methods (Access=protected)
        %% Define output properties
        function num = getNumInputsImpl(~)
            num = 6;
        end

        function num = getNumOutputsImpl(~)
            num = 0;
        end

        function varargout = getInputNamesImpl(obj)
            varargout{1} = 'Kp';
            varargout{2} = 'Ki';
            varargout{3} = 'Kd';
            varargout{4} = 'Modus';
            varargout{5} = 'Sollwert';
            varargout{6} = 'WIN';

        end

        function varargout = getOutputNamesImpl(obj)

        end

        function flag = isOutputSizeLockedImpl(~,~)
            flag = true;
        end

        function varargout = isOutputFixedSizeImpl(~,~)

        end

        function varargout = isOutputComplexImpl(~)

        end

        function varargout = getOutputSizeImpl(~)

        end

        function varargout = getOutputDataTypeImpl(~)

        end

        function maskDisplayCmds = getMaskDisplayImpl(obj)
            outport_label = [];
            num = getNumOutputsImpl(obj);
            if num > 0
                outputs = cell(1,num);
                [outputs{1:num}] = getOutputNamesImpl(obj);
                for i = 1:num
                    outport_label = [outport_label 'port_label(''output'',' num2str(i) ',''' outputs{i} ''');' ]; %#ok<AGROW>
                end
            end
            inport_label = [];
            num = getNumInputsImpl(obj);
            if num > 0
                inputs = cell(1,num);
                [inputs{1:num}] = getInputNamesImpl(obj);
                for i = 1:num
                    inport_label = [inport_label 'port_label(''input'',' num2str(i) ',''' inputs{i} ''');' ]; %#ok<AGROW>
                end
            end
            icon = 'LCD_I2C';
            maskDisplayCmds = [ ...
                ['color(''white'');',...
                'plot([100,100,100,100]*1,[100,100,100,100]*1);',...
                'plot([100,100,100,100]*0,[100,100,100,100]*0);',...
                'color(''blue'');', ...
                ['text(38, 92, ','''',obj.Logo,'''',',''horizontalAlignment'', ''right'');',newline],...
                'color(''black'');'], ...
                ['text(52,50,' [''' ' icon ''',''horizontalAlignment'',''center'');' newline]]   ...
                inport_label ...
                outport_label
                ];
        end

        function sts = getSampleTimeImpl(obj)
            sts = getSampleTimeImpl@matlabshared.sensors.simulink.internal.BlockSampleTime(obj);
        end
    end

    methods (Static, Access=protected)
        function simMode = getSimulateUsingImpl(~)
            simMode = 'Interpreted execution';
        end

        function isVisible = showSimulateUsingImpl
            isVisible = false;
        end
    end

    methods (Static)
        function name = getDescriptiveName(~)
            name = 'LCD_I2C';
        end

        function tf = isSupportedContext(~)
            tf = true;
        end

        function updateBuildInfo(buildInfo, context)
            coder.extrinsic('codertarget.targethardware.getTargetHardware');
            hCS = coder.const(getActiveConfigSet(bdroot));
            targetInfo = coder.const(codertarget.targethardware.getTargetHardware(hCS));

            % Added this env variable to fetch the comm libraries required only for Arduino target.
            % The env variable is cleared at the end of
            % "GenerateWrapperMakefile.m" file.
            if contains(targetInfo.TargetName,'arduinotarget')
                setenv('Arduino_ML_Codegen_I2C', 'Y');
            end

            buildInfo.addIncludePaths('C:\Users\Daniel\Documents\Uni\BSE\BSE_Semester_2\Praktikum\SVN\194_Kugel-Balancierer\Matlab_Simulink\LCD\libs');

            buildInfo.addIncludePaths('C:\Users\Daniel\Documents\Uni\BSE\BSE_Semester_2\Praktikum\SVN\194_Kugel-Balancierer\Matlab_Simulink\LCD');
            addSourceFiles(buildInfo,'LiquidCrystal_I2C.cpp','C:\Users\Daniel\Documents\Uni\BSE\BSE_Semester_2\Praktikum\SVN\194_Kugel-Balancierer\Matlab_Simulink\LCD\libs');
            addSourceFiles(buildInfo,'LCD_I2C.cpp','C:\Users\Daniel\Documents\Uni\BSE\BSE_Semester_2\Praktikum\SVN\194_Kugel-Balancierer\Matlab_Simulink\LCD');

        end
    end
end
