private void btnFuzz_Click(object sender, EventArgs e)
        {
            List <GPIOElement> outs = new List <GPIOElement>();

            foreach (var c in flowButtons.Controls)
            {
                GPIOElement el = c as GPIOElement;
                if (el != null && !el.IsOut)
                {
                    outs.Add(el);
                }
            }

            btnFuzz.Enabled     = false;
            btnStopFuzz.Enabled = true;

            Fuzzer fuzzer = new Fuzzer(outs, _stopFuzz, () => {
                btnStopFuzz.Invoke((Action)(() =>
                {
                    btnStopFuzz.Enabled = false;
                    btnFuzz.Enabled = true;
                }));
            });

            (new Thread(fuzzer.fuzzThreadMain)).Start();
        }
        public void gpio_irq_set(uint id, int evt, bool enable)
        {
            GPIOElement e = findElementById(id);

            if (e == null)
            {
                return;
            }
            e.setirq(evt, enable);
        }
        public void gpio_irq_connect(uint id, PinName pin, gpio_event handler)
        {
            GPIOElement e = findElement(pin);

            if (e == null)
            {
                return;
            }
            e.connect(id, handler);
        }
        public void gpio_irq_disconnect(uint id)
        {
            GPIOElement e = findElementById(id);

            if (e == null)
            {
                return;
            }
            e.disconnect();
        }
        public void gpio_irq_enable(uint id, bool enable)
        {
            GPIOElement e = findElementById(id);

            if (e == null)
            {
                return;
            }
            e.setirq(1, enable);
            e.setirq(2, enable);
        }
        public int gpio_read(PinName pin, bool is_out)
        {
            GPIOElement e = findElement(pin);

            if (e == null)
            {
                return(0);
            }
            e.IsOut = is_out;
            return(e.Value);
        }
        public void gpio_write(PinName pin, bool is_out, int value)
        {
            GPIOElement e = findElement(pin);

            if (e == null)
            {
                return;
            }
            e.IsOut = is_out;
            e.Value = value;
        }
 GPIOElement findElementById(uint id)
 {
     foreach (Control c in flowButtons.Controls)
     {
         GPIOElement e = c as GPIOElement;
         if (e.Id == id)
         {
             return(e);
         }
     }
     return(null);
 }
 GPIOElement findElement(PinName pin)
 {
     foreach (Control c in flowButtons.Controls)
     {
         GPIOElement e = c as GPIOElement;
         if (e.GetDevice().pin == pin)
         {
             return(e);
         }
     }
     return(null);
 }
        private void addDevices(IEnumerable <Device> devices)
        {
            foreach (Device d in devices)
            {
                GPIOElement c = null;
                switch (d.type)
                {
                case DeviceType.PushButton:
                    c = new PushButton();
                    break;

                case DeviceType.Switch:
                    c = new Switch();
                    break;

                case DeviceType.Led:
                    c = new LED();
                    break;

                case DeviceType.Crossover:
                    c = new Crossover();
                    break;

                case DeviceType.Ground:
                    c = new Ground();
                    break;

                case DeviceType.Vout:
                    c = new Vout();
                    break;
                }
                if (c != null)
                {
                    c.setDevice(d);
                    flowButtons.Controls.Add(c);
                }
            }
        }
        public void init(mbedsimulatorctr.MbedEmulator emulator)
        {
            foreach (Control c in flowButtons.Controls)
            {
                GPIOElement g = c as GPIOElement;
                if (g != null)
                {
                    g.remove();
                }
            }
            flowButtons.Controls.Clear();
            clear_lcd();
            rtSerial.Text = "";

            _emulator        = emulator;
            tbName.Text      = emulator.get_info().name;
            tbState.Text     = "Initialized";
            btnStart.Enabled = true;

            IEnumerable <Device> devices = genBuiltinDevices().Concat(_emulator.get_info().devices);

            _emulator.get_info().devices = devices.ToArray();

            addDevices(devices);

            if (!string.IsNullOrEmpty(emulator.get_info().vizname))
            {
                var asm = Assembly.LoadFile(emulator.get_info().vizname);
                var s   = asm.GetTypes().SingleOrDefault(v => typeof(mbedsimulatortypes.IVisualizer).IsAssignableFrom(v));
                if (s != null)
                {
                    var ci = s.GetConstructor(new Type[0]);
                    _viz = (IVisualizer)ci.Invoke(new object[0]);
                    pnlVis.Controls.Add((Control)_viz);
                }
            }
        }