Class: I2c_scanner
- Inherits:
-
Qt::Widget
- Object
- Qt::Widget
- I2c_scanner
- Defined in:
- lib/class/I2C/I2c_scanner.rb
Instance Method Summary collapse
- #autowiring ⇒ Object
-
#initialize ⇒ I2c_scanner
constructor
A new instance of I2c_scanner.
- #resize_to_content ⇒ Object
- #scan ⇒ Object
- #update_cbx(pin) ⇒ Object
- #update_tbl(pin) ⇒ Object
Constructor Details
#initialize ⇒ I2c_scanner
Returns a new instance of I2c_scanner.
17 18 19 20 21 22 23 |
# File 'lib/class/I2C/I2c_scanner.rb', line 17 def initialize super() @view = Ui_Signal_scanner.new centerWindow(self) @view.setupUi(self) update_cbx('B0') end |
Instance Method Details
#autowiring ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/class/I2C/I2c_scanner.rb', line 54 def autowiring signal_found = false @view.tbl_result.rowCount.times do |i| if @view.tbl_result.item(i, 1).text == 'SDA' signal_found = true current_signal = Signall.find_by(name: 'SDA') current_signal.update(pin: @view.tbl_result.item(i, 0).text) elsif @view.tbl_result.item(i, 1).text == 'CLK' signal_found = true current_signal = Signall.find_by(name: 'I2C_CLK') current_signal.update(pin: @view.tbl_result.item(i, 0).text) else # Next row end end if signal_found Qt::MessageBox.new( Qt::MessageBox::Information, 'Hardsploit Autowiring', 'Wiring saved. To change it, go to Menu > Signal mapper' ).exec else Qt::MessageBox.new( Qt::MessageBox::Information, 'Hardsploit Autowiring', 'No signals found in the array' ).exec end rescue Exception => msg ErrorMsg.new.unknown(msg) return false end |
#resize_to_content ⇒ Object
100 101 102 103 104 |
# File 'lib/class/I2C/I2c_scanner.rb', line 100 def resize_to_content @view.tbl_result.resizeColumnsToContents @view.tbl_result.resizeRowsToContents @view.tbl_result.horizontalHeader.stretchLastSection = true end |
#scan ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/class/I2C/I2c_scanner.rb', line 25 def scan @view.cbx_start.setEnabled(false) @view.cbx_stop.setEnabled(false) @view.btn_scan.setEnabled(false) update_tbl(@view.cbx_stop.currentText) Firmware.new('I2C') i2c = HardsploitAPI_I2C.new(speed: 3) @result = i2c.find( start_from: @view.cbx_start.currentText[1].to_i + 9, stop_to: @view.cbx_stop.currentText[1].to_i + 9 ) unless @result[1].is_a? Array @view.tbl_result.setItem(@result.index(0), 1, Qt::TableWidgetItem.new("CLK")) @view.tbl_result.setItem(@result.index(1), 1, Qt::TableWidgetItem.new("SDA")) end @view.cbx_start.setEnabled(true) @view.cbx_stop.setEnabled(true) @view.btn_scan.setEnabled(true) rescue HardsploitAPI::ERROR::HARDSPLOIT_NOT_FOUND ErrorMsg.new.hardsploit_not_found return false rescue HardsploitAPI::ERROR::USB_ERROR ErrorMsg.new.usb_error return false rescue Exception => msg ErrorMsg.new.unknown(msg) return false end |
#update_cbx(pin) ⇒ Object
106 107 108 109 110 111 112 113 |
# File 'lib/class/I2C/I2c_scanner.rb', line 106 def update_cbx(pin) @view.cbx_stop.clear start_at = pin[1].to_i end_at = 7 (end_at - start_at).times do |i| @view.cbx_stop.addItem("B#{(i + start_at) + 1}") end end |
#update_tbl(pin) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/class/I2C/I2c_scanner.rb', line 87 def update_tbl(pin) unless @view.cbx_stop.count.zero? @view.tbl_result.setRowCount(0) nbr = pin[1].to_i - (@view.cbx_start.currentText[1].to_i) + 1 nbr.times do |i| @view.tbl_result.insertRow(i) @view.tbl_result.setItem(i, 0, Qt::TableWidgetItem.new("B#{(i + @view.cbx_start.currentText[1].to_i)}")) @view.tbl_result.setItem(i, 1, Qt::TableWidgetItem.new('-')) end resize_to_content end end |