41 #define _CRT_SECURE_NO_DEPRECATE //do not use windows secure crt 49 #define __FILE_ID__ "buzzer" 53 ,_frequency(FREQUENCY_INVALID)
54 ,_volume(VOLUME_INVALID)
55 ,_playSeqSize(PLAYSEQSIZE_INVALID)
56 ,_playSeqMaxSize(PLAYSEQMAXSIZE_INVALID)
57 ,_playSeqSignature(PLAYSEQSIGNATURE_INVALID)
58 ,_command(COMMAND_INVALID)
59 ,_valueCallbackBuzzer(NULL)
77 if(json_val->
has(
"frequency")) {
80 if(json_val->
has(
"volume")) {
83 if(json_val->
has(
"playSeqSize")) {
86 if(json_val->
has(
"playSeqMaxSize")) {
89 if(json_val->
has(
"playSeqSignature")) {
92 if(json_val->
has(
"command")) {
114 char buf[32]; sprintf(buf,
"%d", (
int)floor(newval * 65536.0 + 0.5)); rest_val = string(buf);
115 res =
_setAttr(
"frequency", rest_val);
116 }
catch (std::exception) {
145 }
catch (std::exception) {
174 }
catch (std::exception) {
197 char buf[32]; sprintf(buf,
"%d", newval); rest_val = string(buf);
199 }
catch (std::exception) {
228 }
catch (std::exception) {
257 }
catch (std::exception) {
289 }
catch (std::exception) {
311 }
catch (std::exception) {
326 res =
_setAttr(
"command", rest_val);
327 }
catch (std::exception) {
375 }
catch (std::exception) {
397 if (callback != NULL) {
404 if (callback != NULL && this->
isOnline()) {
488 int prevDuration = 0;
511 notesLen = (int)(ascNotes).size();
513 while (i < notesLen) {
514 ch = ((u8)ascNotes[i]);
553 prevPitch = prevPitch + 12;
557 prevPitch = prevPitch - 12;
580 if ((ch == 37) && (num > 0)) {
584 if ((ch >= 48) && (ch <= 57)) {
586 num = (num * 10) + (ch - 48);
590 num = ((num * 2) / (3));
592 if (((ch == 32) || (i+1 == notesLen)) && ((note > -99) || (typ != 3))) {
598 ms = (int) floor(320000.0 / (tempo * num)+0.5);
602 dNote = note - (((prevPitch) % (12)));
609 pitch = prevPitch + dNote;
610 freq = (int) floor(440 * exp(pitch * 0.05776226504666)+0.5);
611 ms16 = ((ms) >> (4));
767 vector<YFUN_DESCR> v_fundescr;
769 string serial, funcId, funcName, funcVal, errmsg;
772 v_fundescr.size() == 0 ||
virtual int freqMove(int frequency, int duration)
double getDouble(const string &key)
void(* YBuzzerValueCallback)(YBuzzer *func, const string &functionValue)
yCRITICAL_SECTION _this_cs
static const string COMMAND_INVALID
virtual int addVolMoveToPlaySeq(int volume, int msDuration)
int get_playSeqSignature(void)
static const int PLAYSEQSIZE_INVALID
YRETCODE _load_unsafe(int msValidity)
static const int PLAYSEQMAXSIZE_INVALID
virtual int resetPlaySeq(void)
static int DefaultCacheValidity
string getString(const string &key)
virtual int oncePlaySeq(void)
int set_command(const string &newval)
int get_playSeqSize(void)
void yLeaveCriticalSection(yCRITICAL_SECTION *cs)
static YRETCODE getFunctionInfo(YFUN_DESCR fundesc, YDEV_DESCR &devdescr, string &serial, string &funcId, string &funcName, string &funcVal, string &errmsg)
static YBuzzer * FindBuzzer(string func)
#define YAPI_INVALID_STRING
virtual int volumeMove(int volume, int duration)
virtual int _parseAttr(YJSONObject *json_val)
int set_volume(int newval)
YBuzzerValueCallback _valueCallbackBuzzer
int get_playSeqMaxSize(void)
int getInt(const string &key)
static u64 GetTickCount(void)
static void _AddToCache(const string &classname, const string &func, YFunction *obj)
#define YAPI_INVALID_DOUBLE
static YFunction * _FindFromCache(const string &classname, const string &func)
virtual int playNotes(string notes)
static string ysprintf(const char *fmt,...)
void yEnterCriticalSection(yCRITICAL_SECTION *cs)
static YBuzzer * FirstBuzzer(void)
static yCRITICAL_SECTION _global_cs
virtual int pulse(int frequency, int duration)
YBuzzer(const string &func)
static const double FREQUENCY_INVALID
static int getFunctionsByClass(const string &class_str, YFUN_DESCR prevfundesc, vector< YFUN_DESCR > &buffer, int maxsize, string &errmsg)
int set_frequency(double newval)
virtual int sendCommand(string command)
virtual int _invokeValueCallback(string value)
YBuzzer * nextBuzzer(void)
virtual int addNotesToPlaySeq(string notes)
virtual int registerValueCallback(YBuzzerValueCallback callback)
virtual int _parseAttr(YJSONObject *json_val)
virtual int addPulseToPlaySeq(int freq, int msDuration)
static bool _apiInitialized
YRETCODE _nextFunction(string &hwId)
static const int VOLUME_INVALID
virtual int addFreqMoveToPlaySeq(int freq, int msDelay)
static void _UpdateValueCallbackList(YFunction *func, bool add)
double get_frequency(void)
bool has(const string &key)
virtual int stopPlaySeq(void)
YRETCODE _setAttr(string attrname, string newvalue)
virtual int startPlaySeq(void)
virtual int _invokeValueCallback(string value)
static const int PLAYSEQSIGNATURE_INVALID