Exemplo n.º 1
0
    public int get_displayMode()
    {
        int res;

        lock (_thisLock) {
            if (this._cacheExpiration <= YAPI.GetTickCount())
            {
                if (this.load(YAPI._yapiContext.GetCacheValidity()) != YAPI.SUCCESS)
                {
                    return(DISPLAYMODE_INVALID);
                }
            }
            res = this._displayMode;
        }
        return(res);
    }
Exemplo n.º 2
0
    /**
     * <summary>
     *   Returns the current baud rate used by this YoctoHub port, in kbps.
     * <para>
     *   The default value is 1000 kbps, but a slower rate may be used if communication
     *   problems are encountered.
     * </para>
     * <para>
     * </para>
     * </summary>
     * <returns>
     *   an integer corresponding to the current baud rate used by this YoctoHub port, in kbps
     * </returns>
     * <para>
     *   On failure, throws an exception or returns <c>YHubPort.BAUDRATE_INVALID</c>.
     * </para>
     */
    public int get_baudRate()
    {
        int res;

        lock (_thisLock) {
            if (this._cacheExpiration <= YAPI.GetTickCount())
            {
                if (this.load(YAPI._yapiContext.GetCacheValidity()) != YAPI.SUCCESS)
                {
                    return(BAUDRATE_INVALID);
                }
            }
            res = this._baudRate;
        }
        return(res);
    }
Exemplo n.º 3
0
    /**
     * <summary>
     *   Returns the text currently displayed on the screen.
     * <para>
     * </para>
     * <para>
     * </para>
     * </summary>
     * <returns>
     *   a string corresponding to the text currently displayed on the screen
     * </returns>
     * <para>
     *   On failure, throws an exception or returns <c>YSegmentedDisplay.DISPLAYEDTEXT_INVALID</c>.
     * </para>
     */
    public string get_displayedText()
    {
        string res;

        lock (_thisLock) {
            if (this._cacheExpiration <= YAPI.GetTickCount())
            {
                if (this.load(YAPI._yapiContext.GetCacheValidity()) != YAPI.SUCCESS)
                {
                    return(DISPLAYEDTEXT_INVALID);
                }
            }
            res = this._displayedText;
        }
        return(res);
    }
Exemplo n.º 4
0
    public string get_command()
    {
        string res;

        lock (_thisLock) {
            if (this._cacheExpiration <= YAPI.GetTickCount())
            {
                if (this.load(YAPI._yapiContext.GetCacheValidity()) != YAPI.SUCCESS)
                {
                    return(COMMAND_INVALID);
                }
            }
            res = this._command;
        }
        return(res);
    }
Exemplo n.º 5
0
    /**
     * <summary>
     *   Returns true if the YoctoHub port is powered, false otherwise.
     * <para>
     * </para>
     * <para>
     * </para>
     * </summary>
     * <returns>
     *   either <c>YHubPort.ENABLED_FALSE</c> or <c>YHubPort.ENABLED_TRUE</c>, according to true if the
     *   YoctoHub port is powered, false otherwise
     * </returns>
     * <para>
     *   On failure, throws an exception or returns <c>YHubPort.ENABLED_INVALID</c>.
     * </para>
     */
    public int get_enabled()
    {
        int res;

        lock (_thisLock) {
            if (this._cacheExpiration <= YAPI.GetTickCount())
            {
                if (this.load(YAPI._yapiContext.GetCacheValidity()) != YAPI.SUCCESS)
                {
                    return(ENABLED_INVALID);
                }
            }
            res = this._enabled;
        }
        return(res);
    }
Exemplo n.º 6
0
    /**
     * <summary>
     *   Returns the zero tracking threshold value.
     * <para>
     *   When this threshold is larger than
     *   zero, any measure under the threshold will automatically be ignored and the
     *   zero compensation will be updated.
     * </para>
     * <para>
     * </para>
     * </summary>
     * <returns>
     *   a floating point number corresponding to the zero tracking threshold value
     * </returns>
     * <para>
     *   On failure, throws an exception or returns <c>YWeighScale.ZEROTRACKING_INVALID</c>.
     * </para>
     */
    public double get_zeroTracking()
    {
        double res;

        lock (_thisLock) {
            if (this._cacheExpiration <= YAPI.GetTickCount())
            {
                if (this.load(YAPI._yapiContext.GetCacheValidity()) != YAPI.SUCCESS)
                {
                    return(ZEROTRACKING_INVALID);
                }
            }
            res = this._zeroTracking;
        }
        return(res);
    }
