Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Friends | List of all members
YBuzzer Class Reference

#include <yocto_buzzer.h>

Inheritance diagram for YBuzzer:
Inheritance graph
[legend]

Public Member Functions

virtual int _invokeValueCallback (string value)
 
virtual int addFreqMoveToPlaySeq (int freq, int msDelay)
 
virtual int addNotesToPlaySeq (string notes)
 
virtual int addPulseToPlaySeq (int freq, int msDuration)
 
virtual int addVolMoveToPlaySeq (int volume, int msDuration)
 
string command (void)
 
virtual int freqMove (int frequency, int duration)
 
double frequency (void)
 
string get_command (void)
 
double get_frequency (void)
 
int get_playSeqMaxSize (void)
 
int get_playSeqSignature (void)
 
int get_playSeqSize (void)
 
int get_volume (void)
 
YBuzzernext (void)
 
YBuzzernextBuzzer (void)
 
virtual int oncePlaySeq (void)
 
virtual int playNotes (string notes)
 
int playSeqMaxSize (void)
 
int playSeqSignature (void)
 
int playSeqSize (void)
 
virtual int pulse (int frequency, int duration)
 
virtual int registerValueCallback (YBuzzerValueCallback callback)
 
virtual int resetPlaySeq (void)
 
virtual int sendCommand (string command)
 
int set_command (const string &newval)
 
int set_frequency (double newval)
 
int set_volume (int newval)
 
int setCommand (const string &newval)
 
int setFrequency (double newval)
 
int setVolume (int newval)
 
virtual int startPlaySeq (void)
 
virtual int stopPlaySeq (void)
 
int volume (void)
 
virtual int volumeMove (int volume, int duration)
 
 ~YBuzzer ()
 
- 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)
 
virtual int _parserHelper (void)
 
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)
 
YModuleget_module (void)
 
void * get_userData (void)
 
bool isOnline (void)
 
YRETCODE load (int msValidity)
 
virtual string loadAttribute (string attrName)
 
string logicalName (void)
 
YModulemodule (void)
 
virtual int muteValueCallbacks (void)
 
YFunctionnext (void)
 
