old_contents: #!/usr/bin/env python3
  
  import sys
  import RPi.GPIO as GPIO
  from utils import delay
  from settings import UR, PUMP_CONFIG
  
  
  class PumpInterface:
      """
      Stepper pump interface.
      """
  
      @staticmethod
      def _get_step_period(step_angle, max_frequency):
          step_freq = max_frequency * UR.turn / step_angle
          return 1 / step_freq
  
      def __init__(self, config):
          self.gpio_sleep = config['gpio_sleep']
          self.gpio_step = config['gpio_step']
          self.wake_up_time_s = config['wake_up_time'].m_as('s')
          self.steps_per_volume = config['steps_per_volume']
          self.microsteps = config['microsteps']
          self.step_period_s = self._get_step_period(
              step_angle=config['step_angle'], max_frequency=config['max_frequency']).m_as('s')
  
          GPIO.setmode(GPIO.BCM)
  
          GPIO.setup(self.gpio_sleep, GPIO.OUT)
          GPIO.setup(self.gpio_step, GPIO.OUT)
  
          GPIO.output(self.gpio_sleep, False)
          GPIO.output(self.gpio_step, False)
  
      def __del__(self):
          GPIO.cleanup()
  
      def step(self, count):
          GPIO.output(self.gpio_sleep, True)
          delay(self.wake_up_time_s)
  
          delay_s = 0.5 * self.step_period_s / self.microsteps
  
          for t in range(0, int(count * self.microsteps)):
              GPIO.output(self.gpio_step, True)
              delay(delay_s)
              GPIO.output(self.gpio_step, False)
              delay(delay_s)
  
          GPIO.output(self.gpio_sleep, False)
  
      def pump(self, volume):
          self.step(volume * self.steps_per_volume)
  
  
  def main():
      volume_mL = float(sys.argv[1])
      p = PumpInterface(PUMP_CONFIG)
      p.pump(volume_mL * UR.mL)
  
  
  if __name__ == '__main__':
      main()
  
new_contents: #!/usr/bin/env python3
  
  import sys
  import RPi.GPIO as GPIO
  from utils import delay
  from settings import UR, PUMP_CONFIG
  
  
  class PumpInterface:
      """
      Stepper pump interface.
      """
  
      @staticmethod
      def _get_step_period(step_angle, max_frequency):
          step_freq = max_frequency * UR.turn / step_angle
          return 1 / step_freq
  
      def __init__(self, config):
          self.gpio_sleep = config['gpio_sleep']
          self.gpio_step = config['gpio_step']
          self.wake_up_time_s = config['wake_up_time'].m_as('s')
          self.steps_per_volume = config['steps_per_volume']
          self.microsteps = config['microsteps']
          self.step_period_s = self._get_step_period(
              step_angle=config['step_angle'], max_frequency=config['max_frequency']).m_as('s')
  
          GPIO.setmode(GPIO.BCM)
  
          GPIO.setup(self.gpio_sleep, GPIO.OUT)
          GPIO.setup(self.gpio_step, GPIO.OUT)
  
          GPIO.output(self.gpio_sleep, False)
          GPIO.output(self.gpio_step, False)
  
      def __del__(self):
          GPIO.cleanup()
  
      def step(self, count):
          GPIO.output(self.gpio_sleep, True)
          delay(self.wake_up_time_s)
  
          delay_s = 0.5 * self.step_period_s / self.microsteps
  
          for t in range(0, int(count * self.microsteps)):
              GPIO.output(self.gpio_step, True)
              delay(delay_s)
              GPIO.output(self.gpio_step, False)
              delay(delay_s)
  
          GPIO.output(self.gpio_sleep, False)
  
      def pump(self, volume):
          self.step(volume * self.steps_per_volume)
  
  
  def main():
      if len(sys.argv) != 2:
          print('Usage: ./pump.py volume')
          print('       ./pump.py 10mL')
          return
  
      volume = UR(sys.argv[1])
      try:
          volume.to('L')
      except:
          print('Value "{}" does not represent a volume'.format(volume))
          return
  
      p = PumpInterface(PUMP_CONFIG)
  
      print('Pumping {}'.format(volume))
      p.pump(volume)
  
  
  if __name__ == '__main__':
      main()
  
subject: use quantity as command line argument