Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tizen.System.Device] Add battery power source property #6460

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading