public DriverStation(PortDefinition wifiPort)
        {
            if (wifiPort is IPortUart)
            {
                IPortUart p = (IPortUart)wifiPort;
                _uart    = new System.IO.Ports.SerialPort(p.UART, 115200, System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.One);
                _restart = new Microsoft.SPOT.Hardware.OutputPort(p.Pin6, true);
                if (wifiPort is Port1Definition)
                {
                    _flashPin = new Microsoft.SPOT.Hardware.OutputPort(((Port1Definition)wifiPort).Pin3, true);
                }
                if (wifiPort is Port4Definition)
                {
                    _flashPin = new Microsoft.SPOT.Hardware.OutputPort(((Port4Definition)wifiPort).Pin3, true);
                }
                if (wifiPort is Port6Definition)
                {
                    _flashPin = new Microsoft.SPOT.Hardware.OutputPort(((Port6Definition)wifiPort).Pin3, true);
                }
            }
            else
            {
                status = ErrorCode.PORT_MODULE_TYPE_MISMATCH;
                Reporting.SetError(status);
            }


            _uart.Open();
            _uart.Flush();


            _enabled   = false;
            _connected = false;
            CTRE.Phoenix.Controller.GameControllerValues _g = new Controller.GameControllerValues();
            CTRE.Phoenix.Controller.GameControllerValues _h = new Controller.GameControllerValues();
            CTRE.Phoenix.Controller.GameControllerValues _j = new Controller.GameControllerValues();
            CTRE.Phoenix.Controller.GameControllerValues _k = new Controller.GameControllerValues();
            CTRE.Phoenix.Controller.GameControllerValues _l = new Controller.GameControllerValues();
            CTRE.Phoenix.Controller.GameControllerValues _m = new Controller.GameControllerValues();
            _joysticks = new CTRE.Phoenix.Controller.GameControllerValues[6] {
                _g, _h, _j, _k, _l, _m
            };
            _controllers    = new CTRE.Phoenix.Controller.GameController[6];
            _data           = new byte[255];
            _sendingMessage = new byte[1] {
                0x00
            };
            buffer = new Containers.ByteRingBuffer(255);
        }
 private int HandleError(int errorCode)
 {
     /* error handler */
     if (errorCode != 0)
     {
         /* This requires being in the main CTRE library package to function (due to access protection).
          * For now, print error no. to debug.
          * Reporting.SetError should be made public. - Ozrien*/
         //Reporting.SetError(errorCode, Reporting.getHALErrorMessage(errorCode));
         Debug.Print("PDP Error: " + errorCode + "\r\n");
     }
     /* mirror last status */
     _lastError = errorCode;
     return((int)_lastError);
 }
                public WiFiESP12F(PortDefinition port)
                {
                    if (Contains(port.types, kModulePortType))
                    {
                        status    = ErrorCode.OK;
                        this.port = port;

                        processState  = READY;
                        headerState   = STAGE1;
                        linkIDState   = STAGE1;
                        processedSize = 0;
                        dataCount     = 0;
                        InitUart((IPortUart)(this.port));
                        InitPresenceCheck((IPortUart)this.port);


                        // lex = new WiFiSerialLexer(uart);
                    }
                    else
                    {
                        status = ErrorCode.PORT_MODULE_TYPE_MISMATCH;
                        //Reporting.SetError(status);
                    }
                }
                /** ctor */
                public DisplayModule(IPortSPI port, OrientationType orientation)
                {
                    if (CTRE.Phoenix.Util.Contains(((PortDefinition)port).types, kModulePortType))
                    {
                        status = ErrorCode.OK;
                        _port  = (PortDefinition)port;

                        bool port1F = port is Port1Definition;
                        SPI.Configuration spiConfiguration;
                        if (port1F)
                        {
                            Port1Definition portDef = (Port1Definition)port;
                            spiConfiguration = new SPI.Configuration(portDef.Pin6, false, 0, 0, false, true, 12000, SPI.SPI_module.SPI4);
                            if (portDef.Pin3 != Cpu.Pin.GPIO_NONE)
                            {
                                _outReset = new OutputPort(portDef.Pin3, false);
                            }

                            if (portDef.Pin4 != Cpu.Pin.GPIO_NONE)
                            {
                                _outBackLght = new OutputPort(portDef.Pin4, true);
                            }

                            _outRs = new OutputPort(portDef.Pin5, false);
                        }
                        else
                        {
                            Port8Definition portDef = (Port8Definition)port;
                            spiConfiguration = new SPI.Configuration(portDef.Pin6, false, 0, 0, false, true, 12000, SPI.SPI_module.SPI4);
                            if (portDef.Pin3 != Cpu.Pin.GPIO_NONE)
                            {
                                _outReset = new OutputPort(portDef.Pin3, false);
                            }

                            if (portDef.Pin4 != Cpu.Pin.GPIO_NONE)
                            {
                                _outBackLght = new OutputPort(portDef.Pin4, true);
                            }

                            _outRs = new OutputPort(portDef.Pin5, false);
                        }

                        /* alloc the working arrays */
                        _cache_1B     = new byte[1];
                        _cache_2W     = new ushort[2];
                        _cache_manyBs = new byte[1024];
                        _cache_manyWs = new ushort[1024];

                        _spi = new Microsoft.SPOT.Hardware.SPI(spiConfiguration);

                        /* reset pulse if pin is available */
                        if (_outReset != null)
                        {
                            _outReset.Write(false);
                            Thread.Sleep(150);
                            _outReset.Write(true);
                        }
                        /* setup registers */
                        ConfigureDisplay();

                        /* fixup orientation */
                        _orientation = orientation;
                        ApplytOrientation();

                        /* empty screen */
                        ClearScreen();

                        /* start rendering thread */
                        var th = new Thread(RenderThread);
                        th.Priority = ThreadPriority.Lowest;
                        th.Start();
                    }
                    else
                    {
                        status = ErrorCode.PORT_MODULE_TYPE_MISMATCH;
                        CTRE.Phoenix.Reporting.SetError(status);
                    }
                }
 protected override ErrorCode SetLastError(ErrorCode errorCode)
 {
     _lastError = errorCode;
     return(_lastError);
 }