Skip to content

Commit

Permalink
Improve settings dump/load for ruby client demo apps.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisandreae committed Dec 1, 2020
1 parent 3506f93 commit 8722a90
Show file tree
Hide file tree
Showing 9 changed files with 936 additions and 47 deletions.
7 changes: 7 additions & 0 deletions ruby-client/demo/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gem 'iknow_view_models'
gem 'keyboard_lib', path: '../gem'
gem 'byebug'
170 changes: 170 additions & 0 deletions ruby-client/demo/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
PATH
remote: ../gem
specs:
keyboard_lib (0.1.1)
libusb

GEM
remote: https://rubygems.org/
specs:
actioncable (5.2.3)
actionpack (= 5.2.3)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailer (5.2.3)
actionpack (= 5.2.3)
actionview (= 5.2.3)
activejob (= 5.2.3)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (5.2.3)
actionview (= 5.2.3)
activesupport (= 5.2.3)
rack (~> 2.0)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (5.2.3)
activesupport (= 5.2.3)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
activejob (5.2.3)
activesupport (= 5.2.3)
globalid (>= 0.3.6)
activemodel (5.2.3)
activesupport (= 5.2.3)
activerecord (5.2.3)
activemodel (= 5.2.3)
activesupport (= 5.2.3)
arel (>= 9.0)
activestorage (5.2.3)
actionpack (= 5.2.3)
activerecord (= 5.2.3)
marcel (~> 0.3.1)
activesupport (5.2.3)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
acts_as_manual_list (0.1.2)
activerecord (> 5.0)
activesupport (> 5.0)
lazily (~> 0.2.1)
addressable (2.6.0)
public_suffix (>= 2.0.2, < 4.0)
arel (9.0.0)
builder (3.2.3)
byebug (11.0.1)
concurrent-ruby (1.1.5)
crass (1.0.4)
deep_preloader (1.0.1)
activerecord (>= 5.0.0)
erubi (1.8.0)
ffi (1.11.1)
globalid (0.4.2)
activesupport (>= 4.2.0)
i18n (1.6.0)
concurrent-ruby (~> 1.0)
iknow_cache (1.1.1)
rails (> 5.0)
iknow_params (2.2.1)
activesupport (> 5.0)
json-schema (~> 2.8.0)
tzinfo
iknow_view_models (2.8.5)
activerecord (>= 5.0)
activesupport (>= 5.0)
acts_as_manual_list
concurrent-ruby
deep_preloader
iknow_cache
iknow_params (~> 2.2.0)
jbuilder
json_schema
keyword_builder
lazily
renum
safe_values
jbuilder (2.9.1)
activesupport (>= 4.2.0)
json-schema (2.8.1)
addressable (>= 2.4)
json_schema (0.20.6)
keyword_builder (1.0.0)
lazily (0.2.1)
libusb (0.6.4)
ffi (~> 1.0)
mini_portile2 (~> 2.1)
loofah (2.2.3)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.1)
mini_mime (>= 0.1.1)
marcel (0.3.3)
mimemagic (~> 0.3.2)
method_source (0.9.2)
mimemagic (0.3.3)
mini_mime (1.0.1)
mini_portile2 (2.4.0)
minitest (5.11.3)
nio4r (2.3.1)
nokogiri (1.10.3)
mini_portile2 (~> 2.4.0)
public_suffix (3.0.3)
rack (2.0.7)
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails (5.2.3)
actioncable (= 5.2.3)
actionmailer (= 5.2.3)
actionpack (= 5.2.3)
actionview (= 5.2.3)
activejob (= 5.2.3)
activemodel (= 5.2.3)
activerecord (= 5.2.3)
activestorage (= 5.2.3)
activesupport (= 5.2.3)
bundler (>= 1.3.0)
railties (= 5.2.3)
sprockets-rails (>= 2.0.0)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.0.4)
loofah (~> 2.2, >= 2.2.2)
railties (5.2.3)
actionpack (= 5.2.3)
activesupport (= 5.2.3)
method_source
rake (>= 0.8.7)
thor (>= 0.19.0, < 2.0)
rake (12.3.2)
renum (1.4.0)
safe_values (1.0.1)
sprockets (3.7.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.1)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
thor (0.20.3)
thread_safe (0.3.6)
tzinfo (1.2.5)
thread_safe (~> 0.1)
websocket-driver (0.7.0)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.3)

PLATFORMS
ruby

DEPENDENCIES
byebug
iknow_view_models
keyboard_lib!

BUNDLED WITH
1.17.2
23 changes: 12 additions & 11 deletions ruby-client/dump.rb → ruby-client/demo/dump.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
#!/usr/bin/env ruby
require 'keyboard_lib'

def to_hex(ary)
k = 0;
ary.collect {|x| "%.2x" % x}.inject { | acc, i | acc << ((k+=1) % 16 == 0 ? "\n" : " ") << i }
end

def from_hex(str)
str.split(/\s+/).map {|x| Integer(x, 16) }
end
require 'keyboard_lib'
require 'json'
require_relative './serialization.rb'

KeyboardLib.connected_keyboards.each do |kbd|

puts "# Product: #{kbd.product}"
puts "# Manufacturer: #{kbd.manufacturer}"
puts "# Serial: #{kbd.serial_number}"
Expand All @@ -25,6 +18,14 @@ def from_hex(str)
puts "# macro_max_keys: #{kbd.get_macro_max_keys}"
puts "# flags: #{kbd.get_config_flags}"

# data = {
# mapping: to_hex(kbd.get_mapping),
# programs: kbd.get_programs.map { |p| encode_bytes(p) if p },
# macros: kbd.get_macros.map(&:to_h),
# }
# puts JSON.dump(data)
config = Configuration.new(kbd.get_layout_id, kbd.get_mapping, kbd.get_programs, kbd.get_macros)
view = ConfigurationView.new(config)

puts to_hex(kbd.get_mapping)
puts JSON.dump(view.to_hash)
end
Loading

0 comments on commit 8722a90

Please sign in to comment.