41 #define _CRT_SECURE_NO_DEPRECATE //do not use windows secure crt 49 #define __FILE_ID__ "servo" 53 ,_position(POSITION_INVALID)
54 ,_enabled(ENABLED_INVALID)
55 ,_range(RANGE_INVALID)
56 ,_neutral(NEUTRAL_INVALID)
58 ,_positionAtPowerOn(POSITIONATPOWERON_INVALID)
59 ,_enabledAtPowerOn(ENABLEDATPOWERON_INVALID)
60 ,_valueCallbackServo(NULL)
77 if(json_val->
has(
"position")) {
80 if(json_val->
has(
"enabled")) {
83 if(json_val->
has(
"range")) {
86 if(json_val->
has(
"neutral")) {
89 if(json_val->
has(
"move")) {
91 if (subjson->
has(
"moving")) {
94 if (subjson->
has(
"target")) {
97 if (subjson->
has(
"ms")) {
101 if(json_val->
has(
"positionAtPowerOn")) {
104 if(json_val->
has(
"enabledAtPowerOn")) {
132 }
catch (std::exception) {
155 char buf[32]; sprintf(buf,
"%d", newval); rest_val = string(buf);
156 res =
_setAttr(
"position", rest_val);
157 }
catch (std::exception) {
186 }
catch (std::exception) {
209 rest_val = (newval>0 ?
"1" :
"0");
210 res =
_setAttr(
"enabled", rest_val);
211 }
catch (std::exception) {
240 }
catch (std::exception) {
269 char buf[32]; sprintf(buf,
"%d", newval); rest_val = string(buf);
271 }
catch (std::exception) {
300 }
catch (std::exception) {
329 char buf[32]; sprintf(buf,
"%d", newval); rest_val = string(buf);
330 res =
_setAttr(
"neutral", rest_val);
331 }
catch (std::exception) {
353 }
catch (std::exception) {
367 char buff[64]; sprintf(buff,
"%d:%d",newval.
target,newval.
ms); rest_val = string(buff);
369 }
catch (std::exception) {
390 char buff[64]; sprintf(buff,
"%d:%d",target,ms_duration); rest_val = string(buff);
415 }
catch (std::exception) {
439 char buf[32]; sprintf(buf,
"%d", newval); rest_val = string(buf);
440 res =
_setAttr(
"positionAtPowerOn", rest_val);
441 }
catch (std::exception) {
471 }
catch (std::exception) {
495 rest_val = (newval>0 ?
"1" :
"0");
496 res =
_setAttr(
"enabledAtPowerOn", rest_val);
497 }
catch (std::exception) {
545 }
catch (std::exception) {
567 if (callback != NULL) {
574 if (callback != NULL && this->
isOnline()) {
605 vector<YFUN_DESCR> v_fundescr;
607 string serial, funcId, funcName, funcVal, errmsg;
610 v_fundescr.size() == 0 ||
yCRITICAL_SECTION _this_cs
virtual int _parseAttr(YJSONObject *json_val)
int set_position(int newval)
YRETCODE _load_unsafe(int msValidity)
static const YMove MOVE_INVALID
int set_neutral(int newval)
int set_enabled(Y_ENABLED_enum newval)
static int DefaultCacheValidity
YJSONObject * getYJSONObject(const string &key)
virtual int _invokeValueCallback(string value)
static YServo * FindServo(string func)
static const Y_ENABLED_enum ENABLED_INVALID
void yLeaveCriticalSection(yCRITICAL_SECTION *cs)
int set_range(int newval)
int set_positionAtPowerOn(int newval)
YServo(const string &func)
static YRETCODE getFunctionInfo(YFUN_DESCR fundesc, YDEV_DESCR &devdescr, string &serial, string &funcId, string &funcName, string &funcVal, string &errmsg)
virtual int registerValueCallback(YServoValueCallback callback)
int set_move(YMove newval)
Y_ENABLEDATPOWERON_enum _enabledAtPowerOn
virtual int _parseAttr(YJSONObject *json_val)
static const int POSITION_INVALID
int set_enabledAtPowerOn(Y_ENABLEDATPOWERON_enum newval)
int getInt(const string &key)
static u64 GetTickCount(void)
static YServo * FirstServo(void)
static void _AddToCache(const string &classname, const string &func, YFunction *obj)
Y_ENABLEDATPOWERON_enum get_enabledAtPowerOn(void)
static YFunction * _FindFromCache(const string &classname, const string &func)
void yEnterCriticalSection(yCRITICAL_SECTION *cs)
static yCRITICAL_SECTION _global_cs
static const int NEUTRAL_INVALID
void(* YServoValueCallback)(YServo *func, const string &functionValue)
static const Y_ENABLEDATPOWERON_enum ENABLEDATPOWERON_INVALID
static int getFunctionsByClass(const string &class_str, YFUN_DESCR prevfundesc, vector< YFUN_DESCR > &buffer, int maxsize, string &errmsg)
static const int POSITIONATPOWERON_INVALID
Y_ENABLED_enum get_enabled(void)
static bool _apiInitialized
YRETCODE _nextFunction(string &hwId)
static void _UpdateValueCallbackList(YFunction *func, bool add)
YServoValueCallback _valueCallbackServo
static const int RANGE_INVALID
int get_positionAtPowerOn(void)
bool has(const string &key)
YRETCODE _setAttr(string attrname, string newvalue)
virtual int _invokeValueCallback(string value)