Acceleration

Acceleration

Acceleration is the object that provides acceleration information measured from the acceleration sensor of the mobile device. Here, acceleration refers to the gravitational acceleration (Gravity), and it is the measure of how much force the mobile device is receiving based on the gravitational acceleration of the Earth.

Acceleration information has three values of the x-axis, y-axis, and z-axis. This is the measure of the gravitational acceleration acting on the three axes, which can be used to detect how and in which direction the mobile device is tilted. Acceleration information is widely used in mobile screen rotation functions, motion-based games, etc.

Obtaining Acceleration Information

Acceleration information can be obtained by calling the method of the Acceleration object. The getCurrentAcceleration method measures the acceleration information of the current moment. To periodically measure acceleration information, you can use the watchStart method. Once the method is successfully executed, then the onrecvsuccess event occurs and acceleration information values applied to the x, y, and z axes can be obtained from the AccelerationEventInfo object.

${sample}

The following is an example of obtaining acceleration information of the mobile device. If you touch the Watch Start button after setting Accuracy and Interval Time, then the acceleration information is measured and displayed at the Interval Time intervals. If you touch the Watch Stop button, then the measuring will stop.

Screenshot_20180927-181035

${sample_element}

Acceleration > watchStart

This is the method that sets acceleration information of the mobile device to be received at regular intervals. When calling the method, you can set the arguments for Accuracy and Interval Time, and acceleration information with Accuracy is received at the Interval Time intervals. Accuracy can have an integer value in the range of 0 to 3 and Interval Time can have the value in the range of 200 to 86,400,000ms.

Acceleration > accuracy

This is the property that has the accuracy of the acceleration information measured by the mobile device. It can have an integer value in the range of 0 to 3, and the smaller the value, the higher the accuracy.

Acceleration > xpos

This is the property that has the acceleration value of the x-axis.

Acceleration > ypos

This is the property that has the acceleration value of the y-axis.

Acceleration > zpos

This is the property that has the acceleration value of the z-axis.

${sample_step}

1

Configuring the Screen

Add the Acceleration object. The added object can be checked in the Invisible Object window.

Add the Static, Radio, and Edit components to receive Accuracy and Interval Time values, and add Two Button components to measure acceleration information. Then, place the GroupBox, Static, and Edit components appropriately to display the measured acceleration information on the screen as shown in the example figure.

Components and objects added for configuring the screen are as follows.

Component / Object

ID

Static

Static00~Static07

Radio

rdo_accuracy

Edit

edt_intervaltime

edt_timestamp

edt_accuracy

edt_xpos

edt_ypos

edt_zpos

Button

btn_start

btn_stop

GroupBox

GroupBox00

2

Writing the Watch Start Button Event Function

Write the onclick event function of the Watch Start button as follows.

this.btn_start_onclick = function(obj:nexacro.Button,e:nexacro.ClickEventInfo)
{
	var nAccuracy = this.rdo_accuracy.text;	
	var nIntervalTime = this.edt_intervaltime.value;
	
	if(nIntervalTime < 200 || nIntervalTime > 86400000)
	{
		this.edt_intervaltime.setFocus();

		trace("Invalid range");
		return;
	}
	
	this.Acceleration00.watchStart(nAccuracy, nIntervalTime);
	
	this.btn_start.set_enable(false);
	this.btn_stop.set_enable(true);
};

3

Writing the Watch Stop Button Event Function

Write the onclick event function of the Watch Stop button as follows.

this.btn_stop_onclick = function(obj:nexacro.Button,e:nexacro.ClickEventInfo)
{
	this.Acceleration00.watchStop();
	
	this.btn_start.set_enable(true);
	this.btn_stop.set_enable(false);	
};

4

Writing the Acceleration Event Function

If the acceleration information is successfully received, then the onrecvsuccess event occurs, and if it is not received, then the onrecverror event occurs.

When the acceleration information is successfully received, the onrecvsuccess occurs. You can obtain the timestamp, accuracy, xpos, ypos, and zpos values from AccelerationEventInfo.

this.Acceleration00_onrecvsuccess = function(obj:nexacro.Acceleration,e:nexacro.AccelerationEventInfo)
{
	this.edt_timestamp.set_value(e.timestamp);
	this.edt_accuracy.set_value(e.accuracy);
	this.edt_xpos.set_value(e.xpos);
	this.edt_ypos.set_value(e.ypos);
	this.edt_zpos.set_value(e.zpos);
};

When receiving the acceleration information failures, the onrecverror occurs. Error information is displayed regarding the specific reason the error occurred.

this.Acceleration00_onrecverror = function(obj:nexacro.Acceleration,e:nexacro.AccelerationErrorEventInfo)
{
	var strResult = "["+ e.errortype +" "+ e.statuscode +"] "+ e.errormsg;	
	trace(strResult);	
};

5

Checking on the Mobile Device

Touch the Watch Start button after setting the accuracy and interval time. Once acceleration information is normally measured, the timestamp, xpos, ypos, and zpos values in the Acceleration Information group box at the bottom are updated in the interval time period. Touch the Watch Stop button to stop measuring acceleration information.