Index: drsdaq/DAQReadout.cc
===================================================================
--- drsdaq/DAQReadout.cc	(revision 254)
+++ drsdaq/DAQReadout.cc	(revision 269)
@@ -47,10 +47,4 @@
    {"update", &DAQReadout::cmd_update, false, "<sec>", "Minimum delay between updates to DIM event service"},		  
    {"exit", &DAQReadout::cmd_exit, false, "", "Exit program"},
-   {"fmode", &DAQReadout::cmd_fmode, false, "[off|active|targ]", "Set or get feedback mode"},
-   {"faverage", &DAQReadout::cmd_faverage, false, "[n]", "Set ot get number of averages for feedback"},
-   {"fgain", &DAQReadout::cmd_fgain, false, "[gain]", "Set ot get feedback gain"},
-   {"ftarget", &DAQReadout::cmd_ftarget, false, "[brd chip chan]", "Set or get target value (also 'all' supported)"},
-   {"fresponse", &DAQReadout::cmd_fresponse, false, "[voltage]", "Start response measurement with given voltage difference"},
-   {"fconfig", &DAQReadout::cmd_fconfig, false, "", "Print feedback configuration"},
    {"help", &DAQReadout::cmd_help, false, "", "Print help"}};
 
@@ -96,4 +90,13 @@
   fDefaultFrequency = atof(GetConfig("DefaultFrequency").c_str());
 
+  fLedTrigBoard = atoi(GetConfig("TrigBoard").c_str());
+  fLedTrigChannel = atoi(GetConfig("TrigChannel").c_str());
+  fLedTrigChip = atoi(GetConfig("TrigChip").c_str());
+  fLedTrigSample = atoi(GetConfig("TrigSample").c_str());
+  fLedTrigThreshold = atoi(GetConfig("TrigThreshold").c_str());
+  fLedSignalSample = atoi(GetConfig("SignalSample").c_str());
+  fLedBaselineSample = atoi(GetConfig("BaselineSample").c_str());
+  fIntHalfWidth = atoi(GetConfig("IntHalfWidth").c_str());
+
   if (fFirstSample < 0 || fFirstSample > kNumberOfBins || fSamples > kNumberOfBins) {
     PrintMessage("Warning: Sample range in configuration beyond limits, setting to full range\n");
@@ -140,7 +143,4 @@
   EventService = new DimService (SERVER_NAME"/EventData", (char *) "C", DIMEventData, 0);
 						   
-  // Create instance of HV feedback (must be called after board detection)
-  HVFB	  = new HVFeedback(this);  
-
   // Install DIM command (after all initialized)
   Command = new DimCommand((char *) SERVER_NAME"/Command", (char *) "C", this);
@@ -157,5 +157,5 @@
   delete EventService;	delete[] DIMEventData;
   delete RHeader;		delete EHeader;
-  delete HVFB;			delete[] ACalibTemp;
+  delete[] ACalibTemp;
   delete[] ACalib;		delete[] TCalib;
   delete[] DRSFreq; 	delete[] BStruct;
@@ -220,5 +220,16 @@
 // Print DAQ configuration
 void DAQReadout::cmd_config() {
-  PrintConfig();
+
+  PrintMessage("RawDataPath: %s\n"
+		"DefaultFrequency: %.2f\tFirstSample: %d\tSamples: %u\n"
+		"MinDiskSpaceMB: %u\tMaxFileSizeMB: %d\n"
+		"CalibDataPath: %s\n\n"
+		"LedTrigBoard: %d\t\tLedTrigChip: %d\t\tLedTrigChannel: %d\n"
+        "LedTrigSample: %d\tLedTrigThreshold: %.2f\n"
+        "LedSignalSample: %d\tLedBaselineSample: %d\tIntHalfWidth:%u\n",
+    fRawDataPath,fDefaultFrequency,fFirstSample,fSamples,fMinDiskSpaceMB,
+    fMaxFileSizeMB,fCalibDataPath,
+    fLedTrigBoard, fLedTrigChip, fLedTrigChannel, fLedTrigSample,
+    fLedTrigThreshold, fLedSignalSample, fLedBaselineSample, fIntHalfWidth);
 }
 
@@ -755,56 +766,4 @@
 }
 
