-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Matt White
committed
Jul 17, 2022
1 parent
7ac33fd
commit b547c47
Showing
8 changed files
with
468 additions
and
234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"listener_type": "sphinx", | ||
"speaker_type": "google", | ||
"left_eye": { | ||
"neutral_x": 129.9125660837739, | ||
"neutral_y": 100.04676697844651 | ||
}, | ||
"right_eye": { | ||
"neutral_x": 80.42903619357463, | ||
"neutral_y": 129.9125660837739 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,56 @@ | ||
from dataclasses import dataclass, field | ||
from dataclasses import field | ||
from pydantic.dataclasses import dataclass | ||
from pydantic import BaseModel | ||
|
||
import board | ||
import yaml | ||
|
||
|
||
@dataclass | ||
class Pins: | ||
dotstar_clock: int = board.D6 | ||
dotstar_data: int = board.D5 | ||
button: int = board.D17 | ||
joydown: int = board.D27 | ||
joyleft: int = board.D22 | ||
joyup: int = board.D23 | ||
joyright: int = board.D24 | ||
joyselect: int = board.D16 | ||
|
||
@dataclass | ||
class Config: | ||
import json | ||
from typing import Optional | ||
from loguru import logger | ||
|
||
Pin = board.pin.Pin | ||
|
||
class Pins(BaseModel): | ||
dotstar_clock: Pin = board.D6 | ||
dotstar_data: Pin = board.D5 | ||
button: Pin = board.D17 | ||
joydown: Pin = board.D27 | ||
joyleft: Pin = board.D22 | ||
joyup: Pin = board.D23 | ||
joyright: Pin = board.D24 | ||
joyselect: Pin = board.D16 | ||
|
||
class Config: | ||
arbitrary_types_allowed = True | ||
|
||
|
||
class Eye(BaseModel): | ||
neutral_x: Optional[float] = None | ||
neutral_y: Optional[float] = None | ||
|
||
class Config(BaseModel): | ||
listener_type: str = "sphinx" | ||
speaker_type: str = "google" | ||
pins: Pins = field(default_factory=Pins) | ||
pins: Pins = Pins() | ||
left_eye: Eye = Eye() | ||
right_eye: Eye = Eye() | ||
|
||
def save(self, location: str): | ||
with open(location, "w") as config_file: | ||
config_file.write(json.dumps(self.dict(exclude={"pins"}), indent=2)) | ||
|
||
|
||
|
||
class ConfigFactory: | ||
@classmethod | ||
def create(cls, location: str) -> Config: | ||
with open(location) as config_file: | ||
file_data = yaml.load(config_file, Loader=yaml.FullLoader) | ||
obj = {} | ||
try: | ||
obj = json.loads(config_file.read()) | ||
except json.JSONDecodeError: | ||
logger.warning("error parsing config") | ||
|
||
config = Config.parse_obj(obj) | ||
|
||
|
||
return Config(**(file_data or {})) | ||
return config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters