File: AutoBrightness.m

package info (click to toggle)
psychtoolbox-3 3.0.19.14.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 86,796 kB
  • sloc: ansic: 176,245; cpp: 20,103; objc: 5,393; sh: 2,753; python: 1,397; php: 384; makefile: 193; java: 113
file content (48 lines) | stat: -rw-r--r-- 1,947 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
function [oldSetting, status] = AutoBrightness(screenNumber, newSetting)
% [oldSetting, status] = AutoBrightness([screenNumber=0][, newSetting])
%
% OBSOLETE: Use MacDisplaySettings instead. It's faster and more reliable.
% To support old programs we have rewritten this to simply call
% MacDisplaySettings. However, it's probably best to replace your call to
% AutoBrightness by your own call to MacDisplaySettings, using what's below
% as a model. If you need AutoBrightness you probably also need more of the
% controls offered by MacDisplaySettings.
%
% AUTOBRIGHTNESS. Get and set the "Automatically adjust brightness"
% checkbox on the Mac OS X: System Preferences: Displays panel. The
% function argument "newSetting" (integer 0 or 1) indicates whether you
% want to turn the autobrightness feature on (newSetting==1) or off
% (newSetting==0). If you call without an argument (or anything other than
% 0 or 1) then nothing is changed. The current state is always reported in
% the returned oldSetting (0 or 1). The optionally returned "status" is
% always zero unless the applescript failed.
%
% HISTORY: Written by denis.pelli@nyu.edu for the Psychtoolbox, May 21,
% 2015. Incorporated into MATLAB adding untested code to specify which
% screen, by Mario Kleiner, June 1. Convert return argument from string to
% double, by Denis, June 11, 2015. Replaced by a call to the new
% MacDisplaySettings (as suggested by Mario) Denis Pelli, May 6, 2020.
%
% See also:
% MacDisplaySettings.m
% May 6, 2020, denis.pelli@nyu.edu

if ~IsOSX
    oldSetting = 0;
    status = 1; % Signal failure on this unsupported OS.
    return
end
if nargin<1
    screenNumber=0;
end
if nargin<2
    newSetting=[];
end
newSettings.automatically=newSetting;
[oldSettings,errorMessage]=MacDisplaySettings(screenNumber,newSettings);
oldSetting=oldSettings.automatically;
if ~isempty(errorMessage)
    warning('%s',errorMessage);
end
status=~isempty(errorMessage);
end