Class: I2c_command

Inherits:
Qt::Widget
  • Object
show all
Defined in:
lib/class/I2C/I2c_command.rb

Instance Method Summary collapse

Constructor Details

#initialize(api, chip, bus_id, parent) ⇒ I2c_command

Returns a new instance of I2c_command.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/class/I2C/I2c_command.rb', line 12

def initialize(api, chip, bus_id, parent)
  super()
  @i2c_command_gui = Ui_I2c_command.new
  centerWindow(self)
  @i2c_command_gui.setupUi(self)
  @i2c_command_gui.rbn_read.setChecked(true)
  inputRestrict(@i2c_command_gui.lie_size, 0)
  @chip = chip
  @chip_settings = I2C.find_by(i2c_chip: chip.chip_id)
  @api = api
  @bus_id = bus_id
  @parent = parent
end

Instance Method Details

#check_form_paramObject



41
42
43
44
45
46
47
# File 'lib/class/I2C/I2c_command.rb', line 41

def check_form_param
  if @i2c_command_gui.lie_size.text.empty? || @i2c_command_gui.lie_size.text.to_i.zero?
    Qt::MessageBox.new(Qt::MessageBox::Information, "Form invalid", "Payload size must be filled and superior to 0").exec
    return 0
  end
  return 1
end

#open_generic_cmdObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/class/I2C/I2c_command.rb', line 26

def open_generic_cmd
  return 0 if check_form_param.zero?
  if @i2c_command_gui.rbn_read.isChecked
    mode = "r"
    addr = @chip_settings.i2c_address_r
  else
    mode = "w"
    addr = @chip_settings.i2c_address_w
  end
  i2c_cmd_form = Command_editor.new(0, nil, @chip, @bus_id, @parent, @api, :mode => mode, :size => @i2c_command_gui.lie_size.text, :addr => addr)
  i2c_cmd_form.setWindowModality(Qt::ApplicationModal)
  i2c_cmd_form.show
  close
end