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:

  1. 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:

    XML
    Copy
    <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>
  2. To use the methods and properties of the Tizen.System namespace classes, include the namespace in your application:

    C#
    Copy
    using 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#
    Copy
    int 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 or FALSE:

    C#
    Copy
    bool 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#
    Copy
    BatteryLevelStatus 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#
    Copy
    int num; num = Display.NumberOfDisplays;
  • Get the maximum possible brightness with the MaxBrightness property:

    C#
    Copy
    Display dis = Display.Displays[0]; int maxBrightness = dis.MaxBrightness;
  • Get and set the display brightness with the Brightness property:

    C#
    Copy
    Display 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#
    Copy
    DisplayState 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#
    Copy
    int num; num = Vibrator.NumberOfVibrators;
  • Play and stop an effect on a given haptic device with the Vibrate() and Stop() methods.

    The device vibrates for a specified time with a constant intensity. The effect handle can be 0:

    C#
    Copy
    Vibrator 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#
    Copy
    bool test; test = IR.IsAvailable;
  • Transmit an IR pattern with a specific carrier frequency using the Transmit() method:

    C#
    Copy
    List<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#
    Copy
    int test; test = Led.MaxBrightness;
  • Get and set the current brightness value of a camera flash LED with the Brightness property:

    C#
    Copy
    int 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() and Stop() methods:

    C#
    Copy
    var 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#
    Copy
    Power.RequestLock(PowerLock.Cpu, 2000);
  • Unlock the power state with the ReleaseLock() method:

    C#
    Copy
    Power.ReleaseLock(PowerLock.Cpu);

Monitor device changes

To monitor device changes, use event handlers registered to the following events:

  • LevelChanged and PercentChanged 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:

  1. Define an event handler:

    C#
    Copy
    public static void DisplayEventHandler() { EventHandler<DisplayStateChangedEventArgs> handler = null; handler = (object sender, DisplayStateChangedEventArgs args); Log.Debug(LogTag, string.Format("Display State:: {0}", value)); }
  2. Register the event handler for the StateChanged event of the Tizen.System.Display class:

    C#
    Copy
    Display.StateChanged += handler;
  3. When no longer needed, deregister the event handler:

    C#
    Copy
    Display.StateChanged -= handler;
  • Dependencies
    • Tizen 4.0 and Higher
System
Next System Information
Submit your feedback to GitHub