%_______________________________________________________________________
%
% Configuration for running dotsExperiment
%_______________________________________________________________________
%
% Output
%
% dotInfo | configuration for random dots experiment (struct)
%_______________________________________________________________________
%
function dotInfo = createDotInfo_JQK_170113

  dotInfo.introNumTrial = 10; % number of introduction trials per mode  
  dotInfo.numBlock = 2; % mini mini blocks per condition
  dotInfo.condTime = 540; % condition duration in seconds
  dotInfo.blockTime = dotInfo.condTime / dotInfo.numBlock; % block duration in seconds
  dotInfo.breakTime = 45; % break after blocks in seconds
  dotInfo.winSize = 4; % number of trials for short-term average accuracy
  dotInfo.longWinSize = 8; % number of trials for mid-term average accuracy
  dotInfo.minCoh = 0; % minimum coherence value
  dotInfo.maxCoh = 800; %  maximum coherence value
  dotInfo.coh = 800; % coherence starting value for introduction
  dotInfo.targetAcc = 0.75; % targeted average accuracy for task
  dotInfo.dirSet = [180, 0]; % dots in left or right direction
  dotInfo.numDotField = 1; % show a single dot patches on screen
  dotInfo.apXYD = [0 0 100]; % coordinates and diameter of aperture
  dotInfo.speed = [50]; % speed of dot motion
  dotInfo.trialtype = [2 1 1]; % reaction time, not relevant, keyboard
  dotInfo.dotSize = 5; % dot size in pixels
  dotInfo.maxDotTime = 2; % maximum duration of moving dots
  dotInfo.fixXY = [0 0]; % fixation coordinates
  dotInfo.fixDiam = 2; % fixation diameter
  dotInfo.fixColor = [255 0 0]; % red fixation dot
  dotInfo.fixMinTime = 0.75; % minimum fixation
  dotInfo.fixMaxTime = 1.25; % maximum fixation
  dotInfo.maxDotsPerFrame = 150; % depends on graphics card
  
  % Use OS X keyboard naming scheme across all plattforms
  % Otherwise LeftControl/RightControl are not recognized
  KbName('UnifyKeyNames');
  
  if ismac % Mac keyboard
    dotInfo.keyLeft = KbName('LeftGUI'); % left cmd when dots moving to left
    dotInfo.keyRight = KbName('RightGUI'); % right cmd when dots moving to right
  else % PC keyboard
    dotInfo.keyLeft = KbName('LeftControl'); % left ctrl when dots moving to left
    dotInfo.keyRight = KbName('RightControl'); % right ctrl when dots moving to right
  end
  
  dotInfo.keyModifier = KbName('LeftAlt'); % to prevent accidental input
  dotInfo.keyEscape = KbName('Escape'); % exit experiment
  dotInfo.keyReturn = KbName('Return'); % continue experiment
  
  %% JQK additions for continuous paradigm
  
    % fixed, random timing for RDM blocks

    % let's also fix coherence for now (e.g. Kelly & O'Connell, 2014)
    % 6 of each direction-coherence level

    dotInfo.cohLevels = [0.25, 0.35, 0.5, 0.7];
    dotInfo.directions = [0 180]; % 1 - left, 2 - right

    % TO DO: set random seed

    distrib = repmat([1:8],1,6);
    tmp_rand = randperm(numel(distrib));
    distrib_rand = distrib(tmp_rand);

    dotInfo.coh = NaN(1,numel(distrib_rand));
    dotInfo.dir = NaN(1,numel(distrib_rand));
    for indDis = 1:8
        if indDis <= 4
            indDir = 1;
            indCoh = indDis;
        else
            indDir = 2;
            indCoh = indDis-4;
        end;
        curDis = find(distrib_rand==indDis);
        dotInfo.coh(curDis) = dotInfo.cohLevels(indCoh);
        dotInfo.dir(curDis) = dotInfo.directions(indDir);
    end;

    dotInfo.timeTarget = 1.9; % target time in s
    dotInfo.timeNontarget = [3.6, 6.6, 8.4]; % target time in s

    tmp = []; tmp2 = [];
    for indCoh = 1:numel(dotInfo.coh)
        tmp = [tmp, 0, dotInfo.coh(indCoh)];
        tmp2 = [tmp2, NaN, dotInfo.dir(indCoh)];
    end;
    % tmp = [tmp, 0];
    % tmp2 = [tmp2, NaN];

    dotInfo.coh = tmp;
    dotInfo.dir = tmp2;

    nonTargets = find(dotInfo.coh == 0);
    Targets = find(dotInfo.coh ~= 0);

    nontargetDur = repmat([1:3], 1, 16); % create vector for non-target duration
    tmp_rand = randperm(numel(nontargetDur));
    targetDur_rand = nontargetDur(tmp_rand);

    dotInfo.presTime = NaN(1,numel(dotInfo.coh));
    dotInfo.presTime(nonTargets) = dotInfo.timeNontarget(targetDur_rand);
    dotInfo.presTime(Targets) = dotInfo.timeTarget;

end
