aboutsummaryrefslogtreecommitdiff
path: root/waffle/raw.py
blob: 851385e15acd0b67e5e74c4054658714846b8f8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Copyright 2024 jack (@waffle87)
# SPDX-License-Identifier: GPL-2.0-or-later
import hid
import sys
import psutil
import math
import time
import datetime

vendor_id = 0x6A73
product_id = 0x6B62
usage_page = 0xFF60
usage = 0x61


def get_raw_hid_interface():
    device_interfaces = hid.enumerate(vendor_id, product_id)
    raw_hid_interfaces = [i for i in device_interfaces if i['usage_page'] == usage_page and i['usage'] == usage]
    if len(raw_hid_interfaces) == 0:
        return None
    interface = hid.Device(path=raw_hid_interfaces[0]['path'])
    return interface


def send_packet(data):
    interface = get_raw_hid_interface()
    if interface is None:
        print("no device found")
        sys.exit(1)
    request_data = [0x00] * 32
    request_data[1:len(data) + 1] = data
    request_packet = bytes(request_data)
    try:
        interface.write(request_packet)
    finally:
        interface.close()


if __name__ == "__main__":
    while True:
        time.sleep(30)
        cpu_temp = psutil.sensors_temperatures()["gigabyte_wmi"][2]
        cur_hour = datetime.datetime.now().strftime("%H")
        cur_minute = datetime.datetime.now().strftime("%M")
        send_packet([
            math.trunc(cpu_temp.current),
            int(cur_hour),
            int(cur_minute)
        ])