Skip to content

Commit

Permalink
[Tizen.System.Device] Add battery power source property
Browse files Browse the repository at this point in the history
To support using device_battery_get_power_source(),
this battery powersource property addition is necessary.
Below enum and property is added.

 - public enum BatteryPowerSource
	-> It represents battery power source charger type.
 - public static BatteryPowerSource PowerSource
	-> It is possible to get battery power source type as BatteryPowerSource enum value.

Signed-off-by: Yunhee Seo <[email protected]>
  • Loading branch information
Yunhee Seo authored and chanwoochoi committed Nov 19, 2024
1 parent 30dd484 commit 8f4beb0
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
61 changes: 61 additions & 0 deletions src/Tizen.System/Device/Battery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,35 @@ public enum BatteryLevelStatus
Full
}

/// <summary>
/// Enumeration for the current device's power source information from the battery.
/// These represent the current battery power source type (e.g., ac, usb, etc).
/// </summary>
/// <since_tizen> 12 </since_tizen>
public enum BatteryPowerSource
{
/// <summary>
/// These is no power source.
/// </summary>
/// <since_tizen> 12 </since_tizen>
None = 0,
/// <summary>
/// AC power cable is connected.
/// </summary>
/// <since_tizen> 12 </since_tizen>
Ac = 1,
/// <summary>
/// USB power cable is connected.
/// </summary>
/// <since_tizen> 12 </since_tizen>
Usb = 2,
/// <summary>
/// Power is provided by a wireless source.
/// </summary>
/// <since_tizen> 12 </since_tizen>
Wireless = 3
}

/// <summary>
/// The Battery class provides the properties and events for the device battery.
/// </summary>
Expand Down Expand Up @@ -164,6 +193,38 @@ public static bool IsCharging
return charging;
}
}
/// <summary>
/// Gets the current device's power source information from the battery.
/// </summary>
/// <remarks>
/// Retrieves the current battery power source information (e.g., ac, usb, etc).
/// </remarks>
/// <since_tizen> 12 </since_tizen>
/// <value>The battery power source type.</value>
/// <example>
/// <code>
/// using Tizen.System;
/// ...
/// BatteryPowerSource PowerSourceType = Battery.PowerSource;
/// if (PowerSourceType == BatteryPowerSource.None)
/// ...
/// ...
/// </code>
/// </example>
/// <seealso cref="BatteryPowerSource"/>
public static BatteryPowerSource PowerSource
{
get
{
int power_source_type = 0;
DeviceError res = (DeviceError)Interop.Device.DeviceBatteryGetPowerSource(out power_source_type);
if (res != DeviceError.None)
{
Log.Warn(DeviceExceptionFactory.LogTag, "unable to get battery power source type.");
}
return (BatteryPowerSource)power_source_type;
}
}

private static event EventHandler<BatteryPercentChangedEventArgs> s_capacityChanged;
/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions src/Tizen.System/Interop/Interop.Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ internal enum PowerLockState
public static extern int DeviceBatteryIsCharging(out bool charging);
[DllImport(Libraries.Device, EntryPoint = "device_battery_get_level_status", CallingConvention = CallingConvention.Cdecl)]
public static extern int DeviceBatteryGetLevelStatus(out int status);
[DllImport(Libraries.Device, EntryPoint = "device_battery_get_power_source", CallingConvention = CallingConvention.Cdecl)]
public static extern int DeviceBatteryGetPowerSource(out int power_source_type);

// Display
[DllImport(Libraries.Device, EntryPoint = "device_display_get_numbers", CallingConvention = CallingConvention.Cdecl)]
Expand Down

0 comments on commit 8f4beb0

Please sign in to comment.