Class:Sensor

From Torque Wiki
Revision as of 14:01, 18 January 2022 by Ihawkins (talk | contribs) (Created page with "== Sensor == Used for retrieving from, and creating/setting sensors and sensor readings in Torque === Methods === <syntaxhighlight lang="Java"> /** * Set a value on a give...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
⧼monobook-jumptonavigation⧽⧼monobook-jumptosearch⧽

Sensor

Used for retrieving from, and creating/setting sensors and sensor readings in Torque

Methods

/**
 * Set a value on a given sensor object
 */
public setValue(double newValue);

/**
 * Get the Sensor value
 * 
 * If it is not populated or retrieved yet it will return zero
 *  
 * This will also trigger a request to update the sensor 
 * (via OBD if required) - this may not be immediately done if other
 * sensors are in the process of being requested, or 
 * the sensor is not available (due to no connection, etc)
 *
 * @return The current value for the sensor, or zero if not present
 */
public Double getValue();

/**
 * Get the sensor value
 *  
 * If it is not populated, then return the default value passed
 *
 * This will trigger a request to update the sensor - this may not be immediately done if other
 * sensors are in the process of being requested, or the sensor is not available (due to no connection, etc)
 *
 * @param defaultValue The value to return if the sensor has no value yet, can be null
 * @return The value of the sensor, or 'defaultValue' if not yet present
 */
public Double getValue(Double defaultValue);


/**
 * Retrieve a sensor by name
 *
 * @param The full name of the sensor
 * @return a Sensor object
 */
public static Sensor getSensorByName(String name);


/**
 * Retrieve a sensor by id
 *
 * This retrieves a sensor by it's id (which is loosely defined as the PID of the sensor)
 * A list of IDs can be viewed using the TorqueScan plugin
 *
 * @param id the ID of the sensor
 * @return
 */
public static Sensor getSensorById(int id);


 /**
 * This creates a 'script' sensor that is then available to the rest of the app (and other scripts)
 *  
 * The sensors are keyed by their fullName - if it already exists, it is overwritten.
 * You cannot overwrite existing non-script sensors - trying will throw an exception in your script
 *  
 * Calling setValue on the returned sensor object can be used to update the value.
 *
 * @param fullName The full, unique name of the sensor
 * @param shortName The shortname of the sensor for use in displays
 * @param units The sensor units (ms, S, psi, km/h, etc) 
 * @return A sensor object representing a new sensor or null if the sensor could not be created
 */
public static Sensor createSensor(String fullName, String shortName, String units);


/**
 * Remove a sensor we created
 * 
 * Sensors created by a script are also automatically cleaned up (removed) when the script is
 * stopped or restarted
 *
 * @param fullName
 * @return true if the sensor was found, was originally created by this script, and was removed.
 */
 public static boolean removeSensor(String fullName);