function SDCardLogging_UICallback(hObj, hDlg, tag, ~) 
%SDCARDLOGGING_UICALLBACK Callback for SD Card Logging widget changes

% Copyright 2019 The MathWorks, Inc.
hCS = hObj.getConfigSet;
newVal = hDlg.getWidgetValue(tag);
hCS.setPropEnabled('MatFileLogging',true);
if newVal == 1
    set_param(hCS, 'MatFileLogging', 'on');
    
    % Disable SaveState and SaveFinalState for SD card logging as it is not
    % part of memory estimation script
    set_param(hCS, 'SaveState', 'off');
    hCS.setPropEnabled('SaveState',false);
    set_param(hCS, 'SaveFinalState', 'off');
    hCS.setPropEnabled('SaveFinalState',false);
else
    set_param(hCS, 'MatFileLogging', 'off');
    hCS.setPropEnabled('SaveState',true);
    hCS.setPropEnabled('SaveFinalState',true);
end
hCS.setPropEnabled('MatFileLogging',false);
codertarget.data.setParameterValue(hCS, 'SDCard.Enable', newVal);
hCS.refreshDialog;
end