Windows Virtual Shields for Arduino
Public Member Functions | Public Attributes | Protected Attributes | List of all members
Sensor Class Reference

#include <Sensor.h>

Inherited by Accelerometer, Camera, Compass, Email, Geolocator, Gyrometer, LightSensor, Media, Microphone, Notification, Orientation, Recognition, Sms, Speech, Text, Vibrate, and Web.

Public Member Functions

 Sensor (const VirtualShield &shield, const char sensorType)
 Initializes a new instance of the Sensor class. More...
 
int start (double delta=0, long interval=0)
 Starts the sensor, triggered when longer than the interval and larger than the delta. More...
 
virtual int stop ()
 Stops this sensor. More...
 
int get ()
 Gets a single, current sensor reading. More...
 
int getOnChange (double delta=0)
 Requests a single reading when more than the delta beyond the current reading. More...
 
bool isUpdated ()
 Determines whether this sensor has an updated value. Resets to false after this call. More...
 
int writeAll (const char *serviceName, EPtr values[], int count, Attr extraAttributes[]=0, int extraAttributeCount=0)
 Writes all EPtr values to the communication channel. More...
 
int sensorAction (SensorAction sensorAction, double delta=0, long interval=0) const
 Sends the specific action to start/stop/get/onChange the sensor using a delta and interval. More...
 
virtual bool isEvent (const char *tag, const char *action, ShieldEvent *shieldEvent)
 Determines whether the specified shieldEvent matches the tag and action. More...
 
virtual bool isEvent (int id, const char *action, ShieldEvent *shieldEvent)
 Determines whether the specified shieldEvent matches the id and action. More...
 
void setOnEvent (void(*onEvent)(ShieldEvent *shieldEvent))
 
int sendStop (const char *serviceName)
 
virtual void onJsonReceived (JsonObject &root, ShieldEvent *shieldEvent)
 Event called when a valid json message was received. Consumes the proper values for this sensor. More...
 

Public Attributes

void(* onEvent )(ShieldEvent *shieldEvent)
 
VirtualShieldshield
 
ShieldEvent recentEvent
 
const char sensorType
 
bool isRunning = false
 

Protected Attributes

bool _isUpdated = false
 

Constructor & Destructor Documentation

Sensor::Sensor ( const VirtualShield shield,
const char  sensorType 
)

Initializes a new instance of the Sensor class.

Parameters
shieldThe shield.
sensorTypeFilter for identifying a service.

Member Function Documentation

int Sensor::get ( )

Gets a single, current sensor reading.

int Sensor::getOnChange ( double  delta = 0)

Requests a single reading when more than the delta beyond the current reading.

Parameters
deltaThe delta of expected change. Zero is all.
bool Sensor::isEvent ( const char *  tag,
const char *  action,
ShieldEvent shieldEvent 
)
virtual

Determines whether the specified shieldEvent matches the tag and action.

Parameters
tagThe tag.
actionThe action.
shieldEventThe shield event.
Returns
bool.
bool Sensor::isEvent ( int  id,
const char *  action,
ShieldEvent shieldEvent 
)
virtual

Determines whether the specified shieldEvent matches the id and action.

Parameters
idThe identifier.
actionThe action.
shieldEventThe shield event.
Returns
bool.
bool Sensor::isUpdated ( )

Determines whether this sensor has an updated value. Resets to false after this call.

Returns
true if updated from last check.
void Sensor::onJsonReceived ( JsonObject &  root,
ShieldEvent shieldEvent 
)
virtual

Event called when a valid json message was received. Consumes the proper values for this sensor.

Parameters
rootThe root json object.
shieldEventThe shield event.

Reimplemented in Graphics, Recognition, Text, Media, Orientation, Speech, Accelerometer, Geolocator, Gyrometer, Compass, Email, LightSensor, Sms, Vibrate, Camera, Notification, and Microphone.

int Sensor::sendStop ( const char *  serviceName)
int Sensor::sensorAction ( SensorAction  sensorAction,
double  delta = 0,
long  interval = 0 
) const

Sends the specific action to start/stop/get/onChange the sensor using a delta and interval.

Parameters
sensorActionThe sensor action.
deltaThe delta.
intervalThe interval.
Returns
int.
void Sensor::setOnEvent ( void(*)(ShieldEvent *shieldEvent)  onEvent)
inline
int Sensor::start ( double  delta = 0,
long  interval = 0 
)

Starts the sensor, triggered when longer than the interval and larger than the delta.

Parameters
intervalThe interval in milliseconds. Zero is all.
deltaThe delta of expected change. Zero is all.
int Sensor::stop ( )
virtual

Stops this sensor.

Reimplemented in Recognition, and Speech.

int Sensor::writeAll ( const char *  serviceName,
EPtr  values[],
int  count,
Attr  extraAttributes[] = 0,
int  extraAttributeCount = 0 
)

Writes all EPtr values to the communication channel.

Parameters
serviceNameName of the service.
valuesThe values.
countThe count of values.
Returns
The new id of the message or a negative error.

Member Data Documentation

bool Sensor::_isUpdated = false
protected
bool Sensor::isRunning = false
void(* Sensor::onEvent) (ShieldEvent *shieldEvent)
ShieldEvent Sensor::recentEvent
const char Sensor::sensorType
VirtualShield& Sensor::shield

The documentation for this class was generated from the following files: