# Original PS4 controller class copyright
# © 2015 Clay L. McLeod <clay.l.mcleod@gmail.com>, MIT license.
# (Modifications by Tommy York)

import pygame

class PS4Controller(object):
    """Class representing the PS4 controller. Pretty straightforward functionality."""

    controller = None
    axis_data = None
    button_data = None
    hat_data = None

    def init(self):
        print('PS4Controller init')
        """Initialize the joystick components"""

        pygame.init()
        pygame.joystick.init()
        self.controller = pygame.joystick.Joystick(0)
        self.controller.init()

        if not self.axis_data:
            self.axis_data = {}
            for i in range(self.controller.get_numaxes()):
                self.axis_data[i] = 0

        if not self.button_data:
            self.button_data = {}
            for i in range(self.controller.get_numbuttons()):
                self.button_data[i] = False

        if not self.hat_data:
            self.hat_data = {}
            for i in range(self.controller.get_numhats()):
                self.hat_data[i] = (0, 0)

