我最近写了一个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);
            }
        }
    }
}
.

我的wiimote不断断开连接,此错误在wm.connect()上不断运行; 超时等待状态报告

是否有解决方案?

有帮助吗?

解决方案

我对这个图书馆有很多经验,你的问题很可能是因为你经常调用濑章,这个代码:

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

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

将不断调用setRumple,无论是否下降,请考虑使用此代码:

    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);
      }
    }
.

这种方式仅在需要时调用set rumble方法,而不是不断向Wiimote发送输出报告,导致蓝牙总线过载。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top