Attached Devices
You can control attached devices and monitor device changes in your application.
The main features of the device control include the following:
-
Battery information
You can get battery details, such as the current percentage, the charging state, and the current level state.
-
Device control
You can manage various components and elements on the device:
-
Display
You can get and set display details, such as the number of displays, the maximum brightness of the display, the current brightness, and the display state.
-
Haptic
You can manage haptic devices by, for example, getting the number of haptic devices, opening or closing the haptic handle, and requesting vibration effect playback.
-
IR
You can manage IR devices by, for example, determining whether an IR device is available and transmitting an IR pattern.
-
LED
You can manage the camera flash LED by, for example, getting the maximum and current brightness of the LED. You can also change the current brightness of the camera flash LED, and request the service LED to play effects.
-
Power
You can request the power state to be locked or unlocked.
-
-
Change monitoring
You can register an event handler to monitor device changes.
Prerequisites
To enable your application to use the attached device control functionality, follow the steps below:
-
To use the Tizen.System.Display, Tizen.System.Led, and Tizen.System.Vibrator classes, the application has to request permission by adding the following privileges to the
tizen-manifest.xml
file:XMLCopy<privileges> <!--To use the Display class --> <privilege>http://tizen.org/privilege/display</privilege> <!--To use the Vibrator class --> <privilege>http://tizen.org/privilege/haptic</privilege> <!--To use the Led class --> <privilege>http://tizen.org/privilege/led</privilege> </privileges>
-
To use the methods and properties of the Tizen.System namespace classes, include the namespace in your application:
C#Copyusing Tizen.System;
Retrieve battery information
To retrieve battery information, follow the steps below:
-
Get the battery charge percentage with the
Percent
property of the Tizen.System.Battery class.The property contains the current battery charge percentage as an integer value from 0 to 100 that indicates the remaining battery charge as a percentage of the maximum level:
C#Copyint s_Percent; s_Percent = Battery.Percent;
-
Get the current battery charging state with the
IsCharging
property.The property contains the device battery charging state as
TRUE
orFALSE
:C#Copybool charging; charging = Battery.IsCharging;
-
Get the current battery level with the
Level
property.The property contains the device battery level as a value of the Tizen.System.BatteryLevelStatus enumeration:
C#CopyBatteryLevelStatus status; status = Battery.Level;
Control the display
To retrieve and set display properties, follow these steps:
-
Get the number of display devices with the
NumberOfDisplays
property of the Tizen.System.Display class:C#Copyint num; num = Display.NumberOfDisplays;
-
Get the maximum possible brightness with the
MaxBrightness
property:C#CopyDisplay dis = Display.Displays[0]; int maxBrightness = dis.MaxBrightness;
-
Get and set the display brightness with the
Brightness
property:C#CopyDisplay dis = Display.Displays[0]; int curBrightness = 0; curBrightness = dis.Brightness; dis.Brightness = 30;
-
Get and set the display state with the
State
property.The property contains the display state as a value of the Tizen.System.DisplayState enumeration:
C#CopyDisplayState state; state = Display.State; Display.State = DisplayState.Normal;
Control haptic devices
To control haptic devices, follow these steps:
-
Get the number of haptic devices with the
NumberOfVibrators
property of the Tizen.System.Vibrator class:C#Copyint num; num = Vibrator.NumberOfVibrators;
-
Play and stop an effect on a given haptic device with the
Vibrate()
andStop()
methods.The device vibrates for a specified time with a constant intensity. The effect handle can be 0:
C#CopyVibrator vib = Vibrator.Vibrators[0]; vib.Vibrate(3000, 50); vib.Stop();
Control IR devices
To control an IR device, follow these steps:
-
Determine whether IR is available on the device using the
IsAvailable
property of the Tizen.System.IR class:C#Copybool test; test = IR.IsAvailable;
-
Transmit an IR pattern with a specific carrier frequency using the
Transmit()
method:C#CopyList<int> pattern = new List<int>(); pattern.Add(10); pattern.Add(50); IR.Transmit(10, pattern);
Control LED devices
To control LEDs on the device, follow the steps below:
-
Get the maximum brightness value of a camera flash LED with the
MaxBrightness
property of the Tizen.System.Led class:C#Copyint test; test = Led.MaxBrightness;
-
Get and set the current brightness value of a camera flash LED with the
Brightness
property:C#Copyint test; test = Led.Brightness; Led.Brightness = 45;
-
Play and stop a custom effect on the service LED that is located on the front of the device with the
Play()
andStop()
methods:C#Copyvar t = Task.Run(async delegate { await Task.Delay(1000); return 0; }); Led.Play(500, 200, Color.FromRgba(255, 255, 255, 1)); t.Wait(); Led.Stop();
Control the power state
To lock and unlock the CPU state, follow the steps below:
-
Lock the power state with the
RequestLock()
method of the Tizen.System.Power class.The method locks the given PowerLock of the Tizen.System.PowerLock enumeration for a specified time. After the given time (in milliseconds), the lock is unlocked. If the process is destroyed, every lock is removed:
C#CopyPower.RequestLock(PowerLock.Cpu, 2000);
-
Unlock the power state with the
ReleaseLock()
method:C#CopyPower.ReleaseLock(PowerLock.Cpu);
Monitor device changes
To monitor device changes, use event handlers registered to the following events:
LevelChanged
andPercentChanged
events in the Tizen.System.Battery class are called when the battery level and charge percentage change.ChargingStateChanged
event in the Tizen.System.Battery class is called when the charger is connected or disconnected.StateChanged
event in the Tizen.System.Display class is called when the device display state changes.BrightnessChanged
event in the Tizen.System.Led class is called when LED brightness changes.
To manage device display status change events, follow these steps:
-
Define an event handler:
C#Copypublic static void DisplayEventHandler() { EventHandler<DisplayStateChangedEventArgs> handler = null; handler = (object sender, DisplayStateChangedEventArgs args); Log.Debug(LogTag, string.Format("Display State:: {0}", value)); }
-
Register the event handler for the
StateChanged
event of theTizen.System.Display
class:C#CopyDisplay.StateChanged += handler;
-
When no longer needed, deregister the event handler:
C#CopyDisplay.StateChanged -= handler;
Related information
- Dependencies
- Tizen 4.0 and Higher