예제 #1
0
    // Update is called once per frame
    void Update()
    {
        // Ensure device is ready
        if (!initialized && !StartAnalog())
        {
            return;
        }

        // Check for new reports and process
        if (VRPNAnalogNumReports(AnalogName.ToString()) > 0)
        {
            // Get Reports
            int num = MaxReports;
            VRPNAnalogReports(AnalogName.ToString(), reportsPtr, ref num, LastReport, purgeReports);
            AnalogReport[] reports = new AnalogReport[num];

            // Process Reports
            int    i;
            string reportString = AnalogName.ToString();
            string messageString;
            for (i = 0; i < num; i++)
            {
                reports[i] = (AnalogReport)Marshal.PtrToStructure(reportsPtr[i], typeof(AnalogReport));
                if (i == num - 1)
                {
                    //Trigger analog sensor event in event manager
                    //Only the last one is send, one for frame
                    VRPNEventManager.TriggerEventAnalog(AnalogType.ToString(), AnalogName.ToString(), reports[i]);
                }
                messageString = "<";
                for (int j = 0; j < reports[i].num_channel; j++)
                {
                    messageString += " " + reports[i].channel[j] + ",";
                }
                messageString += ">" + " @ " + reports[i].msg_time.tv_sec + "." + reports[i].msg_time.tv_usec;
                if (ShowDebug)
                {
                    reportString += "/n" + messageString;
                }
            }

            if (ShowDebug)
            {
                debug_text = reportString;
            }

            // Only need time value of most recent report
            if (num > 0 && useLastReportTime)
            {
                LastReport.tv_sec  = reports[num - 1].msg_time.tv_sec;
                LastReport.tv_usec = reports[num - 1].msg_time.tv_usec;
            }
        }
    }
예제 #2
0
    // Functions

    void Start()
    {
        //allocate unmanaged memory for analog reports
        reportsPtr = new IntPtr[MaxReports];
        AnalogReport report = new AnalogReport();

        report.num_channel = MAX_ANALOG_CHANNELS;
        report.channel     = new double[MAX_ANALOG_CHANNELS];
        for (int i = 0; i < MaxReports; i++)
        {
            reportsPtr[i] = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(AnalogReport)));
            Marshal.StructureToPtr(report, reportsPtr[i], true);
        }

        // Setup last report time memory
        LastReport = new VRPNManager.TimeVal();
    }
예제 #3
0
    // Update is called once per frame
    void Update()
    {
        // Ensure device is ready
        if (!initialized && !StartAnalog()) return;

        // Check for new reports and process
        if (VRPNAnalogNumReports(AnalogName.ToString()) > 0)
        {
            // Get Reports
            int num = MaxReports;
            VRPNAnalogReports(AnalogName.ToString(), reportsPtr, ref num, LastReport, purgeReports);
            AnalogReport[] reports = new AnalogReport[num];

            // Process Reports
            int i;
            string reportString = AnalogName.ToString();
            string messageString;
            for (i = 0; i < num; i++)
            {
                reports[i] = (AnalogReport)Marshal.PtrToStructure(reportsPtr[i], typeof(AnalogReport));
                if (i == num - 1)
                {
                    //Trigger analog sensor event in event manager
                    //Only the last one is send, one for frame
                    VRPNEventManager.TriggerEventAnalog(AnalogType.ToString(), AnalogName.ToString(), reports[i]);
                }
                messageString = "<";
                for (int j = 0; j < reports[i].num_channel; j++)
                {
                    messageString += " " + reports[i].channel[j] + ",";
                }
                messageString += ">" + " @ " + reports[i].msg_time.tv_sec + "." + reports[i].msg_time.tv_usec;
                if (ShowDebug) reportString += "/n" + messageString;
            }

            if (ShowDebug)debug_text = reportString;

            // Only need time value of most recent report
            if(num>0 && useLastReportTime)
            {
                LastReport.tv_sec = reports[num-1].msg_time.tv_sec;
                LastReport.tv_usec = reports[num-1].msg_time.tv_usec;
            }

        }
    }
예제 #4
0
    // Functions
    void Start()
    {
        //allocate unmanaged memory for analog reports
        reportsPtr = new IntPtr[MaxReports];
        AnalogReport report = new AnalogReport();
        report.num_channel = MAX_ANALOG_CHANNELS;
        report.channel = new double[MAX_ANALOG_CHANNELS];
        for(int i=0; i<MaxReports ; i++)
        {
            reportsPtr[i] = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(AnalogReport)));
            Marshal.StructureToPtr(report, reportsPtr[i], true);
        }

        // Setup last report time memory
        LastReport = new VRPNManager.TimeVal();
    }
예제 #5
0
 protected void InterfaceCallback(IntPtr userdata, ref TimeValue timestamp, ref AnalogReport report)
 {
     OnStateChanged(timestamp, report.sensor, report.state);
 }
예제 #6
0
 static void myAnalogCallback(IntPtr userdata, ref TimeValue timestamp, ref AnalogReport report)
 {
     Console.WriteLine("Got report: channel is {0}", report.state);
 }