Ejemplo n.º 1
0
        private void RefreshDeviceList()
        {
            toolStripComboBox_deviceList.Items.Clear();

            var deviceInfoArray = Spi.GetDeviceInfoList();

            foreach (var deviceInfo in deviceInfoArray)
            {
                toolStripComboBox_deviceList.Items.Add($"{deviceInfo.Description} ({deviceInfo.SerialNumber})");
            }

            if (deviceInfoArray.Length > 0)
            {
                toolStripComboBox_deviceList.Enabled = true;
                toolStripButton_connect.Enabled      = true;
            }
            else
            {
                toolStripComboBox_deviceList.Items.Add("デバイスが見つかりません");
                toolStripComboBox_deviceList.Enabled = false;
                toolStripButton_connect.Enabled      = false;
            }

            toolStripComboBox_deviceList.SelectedIndex = 0;
            toolStripComboBox_interface.SelectedIndex  = 0;
        }
Ejemplo n.º 2
0
 public SuperNesController(Spi spi, SpiChipSelectPin ps) : base(spi, ps)
 {
     X = new Button(new DigitalInPeripheralPin(this));
     Y = new Button(new DigitalInPeripheralPin(this));
     L = new Button(new DigitalInPeripheralPin(this));
     R = new Button(new DigitalInPeripheralPin(this));
 }
Ejemplo n.º 3
0
        public void SpiPayAtTable_OnValidRequest_ReturnStatus()
        {
            // arrange
            var spi = new Spi();

            // act
            var spiPay = new SpiPayAtTable(spi);

            // assert
            Assert.NotNull(spiPay.Config);

            // act
            var spi2 = (Spi)SpiClientTestUtils.GetInstanceField(spiPay.GetType(), spiPay, "_spi");

            // assert
            Assert.Equal(spi.CurrentStatus, spi2.CurrentStatus);

            // arrange
            spiPay = new SpiPayAtTable();

            // act
            var spi3 = (Spi)SpiClientTestUtils.GetInstanceField(spiPay.GetType(), spiPay, "_spi");

            // assert
            Assert.Null(spi3);
        }