YFunctionnextFunction (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 YBuzzerFind (string func)
 
static YBuzzerFindBuzzer (string func)
 
static YBuzzerFirst (void)
 
static YBuzzerFirstBuzzer (void)
 
- Static Public Member Functions inherited from YFunction
static void _ClearCache (void)
 
static YFunctionFind (string func)
 
static YFunctionFindFunction (string func)
 
static YFunctionFirst (void)
 
static YFunctionFirstFunction (void)
 

Static Public Attributes

static const string COMMAND_INVALID = YAPI_INVALID_STRING
 
static const double FREQUENCY_INVALID = YAPI_INVALID_DOUBLE
 
static const int PLAYSEQMAXSIZE_INVALID = YAPI_INVALID_UINT
 
static const int PLAYSEQSIGNATURE_INVALID = YAPI_INVALID_UINT
 
static const int PLAYSEQSIZE_INVALID = YAPI_INVALID_UINT
 
static const int VOLUME_INVALID = YAPI_INVALID_UINT
 
- Static Public Attributes inherited from YFunction
static const string ADVERTISEDVALUE_INVALID = YAPI_INVALID_STRING
 
static const string FRIENDLYNAME_INVALID = YAPI_INVALID_STRING
 
static const YFUN_DESCR FUNCTIONDESCRIPTOR_INVALID = Y_FUNCTIONDESCRIPTOR_INVALID
 
static const string FUNCTIONID_INVALID = YAPI_INVALID_STRING
 
static const string HARDWAREID_INVALID = YAPI_INVALID_STRING
 
static const string LOGICALNAME_INVALID = YAPI_INVALID_STRING
 

Protected Member Functions

virtual int _parseAttr (YJSONObject *json_val)
 
 YBuzzer (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

string _command
 
double _frequency
 
int _playSeqMaxSize
 
int _playSeqSignature
 
int _playSeqSize
 
YBuzzerValueCallback _valueCallbackBuzzer
 
int _volume
 
- 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

YBuzzeryFindBuzzer (const string &func)
 
YBuzzeryFirstBuzzer (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
 

Detailed Description

YBuzzer Class: Buzzer function interface

The Yoctopuce application programming interface allows you to choose the frequency and volume at which the buzzer must sound. You can also pre-program a play sequence.

Definition at line 71 of file yocto_buzzer.h.

Constructor & Destructor Documentation

YBuzzer::YBuzzer ( const string &  func)
protected

Definition at line 51 of file yocto_buzzer.cpp.

YBuzzer::~YBuzzer ( )

Definition at line 65 of file yocto_buzzer.cpp.

Member Function Documentation

int YBuzzer::_invokeValueCallback ( string  value)
virtual

Reimplemented from YFunction.

Definition at line 413 of file yocto_buzzer.cpp.

int YBuzzer::_parseAttr ( YJSONObject json_val)
protectedvirtual

Reimplemented from YFunction.

Definition at line 75 of file yocto_buzzer.cpp.

int YBuzzer::addFreqMoveToPlaySeq ( int  freq,
int  msDelay 
)
virtual

Adds a new frequency transition to the playing sequence.

Parameters
freq: desired frequency when the transition is completed, in Hz
msDelay: duration of the frequency transition, in milliseconds.
Returns
YAPI_SUCCESS if the call succeeds. On failure, throws an exception or returns a negative error code.

Definition at line 437 of file yocto_buzzer.cpp.

int YBuzzer::addNotesToPlaySeq ( string  notes)
virtual

Adds notes to the playing sequence. Notes are provided as text words, separated by spaces. The pitch is specified using the usual letter from A to G. The duration is specified as the divisor of a whole note: 4 for a fourth, 8 for an eight note, etc. Some modifiers are supported: # and b to alter a note pitch, ' and , to move to the upper/lower octave, . to enlarge the note duration.

Parameters
notes: notes to be played, as a text string.
Returns
YAPI_SUCCESS if the call succeeds. On failure, throws an exception or returns a negative error code.

Definition at line 484 of file yocto_buzzer.cpp.

int YBuzzer::addPulseToPlaySeq ( int  freq,
int  msDuration 
)
virtual

Adds a pulse to the playing sequence.

Parameters
freq: pulse frequency, in Hz
msDuration: pulse duration, in milliseconds.
Returns
YAPI_SUCCESS if the call succeeds. On failure, throws an exception or returns a negative error code.

Definition at line 451 of file yocto_buzzer.cpp.

int YBuzzer::addVolMoveToPlaySeq ( int  volume,
int  msDuration 
)
virtual

Adds a new volume transition to the playing sequence. Frequency stays untouched: if frequency is at zero, the transition has no effect.

Parameters
volume: desired volume when the transition is completed, as a percentage.
msDuration: duration of the volume transition, in milliseconds.
Returns
YAPI_SUCCESS if the call succeeds. On failure, throws an exception or returns a negative error code.

Definition at line 466 of file yocto_buzzer.cpp.

string YBuzzer::command ( void  )
inline

Definition at line 199 of file yocto_buzzer.h.

static YBuzzer* YBuzzer::Find ( string  func)
inlinestatic

Definition at line 388 of file yocto_buzzer.h.

YBuzzer * YBuzzer::FindBuzzer ( string  func)
static

Retrieves a buzzer for a given identifier. The identifier can be specified using several formats:

  • FunctionLogicalName
  • ModuleSerialNumber.FunctionIdentifier
  • ModuleSerialNumber.FunctionLogicalName
  • ModuleLogicalName.FunctionIdentifier
  • ModuleLogicalName.FunctionLogicalName

This function does not require that the buzzer is online at the time it is invoked. The returned object is nevertheless valid. Use the method YBuzzer.isOnline() to test if the buzzer is indeed online at a given time. In case of ambiguity when looking for a buzzer 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.

Parameters
func: a string that uniquely characterizes the buzzer
Returns
a YBuzzer object allowing you to drive the buzzer.

Definition at line 362 of file yocto_buzzer.cpp.

static YBuzzer* YBuzzer::First ( void  )
inlinestatic

Definition at line 412 of file yocto_buzzer.h.

YBuzzer * YBuzzer::FirstBuzzer ( void  )
static

Starts the enumeration of buzzers currently accessible. Use the method YBuzzer.nextBuzzer() to iterate on next buzzers.

Returns
a pointer to a YBuzzer object, corresponding to the first buzzer currently online, or a NULL pointer if there are none.

Definition at line 765 of file yocto_buzzer.cpp.

int YBuzzer::freqMove ( int  frequency,
int  duration 
)
virtual

Makes the buzzer frequency change over a period of time.

Parameters
frequency: frequency to reach, in hertz. A frequency under 25Hz stops the buzzer.
duration: pulse duration in millseconds
Returns
YAPI_SUCCESS if the call succeeds.

On failure, throws an exception or returns a negative error code.

Definition at line 715 of file yocto_buzzer.cpp.

double YBuzzer::frequency ( void  )
inline

Definition at line 130 of file yocto_buzzer.h.

string YBuzzer::get_command ( void  )

Definition at line 297 of file yocto_buzzer.cpp.

double YBuzzer::get_frequency ( void  )

Returns the frequency of the signal sent to the buzzer/speaker.

Returns
a floating point number corresponding to the frequency of the signal sent to the buzzer/speaker

On failure, throws an exception or returns Y_FREQUENCY_INVALID.

Definition at line 131 of file yocto_buzzer.cpp.

int YBuzzer::get_playSeqMaxSize ( void  )

Returns the maximum length of the playing sequence.

Returns
an integer corresponding to the maximum length of the playing sequence

On failure, throws an exception or returns Y_PLAYSEQMAXSIZE_INVALID.

Definition at line 243 of file yocto_buzzer.cpp.

int YBuzzer::get_playSeqSignature ( void  )

Returns the playing sequence signature. As playing sequences cannot be read from the device, this can be used to detect if a specific playing sequence is already programmed.

Returns
an integer corresponding to the playing sequence signature

On failure, throws an exception or returns Y_PLAYSEQSIGNATURE_INVALID.

Definition at line 275 of file yocto_buzzer.cpp.

int YBuzzer::get_playSeqSize ( void  )

Returns the current length of the playing sequence.

Returns
an integer corresponding to the current length of the playing sequence

On failure, throws an exception or returns Y_PLAYSEQSIZE_INVALID.

Definition at line 214 of file yocto_buzzer.cpp.

int YBuzzer::get_volume ( void  )

Returns the volume of the signal sent to the buzzer/speaker.

Returns
an integer corresponding to the volume of the signal sent to the buzzer/speaker

On failure, throws an exception or returns Y_VOLUME_INVALID.

Definition at line 160 of file yocto_buzzer.cpp.

YBuzzer* YBuzzer::next ( void  )
inline

Definition at line 399 of file yocto_buzzer.h.

YBuzzer * YBuzzer::nextBuzzer ( void  )

Continues the enumeration of buzzers started using yFirstBuzzer().

Returns
a pointer to a YBuzzer object, corresponding to a buzzer currently online, or a NULL pointer if there are no more buzzers to enumerate.

Definition at line 755 of file yocto_buzzer.cpp.

int YBuzzer::oncePlaySeq ( void  )
virtual

Starts the preprogrammed playing sequence and run it once only.

Returns
YAPI_SUCCESS if the call succeeds. On failure, throws an exception or returns a negative error code.

Definition at line 685 of file yocto_buzzer.cpp.

int YBuzzer::playNotes ( string  notes)
virtual

Immediately play a note sequence. Notes are provided as text words, separated by spaces. The pitch is specified using the usual letter from A to G. The duration is specified as the divisor of a whole note: 4 for a fourth, 8 for an eight note, etc. Some modifiers are supported: # and b to alter a note pitch, ' and , to move to the upper/lower octave, . to enlarge the note duration.

Parameters
notes: notes to be played, as a text string.
Returns
YAPI_SUCCESS if the call succeeds. On failure, throws an exception or returns a negative error code.

Definition at line 748 of file yocto_buzzer.cpp.

int YBuzzer::playSeqMaxSize ( void  )
inline

Definition at line 179 of file yocto_buzzer.h.

int YBuzzer::playSeqSignature ( void  )
inline

Definition at line 194 of file yocto_buzzer.h.

int YBuzzer::playSeqSize ( void  )
inline

Definition at line 167 of file yocto_buzzer.h.

int YBuzzer::pulse ( int  frequency,
int  duration 
)
virtual

Activates the buzzer for a short duration.

Parameters
frequency: pulse frequency, in hertz
duration: pulse duration in millseconds
Returns
YAPI_SUCCESS if the call succeeds.

On failure, throws an exception or returns a negative error code.

Definition at line 700 of file yocto_buzzer.cpp.

int YBuzzer::registerValueCallback ( YBuzzerValueCallback  callback)
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.

Parameters
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 394 of file yocto_buzzer.cpp.

int YBuzzer::resetPlaySeq ( void  )
virtual

Resets the preprogrammed playing sequence and sets the frequency to zero.

Returns
YAPI_SUCCESS if the call succeeds. On failure, throws an exception or returns a negative error code.

Definition at line 674 of file yocto_buzzer.cpp.

int YBuzzer::sendCommand ( string  command)
virtual

Definition at line 423 of file yocto_buzzer.cpp.

int YBuzzer::set_command ( const string &  newval)

Definition at line 319 of file yocto_buzzer.cpp.

int YBuzzer::set_frequency ( double  newval)

Changes the frequency of the signal sent to the buzzer. A zero value stops the buzzer.

Parameters
newval: a floating point number corresponding to the frequency of the signal sent to the buzzer
Returns
YAPI_SUCCESS if the call succeeds.

On failure, throws an exception or returns a negative error code.

Definition at line 108 of file yocto_buzzer.cpp.

int YBuzzer::set_volume ( int  newval)

Changes the volume of the signal sent to the buzzer/speaker.

Parameters
newval: an integer corresponding to the volume of the signal sent to the buzzer/speaker
Returns
YAPI_SUCCESS if the call succeeds.

On failure, throws an exception or returns a negative error code.

Definition at line 191 of file yocto_buzzer.cpp.

int YBuzzer::setCommand ( const string &  newval)
inline

Definition at line 203 of file yocto_buzzer.h.

int YBuzzer::setFrequency ( double  newval)
inline

Definition at line 118 of file yocto_buzzer.h.

int YBuzzer::setVolume ( int  newval)
inline

Definition at line 155 of file yocto_buzzer.h.

int YBuzzer::startPlaySeq ( void  )
virtual

Starts the preprogrammed playing sequence. The sequence runs in loop until it is stopped by stopPlaySeq or an explicit change. To play the sequence only once, use oncePlaySeq().

Returns
YAPI_SUCCESS if the call succeeds. On failure, throws an exception or returns a negative error code.

Definition at line 652 of file yocto_buzzer.cpp.

int YBuzzer::stopPlaySeq ( void  )
virtual

Stops the preprogrammed playing sequence and sets the frequency to zero.

Returns
YAPI_SUCCESS if the call succeeds. On failure, throws an exception or returns a negative error code.

Definition at line 663 of file yocto_buzzer.cpp.

int YBuzzer::volume ( void  )
inline

Definition at line 142 of file yocto_buzzer.h.

int YBuzzer::volumeMove ( int  volume,
int  duration 
)
virtual

Makes the buzzer volume change over a period of time, frequency stays untouched.

Parameters
volume: volume to reach in %
duration: change duration in millseconds
Returns
YAPI_SUCCESS if the call succeeds.

On failure, throws an exception or returns a negative error code.

Definition at line 730 of file yocto_buzzer.cpp.

Friends And Related Function Documentation

YBuzzer* yFindBuzzer ( const string &  func)
friend

Retrieves a buzzer for a given identifier. The identifier can be specified using several formats:

  • FunctionLogicalName
  • ModuleSerialNumber.FunctionIdentifier
  • ModuleSerialNumber.FunctionLogicalName
  • ModuleLogicalName.FunctionIdentifier
  • ModuleLogicalName.FunctionLogicalName

This function does not require that the buzzer is online at the time it is invoked. The returned object is nevertheless valid. Use the method YBuzzer.isOnline() to test if the buzzer is indeed online at a given time. In case of ambiguity when looking for a buzzer 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.

Parameters
func: a string that uniquely characterizes the buzzer
Returns
a YBuzzer object allowing you to drive the buzzer.

Definition at line 449 of file yocto_buzzer.h.

YBuzzer* yFirstBuzzer ( void  )
friend

Starts the enumeration of buzzers currently accessible. Use the method YBuzzer.nextBuzzer() to iterate on next buzzers.

Returns
a pointer to a YBuzzer object, corresponding to the first buzzer currently online, or a NULL pointer if there are none.

Definition at line 460 of file yocto_buzzer.h.

Member Data Documentation

string YBuzzer::_command
protected

Definition at line 84 of file yocto_buzzer.h.

double YBuzzer::_frequency
protected

Definition at line 79 of file yocto_buzzer.h.

int YBuzzer::_playSeqMaxSize
protected

Definition at line 82 of file yocto_buzzer.h.

int YBuzzer::_playSeqSignature
protected

Definition at line 83 of file yocto_buzzer.h.

int YBuzzer::_playSeqSize
protected

Definition at line 81 of file yocto_buzzer.h.

YBuzzerValueCallback YBuzzer::_valueCallbackBuzzer
protected

Definition at line 85 of file yocto_buzzer.h.

int YBuzzer::_volume
protected

Definition at line 80 of file yocto_buzzer.h.

const string YBuzzer::COMMAND_INVALID = YAPI_INVALID_STRING
static

Definition at line 106 of file yocto_buzzer.h.

const double YBuzzer::FREQUENCY_INVALID = YAPI_INVALID_DOUBLE
static

Definition at line 101 of file yocto_buzzer.h.

const int YBuzzer::PLAYSEQMAXSIZE_INVALID = YAPI_INVALID_UINT
static

Definition at line 104 of file yocto_buzzer.h.

const int YBuzzer::PLAYSEQSIGNATURE_INVALID = YAPI_INVALID_UINT
static

Definition at line 105 of file yocto_buzzer.h.

const int YBuzzer::PLAYSEQSIZE_INVALID = YAPI_INVALID_UINT
static

Definition at line 103 of file yocto_buzzer.h.

const int YBuzzer::VOLUME_INVALID = YAPI_INVALID_UINT
static

Definition at line 102 of file yocto_buzzer.h.


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


yoctopuce_altimeter
Author(s): Anja Sheppard
autogenerated on Mon Jun 10 2019 15:49:13