' Gambas module file

' Copyright(C) 2011-2014, Michał Głowienka aka eloaders <eloaders@linux.pl>
'
' This program is free software; you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation; either version 3 of the License, or
' (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program. If not, see <http://www.gnu.org/licenses/>.

Public Logs As New Logger
Public Product As String
Public bMaxPower As String
Public manufacturer As String
Public speed As String
Public Version As String
Public idProduct As String
Public idVendor As String
Public Serial As String
Public lsusb As String
Public ListAllDiscs As String

Public Sub _inits()
  Dim risultato As String
  Dim righe As New String[]
  Dim count As Integer
  Dim riga As New String[]
  Dim lista As New String[]
  Logs("Add Drives to ComboBox..", Logger.Info)
  Shell "ls /sys/bus/usb/devices/*/* | grep 'manufacturer' | grep usb | cut -d '/' -f 6" To ListAllDiscs
  righe = Split(ListAllDiscs, "\n", "%%", True)
  For count = 0 To righe.Max
  riga = Split(righe[count], " ", "%%", True)
  risultato = Replace(riga[0], " ", "")
  lista.add(risultato)
  Next
  Finfosys.ComboBox5.List = lista
  Finfosys.ComboBox5.Index = 0
 
End

Public Sub get_informations()
 'Product = File.Load("/sys/bus/usb/devices/usb1/product")
 Shell "cat /sys/bus/usb/devices/" & Finfosys.ComboBox5.Text & "/product" Wait To Product
 Shell "cat /sys/bus/usb/devices/" & Finfosys.ComboBox5.Text & "/bMaxPower" Wait To bMaxPower
 Shell "cat /sys/bus/usb/devices/" & Finfosys.ComboBox5.Text & "/manufacturer" Wait To manufacturer
 Shell "cat /sys/bus/usb/devices/" & Finfosys.ComboBox5.Text & "/speed" Wait To speed
 Shell "cat /sys/bus/usb/devices/" & Finfosys.ComboBox5.Text & "/version" Wait To Version
 Shell "cat /sys/bus/usb/devices/" & Finfosys.ComboBox5.Text & "/idProduct" Wait To idProduct
 Shell "cat /sys/bus/usb/devices/" & Finfosys.ComboBox5.Text & "/idVendor" Wait To idVendor
 Shell "cat /sys/bus/usb/devices/" & Finfosys.ComboBox5.Text & "/serial" Wait To Serial
 Shell "lsusb -d " & idVendor & ":" & idProduct & "" Wait To lsusb
 export_informations()
End

Public Sub export_informations()
 Product = Replace(Product, "\n", "")
 bMaxPower = Replace(bMaxPower, "\n", "")
 manufacturer = Replace(manufacturer, "\n", "")
 speed = Replace(speed, "\n", "")
 Version = Replace(Version, "\n", "")
 idProduct = Replace(idProduct, "\n", "")
 idVendor = Replace(idVendor, "\n", "")
 Shell "lsusb -d " & idVendor & ":" & idProduct & "" Wait To lsusb
 lsusb = Replace(lsusb, "\n", "")
 Serial = Replace(Serial, "\n", "")
 Finfosys.TextBox40.Text = Product
 Finfosys.TextBox41.Text = bMaxPower
 Finfosys.TextBox42.Text = manufacturer
 Finfosys.TextBox46.Text = speed & " MB"
 Finfosys.TextBox49.Text = Version
 Finfosys.TextBox50.Text = idProduct
 Finfosys.TextBox51.Text = idVendor
 Finfosys.TextBox43.Text = lsusb
 Finfosys.TextBox54.Text = Serial
End
