jsWarn does not show vars correctly

Posted on
  • During debugging for software PWM some jsWarn (in jstimer, function jstPinPWM) have been used.
    Looks to me, that 2nd var of same type is always shown as zero.
    See attached code, where only sequence of 2 vars is changed:

    jsWarn("duty:%f,period:%d,pulse:%d \n",dutyCycle,period,pulseLength);
    jsWarn("duty:%f,pulse:%d,period:%d \n",dutyCycle,pulseLength,period);
    
    

    Result in debug window is:
    WARNING: duty:0.5,period:100000,pulse:0
    WARNING: duty:0.5,pulse:50000,period:0

    Or is %d the wrong format ?

  • My guess in period and pulseLength are uint64 values, not uint32? This is a classic C printf-style problem.

    You just need to cast the values to be 32 bit:

    jsWarn("duty:%f,period:%d,pulse:%d \n",dutyCycle,(uint32_t)period,(uint32_t­)pulseLength);
    jsWarn("duty:%f,pulse:%d,period:%d \n",dutyCycle,(uint32_t)pulseLength,(uin­t32_t)period);
    
    
  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

jsWarn does not show vars correctly

Posted by Avatar for JumJum @JumJum

Actions