41 #define _CRT_SECURE_NO_DEPRECATE //do not use windows secure crt 49 #define __FILE_ID__ "pwmoutput" 53 ,_enabled(ENABLED_INVALID)
54 ,_frequency(FREQUENCY_INVALID)
55 ,_period(PERIOD_INVALID)
56 ,_dutyCycle(DUTYCYCLE_INVALID)
57 ,_pulseDuration(PULSEDURATION_INVALID)
58 ,_pwmTransition(PWMTRANSITION_INVALID)
59 ,_enabledAtPowerOn(ENABLEDATPOWERON_INVALID)
60 ,_dutyCycleAtPowerOn(DUTYCYCLEATPOWERON_INVALID)
61 ,_valueCallbackPwmOutput(NULL)
83 if(json_val->
has(
"enabled")) {
86 if(json_val->
has(
"frequency")) {
89 if(json_val->
has(
"period")) {
90 _period = floor(json_val->
getDouble(
"period") * 1000.0 / 65536.0 + 0.5) / 1000.0;
92 if(json_val->
has(
"dutyCycle")) {
95 if(json_val->
has(
"pulseDuration")) {
98 if(json_val->
has(
"pwmTransition")) {
101 if(json_val->
has(
"enabledAtPowerOn")) {
104 if(json_val->
has(
"dutyCycleAtPowerOn")) {
132 }
catch (std::exception) {
155 rest_val = (newval>0 ?
"1" :
"0");
156 res =
_setAttr(
"enabled", rest_val);
157 }
catch (std::exception) {
181 char buf[32]; sprintf(buf,
"%d", (
int)floor(newval * 65536.0 + 0.5)); rest_val = string(buf);
182 res =
_setAttr(
"frequency", rest_val);
183 }
catch (std::exception) {
212 }
catch (std::exception) {
235 char buf[32]; sprintf(buf,
"%d", (
int)floor(newval * 65536.0 + 0.5)); rest_val = string(buf);
237 }
catch (std::exception) {
266 }
catch (std::exception) {
289 char buf[32]; sprintf(buf,
"%d", (
int)floor(newval * 65536.0 + 0.5)); rest_val = string(buf);
290 res =
_setAttr(
"dutyCycle", rest_val);
291 }
catch (std::exception) {
320 }
catch (std::exception) {
344 char buf[32]; sprintf(buf,
"%d", (
int)floor(newval * 65536.0 + 0.5)); rest_val = string(buf);
345 res =
_setAttr(
"pulseDuration", rest_val);
346 }
catch (std::exception) {
376 }
catch (std::exception) {
398 }
catch (std::exception) {
413 res =
_setAttr(
"pwmTransition", rest_val);
414 }
catch (std::exception) {
444 }
catch (std::exception) {
469 rest_val = (newval>0 ?
"1" :
"0");
470 res =
_setAttr(
"enabledAtPowerOn", rest_val);
471 }
catch (std::exception) {
495 char buf[32]; sprintf(buf,
"%d", (
int)floor(newval * 65536.0 + 0.5)); rest_val = string(buf);
496 res =
_setAttr(
"dutyCycleAtPowerOn", rest_val);
497 }
catch (std::exception) {
527 }
catch (std::exception) {
575 }
catch (std::exception) {
597 if (callback != NULL) {
604 if (callback != NULL && this->
isOnline()) {
638 if (ms_target < 0.0) {
662 if (target > 100.0) {
681 vector<YFUN_DESCR> v_fundescr;
683 string serial, funcId, funcName, funcVal, errmsg;
686 v_fundescr.size() == 0 ||
double getDouble(const string &key)
yCRITICAL_SECTION _this_cs
int set_enabled(Y_ENABLED_enum newval)
virtual int registerValueCallback(YPwmOutputValueCallback callback)
YRETCODE _load_unsafe(int msValidity)
Y_ENABLED_enum get_enabled(void)
double get_pulseDuration(void)
static const double PULSEDURATION_INVALID
virtual int _invokeValueCallback(string value)
double get_frequency(void)
int set_dutyCycleAtPowerOn(double newval)
int set_frequency(double newval)
static const string PWMTRANSITION_INVALID
static int DefaultCacheValidity
string getString(const string &key)
virtual int dutyCycleMove(double target, int ms_duration)
static const double PERIOD_INVALID
void yLeaveCriticalSection(yCRITICAL_SECTION *cs)
double get_dutyCycleAtPowerOn(void)
static YRETCODE getFunctionInfo(YFUN_DESCR fundesc, YDEV_DESCR &devdescr, string &serial, string &funcId, string &funcName, string &funcVal, string &errmsg)
int set_pulseDuration(double newval)
#define YAPI_INVALID_STRING
static YPwmOutput * FirstPwmOutput(void)
virtual int _parseAttr(YJSONObject *json_val)
int getInt(const string &key)
static u64 GetTickCount(void)
static void _AddToCache(const string &classname, const string &func, YFunction *obj)
#define YAPI_INVALID_DOUBLE
void(* YPwmOutputValueCallback)(YPwmOutput *func, const string &functionValue)
static YFunction * _FindFromCache(const string &classname, const string &func)
int set_pwmTransition(const string &newval)
static string ysprintf(const char *fmt,...)
static const Y_ENABLED_enum ENABLED_INVALID
void yEnterCriticalSection(yCRITICAL_SECTION *cs)
static yCRITICAL_SECTION _global_cs
static const double DUTYCYCLEATPOWERON_INVALID
YPwmOutputValueCallback _valueCallbackPwmOutput
int set_enabledAtPowerOn(Y_ENABLEDATPOWERON_enum newval)
static int getFunctionsByClass(const string &class_str, YFUN_DESCR prevfundesc, vector< YFUN_DESCR > &buffer, int maxsize, string &errmsg)
int set_period(double newval)
double _dutyCycleAtPowerOn
virtual int _parseAttr(YJSONObject *json_val)
int set_dutyCycle(double newval)
string get_pwmTransition(void)
static const double DUTYCYCLE_INVALID
static bool _apiInitialized
YRETCODE _nextFunction(string &hwId)
static const double FREQUENCY_INVALID
static void _UpdateValueCallbackList(YFunction *func, bool add)
double get_dutyCycle(void)
virtual int pulseDurationMove(double ms_target, int ms_duration)
YPwmOutput * nextPwmOutput(void)
static YPwmOutput * FindPwmOutput(string func)
bool has(const string &key)
YRETCODE _setAttr(string attrname, string newvalue)
static const Y_ENABLEDATPOWERON_enum ENABLEDATPOWERON_INVALID
Y_ENABLEDATPOWERON_enum get_enabledAtPowerOn(void)
Y_ENABLEDATPOWERON_enum _enabledAtPowerOn
YPwmOutput(const string &func)
virtual int _invokeValueCallback(string value)