' Gambas module file

Public addres_battery As String
Public addres_battery_2 As String
Public Present As String
Public Design_capacity As String
Public last_full_capacity As String
Public battery_technology As String
Public design_voltage As String
Public design_capacity_warning As String
Public design_capacity_low As String
Public cycle_count As String
Public capacity_granularity_1 As String
Public capacity_granularity_2 As String
Public model_number As String
Public serial_number As String
Public battery_type As String
Public OEM_info As String
Public calculate_percentage_max As String
Public calculate_percentage As String
Public cal_max As Float
Public cal As Float


Public Sub _inits()
If Exist("/proc/acpi/battery/BAT0", True) Then
 addres_battery = "/proc/acpi/battery/BAT0/info"
 addres_battery_2 = "/proc/acpi/battery/BAT0/state"
 Finfosys.TabStrip1[9].Visible = True
 battery._get_inf()
 battery._replace_n()
 Finfosys.battery_info()
Endif
If Exist("/proc/acpi/battery/BAT1/info", True) Then
 addres_battery = "/proc/acpi/battery/BAT1/info"
 addres_battery_2 = "/proc/acpi/battery/BAT1/state"
 Finfosys.TabStrip1[9].Visible = True
 battery._get_inf()
 battery._replace_n()
 Finfosys.battery_info()
Endif
End

Public Sub _get_inf()
 
 Shell "grep 'present:' " & addres_battery & " | cut -d ':' -f 2" Wait To Present
 Shell "grep 'design capacity:' " & addres_battery & " | cut -d ':' -f 2" Wait To Design_capacity
 Shell "grep 'last full capacity:' " & addres_battery & " | cut -d ':' -f 2" Wait To last_full_capacity
 Shell "grep 'battery technology:' " & addres_battery & " | cut -d ':' -f 2" Wait To battery_technology
 Shell "grep 'design voltage:' " & addres_battery & " | cut -d ':' -f 2" Wait To design_voltage
 Shell "grep 'design capacity warning:' " & addres_battery & " | cut -d ':' -f 2" Wait To design_capacity_warning
 Shell "grep 'design capacity low:' " & addres_battery & " | cut -d ':' -f 2" Wait To design_capacity_low
 Shell "grep 'cycle count:' " & addres_battery & " | cut -d ':' -f 2" Wait To cycle_count
 Shell "grep 'capacity granularity 1:' " & addres_battery & " | cut -d ':' -f 2" Wait To capacity_granularity_1
 Shell "grep 'capacity granularity 2:' " & addres_battery & " | cut -d ':' -f 2" Wait To capacity_granularity_2
 Shell "grep 'model number:' " & addres_battery & " | cut -d ':' -f 2" Wait To model_number
 Shell "grep 'serial number:' " & addres_battery & " | cut -d ':' -f 2" Wait To serial_number
 Shell "grep 'battery type:' " & addres_battery & " | cut -d ':' -f 2" Wait To battery_type
 Shell "grep 'OEM info:' " & addres_battery & " | cut -d ':' -f 2" Wait To OEM_info
 Shell "grep 'last full capacity:' " & addres_battery & " | cut -d ':' -f 2" Wait To calculate_percentage_max
 Shell "grep 'remaining capacity:' " & addres_battery_2 & " | cut -d ':' -f 2" Wait To calculate_percentage

End

Public Sub _replace_n()
 Present = Replace(LTrim$(Present), "\n", "")
 Design_capacity = Replace(LTrim$(Design_capacity), "\n", "")
 last_full_capacity = Replace(LTrim$(last_full_capacity), "\n", "")
 battery_technology = Replace(LTrim$(battery_technology), "\n", "")
 design_voltage = Replace(LTrim$(design_voltage), "\n", "")
 design_capacity_warning = Replace(LTrim$(design_capacity_warning), "\n", "")
 design_capacity_low = Replace(LTrim$(design_capacity_low), "\n", "")
 cycle_count = Replace(LTrim$(cycle_count), "\n", "")
 capacity_granularity_1 = Replace(LTrim$(capacity_granularity_1), "\n", "")
 capacity_granularity_2 = Replace(LTrim$(capacity_granularity_2), "\n", "")
 model_number = Replace(LTrim$(model_number), "\n", "")
 serial_number = Replace(LTrim$(serial_number), "\n", "")
 battery_type = Replace(LTrim$(battery_type), "\n", "")
 OEM_info = Replace(LTrim$(OEM_info), "\n", "")
 'Calculate battery
 calculate_percentage = Replace(Replace(Replace(calculate_percentage, "mAh", ""), " ", ""), "\n", "")
 calculate_percentage_max = Replace(Replace(Replace(calculate_percentage_max, "mAh", ""), " ", ""), "\n", "")
 Try Finfosys.ProgressBar3.Value = calculate_percentage / calculate_percentage_max
End

