Skip to content

Instantly share code, notes, and snippets.

@asonas
Last active April 2, 2023 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asonas/82d5f47a51d490c14bb2321211a14db2 to your computer and use it in GitHub Desktop.
Save asonas/82d5f47a51d490c14bb2321211a14db2 to your computer and use it in GitHub Desktop.
kbd = Keyboard.new
kbd.init_pins(
[1, 2, 3, 4],
[5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
)
kbd.add_layer :default, %i[
KC_TAB KC_Q KC_W KC_E KC_R KC_T KC_Y KC_U KC_I KC_O KC_P KC_LBRC KC_RBRC KC_BSLS RAISE
KC_LCTL KC_A KC_S KC_D KC_F KC_G KC_H KC_J KC_K KC_L KC_SCOLON KC_QUOT KC_ENT nil LOWER
KC_LSFT KC_Z KC_X KC_C KC_V KC_B KC_N KC_M KC_COMMA KC_DOT KC_SLASH KC_ESC KC_UP nil nil
LOWER KC_LALT KC_LGUI KC_SPACE nil KC_BSPC nil KC_LANG2 nil KC_LANG KC_LALT nil KC_LEFT KC_DOWN KC_RGHT
]
kbd.add_layer :lower, %i[
KC_GRAVE KC_1 KC_2 KC_3 KC_4 KC_5 KC_6 KC_7 KC_8 KC_9 KC_0 KC_MINUS KC_EQUAL nil nil
nil KC_F1 KC_F2 KC_F3 KC_F4 KC_F5 KC_F6 KC_F7 KC_F8 KC_F9 KC_F10 nil nil nil nil
KC_LSFT KC_F11 KC_F12 KC_LPRN KC_RPRN KC_AMPR nil nil nil nil KC_GRV KC_LBRC nil nil nil
nil KC_LALT KC_LGUI KC_SPACE nil KC_BSPC nil KC_RGUI KC_LCTL KC_LALT nil nil KC_LEFT KC_DOWN KC_RGHT
]
#kbd.add_layer :lower, %i[
# KC_EXLM KC_AT KC_HASH KC_DLR KC_PERC KC_CIRC KC_AMPR KC_ASTER KC_LPRN KC_RPRN
# KC_DEL KC_ESC KC_NO KC_NO KC_NO KC_PGDN KC_PGUP KC_PSCREEN KC_NO KC_NO
# KC_CAPot KC_VOLU KC_NO, KC_ENT RESET KC_NO KC_NO KC_NO KC_UP KC_NO
# KC_NO KC_VOLD KC_LGUI KC_LSFT KC_SPC KC_BSPC KC_LALT KC_ENT KC_NO KC_LEFT KC_DOWN KC_RGHT
#]
#kbd.define_mode_key :RAISE, [ :KC_NO, :raise, 150, 200 ]
kbd.define_mode_key :LOWER, [ :KC_NO, :lower, 150, 200 ]
#kbd.define_mode_key :IME_TOGGLE, [ :KC_LANG1, :default, 300, 150 ] # EISU
# `before_report` will work just right before reporting what keys are pushed to USB host.
# You can use it to hack data by adding an instance method to Keyboard class by yourself.
# ex) Use Keyboard#before_report filter if you want to input `":" w/o shift` and `";" w/ shift`
# kbd.before_report do
# kbd.invert_sft if kbd.keys_include?(:KC_SCOLON)
# # You'll be also able to write `invert_ctl` `invert_alt` and `invert_gui`
# end
# Initialize RGBLED with pin, underglow_size, backlight_size and is_rgbw.
rgb = RGB.new(
0, # pin number
0, # size of underglow pixel
61, # size of backlight pixel
false # 32bit data will be sent to a pixel if true while 24bit if false
)
# 15 * 5 => 65 which is 4 larger than 61
RGB_COL_COUNT = 15
RGB_ROW_COUNT = 5
# So we'll have to exclude 6 of them
# (Compare with the photo of the Amatelus73)
EXCLUDE_POS = [
# Exclude five LED positions from the fifth row
[11, 4], [12, 4], [13, 4], [14, 4]
]
ROW_REVERSED = [
true, # First row
false,
true, # Third row
false,
true, # Fifth row
]
def x_pos(col)
224 / (RGB_COL_COUNT - 1) * col
end
def y_pos(row)
64 / (RGB_ROW_COUNT - 1) * row
end
rgb = RGB.new(0, 0, 74)
RGB_ROW_COUNT.times do |row_index|
RGB_COL_COUNT.times do |col|
col_index = ROW_REVERSED[row_index] ? (RGB_COL_COUNT - col - 1) : col
unless EXCLUDE_POS.include?([col_index, row_index])
rgb.add_pixel(x_pos(col_index), y_pos(row_index))
end
end
end
# Set an effect
rgb.effect = :rainbow_mood
rgb.speed = 22 # 1-31 / default: 22
rgb.hue = 100 # 0-100 / default: 0
rgb.saturation = 100 # 0-100 / default: 100
rgb.value = 13
# Append the feature. Will possibly be able to write `Keyboard#append(OLED.new)` in the future
kbd.append rgb
kbd.start!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment