41 #define _CRT_SECURE_NO_DEPRECATE //do not use windows secure crt 49 #define __FILE_ID__ "gyro" 55 ,_valueCallbackQt(NULL)
56 ,_timedReportCallbackQt(NULL)
111 }
catch (std::exception) {
133 if (callback != NULL) {
140 if (callback != NULL && this->
isOnline()) {
174 if (callback != NULL) {
205 vector<YFUN_DESCR> v_fundescr;
207 string serial, funcId, funcName, funcVal, errmsg;
210 v_fundescr.size() == 0 ||
230 int idx = atoi(tmp.c_str());
231 double dbl_value = atof(value.c_str());
240 ,_bandwidth(BANDWIDTH_INVALID)
241 ,_xValue(XVALUE_INVALID)
242 ,_yValue(YVALUE_INVALID)
243 ,_zValue(ZVALUE_INVALID)
244 ,_valueCallbackGyro(NULL)
245 ,_timedReportCallbackGyro(NULL)
260 ,_anglesCallback(NULL)
279 if(json_val->
has(
"bandwidth")) {
282 if(json_val->
has(
"xValue")) {
283 _xValue = floor(json_val->
getDouble(
"xValue") * 1000.0 / 65536.0 + 0.5) / 1000.0;
285 if(json_val->
has(
"yValue")) {
286 _yValue = floor(json_val->
getDouble(
"yValue") * 1000.0 / 65536.0 + 0.5) / 1000.0;
288 if(json_val->
has(
"zValue")) {
289 _zValue = floor(json_val->
getDouble(
"zValue") * 1000.0 / 65536.0 + 0.5) / 1000.0;
316 }
catch (std::exception) {
340 char buf[32]; sprintf(buf,
"%d", newval); rest_val = string(buf);
341 res =
_setAttr(
"bandwidth", rest_val);
342 }
catch (std::exception) {
372 }
catch (std::exception) {
402 }
catch (std::exception) {
432 }
catch (std::exception) {
477 obj =
new YGyro(func);
480 }
catch (std::exception) {
502 if (callback != NULL) {
509 if (callback != NULL && this->
isOnline()) {
543 if (callback != NULL) {
567 age_ms = (((now_stamp -
_qt_stamp)) & (0x7FFFFFFF));
568 if ((age_ms >= 10) || (
_qt_stamp == 0)) {
616 norm = sqx + sqy + sqz + sqw;
617 delta = _y * _w - _x *
_z;
618 if (delta > 0.499 * norm) {
621 _head = floor(2.0 * 1800.0/3.141592653589793238463 * atan2(_x,-_w)+0.5) / 10.0;
623 if (delta < -0.499 * norm) {
626 _head = floor(-2.0 * 1800.0/3.141592653589793238463 * atan2(_x,-_w)+0.5) / 10.0;
628 _roll = floor(1800.0/3.141592653589793238463 * atan2(2.0 * (_w * _x + _y * _z),sqw - sqx - sqy + sqz)+0.5) / 10.0;
629 _pitch = floor(1800.0/3.141592653589793238463 * asin(2.0 * delta / norm)+0.5) / 10.0;
630 _head = floor(1800.0/3.141592653589793238463 * atan2(2.0 * (_x * _y + _z * _w),sqw + sqx - sqy - sqz)+0.5) / 10.0;
770 if (callback != NULL) {
811 if (callback != NULL) {
836 switch(qtIndex - 1) {
876 vector<YFUN_DESCR> v_fundescr;
878 string serial, funcId, funcName, funcVal, errmsg;
881 v_fundescr.size() == 0 ||
int set_bandwidth(int newval)
double getDouble(const string &key)
virtual int registerAnglesCallback(YAnglesCallback callback)
yCRITICAL_SECTION _this_cs
virtual int registerQuaternionCallback(YQuatCallback callback)
static const double ZVALUE_INVALID
static void _UpdateTimedReportCallbackList(YFunction *func, bool add)
YRETCODE _load_unsafe(int msValidity)
static YGyro * FirstGyro(void)
virtual int _loadAngles(void)
virtual int _invokeGyroCallbacks(int qtIndex, double qtValue)
virtual int _loadQuaternion(void)
YQuatCallback _quatCallback
void(* YQtTimedReportCallback)(YQt *func, YMeasure measure)
virtual double get_heading(void)
static YQt * FindQt(string func)
YGyroValueCallback _valueCallbackGyro
static int DefaultCacheValidity
YQtValueCallback _valueCallbackQt
void(* YQtValueCallback)(YQt *func, const string &functionValue)
YGyro(const string &func)
virtual double get_quaternionY(void)
void set_userData(void *data)
YRETCODE load(int msValidity)
void yLeaveCriticalSection(yCRITICAL_SECTION *cs)
virtual double get_roll(void)
static YRETCODE getFunctionInfo(YFUN_DESCR fundesc, YDEV_DESCR &devdescr, string &serial, string &funcId, string &funcName, string &funcVal, string &errmsg)
double get_currentValue(void)
virtual double get_quaternionX(void)
void * get_userData(void)
string get_functionId(void)
YAnglesCallback _anglesCallback
virtual int registerValueCallback(YGyroValueCallback callback)
virtual int registerValueCallback(YQtValueCallback callback)
static YGyro * FindGyro(string func)
int getInt(const string &key)
static u64 GetTickCount(void)
static void _AddToCache(const string &classname, const string &func, YFunction *obj)
static const double XVALUE_INVALID
#define YAPI_INVALID_DOUBLE
virtual int _invokeTimedReportCallback(YMeasure value)
virtual int _invokeValueCallback(string value)
void(* YQuatCallback)(YGyro *yGyro, double w, double x, double y, double z)
static YFunction * _FindFromCache(const string &classname, const string &func)
virtual int _invokeTimedReportCallback(YMeasure value)
virtual double get_quaternionZ(void)
static string ysprintf(const char *fmt,...)
virtual int _invokeValueCallback(string value)
void yEnterCriticalSection(yCRITICAL_SECTION *cs)
static yCRITICAL_SECTION _global_cs
virtual double get_quaternionW(void)
virtual int _invokeTimedReportCallback(YMeasure value)
static const double YVALUE_INVALID
virtual int _parseAttr(YJSONObject *json_val)
virtual int _parseAttr(YJSONObject *json_val)
static int getFunctionsByClass(const string &class_str, YFUN_DESCR prevfundesc, vector< YFUN_DESCR > &buffer, int maxsize, string &errmsg)
static void yInternalGyroCallback(YQt *obj, const string &value)
YQtTimedReportCallback _timedReportCallbackQt
virtual int registerTimedReportCallback(YQtTimedReportCallback callback)
static const int BANDWIDTH_INVALID
void(* YGyroTimedReportCallback)(YGyro *func, YMeasure measure)
static bool _apiInitialized
YRETCODE _nextFunction(string &hwId)
virtual int registerTimedReportCallback(YGyroTimedReportCallback callback)
virtual int _invokeValueCallback(string value)
virtual double get_pitch(void)
static void _UpdateValueCallbackList(YFunction *func, bool add)
void(* YAnglesCallback)(YGyro *yGyro, double roll, double pitch, double head)
YGyroTimedReportCallback _timedReportCallbackGyro
bool has(const string &key)
YRETCODE _setAttr(string attrname, string newvalue)
void(* YGyroValueCallback)(YGyro *func, const string &functionValue)
static YQt * FirstQt(void)