class QMK::Firmware

Public Class Methods

new(keyboard, keymap, config) click to toggle source
# File lib/firmware.rb, line 11
def initialize(keyboard, keymap, config)
  @config = config

  @keyboard = keyboard
  @qmk_keyboard = get_keyboard keyboard
  @keymap = get_keymap(keyboard) || keymap

  @repo = Git.new(LIB_PATH)
end

Public Instance Methods

checkout_stable() click to toggle source
# File lib/firmware.rb, line 45
def checkout_stable
  in_repo do
    @repo.fetch_origin
    @repo.checkout_latest_tag
  end
end
keyboards() click to toggle source
# File lib/firmware.rb, line 59
def keyboards
  if @config[:standalone_keymaps]
    standalone_keyboards
  else
    qmk_keyboards @keymap
  end
end
make(target = nil) click to toggle source
# File lib/firmware.rb, line 21
def make(target = nil)
  if @config[:standalone_keymaps]
    prepare_firmware
  end

  in_repo do
    run "make #{make_target(target)}"
  end
end
programmer() click to toggle source
# File lib/firmware.rb, line 86
def programmer
  Programmer.new(keyboard_path).flasher
end
qmk_keyboards(keymap = nil) click to toggle source
# File lib/firmware.rb, line 73
def qmk_keyboards(keymap = nil)
  Dir["#{keyboards_path}/**/#{keymap}/keymap.c"]
    .map {|path|
      File.dirname(path)
        .gsub(keyboards_path, '')
        .split('/')
        .reject(&:empty?)
        .first
    }
    .uniq
    .sort
end
setup() click to toggle source
# File lib/firmware.rb, line 31
def setup
  @repo.clone 'https://github.com/qmk/qmk_firmware.git'

  in_repo do
    @repo.checkout_latest_tag
  end
end
standalone_keyboards() click to toggle source
# File lib/firmware.rb, line 67
def standalone_keyboards
  Dir["**/keymap.c"]
    .map {|path| File.dirname(path) }
    .sort
end
update() click to toggle source
# File lib/firmware.rb, line 52
def update
  in_repo do
    @repo.clean
    checkout_stable
  end
end
update_submodules() click to toggle source
# File lib/firmware.rb, line 39
def update_submodules
  in_repo do
    run "make git-submodule"
  end
end

Private Instance Methods

get_keyboard(local_keyboard) click to toggle source
# File lib/firmware.rb, line 91
def get_keyboard(local_keyboard)
  @config[:keyboards][local_keyboard] || local_keyboard
end
get_keymap(keyboard) click to toggle source
# File lib/firmware.rb, line 95
def get_keymap(keyboard)
  @config[:keymaps][keyboard]
end
handwired_keymap_path() click to toggle source
# File lib/firmware.rb, line 149
def handwired_keymap_path
  keyboard_path
end
in_repo(&block) click to toggle source
# File lib/firmware.rb, line 99
def in_repo(&block)
  @repo.in_repo &block
end
keyboard_path() click to toggle source
# File lib/firmware.rb, line 133
def keyboard_path
  "#{keyboards_path}/#{@qmk_keyboard}"
end
keyboards_path() click to toggle source
# File lib/firmware.rb, line 129
def keyboards_path
  "#{@repo.path}/keyboards"
end
keymap_path() click to toggle source
# File lib/firmware.rb, line 137
def keymap_path
  if /handwired/ =~ @qmk_keyboard
    return handwired_keymap_path
  end

  standard_keymap_path
end
make_target(target = nil) click to toggle source
# File lib/firmware.rb, line 123
def make_target(target = nil)
  return target unless @keyboard

  [@qmk_keyboard, @keymap, target].compact.join(':')
end
prepare_firmware() click to toggle source
# File lib/firmware.rb, line 115
def prepare_firmware
  local_keyboard_path = File.expand_path "./#{@keyboard}"
  files = Dir.glob "#{local_keyboard_path}/*"

  FileUtils.mkdir_p keymap_path
  FileUtils.cp_r files, keymap_path
end
run(cmd) click to toggle source
# File lib/firmware.rb, line 103
def run(cmd)
  Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
    while line = stdout.gets
      puts line
    end

    while line = stderr.gets
      puts line
    end
  end
end
standard_keymap_path() click to toggle source
# File lib/firmware.rb, line 145
def standard_keymap_path
  "#{keyboard_path}/keymaps/#{@keymap}"
end