settingsManager.m 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. function varargout = settingsManager(varargin)
  2. % settingsManager
  3. %
  4. % Loads, maintains and saves the NPMK Settings File. For internal use only.
  5. %
  6. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  7. % Use settingsManager
  8. %
  9. % Use settingsFile = settingsManager(settingsFile)
  10. %
  11. % settingsFile: The settings variable passed to the function for
  12. % saving. If no input has been specified, the function
  13. % will load an existing file and pass it out to the
  14. % calling function. If a setting file does not exist, the
  15. % function will generate a file with defalt settings and
  16. % then will pass the variables to the calling function.
  17. %
  18. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  19. % Kian Torab
  20. % support@blackrockmicro.com
  21. % Blackrock Microsystems
  22. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  23. % Version History
  24. %
  25. % 1.0.0.0: August 13, 2020
  26. % - Initial release.
  27. %
  28. % 1.1.0.0: September 16, 2020
  29. % - Fixed a bug where the response to 1/4 uV warning was not being saved.
  30. %
  31. % Finding the correct settings file for this version of MATLAB
  32. fullPath = which('settingsManager.m');
  33. fullPath = [fullPath(1:end-17) 'settings.npmk'];
  34. % Does the file already exist?
  35. if exist(fullPath, 'file') == 2
  36. if length(varargin) == 0 % Load the settings file and send as output
  37. varargout{1} = load(fullPath, '-mat');
  38. try varargout{1}.checkeddate; catch varargout{1}.checkeddate = datetime; end
  39. try varargout{1}.ShowZeroPadWarning; catch varargout{1}.ShowZeroPadWarning = 1; end
  40. try varargout{1}.ShowuVWarning; catch varargout{1}.ShowuVWarning = 1; end
  41. elseif length(varargin) == 1
  42. checkeddate = varargin{1}.checkeddate;
  43. ShowZeroPadWarning = varargin{1}.ShowZeroPadWarning;
  44. ShowuVWarning = varargin{1}.ShowuVWarning;
  45. save(fullPath, 'checkeddate', 'ShowZeroPadWarning', 'ShowuVWarning'); % Save the settings file
  46. end
  47. else % Since it doesn't exist, create and save it.
  48. checkeddate = datetime;
  49. ShowZeroPadWarning = 1;
  50. save(fullPath, 'checkeddate', 'ShowZeroPadWarning');
  51. varargout{1} = load(fullPath, '-mat');
  52. end
  53. end % END of Function