' 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 Sub _inits()
   Try Finfosys.ComboBox8.List = Dir("/sys/class/drm/", "*card[0-9]-*")
End

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

 If Exist("/sys/class/drm/") Then
  
  Try status = File.Load("/sys/class/drm/" & Finfosys.ComboBox8.Text & "/status")
  Try enabled = File.Load("/sys/class/drm/" & Finfosys.ComboBox8.Text & "/enabled")
  Try dpms = File.Load("/sys/class/drm/" & Finfosys.ComboBox8.Text & "/dpms")
  Shell "cat /sys/class/drm/" & Finfosys.ComboBox8.Text & "/edid | /usr/bin/i-nex-edid | grep \"ASCII string\" | cut -d ':' -f 2" Wait To monitor_name
  Shell "cat /sys/class/drm/" & Finfosys.ComboBox8.Text & "/edid | /usr/bin/i-nex-edid | grep \"voltage level\"" Wait To voltage_level
  Shell "cat /sys/class/drm/" & Finfosys.ComboBox8.Text & "/edid | /usr/bin/i-nex-edid | grep \"Manufacturer:\" | cut -d ':' -f 2" Wait To manufacturer
  Shell "cat /sys/class/drm/" & Finfosys.ComboBox8.Text & "/edid | /usr/bin/i-nex-edid | grep \"Serial number:\" | cut -d ':' -f 2" Wait To serial_number
  Shell "cat /sys/class/drm/" & Finfosys.ComboBox8.Text & "/edid | /usr/bin/i-nex-edid | grep \"Gamma:\" | cut -d ':' -f 2" Wait To Gamma
  Shell "cat /sys/class/drm/" & Finfosys.ComboBox8.Text & "/edid | /usr/bin/i-nex-edid | grep \"Maximum image size:\" | cut -d ':' -f 2" Wait To Maximum_image_size
  If IsNull(monitor_name) Then
   Shell "cat /sys/class/drm/" & Finfosys.ComboBox8.Text & "/edid | /usr/bin/i-nex-edid | grep \"Monitor name:\" | cut -d ':' -f 2" Wait To monitor_name
  Endif
 Endif

 Finfosys.Label155.Text = "Gamma: " & Replace(Replace(Gamma, "\n", " "), "\n", "")
 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", "")
 Finfosys.Label154.Text = Replace(voltage_level, "\n", "")
 Finfosys.Label156.Text = "Maximum image size: " & Replace(Maximum_image_size, "\n", "")

End
