Domanda

Di recente Sto scrivendo un programma Wiimote:

    using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WiimoteLib;

namespace WiiTester
{
    public partial class Form1 : Form
    {
        Wiimote wm = new Wiimote();
        public Form1()
        {
            InitializeComponent();


            wm.WiimoteChanged += wm_WiimoteChanged;
            wm.WiimoteExtensionChanged += wm_WiimoteExtensionChanged;

            wm.Connect();
            wm.SetReportType(InputReport.IRAccel, true);
        }

        void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs args)
        {
            WiimoteState ws = args.WiimoteState;

            if (ws.ButtonState.A == true)
            {
                wm.SetRumble(true);
            }
            else
            {
                wm.SetRumble(false);
            }
        }

        void wm_WiimoteExtensionChanged(object sender, WiimoteExtensionChangedEventArgs args)
        {
            if (args.Inserted)
            {
                wm.SetReportType(InputReport.IRExtensionAccel, true);
            }
            else
            {
                wm.SetReportType(InputReport.IRAccel, true);
            }
        }
    }
}
.

My Wiimote continua a essere scollegati e questo errore continua a funzionare su wm.connect (); Tempi in attesa del rapporto sullo stato

C'è una soluzione?

È stato utile?

Soluzione

Ho molta esperienza con questa libreria, e il tuo problema è probabilmente causato perché stai chiamando seturo così spesso, questo codice:

    void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs args)
    {
        WiimoteState ws = args.WiimoteState;

        if (ws.ButtonState.A == true)
        {
            wm.SetRumble(true);
        }
        else
        {
            wm.SetRumble(false);
        }
    }
.

Chiamerà SETRUMBUMS Costantemente se A è in basso o meno, considerare l'utilizzo di questo codice:

    bool rumbleOn = false;

   void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs args)
    {
      WiimoteState ws = args.WiimoteState;

      bool newRumble = (ws.ButtonState.A == true);

          if (rumbleOn != newRumble) 
      {
            rumbleOn = newRumble;
            wm.SetRumble(rumbleOn);
      }
    }
.

In questo modo il metodo di rumble impostato viene chiamato solo quando richiesto e non inviare costantemente i rapporti di output al Wiimote che causa il sovraccarico del bus Bluetooth.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top