Device function realization method and apparatus
By switching between master and slave working modes when a functional device connects to a target device, the device type is determined and functional resources are acquired, thus solving the problem of functional devices consuming master device resources and achieving efficient utilization of functional resources and improved user experience.
Patent Information
- Application Number
- PCT/CN2025/082387
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2024-04-16
- Filing Date
- 2025-03-13
- Publication Date
- 2025-10-23
AI Technical Summary
In the prior art, when a functional device is connected to a main device to implement a preset function, it will continuously consume the functional resources of the main device, resulting in the main device being unable to be used normally when the functional resources are less, affecting the user experience.
By switching the master-slave working mode when the functional device connects to the target device, the device type of the target device is determined, and functional resources are obtained from the functional device or the target device according to the device type, so as to avoid the functional device consuming the functional resources of the target device.
It improves the utilization rate of functional resources in both functional and target devices, thereby enhancing the efficiency of target device usage and user experience.
Smart Images

Figure CN2025082387_23102025_PF_FP_ABST
Abstract
Description
Method and device for implementing device function
[0001] The present application claims priority to the Chinese patent application No. 202410458128.6, filed on April 16, 2024, and entitled "Method and device for implementing device function", the whole content of which is incorporated herein by reference. TECHNICAL FIELD
[0002] The present application relates to the technical field of intelligent devices, in particular to a method and device for implementing device function. BACKGROUND
[0003] With the development of technology, various functional devices are constantly updated, such as U disk, mobile hard disk, mouse, keyboard, gamepad, network card, printer, card reader, sound box, and audio conference device, etc. They are connected to computers or mobile phones through USB (Universal Serial Bus) interfaces, and can better assist users and improve user experience in work, life, and study, etc.
[0004] In practical applications, the functional devices, especially the sound box or audio conference device, generally directly consume the functional resources (such as power) of the computer (notebook / tablet) or mobile phone when connecting to the computer or mobile phone and realizing the corresponding function. However, mobile phone products generally have less functional resources, which seriously affects the user experience of mobile phone products. For example, the power of a mobile phone is generally limited and cannot be plugged into an adapter to work. When the mobile phone is connected to a functional device through a USB interface, the power of the mobile phone is constantly consumed by the functional device, which quickly and constantly decreases, affecting the user experience.
[0005] Therefore, the functional device in the prior art constantly consumes the functional resources of the main device when connecting to the main device to realize the preset function, which causes the functional device to constantly consume the resources of the main device when the main device has less functional resources, affecting the normal use of the main device and the user experience. SUMMARY
[0006] The present application provides a method and device for implementing device function to improve the utilization rate of functional resources in the functional device and the target device, improve the use efficiency of the target device, and improve the user experience.
[0007] In a first aspect, the present application provides a method for implementing device function, applied to a functional device. When the functional device is connected to a target device to realize a preset function, the functional device obtains functional resources from itself or the target device. The method comprises the following steps:
[0008] In a case of determining the connection target device, the device type of the target device is determined by switching master-slave working modes;
[0009] Based on the device type, a target resource device for obtaining a preset function resource is determined from the function device and the target device; the target resource device is the function device or the target device;
[0010] The preset function is realized by using the function resource in the target resource device.
[0011] In combination with the first aspect, in a first possible implementation manner of the first aspect, the device type of the target device is determined by switching master-slave working modes, including:
[0012] The working mode is set to a host mode, and it is determined whether the target device has a slave device function;
[0013] The working mode is switched to a slave mode, and it is determined whether the target device has a master device function;
[0014] It is determined whether the target device can communicate through a preset communication protocol;
[0015] In a case of determining that the target device can communicate through the communication protocol, if it is determined that the target device has both the slave device function and the master device function, it is determined that the device type of the target device is a first type;
[0016] In a case of determining that the target device can communicate through the communication protocol, if it is determined that the target device has the master device function and does not have the slave device function, it is determined that the device type of the target device is a second type.
[0017] In combination with the first aspect, in a second possible implementation manner of the first aspect, the target device is connected through a USB interface, and the working mode is set to the host mode to determine whether the target device has the slave device function, including:
[0018] The working mode of the USB interface is set to the host mode, and an instruction for obtaining a target device descriptor is sent to the target device through a preset USB standard protocol;
[0019] In a case of receiving the target device descriptor fed back by the target device, it is determined that the target device has the slave device function.
[0020] In combination with the first aspect, in a third possible implementation manner of the first aspect, the target device is connected through the USB interface, and the working mode is switched to the slave mode to determine whether the target device has the master device function, including:
[0021] switching a working mode of a USB interface to a slave mode, and determining whether an instruction for acquiring a function device descriptor sent by the target device is received through a preset USB standard protocol within a preset time period;
[0022] In a case where the instruction for acquiring the function device descriptor sent by the target device is received within the preset time period, it is determined that the target device has a master device function.
[0023] With reference to the first aspect, in a fourth possible implementation manner of the first aspect, the determining, based on the device type, the target resource device for acquiring the preset function resource from the function device and the target device comprises:
[0024] In a case where the device type is the first type, the function device is determined as the target resource device for acquiring the function resource;
[0025] In a case where the device type is the second type, the target device is determined as the target resource device for acquiring the function resource.
[0026] With reference to the first aspect, in a fifth possible implementation manner of the first aspect, the function resource is an electric quantity resource, and the implementing the preset function by using the function resource in the target resource device comprises:
[0027] In a case where the target resource device is the target device, it is determined whether the target device is connected to an adapter, or it is determined whether a remaining electric quantity of the target device is greater than a preset electric quantity threshold;
[0028] In a case where it is determined that the target device is connected to the adapter, or the remaining electric quantity of the target device is greater than the electric quantity threshold, the preset function is implemented by using an electric quantity resource in the target device;
[0029] In a case where the target resource device is the function device, the preset function is implemented by using an electric quantity resource in the function device.
[0030] With reference to the first aspect, in a sixth possible implementation manner of the first aspect, the function resource is an electric quantity resource, and the implementing the preset function by using the function resource in the target resource device comprises:
[0031] generating preset prompt information according to the target resource device, the prompt information being used for prompting whether to acquire a function resource through the target resource device;
[0032] displaying the prompt information through the target device;
[0033] When a reply message indicating that the function resource is acquired through the target resource device is received, the preset function is implemented by using the function resource in the target resource device.
[0034] In a second aspect, the embodiments of the present application further provide a device function implementation method, applied to a control device, the control device being different from a function device and a target device, the control device controlling the function device to acquire a function resource from the control device or the target device when the function device is connected with the target device to implement a preset function, and the method comprising:
[0035] When it is determined that the function device is connected with the target device, all master-slave relationships corresponding to the function device and the target device are determined.
[0036] Based on the all master-slave relationships, a device type of the target device is determined.
[0037] Based on the device type, a target resource device acquiring the preset function resource is determined from the function device and the target device, the target resource device being the function device or the target device.
[0038] The function device is controlled to implement the preset function by using the function resource in the target resource device.
[0039] In a third aspect, the embodiments of the present application further provide a device function implementation apparatus, applied to a function device, the function device acquiring a function resource from the function device or a target device when the function device is connected with the target device to implement a preset function, and the apparatus comprising:
[0040] A first determining module is configured to determine a device type of a target device by switching master-slave working modes when it is determined that the function device is connected with the target device.
[0041] A second determining module is configured to determine a target resource device acquiring a preset function resource from the function device and the target device based on the device type, the target resource device being the function device or the target device.
[0042] An implementing module is configured to implement the preset function by using the function resource in the target resource device.
[0043] In a fourth aspect, the embodiments of the present application further provide a device function implementation apparatus, applied to a control device, the control device being different from a function device and a target device, the control device controlling the function device to acquire a function resource from the control device or the target device when the function device is connected with the target device to implement a preset function, and the apparatus comprising:
[0044] The master-slave relationship determination module is configured to determine all master-slave relationships between the functional device and the target device when the functional device is connected to the target device.
[0045] The device type determination module is configured to determine a device type of the target device based on the all master-slave relationships.
[0046] The target determination module is configured to determine a target resource device for obtaining a preset functional resource from the functional device and the target device based on the device type; the target resource device is the functional device or the target device.
[0047] The control interaction module is configured to control the functional device to implement the preset function by using the functional resource in the target resource device.
[0048] In a fifth aspect, an electronic device is provided, which includes a processor and a memory. The processor is configured to execute a device function implementation program stored in the memory to implement the device function implementation method in any one of the first aspect or the second aspect.
[0049] In a sixth aspect, a storage medium is provided, which stores one or more programs. The one or more programs are executable by one or more processors to implement the device function implementation method in any one of the first aspect or the second aspect.
[0050] By adopting the method and device provided in the embodiments of the present application, when the functional device is connected to the target device, the master-slave working mode is switched, the device type of the target device is determined, and then the device from which the corresponding functional resource is obtained is determined according to the device type. This can avoid the situation that when the target device is a device with less functional resource, the functional device consumes the functional resource of the target device, so that the functional resource of the functional device cannot be reasonably utilized, the functional resource of the target device is consumed in large quantity, and the target device cannot be normally used. Therefore, the utilization rate of the functional resource in the functional device and the target device is improved, the use efficiency of the target device is improved, and the user experience is improved. BRIEF DESCRIPTION OF DRAWINGS
[0051] In order to more clearly illustrate the technical solutions of the present application, the drawings needed in the embodiments will be briefly introduced. Obviously, other drawings can also be obtained by those skilled in the art without any creative labor.
[0052] FIG. 1 is a structural schematic diagram of a device function implementation system provided by the embodiments of the present application;
[0053] FIG. 2 is an embodiment flowchart of a device function implementation method provided by the embodiments of the present application;
[0054] FIG. 3 is an embodiment flow chart of another method for implementing device functions according to an embodiment of the present application;
[0055] FIG. 4 is an embodiment flow chart of yet another method for implementing device functions according to an embodiment of the present application;
[0056] FIG. 5 is an embodiment flow chart of still another method for implementing device functions according to an embodiment of the present application;
[0057] FIG. 6 is an embodiment flow chart of still another method for implementing device functions according to an embodiment of the present application;
[0058] FIG. 7 is an embodiment flow chart of a method for a first type of device to interact with a target device according to an embodiment of the present application;
[0059] FIG. 8 is an embodiment flow chart of a method for a second type of device to interact with a target device according to an embodiment of the present application;
[0060] FIG. 9 is an embodiment flow chart of still another method for implementing device functions according to an embodiment of the present application;
[0061] FIG. 10 is an embodiment block diagram of a device function implementation apparatus according to an embodiment of the present application;
[0062] FIG. 11 is an embodiment block diagram of another device function implementation apparatus according to an embodiment of the present application;
[0063] FIG. 12 is a structural schematic diagram of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0064] In the embodiments of the present application, in order to make the purposes, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work fall within the scope of protection of the present application.
[0065] The following disclosure provides many different embodiments, or examples, for implementing different structures of the present application. For the purpose of simplification, the components and arrangements of the specific examples are described in the following. Of course, they are only examples, and the purpose is not to limit the present application. In addition, the present application can repeatedly refer to the numbers and / or letters in different examples. Such repetition is for the purpose of simplification and clarity, and does not indicate the relationship between the various embodiments and / or arrangements discussed.
[0066] In order to solve the technical problem that the function device in the prior art continuously consumes the function resources in the master device when connecting with the master device to realize the preset function, which causes the function device to continuously consume the resources of the master device when the master device has less function resources, thereby affecting the normal use of the master device and the user experience, the present application provides a device function implementation method and device, which can determine the device type of the target device by switching the master-slave working mode when the function device is connected with the target device, so as to determine which device to obtain the corresponding function resources according to the device type, which can avoid the situation that the function device consumes the function resources of the target device when the target device has less function resources, thereby causing the function resources of the function device to be unable to be utilized and the function resources of the target device to be consumed a lot and unable to be normally used, thereby improving the utilization rate of the function resources in the function device and the target device, improving the use efficiency of the target device, and improving the user experience.
[0067] In order to facilitate understanding of the device function implementation method provided by the embodiments of the present application, the device function implementation system related by the embodiments of the present application will be described first as follows:
[0068] Referring to FIG. 1, it is a structural schematic diagram of a device function implementation system provided by the embodiments of the present application. As shown in FIG. 1, the device function implementation system 10 can include a function device 11 and a target device 12.
[0069] The function device 11 can be a device with unique functions for assisting users to work, live and study better, such as a U disk, a mobile hard disk, a mouse, a keyboard, a gamepad, a network card, a printer, a card reader, a sound equipment, an audio conference device and the like, which is taken as an audio conference device in FIG. 1 as an example.
[0070] The target device 12 refers to a device that can be connected with the function device 11, which can be used as a master device to control the function device 11, or can be used as a slave device to be controlled by the function device 11, which is not limited by the embodiments of the present application.
[0071] Further, the target device 12 can be a PC device (such as a desktop computer or a notebook computer), or a mobile device (such as a mobile phone or a tablet), which is not limited by the embodiments of the present application, and the target device 12 is taken as a computer in FIG. 1 as an example.
[0072] In actual application, the target device 12 can be connected with the function device 11 through a preset USB interface, and can control the function device 11 to perform related operations as a master device, such as playing a video.
[0073] In addition, the device function implementation system 10 can further include a control device (not shown in the figure), which can be a device different from the function device and the target device, and can be used to control the interaction between the function device and the target device, so as to implement the preset function (for example, to implement the playing function of the function device).
[0074] In the prior art, after the function device 11 is connected to the target device 12 as a slave device, the function resource of the target device 12 can be used to implement the preset function, for example, the target device 12 is used to supply power to maintain the normal use of the function device 11.
[0075] However, the above method is easy to cause the function resource of the target device 12 to be continuously consumed. Taking the function resource as power as an example, if the above target device 12 is a device (such as a computer, a notebook, etc.) that can be connected to an adapter to interact with the function device 11, the function resource of the target device 12 can be consumed by the function device 11 without affecting the normal use of the target device 12; if the above target device 12 is a device (such as a mobile phone, a tablet, etc.) that cannot be connected to an adapter to interact with the function device 11, the above method is easy to cause the function resource of the target device 12 to be consumed completely, so that the target device 12 cannot be used normally, which not only cannot fully utilize the function resource of the function device 11 itself, but also reduces the use time of the target device 12, seriously affecting the user experience.
[0076] To this end, the embodiment of the present application provides a device function implementation method, which can determine the device type of the target device by switching the master-slave working mode of the function device when the function device is connected to the target device, so as to determine from which device to obtain the corresponding function resource according to the device type, which can avoid the situation that when the target device is a device with less function resource, the function device still consumes the function resource of the target device, so that the function resource of the function device cannot be utilized, the function resource of the target device is consumed a lot and cannot be used normally, thereby improving the utilization rate of the function resource of the function device and the target device, improving the use efficiency of the target device, and improving the user experience.
[0077] The device function implementation method provided by the present application will be further explained and described in detail with reference to the accompanying drawings and specific embodiments, and the embodiments do not constitute a limitation on the embodiments of the present application.
[0078] FIG. 2 is an embodiment flowchart of a device function implementation method provided by the embodiment of the present application. As an embodiment, the flowchart shown in FIG. 2 can be applied to a function device, for example, the function device 11 in the device function implementation system 10 shown in FIG. 1. As shown in FIG. 2, the flowchart can include the following steps:
[0079] Step 201, in the case of determining the connection target device, the device type of the target device is determined by switching master-slave working mode.
[0080] The above-mentioned functional device refers to a device with unique functions used by a user in daily life to assist the user to work, live and study better, such as a U disk, a mobile hard disk, a mouse, a keyboard, a game handle, a network card, a printer, a card reader, a sound, an audio conference device, etc.
[0081] The above-mentioned target device refers to a device that can be connected to the above-mentioned functional device, which can control the functional device as a master device, and can be controlled by the functional device as a slave device. The embodiments of the present application do not limit this. The target device can be a PC device (such as a desktop computer or a notebook computer, etc.), or a mobile device (such as a mobile phone or a tablet, etc.), and the embodiments of the present application do not limit this.
[0082] The above-mentioned device type can be understood as the type of the target device, which can be used to indicate whether the target device belongs to a PC device (such as a computer, a notebook, etc.), or a mobile device (such as a mobile phone, a tablet, etc.), or other non-communication devices, such as a U disk or a hard disk for storing data.
[0083] In an embodiment, the functional device can achieve a preset function by connecting with the target device, for example, a U disk can store files in the target device by connecting with the target device, and for example, a sound can play audio files in the target device by connecting with the target device.
[0084] When the functional device connects the target device, the functional resource (such as power resource, storage resource, etc.) can be obtained from itself or the target device to achieve the above-mentioned preset function. Based on this, in order to more efficiently utilize the functional resource in the functional device and the target device, the functional device can first determine the device type of the target device, and then determine which device to obtain the above-mentioned functional resource.
[0085] In an embodiment, the functional device can determine the device type of the target device by switching master-slave working mode. Further, the above-mentioned device type can include a first type and a second type, the above-mentioned first type can be used to represent a device type that can be both a master device and a slave device, which can be a mobile device, such as a mobile phone or a tablet, etc.; the above-mentioned second type can be used to represent a device type that can only be a master device, which can be a PC device, such as a computer or a notebook, etc.
[0086] As for how to determine the device type of the target device by switching master-slave working mode, it can be explained by the flow shown in FIG. 3 below, which will not be described in detail here.
[0087] In step 202, a target resource device for obtaining the preset function resource is determined from the function device and the target device based on the device type, the target resource device being the function device or the target device.
[0088] In step 203, the preset function is implemented by using the function resource in the target resource device.
[0089] The steps 202 and 203 are described as follows:
[0090] The function resource refers to a function resource available to the function device when the function device is connected to the target device to implement the preset function, which can be a function resource in the target device or a function resource of the function device itself, such as a power resource or a storage resource of the target device and the function device. The function device can interact with the target device by obtaining the function resource, thereby implementing the preset function.
[0091] In an embodiment, the function device can select a target resource device for obtaining the function resource from the function device and the target device according to the device type of the target device, and obtain the required function resource from the target resource device, thereby implementing the preset function.
[0092] Optionally, when the function resource of the target device determined according to the device type does not meet the preset requirement (for example, the function resource is greater than a preset function resource threshold), that is, the device type is the first type, it indicates that the function resource of the target device is insufficient and is not suitable for providing the function device, therefore, the function device can determine itself as the target resource device, and obtain the preset function resource from the target resource device, so as to implement the preset function by using the function resource in the target resource device.
[0093] Optionally, when the function resource of the target device determined according to the device type meets the preset requirement, that is, the device type is the second type, it indicates that the function resource of the target device is sufficient, therefore, the function device can determine the target device as the target resource device, and obtain the preset function resource from the target resource device, so as to implement the preset function by using the function resource in the target resource device.
[0094] For example, assuming that the functional device is a sound box, the target device is a smart phone, and the preset functional resource is an electric quantity resource. Based on this, when the sound box is connected to the smart phone and the target device is determined to be the smart phone by switching the master-slave working mode, the smart phone generally has a USB interface and usually does not interact with the sound box while charging. Therefore, the electric quantity of the smart phone is limited. The sound box has an electric quantity and can be connected to a charger to work. Therefore, the sound box can be determined as the target resource device, and the electric quantity resource can be obtained from the sound box to interact with the smart phone, for example, playing a song output by the smart phone.
[0095] In an embodiment, when the functional resource is an electric quantity resource and the target resource device is determined to be the target device, in order to ensure that the target device can provide the functional device with the electric quantity resource for charging, the functional device can first determine whether the target device is connected to an adapter, or determine whether the remaining electric quantity of the target device is greater than a preset electric quantity threshold.
[0096] Optionally, when the target device is connected to an adapter or the remaining electric quantity of the target device is greater than the electric quantity threshold, the preset function can be implemented by using the electric quantity resource in the target device.
[0097] Optionally, when the target device is not connected to an adapter and the remaining electric quantity of the target device is less than or equal to the electric quantity threshold, it is indicated that the target device cannot provide the functional device with sufficient electric quantity resource at this time. Therefore, the functional device can obtain the electric quantity resource from itself, and implement the preset function by using the electric quantity resource.
[0098] Optionally, when the target resource device is determined to be the functional device, the preset function can be directly implemented by using the electric quantity resource in the functional device.
[0099] In another embodiment, the functional resource can be an electric quantity resource. Based on this, when the functional device implements the preset function by using the functional resource in the target resource device, the functional device can generate a preset prompt information according to the target resource device. The prompt information can be used to prompt whether to obtain the functional resource by the target resource device.
[0100] Then, the target device can display the prompt information to further determine whether to obtain the functional resource by the target resource device determined by the functional device according to the prompt information.
[0101] In this way, the target device can output two buttons of “yes” and “no” after outputting the prompt information. If the user clicks “yes”, it is indicated that the functional resource is obtained by the target resource device determined by the functional device. If the user clicks “no”, it is indicated that the functional resource is not obtained by the target resource device determined by the functional device.
[0102] Optionally, when receiving the reply message for indicating that the functional resource is acquired through the target resource device, the user determines to acquire the functional resource from the target resource device, and thus the preset function can be directly implemented by using the functional resource in the target resource device.
[0103] The technical scheme provided by the embodiment of the present application determines the device type of the target device by switching the master-slave working mode when the functional device and the target device are connected to implement the preset function and the functional resource is acquired from the functional device or the target device in the case of determining the connection of the target device, and determines the target resource device for acquiring the preset functional resource from the functional device and the target device based on the device type, and implements the preset function by using the functional resource in the target resource device. This technical scheme determines the device type of the target device by switching the master-slave working mode when the functional device and the target device are connected, and thus determines which device to acquire the corresponding functional resource according to the device type, which can avoid the situation that the functional device consumes the functional resource of the target device when the target device is a device with less functional resource, so that the functional resource of the functional device cannot be reasonably utilized, the functional resource of the target device is consumed in large quantity, and the target device cannot be normally used, and thus improves the utilization rate of the functional resource in the functional device and the target device, improves the use efficiency of the target device, and improves the user experience.
[0104] Referring to FIG. 3, it is an embodiment flowchart of another device function implementation method provided by the embodiment of the present application. The flowchart shown in FIG. 3 describes how the functional device determines the device type of the target device by switching the master-slave working mode on the basis of the flowchart shown in FIG. 2. As shown in FIG. 3, the flowchart can include the following steps:
[0105] Step 301: set the working mode to the master mode, and determine whether the target device has the slave device function.
[0106] The working mode refers to the mode of the functional device as a control end or a controlled end when working. Correspondingly, the master mode is the working mode as a control end.
[0107] The slave device function is a function possessed by a controlled end but not possessed by a control end.
[0108] In the embodiment of the present application, in order to determine whether the target device can be a controlled end, the functional device can set its own working mode to the master mode, and the target device connected with the functional device can be determined to be a controlled end if it has the slave device function, and cannot be a controlled end if it does not have the slave device function.
[0109] As an optional implementation, the function device can be connected with the target device through a USB interface, and the working mode of the USB interface can include a host mode and a slave mode. Based on this, the function device can set the working mode of its USB interface to the host mode, and send an instruction for obtaining a target device descriptor to the target device through a USB standard protocol.
[0110] Optionally, if the target device sends its target device descriptor to the function device after receiving the instruction for obtaining the target device descriptor, it indicates that the target device can be controlled by the function device as a controlled end. Therefore, the function device can determine that the target device has the slave function when receiving the target device descriptor fed back by the target device.
[0111] On the contrary, if the target device does not execute the instruction after receiving the instruction for obtaining the target device descriptor, it indicates that the target device cannot be controlled by the function device as a controlled end. Therefore, the function device can determine that the target device does not have the slave function when not receiving the target device descriptor fed back by the target device within a preset time period.
[0112] Step 302: Switching the working mode to the slave mode, and determining whether the target device has a master device function.
[0113] The slave mode refers to a working mode in which a device can be controlled by a control end as a controlled end. Correspondingly, the master device function refers to a function possessed by a control end but not possessed by a controlled end.
[0114] In the embodiment of the application, in order to determine whether the target device can be a control end, the function device can set its working mode to the slave mode. If the target device connected with the function device has the master device function, it can be determined that it can be a control end; if it does not have the master device function, it can be determined that it cannot be a control end.
[0115] As an optional implementation, the function device can be connected with the target device through a USB interface, and the working mode of the USB interface can include a host mode and a slave mode. Based on this, the function device can set the working mode of its USB interface to the slave mode, and determine whether an instruction for obtaining a function device descriptor sent by the target device is received through a preset USB standard protocol within a preset time period. The function device descriptor refers to a descriptor corresponding to the function device, which includes various device description information of the function device.
[0116] Optionally, if the instruction for obtaining the function device descriptor sent by the target device is received within the preset time period, it indicates that the target device can control the function device as a control end, and therefore, it can be determined that the target device has the master device function.
[0117] Step 303, determine whether the target device can communicate through the preset communication protocol, if yes, execute step 304 or step 306; if no, execute step 308.
[0118] Step 304, in the case of determining that the target device has both slave device function and master device function, determine the device type of the target device as the first type.
[0119] Step 305, determine the functional device as the target resource device for obtaining functional resources.
[0120] Step 306, in the case of determining that the target device has master device function and does not have slave device function, determine the device type of the target device as the second type.
[0121] Step 307, determine the target device as the target resource device for obtaining functional resources.
[0122] Step 308, determine the device type of the target device as a non-communication device, and end the flow.
[0123] The following uniformly describes steps 303 to 308:
[0124] In actual application, since the functional device can be connected with a non-communication device, the non-communication device can not be able to realize the preset function, therefore, in order to exclude the possibility that the target device is a non-communication device, it can be determined whether the functional device and the target device can normally communicate.
[0125] Among them, since devices of different device types generally have the same function, for example, UAC (USB Audio Class, audio interpretation specification) is a standard that defines how to use USB protocol to transmit audio data. The UAC standard is formulated by the USB Implementers Forum (USB-IF) organization, which ensures that USB audio devices of different manufacturers can work seamlessly on operating systems that support USB. Among them, the definition of the UAC standard covers a series of functions of audio devices, including but not limited to: the format of audio stream and the transmission of audio control interface, such as volume adjustment, mute, compression, etc. Audio function unit; such as mixer, selector, sample rate converter, etc. Audio terminal type; such as microphone, loudspeaker, earphone, etc.
[0126] Further, the synchronization processing of audio data UAC standard enables manufacturers to develop audio devices that comply with the USB specification, and users can expect these devices to be compatible with computers, smartphones and other USB-supported devices without the need for additional drivers. Therefore, through the UAC function, two devices can normally communicate through the USB interface.
[0127] Based on this, when determining whether the functional device and the target device can normally communicate, the UAC protocol can be used to determine whether the functional device and the target device can normally communicate.
[0128] Optionally, when it is determined that the functional device and the target device cannot normally communicate, the device type of the target device can be directly determined as a non-communication device, such as a U disk or a hard disk.
[0129] Optionally, when it is determined that the functional device and the target device can normally communicate, the functional device can further determine the device type of the target device.
[0130] As an exemplary embodiment, the device type can be divided into a first type and a second type. The first type can be used to represent a device type that can serve as both a master device and a slave device, which can be a mobile terminal device, such as a mobile phone or a tablet, and the second type can be used to represent a device type that only serves as a master device, which can be a PC terminal device, such as a computer or a notebook. It can be understood that the device type can further include a third type that only serves as a slave device and / or a fourth type that neither serves as a master device nor a slave device, and the present application embodiments do not limit this.
[0131] Based on this, when it is determined that the target device has both slave device function and master device function, it means that the target device can serve as both a master device and a slave device, which meets the standard of a mobile terminal device, and thus the device type of the target device can be determined as the first type.
[0132] Optionally, when it is determined that the target device has master device function but does not have slave device function, it means that the target device can only serve as a master device and cannot serve as a slave device, which meets the standard of a PC terminal device, and thus the device type of the target device can be determined as the second type.
[0133] Further, when it is determined that the device type of the target device is the first type, it means that the functional resource (such as power resource) of the target device is less, and thus in order to fully utilize the functional resource of the functional device, the functional device can be determined as the target resource device.
[0134] When it is determined that the device type of the target device is the second type, it means that the functional resource of the target device is sufficient, and thus in order to ensure the use efficiency of the functional device, the target device can be determined as the target resource device.
[0135] The technical scheme provided in the embodiments of the present application comprises the following steps: setting a work mode as a host mode, determining whether the target device has a slave device function; setting the work mode as a slave mode, determining whether the target device has a master device function; determining whether the target device can communicate through a preset communication protocol; if yes, determining that the device type of the target device is a first type in the case that the target device has both the slave device function and the master device function, and determining the functional device as a target resource device for obtaining a functional resource; in the case that the target device has the master device function and does not have the slave device function, determining that the device type of the target device is a second type, and determining the target device as the target resource device for obtaining the functional resource; if not, determining that the device type of the target device is a non-communication device, and ending the process. This technical scheme can determine the device type of the target device according to whether the target device has the master device function and the slave device function by switching the master-slave work mode of the functional device, thereby achieving more rapid and accurate determination of the device type of the target device.
[0136] Referring to FIG. 4, an embodiment flowchart of another device function implementation method provided in the embodiments of the present application is shown. As an embodiment, the flowchart shown in FIG. 4 can be applied to a control device, which can be a device different from the functional device and the target device shown in FIG. 2. When the control device controls the functional device to connect with the target device to implement a preset function, the control device can control the functional device to obtain a functional resource from the control device or the target device. As shown in FIG. 4, the flowchart can comprise the following steps:
[0137] In step 401, in the case that the functional device is connected with the target device, all master-slave relationships between the functional device and the target device are determined.
[0138] The functional device refers to a device with a unique function used by a user in daily life to assist the user to work, live and study better, such as a U disk, a mobile hard disk, a mouse, a keyboard, a gamepad, a network card, a printer, a card reader, a sound equipment and an audio conference device.
[0139] The target device refers to a device that can be connected with the functional device, which can control the functional device as a master device, or be controlled by the functional device as a slave device, which is not limited in the embodiments of the present application. The target device can be a PC device (such as a desktop computer or a notebook computer), or a mobile device (such as a mobile phone or a tablet computer), which is not limited in the embodiments of the present application.
[0140] The master-slave relationship is used to represent the control and controlled relationship between two devices, which can indicate the relationship between the master device and the slave device. The master device refers to a device as a control device, and the slave device refers to a device as a controlled device.
[0141] In one embodiment, when the functional device is connected to the target device, in order to determine the device type of the target device, the control device may first determine all master-slave relationships between the functional device and the target device. Furthermore, the functional device may be connected to the target device via a preset USB interface.
[0142] Based on this, as an exemplary embodiment, the control device may control the functional device to use the USB interface to determine all master-slave relationships between the functional device and the target device.
[0143] As for how the control device specifically determines all master-slave relationships between the functional device and the target device, it can be explained below through the process shown in Figure 5 and will not be described in detail here.
[0144] Step 402: Based on all the above master-slave relationships, determine the device type of the target device.
[0145] The above device type can be understood as the type of target device, which can be used to indicate whether the target device is a PC device (such as a computer, laptop, etc.), a mobile device (such as a mobile phone, tablet, etc.), or other non-communication devices, such as a USB flash drive or hard drive for storing data.
[0146] In actual applications, when different types of devices interact with functional devices, the master-slave relationships they have during the interaction process are different. For example, computer devices can generally only act as master devices to control functional devices, while mobile devices can act as master devices to control functional devices, and can also act as slave devices to be controlled by the above-mentioned functional devices. Therefore, the control device can determine the device type of the target device based on the entire master-slave relationship between the determined functional device and the target device.
[0147] Furthermore, since devices of different device types generally have the same functions, for example, UAC is a standard that defines how to use the USB protocol to transmit audio data.
[0148] Based on this, in the embodiment of the present application, in order to exclude the possibility that the target device may be a non-communication device, it is possible to first determine whether the above-mentioned functional device and the target device can communicate normally through the UAC protocol.
[0149] Optionally, when it is determined that the above-mentioned functional device and the target device can communicate normally, the execution subject of the embodiment of the present application may further determine the device type of the target device based on all master-slave relationships.
[0150] As for how to determine the device type of the target device based on all master-slave relationships, it can be explained below through the process shown in Figure 6, which is not described in detail here.
[0151] Optionally, in the case that it is determined that the function device and the target device cannot communicate normally, the device type of the target device can be directly determined as a non-communication device, such as a U disk or a hard disk.
[0152] In step 403, the target resource device for obtaining the preset function resource is determined from the function device and the target device according to the device type; the target resource device is the function device or the target device.
[0153] In step 404, the function device is controlled to implement the preset function by using the function resource in the target resource device.
[0154] The steps 403 and 404 are described as follows:
[0155] The function resource refers to a function resource that can be used by the function device when the function device is connected with the target device to implement the preset function; the function resource can be a function resource in the target device or a function resource of the function device itself, such as a power supply function of the target device and the function device. The function device can interact with the target device by obtaining the function resource, so as to implement the preset function.
[0156] In the implementation of the present application, the control device can determine whether the function resource in the target device meets the preset requirement according to the device type of the target device. When the target device meets the preset requirement, it means that the corresponding function resource of the target device is sufficient, and the function device can obtain the corresponding function resource from the target device.
[0157] Optionally, when it is determined according to the device type that the function resource of the target device meets the preset requirement, the control device can control the function device to obtain the preset function resource from the target device, and control the function device to implement the preset function by using the function resource.
[0158] Optionally, when the control device determines that the function resource of the target device does not meet the preset requirement according to the device type (for example, when the target device is a smart phone, it means that the function resource of the target device is limited and does not meet the preset requirement), it means that the function resource included in the target device at this time is less and is not suitable for providing the function device to use, so the preset function resource can be obtained from the function device and the preset function can be implemented.
[0159] For example, assuming that the functional device is a sound box, the target device is a smart phone, and the target function is a charging function. Based on this, when the sound box is connected to the smart phone, the control device can determine that the target device is the smart phone according to all the master-slave relationships between the two devices. Since the smart phone generally has a USB interface, it usually does not interact with the sound box while charging, and the power of the smart phone is limited. The sound box itself has power and can even be connected to a charger to work. Therefore, the control device can obtain power resources from the sound box to achieve the preset function through the power of the control device and the smart phone, for example, playing songs output by the smart phone.
[0160] The technical solution provided by the embodiments of the present application determines all master-slave relationships between the functional device and the target device when the functional device is connected to the target device. The master-slave relationship is used to indicate the relationship between the master device and the slave device. Based on all the master-slave relationships, the device type of the target device is determined, and the target resource device for obtaining the preset functional resource is determined from the functional device and the target device according to the device type. The target resource device is the functional device or the target device. The functional resource in the target resource device is used to control the functional device to achieve the preset function. This technical solution can determine the device type of the target device according to all possible master-slave relationships between the two devices when the functional device is connected to the target device, so as to determine which device to obtain the corresponding functional resource according to the device type. This can avoid the situation that when the target device is a device with less functional resource, the functional device consumes the functional resource of the target device, resulting in the functional resource of the functional device being wasted and the functional resource of the target device being consumed a lot, and the target device cannot be used normally. This technical solution can improve the utilization rate of functional resources and the use efficiency of the target device when the devices interact, and improve the user experience.
[0161] FIG. 5 is an embodiment flowchart of another device function implementation method provided by the embodiments of the present application. The flowchart shown in FIG. 5 describes how the control device specifically determines all the master-slave relationships between the functional device and the target device based on the flowchart shown in FIG. 4. As shown in FIG. 5, the flowchart can include the following steps:
[0162] Step 501: Determine whether the target device is a slave device when the functional device is a master device, and determine whether the target device is a master device when the functional device is a slave device.
[0163] In an embodiment, the master-slave relationship between the functional device and the target device is determined, which can also be understood as determining the master device and the slave device in both the functional device and the target device. Further, the master device and the slave device can also be understood as the control device and the controlled device. Based on this, in the embodiments of the present application, in order to determine the master-slave relationship between the functional device and the target device, the target device can be tested with the functional device as the master device and the slave device respectively, so as to determine whether the target device can be the master device and the slave device, and then the master-slave relationship between the functional device and the target device can be determined.
[0164] As an optional implementation, the functional device and the target device can be connected through the USB interface, and the functional device and the target device can interact through the USB standard protocol, so as to determine whether the target device can be the master device and the slave device. Further, since the functional device can be the master device and the slave device, the USB interface of the functional device can include two functional modes: the master device mode and the slave device mode.
[0165] Based on this, in an exemplary embodiment, when the functional device is taken as the master device to determine whether the target device is the slave device, the working mode of the USB interface of the functional device can be updated to the master device mode, and in the master device mode, the functional device sends an instruction for obtaining a device descriptor to the target device through the preset USB standard protocol.
[0166] In the above, the USB standard protocol refers to the protocol for transmission through the USB interface. The device descriptor refers to the first descriptor read by the master device when two devices are connected through the USB interface, which provides information about the two devices, the configuration of the devices, and the class to which the devices belong.
[0167] After that, if the target device can be the slave device, the target device will receive the instruction and send the corresponding device descriptor to the functional device according to the instruction; if the target device cannot be the slave device, the target device cannot receive the instruction, and thus cannot send the device descriptor to the functional device.
[0168] Optionally, in the case that the functional device receives the device descriptor fed back by the target device, it can be determined that the target device can be the slave device.
[0169] On the contrary, in the case that the functional device does not receive the device descriptor fed back by the target device, it can be determined that the target device cannot be the slave device.
[0170] In an exemplary embodiment, when the functional device is determined as a slave device, the working mode of the USB interface of the functional device can be updated to a slave mode, and in the slave mode, it is determined whether an instruction for obtaining a device descriptor of the functional device is received from the target device through a preset USB standard protocol.
[0171] As described above, when two devices are connected through a USB, the master device can actively obtain the device descriptor. Therefore, if the target device can act as a master device, the target device can send an instruction for obtaining the device descriptor to the functional device through the USB standard protocol after being connected to the functional device.
[0172] Based on this, in a case where the instruction is determined to be received, the target device can be determined as a master device.
[0173] On the contrary, in a case where the instruction is not received within a preset time period, the target device can be determined as a non-master device.
[0174] In a case where the target device is determined to be unable to act as a slave device but able to act as a master device, it is determined that the entire master-slave relationship between the functional device and the target device includes a first master-slave relationship, and the first master-slave relationship indicates that the target device is a master device and the functional device is a slave device.
[0175] In a case where the target device is determined to be able to act as a slave device and able to act as a master device, it is determined that the entire master-slave relationship between the functional device and the target device includes a first master-slave relationship and a second master-slave relationship, and the second master-slave relationship indicates that the functional device is a master device and the target device is a slave device.
[0176] The following describes the steps 502 and 503:
[0177] As described above, the functional device can determine whether the target device can act as a master device and a slave device.
[0178] Based on this, in a case where the target device is determined to be unable to act as a slave device but able to act as a master device, it is determined that the entire master-slave relationship between the functional device and the target device includes a first master-slave relationship, and the first master-slave relationship indicates that the target device is a master device and the functional device is a slave device.
[0179] In a case where the target device is determined to be able to act as a slave device and able to act as a master device, it is determined that the entire master-slave relationship between the functional device and the target device includes a first master-slave relationship and a second master-slave relationship, and the second master-slave relationship indicates that the functional device is a master device and the target device is a slave device.
[0180] The technical scheme provided by the embodiments of the present application determines whether the target device is a slave device by taking the functional device as a master device, and determines whether the target device is a master device by taking the functional device as a slave device, determines that the master-slave relationship between the functional device and the target device includes the first master-slave relationship in the case that the target device cannot be a slave device but can be a master device, the first master-slave relationship indicating that the target device is a master device and the functional device is a slave device, and determines that the master-slave relationship between the functional device and the target device includes the first master-slave relationship and the second master-slave relationship in the case that the target device can be a slave device and can be a master device, the second master-slave relationship indicating that the functional device is a master device and the target device is a slave device.
[0181] The technical scheme determines whether the target device can be a master device and a slave device by taking the functional device as a master device and a slave device respectively, so as to determine the master-slave relationship between the functional device and the target device, and thus quickly and accurately determines the master-slave relationship between the functional device and the target device, and thus accurately determines the device type of the target device.
[0182] FIG. 6 is an embodiment flowchart of another device interaction method provided by the embodiments of the present application. The flowchart shown in FIG. 6 describes how to determine the device type of the target device based on the master-slave relationship and how to determine the target resource device for obtaining the preset functional resource from the functional device and the target device according to the device type based on the flowchart shown in FIG. 5. As shown in FIG. 6, the flowchart can include the following steps:
[0183] Step 601: Determine whether the master-slave relationship is the first master-slave relationship, if yes, perform step 602; if no, perform step 603.
[0184] Step 602: In the case that the master-slave relationship is the first master-slave relationship and the second master-slave relationship, determine that the device type of the target device is the first type.
[0185] Step 603: In the case that the master-slave relationship is the first master-slave relationship, determine that the device type of the target device is the second type.
[0186] The following uniformly describes steps 601 to 603:
[0187] In the embodiments of the present application, the device type can be divided into a first type and a second type. The first type can be used to represent a device type that can act as a master device and a slave device, which can be a mobile terminal device, such as a mobile phone or a tablet, etc. The second type can be used to represent a device type that only acts as a master device, which can be a PC terminal device, such as a computer or a notebook, etc. It can be understood that the device type can also include a third type that only acts as a slave device, and / or a fourth type that neither acts as a master device nor a slave device, and the embodiments of the present application do not limit this.
[0188] Based on this, in the case where it is determined that all master-slave relationships are the first master-slave relationship and the second master-slave relationship, it is explained that the target device at this time can act as a master device and a slave device, which meets the standard of a mobile terminal device, and therefore the device type of the target device can be determined as the first type.
[0189] Optionally, in the case where it is determined that all master-slave relationships are the first master-slave relationship, it is explained that the target device at this time can only act as a master device, which meets the standard of a PC terminal device, and therefore the device type of the target device can be determined as the second type.
[0190] Optionally, in the case where it is determined that the master-slave relationship is the third master-slave relationship in which the function device is a master device and the target device is a slave device, the device type of the target device can be determined as the third type, such as a U disk.
[0191] Optionally, in the case where it is determined that there is no master-slave relationship between the two, the device type of the target device can be determined as the fourth type.
[0192] Step 604: determining a target resource device for obtaining a preset function resource from the function device and the target device according to the device type.
[0193] Step 605: controlling the function device to implement a preset function by using the function resource in the target resource device.
[0194] The following describes steps 604 and 605:
[0195] As can be seen from the above steps, the device type can include the first type and the second type, and since the third type and the fourth type do not involve the function device obtaining the function resource from the target device, the device type belonging to the third type and the fourth type is not involved in this step.
[0196] Based on this, when it is determined that the device type of the target device is the first type, it is explained that the target device at this time is a mobile terminal device (such as a mobile phone), and the function resource of this kind of device is limited, such as a charging function, which cannot be connected to an adapter to work, and therefore the function device can be determined as the target resource device, and the preset function can be implemented by using the function resource in the function device.
[0197] To facilitate understanding of how the first type of target device is determined in the embodiments of the present application, the following takes a phone as an example to illustrate the embodiments of the present application.
[0198] FIG. 7 is an embodiment flowchart of interaction between a first type of device and a target device according to an embodiment of the present application. As shown in FIG. 7, the flowchart can include the following steps:
[0199] When a phone accesses a sound box, the sound box identifies the phone. The detailed flowchart is as follows:
[0200] (1) Power on, the device sets itself as a USB Host mode. When a phone accesses a sound box, the sound box detects that an external device is connected;
[0201] (2) The sound box resets the bus and sends an instruction to the phone to obtain a device descriptor;
[0202] (3) The phone, which can be a Host mode or a Slave mode, normally responds to the instruction to obtain a device descriptor sent by the sound box;
[0203] (4) The sound box and the phone can establish an effective connection as a Host mode. It can be determined that the external device connected to the sound box is a Slave mode device;
[0204] (5) The sound box sets itself as a USB Slave mode and resets the USB port;
[0205] (6) The phone detects that an external device is connected to the USB port and sends an instruction to the sound box to obtain a device descriptor. The sound box normally responds to the instruction of the phone;
[0206] (7) After the complete enumeration process of the USB, the sound box communicates with the phone through the UAC protocol. After normal communication, it can be determined that the external device connected to the sound box is a phone.
[0207] The complete enumeration process of the USB of the master device and the slave device can include a first stage, a second stage, a third stage, a fourth stage, and a fifth stage.
[0208] In the first stage, the host device resets the bus and sends a request device descriptor to the slave device, and the slave device can return the device descriptor; in the second stage, the host device can reset the bus, send a request set address, and based on this, the slave device can enable a new address; in the third stage, the host device can use the new address, send a request device descriptor, and the slave device returns the device descriptor; in the fourth stage, the host device can use the new address, send a request device configuration descriptor, and the slave device can return the configuration descriptor and a configuration descriptor set; in the fifth stage, the host device can send a set configuration request to the slave device. Based on this, the slave device sets the configuration, and in the case of successful configuration, data communication can be performed.
[0209] Optionally, when it is determined that the device type of the target device is the second type, it is indicated that the target device at this time is a PC device (for example, a computer), and the function resource of this kind of device is more, for example, a charging function, and the power is more and can be connected to an adapter to work, and therefore the target device can be determined as the target resource device for obtaining the preset function resource.
[0210] Further, the preset function can be implemented by using the function resource in the target device.
[0211] In order to facilitate understanding of how the second type of the target device is determined in the embodiments of the present application, the target device is taken as a computer, and the function device is taken as a sound box or a conference device as an example for example explanation:
[0212] Participate in Figure 8, an embodiment flow chart of a second type device interacting with a target device provided by the embodiments of the present application. As shown in Figure 8, the flow can include the following steps:
[0213] When the computer accesses the sound box, the detailed process that the sound box identifies the computer type is as follows:
[0214] (1) Power on, the function device sets itself to USB Host mode (host device mode), when the computer accesses the sound box, the sound box detects that there is an external device accessing;
[0215] (2) The sound box resets the bus and sends an instruction to the computer to obtain a device descriptor;
[0216] (3) At this time, the computer is a pure Host mode host and will not respond to the instruction of obtaining the device descriptor sent by the sound box, and the sound box is currently in Host mode and will not return a message;
[0217] (4) The sound box cannot establish an effective connection with the computer, and at this time it can be determined that the external device connected to the sound box is an external device only with Host mode;
[0218] (5) The sound box sets itself to USB Slave mode (slave device mode) and resets the USB port;
[0219] (6) At this time, the computer detects that the USB port has a peripheral access, resets the bus, and sends a request device descriptor instruction to the sound box, and the sound box normally replies to the computer request;
[0220] (7) After the normal USB complete enumeration process, the UAC protocol is communicated with the computer end, and after normal communication, it is determined that the peripheral access to the sound box is a computer product with only Host mode.
[0221] The above-mentioned USB complete enumeration process can include a first stage, a second stage, a third stage, a fourth stage, and a fifth stage.
[0222] In the first stage, the master device resets the bus and sends a request device descriptor to the slave device, and the slave device can return the device descriptor; in the second stage, the master device can reset the bus, send a request to set the address, and based on this, the slave device can enable a new address; in the third stage, the master device can use the new address to send a request device descriptor, and the slave device returns the device descriptor; in the fourth stage, the master device can use the new address to send a request device configuration descriptor, and the slave device can return the configuration descriptor and the configuration descriptor set; in the fifth stage, the master device can send a set configuration request to the slave device. Based on this, the slave device sets the configuration, and in the case of successful configuration, data communication can be performed.
[0223] The technical scheme provided by the embodiment of the application is that, in the case of determining that all master-slave relationships are the first master-slave relationship and the second master-slave relationship, the device type of the target device is determined to be the first type, in the case of determining that all master-slave relationships are the first master-slave relationship, the device type of the target device is determined to be the second type, according to the device type, the target resource device for obtaining the preset function resource is determined from the function device and the target device, and the function device is controlled to realize the preset function by using the function resource in the target resource device. This technical scheme determines the device type of the target device to be the first type or the second type through all master-slave relationships between the function device and the target device, which can simply and efficiently determine the device type of the target device according to the master-slave relationship, and realizes simple, efficient and fast determination of the device type of the target device.
[0224] In order to facilitate understanding of the device function implementation method provided by the embodiment of the application, the following takes the target device including computer devices and mobile phone devices, the function device as a sound box or an audio conference device, and the target function as a charging function as an example for description:
[0225] Referring to FIG. 9, an embodiment flowchart of another method for implementing device functions is provided in the embodiments of the present application. The flowchart shown in FIG. 9 is used to illustrate the method for implementing device functions provided in the embodiments of the present application, taking the target device as a computer device or a mobile phone device, the function device as an audio amplifier or an audio conference device, and the function resource as an electric quantity resource. As shown in FIG. 9, the flowchart can include the following steps:
[0226] 1. By default, the audio amplifier is set as a USB Host mode after power-on;
[0227] 2. When the audio amplifier detects that a peripheral device is connected to the USB port, the audio amplifier acquires the device descriptor information (including but not limited to: PID, VID, device type (here, the device type refers to the device attribute, which is inconsistent with the device type in the application) and the like) of the connected peripheral device through the USB standard protocol. The peripheral device is marked as a peripheral device with a USB Slave mode, otherwise, the peripheral device is marked as a peripheral device with only a USB Host mode;
[0228] 3. The audio amplifier switches itself to a USB Slave mode and resets the USB port;
[0229] 4. The peripheral device with only the Host mode can normally pass through the complete USB enumeration process, and thus it is considered as a computer peripheral device. The audio amplifier is prompted to use the power supply of a computer when it is working;
[0230] 5. The peripheral device with the Slave mode can normally pass through the complete USB enumeration process, and thus it is considered as a mobile phone peripheral device. The audio amplifier is prompted to use only the battery power supply of the audio amplifier and does not consume the power of the mobile phone when it is working;
[0231] 6. The peripheral device cannot pass through the complete USB enumeration process, and thus it is considered as another peripheral device with the master-slave device function but without the UAC function.
[0232] The technical solution provided in the embodiments of the present application can identify whether the computer is connected or the mobile phone is connected. Thus, when it is identified that the mobile phone is connected, the battery of the device is used as the power supply, and the power of the mobile phone or the tablet computer is not consumed, or the current for charging the device is controlled according to whether the computer is connected. The device type of the connected device is accurately judged and identified, so that the function resource is saved, the use efficiency of the target device is improved, and the user experience is improved.
[0233] Referring to FIG. 10, an embodiment block diagram of a device function implementation apparatus is provided in the embodiments of the present application. As an embodiment, the apparatus shown in FIG. 10 is applied to a function device, for example, the function device 11 shown in FIG. 1. As shown in FIG. 10, the apparatus can include:
[0234] The first determining module 101 is configured to determine the device type of the target device by switching master-slave working modes in a case where it is determined that the target device is connected.
[0235] The second determining module 102 is configured to determine a target resource device for obtaining a preset function resource from the function device and the target device based on the device type; the target resource device is the function device or the target device.
[0236] The implementing module 103 is configured to implement the preset function by using the function resource in the target resource device.
[0237] As shown in FIG. 11, another embodiment of a device function implementing apparatus provided by the embodiment of the present application is shown. As an embodiment, the apparatus shown in FIG. 11 is applied to a control device, which is different from the function device and the target device. As shown in FIG. 11, the apparatus can include:
[0238] The master-slave relationship determining module 111 is configured to determine all master-slave relationships corresponding to the function device and the target device in a case where it is determined that the function device is connected to the target device.
[0239] The device type determining module 112 is configured to determine the device type of the target device based on the all master-slave relationships.
[0240] The target determining module 113 is configured to determine a target resource device for obtaining a preset function resource from the function device and the target device based on the device type; the target resource device is the function device or the target device.
[0241] The control interaction module 114 is configured to control the function device to implement the preset function by using the function resource in the target resource device.
[0242] As shown in FIG. 12, a structural schematic diagram of an electronic device provided by the embodiment of the present application is shown, which includes a processor 121, a communication interface 122, a memory 123 and a communication bus 124. The processor 121, the communication interface 122 and the memory 123 complete mutual communication through the communication bus 124.
[0243] The memory 123 is configured to store a computer program.
[0244] In an embodiment of the present application, the processor 121 is configured to implement the device function implementing method provided by any one of the preceding method embodiments when executing the program stored in the memory 123, including:
[0245] In a case where it is determined that the target device is connected, the device type of the target device is determined by switching master-slave working modes.
[0246] determine a target resource device for obtaining a preset function resource from the function device and the target device based on the device type; the target resource device is the function device or the target device;
[0247] implement the preset function by using the function resource in the target resource device.
[0248] Alternatively,
[0249] In a case where it is determined that the function device is connected to the target device, determine all master-slave relationships corresponding to the function device and the target device;
[0250] determine the device type of the target device based on the all master-slave relationships;
[0251] determine a target resource device for obtaining a preset function resource from the function device and the target device based on the device type; the target resource device is the function device or the target device;
[0252] control the function device to implement the preset function by using the function resource in the target resource device.
[0253] In specific implementations, the present application further provides a computer storage medium, wherein the computer storage medium can store a program, and the program can include some or all steps in the foregoing embodiments when executed. The storage medium can be a magnetic disc, an optical disc, a read-only memory (ROM) or a random access memory (RAM), etc.
[0254] Those skilled in the art can clearly understand that the technology in the embodiments of the present application can be realized by means of software and necessary general hardware platforms. Based on such understanding, the technical solutions in the embodiments of the present application can be embodied in the form of a software product, which can be stored in a storage medium, such as a ROM / RAM, a magnetic disc, an optical disc, etc., and includes a number of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments of the present application.
[0255] The same or similar parts among the various embodiments in the specification can be referred to each other. In particular, for the … embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the description in the method embodiment.
[0256] The above-described embodiments of the present application are not intended to limit the scope of the present application.
Claims
1. A method of implementing a device function, the method comprising: The method is applied to a functional device, and the functional device obtains functional resources from itself or a target device when the functional device is connected to the target device to implement a preset function, and the method comprises the following steps: In a case where it is determined that the target device is connected, the device type of the target device is determined by switching master-slave working modes; Based on the device type, a target resource device for obtaining the preset functional resources is determined from the functional device and the target device; the target resource device is the functional device or the target device; The preset function is implemented by using the functional resources in the target resource device.
2. The method of claim 1, wherein, The device type of the target device is determined by switching master-slave working modes, and the method comprises the following steps: The working mode is set to a host mode, and it is determined whether the target device has a slave device function; The working mode is switched to a slave mode, and it is determined whether the target device has a master device function; It is determined whether the target device can communicate through a preset communication protocol; In a case where it is determined that the target device can communicate through the communication protocol, if it is determined that the target device has both the slave device function and the master device function, it is determined that the device type of the target device is a first type; In a case where it is determined that the target device can communicate through the communication protocol, if it is determined that the target device has the master device function and does not have the slave device function, it is determined that the device type of the target device is a second type.
3. The method of claim 2, wherein, The working mode of the USB interface is set to the host mode, and an instruction for obtaining a target device descriptor is sent to the target device through a preset USB standard protocol; In a case where the target device descriptor fed back by the target device is received, it is determined that the target device has the slave device function. The working mode of the USB interface is switched to the slave mode, and it is determined whether an instruction for obtaining a functional device descriptor sent by the target device is received through a preset USB standard protocol within a preset time period; 4. The method of claim 2, wherein, In a case where the instruction for obtaining the functional device descriptor sent by the target device is received within the preset time period, it is determined that the target device has the master device function. Based on the device type, a target resource device for obtaining the preset functional resources is determined from the functional device and the target device; the target resource device is the functional device or the target device; In a case where the device type is the first type, the functional device is determined as the target resource device for obtaining the functional resources; 5. The method according to any one of claims 2 to 4, characterized in that, In a case where the device type is the second type, the target device is determined as the target resource device for obtaining the functional resources. The functional resources are electric quantity resources, and the preset function is implemented by using the functional resources in the target resource device. 6. The method of claim 5, wherein, In a case where the target resource device is the target device, it is determined whether the target device is connected to an adapter, or whether a remaining power of the target device is greater than a preset power threshold; In a case where it is determined that the target device is connected to the adapter, or the remaining power of the target device is greater than the power threshold, a preset function is implemented by using a power resource in the target device; In a case where the target resource device is the function device, the preset function is implemented by using a power resource in the function device.
7. The method of claim 5, wherein, The function resource is a power resource, and the implementation of the preset function by using the function resource in the target resource device comprises: generating a preset prompt information according to the target resource device, the prompt information being used for prompting whether to acquire a function resource through the target resource device; displaying the prompt information through the target device; when a reply message indicating that the function resource is acquired through the target resource device is received, implementing the preset function by using the function resource in the target resource device.
8. A method of implementing a device function, the method comprising: The method is applied to a control device, the control device being different from a function device and a target device, and the control device controls the function device to acquire a function resource from the control device or the target device when the control device controls the function device to connect to the target device to implement a preset function, and the method comprises: In a case where the function device is connected to the target device, determining all master-slave relationships corresponding to the function device and the target device; determining a device type of the target device based on the all master-slave relationships; based on the device type, determining a target resource device acquiring a preset function resource from the function device and the target device; the target resource device being the function device or the target device; controlling the function device to implement the preset function by using the function resource in the target resource device.
9. An apparatus function implementation device, characterized by The device is applied to a function device, and the function device acquires a function resource from the function device or a target device when the function device is connected to the target device to implement a preset function, and the device comprises: a first determination module configured to determine a device type of a target device by switching a master-slave working mode in a case where the function device is connected to the target device; a second determination module configured to determine a target resource device acquiring a preset function resource from the function device and the target device based on the device type; the target resource device being the function device or the target device; an implementation module configured to implement the preset function by using the function resource in the target resource device.
10. An apparatus function implementation device, characterized by The device is applied to a control device, the control device being different from a function device and a target device, and the control device controls the function device to acquire a function resource from the control device or the target device when the control device controls the function device to connect to the target device to implement a preset function, and the device comprises: a master-slave relationship determination module configured to determine all master-slave relationships corresponding to the function device and the target device in a case where the function device is connected to the target device. A device type determining module is configured to determine a device type of the target device based on the master-slave relationship; A target determining module is configured to determine a target resource device for obtaining a preset function resource from the function device and the target device based on the device type; the target resource device is the function device or the target device; A control interaction module is configured to control the function device to implement the preset function by using the function resource in the target resource device.
Citation Information
Patent Citations
Modular system having expandable form factor
CN102566675A
Dynamic configuration of connectors for system level communications
CN102845046A
Design of USB dual-mode interface equipment for UART acquisition terminal
CN103294626A
Charge-discharge method and device for intelligent terminal, terminal and storage medium
CN108054794A
Charging control method, electronic equipment and charging control system
CN115882535A