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

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