Ejemplo n.º 4
0
 /// <summary>
 ///     Construct an LED shift register attached directly to a board SPI module
 /// </summary>
 /// <param name="SpiModule">The board's SPI module</param>
 /// <param name="LatchPin">The pin to use for latches</param>
 /// <param name="OutputEnablePin">The PWM pin to use, allowing controllable global brightness.</param>
 /// <param name="ChannelCount">The number of channels this LED shift register has</param>
 /// <param name="speedMhz">The speed, in MHz, to use when communicating</param>
 public LedShiftRegister(Spi SpiModule, SpiChipSelectPin LatchPin, Pwm OutputEnablePin,
                         LedChannelCount ChannelCount = LedChannelCount.SixteenChannel, double speedMhz = 6) : base(SpiModule,
                                                                                                                    LatchPin, (int)ChannelCount / 8, speedMhz)
 {
     oePwm = OutputEnablePin;
     Start(ChannelCount);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Writes the specified buffer.
        /// </summary>
        /// <param name="buffer">The buffer.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="count">The count.</param>
        /// <returns>The number of bytes written.</returns>
        public int Write(byte[] buffer, int offset, int count)
        {
            var data = new byte[count];

            Buffer.BlockCopy(buffer, offset, data, 0, count);
            return(Spi.SpiWrite(Handle, data));
        }
Ejemplo n.º 6
0
 protected void Write(byte register, byte value)
 {
     SpiBuffer[0]   = register;
     SpiBuffer[0] <<= 8;
     SpiBuffer[0]  |= value;
     Spi.Write(SpiBuffer);
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Reads int the specified buffer.
        /// </summary>
        /// <param name="buffer">The buffer.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="count">The count.</param>
        /// <returns>The number of bytes read into the buffer.</returns>
        public int Read(byte[] buffer, int offset, int count)
        {
            var data = Spi.SpiRead(Handle, count);

            Buffer.BlockCopy(data, 0, buffer, offset, data.Length);
            return(data.Length);
        }
Ejemplo n.º 8
0
        /// <summary>
        ///     Get a GraphicDisplay built from one or more 8x8 MAX7219-powered LED displays commonly available from hobbyist
        ///     vendors.
        /// </summary>
        /// <param name="port">The SPI port these displays are attached to</param>
        /// <param name="latch">The latch pin to use with these displays</param>
        /// <param name="numDevices">The number of 8x8 units that are daisy-chained together</param>
        /// <returns></returns>
        public static LedGraphicDisplay GetMax7219GraphicLedDisplay(Spi port, Pin latch, int numDevices)
        {
            IEnumerable <Led> finalList = new List <Led>();

            for (var i = 0; i < numDevices; i++)
            {
                Max7219 driver;

                driver = new Max7219(port, latch, i);

                var tempList = new List <Led>();

                // We have to re-order the LEDs from the Max7219
                {
                    for (var k = 62; k >= 56; k--)
                    {
                        for (var m = k; m >= 0; m -= 8)
                        {
                            tempList.Add(driver.Leds[m]);
                        }
                    }

                    for (var k = 63; k >= 0; k -= 8)
                    {
                        tempList.Add(driver.Leds[k]);
                    }
                }

                finalList = finalList.Concat(tempList);
            }

            var display = new LedGraphicDisplay(finalList.ToList(), 8 * numDevices, 8);

            return(display);
        }
Ejemplo n.º 9
0
        public SevenSegSpi(Spi SPIModule, Pin csPin, int numDevices = 1)
        {
            this.SPIModule = SPIModule;
            SPIModule.Start(SPIMode.Mode00, 1);
            this.csPin = csPin;

            if (numDevices <= 0 || numDevices > 8)
            {
                throw new Exception("This library supports 1 to 8 displays.");
            }

            this.numDevices = numDevices;

            this.csPin.DigitalValue = true;

            spiData = new byte[numDevices * 2];

            for (int i = 0; i < numDevices; i++)
            {
                spiTransfer(OP_DISPLAYTEST, 0, i);
                //scanlimit is set to max on startup
                setScanLimit(7, i);
                //decode is done in source
                spiTransfer(OP_DECODEMODE, 0, i);
                clearDisplay(i);
                //we go into shutdown-mode on startup
                shutdown(false, i);
                setIntensity(10, i);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        ///     Construct an SPI device attached to a particular module
        /// </summary>
        /// <param name="spiModule">The module this device is attached to</param>
        /// <param name="chipSelect">The chip select pin used by this device</param>
        /// <param name="chipSelectMode">The ChipSelectMode to use with this device</param>
        /// <param name="speedMhz">The speed to operate this device at</param>
        /// <param name="mode">The SpiMode of this device</param>
        public SpiDevice(Spi spiModule, SpiChipSelectPin chipSelect,
                         ChipSelectMode chipSelectMode = ChipSelectMode.SpiActiveLow, double speedMhz = 6,
                         SpiMode mode = SpiMode.Mode00)
        {
            ChipSelectMode = chipSelectMode;
            ChipSelect     = chipSelect;
            _spi           = spiModule;
            Frequency      = speedMhz;
            Mode           = mode;

            _spi.Enabled = true;

            ChipSelect.MakeDigitalPushPullOutAsync();

            // Set the initial chip select state
            if (chipSelectMode == ChipSelectMode.PulseLowAtBeginning ||
                chipSelectMode == ChipSelectMode.PulseLowAtEnd || chipSelectMode == ChipSelectMode.SpiActiveLow)
            {
                ChipSelect.DigitalValue = true;
            }
            else
            {
                ChipSelect.DigitalValue = false;
            }
        }
Ejemplo n.º 11
0
        public SevenSegSpi(Spi SPIModule, Pin csPin, int numDevices = 1)
        {
            this.SPIModule = SPIModule;
            SPIModule.Start(SPIMode.Mode00, 1);
            this.csPin = csPin;

            if(numDevices<=0 || numDevices>8 )
                throw new Exception("This library supports 1 to 8 displays.");

            this.numDevices = numDevices;

            this.csPin.DigitalValue = true;

             spiData = new byte[numDevices*2];

            for(int i=0; i<numDevices; i++)
            {
                spiTransfer(OP_DISPLAYTEST, 0, i);
                //scanlimit is set to max on startup
                setScanLimit(7, i);
                //decode is done in source
                spiTransfer(OP_DECODEMODE, 0, i);
                clearDisplay(i);
                //we go into shutdown-mode on startup
                shutdown(false, i);
                setIntensity(10, i);
            }
        }
        public static LedGraphicDisplay GetMax7219GraphicLedDisplay(Spi port, Pin latch, int numDevices)
        {
            IEnumerable<Led> finalList = new List<Led>();
            for (int i = 0; i < numDevices; i++)
            {
                Max7219 driver;

                driver = new Max7219(port, latch, i);

                var tempList = new List<Led>();

                // We have to re-order the LEDs from the Max7219
                {
                    for (int k = 62; k >= 56; k--)
                    {
                        for (int m = k; m >= 0; m -= 8)
                        {
                            tempList.Add(driver.Leds[m]);
                        }
                    }

                    for (int k = 63; k >= 0; k -= 8)
                    {
                        tempList.Add(driver.Leds[k]);
                    }
                }

                finalList = finalList.Concat(tempList);
            }

            var display = new LedGraphicDisplay(finalList.ToList(), 8 * numDevices, 8);

            return display;
        }
Ejemplo n.º 13
0
        public void Main(Spi spi, SpiPayAtTable pat, Int32 cBTxStatePtr, Int32 cBPairingFlowStatePtr, Int32 cBsecretsPtr, Int32 cBStatusPtr, Int32 cBPayAtTableGetBillDetailsPtr, Int32 cBPayAtTableBillPaymentReceivedPtr)
        {
            _spi = spi; // It is ok to not have the secrets yet to start with.
            _pat = pat;

            ptr             = new IntPtr(cBTxStatePtr);
            callBackTxState = (CBTxFlowStateChanged)Marshal.GetDelegateForFunctionPointer(ptr, typeof(CBTxFlowStateChanged));

            ptr = new IntPtr(cBPairingFlowStatePtr);
            callBackPairingFlowState = (CBPairingFlowStateChanged)Marshal.GetDelegateForFunctionPointer(ptr, typeof(CBPairingFlowStateChanged));

            ptr             = new IntPtr(cBsecretsPtr);
            callBackSecrets = (CBSecretsChanged)Marshal.GetDelegateForFunctionPointer(ptr, typeof(CBSecretsChanged));

            ptr            = new IntPtr(cBStatusPtr);
            callBackStatus = (CBSpiStatusChanged)Marshal.GetDelegateForFunctionPointer(ptr, typeof(CBSpiStatusChanged));

            ptr = new IntPtr(cBPayAtTableGetBillDetailsPtr);
            callBackPayAtTableGetBillStatus = (CBPayAtTableGetBillStatus)Marshal.GetDelegateForFunctionPointer(ptr, typeof(CBPayAtTableGetBillStatus));

            ptr = new IntPtr(cBPayAtTableBillPaymentReceivedPtr);
            callBackPayAtTableBillPaymentReceived = (CBPayAtTableBillPaymentReceived)Marshal.GetDelegateForFunctionPointer(ptr, typeof(CBPayAtTableBillPaymentReceived));

            _spi.StatusChanged           += OnSpiStatusChanged;
            _spi.PairingFlowStateChanged += OnPairingFlowStateChanged;
            _spi.SecretsChanged          += OnSecretsChanged;
            _spi.TxFlowStateChanged      += OnTxFlowStateChanged;

            _pat.GetBillStatus       = OnPayAtTableGetBillStatus;
            _pat.BillPaymentReceived = OnPayAtTableBillPaymentReceived;
        }
Ejemplo n.º 14
0
        private void Start()
        {
            LoadPersistedState();

            _spi = new Spi(_posId, _serialNumber, _eftposAddress, _spiSecrets);
            _spi.SetPosInfo("assembly", "2.6.3");
            _spi.StatusChanged           += OnSpiStatusChanged;
            _spi.PairingFlowStateChanged += OnPairingFlowStateChanged;
            _spi.SecretsChanged          += OnSecretsChanged;
            _spi.TxFlowStateChanged      += OnTxFlowStateChanged;

            _pat = _spi.EnablePayAtTable();
            EnablePayAtTableConfigs();
            _pat.GetBillStatus        = PayAtTableGetBillDetails;
            _pat.BillPaymentReceived  = PayAtTableBillPaymentReceived;
            _pat.BillPaymentFlowEnded = PayAtTableBillPaymentFlowEnded;
            _pat.GetOpenTables        = PayAtTableGetOpenTables;

            try
            {
                _spi.Start();
            }
            catch (Exception e)
            {
                Console.WriteLine($@"SPI check failed: {e.Message}", @"Please ensure you followed all the configuration steps on your machine");
            }

            Console.Clear();
            Console.WriteLine("# Welcome to TablePos !");
            PrintStatusAndActions();
            Console.Write("> ");
            AcceptUserInput();
        }
Ejemplo n.º 15
0
 public void Dispose()
 {
     Spi.Dispose();
     Spi         = null;
     DataCommand = null;
     Reset       = null;
 }
Ejemplo n.º 16
0
 protected override void Dispose(bool disposing = true)
 {
     Irq.DisableInterrupt();
     Spi.Dispose();
     ReceiveContext.Dispose();
     SetSocketPowerState(false);
     base.Dispose(disposing);
 }
 /// <summary>
 ///     Set up a ChainableShiftRegisterOutput connected to an SPI port.
 /// </summary>
 /// <param name="spiModule">the SPI module to use</param>
 /// <param name="latchPin">The latch pin to use</param>
 /// <param name="numBytes">The number of bytes to write to this device</param>
 /// <param name="mode">The SPI mode to use for all shift registers in this chain</param>
 /// <param name="csMode">The ChipSelectMode to use for all shift registers in this chain</param>
 /// <param name="speedMhz">The speed to use for all shift registers in this chain</param>
 public ChainableShiftRegisterOutput(Spi spiModule, SpiChipSelectPin latchPin, int numBytes = 1,
                                     double speedMhz = 6, SpiMode mode = SpiMode.Mode00, ChipSelectMode csMode = ChipSelectMode.PulseHighAtEnd)
 {
     spiDevice     = new SpiDevice(spiModule, latchPin, csMode, speedMhz, mode);
     this.numBytes = numBytes;
     CurrentValue  = new byte[numBytes];
     lastValues    = new byte[numBytes];
 }
Ejemplo n.º 18
0
 public void Write(byte register, byte value)
 {
     SpiBuffer[0] = register;
     SpiBuffer[1] = value;
     chipSelect.Write(GpioPinValue.Low);
     Spi.Write(SpiBuffer);
     chipSelect.Write(GpioPinValue.High);
 }
Ejemplo n.º 19
0
        private void ConnectDevice()
        {
            DeviceInfo = Spi.GetDeviceInfoList()[toolStripComboBox_deviceList.SelectedIndex];
            ymf825     = new CbwYmf825Bb(toolStripComboBox_deviceList.SelectedIndex);
            Driver     = new Ymf825Driver(ymf825);

            ymf825.DataWrote += (sender, args) =>
            {
                registerMap.SetData(args.Address, args.Data);
            };
            ymf825.DataBurstWrote += (sender, args) =>
            {
                if (args.Data.Count <= 0)
                {
                    return;
                }

                if (args.Address == 0x07)
                {
                    registerMap.SetData(args.Address, args.Data.Last());

                    var toneNumber = args.Data[0] - 0x80;

                    if (toneNumber < 0 || toneNumber > 16 || args.Data.Count < toneNumber * 30 + 5)
                    {
                        Console.WriteLine($"Invalid BurstWrite Data - Tone Number: {toneNumber}, Data Size: {args.Data.Count} (required {toneNumber * 30 + 5})");
                        return;
                    }

                    for (var i = 0; i < toneNumber; i++)
                    {
                        for (var j = 0; j < 30; j++)
                        {
                            toneParameterRegisterMap[i].SetData(j, args.Data[i * 30 + j + 1]);
                        }
                    }
                }
                else if (args.Address >= 0x20 || args.Address <= 0x22)
                {
                    var eq = args.Address - 0x20;

                    if (args.Data.Count < 5)
                    {
                        return;
                    }

                    for (var i = 0; i < 5; i++)
                    {
                        registerMap.SetData(0x23 + 3 * eq + i, args.Data[i]);
                    }
                }
            };

            SpiConnected = true;
            Driver.ResetHardware();
            Driver.ResetSoftware();
            Connected?.Invoke(this, new EventArgs());
        }
Ejemplo n.º 20
0
        public NesController(Spi spi, SpiChipSelectPin ps)
        {
            dev = new SpiDevice(spi, ps, ChipSelectMode.PulseHighAtBeginning);

            A      = new Button(new DigitalInPeripheralPin(this));
            B      = new Button(new DigitalInPeripheralPin(this));
            Start  = new Button(new DigitalInPeripheralPin(this));
            Select = new Button(new DigitalInPeripheralPin(this));
        }
Ejemplo n.º 21
0
 private void PrintPairingStatus()
 {
     Console.WriteLine("# --------------- STATUS ------------------");
     Console.WriteLine($"# {_posId} <-> Eftpos: {_eftposAddress} #");
     Console.WriteLine($"# SPI STATUS: {_spi.CurrentStatus}     FLOW: {_spi.CurrentFlow} #");
     Console.WriteLine($"# SPI CONFIG: {_spi.Config}");
     Console.WriteLine("# -----------------------------------------");
     Console.WriteLine($"# POS: v{_version} Spi: v{Spi.GetVersion()}");
 }
Ejemplo n.º 22
0
        public void GetSpiVersion_OnValidResponse_ReturnObject()
        {
            // act
            var spiVersion    = Spi.GetVersion();
            var comWrapper    = new ComWrapper();
            var comSpiVersion = comWrapper.GetSpiVersion();

            // assert
            Assert.Equal(spiVersion, comSpiVersion);
        }
Ejemplo n.º 23
0
 /// <summary>
 ///     Construct a new chain of APA102-based smart LEDs.
 /// </summary>
 /// <param name="spi">The SPI port to use</param>
 /// <param name="numLeds">The number of APA102 smart LEDs in this chain</param>
 /// <param name="frequency">The frequency to use</param>
 public Apa102(Spi spi, int numLeds, double frequency = 6)
 {
     this.spi    = spi;
     spi.Enabled = true;
     this.freq   = frequency;
     for (var i = 0; i < numLeds; i++)
     {
         Leds.Add(new Led(this));
     }
 }
Ejemplo n.º 24
0
        public void RetriesBeforeResolvingDeviceAddress_OnValidValue_Checked()
        {
            // arrange
            const int retriesBeforeResolvingDeviceAddress = 3;

            // act
            Spi spi = new Spi();

            // assert
            Assert.Equal(retriesBeforeResolvingDeviceAddress, SpiClientTestUtils.GetInstanceField(typeof(Spi), spi, "_retriesBeforeResolvingDeviceAddress"));
        }
Ejemplo n.º 25
0
        public void RetriesBeforePairing_OnValidValue_Checked()
        {
            // arrange
            const int retriesBeforePairing = 3;

            // act
            Spi spi = new Spi();

            // assert
            Assert.Equal(retriesBeforePairing, SpiClientTestUtils.GetInstanceField(typeof(Spi), spi, "_retriesBeforePairing"));
        }
Ejemplo n.º 26
0
        public void SleepBeforeReconnectMs_OnValidValue_Checked()
        {
            // arrange
            const int sleepBeforeReconnectMs = 3000;

            // act
            Spi spi = new Spi();

            // assert
            Assert.Equal(sleepBeforeReconnectMs, SpiClientTestUtils.GetInstanceField(typeof(Spi), spi, "_sleepBeforeReconnectMs"));
        }
Ejemplo n.º 27
0
        public void SubmitAuthCode_OnValidResponse_ReturnObjects(string authCode, bool expectedValidFormat, string expectedMessage)
        {
            // arrange
            var spi = new Spi();

            // act
            var submitAuthCodeResult = spi.SubmitAuthCode(authCode);

            // assert
            Assert.Equal(expectedValidFormat, submitAuthCodeResult.ValidFormat);
            Assert.Equal(expectedMessage, submitAuthCodeResult.Message);
        }
Ejemplo n.º 28
0
        public void Dispose()
        {
            dcPin.Dispose();
            resetPin.Dispose();
            Spi.Dispose();

            dcPin         = null;
            resetPin      = null;
            Spi           = null;
            SpiBuffer     = null;
            displayBuffer = null;
        }
Ejemplo n.º 29
0
 private void PrintPairingStatus()
 {
     Console.WriteLine("# --------------- STATUS ------------------");
     Console.WriteLine($"# {_posId} <-> Eftpos: {_eftposAddress} #");
     Console.WriteLine($"# SPI STATUS: {_spi.CurrentStatus}     FLOW: {_spi.CurrentFlow} #");
     Console.WriteLine("# ----------------TABLES-------------------");
     Console.WriteLine($"#    Open Tables: {tableToBillMapping.Count}");
     Console.WriteLine($"# Bills in Store: {billsStore.Count}");
     Console.WriteLine($"# Assembly Bills: {assemblyBillDataStore.Count}");
     Console.WriteLine($"# -----------------------------------------");
     Console.WriteLine($"# POS: v{_version} Spi: v{Spi.GetVersion()}");
 }
Ejemplo n.º 30
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources.
        /// </summary>
        /// <param name="alsoManaged"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        private void Dispose(bool alsoManaged)
        {
            if (_isDisposed)
            {
                return;
            }

            _isDisposed = true;
            if (alsoManaged)
            {
                Spi.BbSPIClose(Handle);
            }
        }
Ejemplo n.º 31
0
        public void SpiInitiate_OnValidCharactersForPosId_IsSet()
        {
            // arrange
            const string posId         = "RamenPos@";
            const string eftposAddress = "10.20.30.40";

            // act
            var spi   = new Spi(posId, "", eftposAddress, null);
            var value = SpiClientTestUtils.GetInstanceField(typeof(Spi), spi, "_posId");

            // assert
            Assert.NotEqual("", value);
        }
Ejemplo n.º 32
0
        public void DisplayLine(int index, byte[] line)
        {
            var rowNumber = (byte)(RegisterAddressMap.Digit0 + index);

            SpiBuffer[0] = rowNumber;
            chipSelect.Write(GpioPinValue.Low);
            for (var i = line.Length - 1; i >= 0; i--)
            {
                SpiBuffer[1] = line[i];
                Spi.Write(SpiBuffer);
            }
            chipSelect.Write(GpioPinValue.High);
        }
Ejemplo n.º 33
0
        static string FormatOutput(string Format, Spi.IO.Directory.DirEntry entry)
        {
            StringBuilder sb = new StringBuilder(Format);
            foreach (string magic in FormatKeyWords)
            {
                string ReplaceString = null;
                switch (magic)
                {
                    case "fullname": ReplaceString = entry.Fullname; break;
                }
                if (!String.IsNullOrEmpty(ReplaceString))
                {
                    sb.Replace("%" + magic + "%", ReplaceString);
                }
            }

            return sb.ToString();
        }
Ejemplo n.º 34
0
 private static void HandleMatchedFile(Spi.IO.Directory.DirEntry entry, string FormatString, Action<string> OutputHandler)
 {
     string output;
     if (String.IsNullOrEmpty(FormatString))
     {
         output = String.Format("{0} {1,12} {2}",
             entry.LastWriteTime.ToString("yyyy.MM.dd HH:mm:ss"),
             entry.Filesize,
             entry.Fullname);
     }
     else
     {
         output = FormatOutput(FormatString, entry);
     }
     if (OutputHandler != null)
     {
         OutputHandler(output);
     }
 }
Ejemplo n.º 35
0
 public DirEntry(StringBuilder Dirname, Spi.Win32.WIN32_FIND_DATA FindData, int BaseDirLen)
 {
     this.Dir = Dirname;
     this.BaseDirLen = BaseDirLen;
     this.FindData = FindData;
 }