[DLL] Battery 1.5.0.0

Plugins y todo lo relacionado para Autoplay Media Studio.
Imagen

Buenas amigos de AMSSpecialist.com siguiendo con Visual Studio vi una opción interesante que te informa de algunos parámetros de la batería y como AMS que yo recuerde no lleva nada sobre este tema he pensado en hacer un dll que nos informe del estado de la batería, espero que os guste.


Funciones:
  • Status - retorno Number: 1: "Charging", 2: "Critical", 3: "High", 4: "Low", 5: "NoSystemBattery", 6: "Unknown", 0: "No Case".
  • FullLifetime - retorno Number: devuelve el periodo de duración de la carga.
  • LifePercent - retorno Number: devuelve el tanto por ciento de batería.
  • LifeRemaining - retorno Number: devuelve en periodo de duración restante de la batería.
  • PowerLineState - retorno Number: 1: "Offline", 2: "Online", 3: "Unknown" 0: "No Case".
Código:
UnmanagedExports.cs:
using System;
using RGiesecke.DllExport;
using System.Windows.Forms;

namespace Battery
{
internal static class BatteryClass
{
[DllExport("Status", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
static int Status()
{
int ChargeStatus;

switch (SystemInformation.PowerStatus.BatteryChargeStatus)
{
case BatteryChargeStatus.Charging:
ChargeStatus = 1;
break;
case BatteryChargeStatus.Critical:
ChargeStatus = 2;
break;
case BatteryChargeStatus.High:
ChargeStatus = 3;
break;
case BatteryChargeStatus.Low:
ChargeStatus = 4;
break;
case BatteryChargeStatus.NoSystemBattery:
ChargeStatus = 5;
break;
case BatteryChargeStatus.Unknown:
ChargeStatus = 6;
break;
default:
ChargeStatus = 0;
break;
}

/// Return int:
///1: "Charging"
///2: "Critical"
///3: "High"
///4: "Low"
///5: "NoSystemBattery"
///6: "Unknown"
///0: "No Case"

return ChargeStatus;
}

[DllExport("FullLifetime", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
static int FullLifetime()
{
return SystemInformation.PowerStatus.BatteryFullLifetime;
}

[DllExport("LifePercent", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
static int LifePercent()
{
return Convert.ToInt16(100 * SystemInformation.PowerStatus.BatteryLifePercent);
}

[DllExport("LifeRemaining", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
static int LifeRemaining()
{
return TimeSpan.FromSeconds(SystemInformation.PowerStatus.BatteryLifeRemaining).Minutes;
}

[DllExport("PowerLineState", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
static int PowerLineState()
{
int PLStatus;

switch (SystemInformation.PowerStatus.PowerLineStatus)
{
case PowerLineStatus.Offline:
PLStatus = 1;
break;
case PowerLineStatus.Online:
PLStatus = 2;
break;
case PowerLineStatus.Unknown:
PLStatus = 3;
break;
default:
PLStatus = 0;
break;
}

/// Return int:
/// 1: "Offline"
/// 2: "Online"
/// 3: "Unknown"
/// 0: "No Case"

return PLStatus;
}
}
}


Ejemplo DLL.CallFunction:
DLLPath = _SourceFolder.."\\AutoPlay\\Docs\\Battery.dll";

result = DLL.CallFunction(DLLPath, "LifePercent", "", DLL_RETURN_TYPE_INTEGER, DLL_CALL_STDCALL);

InputSetText("Input1", result.."%");
Descarga:
1.0.0.0
HIDE: ON
Hidebb Message Hidden Description


1.5.0.0
HIDE: ON
Hidebb Message Hidden Description
Thank you
Gracias....
Thank you

gracias

En breve actualizare esta DLL, modificare las funciones que devuelven string para que devuelvan valores numéricos, de este modo podrán ser adaptadas con mayor facilidad a cualquier idioma.

Un Saludo Ceone.

thanks

gracias

Actualizado a 1.5.0.0

Funciones:
  • Status - retorno Number: 1: "Charging", 2: "Critical", 3: "High", 4: "Low", 5: "NoSystemBattery", 6: "Unknown", 0: "No Case".
  • FullLifetime - retorno Number: devuelve el periodo de duración de la carga.
  • LifePercent - retorno Number: devuelve el tanto por ciento de batería.
  • LifeRemaining - retorno Number: devuelve en periodo de duración restante de la batería.
  • PowerLineState - retorno Number: 1: "Offline", 2: "Online", 3: "Unknown" 0: "No Case".
Descarga:
1.5.0.0
HIDE: ON
Hidebb Message Hidden Description
Thank you for what you offer us amazing ideas
there bug :

1 - full life time always = -1

2 - life remaining = Minutes only ,

i mean if battery life remaining = 4 h : 25 m

your dll result = 25 min

can you fix it

Haitham.2012 escribió:there bug :

1 - full life time always = -1

2 - life remaining = Minutes only ,

i mean if battery life remaining = 4 h : 25 m

your dll result = 25 min

can you fix it
thanks for report im working in it.... ;)

gracias

We waiting the file .... ceone

Thank you

Gracias

:normas: good
great work :)

I will try

thanks

Any news on the fix?