[Solved] fixationDataStream.Next without Console.ReadKey ?

Home Forums Software Development [Solved] fixationDataStream.Next without Console.ReadKey ?

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #7117
    Dominic Potts
    Participant

    Hi, I’m just inquiring about the functionality of some of the sample code on the Tobii github.

    Is it possible to run: fixationDataStream.Next += (o, fixation) =>
    and print out fixation begin, end and duration coordinates until a certain condition is met, rather than using Console.ReadKey() to disconnect from the host?

    link: https://github.com/Tobii/CoreSDK/blob/master/samples/Streams/Interaction_Streams_102/Program.cs

    Thanks,
    Dom

    #7121
    Grant [Tobii]
    Keymaster

    Hi @dom202, as you can see in the sample code, the fixation information such as begin, end and duration is already included in the output text. Naturally, you can comment out the readkey function as use a different means to break. Perhaps the documentation describing the use of Activatable interactor @ https://tobii.github.io/CoreSDK/articles/interactors.html whereby a function is called when the user gazes at the area associated with the interactor and simultaneously presses a key on the keyboard would be useful for your needs?

    If you could kindly be more specific in your needs regarding the ‘certain condition’, we will try to find you the appropriate solution.

    #7123
    Dominic Potts
    Participant

    Hi Grant, Thank you for the prompt response and apologies for not being specific.

    The project I am working on is to do with so called ‘Information Foraging’ Theory, and involves dividing up a display’s content into ‘patches’ or blocks of a specified size that are then plotted onto the screen using the Tobii’s coordinates system. For example a 1080px display can be evenly divided up into 4 patches of size 960px X 540px (There are however multiple layouts)

    I have a function that signals when every patch has been ‘foraged’ (when a patch has been fixated on at least once) and this is the condition I am testing. While all patches have not been foraged I want to run code that is very similar to the fixationDataStream.Next += (o, fixation) => {…} function in the aforementioned sample. It simply prints to console the begin and end fixation coordinates as well as the fixation duration timestamp.

    I have all of this working perfectly, but I want to stop recording fixation once all patches have been ‘foraged’ automatically without the console.ReadKey().

    I have tried implementing the conditional without using the console.readkey(), but the code doesn’t run at all. I’ve also tried wrapping fixationDataStream.Next in a while loop, but this did not solve the issue.

    I will take a look at the documentation again, but if you have any advice it would be greatly appreciated!

    –Dom

    #7124
    Alex [Tobii]
    Participant

    Hi!

    You can use a while loop with Thread.Sleep(10) instead of Console.ReadKey(). Please make sure to set _stop to true when all of your zones are visited.

    
    	private static bool _stop = true;
    	public static void Main()
    	{
    		while (!_stop)
    		{
    			Thread.Sleep(10);
    		}
    	}
    
    #7126
    Dominic Potts
    Participant

    Hi Alex, Thank you for the response.

    I forgot to mention that within the fixationDataStream.Next += (o, fixation) => {…}
    section of my code I have some timers running to measure the time between user fixations. Simply sleeping the thread creates a race condition where all the threads are updating the timer simultaneously.

    I’ve read the documentation on the tobii github, but I was hoping that you could give me some insight into how this fixationDataStream.Next function works? Or perhaps an alternative to Thread.Sleep?

    I really appreciate your help with this.

    –Dom

    #7127
    Alex [Tobii]
    Participant

    fixationDataStream.Next is just a callback with lambda expression. You can transform it to process your callback in a function.

    #7128
    Dominic Potts
    Participant

    Hi Alex, your solution works fine. I was completely overthinking it!

    Thank you for all your help!

    –Dom

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.