<commit_before>require 'serialport'
require 'pry'

class Lightbringer < Thor
  class_option :device, type: :string, default: Dir["/dev/tty.usbmodem*"].first
  class_option :baud, type: :string, default: 9600

  desc "on", "turn on all the lights"
  def on
    port = init_port(options)
    leds = num_leds(port)
    (0...leds).each do |i|
      port.write("s#{i} 255 255 255\n")
    end
  end

  desc "off", "turn off all the lights"
  def off
    port = init_port(options)
    leds = num_leds(port)
    (0...leds).each do |i|
      port.write("s#{i} 0 0 0\n")
    end
  end

  desc "nop", "do nothing"
  def nop
    port = init_port(options)
  end

  private
  def init_port(options)
    port = SerialPort.new(options[:device], baud: options[:baud], dtr: 0)
    loop do
      break if port.gets.chomp == "ready."
    end
    port
  end

  def num_leds(port)
    port.write("c\n")
    port.gets.chomp.to_i<commit_msg>Make nop do something useful.<commit_after>require 'serialport'
require 'pry'

class Lightbringer < Thor
  class_option :device, type: :string, default: Dir["/dev/tty.usbmodem*"].first
  class_option :baud, type: :string, default: 9600

  desc "on", "turn on all the lights"
  def on
    port = init_port(options)
    leds = num_leds(port)
    (0...leds).each do |i|
      port.write("s#{i} 255 255 255\n")
    end
  end

  desc "off", "turn off all the lights"
  def off
    port = init_port(options)
    leds = num_leds(port)
    (0...leds).each do |i|
      port.write("s#{i} 0 0 0\n")
    end
  end

  desc "console", "open a pry console with the port open"
  def nop
    port = init_port(options)
    binding.pry
  end

  private
  def init_port(options)
    port = SerialPort.new(options[:device], baud: options[:baud], dtr: 0)
    loop do
      break if port.gets.chomp == "ready."
    end
    port
  end

  def num_leds(port)
    port.write("c\n")
    port.gets.chomp.to_i
{'fraction_non_alphanumeric': 0.13494992092778071, 'fraction_numerical': 0.020031628887717447, 'mean_word_length': 2.8112449799196786, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5958119', 'n_tokens_mistral': 756, 'n_tokens_neox': 714, 'n_words': 198}