Index: fact/tools/PyDimCtrl/fpydim.py
===================================================================
--- fact/tools/PyDimCtrl/fpydim.py	(revision 13806)
+++ fact/tools/PyDimCtrl/fpydim.py	(revision 13807)
@@ -28,4 +28,5 @@
         self.reg_state_cb()
         self.reg_msg_cb()
+        self.user_func = None
 
     def _cmd(self, cmdstr, *args):
@@ -96,4 +97,8 @@
             print "list_of_states too long, truncating..."
             self.list_of_states = self.list_of_states[1000:]
+            
+        if self.user_func:
+            self.user_func( self.stn )
+        
         if self.print_state: 
             print state
Index: fact/tools/PyDimCtrl/service.py
===================================================================
--- fact/tools/PyDimCtrl/service.py	(revision 13806)
+++ fact/tools/PyDimCtrl/service.py	(revision 13807)
@@ -99,29 +99,4 @@
     time.sleep(CalmDownTime)
     return True
-
-def PrepareBias( verbose = True):
-    msg = MSG()
-    msg.output = verbose
-    bias = bias_control
-
-    if feedback() != 12:
-        msg.warn("feedback is not in Current Control")
-        return False
-
-    bias.set_global_dac(1)
-    if not bias.wait(9, 10):
-        msg.warn("bias not in Voltage ON after 10sec")
-        return False
-    if not bias.wait(5, 10):
-        msg.warn("bias not Ramping after 10sec")
-        return False
-    if not bias.wait(9, 30):
-        msg.warn("bias not fully ramped up after 30sec")
-        return False
-
-    msg("waiting 45sec...")    
-    time.sleep(45)
-    return True
-
 def TakePedestalOnRun( verbose = True ):
     msg = MSG()
@@ -188,26 +163,4 @@
     return True
 
-def TakeDrsCalibration( verbose = True):
-    msg = MSG()
-    msg.output = verbose
-    bias = bias_control
-    fad = fad_control
-
-    bias.set_zero_voltage()
-    if not bias.wait(7, 10):
-        msg.warn("bias has not switched of after 10sec")
-        return False
-    fad.start_drs_calibration()
-    Take( -1, 1000, 'drs-pedestal')
-    Take( -1, 1000, 'drs-gain')
-    Take( -1, 1000, 'drs-pedestal')
-    fad.set_file_format(2)
-    Take( -1, 1000, 'drs-pedestal')
-    Take( -1, 1000, 'drs-time')
-    Take( -1, 1000, 'drs-time-upshifted')
-    fad.reset_secondary_drs_baseline()
-    Take(-1, 1000, 'pedestal')
-    fad.set_file_format(2)
-    Take(-1, 1000, 'pedestal')
 
 def BlinkenLights(verbose = True):
@@ -221,46 +174,9 @@
         time.sleep(1)
 
-def TakeAmplCalib( roi=1024, verbose=True):
-    msg = MSG(verbose)
-    bias = bias_control
-    fad  = fad_control
-    if (roi!=1024) and (roi!=300):
-        raise ValueError('roi must be 300 or 1024')
-    # I do not understand, why the out put needs to be ENABLED??
-    feedback.enable_output(0)
-    bias.set_zero_voltage()
-    bias.wait(7) # VoltageOff
-    fad.start_drs_calibration
-    
-    Take(-1, 1000, 'drs-pedestal')
-    Take(-1, 1000, 'drs-gain')
-    if roi == 300:
-        Take(-1, 1000, 'pedestal')
-    if roi == 1024:
-        Take(-1, 1000, 'drs-pedestal')
-
-    fad.set_file_format(2)
-    if roi == 300:
-        Take(-1, 1000, 'pedestal')
-    if roi == 1024:
-        Take(-1, 1000, 'drs-pedestal')
-
-def TakeTimeCalib( verbose=True ):
-    msg = MSG( verbose )
-    feedback.enable_output(0)
-    if bias() != 7:
-        bias.set_zero_voltage()
-        if not bias.wait(7, 10):
-            msg.warn("bias not ramped down after 10sec")
-            return False
-    fad.set_file_format(2)
-    Take(-1, 1000, 'drs-time')
-    Take(-1, 1000, 'drs-time-upshifted')
-
-
-
-
-def Connect( verbose=True ):
-
+
+
+
+#==============================================================================
+def Connect():
     prepare_ftm_control()
     prepare_fsc_control()
