' Gambas module file

' 
Public Sub _inits()
  Dim Interfaces_X As String
  Dim Avail_Interfaces As Integer 
  Dim Max_Interfaces As Integer
  Dim all_interfaces As String
  
  Debug "Add Interfaces to ComboBox"
  Shell "ls /sys/class/drm/ | grep 'card[0-9]-' | wc -l" Wait To all_interfaces
  Max_Interfaces = Val(all_interfaces)
  For Avail_Interfaces = 1 To Max_Interfaces
   Shell "ls /sys/class/drm/ | grep 'card[0-9]-' | sed -n '" & Avail_Interfaces & "p'" Wait To Interfaces_X
   Interfaces_X = Replace(Interfaces_X, "\n", "")
   Finfosys.ComboBox8.Add(Interfaces_X)
  Next
  
End

Public Sub _check()
 Dim status, enabled, dpms, monitor_name, manufacturer, serial_number As String

 If Exist("/sys/class/drm/") Then
  
  status = File.Load("/sys/class/drm/" & Finfosys.ComboBox8.Text & "/status")
  enabled = File.Load("/sys/class/drm/" & Finfosys.ComboBox8.Text & "/enabled")
  dpms = File.Load("/sys/class/drm/" & Finfosys.ComboBox8.Text & "/dpms")
  Shell "/usr/bin/inex-edid /sys/class/drm/" & Finfosys.ComboBox8.Text & "/edid | grep 'ASCII string' | cut -d ':' -f 2" Wait To monitor_name
  
  Shell "/usr/bin/inex-edid /sys/class/drm/" & Finfosys.ComboBox8.Text & "/edid | grep 'Manufacturer:' | cut -d ':' -f 2" Wait To manufacturer
  Shell "/usr/bin/inex-edid /sys/class/drm/" & Finfosys.ComboBox8.Text & "/edid | grep 'Serial number:' | cut -d ':' -f 2" Wait To serial_number
  If monitor_name = Null Then
   Shell "/usr/bin/inex-edid /sys/class/drm/" & Finfosys.ComboBox8.Text & "/edid | grep 'Monitor name:' | cut -d ':' -f 2" Wait To monitor_name
  Endif
 Endif
 
 Finfosys.Label100.Text = "Monitor name: " & Replace(Replace(monitor_name, "\n", " "), "\n", "")
 Finfosys.Label65.Text = "Status: " & Replace(status, "\n", "")
 Finfosys.Label66.Text = "Enabled: " & Replace(enabled, "\n", "")
 Finfosys.Label67.Text = "DPMS: " & Replace(dpms, "\n", "")
 Finfosys.Label101.Text = "Manufacturer: " & Replace(manufacturer, "\n", "")
 Finfosys.Label102.Text = "Serial number: " & Replace(serial_number, "\n", "")

End
