#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Aug 24 23:56:25 2018

@author: mtkes
"""

import wpilib

from wpilib.command import Command
from wpilib.command import Scheduler

from wpilib.joystick import Joystick
from wpilib.buttons import JoystickButton

from subsystems.driveSubsystem import DriveSubsystem
from commands.moveForward import MoveForward
from commands.moveBackward import MoveBackward
from commands.stop import Stop
from commands.turnRight import TurnRight
from commands.turnLeft import TurnLeft

# Put in OI
PS4AxisStrings = [

	"LEFT_STICK_X",
	"LEFT_STICK_Y",
	"RIGHT_STICK_X",
	"L2_AXIS",
	"R2_AXIS",
	"RIGHT_STICK_Y"
]
PS4AxisEnum = enumerate(PS4AxisStrings)
PS4Axis = {}
for i,e in PS4AxisEnum:
    PS4Axis[e] = i 
	
PS4ButtonStrings = [    

   "Undefined",
	"SQUARE", 
	"CROSS", 
	"CIRCLE", 
	"TRIANGLE", 
	"L1", 
	"R1", 
	"L2", 
	"R2",
	"SHARE", 
	"OPTIONS", 
	"L_STICK", 
	"R_STICK", 
	"PS4", 
	"TRACKPAD"
]
PS4ButtonEnum = enumerate(PS4ButtonStrings)
PS4Button = {}
for i,e in PS4ButtonEnum:
    PS4Button[e] = i

# Do something similar to the above for RobotMap motor IDs and functional
# button mapping
    
class MyRobot(wpilib.IterativeRobot):

    def robotInit(self):
        Command.getRobot = lambda x=0: self
        self.driveSubsystem = DriveSubsystem()
                
        self.controller = Joystick(0)
        
        self.forward  = JoystickButton(self.controller, PS4Button["TRIANGLE"])
        self.backward = JoystickButton(self.controller, PS4Button["CROSS"])
        self.right    = JoystickButton(self.controller, PS4Button["CIRCLE"])
        self.left     = JoystickButton(self.controller, PS4Button["SQUARE"])
                
        self.forward.whenPressed(MoveForward())
        self.forward.whenReleased(Stop())
        
        self.backward.whenPressed(MoveBackward())
        self.backward.whenReleased(Stop())
        
        self.right.whenPressed(TurnRight())
        self.right.whenReleased(Stop())
        
        self.left.whenPressed(TurnLeft())
        self.left.whenReleased(Stop())
        
    def disabled(self):
        '''Called when the robot is disabled'''
        pass
            
    def autonomousInit(self):
        '''Called only at the beginning of autonomous mode'''
        pass

    def autonomousPeriodic(self):
        '''Called every 20ms in autonomous mode'''
        pass

    def disabledInit(self):
        '''Called only at the beginning of disabled mode'''
        pass
    
    def disabledPeriodic(self):
        '''Called every 20ms in disabled mode'''
        pass

    def teleopInit(self):
        '''Called only at the beginning of teleoperated mode'''
        pass

    def teleopPeriodic(self):
        '''Called every 20ms in teleoperated mode'''
        Scheduler.getInstance().run()


if __name__ == '__main__':
    wpilib.run(MyRobot,physics_enabled=True)
@@ -542,29 +542,25 @@
  OI%0A
+%0A
 PS4Axis
-Strings = %5B%0A%0A%09
+ = %7B%09%0A   
 %22LEF
@@ -565,24 +565,29 @@
 EFT_STICK_X%22
+  : 0
 ,%0A%09%22LEFT_STI
@@ -591,16 +591,21 @@
 STICK_Y%22
+  : 1
 ,%0A%09%22RIGH
@@ -614,16 +614,20 @@
 STICK_X%22
+ : 2
 ,%0A%09%22L2_A
@@ -626,24 +626,34 @@
 ,%0A%09%22L2_AXIS%22
+       : 3
 ,%0A%09%22R2_AXIS%22
@@ -652,16 +652,26 @@
 R2_AXIS%22
+       : 4
 ,%0A%09%22RIGH
@@ -684,107 +684,15 @@
 K_Y%22
-%0A%5D%0APS4AxisEnum = enumerate(PS4AxisStrings)%0APS4Axis = %7B%7D%0Afor i,e in PS4AxisEnum:%0A    PS4Axis%5Be%5D = i 
+ : 5%0A%7D%0A
 %0A%09%0AP
@@ -703,19 +703,12 @@
 tton
-Strings
  = 
-%5B
+%7B
     
@@ -723,16 +723,23 @@
 defined%22
+    : 0
 ,%0A%09%22SQUA
@@ -737,24 +737,34 @@
 0,%0A%09%22SQUARE%22
+       : 1
 , %0A%09%22CROSS%22,
@@ -762,16 +762,27 @@
 %09%22CROSS%22
+        : 2
 , %0A%09%22CIR
@@ -785,16 +785,26 @@
 %22CIRCLE%22
+       : 3
 , %0A%09%22TRI
@@ -813,50 +813,125 @@
 GLE%22
-, %0A%09%22L1%22, %0A%09%22R1%22, %0A%09%22L2%22, %0A%09%22R2%22,%0A%09%22SHARE%22
+     : 4, %0A%09%22L1%22           : 5, %0A%09%22R1%22           : 6, %0A%09%22L2%22           : 7, %0A%09%22R2%22           : 8,%0A%09%22SHARE%22        : 9
 , %0A%09
@@ -939,16 +939,26 @@
 OPTIONS%22
+      : 10
 , %0A%09%22L_S
@@ -958,24 +958,34 @@
  %0A%09%22L_STICK%22
+      : 11
 , %0A%09%22R_STICK
@@ -989,139 +989,66 @@
 ICK%22
-, %0A%09%22PS4%22, %0A%09%22TRACKPAD%22%0A%5D%0APS4ButtonEnum = enumerate(PS4ButtonStrings)%0APS4Button = %7B%7D%0Afor i,e in PS4ButtonEnum:%0A    PS4Button%5Be%5D = i
+      : 12, %0A%09%22PS4%22          : 13, %0A%09%22TRACKPAD%22     : 14%0A%7D
 %0A%0A# 
@@ -2073,95 +2073,8 @@
     
-%0A    def disabled(self):%0A        '''Called when the robot is disabled'''%0A        pass%0A 
     

Clean Up Dictionary Use