OpenBCI / OpenBCI_Cyton_Library

Repository for OpenBCI Cyton Arduino Libraries
MIT License
88 stars 89 forks source link

Logic error on first sample with daisy #42

Open baffo32 opened 7 years ago

baffo32 commented 7 years ago

I do not have a daisy board to test anything, but I noticed this reading the code:

firstDataPacket, initialized to true, is cleared to false at the end of updateBoardData(). It is then checked if false which it always will be because it was just set, data that hasn't been read yet is backed up, and the flag is re-cleared to false if true which will never happen because it has just been set to false, in updateDaisyData(). It looks like this would result in the first sample being corrupt.

It looks like the clearing of firstDataPacket should be moved out of the individual channel update functions here and here and into the end of updateChannelData which calls them both, right here.

After this change, though, it still looks like the first sample sent would still be corrupt, because meanDaisyChannelDataRaw is not specified in the first sample. One solution would be to add an else { } block here containing code that would fill meanDaisyChannelDataRaw with the contents of daisyChannelDataRaw without any averaging.

If one were to address this area of code more thoroughly, there is an additional possible 'issue' which is that the daisy and board running averages are sampled when output, alternatingly, so there is no way to reconstruct from the output a complete 'snapshot' at any point of time -- the daisy information represents time = (x+1/2), and the board information represents time = (x-1/2). A different approach would be to change the logical flow to output briefly buffered averages from the past that are both taken from the same points in time.