import sys 

DEFAULT_F_PWM_SS = 50
DEFAULT_F_GCLK_TCC = 8000000
DEFAULT_TCC_PRESCALER = 64

def get_top(f_pwm_ss = DEFAULT_F_PWM_SS, f_gclk_tcc = DEFAULT_F_GCLK_TCC, 
        N = DEFAULT_TCC_PRESCALER):
    print("TOP: %f\n" % ((float(f_gclk_tcc) / (float(N) * float(f_pwm_ss))) - float(1.0)));

def get_match_from_pw(TOP, Pw, f_pwm_ss = DEFAULT_F_PWM_SS):
    print("Match Value for %f: %d\n" %(Pw, (Pw * TOP * f_pwm_ss)));

if __name__ == '__main__':
    print("Number of args: %d\n" % int(len(sys.argv)))
    if len(sys.argv) >= 2:
        if len(sys.argv) == 2:
            globals()[sys.argv[1]]()
        elif len(sys.argv) == 3:
            globals()[sys.argv[1]](float(sys.argv[2]))
        elif len(sys.argv) == 4:
            globals()[sys.argv[1]](float(sys.argv[2]), float(sys.argv[3]))
        elif len(sys.argv) == 5:
            globals()[sys.argv[1]](float(sys.argv[2]), float(sys.argv[3]), float(sys.argv[4]))
        else:
            print("Invalid number of arguments\n");
            quit()
    else:
        print("Please pick an operation:\n");
        print('get_top')
        print('get_match_from_pw')
        quit()
