Exemplo n.º 1
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            Label[] labels = { labelBtn1,  labelBtn2, labelBtn3,  labelBtn4,  labelBtn5,  labelBtn6,  labelBtn7,
                               labelBtn8,  labelBtn9, labelBtn10, labelBtn11, labelBtn12, labelBtn13, labelBtn14,
                               labelBtn15, labelBtn16 };

            Joystick_WMM.JOYINFOEX info = Joystick_WMM.getJoyPosEx((uint)0);

            uint mask = 1;

            for (int i = 0; i < 16; i++)
            {
                if ((info.dwButtons & mask) != 0)
                {
                    labels[i].ForeColor = Color.Red;
                }
                else
                {
                    labels[i].ForeColor = DefaultForeColor;
                }

                mask <<= 1;
            }
        }
Exemplo n.º 2
0
        void tareaJOY()
        {
            if (changed_mask)
            {
                changed_mask = false;
                wfly.SetMask(_mask);
            }
            Joystick_WMM.JOYINFOEX joyinfo = Joystick_WMM.getJoyPosEx((uint)0);

            // Analiza si se ha pulsado algun boton nuevo
            int bmask = 1;

            for (int i = 0; i < 16; i++)
            {
                if ((joyinfo.dwButtons & bmask) == 0)
                {
                    old_buttons &= ~bmask;
                }
                else if ((old_buttons & bmask) == 0)
                {
                    old_buttons |= bmask;
                    Singleton.EventosJoy evento = (Singleton.EventosJoy)((int)singleton.joy_buttons[i]);
                    ProcesarEventoJoy(evento);
                }
                bmask <<= 1;
            }

            // Analiza el modem uplink
            if (changed_switches)
            {
                changed_switches = false;
                SetSwitches(modem_ruta, modem_autopilot, (byte)modem_hud, modem_cam);
            }
            if (changed_alt)
            {
                changed_alt = false;
                SetAltitude((int)modem_alt);
            }
            if (changed_lonlat)
            {
                changed_lonlat = false;
                SetLonLat(modem_lon, modem_lat);
            }

            // Comandos varios
            if (changed_debugvar)
            {
                changed_debugvar = false;
                SetDebugVar(debugvar_id, debugvar_value);
            }
            else if (changed_wptid)
            {
                changed_wptid = false;
                SetWptID(_wpt_id);
            }
            else if (trig_cmdCenterIR)
            {
                trig_cmdCenterIR = false;
                SetCenterIR();
            }
            else if (trig_cmdGainIR)
            {
                trig_cmdGainIR = false;
                SetGainIR();
            }
            else if (trig_cmdSetHome)
            {
                trig_cmdSetHome = false;
                SetHome();
            }
            else if (trig_cmdSaveFlash)
            {
                trig_cmdSaveFlash = false;
                SaveFlash();
            }


            // Analiza movimiento PAN & TILT
            int v = ((short)joyinfo.dwPOV);

            if (v >= 0)
            {
                float alfa   = (float)(v / 100 * Math.PI / 180.0);
                float mi_pan = pan + (float)(Math.Sin(alfa) * singleton.pantilt_speed / 10.0); // dt=10hz
                if (mi_pan > 1)
                {
                    pan = 1;
                }
                else if (mi_pan < -1)
                {
                    pan = -1;
                }
                else
                {
                    pan = mi_pan;
                }
                float mi_tilt = tilt + (float)(Math.Cos(alfa) * singleton.pantilt_speed / 10.0);
                if (mi_tilt > 1)
                {
                    tilt = 1;
                }
                else if (mi_tilt < -1)
                {
                    tilt = -1;
                }
                else
                {
                    tilt = mi_tilt;
                }
            }

            // Analiza Ejes del joystick
            float _pitch = AdjustaValor(2 * (joyinfo.dwYpos / 65535.0f) - 1, TrimEle);
            float _roll  = AdjustaValor(2 * (joyinfo.dwXpos / 65535.0f) - 1, TrimAil);
            float _yaw   = AdjustaValor(2 * (joyinfo.dwRpos / 65535.0f) - 1, TrimTail);
            float _thr   = 1 - 2 * (joyinfo.dwZpos / 65535.0f);

            SetControles(_roll, _pitch, _thr, _yaw, pan, tilt, flaps);
            //wfly.SetServos(pan, _pitch, _thr, tilt);

            //           System.Console.WriteLine("PITCH " + _pitch + " ROLL " + _roll + " THR " + _thr + " TAIL " + _yaw);
            // System.Console.WriteLine("Auto " + modem_autopilot + " HUD " + modem_hud +
            //     " RUTA " + modem_rutacasa + " CAM " + modem_cam + " PAN " + pan + " TILT " + tilt);
        }