private void ReadJoystick() { DateTime now = DateTime.Now; Joystick.Position pos = _joystick.GetJoystickPosition(); // note: X/Y values munged to account for physical joystick orientation // TODO: pull this configuration out for subclassing int x = scaleJoystickValue(pos.X); int y = scaleJoystickValue(pos.Y); Position position = GetPosition(x, y); if (position == _position) { long ticks = now.Ticks - _joystickHoldTicks; long millis = ticks / TimeSpan.TicksPerMillisecond; if (millis >= _joystickHoldTimeMillis) { _joystickHoldTicks = now.Ticks; JoystickMotion.Invoke(position, _position); } } else { _position = position; _joystickHoldTicks = now.Ticks; } }
void jt_Tick(GT.Timer timer) { Joystick.Position position = joystick.GetPosition(); if (didJoystickMove(position)) { if (position.Y > .9) { upEventFired(); } else if (position.Y < -.9) { downEventFired(); } else if (position.X > .9) { rightEventFired(); } else if (position.X < -.9) { leftEventFired(); } lastJoystickPosition = position; } }
private void joystickTimer_Tick(GT.Timer timer) { const double X_DEADZONE = 0.25; const double Y_DEADZONE = 0.25; // If Misilelauncher is initializated, handle joystick position if (launcherPod != null){ joystickPosition = joystick.GetPosition(); if (joystickPosition.X > X_DEADZONE) { launcherPod.MisileDO(MisileLauncher.MisileCommand.RIGHT); } else if (joystickPosition.X < -X_DEADZONE) { launcherPod.MisileDO(MisileLauncher.MisileCommand.LEFT); } if (joystickPosition.Y > Y_DEADZONE) { launcherPod.MisileDO(MisileLauncher.MisileCommand.UP); } else if (joystickPosition.Y < -Y_DEADZONE) { launcherPod.MisileDO(MisileLauncher.MisileCommand.DOWN); } launcherPod.MisileDO(MisileLauncher.MisileCommand.STOP); } }
/*Timer_Tick function for joystick*/ private void Timer_Tick(GT.Timer timer) { Joystick.Position pos = joystick.GetPosition(); if (pos.X > 0.50) { Joystick_Up(); } else if (pos.X < -0.50) { Joystick_Down(); } }
/// <summary> /// constructor - set up the input /// </summary> /// <param name="x"> x coordinate where to draw the input mask</param> /// <param name="y">y coordinate where to draw the input mask</param> /// <param name="radius"> how big the input mask should be</param> /// <param name="display"> display module</param> /// <param name="joystick"> joystick module</param> /// <param name="finishedHandler"> event handler which indicates if an input was finished</param> public ColorCodeInput(int x, int y, int radius, Gadgeteer.Modules.Module.DisplayModule display, Gadgeteer.Modules.GHIElectronics.Joystick joystick, EventHandler finishedHandler) { this.pos_x = x; this.pos_y = y; this.radius = radius; this.display = display; this.joystick = joystick; this.pos_code = 0; this.finishedHandler = finishedHandler; this.code = new ColorCode(); this.view = new ColorCodeView(pos_x,pos_y,radius,display,code); this.pos_joystick = new Joystick.Position(); }
void timer_Tick(Gadgeteer.Timer timer) { double realX = 0, realY = 0; Joystick.Position newJoystickPosition = joystick.GetPosition(); double newX = joystickPosition.X; // - .5 + currentPosition.X - currentPosition.X; double newY = joystickPosition.Y; // -.5 + currentPosition.Y - currentPosition.Y; joystickPosition = newJoystickPosition; // did we actually move... if (System.Math.Abs(newX) >= 0.03) { realX = newX; //display.SimpleGraphics.Clear(); } if (System.Math.Abs(newY) >= 0.03) { realY = newY; //display.SimpleGraphics.Clear(); } if (realX == 0.0 && realY == 0.0) { return; } if (realX + currentPosition.X >= displayWidth) { currentPosition.X = 0; } if (realX + currentPosition.X <= 0) { currentPosition.X = displayWidth; } if (realY + currentPosition.Y >= displayHeight) { currentPosition.Y = 0; } if (realY + currentPosition.Y <= 0) { currentPosition.Y = displayHeight; } Debug.Print(realX + " " + realY); currentPosition.X += realX * 5; //for increasing cursor speed currentPosition.Y += realY * 5; //for increasing cursoe speed DrawCursor(); }
// ----------------------- End Network & Connections ----------------------- // private void joystick_function(GT.Timer timer) { if (setupComplete) { return; } double realX = 0, realY = 0; Joystick.Position newJoystickPosition = joystick.GetPosition(); double newX = joystickPosition.X; double newY = joystickPosition.Y; joystickPosition = newJoystickPosition; // did we actually move... if (System.Math.Abs(newX) >= 0.05) { realX = newX; } if (System.Math.Abs(newY) >= 0.05) { realY = newY; } if (realX == 0.0 && realY == 0.0) { return; } if (System.Math.Abs(newX) >= System.Math.Abs(newY)) { if (current_orizzontal_pos + realX / 80 <= 0.1 && current_orizzontal_pos + realX / 80 >= 0.05) { orizzontal_mov.Set(50, current_orizzontal_pos + realX / 80); current_orizzontal_pos = current_orizzontal_pos + realX / 80; } } else { if (current_vertical_pos + realY / 80 <= 0.1 && current_vertical_pos + realY / 80 >= 0.05) { vertical_mov.Set(50, current_vertical_pos + realY / 80); current_vertical_pos = current_vertical_pos + realY / 80; } } }
void JoystickRead() { Double LastX = 0.5; Double LastY = 0.5; while (true) { joystickPosition = joystick.GetJoystickPosition(); Double X = joystickPosition.X; Double Y = joystickPosition.Y; if (X != LastX | Y != LastY) { Debug.Print("Joystickposition - X: " + X + " Y: " + Y); DisplayJoystickPosition(X, Y); } LastX = X; LastY = Y; Thread.Sleep(250); } }
//Code to handle joystick movements #region JoyStickHelpers private bool didJoystickMove(Joystick.Position position) { double realX = 0, realY = 0; Joystick.Position newJoystickPosition = position; double newX = newJoystickPosition.X - lastJoystickPosition.X; double newY = newJoystickPosition.Y - lastJoystickPosition.Y; // did we actually move... if (System.Math.Abs(newX) >= 0.5) { realX = newX; } if (System.Math.Abs(newY) >= 0.5) { realY = newY; } if (realX == 0.0 && realY == 0.5) { return(false); } Debug.Print("Real x :: " + realX + " Real Y :: " + realY); return(true); }
void timer_Tick(GT.Timer timer) { Debug.Print("light :" + lightSense.GetIlluminance()); Debug.Print("posisi :" + joystick.GetPosition().X + "," + joystick.GetPosition().Y); Joystick.Position pos = joystick.GetPosition(); double illuminance = lightSense.GetIlluminance(); if (pos.X < -0.5 && System.Math.Abs(pos.Y) < 0.2) { //kiri led7R.TurnLedOn(0); } else if (pos.X > 0.5 && System.Math.Abs(pos.Y) < 0.2) { //kanan led7R.TurnLedOn(3); } else if (pos.Y < -0.5 && System.Math.Abs(pos.X) < 0.2) { //atas led7R.TurnLedOn(4); led7R.TurnLedOn(5); } else if (pos.Y > 0.5 && System.Math.Abs(pos.X) < 0.2) { //bawah led7R.TurnLedOn(1); led7R.TurnLedOn(2); } else { double Cahaya = lightSense.ReadProportion(); int rotasi = 50 + (int)(200 * Cahaya); led7R.Animate(rotasi, true, true, false); } }
public void Update(long elapsedTime) { _position = _joystick.GetJoystickPosition(); }
// This method is run when the mainboard is powered up or reset. void ProgramStarted() { /******************************************************************************************* Modules added in the Program.gadgeteer designer view are used by typing their name followed by a period, e.g. button. or camera. Many modules generate useful events. Type +=<tab><tab> to add a handler to an event, e.g.: button.ButtonPressed +=<tab><tab> If you want to do something periodically, use a GT.Timer and handle its Tick event, e.g.: GT.Timer timer = new GT.Timer(1000); // every second (1000ms) timer.Tick +=<tab><tab> timer.Start(); *******************************************************************************************/ // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging. multicolorLed.TurnRed(); // Subscribe to USBH events. USBHostController.DeviceConnectedEvent += DeviceConnectedEvent; USBHostController.DeviceDisconnectedEvent += DeviceDisconnectedEvent; // Get Joystick Position joystickPosition = joystick.GetPosition(); GT.Timer joystickTimer = new GT.Timer(50); joystickTimer.Tick += joystickTimer_Tick; joystickTimer.Start(); // Subscribe to Joystick events. joystick.JoystickPressed += new Joystick.JoystickEventHandler(joystick_JoystickPressed); Debug.Print("Program Started"); }
private void ListenJoystick() { Joystick.Position myPosition = MainHandle.Joystick.GetPosition(); this.JoystickPosition(myPosition.X, myPosition.Y); }
void ProgramStarted() { Debug.Print("Program Started"); joystick.JoystickPressed += new Joystick.JoystickEventHandler(joystick_JoystickPressed); joystick.JoystickReleased += new Joystick.JoystickEventHandler(joystick_JoystickReleased); joystickPosition = joystick.GetJoystickPosition(); Thread joystickReadThread = new Thread(JoystickRead); joystickReadThread.Start(); }
/// <summary> /// every tick of the timer this method will be executed and prints the actual input of the code and /// an indicator line where the actual position of the joystick is. /// </summary> /// <param name="timer"></param> private void show_on_display(GT.Timer timer) { direction direction_v; //pos_code indicator for (int i = 0; i < 4; i++) { if (i == pos_code) { display.SimpleGraphics.DisplayLine(GT.Color.White, 2, pos_x + i* (2 * radius + 3) - radius, pos_y + radius + 4, pos_x + i * (2 * radius + 3) + radius, pos_y + radius + 4); } else { display.SimpleGraphics.DisplayLine(GT.Color.Black, 2, pos_x + i * (2 * radius + 3) - radius, pos_y + radius + 4, pos_x + i * (2 * radius + 3) + radius, pos_y + radius + 4); } } view.drawColorCode(); pos_joystick = joystick.GetPosition(); direction_v = getDirectionJoystick(pos_joystick); // Debug.Print("direction_v = " + direction_v); if (direction_v == direction.UP || direction_v == direction.DOWN) changeColor(direction_v, code, pos_code); if (direction_v == direction.LEFT) { if (pos_code > 0) pos_code--; } if (direction_v == direction.RIGHT) { if (pos_code < 3) pos_code++; } }