![]() |
Windows Virtual Shields for Arduino
|
#include <VirtualShield.h>
Public Member Functions | |
VirtualShield () | |
Initializes a new instance of the VirtualShield class. More... | |
void | begin (long bitRate=DEFAULT_BAUDRATE) |
Begins the specified bit rate. More... | |
void | setPort (int port) |
Sets the port for bluetooth (this only works for AVR_ATmega32U4 where there are more than one port). More... | |
bool | checkSensors (int watchForId=0, long timeout=0, int waitForResultId=-1) |
Receives events as long as they exist, or until an optional timeout occurs. More... | |
int | waitFor (int id, long timeout=WAITFOR_TIMEOUT, bool asSuccess=true, int resultId=-1) |
Blocks and awaits an event with an id. More... | |
bool | hasError (ShieldEvent *shieldEvent=0) |
Returns true More... | |
bool | getEvent (ShieldEvent *shieldEvent) |
Gets zero or one available events for processing. More... | |
int | directToSerial (const char *cmd) |
bool | addSensor (Sensor *sensor) |
Adds a sensor to the list of known sensors in order to match and dispatch for incoming events. More... | |
virtual void | onJsonReceived (JsonObject &root, ShieldEvent *shieldEvent) |
Event called when a valid json message was received. Dispatches to added sensors that match the incoming Type. More... | |
void | write (const char *text) |
Writes the specified text to the communication channel. More... | |
int | writeAll (const char *serviceName, EPtr values[], int count, Attr extraAttributes[]=0, int extraAttributeCount=0, const char sensorType= '\0') |
Writes all EPtr values to the communication channel. More... | |
int | writeAll (const char *serviceName) |
Writes the service name only to the communication channel. More... | |
int | beginWrite (const char *serviceName) |
Begins a service write operation to the communication channel. Increments a message id, includes and returns the id. More... | |
int | write (EPtr eptr) const |
Writes the specified eptr. More... | |
int | endWrite () |
Ends the write operation. More... | |
int | block (int id, bool blocking, long timeout=WAITFOR_TIMEOUT, int waitForResultId=-1) |
Blocks while waiting for a specific id-based response (only when blocking is true and allowAutoBlocking is true). More... | |
void | setOnEvent (void(*onEvent)(ShieldEvent *)) |
void | setOnConnect (void(*onConnect)(ShieldEvent *)) |
void | setOnRefresh (void(*onRefresh)(ShieldEvent *)) |
void | setOnSuspend (void(*onSuspend)(ShieldEvent *)) |
void | setOnResume (void(*onResume)(ShieldEvent *)) |
void | enableAutoBlocking (bool enable) |
Enables or disables block() to block for specific id-based responses. More... | |
int | parseToHash (const char *text, unsigned int *hash, int hashCount, char separator= ' ', unsigned int length=-1) |
Static Public Member Functions | |
static unsigned int | hash (const char *s, unsigned int len=-1, unsigned int seed=0) |
Public Attributes | |
void(* | onEvent )(ShieldEvent *)=0 |
void(* | onConnect )(ShieldEvent *)=0 |
void(* | onRefresh )(ShieldEvent *)=0 |
void(* | onSuspend )(ShieldEvent *)=0 |
void(* | onResume )(ShieldEvent *)=0 |
Protected Member Functions | |
int | sendFlashStringOnSerial (const char *flashStringAdr, int start=-1, bool encode=false) const |
Sends the flash (PROGMEM) string on the communication channel. More... | |
void | onJsonStringReceived (char *json, ShieldEvent *shieldEvent) |
Event callback for when a full json string is received. More... | |
void | onStringReceived (char *buffer, int length, ShieldEvent *shieldEvent) |
Event callback for when a full string is received. More... | |
void | flush () |
Flushes this instance onto the serial port. More... | |
Protected Attributes | |
Stream * | _VShieldSerial |
VirtualShield::VirtualShield | ( | ) |
Initializes a new instance of the VirtualShield class.
bool VirtualShield::addSensor | ( | Sensor * | sensor | ) |
Adds a sensor to the list of known sensors in order to match and dispatch for incoming events.
sensor | The sensor to add. |
void VirtualShield::begin | ( | long | bitRate = DEFAULT_BAUDRATE | ) |
Begins the specified bit rate.
bitRate | The bit rate to use for the virtual shield serial connection. |
int VirtualShield::beginWrite | ( | const char * | serviceName | ) |
Begins a service write operation to the communication channel. Increments a message id, includes and returns the id.
serviceName | Name of the service. |
int VirtualShield::block | ( | int | id, |
bool | blocking, | ||
long | timeout = WAITFOR_TIMEOUT , |
||
int | watchForResultId = -1 |
||
) |
Blocks while waiting for a specific id-based response (only when blocking is true and allowAutoBlocking is true).
bool VirtualShield::checkSensors | ( | int | watchForId = 0 , |
long | timeout = 0 , |
||
int | watchForResultId = -1 |
||
) |
Receives events as long as they exist, or until an optional timeout occurs.
watchForId | An id to return true if found. Otherwise true is returned for any events processed. |
timeout | The timeout in milliseconds. |
int VirtualShield::directToSerial | ( | const char * | cmd | ) |
|
inline |
Enables or disables block() to block for specific id-based responses.
int VirtualShield::endWrite | ( | ) |
Ends the write operation.
|
protected |
Flushes this instance onto the serial port.
bool VirtualShield::getEvent | ( | ShieldEvent * | shieldEvent | ) |
Gets zero or one available events for processing.
shieldEvent | The address of ShieldEvent to populate. |
bool VirtualShield::hasError | ( | ShieldEvent * | shieldEvent = 0 | ) |
Returns true
id | The id. |
timeout | The timeout. |
|
static |
|
virtual |
Event called when a valid json message was received. Dispatches to added sensors that match the incoming Type.
root | The root json object. |
shieldEvent | The shield event. |
|
protected |
Event callback for when a full json string is received.
json | The json string. |
shieldEvent | The shield event to populate. |
|
protected |
Event callback for when a full string is received.
buffer | The buffer. |
length | The length. |
shieldEvent | The shield event. |
int VirtualShield::parseToHash | ( | const char * | text, |
unsigned int * | hash, | ||
int | hashCount, | ||
char | separator = ' ' , |
||
unsigned int | length = -1 |
||
) |
|
protected |
Sends the flash (PROGMEM) string on the communication channel.
flashStringAdr | The flash (PROGMEM) string address. |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
void VirtualShield::setPort | ( | int | port | ) |
Sets the port for bluetooth (this only works for AVR_ATmega32U4 where there are more than one port).
port | The port. |
int VirtualShield::waitFor | ( | int | id, |
long | timeout = WAITFOR_TIMEOUT , |
||
bool | asSuccess = true , |
||
int | resultId = -1 |
||
) |
Blocks and awaits an event with an id.
id | The id. |
timeout | The timeout. |
void VirtualShield::write | ( | const char * | text | ) |
Writes the specified text to the communication channel.
text | The text. |
int VirtualShield::write | ( | EPtr | eptr | ) | const |
Writes the specified eptr.
eptr | The eptr. |
int VirtualShield::writeAll | ( | const char * | serviceName, |
EPtr | values[], | ||
int | count, | ||
Attr | extraAttributes[] = 0 , |
||
int | extraAttributeCount = 0 , |
||
const char | sensorType = '\0' |
||
) |
Writes all EPtr values to the communication channel.
serviceName | Name of the service. |
values | The values. |
count | The count of values. |
int VirtualShield::writeAll | ( | const char * | serviceName | ) |
Writes the service name only to the communication channel.
serviceName | Name of the service. |
|
protected |
void(* VirtualShield::onConnect) (ShieldEvent *)=0 |
void(* VirtualShield::onEvent) (ShieldEvent *)=0 |
void(* VirtualShield::onRefresh) (ShieldEvent *)=0 |
void(* VirtualShield::onResume) (ShieldEvent *)=0 |
void(* VirtualShield::onSuspend) (ShieldEvent *)=0 |