#!/usr/bin/python3
import os, time, sys

FAN1 = (0x67, 0x68)
FAN2 = (0x6B, 0x6C)
TEMP_ADDR = 0x65

def read_reg(add):
    cmd = "./ecx86_64 -a %s -r" % hex(add)
    f = os.popen(cmd)
    return int(f.read(), 16)


def main():
    while True:
        f1_h = read_reg(FAN1[0])
        f1_l = read_reg(FAN1[1])
        f1_speed = ((f1_h & 0xFF) << 8) | (f1_l & 0xFF)

        f2_h = read_reg(FAN2[0])
        f2_l = read_reg(FAN2[1])
        f2_speed = ((f2_h & 0xFF) << 8) | (f2_l & 0xFF)
        
        temp = read_reg(TEMP_ADDR)
        
        sys.stdout.write("\r")
        sys.stdout.write("temp: %s fan1 rpm: %s \t fan2 rpm: %s           " % (temp, f1_speed, f2_speed))
        sys.stdout.flush()
        time.sleep(1)


if __name__ == '__main__':
    os.system("chmod +x ./ecx86_64")
    main()
