<commit_before>require 'arduino_firmata'
require 'yaml'
require 'singleton'

class VendingMachine
  include Singleton

  CONFIG = YAML.load File.open 'config/config.yaml'

  def arduino
    @arduino ||= ArduinoFirmata.connect("/dev/ttyUSB#{CONFIG['usb_port']}", bps: 115200, nonblock_io: true)
  end

  def dispense(flavour)
    port = get_port flavour
    arduino.digital_write port, true
    sleep CONFIG['pin_time']
    reset_ports
    "Dispensed on chute #{port}"
  end

  def get_port(flavour)
    num = rand(VendingMachine.flavours[flavour].count)
    VendingMachine.flavours[flavour][num]
  end

  def reset_port port
    arduino.digital_write port, false
  end

  def reset_ports
    (1..13).each do |n|
      reset_port n
    end
  end

  def self.flavours
    YAML.load File.read 'config/flavours.yaml'
  end

end
<commit_msg>Sleep after each reset<commit_after>require 'arduino_firmata'
require 'yaml'
require 'singleton'

class VendingMachine
  include Singleton

  CONFIG = YAML.load File.open 'config/config.yaml'

  def arduino
    @arduino ||= ArduinoFirmata.connect("/dev/ttyUSB#{CONFIG['usb_port']}", bps: 115200, nonblock_io: true)
  end

  def dispense(flavour)
    port = get_port flavour
    arduino.digital_write port, true
    sleep CONFIG['pin_time']
    reset_ports
    "Dispensed on chute #{port}"
  end

  def get_port(flavour)
    num = rand(VendingMachine.flavours[flavour].count)
    VendingMachine.flavours[flavour][num]
  end

  def reset_port port
    arduino.digital_write port, false
  end

  def reset_ports
    (1..13).each do |n|
      reset_port n
      sleep 0.1
    end
  end

  def self.flavours
    YAML.load File.read 'config/flavours.yaml'
  end

end

{'fraction_non_alphanumeric': 0.09723040659988215, 'fraction_numerical': 0.011785503830288745, 'mean_word_length': 3.480211081794195, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4516366', 'n_tokens_mistral': 654, 'n_tokens_neox': 601, 'n_words': 141}