"""
This python file runs separate from
the rest of the BoardFramework. It simply makes
use of the iiccomm in order to execute an enable
command for the VCC_RAM and a disable command.

| author     = "Seth Miers"
| copyright  = "Copyright, Xilinx Inc. All rights reserved."
| credits    = ["Seth Miers"]
| license    = "GPL"
| version    = "3.0"
| maintainer = "Seth Miers"
| email      = "sethm@xilinx.com"
| status     = "Development"


"""

##########################################
#               Imports                  #
##########################################

# --------------Packages---------------- #
import argparse   # Used to parse args
from time import sleep  # used for delays

# --------------Auxiliary--------------- #
import os
import sys

sys.path[0] = (os.path.dirname(sys.path[0]))
print(sys.path[0])

# --------------Local------------------- #
# pylint: disable=wrong-import-position, import-error
import iiccomm  # noqa: E402

##########################################
#          GLOBAL VARIABLES              #
##########################################

# this variable is used for the main IIC
IIC_COMM = iiccomm.IicComm(1)

##########################################
#              Main Code                 #
##########################################


def vcc_ram_enable():
    '''
    enables the vcc_ram on the VCK190.

    The equivalant SerialToIICBridge commands are:

    IW4\\r74\\r01\\r\\t IW4\\r47\\r0003\\r\\t
    IW4\\r47\\r0180\\r\\t IW4\\r74\\r00\\r\\t

    '''

    IIC_COMM.iic_send(0x74, [0x01])  # Set the mux to 01
    IIC_COMM.iic_send(0x47, [0x00, 0x03])  # Set the page for the IRPS5401

    IIC_COMM.iic_send(0x47, [0x01, 0x80])  # Enables the vout

    IIC_COMM.iic_send(0x74, [0x00])  # reset the mux


def vcc_ram_disable():
    '''
    disables the vcc_ram on the VCK190.

    The equivalant SerialToIICBridge commands are:

    IW4\\r74\\r01\\r\\t IW4\\r47\\r0003\\r\\t
    IW4\\r47\\r0100\\r\\t IW4\\r74\\r00\\r\\t

    '''

    IIC_COMM.iic_send(0x74, [0x01])  # Set the mux to 01
    IIC_COMM.iic_send(0x47, [0x00, 0x03])  # Set the page for the IRPS5401

    IIC_COMM.iic_send(0x47, [0x01, 0x00])  # Disables the vout

    IIC_COMM.iic_send(0x74, [0x00])  # reset the mux


if __name__ == "__main__":
    # pylint: disable=pointless-string-statement
    '''
    Create a parser to pull out the arguments that were used to
    start the program
    '''
    PARSER = argparse.ArgumentParser(description='Run the BoardFramework.')
    PARSER.add_argument('-e', '--enable', action='store_true',
                        help='When this is set, the vcc_ram is enabled')
    PARSER.add_argument('-d', '--disable', action='store_true',
                        help='When this is set, the vcc_ram is disabled \
                              the disable command takes priority if both \
                              are set.')
    ARGS = vars(PARSER.parse_args())

    '''
    Determine what to do based on those arguments.
    '''
    print(ARGS)
    if ARGS.get('disable'):
        vcc_ram_disable()
    elif ARGS.get('enable'):
        vcc_ram_enable()
