private void SecondFile_VerticalScrollBarChanged(object sender, ByteEventArgs e)
        {
            if (_internalChange)
            {
                return;
            }

            _internalChange = true;
            FirstFile.SetPosition(e.BytePositionInStream);
            _internalChange = false;
        }
Exemple #2
0
 private void rgbControl_Closed(object sender, ByteEventArgs e)
 {
     Dispatcher.UIThread.InvokeAsync(new Action(() =>
     {
         configButtons.IsEnabled = true;
         configPanel.IsVisible   = true;
         if (e.Index != -1)
         {
             configPanel.SetColor(e.Index, e.Value);
         }
     }));
 }
Exemple #3
0
 //Methode appelée sur evenement (event) provenant du port Serie.
 //Cette methode est donc appelée depuis le thread du port Serie. Ce qui peut poser des problemes d'acces inter-thread
 public void ActualizeCyclesPerMinute(object sender, ByteEventArgs e)
 {
     //La solution consiste a passer par un delegué qui executera l'action a effectuer depuis le thread concerné.
     //Ici, l'action a effectuer est la modification d'un bouton. Ce bouton est un objet UI, et donc l'action doit etre executée depuis un thread UI.
     //Sachant que chaque objet UI (d'interface graphique) dispose d'un dispatcher qui permet d'executer un delegué (une methode) depuis son propre thread.
     //La difference entre un Invoke et un beginInvoke est le fait que le Invoke attend la fin de l'execution de l'action avant de sortir.
     labelCycles.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(delegate()
     {
         labelCycles.Content = e.Value.ToString();
         cycles = e.Value;
     }));
 }
Exemple #4
0
 private void rgbControl_OnClosed(object sender, ByteEventArgs e)
 {
     Dispatcher.UIThread.InvokeAsync(new Action(() =>
     {
         mainViewer.IsVisible = true;
         if (e.Index != -1)
         {
             hue[e.Index] = e.Value;
             rgbButton[e.Index].Content    = e.Value.ToString();
             rgbButton[e.Index].Background = new SolidColorBrush(HueToColor.Convert(e.Value));
         }
     }));
 }
 protected void OnMessageReceived(object sender, ByteEventArgs e)
 {
     Trace.WriteLineIf(Settings.TraceSwitch.TraceVerbose, "Parsing incoming NS command...", GetType().Name);
     try
     {
         NSMessage nsMessage = new NSMessage();
         nsMessage.ParseBytes(e.Bytes);
         OnNSMessageReceived(this, new NSMessageEventArgs(nsMessage));
     }
     catch (Exception exc)
     {
         OnHandlerException(this, new ExceptionEventArgs(new MSNPSharpException(
                                                             "An exception occured while handling a nameserver message. See inner exception for more details.", exc)));
     }
 }
Exemple #6
0
        private void analysis(object obj)
        {
            while (analysisRunning)
            {
                while (!queueReceiveBuffer.IsEmpty)
                {
                    CanDataWithInfo bi     = null;
                    bool            result = queueReceiveBuffer.TryDequeue(out bi);
                    if (!result || null == bi)
                    {
                        continue;
                    }
                    if (bi.canId == 0)
                    {
                        continue;
                    }
                    ByteEventArgs byteEventArgs = new ByteEventArgs(DateTime.Now, new BytesWithInfo(bi.bytes, ""));
                    eventReceived?.Invoke(this, byteEventArgs);

                    //写入文件记录
                    logger.Info(byteEventArgs.getBytesString());

                    if (bi.canId == 0x04)
                    {
                        //读6个字节的数据
                        byte[] byData   = bi.bytes;
                        int    boxId    = byData[1] << 8 | byData[0];
                        int    boxState = byData[2];
                        eventBoxStateChanged?.Invoke(this, new BoxStateEventArgs(boxId, boxState));
                    }
                    else if (bi.canId == 0x06)
                    {
                        //第一个视频开始播放命令
                        LightBoxHelper.videoBegin = true;
                    }
                    Thread.Sleep(1);
                }
                Thread.Sleep(1);
            }
        }
