raghulkrishna / deepcool-ak620-digital-linux

MIT License
29 stars 13 forks source link

Fahrenheit display, alarm control and much more for AK series #9

Open Tasshack opened 5 months ago

Tasshack commented 5 months ago

I have decoded some missing parts of the protocol using a USB monitoring sofware on a Windows machine.

Here are some information that i found;

This is the sample code that contains all of the information mentioned above. I hope this helps.

import time
import hid
import psutil
import math

PRODUCT_ID = 0x0001  # AK400
SENSOR = "coretemp"

FAHRENHEIT = True
ALARM_TEMP = 75 # set to 0 to disable
INTERVAL = 0.5

try:
    data = [16, 170] + [0 for i in range(62)]
    h = hid.device()
    h.open(0x3633, PRODUCT_ID)
    h.set_nonblocking(1)
    h.write(data)
    data[1] = 35 if FAHRENHEIT else 19
    while True:
        temperature = psutil.sensors_temperatures()[SENSOR][0].current
        if FAHRENHEIT:
            temperature = (temperature * 1.8) + 32
        temperature = round(max(min(temperature, 999), -99))
        data[2] = math.ceil(psutil.cpu_percent() / 10.0)
        data[6] = ALARM_TEMP > 0 and temperature >= ALARM_TEMP
        value = str(temperature)
        if temperature < -9:
            data[3] = 180
            data[4] = int(value[1])
            data[5] = int(value[2])
        elif temperature < 0:
            data[3] = 0
            data[4] = 180
            data[5] = int(value[1])
        elif temperature < 10:
            data[3] = 0
            data[4] = 0
            data[5] = int(value[0])
        elif temperature < 100:
            data[3] = 0
            data[4] = int(value[0])
            data[5] = int(value[1])
        else:
            data[3] = int(value[0])
            data[4] = int(value[1])
            data[5] = int(value[2])
        h.set_nonblocking(1)
        h.write(data)
        time.sleep(INTERVAL)
except IOError as error:
    print(error)
except KeyboardInterrupt:
    pass
finally:
    if "h" in locals():
        h.close()
raghulkrishna commented 5 months ago

Thanks for the info. i will test this out this weekend