Beispiel #1
0
        private void tsbEnterBootloader_Click(object sender, EventArgs e)
        {
            var dev = MuniaController.GetConfigInterface();

            if (dev == null)
            {
                MessageBox.Show("Interface not found");
                return;
            }
            try {
                using (var stream = dev.Open()) {
                    byte[] buff = new byte[9];
                    buff[0] = 0;
                    buff[1] = 0x48;                     // CFG_CMD_RESET_BL
                    stream.Write(buff, 0, buff.Length);
                }
            }
            catch (Win32Exception) { }
            catch (IOException) { }
            catch (TimeoutException) { }
            catch (Exception exc) {
                MessageBox.Show("An error occurred while retrieving information from the MUNIA device:\r\n\r\n" + exc,
                                "Unknown error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #2
0
        void UpdateDevices()
        {
            munias = MuniaController.ListDevices().ToList();
            lbMuniaDevices.DataSource = munias;

            nspys = ArduinoController.ListDevices().ToList();
            lbNintendoSpyDevices.DataSource = nspys;

            generics = GenericController.ListDevices().ToList();
            lbGenericDevices.DataSource = generics;
        }
Beispiel #3
0
 public static void LoadControllers()
 {
     Controllers.Clear();
     foreach (var dev in MuniaController.ListDevices())
     {
         Controllers.Add(dev);
     }
     foreach (var dev in ArduinoControllerManager.ListDevices())
     {
         Controllers.Add(dev);
     }
 }
Beispiel #4
0
        private void tsmiMuniaSettings_Click(object sender, EventArgs e)
        {
            var dev = MuniaController.GetConfigInterface();

            if (dev == null)
            {
                MessageBox.Show("MUNIA config interface not found. This typically has one of three causes:\r\n  MUNIA isn't plugged in\r\n  MUNIA is currently in bootloader mode\r\n  Installed firmware doesn't implement this feature yet. Upgrade using the instructions at http://munia.io/fw",
                                "Not possible", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            HidStream stream;

            if (dev.TryOpen(out stream))
            {
                try {
                    byte[] buff = new byte[9];
                    buff[0] = 0;
                    buff[1] = 0x47;                      // CFG_CMD_READ
                    stream.Write(buff, 0, 9);
                    stream.Read(buff, 0, 9);

                    var settings = new MUNIA.MuniaDeviceInfo();
                    if (settings.Parse(buff))
                    {
                        if (settings.IsLegacy)
                        {
                            var dlg = new MuniaSettingsDialog(stream, settings);
                            dlg.ShowDialog(this);
                        }
                        else
                        {
                            var dlg = new MuniaSettingsDialog(stream, settings);
                            dlg.ShowDialog(this);
                        }
                    }
                    else
                    {
                        throw new InvalidOperationException("Invalid settings container received from MUNIA device: " + string.Join(" ", buff.Select(x => x.ToString("X2"))));
                    }
                }

                catch (Exception exc) {
                    MessageBox.Show("An error occurred while retrieving information from the MUNIA device:\r\n\r\n" + exc,
                                    "Unknown error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
 public static void LoadControllers()
 {
     Controllers.Clear();
     foreach (var dev in MuniaController.ListDevices())
     {
         Controllers.Add(dev);
     }
     foreach (var dev in ArduinoController.ListDevices())
     {
         Controllers.Add(dev);
     }
     foreach (var dev in XInputController.ListDevices())
     {
         Controllers.Add(dev);
     }
     foreach (var dev in GenericController.ListDevices())
     {
         Controllers.Add(dev);
     }
     foreach (var dev in MappedController.ListDevices())
     {
         Controllers.Add(dev);
     }
 }
Beispiel #6
0
 private void Register(MuniaController c)
 {
     _activeController = c;
     c.Activate();
     c.StateUpdated += ControllerStateUpdated;
 }
Beispiel #7
0
 public MainForm()
 {
     InitializeComponent();
     comboBox1.Items.AddRange(MuniaController.ListDevices().ToArray());
 }
Beispiel #8
0
 private void RefreshDeviceList(object sender, UsbNotificationEventArgs e)
 {
     lbDevices.DataSource = MuniaController.GetConfigInterfaces().ToList();
 }
Beispiel #9
0
        private void UpdateUI()
        {
            // enter bootloader button is enabled if vid/pid of MUNIA
            // is observed, if so all other functions are disabled
            var muniaInterfaces = MuniaController.GetMuniaConfigInterfaces();

            if (muniaInterfaces.Any())
            {
                // munia detected, so it's not in BL, but we can send a packet to request this
                tsbLoadHex.Enabled         = tsbProgram.Enabled = tsbReset.Enabled = false;
                _blDevice                  = null;
                _blInterface               = null;
                imgBlStatus.Image          = Resources.warn;
                lblStatus.Text             = "Status: user";
                imgBlStatus.ToolTipText    = "MUNIA is currently in user mode.\r\nReboot it in bootloader mode to continue.";
                tsbEnterBootloader.Enabled = true;
                lblHEX.Visible             = imgHexStatus.Visible = pbFlash.Visible = lblProgress.Visible = false;
                tsbLoadHex.Enabled         = tsbProgram.Enabled = tsbReset.Enabled = false;
                return;
            }
            else
            {
                tsbEnterBootloader.Enabled = false;
            }

            // see if there is a selected device, and whether is still valid
            HidStream s          = null;
            bool      blDeviceOk = false;

            if (_blDevice != null && _blDevice.TryOpen(out s))
            {
                s.Dispose();
                blDeviceOk = true;
            }
            else
            {
                _blDevice = null;
            }

            // if no device selected, see if we can find one
            if (_blDevice == null)
            {
                _blDevice  = MuniaController.GetMuniaBootloaderInterfaces().FirstOrDefault();
                blDeviceOk = _blDevice != null && _blDevice.TryOpen(out s);
                if (blDeviceOk)
                {
                    s.Dispose();
                    _blInterface = new HidBootloader(_blDevice);
                }
            }

            if (blDeviceOk)
            {
                imgBlStatus.Image     = Resources.ok;
                lblStatus.Text        = "Status: in BL";
                lblStatus.ToolTipText = "MUNIA is currently in bootloader mode,\r\n and is ready to be flashed.";
            }
            else
            {
                imgBlStatus.Image     = Resources.notok;
                lblStatus.Text        = "Status: not found";
                lblStatus.ToolTipText = "MUNIA is currently not plugged in or malfunctioning.";
                lblHEX.Visible        = imgHexStatus.Visible = pbFlash.Visible = lblProgress.Visible = false;
                tsbLoadHex.Enabled    = tsbProgram.Enabled = tsbReset.Enabled = false;
                return;
            }

            lblHEX.Visible     = imgHexStatus.Visible = pbFlash.Visible = lblProgress.Visible = true;
            tsbLoadHex.Enabled = true;
            tsbReset.Enabled   = true;
            if (_hexFile?.Size > 0x100)
            {
                tsbProgram.Enabled       = true;
                imgHexStatus.Image       = Resources.ok;
                imgHexStatus.ToolTipText = "Firmware hex file is successfully loaded.";
            }
            else
            {
                tsbProgram.Enabled       = false;
                imgHexStatus.Image       = Resources.notok;
                imgHexStatus.ToolTipText = "Load a firmware hex file to flash first.";
            }
        }