Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: michaellee1019/i2cdetect
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.0.4
Choose a base ref
...
head repository: michaellee1019/i2cdetect
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
  • 3 commits
  • 7 files changed
  • 1 contributor

Commits on Dec 20, 2024

  1. make default bus 1 for easy configuration

    michaellee1019 committed Dec 20, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    777de25 View commit details

Commits on Jan 22, 2025

  1. Copy the full SHA
    89dcbda View commit details
  2. Copy the full SHA
    060780b View commit details
Showing with 189 additions and 11 deletions.
  1. +168 −0 .gitignore
  2. +15 −7 README.md
  3. 0 build.sh
  4. +3 −1 meta.json
  5. +3 −2 models.py
  6. 0 exec.sh → reload.sh
  7. +0 −1 setup.sh
168 changes: 168 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
# https://github.com/github/gitignore/blob/main/Python.gitignore
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
module.tar.gz

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
.pdm.toml
.pdm-python
.pdm-build/

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
.installed

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# MacOS Garbage
.DS_Store
22 changes: 15 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
# michaellee1019:i2cdetect
A Viam module that returns all active i2c addresses as sensor values. Useful for troubleshooting wiring and connection issues without having to install software or SSH into the device.
# Module michaellee1019:i2cdetect
A Viam module for i2c troubleshooting.

# Attributes
Specifying an `i2c_bus` attribute is required.
## Model i2cdetect
This is a Viam Sensor component that returns all active i2c addresses as sensor values. Useful for troubleshooting wiring and connection issues without having to install the `i2cdetect` linux command or SSH into the device.

### Configuration
```json
{
"i2c_bus": 1,
"i2c_bus": <int>
}
```

# GetReadings
The Sensor.GetReadings response will look like the following. It will list the hexidecimal i2c address of each device that is communicating over the i2c bus. Note that the api call will trigger a read from devices at all addresses on the bus. It could have unindended consequences for devices that perform operations during a read, but is generally safe.
### Attributes
The following attributes are available for this model:

| Name | Type | Inclusion | Description |
|---------------|--------|-----------|----------------------------|
| `i2c_bus` | int | Optional | The I2C bus number. Defaults to `1`. |

### GetReadings
The `Sensor.GetReadings` response will look like the following. It will list the hexidecimal i2c address of each device that is communicating over the i2c bus. Note that the api call will trigger a read from devices at all addresses on the bus. It could have unindended consequences for devices that perform operations during a read, but is generally safe.

```json

Empty file modified build.sh
100644 → 100755
Empty file.
4 changes: 3 additions & 1 deletion meta.json
Original file line number Diff line number Diff line change
@@ -6,7 +6,9 @@
"models": [
{
"api": "rdk:component:sensor",
"model": "michaellee1019:i2cdetect:i2cdetect"
"model": "michaellee1019:i2cdetect:i2cdetect",
"short_description": "Returns all active i2c addresses as sensor values. Equivalent to the i2cdetect command without ssh.",
"markdown_link": "README.md#model-i2cdetect"
}
],
"build": {
5 changes: 3 additions & 2 deletions models.py
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@

class i2cdetect(Sensor):
MODEL = "michaellee1019:i2cdetect:i2cdetect"
i2c_bus = None
i2c_bus: int = 1

@classmethod
def new(self, config: ComponentConfig, dependencies: Mapping[ResourceName, ResourceBase]) -> Self:
@@ -20,7 +20,8 @@ def new(self, config: ComponentConfig, dependencies: Mapping[ResourceName, Resou
def reconfigure(self,
config: ComponentConfig,
dependencies: Mapping[ResourceName, ResourceBase]):
self.i2c_bus = int(config.attributes.fields["i2c_bus"].number_value)
if config.attributes.fields["i2c_bus"].number_value:
self.i2c_bus = int(config.attributes.fields["i2c_bus"].number_value)

async def get_readings(self, **kwargs):
bus = smbus2.SMBus(self.i2c_bus)
File renamed without changes.
1 change: 0 additions & 1 deletion setup.sh
Original file line number Diff line number Diff line change
@@ -28,7 +28,6 @@ source .env
if [ -f $VIRTUAL_ENV/.install_complete ]; then
echo "completion marker is present, skipping virtualenv setup"
else
sudo apt install -y git
echo creating virtualenv at $VIRTUAL_ENV
python3 -m venv $VIRTUAL_ENV
echo installing dependencies from requirements.txt