User Tools

Site Tools


built_in:sensors

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
built_in:sensors [2014/12/05 13:48]
162.252.85.172 [Methods]
built_in:sensors [2018/01/03 10:23] (current)
Line 1: Line 1:
-====== Sensor control ====== +====== Sensors ====== 
-===== Create ===== + 
-Create Sensor objects using the CreateSensor function of the app object:+//(Information and examples taken from the DroidScript documentation). Information provided by Nick Weber// 
 + 
 +===== Description ===== 
 +Create Sensor objects using the **CreateSensor** function of the **[[built_in:app|app]]** object:
 <code>sns = app.CreateSensor( type, options );</code> <code>sns = app.CreateSensor( type, options );</code>
-Types available are: "Accelerometer", "MagneticField", "Orientation""Lightand "Proximity".+Types available are:  
 +  * **Accelerometer** 
 +  * **MagneticField** 
 +  * **Orientation** 
 +  * **Light** 
 +  * **Proximity** 
 +  * **Temperature** 
 +  * **GameRotation** 
 +  * **GeomagneticRotation** 
 +  * **Gravity** 
 +  * **Gyroscope** 
 +  * **HeartRate** 
 +  * **Acceleration** 
 +  * **Pressure** 
 +  * **Humidity** 
 +  * **Rotation** 
 +  * **Motion** 
 +  * **StepCounter** 
 +  * **StepDetector** 
 + 
 +Try **sns.GetNames()** which lists all the sensor information. You can probably scan for certain keywords. 
 + 
 +You can also use a sensor id number instead of the name (just in case a future sensor is added). 
 + 
 +You can use the **SetOnChange** function of the Sensor to set the name of a function you want to be called when a the changes occur. 
 + 
 +Change the rate that a sensor checks for changes by adding one the options **"Fastest"****"Fast"****"Medium"** or **"Slow"**. 
 +"Slowis the default.
  
-You can use the SetOnChange function of the Sensor to set the name of a function you want to be called when a the changes occur. 
  
-Change the rate that a sensor checks for changes by adding one the options "Fastest", "Fast", "Medium" or "Slow". "Slow" is the default. 
 ===== Methods ===== ===== Methods =====
-^Method ^Description ^ +Some controls use the same methods.\\ 
-|Sensor.Destroy() | | +For examples of the **[[same methods]]** look here. 
-|Sensor.GetAbsHeight() | | +^ Method                          ^ Description                              
-|Sensor.GetAbsWidth() | | +| Sensor.GetAzimuth()                                                      
-|Sensor.GetAzimuth() | | +| Sensor.GetHeight()                                                       
-|Sensor.GetHeight() | | +| Sensor.GetNames()               returns a list of all available sensors  
-|Sensor.GetPitch() | | +| Sensor.GetPitch()                                                        
-|Sensor.GetPosition() | | +| Sensor.GetRoll()                                                         
-|Sensor.GetRoll() | | +| Sensor.GetType()                                                         
-|Sensor.GetType() | | +| Sensor.GetValues()                                                       
-|Sensor.GetVisibility() | | +| Sensor.SetMaxRaterate       default 20ms                             
-|Sensor.GetWidth() | | +| Sensor.SetMinChangevalue    a value between 0 and 1                  
-|Sensor.Release() | | +| Sensor.SetOnChangecallback                                           
-|Sensor.SetBackColor( p1 ) | | +| Sensor.Start()                                                           
-|Sensor.SetBackGradientp1,p2,p3,p4,p5,p6,p7 | | +| Sensor.Stop()                                                            
-|Sensor.SetBackGradientRadialp1,p2,p3,p4,p5,p6,p7 + 
-|Sensor.SetBackgroundp1,p2 | | +===== Examples ===== 
-|Sensor.SetMarginsleft,top,right,bottom | | +^Sensor Type ^Code Example ^ 
-|Sensor.SetMinChangep1 | | +|Accelerometer <code javascript>function OnStart() 
-|Sensor.SetOnChange( p1 | | +
-|Sensor.SetPaddingp1,p2,p3,p4 +  lay = app.CreateLayout"Linear""VCenter,FillXY" ); 
-|Sensor.SetPositionp1,p2,p3,p4 | | + 
-|Sensor.SetScalex,| | +  txt = app.CreateText( ""0.80.3"Multiline" ); 
-|Sensor.SetSizep1,p2 | | +  lay.AddChildtxt ); 
-|Sensor.SetVisibilityp1 | | +  app.AddLayout( lay ); 
-|Sensor.Start() | | + 
-|Sensor.Stop() |+  sns = app.CreateSensor( "Accelerometer" ); 
 +  sns.SetOnChange( sns_OnChange ); 
 +  sns.Start(); 
 + 
 +
 + 
 +function sns_OnChange( xyztime ) 
 +
 +  txt.SetText( "x="+x + "\n y="+y + "\n z="+z ); 
 +
 +</code> 
 +|Orientation | <code javascript>function OnStart() 
 +
 +  lay = app.CreateLayout"Linear""VCenter,FillXY" ); 
 + 
 +  txt = app.CreateText""0.80.3"Multiline" ); 
 +  lay.AddChildtxt ); 
 +  app.AddLayout( lay ); 
 + 
 +  sns = app.CreateSensor( "Orientation" ); 
 +  sns.SetOnChange( sns_OnChange ); 
 +  sns.Start(); 
 + 
 +
 + 
 +function sns_OnChangeazimuthpitchrolltime ) 
 +
 +  var msg = " azimuth = " + azimuth.toFixed(1); 
 +  msg += "\n pitch = " + pitch.toFixed(1); 
 +  msg += "\n roll = " + roll.toFixed(1); 
 +  txt.SetText( msg ); 
 +
 +</code> 
 +|Light | <code javascript>function OnStart() 
 +
 +  lay = app.CreateLayout"Linear""VCenter,FillXY" ); 
 + 
 +  txt = app.CreateText""0.8, 0.3 ); 
 +  lay.AddChildtxt ); 
 +  app.AddLayoutlay ); 
 + 
 +  sns = app.CreateSensor( "Light" ); 
 +  sns.SetOnChange( sns_OnChange ); 
 +  sns.Start(); 
 + 
 +
 + 
 +function sns_OnChange( lux ) 
 +
 +  txt.SetText"level = " + lux + " lux" )
 +
 + 
 +</code> |
built_in/sensors.1417787289.txt.gz · Last modified: 2014/12/05 21:48 (external edit)