' 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 Temperature As String
Public CriticalTemperature As String
Public calculate As Float
Public calculatecrit As Float
Public supporttemp As Boolean = True
Public supportcritical As Boolean = True
Public TemperaturesDirectiories As Collection
Public TemperatureCriticalDirectories As Collection
Public Sub _inits()
 Dim i As Integer
 TemperaturesDirectiories = [("0"): ("/sys/bus/acpi/devices/LNXTHERM:00/thermal_zone/temp"),
                             ("1"): ("/proc/acpi/thermal_zone/THM0/temperature"),
                             ("2"): ("/sys/class/hwmon/hwmon0/device/temp2_input"),
                             ("3"): ("/sys/class/hwmon/hwmon0/temp1_input"),
                             ("4"): ("/sys/devices/platform/coretemp.0/temp2_input"),
                             ("5"): ("/sys/class/hwmon/hwmon0/device/temp1_input"), 
                             ("6"): ("/sys/class/hwmon/hwmon0/temp2_input"),
                             ("7"): ("/sys/bus/acpi/drivers/ATK0110/ATK0110:00/hwmon/hwmon0/temp1_input"),
                             ("8"): ("/sys/devices/virtual/thermal/thermal_zone0/temp"),
                             ("9"): ("/sys/class/hwmon/hwmon1/temp1_input")]
 
 TemperatureCriticalDirectories = [("0"): ("/sys/devices/platform/coretemp.0/temp2_crit"),
                                   ("1"): ("/sys/class/hwmon/hwmon0/temp2_crit"),
                                   ("2"): ("/sys/class/hwmon/hwmon0/temp1_crit"),
                                   ("3"): ("/sys/class/hwmon/hwmon1/temp1_crit")]
 
 For i = 0 To TemperaturesDirectiories.Count
  If Exist(TemperaturesDirectiories[i]) = True Then
   Try Temperature = File.Load(TemperaturesDirectiories[i])
   supporttemp = True
   Break
  Endif
 Next
 
 For i = 0 To TemperatureCriticalDirectories.Count
  If Exist(TemperatureCriticalDirectories[i]) = True Then
   Try CriticalTemperature = File.Load(TemperatureCriticalDirectories[i])
   supportcritical = True
   Break
  Endif
 Next
 
 If supportcritical = True Then
  If CriticalTemperature = Null Then
    Logs("Not found crit temp", Logger.Error)
      supportcritical = False
  Else
    calculatecrit = CFloat(Val(Replace(CriticalTemperature, "\n", "")))
  Endif
 Endif
 
 If supporttemp = True Then
  If Temperature = Null Then
    Logs("Not found temp", Logger.Error)
      supporttemp = False
  Else
    calculate = CFloat(Val(Replace(Temperature, "\n", "")))
  Endif
 Endif
 
End
