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.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. if box:get_setting(5) == 'true' then
  13. free_spelling = true
  14. else
  15. free_spelling = false
  16. end
  17. end
  18. -- this function is called when the box is uninitialized
  19. function uninitialize(box)
  20. end
  21. -- this function is called once by the box
  22. function process(box)
  23. -- loop until box:keep_processing() returns zero
  24. -- cpu will be released with a call to sleep
  25. -- at the end of the loop
  26. while box:keep_processing() do
  27. -- gets current simulated time
  28. t = box:get_current_time()
  29. -- loops on every received stimulation for a given input
  30. for stimulation = 1, box:get_stimulation_count(1) do
  31. -- gets stimulation
  32. stimulation_id, stimulation_time, stimulation_duration = box:get_stimulation(1, 1)
  33. if not free_spelling then
  34. if stimulation_id == OVTK_StimulationId_RestStart then
  35. -- triggers the target
  36. box:send_stimulation(1, row_base+math.random(1,6)-1, t+delay, 0)
  37. box:send_stimulation(1, col_base, t+delay, 0)
  38. elseif stimulation_id == OVTK_StimulationId_ExperimentStop then
  39. -- triggers train stimulation
  40. box:send_stimulation(1, OVTK_StimulationId_Train, t+delay+1, 0)
  41. end
  42. end
  43. -- discards it
  44. box:remove_stimulation(1, 1)
  45. end
  46. -- releases cpu
  47. box:sleep()
  48. end
  49. end