You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

p300-tactile-target.lua 1.5KB

2 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. -- This Lua script generates target stimulations the 1x6 p300-tactile matrix
  2. --
  3. -- Author : Tobias Baumann
  4. -- Date : 2021-06-09
  5. -- this function is called when the box is initialized
  6. function initialize(box)
  7. dofile(box:get_config("${Path_Data}") .. "/plugins/stimulation/lua-stimulator-stim-codes.lua")
  8. math.randomseed(os.time())
  9. row_base = _G[box:get_setting(2)]
  10. col_base = _G[box:get_setting(3)]
  11. delay = box:get_setting(4)
  12. end
  13. -- this function is called when the box is uninitialized
  14. function uninitialize(box)
  15. end
  16. -- this function is called once by the box
  17. function process(box)
  18. -- loop until box:keep_processing() returns zero
  19. -- cpu will be released with a call to sleep
  20. -- at the end of the loop
  21. while box:keep_processing() do
  22. -- gets current simulated time
  23. t = box:get_current_time()
  24. -- loops on every received stimulation for a given input
  25. for stimulation = 1, box:get_stimulation_count(1) do
  26. -- gets stimulation
  27. stimulation_id, stimulation_time, stimulation_duration = box:get_stimulation(1, 1)
  28. if stimulation_id == OVTK_StimulationId_RestStart then
  29. -- triggers the target
  30. box:send_stimulation(1, row_base+math.random(1,6)-1, t+delay, 0)
  31. box:send_stimulation(1, col_base, t+delay, 0)
  32. elseif stimulation_id == OVTK_StimulationId_ExperimentStop then
  33. -- triggers train stimulation
  34. box:send_stimulation(1, OVTK_StimulationId_Train, t+delay+1, 0)
  35. end
  36. -- discards it
  37. box:remove_stimulation(1, 1)
  38. end
  39. -- releases cpu
  40. box:sleep()
  41. end
  42. end