KravitzLabDevices / FED3_library

GNU General Public License v3.0
6 stars 17 forks source link

Add serial communication of events, compatibility with FEDWatcher #38

Closed matiasandina closed 2 years ago

matiasandina commented 2 years ago

I have been testing sending messages through serial with FEDWatcher. I have included a working example in the serialTest folder. serialTest.ino is basically an adapted Classic sketch. It is sourcing FED3.h locally from that folder (see line below), which also includes the FED3.cpp and SoftwareSerial files.

#include "FED3.h"    

The intention of this folder is to provide an environment for testing the software by flashing this into a FED3 without having to worry about what version of FED3 we were running on our "real" environments. I have tested the serial communication with serialTest.ino and with a CSPlusMinus pavlovian sketch. I am not submitting that last sketch in this pull request because I want to keep things as small as possible. The test folder would be temporary, only to try with FEDWatcher. Alternatively, it could be tested that the FEDs output a signal via BNC at the moment of the different events. I have tested on my end for a few months now and its functioning does not otherwise affect the FED3 programs (two independent installs in two raspberry pis, several FED3s gathering data in real time).

Changes

Most of the changes have been done by adding new functions. In that sense, they shouldn't break previous code. The changes that have been made into existing functions (e.g., logdata()) check whether serial is enabled or not before doing their magic. Other changes include calling logdata() before updating the screen. This is mostly to have better correlation between the actual moment of the event and the reception of the event through serial (managed by logdata()). This will also make the timestamp saved to SD a tiny bit more precise.

I am sorry that the list of commits is so long, there were a few updates on the main library while we were testing it. In the last updates there were a few changes that wouldn't merge without conflicts, so I merged and re-committed our own modifications again. Please focus on changes done November 1st, after I merged with the latest version of FED3_library. I wanted to have the new functionality of logging pokes while pellets were available, so I decided to finally submit this.