Exemple #7
0
 public void GenerateMessageSetAsservissementMode(object sender, ByteEventArgs e)
 {
     byte[] payload = new byte[1];
     payload[0] = Convert.ToByte(e.Value);
     OnMessageToRobot((Int16)Commands.PC2R_SetAsservissementMode, 1, payload);
 }
Exemple #8
0
 public void GenerateMessageSetIOPollingFrequencyToRobot(object sender, ByteEventArgs e)
 {
     byte[] payload = new byte[1];
     payload[0] = e.Value;
     OnMessageToRobot((Int16)Commands.PC2R_IOPollingSetFrequency, 1, payload);
 }
 //串口发出数据
 private void Ins_eventReceived(object sender, ByteEventArgs e)
 {
     txtReceived.Dispatcher.Invoke(new Action(() => {
         txtReceived.Text = txtReceived.Text + "\n" + e.ToString();
     }));
 }
Exemple #10
0
        public static void Main()
        {
            using VulcanKeyboard keyboard = VulcanKeyboard.Initialize();

            if (keyboard == null)
            {
                Console.WriteLine("Did not find vulcan!");
                Console.ReadLine();
                return;
            }
            var pos = GetKeyPositions();
            //Thread.Sleep(3000);

            //Cursor.Position = new Point(screenLeft, screenTop);
            //Thread.Sleep(200);
            //Cursor.Position = new Point(screenLeft + screenWidth, screenTop);
            //Thread.Sleep(200);
            //Cursor.Position = new Point(screenLeft + screenWidth, screenTop + screenHeight);
            //Thread.Sleep(200);
            //Cursor.Position = new Point(screenLeft, screenTop + screenHeight);
            //Thread.Sleep(200);


            bool initKeyboard = true;
            bool fnPressed    = false;
            bool easyPressed  = false;

            Dictionary <int, byte[]> mapping            = new Dictionary <int, byte[]>();
            Dictionary <int, Color>  alreadyClickedKeys = new Dictionary <int, Color>();

            if (initKeyboard)
            {
                var are  = new AutoResetEvent(false);
                var are2 = new AutoResetEvent(false);
                keyboard.SetColor(Color.Black);
                keyboard.SetKeyColor(0, Color.Green);
                keyboard.Update();

                int i = 0;
                Dictionary <string, byte[]> keys = new Dictionary <string, byte[]>()
                {
                    { "esc", new byte[] { 0x03, 0x00, 0xFB, 0x11 } },
                    { "fn", new byte[] { 0x03, 0x00, 0xFB, 0x77 } },
                    { "easyshift", new byte[] { 0x03, 0x00, 0x0A, 0xFF } },
                    { "oemminus", new byte[] { 0x03, 0x00, 0xFB, 0x5E } },
                };
                ByteEventArgs args = null;

                keyboard.KeyPressedReceived += (object sender, ByteEventArgs even) =>
                {
                    args = even;
                    are2.Set();
                    try
                    {
                        if (args.Bytes.Take(4).SequenceEqual(keys["fn"]))
                        {
                            return;
                        }
                        if (args.Bytes.Take(4).SequenceEqual(keys["easyshift"]))
                        {
                            return;
                        }

                        if (fnPressed && args.Bytes.Take(4).SequenceEqual(keys["oemminus"]) && args.Bytes[4] > 0)
                        {
                            Console.WriteLine("You have made a custom fn hotkey :)");
                        }

                        if (easyPressed && args.Bytes.Take(4).SequenceEqual(keys["oemminus"]) && args.Bytes[4] > 0)
                        {
                            Console.WriteLine("You have made a custom easy hotkey :)");
                        }

                        if (even.Bytes.Take(4).SequenceEqual(keys["esc"]))
                        {
                            i++;
                            keyboard.SetColor(Color.Black);
                            //keyboard.SetKeyColor(i, Color.Green);
                            keyboard.SetKeyColor(i / 2, Color.Green);
                            keyboard.Update();
                            return;
                        }

                        //i++;

                        keyboard.SetColor(Color.Black);
                        //keyboard.SetKeyColor(i, Color.Green);
                        keyboard.SetKeyColor(i / 2, Color.Green);
                        keyboard.Update();

                        //mapping.Add(i, even.Bytes.Take(20).ToArray());

                        //if (i > 300)
                        //    are.Set();
                    }
                    catch (Exception e)
                    {
                    }
                };;
                var task = Task.Run(() =>
                {
                    while (true)
                    {
                        are2.WaitOne();
                        if (args.Bytes.Take(4).SequenceEqual(keys["fn"]))
                        {
                            var block = args.Bytes[4] > 0;
                            if (block)
                            {
                                keyboard.SetColor(Color.Red);
                            }
                            else
                            {
                                keyboard.SetColor(Color.Green);
                            }
                            keyboard.Update();
                            fnPressed = block;
                            try
                            {
                                BlockInput(block);
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e.Message);
                                BlockInput(false);
                            }
                        }
                        else if (args.Bytes.Take(4).SequenceEqual(keys["easyshift"]))
                        {
                            var block = args.Bytes[4] < 1;
                            if (block)
                            {
                                keyboard.SetColor(Color.Yellow);
                            }
                            else
                            {
                                keyboard.SetColor(Color.Green);
                            }
                            keyboard.Update();
                            easyPressed = block;
                            try
                            {
                                BlockInput(block);
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e.Message);
                                BlockInput(false);
                            }
                        }
                    }
                });
                are.WaitOne();
            }



            CudafyTranslator.GenerateDebug = true;
            CudafyModule km = CudafyTranslator.Cudafy(ePlatform.x64, eArchitecture.OpenCL);//, Version.Parse("9.0"), false, new Type[]{N.GetType()});

            km.GenerateDebug = true;
            GPGPU gpu = CudafyHost.GetDevice(eGPUType.OpenCL, 0);// CudafyModes.Target, CudafyModes.DeviceId);

            //GPGPU gpu = new OpenCLDevice(2);

            gpu.LoadModule(km);
            double frameTime = 1000d / 500d;

            GPUColorBGRA[] colors = new GPUColorBGRA[] {
                //new GPUColorRGB { Red = 0xAD, Green = 0x4A, Blue =0x00},
                //new GPUColorRGB { Red = 0xCE, Green = 0x73, Blue =0x00},
                //new GPUColorRGB { Red = 0x00, Green = 0xAD, Blue =0xF7},
                //new GPUColorRGB { Red = 0xD2, Green = 0xCC, Blue =0x2B},
                //new GPUColorRGB { Red = 0x8C, Green = 0x7A, Blue =0x8B},
                //new GPUColorRGB { Red = 0xEC, Green = 0x00, Blue =0x00},
                //new GPUColorRGB { Red = 0x39, Green = 0x03, Blue =0x03},
                //new GPUColorRGB { Red = 0x4A, Green = 0x4A, Blue = 0x4A },

                ////Minecraft
                new GPUColorBGRA {
                    Red = 43, Green = 113, Blue = 119
                },
                //new GPUColorRGB { Red = 43, Green = 119, Blue = 113 },
                //new GPUColorRGB { Red = 113, Green = 43, Blue = 119 },
                //new GPUColorRGB { Red = 113, Green = 119, Blue = 43 },
                //new GPUColorRGB { Red = 119, Green = 113, Blue = 43 },
                //new GPUColorRGB { Red = 119, Green = 43, Blue = 113 },
            };

            //var ret = gpu.CopyToDevice(colors);

            float[,,] output = new float[keysWidth, keysHeight, 3];
            //float[] debugOutput = new float[screenWidth * screenHeight];
            float[,] outputs = new float[keysWidth, keysHeight];
            //float[] debugOutputs = new float[debugOutput.Length];
            float[,,] devoutput = gpu.Allocate <float>(keysWidth, keysHeight, 3);
            //float[] deboutput = gpu.Allocate<float>(debugOutput.Length);
            //int[] devindices = gpu.Allocate<int>(blockSize.x);
            List <float>  res    = new List <float>();
            HashSet <int> often  = new HashSet <int>();
            HashSet <int> often2 = new HashSet <int>();

            int[]         indices     = new int[blockSize.x];
            byte          clearOftens = 0;
            int           x           = 0;
            int           y           = 0;
            HashSet <int> ys          = new HashSet <int>();
            byte          b           = 0;
            //Thread.Sleep(2000);
            int count = 120;

            var keyColors = new Color[] { Color.Red, Color.Green, Color.Blue };
            var enumVals  = System.Enum.GetValues(typeof(Key)).Cast <int>().ToArray();

            Random r = new Random();

            using (var screenShot = new DirectScreenshot(gpu, screenWidth, screenHeight))
            {
                while (true)
                {
                    //for (int loops = 0; loops < 150; loops++)
                    //{
                    watch.Restart();
                    //(int x, int y) pointerPos = ;
                    screenShot.Capture();

                    //gpu.CopyToDevice(indices, devindices);
                    //gpu.Set(devindices);
                    //gpu.Launch(gridSize, blockSize).ScaleImageKernel(screenShot.rgbValues, ret, devindices, devoutput, deboutput);
                    _ = gpu.Launch(new dim3(keysWidth / 4, keysHeight / 3), new dim3(4, 3)).EnhancedScaleImageKernel(screenShot.rgbValues, screenWidth, screenHeight, devoutput);


                    ////Thread.Sleep(500);
                    gpu.CopyFromDevice(devoutput, output);

                    //var bitmap = new Bitmap(100, 16, PixelFormat.Format24bppRgb);
                    //unsafe
                    //{
                    //    var bmpData = bitmap.LockBits(new Rectangle(new Point(), bitmap.Size), ImageLockMode.WriteOnly, bitmap.PixelFormat);
                    //    var ptr = (byte*)bmpData.Scan0;

                    //    for (int y1 = 0; y1 < 16; y1++)
                    //    {
                    //        for (int x1 = 0; x1 < 100; x1++)
                    //        {

                    //            ptr[(y1 * 100 + x1) * 3 + 0] = (byte)output[x1, y1, 2];
                    //            ptr[(y1 * 100 + x1) * 3 + 1] = (byte)output[x1, y1, 1];
                    //            ptr[(y1 * 100 + x1) * 3 + 2] = (byte)output[x1, y1, 0];
                    //        }
                    //    }
                    //    bitmap.UnlockBits(bmpData);
                    //}
                    //bitmap.Save("TestImage.bmp");
                    ;
                    //gpu.CopyFromDevice(deboutput, debugOutput);
                    //gpu.CopyFromDevice(devindices, indices);
                    //var asdq = indices.Select((x, i) => x==0 ? -1 : (i * gridSize.x)).Where(x=>x!=-1).ToList();
                    //Console.Error.WriteLine("Milliseconds Array Sort begin: " + watch.Elapsed.TotalMilliseconds);

                    //for (int i = 0; i < output.Length; i+=gridSize.x)
                    //{
                    //    for (int oz = i; oz < gridSize.x + i; oz++)
                    //    {
                    //        var item = (int)output[oz];
                    //        if (item <= 0)
                    //            break;
                    //        count++;
                    //        //Console.WriteLine(/* LeftClick*/(item % screenWidth, item / screenWidth));
                    //        LeftClick(item % screenWidth, item / screenWidth);
                    //        //Thread.Sleep(333);
                    //    }
                    //}
                    //var zerosCount = debugOutput.Count(z => z != 0);
                    //watch.Restart();
                    //var onesAndOnlys = output.Count(z => z == 0);
                    //outputs = output.Where(f => f != 0).ToArray();
                    //Console.WriteLine(watch.Elapsed + " took where");
                    //watch.Restart();

                    //Array.Sort(output);
                    //output = output.Reverse().ToArray();
                    //Console.WriteLine(watch.Elapsed + " took sort");
                    //watch.Stop();
                    //for (int i = 0; i < outputs.Length/*&& count < 200*/; i++)
                    //{
                    //    var item = (int)outputs[i];
                    //    if (item != 0)
                    //        count++;
                    //    if (Control.IsKeyLocked(Keys.CapsLock))
                    //        break;
                    //    if (item == 0)
                    //        break;
                    //    x = item % screenWidth;
                    //    y = item / screenWidth;
                    //    //if (x == pointerPos.x && y == pointerPos.y)
                    //    //    Console.WriteLine("Pointer in Array");
                    //    //if (often2.Contains(item))
                    //    //    continue;
                    //    //if (often.Contains(item))
                    //    //{
                    //    //    if (!often2.Contains(item))
                    //    //    {
                    //    if (x > ourscreenLeft && x < ourscreenWidth + ourscreenLeft
                    //        && y > ourscreenTop && y < ourscreenTop + ourscreenHeight
                    //        && x == 666
                    //        && false)
                    //    {
                    //        //ys.Add(y);
                    //        //count++;
                    //        //Console.WriteLine($"{x}:{y}");
                    //        LeftClick(item % screenWidth + 243, item / screenWidth + 20); //Insaniquarium
                    //    }
                    //    //else
                    //    {
                    //        ;
                    //    }
                    //    //if ((item % screenWidth) == 26)
                    //    //LeftClick((item % screenWidth) + screenLeft + 243, (item / screenWidth) + 20);
                    //    //often2.Add(item);
                    //    //    }
                    //    //}
                    //    //else
                    //    //{
                    //    //    b++;

                    //    //    LeftClick(item % screenWidth, item / screenWidth);
                    //    //    often.Add(item);
                    //    //}

                    //    count++;
                    //    //LeftClick(item % screenWidth, item / screenWidth);
                    //    //Thread.Sleep(1);


                    //    //break;
                    //    //count++;
                    //    //Console.WriteLine(/* LeftClick*/(item % screenWidth, item / screenWidth));
                    //}
                    //b++;
                    //if (!Control.IsKeyLocked(Keys.CapsLock))
                    //{
                    //    //mouse_event((int)MouseEventFlags.MOUSEEVENTF_WHEEL, 0, 0, -120, 0);
                    //    //Thread.Sleep(50);
                    //}

                    watch.Stop();
                    //Console.WriteLine("Found: " + count);
                    //count = 0;
                    //var l = output.Select((x,i) => (x,i)).Where(x => x.x > 0).Select(x=>((float)x.i) / 2025).ToList();
                    //Console.WriteLine(count + " | " + l.Count);
                    //Console.Write("Found: " +  + " | ");
                    double elapsed = watch.Elapsed.TotalMilliseconds;
                    //Console.Error.WriteLine("Milliseconds: " + watch.Elapsed.TotalMilliseconds);


                    var color = keyColors[count % 3];
                    keyboard.SetColor(Color.Orange);
                    //keyboard.SetKeyColor((Key)enumVals[(count / 3)], color);
                    //keyboard.SetKeyColor((Key)enumVals[(((count / 3)+ enumVals.Length-1) % enumVals.Length)], Color.Black);
                    //count = (count + 1)%(enumVals.Length* 3);
                    //keyboard.SetColor(Color.FromArgb((count >> 16) & 0xff, (count >> 8) & 0xff, count & 0xff));
                    //count += r.Next(0, 255);
                    //keyboard.SetColor(Color.Green);
                    //for (int i = 0; i < 131; i++)
                    //{
                    //    keyboard.SetKeyColor((Key)i, Color.FromArgb(255 << 24 | r.Next(0, 255 << 16)));
                    //}

                    SetKeyColorsForAmbilight(keyboard, output);


                    //watch.Restart();
                    keyboard.Update();
                    //watch.Stop();
                    //Console.WriteLine("Set colors took:" + watch.ElapsedMilliseconds + "ms");
                    elapsed += watch.Elapsed.TotalMilliseconds;


                    //Thread.Sleep((int)Math.Max((frameTime - watch.Elapsed.TotalMilliseconds), 0));
                    Thread.Sleep(1);
                    //Thread.Sleep(Math.Min(33, Math.Max(0, 33 - (int)elapsed)));
                    //clearOftens++;
                    //if (clearOftens % 20 == 0)
                    //    often.Clear();
                    //else if (clearOftens == 101)
                    //{
                    //    often.Clear();
                    //    often2.Clear();
                    //    clearOftens = 0;
                    //}
                    //mouse_event((int)MouseEventFlags.MOUSEEVENTF_WHEEL, 0, 0, -120, 0);
                    //}
                    //Console.ReadKey();
                }
            }
            gpu.FreeAll();
            Console.Read();
        }
        /// <summary>
        /// Discards the foo message and sends the message to all handlers as a P2PDCMessage object.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void OnMessageReceived(object sender, ByteEventArgs e)
        {
            Trace.WriteLineIf(Settings.TraceSwitch.TraceVerbose,
                              "Analyzing message in DC state <" + dcState + ">", GetType().Name);

            byte[] data = e.Bytes;

            switch (dcState)
            {
            case DirectConnectionState.Established:
            {
                // Convert to a p2pdc message
                P2PDCMessage dcMessage = new P2PDCMessage(version);
                dcMessage.ParseBytes(data);

                OnP2PMessageReceived(new P2PMessageEventArgs(dcMessage));
            }
            break;

            case DirectConnectionState.HandshakeReply:
            {
                P2PDCHandshakeMessage match = VerifyHandshake(data);

                if (match == null)
                {
                    Dispose();
                    return;
                }

                Trace.WriteLineIf(Settings.TraceSwitch.TraceVerbose,
                                  "Nonce accepted: " + match.Guid + "; My Nonce: " + this.nonce + "; Need Hash: " + needHash, GetType().Name);

                DCState = DirectConnectionState.Established;
            }
            break;

            case DirectConnectionState.Handshake:
            {
                P2PDCHandshakeMessage match = VerifyHandshake(data);

                if (match == null)
                {
                    Dispose();
                    return;
                }

                Trace.WriteLineIf(Settings.TraceSwitch.TraceVerbose,
                                  "Nonce MATCH: " + match.Guid, GetType().Name);

                match.Guid = reply;

                if (version == P2PVersion.P2PV1)
                {
                    startupSession.IncreaseLocalIdentifier();
                    match.Header.Identifier = startupSession.LocalIdentifier;
                }

                // Send Nonce Reply
                SendMessage(match);

                DCState = DirectConnectionState.Established;
            }
            break;

            case DirectConnectionState.Foo:
            {
                string initialData = Encoding.ASCII.GetString(data);

                if (data.Length == 4 && initialData == "foo\0")
                {
                    DCState = DirectConnectionState.Handshake;
                    Trace.WriteLineIf(Settings.TraceSwitch.TraceVerbose, "foo0 handled", GetType().Name);
                }
                else
                {
                    Trace.WriteLineIf(Settings.TraceSwitch.TraceWarning, "foo0 expected, but it was: " + initialData, GetType().Name);
                    Dispose();
                    return;
                }
            }
            break;

            case DirectConnectionState.Closed:
                break;
            }
        }