Abstract:
An embodiment of the invention provides an orientation detection method for a portable device. The method comprises acquiring an accelerometer data, determining whether the portable device is in a flat status, determining whether the portable device is in a stable status, and when the portable device is determined in both the flat status and the stable status, stopping acquiring the accelerometer data until receiving an enable signal.

Description:
CROSS REFERENCE TO RELATED APPLICATIONS 
     This application claims the benefit of U.S. Provisional Application No. 61/531,520 filed 6 Sep. 2011, the entirety of which is incorporated by reference herein. 
    
    
     BACKGROUND OF THE INVENTION 
     1. Field of the Invention 
     The present invention relates to a portable device, and in particular relates to the portable device with orientation detection mechanism. 
     2. Description of the Related Art 
     In recent years, portable devices, such as mobile phones, smart phones or personal digital assistants, have become ubiquitous and most people have become more and more dependent on portable devices in their the daily lives. The design of the portable devices is moving toward light, thin, short, and small specification, which limits the space for batteries. Furthermore, more and more functions, devices or modules are being integrated into portable devices, such that overall power required for the portable devices is increasing. Thus, power consumption has become an increasingly important factor in the design of portable devices. 
     BRIEF SUMMARY OF THE INVENTION 
     An embodiment of the invention provides an orientation detection method for a portable device. The method comprises acquiring an accelerometer data, determining whether the portable device is in a flat status, determining whether the portable device is in a stable status, and when the portable device is determined in both the flat status and the stable status, stopping acquiring the accelerometer data until receiving an enable signal. 
     Another embodiment of the invention provides a portable device comprising an accelerometer and a processor. The processor queries the accelerometer to acquire an accelerometer data to determine whether the portable device is in both the flat status and the stable status, and when the portable device is determined in both the flat status and the stable status, the processor stops querying the accelerometer data until the processor receives an enable signal. 
     A detailed description is given in the following embodiments with reference to the accompanying drawings. 
    
    
     
       BRIEF DESCRIPTION OF THE DRAWINGS 
       The present invention can be more fully understood by reading the subsequent detailed description and examples with references made to the accompanying drawings, wherein: 
         FIG. 1  is a flowchart of an orientation detection algorithm according to an embodiment of the invention. 
         FIG. 2  is a flowchart of an orientation detection algorithm according to another embodiment of the invention. 
         FIG. 3  is a flowchart of an orientation detection algorithm according to another embodiment of the invention. 
         FIGS. 4A and 4B  show a flowchart of an orientation detection algorithm according to another embodiment of the invention. 
         FIG. 5  is a block diagram of a portable device having the described orientation detection mechanism according to an embodiment of the invention. 
     
    
    
     DETAILED DESCRIPTION OF THE INVENTION 
     The following description is of the best-contemplated mode of carrying out the invention. This description is made for the purpose of illustrating the general principles of the invention and should not be taken in a limiting sense. The scope of the invention is best determined by reference to the appended claims. 
     A G-sensor is usually an accelerometer. It measures the forces that act on it during changes in velocity. Generally, portable devices or handheld devices use G-sensors to align a screen based on upon which direction the portable device is held. It changes the orientation according to the accelerometer output. According to some portable device implementations with G-sensors, the operating system or the processor of the portable device may query accelerometer data at a predetermined sample rate to determine the orientation of the portable device. However, a high sample rate wastes processor resources when data is queried. Thus, the present disclosure provides an innovative orientation detection algorithm to reduce power consumption when the G-sensor is queried. 
     Please refer to  FIG. 1 .  FIG. 1  is a flowchart of an orientation detection algorithm according to an embodiment of the invention. In step S 11 , the orientation detection algorithm is enabled. The timing to enable the orientation detection algorithm can be determined according to need of a designer. The orientation detection algorithm is enabled when an application program that requires information of device orientation for processing is executed. These application program lists may include the desktop program which is automatically launched when device is turned on. For example, some browser application or gaming required orientation information to align the screen. 
     In step S 12 , the processor (or called CPU) of the portable device acquires the accelerometer data from the G-sensor and calculates current angles (tilt and rotation angle) of the portable device. The processor can further determine an orientation direction according to two calculated angles. 
     After calculating the current angle, step S 13  is performed. In step S 13 , the orientation detection algorithm determines whether the portable device is in a flat status. The flat status is determined according to an absolute value of a tilt angle and a rotation angle of the portable device. If the absolute value is less than Zt (tilt angle) and Zr (rotation angle) degrees, the portable device is determined to be in a flat status. In other words, if the tilt angle and the rotation angle of the portable device range from −Zt degrees to Zt degrees (tilt angle) and from −Zr to Zr degrees (rotation angle), the portable device is determined to be in a flat status. Note that both the tilt angle and the rotation angle of the portable device are considered for the determination of the flat status of the portable device in this embodiment. 
     When the portable device is not in the flat status, step S 15  is performed, wherein the processor sleeps for a first duration (S 1 -A duration), such as 200 ms, and then the processor repeats the operation of step S 12 . When the portable device is in the flat status, step S 14  is performed, wherein the processor determines whether the portable device is in a stable condition. The stable condition is determined according to a second duration (S 1 -B duration) in which the portable device is in the flat status. If the second duration exceeds a threshold (S 1 -C duration as threshold), the portable device is determined to be in the stable condition, and step S 16  is performed. If the second duration does not exceed the threshold, step S 15  is performed, wherein the processor sleeps for a first duration, such as 200 ms, and then the processor repeats the operation of step S 12 . 
     In step S 16 , the processor of the portable device enables a flat interrupt function of the G-sensor. It is noted that not every G-sensor has the flat interrupt function, and the present orientation detection algorithm is customized for those G-sensors with the flat interrupt function. One pin of the G-sensor is coupled to a GPIO pin of the processor of the portable device. When the G-sensor detects that the portable device is not in the flat status, the G-sensor transmits a flat interrupt signal to the processor. In this embodiment, the steps S 13  and S 14  are executed by a processor of the portable device, but the flat status in steps S 16  and S 17  are determined by the G-sensor. In step S 17 , the G-sensor waits for the interrupt event. In this embodiment, the interrupt event represents the posture status change of the portable device. For example, if the tilt angle or the rotation angle of the portable device exceeds a predetermined angle, the interrupt event is determined to have occurred and the G-sensor outputs a flat interrupt signal to the processor of the portable device. In step S 17 , the processor of the portable device does not query for the accelerometer data to reduce waste of resources and power consumption of the processor. 
     In step S 18 , after the processor receives the flat interrupt signal, the processor acquires the accelerometer data to calculate the tilt angle and the rotation angle of the portable device. Then, step S 19  is performed to determine whether the portable device is still in the flat status. If the processor determines that the portable device is still in the flat status, step S 17  is performed. If the processor determines that the portable device is not in the flat status, step S 12  is performed. 
       FIG. 2  is a flowchart of an orientation detection algorithm according to another embodiment of the invention. In step S 21 , the processor (or called CPU) of the portable device acquires the accelerometer data from the accelerometer and calculates a current angle of the portable device. The processor can further determine an orientation direction according to two calculated angles. 
     After calculating the current angle, step S 22  is performed. In step S 22 , the orientation detection algorithm determines whether the portable device is in a flat status. The flat status is determined according to an absolute value of a tilt angle and a rotation angle of the portable device. If the absolute value is less than Zt and Zr degrees, the portable device is determined to be in a flat status. In other words, if the tilt angle and the rotation angle of the portable device range from −Zt degrees to Zt degrees (tilt angle) and from −Zr to Zr degrees (rotation angle), the portable device is determined to be in a flat status. Note that both the tilt angle and the rotation angle of the portable device are considered for the determination of the flat status of the portable device in this embodiment. 
     When the portable device is not in the flat status, step S 24  is performed. In step S 24 , the processor queries the accelerometer at a first rate (with S 2 -A duration as the interval). In other words, the processor sleeps for a first duration (S 2 -A), such as 200 ms, and then the processor repeats the operation of step S 21  to acquire the accelerometer data. When the portable device is in the flat status, step S 23  is performed, wherein the processor determines whether the portable device is in a stable condition in step S 23 . The stable condition is determined according to a second duration (S 2 -B duration) in which the portable device is in the flat status. If the second duration exceeds a threshold (S 2 -C duration as threshold), the portable device is determined to be in the stable condition, and step S 25  is performed. In one embodiment, the threshold (S 2 -C) may be 1000 ms. If the second duration does not exceed the threshold, step S 24  is performed, wherein the processor sleeps for a first duration (S 2 -A), such as 200 ms, and then the processor repeats the operation of step S 21 . 
     In step S 25 , the processor queries the accelerometer at a second rate (with S 2 -D duration as the interval). In other words, the processor sleeps for a third duration (S 2 -D), such as 600 ms, and then the processor repeats the operation of step S 21  to acquire the accelerometer data. 
     The main feature of the orientation detection algorithm shown in  FIG. 2  uses two different query rates for the processor of the portable device. If the portable device is in the flat status and stable, the processor queries the accelerometer at the second rate (with S 2 -D as the interval), and if the portable device is not in the flat status or is not stable, the processor queries the accelerometer at the first rate (with S 2 -A as the interval), wherein the first rate is faster than the second rate (with S 2 -D as the interval). 
       FIG. 3  is a flowchart of an orientation detection algorithm according to another embodiment of the invention. In step S 31 , the orientation detection algorithm is enabled. The timing to enable the orientation detection algorithm can be determined according to need of a designer. In step S 32 , the processor (or called CPU) of the portable device acquires the accelerometer data from the accelerometer and calculates a current angle of the portable device. The processor can further determine an orientation direction according to two calculated angles. 
     After calculating the current angle, step S 33  is performed. In step S 33 , the orientation detection algorithm determines whether the portable device is in a flat status. The flat status is determined according to an absolute value of a tilt angle and a rotation angle of the portable device. If the absolute value is less than Zt and Zr degrees, the portable device is determined to be in a flat status. In other words, if the tilt angle and the rotation angle of the portable device range from −Zt degrees to Zt degrees (tilt angle) and from −Zr to Zr degrees (rotation angle), the portable device is determined to be in a flat status. Note that both the tilt angle and the rotation angle of the portable device are considered for the determination of the flat status of the portable device in this embodiment. 
     When the portable device is not in the flat status, step S 34  is performed, wherein the processor queries the accelerometer at a first rate (with S 3 -A duration as the interval). In other words, the processor sleeps for a first duration (S 3 -A), such as 200 ms, and then the processor repeats the operation of step S 32 . When the portable device is in the flat status, step S 35  is performed, wherein the processor will determine whether the portable device is in a stable condition. The stable condition is determined according to a second duration (S 3 -B duration) in which the portable device is in the flat status. If the second duration exceeds a threshold (S 3 -C duration as threshold), the portable device is determined to be in the stable condition, and step S 36  is performed. If the second duration does not exceed the threshold, step S 34  is performed, wherein the processor sleeps for a first duration (S 3 -A), such as 200 ms, and then the processor repeats the operation of step S 32 . In this embodiment, the threshold (S 3 -C) may be 1000 ms. 
     In step S 36 , the processor queries the accelerometer at a second rate (with S 3 -D duration as the interval). In other words, the processor sleeps for a third duration (S 3 -D), such as 600 ms, and then the processor repeats the operation of step S 32 . 
       FIGS. 4A and 4B  show a flowchart of an orientation detection algorithm according to another embodiment of the invention. In step S 401 , the orientation detection algorithm is enabled. The timing to enable the orientation detection algorithm can be determined according to need of a designer. In step S 402 , the processor (or called CPU) of the portable device acquires the accelerometer data from the accelerometer and calculates a current angle of the portable device. The processor can further determine an orientation direction according to two calculated angles. 
     After estimating the current angle of the portable device, step  403  is performed. In step  403 , the orientation detection algorithm determines whether the portable device is in a flat status. The flat status is determined according to an absolute value of a tilt angle and a rotation angle of the portable device. If the absolute value is less than Zt and Zr degrees, the portable device is determined to be in a flat status. In other words, if the tilt angle and the rotation angle of the portable device range from −Zt degrees to Zt degrees (tilt angle) and from −Zr to Zr degrees (rotation angle), the portable device is determined to be in a flat status. Note that both the tilt angle and the rotation angle of the portable device are considered for the determination of the flat status of the portable device in this embodiment. 
     When the portable device is not in the flat status, step S 410  is performed, wherein the processor will determine whether the portable device is in a stable condition. The stable condition is determined according to a second duration (S 4 -B 1  duration) in which the portable device is in the previous status (i.e. no change on tilt and rotation angle). If the second duration doesn&#39;t exceed a first threshold (S 4 -C 1  duration as threshold), the portable device is determined to be not in the stable condition, and step S 405  is performed. In step S 405 , the processor sleeps for a first duration (S 4 -A duration), such as 200 ms, and then the processor repeats the operation of step S 402 . If the second duration (S 4 -B 1 ) exceeds a threshold (S 4 -C 1 ), the portable device is determined as being stable and step S 411  is performed. 
     In step S 403 , if the portable device is determined as being in the flat status, step S 404  is performed. The operation in step S 404  is the same as the operation in the step S 410 , wherein the processor will determine whether the portable device is in a stable condition. The stable condition is determined according to a third duration (S 4 -B 2  duration) in which the portable device is in the flat status. If the third duration (S 4 -B 2 ) exceeds a second threshold (S 4 -C 2  duration as threshold), the portable device is determined to be in the stable condition, and step S 406  is performed. If the third duration does not exceed the second threshold, the portable device is determined as being not stable and step S 405  is performed. In step S 405 , the processor sleeps for a first duration (S 4 -A), such as 200 ms, and then the processor repeats the operation of step S 402 . In some situations, the second threshold (S 4 -C 2 ) can be set to be the same as the first threshold (S 4 -C 1 ). 
     In step S 406 , the processor of the portable device enables a flat interrupt function of the accelerometer. It is noted that not every accelerometer has the flat interrupt function, and the present orientation detection algorithm is customized for those accelerometers with the flat interrupt function. One pin of the accelerometer is coupled to a GPIO pin of the processor of the portable device. When the accelerometer detects that the portable device is not in the flat status, the accelerometer transmits a flat interrupt signal to the processor. In another aspect, the processor monitors the status of the GPIO pin, and when the logic level of the GPIO pin changes, the processor then executes the step S 408 . 
     In step S 407 , the accelerometer waits for the interrupt event. In this embodiment, the interrupt event is the status of the portable device. For example, if the tilt angle or the rotation angle of the portable device exceeds a predetermined angle, the interrupt event is determined to have occurred and the accelerometer outputs a flat interrupt signal to the processor of the portable device. In step S 407 , the processor of the portable device does not query for the accelerometer data to reduce waste of resources and power consumption of the processor. 
     In step S 408 , after the processor receives the flat interrupt signal, the processor acquires the accelerometer data to calculate the tilt angle and the rotation angle of the portable device. Then step S 409  is performed to determine whether the portable is still in the flat status. If the processor determines that the portable device is still in the flat status, step S 407  is performed. If the processor determines that the portable device is not in the flat status, step S 402  performed. 
     In step S 410 , if the portable device is determined to be in the stable condition, step S 411  is performed, wherein the processor enables any-motion interrupt function of the accelerometer and then stores the current status of the portable device. The current status of the portable device comprises the current tilt angle and the current rotation angle of the portable device. The motion interrupt function triggers an interrupt signal to the processor when the accelerometer has determined that the portable device has been moved or rotated. 
     In step S 412 , the processor waits for the interrupt signal triggered by the accelerometer. If the processor receives the interrupt signal from the accelerometer, step S 402  is performed, and the processor of the portable device then acquires the accelerometer data from the accelerometer and calculates a first tilt and rotation angles of the portable device. In step S 412 , when there is no interrupt signal has been triggered for a fourth duration (S 4 -D duration), such as 1000 ms, wherein thereafter, step S 413  is performed. In step S 413 , the processor of the portable device then acquires the accelerometer data from the accelerometer and calculates a first tilt angle and a first rotation angle. The processor then compares the first tilt angle with the previous stored tilt angle and compares the first rotation angle with the previous stored rotation angle. If angle difference between the first tilt angle and the previous stored tilt angle or angle difference between the first rotation angle and the previous stored rotation angle exceeds a predetermined angle, the processor determines that the portable device has been moved, and step S 402  is performed. If angle difference between the first tilt angle and the previous stored tilt angle and angle difference between the first rotation angle and the previous stored rotation angle do not exceed the predetermined angle, the processor determines that the portable device has not moved, and step S 412  is performed. In this embodiment, when the steps S 411  and S 412  are executed, the processor of the portable device does not query the accelerometer to reduce waste of resources and power consumption of the processor. 
       FIG. 5  is a block diagram of a portable device having the described orientation detection mechanism according to an embodiment of the invention. The processor  51  queries the accelerometer  52  to acquire accelerometer data and estimates a tilt angle and a rotation angle of the portable device. In the conventional design, the processor  51  continuously queries the accelerometer  52  to acquire accelerometer data and this wastes resources and power consumption of the processor. Therefore, the processor  51  executes the orientation detection algorithm  53  to reduce waste of resources and power consumption. For details of the orientation detection algorithm  53 , reference may be made to the description and drawing of  FIGS. 1-4 , and thus, are not described again for briefly. 
     While the invention has been described by way of example and in terms of the preferred embodiments, it is to be understood that the invention is not limited to the disclosed embodiments. To the contrary, it is intended to cover various modifications and similar arrangements (as would be apparent to those skilled in the art). Therefore, the scope of the appended claims should be accorded the broadest interpretation so as to encompass all such modifications and similar arrangements.