Class: Rbuspirate::Client
- Inherits:
-
Object
- Object
- Rbuspirate::Client
- Defined in:
- lib/rbuspirate.rb
Instance Attribute Summary collapse
-
#interface ⇒ Object
(also: #iface)
readonly
Returns the value of attribute interface.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#needs_reset ⇒ Object
readonly
Returns the value of attribute needs_reset.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(dvc, sync: true) ⇒ Client
constructor
A new instance of Client.
- #pin_on_off(power: false, pullup: false, aux: false, mosi: false, clk: false, miso: false, cs: false) ⇒ Object
- #reset_binary_mode ⇒ Object
Constructor Details
#initialize(dvc, sync: true) ⇒ Client
Returns a new instance of Client.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rbuspirate.rb', line 31 def initialize(dvc, sync: true) raise ArgumentError, 'Shitty arg' unless [SerialPort, String].include?(dvc.class) if dvc.instance_of?(String) raise 'Connect buspirate first' unless File.exist?(dvc) raise 'Device argument must be device' if File.stat(dvc).rdev.zero? dvc = SerialPort.new(dvc, 115_200, 8, 1, SerialPort::NONE) dvc.flow_control = SerialPort::NONE end @le_port = dvc @le_port.sync = true if sync @needs_reset = false reset_binary_mode end |
Instance Attribute Details
#interface ⇒ Object (readonly) Also known as: iface
Returns the value of attribute interface.
28 29 30 |
# File 'lib/rbuspirate.rb', line 28 def interface @interface end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
28 29 30 |
# File 'lib/rbuspirate.rb', line 28 def mode @mode end |
#needs_reset ⇒ Object (readonly)
Returns the value of attribute needs_reset.
28 29 30 |
# File 'lib/rbuspirate.rb', line 28 def needs_reset @needs_reset end |
Class Method Details
.register_mode(name_symbol, switch_command, wait_timeout, enter_response, interface_class) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rbuspirate.rb', line 14 def self.register_mode( name_symbol, switch_command, wait_timeout, enter_response, interface_class ) define_method("enter_#{name_symbol}".to_sym) do switch_mode( name_symbol, switch_command, wait_timeout, enter_response, interface_class ) end end |
Instance Method Details
#pin_on_off(power: false, pullup: false, aux: false, mosi: false, clk: false, miso: false, cs: false) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/rbuspirate.rb', line 66 def pin_on_off(power: false, pullup: false, aux: false, mosi: false, clk: false, miso: false, cs: false) argarray = [power, pullup, aux, mosi, clk, miso, cs].freeze argarray.each do |arg| raise ArgumentError, 'Shitty arg' unless [true, false].include?(arg) end final_comm = argarray .each.with_index .inject(Commands::Config::PINONOFF) do |comm, (arg, idx)| arg ? (comm | 1 << idx) : (comm) end @le_port.putc(final_comm) # I don't fucking understand: # "The Bus pirate responds to each update # with a byte in the same format # that shows the current state of the pins" # So, why response is always a null byte ? resp = @le_port.expect( Responses::PINS_SET, Timeouts::PINONOFF ) raise 'Setting pins state failied' unless resp end |
#reset_binary_mode ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rbuspirate.rb', line 47 def reset_binary_mode raise 'Device needs reset to change mode' if @needs_reset 20.times do @le_port.putc(Commands::RESET_BITBANG) resp = @le_port.expect( Responses::BITBANG_MODE, Timeouts::BINARY_RESET ) if resp @interface = nil @mode = :bitbang return true end end raise 'Enter to bitbang failied' end |