@@ -886,7 +886,7 @@ void Force::Calibrate(){
886886// /// and set everything up /////
887887// //////////////////////////////////////////////////
888888
889- void Force::begin () {
889+ void Force::begin (bool log_lite ) {
890890 Serial.begin (9600 );
891891
892892 if (!ss.begin ()) {
@@ -954,7 +954,7 @@ void Force::begin() {
954954 // Initialize SD
955955 SdFile::dateTimeCallback (dateTime);
956956 CreateDataFile ();
957- writeHeader ();
957+ writeHeader (log_lite );
958958
959959}
960960
@@ -963,15 +963,14 @@ void Force::begin() {
963963// //////////////////////////////////////////////////
964964// // function to update things on every loop /////
965965// //////////////////////////////////////////////////
966- void Force::run (bool log_data ) {
966+ void Force::run () {
967967 SenseLeft ();
968968 SenseRight ();
969969 UpdateDisplay ();
970970 DateTime now = rtc.now ();
971971 unixtime = now.unixtime ();
972972 check_buttons ();
973973 check_lastDispense ();
974- if (log_data == true ) logdata ();
975974}
976975
977976
@@ -1076,7 +1075,7 @@ void Force::graphLegend() {
10761075 if (gramsLeft > 1 or gramsRight >1 ){
10771076 tft.fillRect (80 , 5 , 24 , 12 , ST7735_BLACK); // clear task data on each trial
10781077 }
1079- tft.print (trialLeft );
1078+ tft.print (rewardLeft );
10801079
10811080 // Print trial right
10821081 tft.setCursor (45 ,17 );
@@ -1085,7 +1084,7 @@ void Force::graphLegend() {
10851084 if (gramsLeft > 1 or gramsRight > 1 ){
10861085 tft.fillRect (80 , 17 , 24 , 12 , ST7735_BLACK);
10871086 }
1088- tft.print (trialRight );
1087+ tft.print (rewardRight );
10891088
10901089 // Print FR ratio
10911090 tft.setCursor (110 , 5 );
@@ -1172,14 +1171,20 @@ void Force::CreateDataFile() {
11721171// ////////////////////////////////////////////////
11731172// /// Write header to data file ///////
11741173// ////////////////////////////////////////////////
1175- void Force::writeHeader () {
1176- logfile.println (" MM:DD:YYYY hh:mm:ss, Seconds, Library_Version, Program, Device_Number, ProgressiveRatio, Grams_req, Hold_time, Ratio, Dispense_amount, Dispense_delay, Timeout, Trials_per_block, Max_force, TrialLeft, TrialRight, Press, Lever1_Grams, Lever2_Grams, LickLeft, LickRight, Dispense, Random_Num, Shock_trial" );
1174+ void Force::writeHeader (bool log_lite) {
1175+ if (log_lite == true ) {
1176+ logfile.println (" MM:DD:YYYY hh:mm:ss, Library_Version, Program, Device_Number, Dispense_amount, Dispense_delay, Timeout, Trials_per_block, Max_force, Trials_left, Trials_right, Left_rewarded, Right_rewarded" );
1177+ }
1178+ else if (log_lite == false ) {
1179+ logfile.println (" MM:DD:YYYY hh:mm:ss, Seconds, Library_Version, Program, Device_Number, ProgressiveRatio, Grams_req, Hold_time, Ratio, Dispense_amount, Dispense_delay, Timeout, Trials_per_block, Max_force, TrialLeft, TrialRight, Press, Lever1_Grams, Lever2_Grams, LickLeft, LickRight, Dispense" );
1180+ }
1181+
11771182}
11781183
11791184// ////////////////////////////////////////////////
11801185// /// Write data to file ///////
11811186// ////////////////////////////////////////////////
1182- void Force::WriteToSD () {
1187+ void Force::logdata () {
11831188 DateTime now = rtc.now ();
11841189 logfile.print (now.month ());
11851190 logfile.print (" /" );
@@ -1238,10 +1243,10 @@ void Force::WriteToSD() {
12381243 logfile.print (max_force);
12391244 logfile.print (" ," );
12401245
1241- logfile.print (trialLeft );
1246+ logfile.print (rewardLeft );
12421247 logfile.print (" ," );
12431248
1244- logfile.print (trialRight );
1249+ logfile.print (rewardRight );
12451250 logfile.print (" ," );
12461251
12471252 logfile.print (pressesLeft);
@@ -1262,10 +1267,66 @@ void Force::WriteToSD() {
12621267 logfile.print (dispensing);
12631268 logfile.print (" ," );
12641269
1265- logfile.print (random_number);
1270+ logfile.flush ();
1271+
1272+ if ( ! logfile ) {
1273+ error (2 );
1274+ }
1275+ }
1276+
1277+ void Force::logdata_lite () {
1278+ DateTime now = rtc.now ();
1279+ logfile.print (now.month ());
1280+ logfile.print (" /" );
1281+ logfile.print (now.day ());
1282+ logfile.print (" /" );
1283+ logfile.print (now.year ());
1284+ logfile.print (" " );
1285+ logfile.print (now.hour ());
1286+ logfile.print (" :" );
1287+ if (now.minute () < 10 )
1288+ logfile.print (' 0' ); // Trick to add leading zero for formatting
1289+ logfile.print (now.minute ());
1290+ logfile.print (" :" );
1291+ if (now.second () < 10 )
1292+ logfile.print (' 0' ); // Trick to add leading zero for formatting
1293+ logfile.print (now.second ());
1294+ logfile.print (" ," );
1295+
1296+ logfile.print (ver); // Print library version
12661297 logfile.print (" ," );
12671298
1268- logfile.println (shock);
1299+ logfile.print (library_version); // Print code or program version
1300+ logfile.print (" ," );
1301+
1302+ logfile.print (FRC); // Print device name
1303+ logfile.print (" ," );
1304+
1305+ logfile.print (dispense_amount);
1306+ logfile.print (" ," );
1307+
1308+ logfile.print (dispense_delay);
1309+ logfile.print (" ," );
1310+
1311+ logfile.print (timeout_length);
1312+ logfile.print (" ," );
1313+
1314+ logfile.print (trials_per_block);
1315+ logfile.print (" ," );
1316+
1317+ logfile.print (event);
1318+ logfile.print (" ," );
1319+
1320+ logfile.print (trials_left);
1321+ logfile.print (" ," );
1322+
1323+ logfile.print (trials_right);
1324+ logfile.print (" ," );
1325+
1326+ logfile.print (rewardLeft);
1327+ logfile.print (" ," );
1328+
1329+ logfile.println (rewardRight);
12691330
12701331 logfile.flush ();
12711332
@@ -1274,6 +1335,18 @@ void Force::WriteToSD() {
12741335 }
12751336}
12761337
1338+ void Force::loglite_Left () {
1339+ event = " Left" ;
1340+ trials_left ++;
1341+ logdata_lite ();
1342+ }
1343+
1344+ void Force::loglite_Right () {
1345+ event = " Right" ;
1346+ trials_right ++;
1347+ logdata_lite ();
1348+ }
1349+
12771350/* *******************************************************
12781351 If any errors are detected with the SD card print on the screen
12791352********************************************************/
@@ -1314,14 +1387,6 @@ void Force::getFilename(char *filename) {
13141387 return ;
13151388}
13161389
1317- // //////////////////////////////////////
1318- // /// Log data ///////
1319- // //////////////////////////////////////
1320-
1321- void Force::logdata () {
1322- WriteToSD ();
1323- }
1324-
13251390
13261391// ///////////////////////////////////////////////////////////////////////
13271392// ///// Task functions ////////
@@ -1346,7 +1411,7 @@ void Force::Timeout(int timeout_length) {
13461411 tft.setTextColor (ST7735_WHITE);
13471412 tft.print (" Timeout:" );
13481413 tft.print ((-(millis () - dispense_time - (timeout_length*1000 ))/ 1000 ),1 );
1349- run (false );
1414+ run ();
13501415 tft.fillRect (84 , 43 , 80 , 12 , ST7735_BLACK);
13511416 if ((gramsLeft > 1.5 ) or (gramsRight > 1.5 )) { // reset timeout if either lever pushed
13521417 Timeout (timeout_length);
@@ -1374,7 +1439,7 @@ void Force::Click() {
13741439
13751440void Force::DispenseLeft () {
13761441 dispensing = true ;
1377- trialLeft ++;
1442+ rewardLeft ++;
13781443 Tone (4000 ,200 );
13791444 float successTime = millis ();
13801445 while ((millis () - successTime) < (dispense_delay * 1000 )){
@@ -1412,7 +1477,7 @@ void Force::DispenseLeft() {
14121477
14131478void Force::DispenseRight () {
14141479 dispensing = true ;
1415- trialRight ++;
1480+ rewardRight ++;
14161481 Tone (4000 ,200 );
14171482 float successTime = millis ();
14181483 while ((millis () - successTime) < (dispense_delay * 1000 )){
0 commit comments