sysinfo.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. ###
  2. # M4cs Keymap for dekuNukem/duckyPad QMK firmware
  3. # Copyright (C) 2020 Max Bridgland
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. ###
  15. import hid
  16. import time
  17. import string
  18. import psutil
  19. import GPUtil
  20. import datetime
  21. vendor_id = 0x444E
  22. product_id = 0x4450
  23. usage_page = 0xFF60
  24. usage = 0x61
  25. device_interfaces = hid.enumerate(vendor_id, product_id)
  26. raw_hid_interfaces = [i for i in device_interfaces if i['usage_page'] == usage_page and i['usage'] == usage]
  27. if len(raw_hid_interfaces) == 0:
  28. print('Couldnt find any interfaces')
  29. exit()
  30. interface = hid.device()
  31. interface.open_path(raw_hid_interfaces[0]['path'])
  32. print("Manufacturer: %s" % interface.get_manufacturer_string())
  33. print("Product: %s" % interface.get_product_string())
  34. time.sleep(0.05)
  35. while True:
  36. time.sleep(0.75)
  37. cpufreq = psutil.cpu_freq()
  38. currFreq = int(cpufreq.current)
  39. svmem = psutil.virtual_memory()
  40. memPerc = int(svmem.percent * 10)
  41. gpus = GPUtil.getGPUs()
  42. gpu = gpus[0]
  43. load = int(gpu.load*100)
  44. temp = int(gpu.temperature)
  45. data = [0]
  46. for x in str(currFreq):
  47. data.append(int(x))
  48. data.append(13)
  49. for x in str(memPerc):
  50. data.append(int(x))
  51. data.append(13)
  52. for x in str(load):
  53. data.append(int(x))
  54. data.append(13)
  55. for x in str(temp):
  56. data.append(int(x))
  57. data.append(13)
  58. now_hour = datetime.datetime.now().strftime("%I")
  59. now_min = datetime.datetime.now().strftime("%M")
  60. data.append(int(now_hour[0]))
  61. data.append(int(now_hour[1]))
  62. data.append(13)
  63. data.append(int(now_min[0]))
  64. data.append(int(now_min[1]))
  65. data.append(13)
  66. interface.write(data)