Tests with configs

This commit is contained in:
Marc Riera Irigoyen 2022-10-12 23:48:00 +02:00
parent 25ba4cdbc0
commit 8c875d3b8d
5 changed files with 48 additions and 27 deletions

View file

@ -1,13 +1,27 @@
import json
class ConfigHandler:
def __init__(self):
def __init__(self, path):
super().__init__()
def load():
return
self._path = path
self._config = []
self.load()
def save():
return
def load(self):
try:
with open(self._path, 'r') as f:
self._config = json.load(f)
except Exception:
pass
def update():
return
def save(self):
with open(self._path, 'w') as f:
json.dump(self._config, f, indent = 4)
def get_config(self, hash):
return None
def set_config(self, hash, data):
return

View file

@ -1,5 +1,6 @@
from enum import Enum
from evdev import InputDevice, list_devices, ecodes as e, UInput, AbsInfo
from hashlib import sha1
class GamepadHandler:
def __init__(self):
@ -24,11 +25,23 @@ class Gamepad:
self.vid = vid
self.pid = pid
self.name = name
self.type = self.get_gamepad_type(vid, pid)
self.config = None
self.id = self._get_gamepad_id()
self.hash = self._get_gamepad_hash()
self.type = self._get_gamepad_type()
self.config = []
def get_gamepad_type(self, vid, pid):
match vid, pid:
def _get_gamepad_id(self):
vid = format(self.vid, "x").zfill(4)
pid = format(self.pid, "x").zfill(4)
id = str(vid + ":" + pid)
return id
def _get_gamepad_hash(self):
hash = sha1(str(self.id + ":" + self.name).encode('utf-8')).hexdigest()
return hash
def _get_gamepad_type(self):
match self.vid, self.pid:
case 0x0f0d, 0x00c1:
return self.GamepadType.NSWITCH
return self.GamepadType.UNKNOWN