diff --git a/build.sh b/build.sh index 03759e8..1bf0ffc 100755 --- a/build.sh +++ b/build.sh @@ -16,5 +16,5 @@ if ! uv pip install pyinstaller -q; then exit 1 fi -uv run pyinstaller --onefile --hidden-import="googleapiclient" src/main.py +uv run pyinstaller --onefile --hidden-import="googleapiclient" -p src src/main.py tar -czvf dist/archive.tar.gz ./dist/main diff --git a/requirements.txt b/requirements.txt index 920fcb2..a209a1d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ viam-sdk adafruit-circuitpython-mcp3xxx -google-api-python-client +RPi.GPIO diff --git a/setup.sh b/setup.sh index 8137f9c..e073852 100755 --- a/setup.sh +++ b/setup.sh @@ -27,7 +27,7 @@ fi source $VENV_NAME/bin/activate -if ! uv pip sync requirements.txt; then +if ! uv pip install -r requirements.txt; then echo "unable to sync requirements to venv" exit 1 fi diff --git a/src/__init__.py b/src/__init__.py index 9437b7d..001a5f5 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -1,10 +1,3 @@ """ This file registers the model with the Python SDK. """ - -from viam.components.sensor import Sensor -from viam.resource.registry import Registry, ResourceCreatorRegistration - -from .mcp300x import mcp300x - -Registry.register_resource_creator(Sensor.SUBTYPE, mcp300x.MODEL, ResourceCreatorRegistration(mcp300x.new, mcp300x.validate)) diff --git a/src/main.py b/src/main.py index b5397dc..ab55998 100644 --- a/src/main.py +++ b/src/main.py @@ -1,16 +1,24 @@ import asyncio from viam.components.sensor import Sensor +from viam.resource.registry import Registry, ResourceCreatorRegistration from viam.module.module import Module -from .mcp300x import mcp300x +from mcp300x import mcp3xxx + async def main(): """This function creates and starts a new module, after adding all desired resources. Resources must be pre-registered. For an example, see the `__init__.py` file. """ + Registry.register_resource_creator( + Sensor.SUBTYPE, + mcp3xxx.MODEL, + ResourceCreatorRegistration(mcp3xxx.new, mcp3xxx.validate), + ) module = Module.from_args() - module.add_model_from_registry(Sensor.SUBTYPE, mcp300x.MODEL) + module.add_model_from_registry(Sensor.SUBTYPE, mcp3xxx.MODEL) await module.start() + if __name__ == "__main__": asyncio.run(main()) diff --git a/src/mcp300x.py b/src/mcp300x.py index 777998c..860f541 100644 --- a/src/mcp300x.py +++ b/src/mcp300x.py @@ -59,12 +59,6 @@ def reconfigure( self.channel_map = dict(config.attributes.fields["channel_map"].struct_value) LOGGER.debug(f"Channel map is {self.channel_map}") - if getattr(self, "spi") is not None: - self.spi.deinit() - - if getattr(self, "cs") is not None: - self.cs.deinit() - # Sensor Pin Logic # Creates the SPI bus self.spi = busio.SPI(clock=board.SCK, MISO=board.MISO, MOSI=board.MOSI)