Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Input;
- using System.IO.Ports;
- namespace poppetGamePad {
- class Program {
- static int Main(string[] args) {
- /*if (args.Length != 2) {
- Console.WriteLine("Invalid Args");
- return 1;
- }*/
- string COM = "COM17";
- int baud = 115200;
- SerialPort sp = new SerialPort(COM, baud);
- sp.Open();
- sp.Write(new byte[] { 7}, 0, 1);
- GamePadState oldState;
- GamePadState currentState = GamePad.GetState(PlayerIndex.One);
- bool running = true;
- while (running) {
- oldState = currentState;
- currentState = GamePad.GetState(PlayerIndex.One);
- if (currentState.Buttons.Back == ButtonState.Pressed) {
- running = false;
- }
- if (currentState != oldState) {
- //do stuff
- if (currentState.Buttons.A == ButtonState.Pressed) {
- //green
- sp.Write(new byte[] { (byte)(((byte)(currentState.Triggers.Right * 31) << 3) + 1) }, 0, 1);
- }
- if (currentState.Buttons.B == ButtonState.Pressed) {
- //red
- sp.Write(new byte[] { (byte)((byte)(currentState.Triggers.Right * 31) << 3) }, 0, 1);
- }
- if (currentState.Buttons.X == ButtonState.Pressed) {
- //blue
- sp.Write(new byte[] { (byte)(((byte)(currentState.Triggers.Right * 31) << 3) + 2) }, 0, 1);
- }
- float X = currentState.ThumbSticks.Left.X;
- float Y = currentState.ThumbSticks.Left.Y;
- float left = Y + X;
- float right = Y - X;
- if (left > 1) {
- left = 1;
- }
- if (left < -1) {
- left = -1;
- }
- if (right > 1) {
- right = 1;
- }
- if (right < -1) {
- right = -1;
- }
- Console.Write(left); Console.Write(" "); Console.WriteLine(right);
- byte leftCommand = 3;
- byte rightCommand = 4;
- if (left < 0) {
- leftCommand = 5;
- left = -left;
- }
- if (right < 0) {
- rightCommand = 6;
- right = -right;
- }
- sp.Write(new byte[] { (byte)(((byte)(left * 31) << 3) + leftCommand) }, 0, 1);
- sp.Write(new byte[] { (byte)(((byte)(right * 31) << 3) + rightCommand) }, 0, 1);
- }
- if (currentState.Buttons.Y == ButtonState.Pressed) {
- //blue
- sp.Write(new byte[] { (byte)(((byte)(currentState.Triggers.Right * 31) << 3) + 7) }, 0, 1);
- }
- }
- sp.Close();
- return 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement