Example #1
0
        public MadeInTheUSB.spi.SPIEngine.SPIResult Set(int digitalValue, ADDRESS pot = ADDRESS.POT_0)
        {
            try { 
                this._spiEngine.Select();

                var r = new MadeInTheUSB.spi.SPIEngine.SPIResult();
                if((digitalValue < this.MinDigitalValue)||(digitalValue > this.MaxDigitalValue))
                    return r;
                this.DigitalValue = digitalValue;
                r = Transfer(pot, COMMAND.WRITE, digitalValue);
            
                //// Verify that the command error flag is off
                //var b0         = r.ReadBuffer[0];
                //bool valid     = !WinUtil.BitUtil.IsSet(b0, CMDERR_MASK);
                //r.Succeeded = r.Succeeded && valid;

                return r;
            }
            finally { 
                this._spiEngine.Unselect();
            }
        }
Example #2
0
        //public int Get(ADDRESS pot = ADDRESS.POT_0)
        //{
        //    try
        //    {
        //        this._spiEngine.Select();

        //        int result     = -1;
        //        var cmd        = build_command(pot, COMMAND.READ);
        //        var r          = _spiEngine.Transfer(cmd);
        //        var b0         = r.ReadBuffer[0];
        //        bool valid     = WinUtil.BitUtil.IsSet(b0, CMDERR_MASK);
            
        //        if (valid)
        //        {
        //            var dataByte = build_data(0);
        //            var r2  = _spiEngine.Transfer(dataByte);
        //            result  = r2.ReadBuffer[0];
        //        }
        //        return result;
        //    }
        //    finally { 
        //        this._spiEngine.Unselect();
        //    }
        //}

        public int Get(ADDRESS pot = ADDRESS.POT_0)
        {
            try { 
                this._spiEngine.Select();
                var r = new MadeInTheUSB.spi.SPIEngine.SPIResult();
                r = Transfer(pot, COMMAND.READ, 0);
                return r.Succeeded ? r.Value : -1;
            }
            finally { 
                this._spiEngine.Unselect();
            }
        }
Example #3
0
        public MadeInTheUSB.spi.SPIEngine.SPIResult Decrement(int times = 1, ADDRESS pot = ADDRESS.POT_0)
        {
            var r = new MadeInTheUSB.spi.SPIEngine.SPIResult();
            if (times > 1) {

                for (var i = 0; i < times; i++)
                {
                    r = this.Decrement(1);
                }
            }
            else { 
                if(this.DigitalValue > this.MinDigitalValue )
                {
                    this.DigitalValue--;
                    this.Transfer(pot, COMMAND.DECREMENT);
                }
            }
            return r;
        }