
/*
  EasyJoystick - Arduino library for analog joystick modules

  Provides simple directional input (up, down, left, right, center)
  from 2-axis analog joysticks such as the KY-023.

  Author: Seth Kinzel
  License: MIT
  Repository: https://github.com/SethKinzel/EasyJoystick
*/


#ifndef EasyJoystick_h
#define EasyJoystick_h
#include <Arduino.h>

class EasyJoystick {
  private:
  const int16_t centerThreshold = 150; // how big the middle normal zone is
  const int16_t debounceMiddle = 25; // how far away from the middle normal zone to draw lines for big zones
  const int16_t debounceEdge = 15; // how far away from the diagonal lines seperating up, right, down, and left to draw lines for big zones
  int8_t xPin;
  int8_t yPin;
  bool flipX;
  bool flipY;
  int8_t currentState = NONE;
  int8_t previousState = NONE;

  public:
  // these constants can be used in your main code
  typedef enum
  {
    NONE,
    MIDDLE,
    UP,
    DOWN,
    LEFT,
    RIGHT
  } directionType;

  // main functions
  void begin(int8_t, int8_t, bool, bool);
  void loop();
  int8_t getState();
  bool changed();
  bool isMiddle();
  bool isUp();
  bool isDown();
  bool isLeft();
  bool isRight();
  bool isUDLR();
  bool newMiddle();
  bool newUp();
  bool newDown();
  bool newLeft();
  bool newRight();
  bool newUDLR();
};

#endif