Exemplo n.º 7
0
    /**
     * <summary>
     *   Returns the current current thermal compensation value.
     * <para>
     * </para>
     * <para>
     * </para>
     * </summary>
     * <returns>
     *   a floating point number corresponding to the current current thermal compensation value
     * </returns>
     * <para>
     *   On failure, throws an exception or returns <c>YWeighScale.COMPENSATION_INVALID</c>.
     * </para>
     */
    public double get_compensation()
    {
        double res;

        lock (_thisLock) {
            if (this._cacheExpiration <= YAPI.GetTickCount())
            {
                if (this.load(YAPI._yapiContext.GetCacheValidity()) != YAPI.SUCCESS)
                {
                    return(COMPENSATION_INVALID);
                }
            }
            res = this._compensation;
        }
        return(res);
    }
Exemplo n.º 8
0
    /**
     * <summary>
     *   Returns the temperature change update rate, in per mille.
     * <para>
     *   The temperature change is updated every 10 seconds, by applying this adaptation rate
     *   to the difference between the measures ambient temperature and the current temperature used for
     *   change compensation. The standard rate is 0.6 per mille, and the maximal rate is 65 per mille.
     * </para>
     * <para>
     * </para>
     * </summary>
     * <returns>
     *   a floating point number corresponding to the temperature change update rate, in per mille
     * </returns>
     * <para>
     *   On failure, throws an exception or returns <c>YWeighScale.TEMPCHGADAPTRATIO_INVALID</c>.
     * </para>
     */
    public double get_tempChgAdaptRatio()
    {
        double res;

        lock (_thisLock) {
            if (this._cacheExpiration <= YAPI.GetTickCount())
            {
                if (this.load(YAPI._yapiContext.GetCacheValidity()) != YAPI.SUCCESS)
                {
                    return(TEMPCHGADAPTRATIO_INVALID);
                }
            }
            res = this._tempChgAdaptRatio;
        }
        return(res);
    }
Exemplo n.º 9
0
    /**
     * <summary>
     *   Returns the current load cell bridge excitation method.
     * <para>
     * </para>
     * <para>
     * </para>
     * </summary>
     * <returns>
     *   a value among <c>YWeighScale.EXCITATION_OFF</c>, <c>YWeighScale.EXCITATION_DC</c> and
     *   <c>YWeighScale.EXCITATION_AC</c> corresponding to the current load cell bridge excitation method
     * </returns>
     * <para>
     *   On failure, throws an exception or returns <c>YWeighScale.EXCITATION_INVALID</c>.
     * </para>
     */
    public int get_excitation()
    {
        int res;

        lock (_thisLock) {
            if (this._cacheExpiration <= YAPI.GetTickCount())
            {
                if (this.load(YAPI._yapiContext.GetCacheValidity()) != YAPI.SUCCESS)
                {
                    return(EXCITATION_INVALID);
                }
            }
            res = this._excitation;
        }
        return(res);
    }
    /**
     * <summary>
     *   Returns the number of synchronized controllers.
     * <para>
     * </para>
     * <para>
     * </para>
     * </summary>
     * <returns>
     *   an integer corresponding to the number of synchronized controllers
     * </returns>
     * <para>
     *   On failure, throws an exception or returns <c>YMultiAxisController.NAXIS_INVALID</c>.
     * </para>
     */
    public int get_nAxis()
    {
        int res;

        lock (_thisLock) {
            if (this._cacheExpiration <= YAPI.GetTickCount())
            {
                if (this.load(YAPI._yapiContext.GetCacheValidity()) != YAPI.SUCCESS)
                {
                    return(NAXIS_INVALID);
                }
            }
            res = this._nAxis;
        }
        return(res);
    }
Exemplo n.º 11
0
    /**
     * <summary>
     *   Returns the state of the relays at device startup (A for the idle position,
     *   B for the active position, UNCHANGED to leave the relay state as is).
     * <para>
     * </para>
     * <para>
     * </para>
     * </summary>
     * <returns>
     *   a value among <c>YRelay.STATEATPOWERON_UNCHANGED</c>, <c>YRelay.STATEATPOWERON_A</c> and
     *   <c>YRelay.STATEATPOWERON_B</c> corresponding to the state of the relays at device startup (A for
     *   the idle position,
     *   B for the active position, UNCHANGED to leave the relay state as is)
     * </returns>
     * <para>
     *   On failure, throws an exception or returns <c>YRelay.STATEATPOWERON_INVALID</c>.
     * </para>
     */
    public int get_stateAtPowerOn()
    {
        int res;

        lock (_thisLock)
        {
            if (this._cacheExpiration <= YAPI.GetTickCount())
            {
                if (this.load(YAPI._yapiContext.GetCacheValidity()) != YAPI.SUCCESS)
                {
                    return(STATEATPOWERON_INVALID);
                }
            }
            res = this._stateAtPowerOn;
        }
        return(res);
    }
Exemplo n.º 12
0
    /**
     * <summary>
     *   Returns the current measured value.
     * <para>
     * </para>
     * <para>
     * </para>
     * </summary>
     * <returns>
     *   a floating point number corresponding to the current measured value
     * </returns>
     * <para>
     *   On failure, throws an exception or returns <c>YVoltage.CURRENTVALUE_INVALID</c>.
     * </para>
     */
    public double get_currentValue()
    {
        if (_cacheExpiration <= YAPI.GetTickCount())
        {
            if (YAPI.YISERR(load(YAPI.DefaultCacheValidity)))
            {
                return(YVoltage.CURRENTVALUE_INVALID);
            }
        }
        double res = YAPI._applyCalibration(_currentRawValue, _calibrationParam, _calibrationOffset, _resolution);

        if (res != YVoltage.CURRENTVALUE_INVALID)
        {
            return(res);
        }
        return(_currentValue);
    }
Exemplo n.º 13
0
    /**
     * <summary>
     *   Returns the number of milliseconds remaining before a pulse (delayedPulse() call)
     *   When there is no scheduled pulse, returns zero.
     * <para>
     * </para>
     * <para>
     * </para>
     * </summary>
     * <returns>
     *   an integer corresponding to the number of milliseconds remaining before a pulse (delayedPulse() call)
     *   When there is no scheduled pulse, returns zero
     * </returns>
     * <para>
     *   On failure, throws an exception or returns <c>YRelay.COUNTDOWN_INVALID</c>.
     * </para>
     */
    public long get_countdown()
    {
        long res;

        lock (_thisLock)
        {
            if (this._cacheExpiration <= YAPI.GetTickCount())
            {
                if (this.load(YAPI._yapiContext.GetCacheValidity()) != YAPI.SUCCESS)
                {
                    return(COUNTDOWN_INVALID);
                }
            }
            res = this._countdown;
        }
        return(res);
    }
Exemplo n.º 14
0
    public YRelayDelayedPulse get_delayedPulseTimer()
    {
        YRelayDelayedPulse res;

        lock (_thisLock)
        {
            if (this._cacheExpiration <= YAPI.GetTickCount())
            {
                if (this.load(YAPI._yapiContext.GetCacheValidity()) != YAPI.SUCCESS)
                {
                    return(DELAYEDPULSETIMER_INVALID);
                }
            }
            res = this._delayedPulseTimer;
        }
        return(res);
    }
Exemplo n.º 15
0
    /**
     * <summary>
     *   Returns the number of milliseconds remaining before the relays is returned to idle position
     *   (state A), during a measured pulse generation.
     * <para>
     *   When there is no ongoing pulse, returns zero.
     * </para>
     * <para>
     * </para>
     * </summary>
     * <returns>
     *   an integer corresponding to the number of milliseconds remaining before the relays is returned to idle position
     *   (state A), during a measured pulse generation
     * </returns>
     * <para>
     *   On failure, throws an exception or returns <c>YRelay.PULSETIMER_INVALID</c>.
     * </para>
     */
    public long get_pulseTimer()
    {
        long res;

        lock (_thisLock)
        {
            if (this._cacheExpiration <= YAPI.GetTickCount())
            {
                if (this.load(YAPI._yapiContext.GetCacheValidity()) != YAPI.SUCCESS)
                {
                    return(PULSETIMER_INVALID);
                }
            }
            res = this._pulseTimer;
        }
        return(res);
    }
Exemplo n.º 16
0
    /**
     * <summary>
     *   Retourne the maximum time (ms) allowed for the relay to stay in state B
     *   before automatically switching back in to A state.
     * <para>
     *   Zero means no time limit.
     * </para>
     * <para>
     * </para>
     * </summary>
     * <returns>
     *   an integer
     * </returns>
     * <para>
     *   On failure, throws an exception or returns <c>YRelay.MAXTIMEONSTATEB_INVALID</c>.
     * </para>
     */
    public long get_maxTimeOnStateB()
    {
        long res;

        lock (_thisLock)
        {
            if (this._cacheExpiration <= YAPI.GetTickCount())
            {
                if (this.load(YAPI._yapiContext.GetCacheValidity()) != YAPI.SUCCESS)
                {
                    return(MAXTIMEONSTATEB_INVALID);
                }
            }
            res = this._maxTimeOnStateB;
        }
        return(res);
    }
Exemplo n.º 17
0
        private void RefreshTimer_Tick(object sender, EventArgs e)
        {
            string errmsg = "";

            YAPI.HandleEvents(ref errmsg);
            refreshUI();
            ulong now = YAPI.GetTickCount();

            if (now - eventTick >= 1000)
            {
                for (int i = 0; i < eventCount.Length; i++)
                {
                    freq[i]       = (int)Math.Round(eventCount[i] * 1000.0 / (now - eventTick));
                    eventCount[i] = 0;
                }
                eventTick = now;
            }
        }
    void EfficientApproach()
    {
        ulong  tm_start = YAPI.GetTickCount();
        string errmsg   = "";
        int    res      = YAPI.HandleEvents(ref errmsg);

        if (res != YAPI.SUCCESS)
        {
            errorText.text = errmsg;
            return;
        }
        ulong tm_stop = YAPI.GetTickCount();

        Debug.Log(string.Format("Get values (r{0:f} p{1:f} took {2:d}ms", _x, _z, tm_stop - tm_start));
        Vector3 movement = new Vector3((float)_x, 0.0f, (float)_z);

        rb.AddForce(movement * speed);
    }
Exemplo n.º 19
0
    public virtual int _loadQuaternion()
    {
        int now_stamp;
        int age_ms;

        now_stamp = (int)((YAPI.GetTickCount()) & (0x7FFFFFFF));
        age_ms    = (((now_stamp - this._qt_stamp)) & (0x7FFFFFFF));
        if ((age_ms >= 10) || (this._qt_stamp == 0))
        {
            if (this.load(10) != YAPI.SUCCESS)
            {
                return(YAPI.DEVICE_NOT_FOUND);
            }
            if (this._qt_stamp == 0)
            {
                this._qt_w = YQt.FindQt("" + this._serial + ".qt1");
                this._qt_x = YQt.FindQt("" + this._serial + ".qt2");
                this._qt_y = YQt.FindQt("" + this._serial + ".qt3");
                this._qt_z = YQt.FindQt("" + this._serial + ".qt4");
            }
            if (this._qt_w.load(9) != YAPI.SUCCESS)
            {
                return(YAPI.DEVICE_NOT_FOUND);
            }
            if (this._qt_x.load(9) != YAPI.SUCCESS)
            {
                return(YAPI.DEVICE_NOT_FOUND);
            }
            if (this._qt_y.load(9) != YAPI.SUCCESS)
            {
                return(YAPI.DEVICE_NOT_FOUND);
            }
            if (this._qt_z.load(9) != YAPI.SUCCESS)
            {
                return(YAPI.DEVICE_NOT_FOUND);
            }
            this._w        = this._qt_w.get_currentValue();
            this._x        = this._qt_x.get_currentValue();
            this._y        = this._qt_y.get_currentValue();
            this._z        = this._qt_z.get_currentValue();
            this._qt_stamp = now_stamp;
        }
        return(YAPI.SUCCESS);
    }