@@ -269,5 +185,4 @@
     prepare_feedback()
     prepare_data_logger()
-    
 
 def prepare_fsc_control( verbose = True, timeout = 10, delay = 0.2):
@@ -516,4 +431,114 @@
 
 
+
+#==============================================================================
+def TakeDrsAmplitudeCalibration( roi = None, verbose = True):
+    """ Takes DRS Amplitude Calibration
+        *roy* integer: 300, 1024 or 
+        *roy* string : 'both'
+        in case of both, the roi=300 calibration is done last.
+        
+        after each complete AmpliteCalibration a 4th pedestal run of the same 
+        roi is taken, for crosschecking.
+        """
+    msg = MSG( verbose )
+    bias = bias_control
+    fad = fad_control
+    if not roi in [300,1024,'both']:
+        raise ValueError("roi must be 300,1024 or the string 'both'")
+
+
+    bias.set_zero_voltage()
+    if not bias.wait(7, 10):
+        msg.warn("bias has not switched of after 10sec")
+        return False
+
+    fad.start_drs_calibration()
+    Take( -1, 1000, 'drs-pedestal')
+    Take( -1, 1000, 'drs-gain')
+    if roi == 300:
+        Take( -1, 1000, 'pedestal')
+        fad.set_file_format(2)
+        Take( -1, 1000, 'pedestal')
+    elif roi == 1024:
+        Take( -1, 1000, 'drs-pedestal')
+        fad.set_file_format(2)
+        Take( -1, 1000, 'drs-pedestal')
+    elif roi == 'both':
+        Take( -1, 1000, 'drs-pedestal')
+        fad.set_file_format(2)
+        Take( -1, 1000, 'drs-pedestal')
+        fad.reset_secondary_drs_baseline()
+        Take( -1, 1000, 'pedestal')
+        fad.set_file_format(2)
+        Take( -1, 1000, 'pedestal')
+
+
+def TakeDrsTimeCalibration( mode = None, verbose = True):
+    """ Takes DRS Time Calibration
+        *mode* can be 'upshifted', 'old' or 'both'
+    """
+    msg = MSG( verbose )
+    bias = bias_control
+    fad = fad_control
+    if not mode in ['upshifted', 'old', 'both']:
+        raise ValueError("mode must be: 'upshifted','old' or 'both'")
+
+    bias.set_zero_voltage()
+    if not bias.wait(7, 10):
+        msg.warn("bias has not switched of after 10sec")
+        return False
+
+    fad.set_file_format(2)
+    if mode == 'old':
+        Take(-1, 1000, 'drs-time')
+    if mode == 'upshifted':
+        Take(-1, 1000, 'drs-time-upshifted')
+    if mode == 'both':
+        Take(-1, 1000, 'drs-time')
+        Take(-1, 1000, 'drs-time-upshifted')
+
+
+def VoltageOn( mode = None, Watchdog = None, verbose = True):
+    msg = MSG( verbose )
+    bias = bias_control
+    fb = feedback
+
+    if not mode in ['temperature', 'current', 'feedback']:
+        raise ValueError("mode must be 'temperature', 'current' or 'feedback'")
+    
+    feedback.start(..... blaaaaa .....)
+    hier muss noch ne menge passieren
+    
+    bias.set_global_dac(1)
+    if not bias.wait(9, 10):
+        msg.warn("bias not in Voltage ON after 10sec")
+        return False
+    if not bias.wait(5, 10):
+        msg.warn("bias not Ramping after 10sec")
+        return False
+    if not bias.wait(9, 30):
+        msg.warn("bias not fully ramped up after 30sec")
+        return False
+
+    msg("waiting 45sec...")    
+    time.sleep(45)
+    return True
+
+# standard watchdogs:
+def std_bias_watchdog( state, verbose=True ):
+    msg = MSG(verbose)
+    if state == 1: #Disconnected
+        msg.warn("BIAS just DISCONNECTED .. trying to reconnect")
+        msg.warn("current runnumber:"+fad_control.runnumber() )
+        bias.reconnect()
+        time.sleep(1)
+        bias.set_zero_voltage()
+        # TODO: This should work, but it is stupid.
+        bias.reset_over_current_status()
+        bias.reset_over_current_status()
+        bias.set_zero_voltage()
+        bias.reset_over_current_status()
+        bias.set_global_dac(1)
 
 # create introduction:
