#include <yocto_buzzer.h>
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) |
YBuzzer * | next (void) |
YBuzzer * | nextBuzzer (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) |
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 YBuzzer * | Find (string func) |
static YBuzzer * | FindBuzzer (string func) |
static YBuzzer * | First (void) |
static YBuzzer * | FirstBuzzer (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) |
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 | |
YBuzzer * | yFindBuzzer (const string &func) |
YBuzzer * | yFirstBuzzer (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 |
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.
|
protected |
Definition at line 51 of file yocto_buzzer.cpp.
YBuzzer::~YBuzzer | ( | ) |
Definition at line 65 of file yocto_buzzer.cpp.
|
virtual |
Reimplemented from YFunction.
Definition at line 413 of file yocto_buzzer.cpp.
|
protectedvirtual |
Reimplemented from YFunction.
Definition at line 75 of file yocto_buzzer.cpp.
|
virtual |
Adds a new frequency transition to the playing sequence.
freq | : desired frequency when the transition is completed, in Hz |
msDelay | : duration of the frequency transition, in milliseconds. |
Definition at line 437 of file yocto_buzzer.cpp.
|
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.
notes | : notes to be played, as a text string. |
Definition at line 484 of file yocto_buzzer.cpp.
|
virtual |
Adds a pulse to the playing sequence.
freq | : pulse frequency, in Hz |
msDuration | : pulse duration, in milliseconds. |
Definition at line 451 of file yocto_buzzer.cpp.
|
virtual |
Adds a new volume transition to the playing sequence. Frequency stays untouched: if frequency is at zero, the transition has no effect.
volume | : desired volume when the transition is completed, as a percentage. |
msDuration | : duration of the volume transition, in milliseconds. |
Definition at line 466 of file yocto_buzzer.cpp.
|
inline |
Definition at line 199 of file yocto_buzzer.h.
|
inlinestatic |
Definition at line 388 of file yocto_buzzer.h.
|
static |
Retrieves a buzzer for a given identifier. The identifier can be specified using several formats:
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.
func | : a string that uniquely characterizes the buzzer |
Definition at line 362 of file yocto_buzzer.cpp.
|
inlinestatic |
Definition at line 412 of file yocto_buzzer.h.
|
static |
Starts the enumeration of buzzers currently accessible. Use the method YBuzzer.nextBuzzer() to iterate on next buzzers.
Definition at line 765 of file yocto_buzzer.cpp.
|
virtual |
Makes the buzzer frequency change over a period of time.
frequency | : frequency to reach, in hertz. A frequency under 25Hz stops the buzzer. |
duration | : pulse duration in millseconds |
On failure, throws an exception or returns a negative error code.
Definition at line 715 of file yocto_buzzer.cpp.
|
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.
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.
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.
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.
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.
On failure, throws an exception or returns Y_VOLUME_INVALID.
Definition at line 160 of file yocto_buzzer.cpp.
|
inline |
Definition at line 399 of file yocto_buzzer.h.
YBuzzer * YBuzzer::nextBuzzer | ( | void | ) |
Continues the enumeration of buzzers started using yFirstBuzzer().
Definition at line 755 of file yocto_buzzer.cpp.
|
virtual |
Starts the preprogrammed playing sequence and run it once only.
Definition at line 685 of file yocto_buzzer.cpp.
|
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.
notes | : notes to be played, as a text string. |
Definition at line 748 of file yocto_buzzer.cpp.
|
inline |
Definition at line 179 of file yocto_buzzer.h.
|
inline |
Definition at line 194 of file yocto_buzzer.h.
|
inline |
Definition at line 167 of file yocto_buzzer.h.
|
virtual |
Activates the buzzer for a short duration.
frequency | : pulse frequency, in hertz |
duration | : pulse duration in millseconds |
On failure, throws an exception or returns a negative error code.
Definition at line 700 of file yocto_buzzer.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 394 of file yocto_buzzer.cpp.
|
virtual |
Resets the preprogrammed playing sequence and sets the frequency to zero.
Definition at line 674 of file yocto_buzzer.cpp.
|
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.
newval | : a floating point number corresponding to the frequency of the signal sent to the buzzer |
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.
newval | : an integer corresponding to the volume of the signal sent to the buzzer/speaker |
On failure, throws an exception or returns a negative error code.
Definition at line 191 of file yocto_buzzer.cpp.
|
inline |
Definition at line 203 of file yocto_buzzer.h.
|
inline |
Definition at line 118 of file yocto_buzzer.h.
|
inline |
Definition at line 155 of file yocto_buzzer.h.
|
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().
Definition at line 652 of file yocto_buzzer.cpp.
|
virtual |
Stops the preprogrammed playing sequence and sets the frequency to zero.
Definition at line 663 of file yocto_buzzer.cpp.
|
inline |
Definition at line 142 of file yocto_buzzer.h.
|
virtual |
Makes the buzzer volume change over a period of time, frequency stays untouched.
volume | : volume to reach in % |
duration | : change duration in millseconds |
On failure, throws an exception or returns a negative error code.
Definition at line 730 of file yocto_buzzer.cpp.
|
friend |
Retrieves a buzzer for a given identifier. The identifier can be specified using several formats:
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.
func | : a string that uniquely characterizes the buzzer |
Definition at line 449 of file yocto_buzzer.h.
|
friend |
Starts the enumeration of buzzers currently accessible. Use the method YBuzzer.nextBuzzer() to iterate on next buzzers.
Definition at line 460 of file yocto_buzzer.h.
|
protected |
Definition at line 84 of file yocto_buzzer.h.
|
protected |
Definition at line 79 of file yocto_buzzer.h.
|
protected |
Definition at line 82 of file yocto_buzzer.h.
|
protected |
Definition at line 83 of file yocto_buzzer.h.
|
protected |
Definition at line 81 of file yocto_buzzer.h.
|
protected |
Definition at line 85 of file yocto_buzzer.h.
|
protected |
Definition at line 80 of file yocto_buzzer.h.
|
static |
Definition at line 106 of file yocto_buzzer.h.
|
static |
Definition at line 101 of file yocto_buzzer.h.
|
static |
Definition at line 104 of file yocto_buzzer.h.
|
static |
Definition at line 105 of file yocto_buzzer.h.
|
static |
Definition at line 103 of file yocto_buzzer.h.
|
static |
Definition at line 102 of file yocto_buzzer.h.