From d682e28c622be2a3ed119dfc2487c33d1e9d6848 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Thu, 22 Jun 2017 16:14:42 +0900 Subject: [PATCH] Add .NET attached devices Guide PS2: Reviewed. Change-Id: I52e35c85e776e871bfab52c95d20f7dc424efae7 Signed-off-by: lokilee73 --- org.tizen.guides/html/dotnet/attached_devices.htm | 328 ++++++++++++++++++++++ 1 file changed, 328 insertions(+) create mode 100755 org.tizen.guides/html/dotnet/attached_devices.htm diff --git a/org.tizen.guides/html/dotnet/attached_devices.htm b/org.tizen.guides/html/dotnet/attached_devices.htm new file mode 100755 index 0000000..22ecb6a --- /dev/null +++ b/org.tizen.guides/html/dotnet/attached_devices.htm @@ -0,0 +1,328 @@ + + + + + + + + + + + + + + Attached Devices + + + + + + +
+

Attached Devices

+ +

You can control attached devices and monitor device changes in your application.

+

The main features of the device control include:

+ +
    +
  • Battery information +

    You can get battery details, such as the current percentage, the charging state, and the current level state.

  • +
  • 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 device control functionality:

+
    +
  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:, the application has to request permission by adding the following privileges to the tizen-manifest.xml file:

    +
    +<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. +
  3. To use the methods and properties of the Tizen.System namespace classes, include the namespace in your application: + +
    +using Tizen.System;
    +
    +
  4. +
+ +

Retrieving Battery Information

+ +

To retrieve battery information:

+
    +
  • Get the battery charge percentage with the Percent property of the Tizen.System.Battery class. +

    The property contains the remaining battery charge percentage as an integer value from 0 to 100.

    + +
    +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.

    + +
    +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.

    + +
    +var status;
    +status = Battery.Level;
    +
    +
  • +
+ + +

Controlling the Display

+ +

To retrieve and set display properties:

+
    +
  • Get the number of display devices with the NumberOfDisplays property of the Tizen.System.Display class: +
    +int num;
    +num = Display.NumberOfDisplays;
    +
    +
  • + +
  • Get the maximum possible brightness with the MaxBrightness property: + +
    +Display dis = Display.Displays[0];
    +
    +int curBrightness = dis.Brightness;
    +dis.Brightness = dis.MaxBrightness;
    +
    +
  • + +
  • Get and set the display brightness with the Brightness property: + +
    +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.

    +
    +var state;
    +state = Display.State;
    +
  • +
+ +

Controlling Haptic Devices

+ +

To control haptic devices:

+
    +
  • Get the number of haptic devices with the NumberOfVibrators property of the Tizen.System.Vibrator class: +
    +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.

    +
    +Vibrator vib = Vibrator.Vibrators[0];
    +vib.Vibrate(3000, 50);
    +
    +vib.Stop();
    +
    +
  • +
+ + +

Controlling IR Devices

+ +

To control an IR device:

+
    +
  1. Determine whether IR is available in the device using the IsAvailable property of the Tizen.System.IR class: +
    +var test
    +test = IR.IsAvailable;
    +
    +
  2. + +
  3. Transmit an IR pattern with a specific carrier frequency using the Transmit() method: +
    +List<int> pattern = new List<int>();
    +pattern.Add(10);
    +pattern.Add(50);
    +IR.Transmit(10, pattern);
    +
    +
  4. +
+ + +

Controlling LED Devices

+ +

To control LEDs on the device:

+
    +
  • Get the maximum brightness value of the camera flash LED with the MaxBrightness property of the Tizen.System.Led class: +
    +var test
    +test = Led.MaxBrightness;
    +
    +
  • + +
  • Get and set the current brightness value of the camera flash LED with the Brightness property: + +
    +var 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: + +
    +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();
    +
    +
  • +
+ +

Controlling the Power State

+ +

To lock and unlock the CPU state:

+
    +
  • Lock the power state with the RequestCpuLock() method of the Tizen.System.Power class. +

    The method locks the CPU for a specified time. After the given time (in milliseconds), the lock is unlocked. If the process is destroyed, every lock is removed.

    + +
    +Power.RequestCpuLock(2000);
    +
    +
  • + +
  • Unlock the power state with the ReleaseCpuLock() method: +
    +Power.ReleaseCpuLock();
    +
    +
  • +
+ +

Monitoring 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.
  • +
  • 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:

+
    +
  1. Define an event handler: +
    +public static void DisplayEventHandler()
    +{
    +    EventHandler<DisplayStateChangedEventArgs> handler = null;
    +    handler = (object sender, DisplayStateChangedEventArgs args);
    +    Log.Debug(LogTag, string.Format("Display State:: {0}", value));
    +}
    +
    +
  2. + +
  3. Register the event handler for the StateChanged event of the Tizen.System.Display class: +
    +Display.StateChanged += handler;
    +
    +
  4. + +
  5. When it is no longer needed, deregister the event handler: +
    +Display.StateChanged -= handler;
    +
    +
  6. +
+ + + +
+ +Go to top + + + + + + + \ No newline at end of file -- 2.7.4