Exemplo n.º 20
0
    public virtual int _invokeGyroCallbacks(int qtIndex, double qtValue)
    {
        switch (qtIndex - 1)
        {
        case 0:
            this._w = qtValue;
            break;

        case 1:
            this._x = qtValue;
            break;

        case 2:
            this._y = qtValue;
            break;

        case 3:
            this._z = qtValue;
            break;
        }
        if (qtIndex < 4)
        {
            return(0);
        }
        this._qt_stamp = (int)((YAPI.GetTickCount()) & (0x7FFFFFFF));
        if (this._quatCallback != null)
        {
            this._quatCallback(this, this._w, this._x, this._y, this._z);
        }
        if (this._anglesCallback != null)
        {
            this._loadAngles();
            this._anglesCallback(this, this._roll, this._pitch, this._head);
        }
        return(0);
    }
    /**
     * <summary>
     *   Continues the sensors tridimensional calibration process previously
     *   initiated using method <c>start3DCalibration</c>.
     * <para>
     *   This method should be called approximately 5 times per second, while
     *   positioning the device according to the instructions provided by method
     *   <c>get_3DCalibrationHint</c>. Note that the instructions change during
     *   the calibration process.
     * </para>
     * <para>
     *   On failure, throws an exception or returns a negative error code.
     * </para>
     * </summary>
     */
    public virtual int more3DCalibration()
    {
        int currTick = 0;

        byte[] jsonData;
        double xVal   = 0;
        double yVal   = 0;
        double zVal   = 0;
        double xSq    = 0;
        double ySq    = 0;
        double zSq    = 0;
        double norm   = 0;
        int    orient = 0;
        int    idx    = 0;
        int    pos    = 0;
        int    err    = 0;

        // make sure calibration has been started
        if (this._calibStage == 0)
        {
            return(YAPI.INVALID_ARGUMENT);
        }
        if (this._calibProgress == 100)
        {
            return(YAPI.SUCCESS);
        }

        // make sure we leave at least 160ms between samples
        currTick = (int)((YAPI.GetTickCount()) & (0x7FFFFFFF));
        if (((currTick - this._calibPrevTick) & (0x7FFFFFFF)) < 160)
        {
            return(YAPI.SUCCESS);
        }
        // load current accelerometer values, make sure we are on a straight angle
        // (default timeout to 0,5 sec without reading measure when out of range)
        this._calibStageHint = "Set down the device on a steady horizontal surface";
        this._calibPrevTick  = ((currTick + 500) & (0x7FFFFFFF));
        jsonData             = this._download("api/accelerometer.json");
        xVal = Convert.ToInt32(this._json_get_key(jsonData, "xValue")) / 65536.0;
        yVal = Convert.ToInt32(this._json_get_key(jsonData, "yValue")) / 65536.0;
        zVal = Convert.ToInt32(this._json_get_key(jsonData, "zValue")) / 65536.0;
        xSq  = xVal * xVal;
        if (xSq >= 0.04 && xSq < 0.64)
        {
            return(YAPI.SUCCESS);
        }
        if (xSq >= 1.44)
        {
            return(YAPI.SUCCESS);
        }
        ySq = yVal * yVal;
        if (ySq >= 0.04 && ySq < 0.64)
        {
            return(YAPI.SUCCESS);
        }
        if (ySq >= 1.44)
        {
            return(YAPI.SUCCESS);
        }
        zSq = zVal * zVal;
        if (zSq >= 0.04 && zSq < 0.64)
        {
            return(YAPI.SUCCESS);
        }
        if (zSq >= 1.44)
        {
            return(YAPI.SUCCESS);
        }
        norm = Math.Sqrt(xSq + ySq + zSq);
        if (norm < 0.8 || norm > 1.2)
        {
            return(YAPI.SUCCESS);
        }
        this._calibPrevTick = currTick;

        // Determine the device orientation index
        if (zSq > 0.5)
        {
            if (zVal > 0)
            {
                orient = 0;
            }
            else
            {
                orient = 1;
            }
        }
        if (xSq > 0.5)
        {
            if (xVal > 0)
            {
                orient = 2;
            }
            else
            {
                orient = 3;
            }
        }
        if (ySq > 0.5)
        {
            if (yVal > 0)
            {
                orient = 4;
            }
            else
            {
                orient = 5;
            }
        }

        // Discard measures that are not in the proper orientation
        if (this._calibStageProgress == 0)
        {
            idx = 0;
            err = 0;
            while (idx + 1 < this._calibStage)
            {
                if (this._calibOrient[idx] == orient)
                {
                    err = 1;
                }
                idx = idx + 1;
            }
            if (err != 0)
            {
                this._calibStageHint = "Turn the device on another face";
                return(YAPI.SUCCESS);
            }
            this._calibOrient.Add(orient);
        }
        else
        {
            if (orient != this._calibOrient[this._calibStage - 1])
            {
                this._calibStageHint = "Not yet done, please move back to the previous face";
                return(YAPI.SUCCESS);
            }
        }

        // Save measure
        this._calibStageHint = "calibrating..";
        this._calibDataAccX.Add(xVal);
        this._calibDataAccY.Add(yVal);
        this._calibDataAccZ.Add(zVal);
        this._calibDataAcc.Add(norm);
        this._calibInternalPos = this._calibInternalPos + 1;
        this._calibProgress    = 1 + 16 * (this._calibStage - 1) + ((16 * this._calibInternalPos) / (this._calibCount));
        if (this._calibInternalPos < this._calibCount)
        {
            this._calibStageProgress = 1 + ((99 * this._calibInternalPos) / (this._calibCount));
            return(YAPI.SUCCESS);
        }

        // Stage done, compute preliminary result
        pos = (this._calibStage - 1) * this._calibCount;
        this._calibSort(pos, pos + this._calibCount);
        pos = pos + ((this._calibCount) / (2));
        this._calibLogMsg = "Stage " + Convert.ToString(this._calibStage) + ": median is " + Convert.ToString(
            (int)Math.Round(1000 * this._calibDataAccX[pos])) + "," + Convert.ToString(
            (int)Math.Round(1000 * this._calibDataAccY[pos])) + "," + Convert.ToString((int)Math.Round(1000 * this._calibDataAccZ[pos]));

        // move to next stage
        this._calibStage = this._calibStage + 1;
        if (this._calibStage < 7)
        {
            this._calibStageHint     = "Turn the device on another face";
            this._calibPrevTick      = ((currTick + 500) & (0x7FFFFFFF));
            this._calibStageProgress = 0;
            this._calibInternalPos   = 0;
            return(YAPI.SUCCESS);
        }
        // Data collection completed, compute accelerometer shift
        xVal = 0;
        yVal = 0;
        zVal = 0;
        idx  = 0;
        while (idx < 6)
        {
            pos    = idx * this._calibCount + ((this._calibCount) / (2));
            orient = this._calibOrient[idx];
            if (orient == 0 || orient == 1)
            {
                zVal = zVal + this._calibDataAccZ[pos];
            }
            if (orient == 2 || orient == 3)
            {
                xVal = xVal + this._calibDataAccX[pos];
            }
            if (orient == 4 || orient == 5)
            {
                yVal = yVal + this._calibDataAccY[pos];
            }
            idx = idx + 1;
        }
        this._calibAccXOfs = xVal / 2.0;
        this._calibAccYOfs = yVal / 2.0;
        this._calibAccZOfs = zVal / 2.0;

        // Recompute all norms, taking into account the computed shift, and re-sort
        pos = 0;
        while (pos < this._calibDataAcc.Count)
        {
            xVal = this._calibDataAccX[pos] - this._calibAccXOfs;
            yVal = this._calibDataAccY[pos] - this._calibAccYOfs;
            zVal = this._calibDataAccZ[pos] - this._calibAccZOfs;
            norm = Math.Sqrt(xVal * xVal + yVal * yVal + zVal * zVal);
            this._calibDataAcc[pos] = norm;
            pos = pos + 1;
        }
        idx = 0;
        while (idx < 6)
        {
            pos = idx * this._calibCount;
            this._calibSort(pos, pos + this._calibCount);
            idx = idx + 1;
        }

        // Compute the scaling factor for each axis
        xVal = 0;
        yVal = 0;
        zVal = 0;
        idx  = 0;
        while (idx < 6)
        {
            pos    = idx * this._calibCount + ((this._calibCount) / (2));
            orient = this._calibOrient[idx];
            if (orient == 0 || orient == 1)
            {
                zVal = zVal + this._calibDataAcc[pos];
            }
            if (orient == 2 || orient == 3)
            {
                xVal = xVal + this._calibDataAcc[pos];
            }
            if (orient == 4 || orient == 5)
            {
                yVal = yVal + this._calibDataAcc[pos];
            }
            idx = idx + 1;
        }
        this._calibAccXScale = xVal / 2.0;
        this._calibAccYScale = yVal / 2.0;
        this._calibAccZScale = zVal / 2.0;

        // Report completion
        this._calibProgress  = 100;
        this._calibStageHint = "Calibration data ready for saving";
        return(YAPI.SUCCESS);
    }
    public virtual int more3DCalibrationV2()
    {
        int currTick;

        byte[]     calibParam;
        List <int> iCalib = new List <int>();
        int        cal3;
        int        calAcc;
        int        calMag;
        int        calGyr;

        // make sure calibration has been started
        if (this._calibStage == 0)
        {
            return(YAPI.INVALID_ARGUMENT);
        }
        if (this._calibProgress == 100)
        {
            return(YAPI.SUCCESS);
        }
        // make sure we don't start before previous calibration is cleared
        if (this._calibStage == 1)
        {
            currTick = (int)((YAPI.GetTickCount()) & (0x7FFFFFFF));
            currTick = ((currTick - this._calibPrevTick) & (0x7FFFFFFF));
            if (currTick < 1600)
            {
                this._calibStageHint     = "Set down the device on a steady horizontal surface";
                this._calibStageProgress = ((currTick) / (40));
                this._calibProgress      = 1;
                return(YAPI.SUCCESS);
            }
        }

        calibParam = this._download("api/refFrame/calibrationParam.txt");
        iCalib     = YAPI._decodeFloats(YAPI.DefaultEncoding.GetString(calibParam));
        cal3       = ((iCalib[1]) / (1000));
        calAcc     = ((cal3) / (100));
        calMag     = ((cal3) / (10)) - 10 * calAcc;
        calGyr     = ((cal3) % (10));
        if (calGyr < 3)
        {
            this._calibStageHint     = "Set down the device on a steady horizontal surface";
            this._calibStageProgress = 40 + calGyr * 20;
            this._calibProgress      = 4 + calGyr * 2;
        }
        else
        {
            this._calibStage = 2;
            if (calMag < 3)
            {
                this._calibStageHint     = "Slowly draw '8' shapes along the 3 axis";
                this._calibStageProgress = 1 + calMag * 33;
                this._calibProgress      = 10 + calMag * 5;
            }
            else
            {
                this._calibStage = 3;
                if (calAcc < 3)
                {
                    this._calibStageHint     = "Slowly turn the device, stopping at each 90 degrees";
                    this._calibStageProgress = 1 + calAcc * 33;
                    this._calibProgress      = 25 + calAcc * 25;
                }
                else
                {
                    this._calibStageProgress = 99;
                    this._calibProgress      = 100;
                }
            }
        }
        return(YAPI.SUCCESS);
    }
