Sha256: 387c21ba1ca195428f785fe8d7ce71e68fccdc8dc0f8ab2d172ddc436ff4c07c
Contents?: true
Size: 1.12 KB
Versions: 1
Compression:
Stored size: 1.12 KB
Contents
require 'pi_piper' require 'qt1070' module Touchberrypi class Keyboard include PiPiper include Qt1070 KEY_MAP = ["LEFT","RIGHT","UP","DOWN","B","A","X"] def initialize sensor = Qt1070.new "/dev/i2c-1" # read sensor status to reset 'change' pin sensor.detection_status @previous_status = sensor.key_status this = self watch :pin => 4, :pull => :up, :trigger => :falling do detection = sensor.detection_status status = sensor.key_status this.call_block status end end def on_key_change &block @on_key_change_block = block end def on_key_up &block @on_key_up_block = block end def on_key_down &block @on_key_down_block = block end def call_block status status.length.times do |i| if status[i] != @previous_status[i] key = KEY_MAP[i] @on_key_up_block.call key if status[i] == "released" unless @on_key_up_block.nil? @on_key_down_block.call key if status[i] == "pressed" unless @on_key_down_block.nil? @on_key_change_block.call key, status[i] unless @on_key_change_block.nil? end end @previous_status = status end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
touchberrypi-0.1.1 | lib/touchberrypi/Keyboard.rb |