public mainForm() { InitializeComponent(); robot = new RobotClass(); ReadConfig(); gridStatus.Rows.Add(10); gridStatus.Rows[0].Cells[0].Value = "NAK"; gridStatus.Rows[0].Cells[0].Style.Alignment = DataGridViewContentAlignment.MiddleCenter; gridStatus.Rows[0].Cells[1].Value = "CRC"; gridStatus.Rows[1].Cells[1].Value = "CONN"; gridStatus.Rows[2].Cells[0].Value = "Volts/Watts"; gridStatus.Rows[3].Cells[0].Value = "Amps/mAh"; gridStatus.Rows[4].Cells[0].Value = "Uptime"; gridStatus.Rows[5].Cells[0].Value = "Drv speed"; gridStatus.Rows[6].Cells[0].Value = "Srv speed"; gridStatus.Rows[7].Cells[0].Value = "Mode"; gridStatus.Rows[8].Cells[0].Value = "X; Y; Z"; gridStatus.Rows[9].Cells[0].Value = "j0 offset"; gridServo.Rows.Add(robot.Servos.Length); try { id = new InputDevice(Handle); id.JoystickEvent += new InputDevice.DeviceEventHandler(JoyEvent); } catch (ApplicationException e) { error(e.Message); } }
private void inputDevice_KeyPressed(object sender, InputDevice.KeyControlEventArgs e) { //TODO: Send the keyboard that the input came from to the controller_changed event instead of the programmer and let the presenter figure it out Programmer controllingProgrammer = Programmer.Neither; if (string.IsNullOrEmpty(keyboardId1)) keyboardId1 = e.Keyboard.deviceHandle.ToString(); else if(string.IsNullOrEmpty(keyboardId2) && e.Keyboard.deviceHandle.ToString() != keyboardId1) keyboardId2 = e.Keyboard.deviceHandle.ToString(); if (e.Keyboard.deviceHandle.ToString() == keyboardId1) controllingProgrammer = programmer1; if (e.Keyboard.deviceHandle.ToString() == keyboardId2) controllingProgrammer = programmer2; if (Controller_Changed != null) Controller_Changed(this, new ControllerChangedEventArgs(controllingProgrammer)); }
private void Form1_Load(object sender, EventArgs e) { inputDevice = new InputDevice(Handle); inputDevice.EnumerateDevices(); handler = new InputDevice.DeviceEventHandler(inputDevice_KeyPressed); IntervalTimer = new Timer(); }
private void JoyEvent(object sender, InputDevice.JoystickEventArgs e) { if (e.Buttons[4]) DriveHelper.IncSpeed(2); if (e.Buttons[6]) DriveHelper.IncSpeed(-2); // motors DriveHelper.Up(e.Up); DriveHelper.Down(e.Down); DriveHelper.Left(e.Left); DriveHelper.Right(e.Right); // mode select if (e.Buttons[2]) SetControlMode(ControlMode.A); if (e.Buttons[1]) SetControlMode(ControlMode.B); if (e.Buttons[3]) SetControlMode(ControlMode.X); if (e.Buttons[0]) SetControlMode(ControlMode.Y); if (chbServoControl.Checked) { if (controlMode == ControlMode.A) { if (e.X1 < STICK_MIN) robot.SetServoMove("j0", -1); else if (e.X1 > STICK_MAX) robot.SetServoMove("j0", 1); else robot.SetServoMove("j0", 0); if (e.Y1 < STICK_MIN) robot.SetServoMove("j1", 1); else if (e.Y1 > STICK_MAX) robot.SetServoMove("j1", -1); else robot.SetServoMove("j1", 0); if (e.Y2 < STICK_MIN) robot.SetServoMove("j2", 1); else if (e.Y2 > STICK_MAX) robot.SetServoMove("j2", -1); else robot.SetServoMove("j2", 0); if (e.Buttons[10]) { robot.ParkServo("j0"); robot.ParkServo("j1"); } if (e.Buttons[11]) { robot.ParkServo("j2"); } } else if (controlMode == ControlMode.B) { if (e.X1 < STICK_MIN) robot.SetServoMove("j3", -1); else if (e.X1 > STICK_MAX) robot.SetServoMove("j3", 1); else robot.SetServoMove("j3", 0); if (e.Y1 < STICK_MIN) robot.SetServoMove("j4", 1); else if (e.Y1 > STICK_MAX) robot.SetServoMove("j4", -1); else robot.SetServoMove("j4", 0); if (e.X2 < STICK_MIN) robot.SetServoMove("j5", -1); else if (e.X2 > STICK_MAX) robot.SetServoMove("j5", 1); else robot.SetServoMove("j5", 0); if (e.Y2 < STICK_MIN) robot.SetServoMove("grip", 1); else if (e.Y2 > STICK_MAX) robot.SetServoMove("grip", -1); else robot.SetServoMove("grip", 0); if (e.Buttons[10]) { robot.ParkServo("j3"); robot.ParkServo("j4"); } if (e.Buttons[11]) { robot.ParkServo("j5"); robot.ParkServo("grip"); } } else if (controlMode == ControlMode.X) { // } // disable the arm if (e.Buttons[8]) robot.EnableAllServos(false); // goto start position if (e.Buttons[9]) robot.ParkAllServos(); } }
void inputDevice_KeyPressed(object sender, InputDevice.KeyControlEventArgs e) { //TODO: How can I clean this up? //TODO: Associate the keyboards from config or admin menu Programmer controllingProgrammer = Programmer.Neither; if (string.IsNullOrEmpty(keyboardId1)) keyboardId1 = e.Keyboard.deviceHandle.ToString(); else if(string.IsNullOrEmpty(keyboardId2) && e.Keyboard.deviceHandle.ToString() != keyboardId1) keyboardId2 = e.Keyboard.deviceHandle.ToString(); if (e.Keyboard.deviceHandle.ToString() == keyboardId1) controllingProgrammer = programmer1; if (e.Keyboard.deviceHandle.ToString() == keyboardId2) controllingProgrammer = programmer2; if (Controller_Changed != null) Controller_Changed(this, new ControllerChangedEventArgs(controllingProgrammer)); }