Summary of the invention
Technical problem to be solved by this invention is: provide a kind of method based on the bidirectional balanced electricity of USB-OTG and device, realizes two equipment and mutually can obtain the other side's information about power and perform charging mutually.
In order to solve the problems of the technologies described above, the technical solution used in the present invention is:
Based on a method for the bidirectional balanced electricity of USB-OTG, comprising:
S101, identify the ID pin whether ground connection of the USB-OTG interface of the first equipment, described first equipment is provided with the first battery, if recognize the ID pin ground connection of the first equipment, then enters step S102;
If the ID pin ground connection of the unidentified USB-OTG interface to the first equipment, then identify the ID pin whether ground connection of the USB-OTG interface of the second equipment, described second equipment is provided with the second battery, if recognize the ID pin ground connection of the second equipment, then enters step S103;
If the unidentified ID pin ground connection to the second equipment, then enter step S104;
S102, when recognizing the ID pin ground connection of the first equipment, described second equipment reads the first battery electric quantity of described first equipment, the first residue stand-by time of the first equipment is calculated according to gained first battery meter, described second equipment reads the second battery electric quantity, the second residue stand-by time is calculated according to gained second battery meter, described second residue stand-by time and described first is remained stand-by time compare, if residue stand-by time difference is greater than pre-set threshold value, then calculate the first charging duration according to gained first battery electric quantity and the second battery meter, second equipment charges duration to the first equipment charge according to described first, if residue stand-by time difference is less than or equal to pre-set threshold value, then enter step S104,
S103, when recognizing the ID pin ground connection of the second equipment, described first equipment reads the second battery electric quantity of described second equipment, the second residue stand-by time of the second equipment is calculated according to gained second battery meter, described first equipment reads the first battery electric quantity, the first residue stand-by time is calculated according to gained first battery meter, described first residue stand-by time and described second is remained stand-by time compare, if residue stand-by time difference is greater than pre-set threshold value, then calculate the second charging duration according to gained second battery electric quantity and the first battery meter, first equipment charges duration to the second equipment charge according to described second, if residue stand-by time difference is less than or equal to pre-set threshold value, then enter step S104,
S104, end current process.
Another technical scheme that the present invention adopts is:
Based on a device for the bidirectional balanced electricity of USB-OTG, comprising: identification module, the first processing module, the second processing module and end module;
Described identification module comprises the first recognition unit and the second recognition unit;
Described first recognition unit, for identifying the ID pin whether ground connection of described first equipment;
Described second recognition unit, for identifying the ID pin whether ground connection of described second equipment;
Described first processing module comprises the first reading unit, the first computing unit, the first comparing unit and the first charhing unit;
Described first reading unit, reads the first battery electric quantity of the second battery electric quantity and the first equipment for the second equipment;
Described first computing unit, for calculating the first residue stand-by time of the first equipment and calculating the second residue stand-by time of the second equipment according to the first reading unit gained second battery meter according to the first reading unit gained first battery meter;
Described first comparing unit, compares for second of described first computing unit gained the residue stand-by time and first is remained stand-by time;
Described first charhing unit, if be greater than pre-set threshold value for residue stand-by time difference, then calculate the first charging duration according to gained first battery electric quantity and the second battery meter, the second equipment charges duration to the first equipment charge according to described first;
Described second processing module comprises the second reading unit, the second computing unit, the second comparing unit and the second charhing unit;
Described second reading unit, reads the second battery electric quantity of the first battery electric quantity and the second equipment for the first equipment;
Described second computing unit, for calculating the second residue stand-by time of the second equipment and calculating the first residue stand-by time of the first equipment according to the second reading unit gained first battery meter according to the second reading unit gained second battery meter;
Described second comparing unit, compares for first of described second computing unit gained the residue stand-by time and second is remained stand-by time;
Described second charhing unit, if be greater than pre-set threshold value for residue stand-by time difference, then calculate the second charging duration according to gained second battery electric quantity and the first battery meter, the first equipment charges duration to the second equipment charge according to described second;
Described end module, for terminating current process.
Beneficial effect of the present invention is: by identifying the ID pin whether ground connection of the USB-OTG interface of the first equipment or the second equipment, judge the master slave relation of the first equipment and the second equipment, if the ID pin ground connection of the first equipment, then the second equipment is main, first equipment be from, described second equipment is to the first equipment charge, if the ID pin ground connection of the second equipment, then the first equipment is main, second equipment be from, described first equipment is to the second equipment charge, by be read as main equipment from the information about power of equipment, judge whether to charge with for main equipment information about power compares, if residue stand-by time difference is greater than pre-set threshold value, then by for main equipment to for from equipment charge, realize two equipment mutually to obtain the other side's information about power and perform charging mutually.The electricity being realized two equipment by the present invention is complementary, and keeps balance, ensures that whole system makes full use of battery on two equipment to realize maximum stand-by time.
Embodiment
By describing technology contents of the present invention in detail, realized object and effect, accompanying drawing is coordinated to be explained below in conjunction with execution mode.
The design of most critical of the present invention is: by identifying the ID pin whether ground connection of the USB-OTG interface of the first equipment or the second equipment, judge the master slave relation of the first equipment and the second equipment, compare according to the information about power of the first equipment and the second equipment and judge whether to charge, if, by for main equipment to for from equipment charge, realize two equipment and mutually can obtain the other side's information about power and perform and mutually charge.
Please refer to Fig. 1, is the flow chart of the method based on the bidirectional balanced electricity of USB-OTG in the specific embodiment of the invention, specific as follows:
Based on a method for the bidirectional balanced electricity of USB-OTG, comprising:
S101, identify the ID pin whether ground connection of the USB-OTG interface of the first equipment, described first equipment is provided with the first battery, if recognize the ID pin ground connection of the first equipment, then enters step S102;
If the ID pin ground connection of the unidentified USB-OTG interface to the first equipment, then identify the ID pin whether ground connection of the USB-OTG interface of the second equipment, described second equipment is provided with the second battery, if recognize the ID pin ground connection of the second equipment, then enters step S103;
If the unidentified ID pin ground connection to the second equipment, then enter step S104;
S102, when recognizing the ID pin ground connection of the first equipment, described second equipment reads the first battery electric quantity of described first equipment, the first residue stand-by time of the first equipment is calculated according to gained first battery meter, described second equipment reads the second battery electric quantity, the second residue stand-by time is calculated according to gained second battery meter, described second residue stand-by time and described first is remained stand-by time compare, if residue stand-by time difference is greater than pre-set threshold value, then calculate the first charging duration according to gained first battery electric quantity and the second battery meter, second equipment charges duration to the first equipment charge according to described first, if residue stand-by time difference is less than or equal to pre-set threshold value, then enter step S104,
S103, when recognizing the ID pin ground connection of the second equipment, described first equipment reads the second battery electric quantity of described second equipment, the second residue stand-by time of the second equipment is calculated according to gained second battery meter, described first equipment reads the first battery electric quantity, the first residue stand-by time is calculated according to gained first battery meter, described first residue stand-by time and described second is remained stand-by time compare, if residue stand-by time difference is greater than pre-set threshold value, then calculate the second charging duration according to gained second battery electric quantity and the first battery meter, first equipment charges duration to the second equipment charge according to described second, if residue stand-by time difference is less than or equal to pre-set threshold value, then enter step S104,
S104, end current process.
From foregoing description, beneficial effect of the present invention is: by identifying the ID pin whether ground connection of the USB-OTG interface of the first equipment or the second equipment, judge the master slave relation of the first equipment and the second equipment, if the ID pin ground connection of the first equipment, then the second equipment is main, first equipment be from, described second equipment is to the first equipment charge, if the ID pin ground connection of the second equipment, then the first equipment is main, second equipment be from, described first equipment is to the second equipment charge, by be read as main equipment from the information about power of equipment, judge whether to charge with for main equipment information about power compares, if residue stand-by time difference is greater than pre-set threshold value, then by for main equipment to for from equipment charge, realize two equipment mutually to obtain the other side's information about power and perform charging mutually.The electricity being realized two equipment by the present invention is complementary, and keeps balance, ensures that whole system makes full use of battery on two equipment to realize maximum stand-by time.
Further, described step S102 also comprises: be connected with power electric by pull-up resistor by D+ or the D-pin of the first equipment with the USB-OTG interface of the second equipment.
Seen from the above description, D+ or the D-pin of the USB-OTG interface of the first equipment and the second equipment electrically connects as the prerequisite of identification id pin by pull-up resistor and power supply.
Further, " calculate the first charging duration " in described step S103 to be specially: the first battery electric quantity the second battery electric quantity of described second equipment being deducted described first equipment, second equipment that electricity difference is multiplied by, to unit capacity charging interval coefficient during the first equipment charge, obtains the first charging duration of the second equipment to the first equipment;
" calculate the second charging duration " in described step S104 to be specially: the second battery electric quantity the first battery electric quantity of described first equipment being deducted described second equipment, first equipment that electricity difference is multiplied by, to unit capacity charging interval coefficient during the second equipment charge, obtains the second charging duration of the first equipment to the second equipment.
Seen from the above description, according to calculating first charge duration or second charging duration obtain charging duration, according to charging duration charge, two equipment can be made to reach the electricity of balance.
Further, in described step S102, " described first equipment reads the second battery electric quantity of described second equipment " is read by USB interface; In described step S103, " described second equipment reads the first battery electric quantity of described first equipment " is read by USB interface.
Seen from the above description, the battery electric quantity obtaining another equipment is read by USB interface, and current most smart mobile phone all possesses USB interface, has generality, is convenient to application.
Further, described step S104 also comprises and returns S101 step, is specially: after waiting for the interval duration of 5 minutes, return step S101.Wait for that interval duration is to calibrate the dump energy ratio of two equipment, reducing the electric quantity loss that unnecessary charging causes.Wait for that the installation warrants of interval duration is that the electricity of initial judgement two equipment room is poor, interval duration balances the charging interval needed for electricity difference, interval duration=electricity difference (mAh unit)/charging current (mA unit)/2* charge efficiency.(except 2 is because an equipment electricity increase, an equipment electricity reduce).
Referring to Fig. 2, is the structural representation of the device based on the bidirectional balanced electricity of USB-OTG in the specific embodiment of the invention, specific as follows:
Based on a device for the bidirectional balanced electricity of USB-OTG, comprising: identification module 1, first processing module 2, second processing module 3 and end module 4;
Described identification module 1 comprises the first recognition unit 11 and the second recognition unit 12;
Described first recognition unit 11, for identifying the ID pin whether ground connection of described first equipment;
Described second recognition unit 12, for identifying the ID pin whether ground connection of described second equipment;
Described first processing module 2 comprises the first reading unit 21, first computing unit 22, first comparing unit 23 and the first charhing unit 24;
Described first reading unit 21, reads the first battery electric quantity of the second battery electric quantity and the first equipment for the second equipment;
Described first computing unit 22, for calculating the first residue stand-by time of the first equipment and calculating the second residue stand-by time of the second equipment according to the first reading unit 21 gained second battery meter according to the first reading unit 21 gained first battery meter;
Described first comparing unit 23, compares for second of described first computing unit 22 gained the residue stand-by time and first is remained stand-by time;
Described first charhing unit 24, if be greater than pre-set threshold value for residue stand-by time difference, then calculate the first charging duration according to gained first battery electric quantity and the second battery meter, the second equipment charges duration to the first equipment charge according to described first;
Described second processing module 3 comprises the second reading unit 31, second computing unit 32, second comparing unit 33 and the second charhing unit 34;
Described second reading unit 31, reads the second battery electric quantity of the first battery electric quantity and the second equipment for the first equipment;
Described second computing unit 32, for calculating the second residue stand-by time of the second equipment and calculating the first residue stand-by time of the first equipment according to the second reading unit 31 gained first battery meter according to the second reading unit 31 gained second battery meter;
Described second comparing unit 33, compares for first of described second computing unit 32 gained the residue stand-by time and second is remained stand-by time;
Described second charhing unit 34, if be greater than pre-set threshold value for residue stand-by time difference, then calculate the second charging duration according to gained second battery electric quantity and the first battery meter, the first equipment charges duration to the second equipment charge according to described second;
Described end module 4, for terminating current process.
From foregoing description, beneficial effect of the present invention is: by identifying the ID pin whether ground connection of the USB-OTG interface of the first equipment or the second equipment, judge the master slave relation of the first equipment and the second equipment, if the ID pin ground connection of the first equipment, then the second equipment is main, first equipment be from, described second equipment is to the first equipment charge, if the ID pin ground connection of the second equipment, then the first equipment is main, second equipment be from, described first equipment is to the second equipment charge, by be read as main equipment from the information about power of equipment, judge whether to charge with for main equipment information about power compares, if residue stand-by time difference is greater than pre-set threshold value, then by for main equipment to for from equipment charge, realize two equipment mutually to obtain the other side's information about power and perform charging mutually.The electricity being realized two equipment by the present invention is complementary, and keeps balance, ensures that whole system makes full use of battery on two equipment to realize maximum stand-by time.
Further, described identification module 1 also comprises power subsystem, for being connected with power electric by pull-up resistor by D+ or the D-pin of the first equipment with the USB-OTG interface of the second equipment.
Seen from the above description, D+ or the D-pin of the first equipment and the second equipment electrically connects as the prerequisite of identification id pin by pull-up resistor and power supply.
Further, described first computing unit 22 also comprises the first subtracter, the first multiplier and the first parameter setting device;
Described first subtracter, for deducting the first battery electric quantity of described first equipment by the second battery electric quantity of described second equipment;
Described first multiplier, for being multiplied by the second equipment to unit capacity charging interval coefficient during the first equipment charge by electricity difference;
Described first parameter setting device, for arranging the second equipment to unit capacity charging interval coefficient during the first equipment charge;
Described second computing unit 32 also comprises the second subtracter, the second multiplier and the second parameter setting device;
Described second subtracter, for deducting the second battery electric quantity of described second equipment by the first battery electric quantity of described first equipment;
Described second multiplier, for being multiplied by the first equipment to unit capacity charging interval coefficient during the second equipment charge by electricity difference;
Described second parameter setting device, for arranging the first equipment to unit capacity charging interval coefficient during the second equipment charge.
Seen from the above description, according to calculating first charge duration or second charging duration obtain charging duration, according to charging duration charge, two equipment can be made to reach the electricity of balance.
Further, described first reading unit 21 comprises the first USB interface, for obtaining the second battery electric quantity of described second equipment; Described second reading unit 31 comprises secondary USB interface, for obtaining the first battery electric quantity of described first equipment.
Seen from the above description, the battery electric quantity obtaining another equipment is obtained by USB, and current most smart mobile phone all possesses USB interface, has generality, is convenient to application.
Further, described end module comprises wait unit and returns unit;
Described wait unit, for waiting for the interval duration of 5 minutes; Interval duration=electricity difference (mAh unit)/charging current (mA unit)/2* charge efficiency
Describedly returning unit, identifying for turning back to identification module.
Seen from the above description, wait for that certain interval duration carries out identification id pin whether ground connection again, avoid lasting identification to cause the wasting of resources, separately prove through test: the interval duration waiting for 5 minutes, can reach the highest resource utilization.
Refer to Fig. 3 to Fig. 4, by arranging the first controllable electronic switch K1 at the ID pin of the first equipment and the second equipment, according to control electronic switch, the ID pin ground connection of which equipment can be controlled, by arranging the second controllable electronic switch K2, D+ or the D-network that can control the USB of two equipment by a 1.5K pull-up resistor Electricity Federation to power supply, object be in order to can allow be in master slave relation for from equipment repeatedly enumerated, by arranging the 3rd controllable electronic switch K3, be used for controlling to be switched on or switched off the VBUS network of the first equipment and the second equipment, can Artificial Control cut off where necessary the charging of two equipment rooms with by the relation of charging.According to above three controllable electronic switches, by the charge condition of manual observation two equipment, then result hand-guided three controllable electronic switches according to the observation, realize control be by the first equipment to the second equipment charge or by the second equipment to the first equipment charge.
Further, the bidirectional switch function of the first controllable electronic switch K1 can be realized with two metal-oxide-semiconductors and not gate.
Further, under Android system, device battery electricity can be obtained by function.
Further, provided by the inventionly judge whether that the condition of carrying out charging is two equipment residue stand-by time differences and the comparing of pre-set threshold value, described in judge whether that the condition of carrying out charging can also be the cell voltage of two equipment or the battery dump energy of two equipment.
In sum, a kind of method based on the bidirectional balanced electricity of USB-OTG provided by the invention and device, by identifying the ID pin whether ground connection of the USB-OTG interface of the first equipment or the second equipment, judge the master slave relation of the first equipment and the second equipment, if the ID pin ground connection of the first equipment, then the second equipment is main, first equipment be from, described second equipment is to the first equipment charge, if the ID pin ground connection of the second equipment, then the first equipment is main, second equipment be from, described first equipment is to the second equipment charge, by be read as main equipment from the information about power of equipment, judge whether to charge with for main equipment information about power compares, if residue stand-by time difference is greater than pre-set threshold value, then by for main equipment to for from equipment charge, realize two equipment mutually to obtain the other side's information about power and perform charging mutually.The electricity being realized two equipment by the present invention is complementary, and keeps balance, ensures that whole system makes full use of battery on two equipment to realize maximum stand-by time.D+ or the D-pin of the first equipment and the second equipment is the prerequisite of identification id pin by pull-up resistor Electricity Federation power supply.According to calculating first charge duration or second charging duration obtain charging duration, according to charging duration charge, two equipment can be made to reach the electricity of balance.The battery electric quantity obtaining another equipment is obtained by USB, and current most smart mobile phone all possesses USB interface, has generality, is convenient to application.
The foregoing is only embodiments of the invention; not thereby the scope of the claims of the present invention is limited; every equivalents utilizing specification of the present invention and accompanying drawing content to do, or be directly or indirectly used in relevant technical field, be all in like manner included in scope of patent protection of the present invention.