From: lokilee73 Date: Thu, 24 Aug 2017 12:27:43 +0000 (+0900) Subject: Add a sample guide for the added usb host functions X-Git-Tag: GitHub/PR#40/tizen-studio~54^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a8ba1441ba28c802c55b1f287616f5019165248a;p=sdk%2Fonline-doc.git Add a sample guide for the added usb host functions PS2: Reviewed Change-Id: Ia3e095a1a025dd775f2367919f7cb083cc9f4657 Signed-off-by: lokilee73 --- diff --git a/org.tizen.guides/html/native/connectivity/usb_host_n.htm b/org.tizen.guides/html/native/connectivity/usb_host_n.htm old mode 100644 new mode 100755 index 62e0809..beee193 --- a/org.tizen.guides/html/native/connectivity/usb_host_n.htm +++ b/org.tizen.guides/html/native/connectivity/usb_host_n.htm @@ -28,6 +28,7 @@ @@ -54,7 +55,7 @@

You can set up your application for the USB host functionality by initializing the interface context.

  • Finding and opening a device through a device list -

    To use the USB host functionality, you have to find a device and gather information about it.

    +

    To use the USB host functionality, you have to find a device and gather information about it. You can also monitor when a USB device is attached or detached.

  • Finding interface and endpoints

    You can find the correct interface and configuration to connect to a device using USB.

  • @@ -184,6 +185,35 @@ else +

    Monitoring Device Connections

    +To receive notifications when a USB device is attached or detached: +
      +
    1. Define and register a callback, which is called when the device is attached or detached. +

      Define the events you want to monitor in the third parameter of the usb_host_set_hotplug_cb() function. The available values are: USB_HOST_HOTPLUG_EVENT_ATTACH, USB_HOST_HOTPLUG_EVENT_DETACH, and USB_HOST_HOTPLUG_EVENT_ANY.

      +
      +void
      +detected_cb(usb_host_device_h ndev, void *data)
      +{
      +    dlog_print(DLOG_INFO, LOG_TAG, "USB is attached or detached");
      +}
      +
      +int ret;
      +usb_host_hotplug_h hotplug;
      +
      +ret = usb_host_set_hotplug_cb(ctx, detected_cb, USB_HOST_HOTPLUG_EVENT_ANY, NULL, &hotplug);
      +if (ret == USB_HOST_ERROR_NONE)
      +    dlog_print(DLOG_INFO, LOG_TAG, "USB callback is successfully registered");
      +else
      +    dlog_print(DLOG_INFO, LOG_TAG, "Unable to register USB callback function");
      +
      +
    2. +
    3. When the notifications are no longer needed, deregister the callback: +
      +usb_host_unset_hotplug_cb(hotplug);
      +
      +
    4. +
    +

    Finding the Interface and Endpoints

    USB communication always happens between the host and one of the endpoints. The endpoints are grouped into interfaces and interfaces into configurations. A device can have multiple configurations, but only one can be active at a time. All interfaces inside an active configuration can be used at the same time.