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-filter-flash.lua 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. -- Picks out 'flashes' from a stimulation stream
  2. -- this function is called when the box is initialized
  3. function initialize(box)
  4. dofile(box:get_config("${Path_Data}") .. "/plugins/stimulation/lua-stimulator-stim-codes.lua")
  5. box:set_filter_mode(1);
  6. state = 0
  7. do_debug = false
  8. end
  9. -- this function is called when the box is uninitialized
  10. function uninitialize(box)
  11. end
  12. -- this function is called once by the box
  13. function process(box)
  14. -- loop until box:keep_processing() returns zero
  15. -- cpu will be released with a call to sleep
  16. -- at the end of the loop
  17. while box:keep_processing() do
  18. -- gets current simulated time
  19. t = box:get_current_time()
  20. -- loops on every received stimulation for a given input
  21. for stimulation = 1, box:get_stimulation_count(1) do
  22. -- gets stimulation
  23. stimulation_id, stimulation_time, stimulation_duration = box:get_stimulation(1, 1)
  24. if stimulation_id == OVTK_StimulationId_SegmentStart then
  25. state = 1
  26. elseif stimulation_id == OVTK_StimulationId_SegmentStop then
  27. state = 0
  28. end
  29. -- If we're between 'rest start' and 'rest_stop', this specifies a target
  30. if state == 1 and stimulation_id >= OVTK_StimulationId_LabelStart and stimulation_id <= OVTK_StimulationId_LabelEnd then
  31. box:send_stimulation(1, stimulation_id, stimulation_time, 0)
  32. if do_debug then
  33. box:log("Info", string.format("Push a target %d at %f (now %f)", stimulation_id, stimulation_time, t))
  34. end
  35. end
  36. -- discards it
  37. box:remove_stimulation(1, 1)
  38. end
  39. -- releases cpu
  40. box:sleep()
  41. end
  42. end