JA_check_hands_Warming_Up.m 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. function [sens, Par] = JA_check_hands_Warming_Up(Par,s)
  2. % it checks that before the onset of the trial sensors sense enough pressure
  3. % threshold to be exceeded
  4. threshold = 50;
  5. % washout what's in the serial port
  6. scrittura(s);
  7. [~, ifi_as] = JA_frames_function(1, Par.ifi);
  8. initial_test = 0.5; %secs
  9. t = 0;
  10. tic;
  11. while t <= initial_test
  12. t = toc;
  13. % check if after 0.5 s the sensors are fine --> if so exit the function
  14. [sens] = JA_inside_fun_READ_WRITE();
  15. end
  16. % if any sensor does not sense enough pressure
  17. if sens.SBJ_DCG < threshold...
  18. || sens.SBJ_RISP < threshold
  19. while 1 % run the while loop until all the sensors sense pressure above threshold for 3 consecutive seconds
  20. % ask PTP and CF to put fingers on sensors by printing it on
  21. % the screen
  22. JA_inside_fun_FINGER_ON_SENSORS('Dita sui sensori!:-)')
  23. % wait 1 second
  24. WaitSecs(1.0);
  25. % check sensors again
  26. [sens] = JA_inside_fun_READ_WRITE();
  27. % if any of the sensors still do not feel enough pressure
  28. if sens.SBJ_DCG < threshold || sens.SBJ_RISP < threshold
  29. % go back to the while loop
  30. disp('not enough')
  31. continue
  32. else % in case all sense enough pressure --> start count down of 3 seconds
  33. [sens] = JA_inside_fun_FOR_CYCLE_COUNT_DOWN();
  34. disp('out of for cycle')
  35. % if the for loop ends --> sensors sensed enough pressure
  36. % --> return
  37. end
  38. disp('control last sensor cheking')
  39. if sens.SBJ_DCG > threshold...
  40. && sens.SBJ_RISP > threshold
  41. % if the cycle inside JA_inside_fun_FOR_CYCLE_COUNT_DOWNend well, exit function
  42. disp('great!')
  43. return
  44. else
  45. disp('not_enough...do it again')
  46. end
  47. end
  48. % fi the while loop spits enough pressure on sensors
  49. % recorded on a period of 0.5 seconds
  50. % exit the function providing sensor values as output
  51. end
  52. %end
  53. disp('good initial conditions')
  54. %JA_ready_screen()
  55. return % if initial conditions are good, exit function
  56. function [sens] = JA_inside_fun_READ_WRITE()
  57. % get baseline pressure
  58. tmp_value = scrittura(s);
  59. % slpit the 3 values that are read from the three pins in arduino
  60. tmp2 = (strsplit(tmp_value, '_'));
  61. % assign each value to the correct object (the SBJ_DCG is needed to check participnats' engagement effect)
  62. bs = str2double(tmp2);
  63. sens.CF = bs(1); % sensor used by CF to
  64. sens.SBJ_DCG = bs(2);
  65. sens.SBJ_RISP = bs(3);
  66. end
  67. function [] = JA_inside_fun_COUNT_DOWN(number)
  68. cd_num = num2str(number);
  69. % draw black 'hidden screen'
  70. Screen('FillRect', Par.window, [0 0 0], Par.screen_dimensions);
  71. % draw a count down starting from 3 on the hidden screen
  72. Screen('TextSize', Par.window, 80);
  73. DrawFormattedText(Par.window, cd_num, 'center',...
  74. 'center', [0 1 1]);
  75. [Par.VBL] = Screen(Par.window, 'Flip', Par.VBL+Par.ifi,1);
  76. end
  77. function [] = JA_inside_fun_FINGER_ON_SENSORS(text)
  78. %text = 'Dita sui sensori!:-)';
  79. % draw black background
  80. Screen('FillRect', Par.window, [0 0 0], Par.screen_dimensions);
  81. % set text size
  82. Screen('TextSize', Par.window, 80);
  83. % draw text 'fingers on the sensors!' on the 'hidden screen'
  84. DrawFormattedText(Par.window, text, 'center',...
  85. 'center', [0 1 1]);
  86. % flip the 'hidden screen' to the 'front screen'
  87. [Par.VBL] = Screen(Par.window, 'Flip', Par.VBL+ifi_as,1);
  88. end
  89. function [sens] = JA_inside_fun_FOR_CYCLE_COUNT_DOWN()
  90. for last_count = 3:-1:1
  91. % display count down
  92. JA_inside_fun_COUNT_DOWN(last_count)
  93. % check sensors --> are they still ok?
  94. [sens] = JA_inside_fun_READ_WRITE();
  95. % if any of them do not feel eonough pressure break the for
  96. % loop --> this will bring the script to the beginning of
  97. %the while loop
  98. if sens.SBJ_DCG < threshold...
  99. || sens.SBJ_RISP < threshold
  100. ...go back to the 'while loop' before the for loop
  101. disp('at least one sensor does not sense...go back to while');
  102. break
  103. end
  104. % wait before starting the next count
  105. WaitSecs(0.5);
  106. end
  107. end
  108. end