' 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 temp_acpi As Boolean = Exist("/sys/bus/acpi/devices/LNXTHERM:00/thermal_zone/temp")
Public temp_acpi_thm As Boolean = Exist("/proc/acpi/thermal_zone/THM0/temperature")
Public temp_hwmon As Boolean = Exist("/sys/class/hwmon/hwmon0/device/temp2_input")
Public temp_hwmon2 As Boolean = Exist("/sys/class/hwmon/hwmon0/temp1_input")
Public temp_coretemp As Boolean = Exist("/sys/devices/platform/coretemp.0/temp2_input")
'
Public Temperature As String
Public calculate As Float
Public supporttemp As Boolean = False
Public hFile As File
Public sLine As String

Public Sub _inits()
 
 If temp_acpi_thm = True Then
 Shell "cat /proc/acpi/thermal_zone/THM0/temperature" Wait To Temperature
 supporttemp = True
 Else
  supporttemp = False
 Endif
 
 If temp_acpi = True Then
 Shell "cat /sys/bus/acpi/devices/LNXTHERM:00/thermal_zone/temp" Wait To Temperature
 supporttemp = True
 Else
  supporttemp = False
 Endif
 
 If temp_hwmon = True Then
 Shell "cat /sys/class/hwmon/hwmon0/device/temp2_input" Wait To Temperature
 supporttemp = True
 Else
  supporttemp = False
 Endif
 
 If temp_hwmon2 = True Then
 Shell "cat /sys/class/hwmon/hwmon0/temp1_input" Wait To Temperature
 supporttemp = True
 Else
  supporttemp = False
 Endif
 
 If temp_coretemp = True Then
 supporttemp = True
 Shell "cat /sys/devices/platform/coretemp.0/temp2_input" Wait To Temperature
 Else
  supporttemp = False
 Endif
 
 If Access("/sys/class/hwmon/hwmon0/device/temp1_input", gb.Read) = True Then
  supporttemp = True
  Shell "cat /sys/class/hwmon/hwmon0/device/temp1_input" Wait To Temperature
 Else
  supporttemp = False
 Endif
 
 If Temperature = Null Then
 Logs("Not found temp", Logger.Error)
 Else
  calculate = CFloat(Val(Temperature))
 Endif
 
 'hFile = Open "/sys/devices/platform/coretemp.0/temp2_input" For Input

 'While Not Eof(hFile)
 'Line Input #hFile, sLine
 'Print sLine
 'Wend
 'calculate = Replace(Replace(Temperature, " ", ""), "\n", "")
 'hwmon For New 2.6.39, 3. x linux kernels
        '/sys/class/hwmon/hwmon0/temp1_input',
        '/sys/devices/platform/coretemp.0/temp1_input',
        '/sys/bus/acpi/devices/LNXTHERM\:00/thermal_zone/temp',
        '/sys/devices/virtual/thermal/thermal_zone0/temp',
        '/sys/bus/acpi/drivers/ATK0110/ATK0110:00/hwmon/hwmon0/temp1_input',
        'Debian Sid / Experimental On AMD - 64
        '/sys/class/hwmon/hwmon0/device/temp1_input'
 
End