Exemplo n.º 23
0
        static void Main(string[] args)
        {
            string   errmsg = "";
            string   target;
            YI2cPort i2cPort;

            if (args.Length < 1)
            {
                usage();
            }
            target = args[0].ToUpper();

            if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS)
            {
                Console.WriteLine("RegisterHub error: " + errmsg);
                Environment.Exit(0);
            }

            if (target == "ANY")
            {
                i2cPort = YI2cPort.FirstI2cPort();
                if (i2cPort == null)
                {
                    Console.WriteLine("No module connected (check USB cable) ");
                    Environment.Exit(0);
                }
                target = i2cPort.get_module().get_serialNumber();
            }

            i2cPort = YI2cPort.FindI2cPort(target + ".i2cPort");
            if (i2cPort.isOnline())
            {
                i2cPort.set_i2cMode("400kbps");
                i2cPort.set_i2cVoltageLevel(YI2cPort.I2CVOLTAGELEVEL_3V3);
                i2cPort.reset();
                // do not forget to configure the powerOutput and
                // of the Yocto-I2C as well if used
                Console.WriteLine("****************************");
                Console.WriteLine("* make sure voltage levels *");
                Console.WriteLine("* are properly configured  *");
                Console.WriteLine("****************************");

                List <int> toSend   = new List <int>(new int[] { 0x05 });
                List <int> received = i2cPort.i2cSendAndReceiveArray(0x1f, toSend, 2);
                int        tempReg  = (received[0] << 8) + received[1];
                if ((tempReg & 0x1000) != 0)
                {
                    tempReg -= 0x2000; // perform sign extension
                }
                else
                {
                    tempReg &= 0x0fff; // clear status bits
                }
                Console.WriteLine("Ambiant temperature: " + String.Format("{0:0.000}", (tempReg / 16.0)));
            }
            else
            {
                Console.WriteLine("Module not connected");
                Console.WriteLine("check identification and USB cable");
            }
            YAPI.FreeAPI();

            // wait 5 sec to show the output
            ulong now = YAPI.GetTickCount();

            while (YAPI.GetTickCount() - now < 5000)
            {
                ;
            }
        }