Ejemplo n.º 1
0
        private async Task _tf_DoWork(Object sender, DoWorkEventArgs e)
        {
            Classes.HT16K33AnimatorAction action = (Classes.HT16K33AnimatorAction)e.Argument;

            try {
                do
                {
                    foreach (Classes.HT16K33AnimatorActionFrame frame in action.Frames)
                    {
                        if (!_ezb.IsConnected)
                        {
                            return;
                        }

                        _ht.UpdateLEDs(frame.Matrix);

                        await Task.Delay(frame.PauseTimeMS);

                        if (_tf.CancellationPending)
                        {
                            return;
                        }
                    }
                } while (action.Repeats && !_tf.CancellationPending);
            } catch (Exception ex) {
                _ezb.Log(false, "Error in thread worker of HT16K33 Animator: {0}", ex);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Stream raw audio data to the EZ-B v4's speakers.
        /// 0 is silent, 100 is normal, 200 is 2x gain, 300 is 3x gain, etc.
        /// The audio must be RAW 8 Bit at 18 KHZ Sample Rate
        /// </summary>
        public async Task PlayData(Stream ms, decimal volume, int[] progressPositions, int playFromSample)
        {
            await Stop();

            if (!_ezb.IsConnected)
            {
                return;
            }

            if (_ezb.EZBType != EZB.EZ_B_Type_Enum.ezb4)
            {
                _ezb.Log(false, "This feature is only available for EZ-B v4");

                return;
            }

            if (_ms != null)
            {
                _ms.Dispose();
            }

            _ms = new MemoryStream();

            ms.CopyTo(_ms);

            byte[] bTmp = new byte[PREBUFFER_SIZE];

            _ms.Write(bTmp, 0, bTmp.Length);

            _playFromSample = playFromSample;

            _ms.Position = playFromSample;

            _progressPositions = progressPositions;

            Volume = volume;

            _threadAudio.RunWorkerAsync();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Set the clock speed of the i2c interface
        /// </summary>
        public void SetClockSpeed(UInt32 rate)
        {
            if (_ezb.EZBType != EZB.EZ_B_Type_Enum.ezb4)
            {
                return;
            }

            _ezb.Log(false, "Setting i2c rate: {0}", rate);

            List <Byte> b = new List <byte>();

            b.Add((byte)EZB.CmdEZBv4Enum.CmdV4I2CClockSpeed);
            b.AddRange(BitConverter.GetBytes(rate));

            _ezb.sendCommand(EZB.CommandEnum.CmdEZBv4, b.ToArray());
        }
Ejemplo n.º 4
0
        private async Task _worker_DoWork(Object sender, DoWorkEventArgs e)
        {
            List <byte> bufferImage = new List <byte>();

            byte[] bufferTmp = new byte[BUFFER_SIZE];

            try {
                if (OnStart != null)
                {
                    OnStart();
                }

                _settingsToSend.Add((byte)CameraSettingsEnum.START);

                while (!_worker.CancellationPending)
                {
                    if (_settingsToSend.Count > 0)
                    {
                        await _tcpClient.Send(_settingsToSend.ToArray());

                        _settingsToSend.Clear();
                    }

                    bufferImage.AddRange(await _tcpClient.ReadBytes(BUFFER_SIZE));

                    int foundStart = Functions.IndexOf(bufferImage.ToArray(), 0, TAG_EZIMAGE);

                    if (foundStart == -1)
                    {
                        continue;
                    }

                    if (foundStart > 0)
                    {
                        bufferImage.RemoveRange(0, foundStart);
                    }

                    if (bufferImage.Count < TAG_EZIMAGE.Length + sizeof(UInt32))
                    {
                        continue;
                    }

                    int imageSize = (int)BitConverter.ToUInt32(bufferImage.GetRange(TAG_EZIMAGE.Length, sizeof(UInt32)).ToArray(), 0);

                    if (bufferImage.Count <= imageSize + TAG_EZIMAGE.Length + sizeof(UInt32))
                    {
                        continue;
                    }

                    bufferImage.RemoveRange(0, TAG_EZIMAGE.Length + sizeof(UInt32));

                    _imageSize = imageSize;

                    try {
                        if (OnImageDataReady != null)
                        {
                            OnImageDataReady(bufferImage.GetRange(0, imageSize).ToArray());
                        }
                    } catch (Exception ex) {
                        _ezb.Log(false, "ezbv4 camera image render error: {0}", ex);
                    }

                    bufferImage.RemoveRange(0, imageSize);
                }

                await _tcpClient.Send((byte)CameraSettingsEnum.STOP);

                _tcpClient.Disconnect();
            } catch (Exception ex) {
                _ezb.Log(false, "EZ-B v4 Camera Error: {0}", ex);
            } finally {
                if (OnStop != null)
                {
                    OnStop();
                }
            }
        }