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-speller-target.lua 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. -- This Lua script generates target stimulations for the P300 visualization
  2. -- box based on the matrix of letters / numbers a P300 speller has
  3. --
  4. -- Author : Yann Renard, INRIA
  5. -- Date : 2011-03-15
  6. grid =
  7. {
  8. { 'a', 'b', 'c', 'd', 'e', 'f' },
  9. { 'g', 'h', 'i', 'j', 'k', 'l' },
  10. { 'm', 'n', 'o', 'p', 'q', 'r' },
  11. { 's', 't', 'u', 'v', 'w', 'x' },
  12. { 'y', 'z', '1', '2', '3', '4' },
  13. { '5', '6', '7', '8', '9', '0' },
  14. }
  15. index = 0
  16. function get_location(c)
  17. for i = 1, 6 do
  18. for j = 1, 6 do
  19. if grid[i][j] == c then
  20. return i, j
  21. end
  22. end
  23. end
  24. return 0, 0
  25. end
  26. -- this function is called when the box is initialized
  27. function initialize(box)
  28. dofile(box:get_config("${Path_Data}") .. "/plugins/stimulation/lua-stimulator-stim-codes.lua")
  29. math.randomseed(os.time())
  30. target = box:get_setting(2)
  31. row_base = _G[box:get_setting(3)]
  32. col_base = _G[box:get_setting(4)]
  33. delay = box:get_setting(5)
  34. if target == "" then
  35. for i = 1, 1000 do
  36. a = math.random(1, #grid)
  37. b = math.random(1, #grid[1])
  38. target = target .. grid[a][b]
  39. end
  40. end
  41. end
  42. -- this function is called when the box is uninitialized
  43. function uninitialize(box)
  44. end
  45. -- this function is called once by the box
  46. function process(box)
  47. -- loop until box:keep_processing() returns zero
  48. -- cpu will be released with a call to sleep
  49. -- at the end of the loop
  50. while box:keep_processing() do
  51. -- gets current simulated time
  52. t = box:get_current_time()
  53. -- loops on every received stimulation for a given input
  54. for stimulation = 1, box:get_stimulation_count(1) do
  55. -- gets stimulation
  56. stimulation_id, stimulation_time, stimulation_duration = box:get_stimulation(1, 1)
  57. if stimulation_id == OVTK_StimulationId_RestStart then
  58. -- finds a new target
  59. index = index + 1
  60. r, c = get_location(string.sub(target, index, index))
  61. -- triggers the target
  62. box:send_stimulation(1, row_base+r-1, t+delay, 0)
  63. box:send_stimulation(1, col_base+c-1, t+delay, 0)
  64. elseif stimulation_id == OVTK_StimulationId_ExperimentStop then
  65. -- triggers train stimulation
  66. box:send_stimulation(1, OVTK_StimulationId_Train, t+delay+1, 0)
  67. end
  68. -- discards it
  69. box:remove_stimulation(1, 1)
  70. end
  71. -- releases cpu
  72. box:sleep()
  73. end
  74. end