#include <yocto_api.h>
Public Member Functions | |
virtual double | _applyCalibration (double rawValue) |
virtual double | _decodeAvg (int dw) |
virtual YMeasure | _decodeTimedReport (double timestamp, vector< int > report) |
virtual double | _decodeVal (int w) |
virtual string | _encodeCalibrationPoints (vector< double > rawValues, vector< double > refValues) |
virtual int | _invokeTimedReportCallback (YMeasure value) |
virtual int | _invokeValueCallback (string value) |
virtual int | _parserHelper (void) |
Y_ADVMODE_enum | advMode (void) |
virtual int | calibrateFromPoints (vector< double > rawValues, vector< double > refValues) |
string | calibrationParam (void) |
double | currentRawValue (void) |
double | currentValue (void) |
Y_ADVMODE_enum | get_advMode (void) |
string | get_calibrationParam (void) |
double | get_currentRawValue (void) |
double | get_currentValue (void) |
virtual YDataLogger * | get_dataLogger (void) |
double | get_highestValue (void) |
string | get_logFrequency (void) |
double | get_lowestValue (void) |
virtual YDataSet | get_recordedData (s64 startTime, s64 endTime) |
string | get_reportFrequency (void) |
double | get_resolution (void) |
int | get_sensorState (void) |
string | get_unit (void) |
double | highestValue (void) |
virtual bool | isSensorReady (void) |
virtual int | loadCalibrationPoints (vector< double > &rawValues, vector< double > &refValues) |
string | logFrequency (void) |
double | lowestValue (void) |
YSensor * | next (void) |
YSensor * | nextSensor (void) |
virtual int | registerTimedReportCallback (YSensorTimedReportCallback callback) |
virtual int | registerValueCallback (YSensorValueCallback callback) |
string | reportFrequency (void) |
double | resolution (void) |
int | sensorState (void) |
int | set_advMode (Y_ADVMODE_enum newval) |
int | set_calibrationParam (const string &newval) |
int | set_highestValue (double newval) |
int | set_logFrequency (const string &newval) |
int | set_lowestValue (double newval) |
int | set_reportFrequency (const string &newval) |
int | set_resolution (double newval) |
int | setAdvMode (Y_ADVMODE_enum newval) |
int | setCalibrationParam (const string &newval) |
int | setHighestValue (double newval) |
int | setLogFrequency (const string &newval) |
int | setLowestValue (double newval) |
int | setReportFrequency (const string &newval) |
int | setResolution (double newval) |
virtual int | startDataLogger (void) |
virtual int | stopDataLogger (void) |
string | unit (void) |
~YSensor () | |
Public Member Functions inherited from YFunction | |
void | _clearDataStreamCache () |
string | _decode_json_string (const string &json) |
string | _download (const string &url) |
YDataStream * | _findDataStream (YDataSet &dataset, const string &def) |
string | _get_json_path (const string &json, const string &path) |
vector< string > | _json_get_array (const string &json) |
string | _json_get_key (const string &json, const string &data) |
string | _json_get_string (const string &json) |
int | _parseEx (yJsonStateMachine &j) |
string | _parseString (yJsonStateMachine &j) |
string | _request (const string &request) |
string | _requestEx (int tcpchan, const string &request, yapiRequestProgressCallback callback, void *context) |
void | _throw (YRETCODE errType, string errMsg) |
YRETCODE | _upload (const string &path, const string &content) |
YRETCODE | _uploadWithProgress (const string &path, const string &content, yapiRequestProgressCallback callback, void *context) |
string | advertisedValue (void) |
void | clearCache () |
string | describe (void) |
string | errMessage (void) |
string | errorMessage (void) |
YRETCODE | errorType (void) |
YRETCODE | errType (void) |
YFUN_DESCR | functionDescriptor (void) |
string | get_advertisedValue (void) |
string | get_errorMessage (void) |
YRETCODE | get_errorType (void) |
virtual string | get_friendlyName (void) |
YFUN_DESCR | get_functionDescriptor (void) |
string | get_functionId (void) |
string | get_hardwareId (void) |
string | get_hubSerial () |
string | get_logicalName (void) |
YModule * | get_module (void) |
void * | get_userData (void) |
bool | isOnline (void) |
YRETCODE | load (int msValidity) |
virtual string | loadAttribute (string attrName) |
string | logicalName (void) |
YModule * | module (void) |
virtual int | muteValueCallbacks (void) |
YFunction * | next (void) |
YFunction * | nextFunction (void) |
virtual int | registerValueCallback (YFunctionValueCallback callback) |
int | set_advertisedValue (const string &newval) |
int | set_logicalName (const string &newval) |
void | set_userData (void *data) |
int | setAdvertisedValue (const string &newval) |
int | setLogicalName (const string &newval) |
void | setUserData (void *data) |
virtual int | unmuteValueCallbacks (void) |
void * | userData (void) |
virtual | ~YFunction () |
Static Public Member Functions | |
static YSensor * | Find (string func) |
static YSensor * | FindSensor (string func) |
static YSensor * | First (void) |
static YSensor * | FirstSensor (void) |
Static Public Member Functions inherited from YFunction | |
static void | _ClearCache (void) |
static YFunction * | Find (string func) |
static YFunction * | FindFunction (string func) |
static YFunction * | First (void) |
static YFunction * | FirstFunction (void) |
Protected Member Functions | |
virtual int | _parseAttr (YJSONObject *json_val) |
YSensor (const string &func) | |
Protected Member Functions inherited from YFunction | |
YRETCODE | _buildSetRequest (const string &changeattr, const string *changeval, string &request, string &errmsg) |
string | _escapeAttr (const string &changeval) |
YRETCODE | _getDescriptor (YFUN_DESCR &fundescr, string &errMsg) |
YRETCODE | _getDevice (YDevice *&dev, string &errMsg) |
YRETCODE | _load_unsafe (int msValidity) |
YRETCODE | _nextFunction (string &hwId) |
int | _parse (YJSONObject *j) |
YRETCODE | _setAttr (string attrname, string newvalue) |
YFunction (const string &func) | |
Protected Attributes | |
Y_ADVMODE_enum | _advMode |
yCalibrationHandler | _calhdl |
string | _calibrationParam |
vector< int > | _calpar |
vector< double > | _calraw |
vector< double > | _calref |
int | _caltyp |
double | _currentRawValue |
double | _currentValue |
double | _decexp |
double | _highestValue |
double | _iresol |
bool | _isScal |
bool | _isScal32 |
string | _logFrequency |
double | _lowestValue |
double | _offset |
double | _prevTimedReport |
string | _reportFrequency |
double | _resolution |
double | _scale |
int | _sensorState |
YSensorTimedReportCallback | _timedReportCallbackSensor |
string | _unit |
YSensorValueCallback | _valueCallbackSensor |
Protected Attributes inherited from YFunction | |
string | _advertisedValue |
u64 | _cacheExpiration |
string | _className |
std::map< string, YDataStream * > | _dataStreams |
string | _func |
YFUN_DESCR | _fundescr |
string | _funId |
string | _hwId |
string | _lastErrorMsg |
YRETCODE | _lastErrorType |
string | _logicalName |
string | _serial |
yCRITICAL_SECTION | _this_cs |
void * | _userData |
YFunctionValueCallback | _valueCallbackFunction |
Friends | |
YSensor * | yFindSensor (const string &func) |
YSensor * | yFirstSensor (void) |
Additional Inherited Members | |
Static Protected Member Functions inherited from YFunction | |
static void | _AddToCache (const string &classname, const string &func, YFunction *obj) |
static YFunction * | _FindFromCache (const string &classname, const string &func) |
static void | _UpdateTimedReportCallbackList (YFunction *func, bool add) |
static void | _UpdateValueCallbackList (YFunction *func, bool add) |
Static Protected Attributes inherited from YFunction | |
static std::map< string, YFunction * > | _cache |
YSensor Class: Sensor function interface
The YSensor class is the parent class for all Yoctopuce sensors. It can be used to read the current value and unit of any sensor, read the min/max value, configure autonomous recording frequency and access recorded data. It also provide a function to register a callback invoked each time the observed value changes, or at a predefined interval. Using this class rather than a specific subclass makes it possible to create generic applications that work with any Yoctopuce sensor, even those that do not yet exist. Note: The YAnButton class is the only analog input which does not inherit from YSensor.
Definition at line 2665 of file yocto_api.h.
|
protected |
Definition at line 6968 of file yocto_api.cpp.
YSensor::~YSensor | ( | ) |
Definition at line 6996 of file yocto_api.cpp.
|
virtual |
Definition at line 8095 of file yocto_api.cpp.
|
virtual |
Definition at line 8268 of file yocto_api.cpp.
|
virtual |
Definition at line 8112 of file yocto_api.cpp.
|
virtual |
Definition at line 8251 of file yocto_api.cpp.
|
virtual |
Definition at line 8034 of file yocto_api.cpp.
|
virtual |
Reimplemented in YGyro, YMultiCellWeighScale, YProximity, YGenericSensor, YPwmInput, YWeighScale, YTemperature, YRangeFinder, YAccelerometer, YMagnetometer, YLightSensor, YCompass, YQuadratureDecoder, YAltitude, YPower, YTilt, YHumidity, YCarbonDioxide, YCurrent, YVoltage, YGroundSpeed, YLatitude, YLongitude, YQt, YPressure, and YVoc.
Definition at line 7936 of file yocto_api.cpp.
|
virtual |
Reimplemented from YFunction.
Reimplemented in YGyro, YMultiCellWeighScale, YProximity, YGenericSensor, YPwmInput, YWeighScale, YTemperature, YRangeFinder, YAccelerometer, YMagnetometer, YLightSensor, YCompass, YQuadratureDecoder, YAltitude, YPower, YTilt, YHumidity, YCarbonDioxide, YCurrent, YVoltage, YGroundSpeed, YLatitude, YLongitude, YQt, YPressure, and YVoc.
Definition at line 7645 of file yocto_api.cpp.
|
protectedvirtual |
Reimplemented from YFunction.
Reimplemented in YGyro, YProximity, YPwmInput, YTemperature, YMultiCellWeighScale, YWeighScale, YAccelerometer, YGenericSensor, YCompass, YRangeFinder, YTilt, YLightSensor, YMagnetometer, YQuadratureDecoder, YCurrent, YVoltage, YPower, YAltitude, YCarbonDioxide, and YHumidity.
Definition at line 7015 of file yocto_api.cpp.
|
virtual |
Reimplemented from YFunction.
Definition at line 7655 of file yocto_api.cpp.
|
inline |
Definition at line 2899 of file yocto_api.h.
|
virtual |
Configures error correction data points, in particular to compensate for a possible perturbation of the measure caused by an enclosure. It is possible to configure up to five correction points. Correction points must be provided in ascending order, and be in the range of the sensor. The device will automatically perform a linear interpolation of the error correction between specified points. Remember to call the saveToFlash() method of the module if the modification must be kept.
For more information on advanced capabilities to refine the calibration of sensors, please contact suppo. rt@y octop uce. com
rawValues | : array of floating point numbers, corresponding to the raw values returned by the sensor for the correction points. |
refValues | : array of floating point numbers, corresponding to the corrected values for the correction points. |
On failure, throws an exception or returns a negative error code.
Definition at line 7966 of file yocto_api.cpp.
|
inline |
Definition at line 2918 of file yocto_api.h.
|
inline |
Definition at line 2824 of file yocto_api.h.
|
inline |
Definition at line 2754 of file yocto_api.h.
|
inlinestatic |
Definition at line 3141 of file yocto_api.h.
|
static |
Retrieves a sensor for a given identifier. The identifier can be specified using several formats:
This function does not require that the sensor is online at the time it is invoked. The returned object is nevertheless valid. Use the method YSensor.isOnline() to test if the sensor is indeed online at a given time. In case of ambiguity when looking for a sensor by logical name, no error is notified: the first instance found is returned. The search is performed first by hardware name, then by logical name.
If a call to this object's is_online() method returns FALSE although you are certain that the matching device is plugged, make sure that you did call registerHub() at application initialization time.
func | : a string that uniquely characterizes the sensor |
Definition at line 7594 of file yocto_api.cpp.
|
inlinestatic |
Definition at line 3165 of file yocto_api.h.
|
static |
Starts the enumeration of sensors currently accessible. Use the method YSensor.nextSensor() to iterate on next sensors.
Definition at line 8295 of file yocto_api.cpp.
Y_ADVMODE_enum YSensor::get_advMode | ( | void | ) |
Returns the measuring mode used for the advertised value pushed to the parent hub.
On failure, throws an exception or returns Y_ADVMODE_INVALID.
Definition at line 7393 of file yocto_api.cpp.
string YSensor::get_calibrationParam | ( | void | ) |
Definition at line 7441 of file yocto_api.cpp.
double YSensor::get_currentRawValue | ( | void | ) |
Returns the uncalibrated, unrounded raw value returned by the sensor, in the specified unit, as a floating point number.
On failure, throws an exception or returns Y_CURRENTRAWVALUE_INVALID.
Definition at line 7243 of file yocto_api.cpp.
double YSensor::get_currentValue | ( | void | ) |
Returns the current value of the measure, in the specified unit, as a floating point number.
On failure, throws an exception or returns Y_CURRENTVALUE_INVALID.
Definition at line 7091 of file yocto_api.cpp.
|
virtual |
Returns the YDatalogger object of the device hosting the sensor. This method returns an object of class YDatalogger that can control global parameters of the data logger. The returned object should not be freed.
Definition at line 7823 of file yocto_api.cpp.
double YSensor::get_highestValue | ( | void | ) |
Returns the maximal value observed for the measure since the device was started. Can be reset to an arbitrary value thanks to set_highestValue().
On failure, throws an exception or returns Y_HIGHESTVALUE_INVALID.
Definition at line 7211 of file yocto_api.cpp.
string YSensor::get_logFrequency | ( | void | ) |
Returns the datalogger recording frequency for this function, or "OFF" when measures are not stored in the data logger flash memory.
On failure, throws an exception or returns Y_LOGFREQUENCY_INVALID.
Definition at line 7274 of file yocto_api.cpp.
double YSensor::get_lowestValue | ( | void | ) |
Returns the minimal value observed for the measure since the device was started. Can be reset to an arbitrary value thanks to set_lowestValue().
On failure, throws an exception or returns Y_LOWESTVALUE_INVALID.
Definition at line 7153 of file yocto_api.cpp.
|
virtual |
Retrieves a DataSet object holding historical data for this sensor, for a specified time interval. The measures will be retrieved from the data logger, which must have been turned on at the desired time. See the documentation of the DataSet class for information on how to get an overview of the recorded data, and how to load progressively a large set of measures from the data logger.
This function only works if the device uses a recent firmware, as DataSet objects are not supported by firmwares older than version 13000.
startTime | : the start of the desired measure time interval, as a Unix timestamp, i.e. the number of seconds since January 1, 1970 UTC. The special value 0 can be used to include any meaasure, without initial limit. |
endTime | : the end of the desired measure time interval, as a Unix timestamp, i.e. the number of seconds since January 1, 1970 UTC. The special value 0 can be used to include any meaasure, without ending limit. |
Definition at line 7902 of file yocto_api.cpp.
string YSensor::get_reportFrequency | ( | void | ) |
Returns the timed value notification frequency, or "OFF" if timed value notifications are disabled for this function.
On failure, throws an exception or returns Y_REPORTFREQUENCY_INVALID.
Definition at line 7334 of file yocto_api.cpp.
double YSensor::get_resolution | ( | void | ) |
Returns the resolution of the measured values. The resolution corresponds to the numerical precision of the measures, which is not always the same as the actual precision of the sensor.
On failure, throws an exception or returns Y_RESOLUTION_INVALID.
Definition at line 7513 of file yocto_api.cpp.
int YSensor::get_sensorState | ( | void | ) |
Returns the sensor health state code, which is zero when there is an up-to-date measure available or a positive code if the sensor is not able to provide a measure right now.
On failure, throws an exception or returns Y_SENSORSTATE_INVALID.
Definition at line 7545 of file yocto_api.cpp.
string YSensor::get_unit | ( | void | ) |
Returns the measuring unit for the measure.
On failure, throws an exception or returns Y_UNIT_INVALID.
Definition at line 7061 of file yocto_api.cpp.
|
inline |
Definition at line 2810 of file yocto_api.h.
|
virtual |
Checks if the sensor is currently able to provide an up-to-date measure. Returns false if the device is unreachable, or if the sensor does not have a current measure to transmit. No exception is raised if there is an error while trying to contact the device hosting $THEFUNCTION$.
Definition at line 7805 of file yocto_api.cpp.
|
virtual |
Retrieves error correction data points previously entered using the method calibrateFromPoints.
rawValues | : array of floating point numbers, that will be filled by the function with the raw sensor values for the correction points. |
refValues | : array of floating point numbers, that will be filled by the function with the desired values for the correction points. |
On failure, throws an exception or returns a negative error code.
Definition at line 7996 of file yocto_api.cpp.
|
inline |
Definition at line 2838 of file yocto_api.h.
|
inline |
Definition at line 2782 of file yocto_api.h.
|
inline |
Definition at line 3152 of file yocto_api.h.
YSensor * YSensor::nextSensor | ( | void | ) |
Continues the enumeration of sensors started using yFirstSensor().
Definition at line 8285 of file yocto_api.cpp.
|
virtual |
Registers the callback function that is invoked on every periodic timed notification. The callback is invoked only during the execution of ySleep or yHandleEvents. This provides control over the time when the callback is triggered. For good responsiveness, remember to call one of these two functions periodically. To unregister a callback, pass a NULL pointer as argument.
callback | : the callback function to call, or a NULL pointer. The callback function should take two arguments: the function object of which the value has changed, and an YMeasure object describing the new advertised value. |
Definition at line 7923 of file yocto_api.cpp.
|
virtual |
Registers the callback function that is invoked on every change of advertised value. The callback is invoked only during the execution of ySleep or yHandleEvents. This provides control over the time when the callback is triggered. For good responsiveness, remember to call one of these two functions periodically. To unregister a callback, pass a NULL pointer as argument.
callback | : the callback function to call, or a NULL pointer. The callback function should take two arguments: the function object of which the value has changed, and the character string describing the new advertised value. |
Definition at line 7626 of file yocto_api.cpp.
|
inline |
Definition at line 2869 of file yocto_api.h.
|
inline |
Definition at line 2949 of file yocto_api.h.
|
inline |
Definition at line 2964 of file yocto_api.h.
int YSensor::set_advMode | ( | Y_ADVMODE_enum | newval | ) |
Changes the measuring mode used for the advertised value pushed to the parent hub.
newval | : a value among Y_ADVMODE_IMMEDIATE, Y_ADVMODE_PERIOD_AVG, Y_ADVMODE_PERIOD_MIN and Y_ADVMODE_PERIOD_MAX corresponding to the measuring mode used for the advertised value pushed to the parent hub |
On failure, throws an exception or returns a negative error code.
Definition at line 7425 of file yocto_api.cpp.
int YSensor::set_calibrationParam | ( | const string & | newval | ) |
Definition at line 7463 of file yocto_api.cpp.
int YSensor::set_highestValue | ( | double | newval | ) |
Changes the recorded maximal value observed. Can be used to reset the value returned by get_lowestValue().
newval | : a floating point number corresponding to the recorded maximal value observed |
On failure, throws an exception or returns a negative error code.
Definition at line 7186 of file yocto_api.cpp.
int YSensor::set_logFrequency | ( | const string & | newval | ) |
Changes the datalogger recording frequency for this function. The frequency can be specified as samples per second, as sample per minute (for instance "15/m") or in samples per hour (eg. "4/h"). To disable recording for this function, use the value "OFF".
newval | : a string corresponding to the datalogger recording frequency for this function |
On failure, throws an exception or returns a negative error code.
Definition at line 7309 of file yocto_api.cpp.
int YSensor::set_lowestValue | ( | double | newval | ) |
Changes the recorded minimal value observed. Can be used to reset the value returned by get_lowestValue().
newval | : a floating point number corresponding to the recorded minimal value observed |
On failure, throws an exception or returns a negative error code.
Definition at line 7128 of file yocto_api.cpp.
int YSensor::set_reportFrequency | ( | const string & | newval | ) |
Changes the timed value notification frequency for this function. The frequency can be specified as samples per second, as sample per minute (for instance "15/m") or in samples per hour (eg. "4/h"). To disable timed value notifications for this function, use the value "OFF".
newval | : a string corresponding to the timed value notification frequency for this function |
On failure, throws an exception or returns a negative error code.
Definition at line 7369 of file yocto_api.cpp.
int YSensor::set_resolution | ( | double | newval | ) |
Changes the resolution of the measured physical values. The resolution corresponds to the numerical precision when displaying value. It does not change the precision of the measure itself.
newval | : a floating point number corresponding to the resolution of the measured physical values |
On failure, throws an exception or returns a negative error code.
Definition at line 7489 of file yocto_api.cpp.
|
inline |
Definition at line 2913 of file yocto_api.h.
|
inline |
Definition at line 2922 of file yocto_api.h.
|
inline |
Definition at line 2796 of file yocto_api.h.
|
inline |
Definition at line 2855 of file yocto_api.h.
|
inline |
Definition at line 2768 of file yocto_api.h.
|
inline |
Definition at line 2886 of file yocto_api.h.
|
inline |
Definition at line 2936 of file yocto_api.h.
|
virtual |
Starts the data logger on the device. Note that the data logger will only save the measures on this sensor if the logFrequency is not set to "OFF".
Definition at line 7847 of file yocto_api.cpp.
|
virtual |
Stops the datalogger on the device.
Definition at line 7864 of file yocto_api.cpp.
|
inline |
Definition at line 2741 of file yocto_api.h.
|
friend |
Retrieves a sensor for a given identifier. The identifier can be specified using several formats:
This function does not require that the sensor is online at the time it is invoked. The returned object is nevertheless valid. Use the method YSensor.isOnline() to test if the sensor is indeed online at a given time. In case of ambiguity when looking for a sensor by logical name, no error is notified: the first instance found is returned. The search is performed first by hardware name, then by logical name.
If a call to this object's is_online() method returns FALSE although you are certain that the matching device is plugged, make sure that you did call registerHub() at application initialization time.
func | : a string that uniquely characterizes the sensor |
Definition at line 3202 of file yocto_api.h.
|
friend |
Starts the enumeration of sensors currently accessible. Use the method YSensor.nextSensor() to iterate on next sensors.
Definition at line 3213 of file yocto_api.h.
|
protected |
Definition at line 2680 of file yocto_api.h.
|
protected |
Definition at line 2697 of file yocto_api.h.
|
protected |
Definition at line 2681 of file yocto_api.h.
|
protected |
Definition at line 2694 of file yocto_api.h.
|
protected |
Definition at line 2695 of file yocto_api.h.
|
protected |
Definition at line 2696 of file yocto_api.h.
|
protected |
Definition at line 2693 of file yocto_api.h.
|
protected |
Definition at line 2677 of file yocto_api.h.
|
protected |
Definition at line 2674 of file yocto_api.h.
|
protected |
Definition at line 2690 of file yocto_api.h.
|
protected |
Definition at line 2676 of file yocto_api.h.
|
protected |
Definition at line 2687 of file yocto_api.h.
|
protected |
Definition at line 2691 of file yocto_api.h.
|
protected |
Definition at line 2692 of file yocto_api.h.
|
protected |
Definition at line 2678 of file yocto_api.h.
|
protected |
Definition at line 2675 of file yocto_api.h.
|
protected |
Definition at line 2688 of file yocto_api.h.
|
protected |
Definition at line 2686 of file yocto_api.h.
|
protected |
Definition at line 2679 of file yocto_api.h.
|
protected |
Definition at line 2682 of file yocto_api.h.
|
protected |
Definition at line 2689 of file yocto_api.h.
|
protected |
Definition at line 2683 of file yocto_api.h.
|
protected |
Definition at line 2685 of file yocto_api.h.
|
protected |
Definition at line 2673 of file yocto_api.h.
|
protected |
Definition at line 2684 of file yocto_api.h.
|
static |
Definition at line 2723 of file yocto_api.h.
|
static |
Definition at line 2727 of file yocto_api.h.
|
static |
Definition at line 2724 of file yocto_api.h.
|
static |
Definition at line 2726 of file yocto_api.h.
|
static |
Definition at line 2725 of file yocto_api.h.
|
static |
Definition at line 2728 of file yocto_api.h.
|
static |
Definition at line 2720 of file yocto_api.h.
|
static |
Definition at line 2717 of file yocto_api.h.
|
static |
Definition at line 2719 of file yocto_api.h.
|
static |
Definition at line 2721 of file yocto_api.h.
|
static |
Definition at line 2718 of file yocto_api.h.
|
static |
Definition at line 2722 of file yocto_api.h.
|
static |
Definition at line 2729 of file yocto_api.h.
|
static |
Definition at line 2730 of file yocto_api.h.
|
static |
Definition at line 2716 of file yocto_api.h.