Class: Pigpio::BitBangSerialTx

Inherits:
Object
  • Object
show all
Defined in:
lib/pigpio/bit_bang_serial_tx.rb

Direct Known Subclasses

BitBangSerial

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tx, baud = 9600, data_bits = 8, stop_bits = 1) ⇒ BitBangSerialTx

Returns a new instance of BitBangSerialTx.



4
5
6
7
8
9
# File 'lib/pigpio/bit_bang_serial_tx.rb', line 4

def initialize(tx, baud = 9600, data_bits = 8, stop_bits = 1)
  @tx = tx
  @baud = baud
  @data_bits = data_bits
  @stop_half_bits = (stop_bits * 2).round.to_i
end

Instance Attribute Details

#txObject (readonly)

Returns the value of attribute tx.



3
4
5
# File 'lib/pigpio/bit_bang_serial_tx.rb', line 3

def tx
  @tx
end

Instance Method Details

#busy?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/pigpio/bit_bang_serial_tx.rb', line 39

def busy?
  IF.wave_tx_busy(@tx.pi)
end

#closeObject



11
12
13
14
# File 'lib/pigpio/bit_bang_serial_tx.rb', line 11

def close
  IF.wave_tx_stop(@tx.pi) if busy?
  IF.wave_clear(@tx.pi)
end

#stopObject



43
44
45
# File 'lib/pigpio/bit_bang_serial_tx.rb', line 43

def stop
  IF.wave_tx_stop(@tx.pi)
end

#syncObject



26
27
28
29
30
# File 'lib/pigpio/bit_bang_serial_tx.rb', line 26

def sync
  while busy?
    sleep 0.1
  end
end

#write(buf) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/pigpio/bit_bang_serial_tx.rb', line 16

def write(buf)
  IF.wave_clear(@tx.pi)
  IF.wave_add_new(@tx.pi)
  ret = IF.wave_add_serial(@tx.pi, @tx.gpio, @baud, @data_bits, @stop_half_bits, 0, buf)
  return ret if ret < 0
  wid = IF.wave_create(@tx.pi)
  return wid if wid < 0
  IF.wave_send_once(@tx.pi, wid)
end

#write_sync(buf) ⇒ Object



32
33
34
35
36
37
# File 'lib/pigpio/bit_bang_serial_tx.rb', line 32

def write_sync(buf)
  ret = write(buf)
  return ret if ret < 0
  sync
  IF.wave_clear(@tx.pi)
end