-// Set/get mode of feedback
-void DAQReadout::cmd_fmode() {
-
-  if(Match(Param[1],"off")) HVFB->SetFBMode(FB_Off);
-  else if(Match(Param[1],"active")) HVFB->SetFBMode(FB_Active);
-  else if(Match(Param[1],"targets")) HVFB->SetFBMode(FB_Targets);
-  else HVFB->GetFBMode();
-}
-
-// Set/get current number of events
-void DAQReadout::cmd_faverage() {
-
-  if(NParam==1) PrintMessage("Current number of feedback events: %u   (acting when %u events are reached)\n",
-                       HVFB->GetCurrentCount(), HVFB->GetNumAverages());
-  else if(atoi(Param[1])>=0) HVFB->SetNumAverages(atoi(Param[1]));
-  else PrintUsage();
-}
-
-// Set/get feedback gain
-void DAQReadout::cmd_fgain() {
-
-  if(NParam==2) HVFB->SetGain(atof(Param[1]));
-  PrintMessage("Feedback gain is %.2f\n", HVFB->GetGain());
-}
-
-// Set/get target value
-void DAQReadout::cmd_ftarget() {
-
-  if(NParam==1) HVFB->GetTargets();
-  else if(NParam!=5) PrintUsage();
-  else for (int i=FirstBoard; i<=LastBoard; i++)
-         for (int j=0; j<GetBoard(i)->GetNumberOfChips(); j++)
-           for (int k=0; k<GetBoard(i)->GetNumberOfChannels(); k++)
-             if ((atoi(Param[1])==i || Match(Param[1],"all")) &&
-	         (atoi(Param[2])==j || Match(Param[2],"all")) &&
-	         (atoi(Param[3])==k || Match(Param[3],"all")))
-      	      HVFB->SetTarget(i,j,k,atof(Param[4]));
-}
-
-// Start response measurement
-void DAQReadout::cmd_fresponse() {
-
-  if(NParam==1) HVFB->GetResponse();
-  else if(atof(Param[1])) HVFB->MeasureResponse(atof(Param[1]));
-  else PrintUsage();
-}
-
-// Print feedback configuration
-void DAQReadout::cmd_fconfig() {
-
-  HVFB->PrintConfig();
-}
 
 // ----------------------------------------------
@@ -1156,14 +1115,4 @@
 }
 
-// Print configuration to target
-void DAQReadout::PrintConfig() {
-  PrintMessage("RawDataPath: %s\n"
-      	       "DefaultFrequency: %.2f\tFirstSample: %d\tSamples: %u\n"
-     	       "MinDiskSpaceMB: %u\tMaxFileSizeMB: %d\n"
-			   "CalibDataPath: %s\n",
-    fRawDataPath,fDefaultFrequency,fFirstSample,fSamples,fMinDiskSpaceMB,
-    fMaxFileSizeMB,fCalibDataPath);
-}
-
 // Print usage text for command
 void DAQReadout::PrintUsage() {
@@ -1249,7 +1198,9 @@
   int DIMSize;
 
+  // Initialize run
   NumEvents = 0;
   FileNumber = 0;
-  HVFB->ClearAverages();    
+  DimClient::sendCommandNB("Feedback/Command", "clear");
+    
   gettimeofday(&StartTime, NULL);
   PrintMessage("\rStarting run #%d (%s) with %u event(s)\n", RunNumber, daq_runtype_str[daq_runtype], NumEventsRequested);
@@ -1303,6 +1254,26 @@
       }
 
-      // Call feedback to process event
-      HVFB->ProcessEvent();
+	  // Check for LED trigger
+	  if (WaveForm[fLedTrigBoard][fLedTrigChip][fLedTrigChannel][fLedTrigSample] > fLedTrigThreshold) {
+		std::stringstream Cmd;
+		float Integral;
+
+		// Calculate feedback signal
+		for (int i=FirstBoard; i<=LastBoard; i++) {
+		  for (unsigned int j=0; j<RHeader->NChips; j++) {
+			for (unsigned int k=0; k<RHeader->NChannels; k++) {
+			  Integral = 0.0;
+			  for (int q=-fIntHalfWidth; q<=(int) fIntHalfWidth; q++) { 
+        		Integral += (WaveForm[i][j][k][fLedSignalSample+q] - WaveForm[i][j][k][fLedBaselineSample+q])*GetBoard(i)->GetPrecision();
+			  }
+        	  Integral /= 2*fIntHalfWidth+1;
+			  Cmd << Integral << " ";
+    		}
+		  }
+		}
+
+		// Send data to feedback
+		DimClient::sendCommandNB("Feedback/Command", (char *) ("data "+Cmd.str()).c_str());
+	  }
 
       // Call routine to update DIM service (update rate is limited)
