示例#1
0
        public BadgeConnection(string port, int baud, IBadgeResponseDispatcher dispatcher, int retryInterval = 500)
        {
            m_dispatcher = dispatcher;

            Port   = port;
            Baud   = baud;
            Stream = new SerialPort(Port, Baud, Parity.None, 8, StopBits.One);
            Stream.DataReceived += DataReceived;
            Stream.Open();

            //
            for (byte i = 2; i != 0; ++i)
            {
                m_availableIds.Enqueue(i);
            }
            m_nextPacketID = 1;

            //
            if (System.Diagnostics.Debugger.IsAttached)
            {
                retryInterval = 5000;
            }
            m_timer         = new System.Threading.Timer(TimeoutEvent, null, retryInterval, retryInterval);
            m_timerInterval = retryInterval;

            //
            Stream.Write(Enumerable.Repeat <byte>(0xFF, 256).ToArray(), 0, 256);
            MemoryStream m = new MemoryStream();

            BadgeCommands.CreateQuerySetting(m, SettingValue.Caps);
            Send(m, true, true);
        }
示例#2
0
        public static int GetFullCommandLength(CommandCodes command, byte[] buffer, int offset)
        {
            switch (command)
            {
            case CommandCodes.UpdateSetting:
            {
                SettingValue setting = (SettingValue)(buffer[offset] & 0xF);
                return(GetSettingUpdateLength(setting));
            }

            case CommandCodes.WriteRect:
            {
                Target      targetBuffer;
                PixelFormat format;
                byte        x, y;
                byte        width, height;
                byte        bufferLength;
                int         headerLen = BadgeCommands.DecodeWriteRect(buffer, offset, out targetBuffer, out format, out x, out y, out width, out height, out bufferLength);
                return(headerLen + bufferLength);
            }

            case CommandCodes.WriteMemory:
            {
                byte  numDWords;
                short address;
                byte  bufferLength;
                int   headerLen = BadgeCommands.DecodeWriteMemory(buffer, offset, out address, out numDWords, out bufferLength);
                return(headerLen + bufferLength);
            }

            default: return(GetMinCommandLength(command));
            }
        }
示例#3
0
        void RunFrame()
        {
            var commands = new MemoryStream();

            if (m_prevBrightness != Brightness)
            {
                m_prevBrightness = Brightness;
                BadgeCommands.CreateUpdateBrightnessSetting(commands, Brightness);
            }

            if (UseFrameBuffer)
            {
                BadgeCaps device = Device;
                if (device != null && (m_renderTarget == null || !m_renderTarget.SameDimentions(device.Width, device.Height, device.BitsPerPixel == 1 ? PixelFormat.OneBit : PixelFormat.TwoBits)))
                {
                    m_renderTarget = new BadgeRenderTarget(device.Width, device.Height, device.BitsPerPixel == 1 ? PixelFormat.OneBit : PixelFormat.TwoBits);
                }

                if (m_renderTarget != null)
                {
                    var render = RenderFrame;
                    if (render != null)
                    {
                        render(this, new BadgeFrameEventArgs(Device, m_renderTarget));
                    }

                    if (Dither)
                    {
                        m_renderTarget.DitherImage();
                    }
                    m_renderTarget.PackBuffer(RotateFrame);

                    var ready = FrameReady;
                    if (ready != null)
                    {
                        ready(this, new BadgeFrameEventArgs(Device, m_renderTarget));
                    }

                    int writeBufferLength;
                    BadgeCommands.CreateWriteRect(commands, Target.BackBuffer, m_renderTarget.PackedFormat,
                                                  0, 0, (byte)m_renderTarget.WidthInBlocks, (byte)m_renderTarget.Height, out writeBufferLength);
                    commands.Write(m_renderTarget.PackedBuffer, 0, m_renderTarget.PackedBuffer.Length);
                    BadgeCommands.CreateSwap(commands, false, 0);
                }
            }
            else
            {
                var getCommands = GenerateCommands;
                if (getCommands != null)
                {
                    getCommands(this, new BadgeCommandEventArgs(Device, commands));
                }
            }

            var readyToSend = ReadyToSend;

            if (readyToSend != null)
            {
                readyToSend(this, new BadgeCommandEventArgs(Device, commands));
            }

            SendFrame(commands);
        }