#ifndef __PCA9685
#define __PCA9685

/*
 * PCA9685 library for ESP8266
 * Copyright 2017 (c) Mark van Renswoude
*/
#include <stdint.h>


class PCA9685
{
  private:
    uint8_t mAddress;

  protected:
    uint8_t read(uint8_t registerAddress);
    void write(uint8_t registerAddress, uint8_t value);
    inline void write(uint8_t data);

  public:
    static const uint16_t Off = 0;
    static const uint16_t On = 4095;

    static const uint8_t RegisterMode1 = 0x0;
    static const uint8_t RegisterPrescale = 0xFE;

    static const uint8_t RegisterLED0OnL = 0x6;
    static const uint8_t RegisterAllLEDOnL = 0xFA;

    static const uint8_t Mode1Restart = 0x80;
    static const uint8_t Mode1AI = 0x20;
    static const uint8_t Mode1Sleep = 0x10;
    static const uint8_t Mode1AllCall = 0x01;

    // Call this to initializes the I2C library
    void setAddress(uint8_t address, uint8_t pinSDA, uint8_t pinSCL);

    // Call this if you already initialized the I2C library
    void setAddress(uint8_t address);

    void setPWMFrequency(float frequency);

    void setPWM(uint8_t pin, uint16_t value);
    void setPWM(uint8_t pin, uint16_t on, uint16_t off);

    void setAll(uint16_t value);
    void setAll(uint16_t on, uint16_t off);
};

#endif