Skip to content

Commit

Permalink
Merge pull request #91 from Chr157i4n/dev
Browse files Browse the repository at this point in the history
version 0.6
  • Loading branch information
Chr157i4n authored Mar 1, 2025
2 parents 9bac6f9 + 30adda1 commit 42e1aec
Show file tree
Hide file tree
Showing 54 changed files with 3,487 additions and 2,675 deletions.
200 changes: 139 additions & 61 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,61 +1,139 @@
name: Test

on: [push, pull_request]

jobs:
markdownlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: DavidAnson/markdownlint-cli2-action@v14
with:
globs: |
README.md
CHANGELOG.md
docs/*.md
pylint:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.12", "3.13"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint
pip install gpiozero
pip install RPi.GPIO
pip install Mock.GPIO
pip install mock
pip install pyserial
- name: Analysing the code with pylint
run: |
pylint $(git ls-files '*.py') --disable=C0103 --disable=W0511 --disable=W0012 --extension-pkg-whitelist=RPi --max-line-length=160
unittest:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.12", "3.13"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install gpiozero
pip install RPi.GPIO
pip install Mock.GPIO
pip install pyserial
- name: Run unittests
run: |
python -m unittest
name: Test

on: [push, pull_request]

jobs:
markdownlint:
name: Markdown-Lint
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- uses: actions/checkout@v4
- uses: DavidAnson/markdownlint-cli2-action@v14
with:
globs: |
README.md
CHANGELOG.md
docs/*.md
pylint:
name: Pylint
runs-on: ubuntu-latest
permissions:
contents: read

strategy:
matrix:
python-version: ["3.9", "3.12", "3.13"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint
pip install gpiozero
pip install RPi.GPIO
pip install git+https://github.com/Chr157i4n/Mock.GPIO
pip install mock
pip install pyserial
- name: Analysing the code with pylint
run: |
pylint $(git ls-files '*.py') --disable=C0103 --disable=W0511 --disable=W0012 --extension-pkg-whitelist=RPi --max-line-length=160
unittest:
name: Unittests
runs-on: ubuntu-latest
permissions:
contents: read

strategy:
matrix:
python-version: ["3.9", "3.12", "3.13"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install gpiozero
pip install RPi.GPIO
pip install git+https://github.com/Chr157i4n/Mock.GPIO
pip install pyserial
- name: Run unittests
run: |
python -m unittest
codeql:
name: Analyze (${{ matrix.language }})
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
permissions:
security-events: write
packages: read
actions: read
contents: read

strategy:
fail-fast: false
matrix:
include:
- language: python
build-mode: none
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"


grype-scan:
permissions:
contents: write # for actions/checkout to fetch code
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
runs-on: ubuntu-latest

steps:
- name: Check out the code
uses: actions/checkout@v4
- name: Create SBOM
run: |
npm install -g @cyclonedx/cdxgen
cdxgen -r . -o bom.json
- name: Upload SBOM Artifact
uses: actions/upload-artifact@v4
with:
name: sbom
path: bom.json
- name: Scan project
uses: anchore/[email protected]
id: scan
with:
sbom: "bom.json"
fail-build: true
severity-cutoff: critical
add-cpes-if-none: true
- name: Upload vulnerability report
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: ${{ steps.scan.outputs.sarif }}
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## version 0.6

- refactored deserialisation and serialisation of register values to use classes
- changed file names according to PEP8
- changed class names according to PEP8

## version 0.5.7

- refactored GPIO access to use inherited classes
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ So you don't need to connect anything to the Vio pin of the driver.
## Usage
```python
from TMC_2209.TMC_2209_StepperDriver import *
tmc = TMC_2209(21, 16, 20)
from tmc_driver.tmc_2209 import *
tmc = Tmc2209(21, 16, 20, TmcUart("/dev/serial0"))
tmc.set_direction_reg(False)
tmc.set_current(300)
Expand Down
1 change: 0 additions & 1 deletion demo/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
#pylint: disable=invalid-name
32 changes: 19 additions & 13 deletions demo/debug_script_01_uart_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@

import time
try:
from src.TMC_2209.TMC_2209_StepperDriver import *
from src.TMC_2209._TMC_2209_GPIO_board import Board
from src.tmc_driver.tmc_2209 import *
except ModuleNotFoundError:
from TMC_2209.TMC_2209_StepperDriver import *
from TMC_2209._TMC_2209_GPIO_board import Board
from tmc_driver.tmc_2209 import *


print("---")
Expand All @@ -24,29 +22,37 @@


#-----------------------------------------------------------------------
# initiate the TMC_2209 class
# initiate the Tmc2209 class
# use your pins for pin_en, pin_step, pin_dir here
#-----------------------------------------------------------------------
if BOARD == Board.RASPBERRY_PI:
tmc = TMC_2209(21, 16, 20, skip_uart_init=True)
tmc = Tmc2209(21, 16, 20, None)
elif BOARD == Board.RASPBERRY_PI5:
tmc = TMC_2209(21, 16, 20, serialport="/dev/ttyAMA0", skip_uart_init=True)
tmc = Tmc2209(21, 16, 20, None)
elif BOARD == Board.NVIDIA_JETSON:
tmc = TMC_2209(13, 6, 5, serialport="/dev/ttyTHS1", skip_uart_init=True)
tmc = Tmc2209(13, 6, 5, None)
else:
# just in case
tmc = TMC_2209(21, 16, 20, skip_uart_init=True)
tmc = Tmc2209(21, 16, 20, TmcUart("/dev/serial0"))


if BOARD == Board.RASPBERRY_PI:
tmc.tmc_com = TmcUart("/dev/serial0")
elif BOARD == Board.RASPBERRY_PI5:
tmc.tmc_com = TmcUart("/dev/ttyAMA0")
elif BOARD == Board.NVIDIA_JETSON:
tmc.tmc_com = TmcUart("/dev/ttyTHS1")

tmc.tmc_com.tmc_logger = tmc.tmc_logger


#-----------------------------------------------------------------------
# set the loglevel of the libary (currently only printed)
# set whether the movement should be relative or absolute
# both optional
#-----------------------------------------------------------------------
tmc.tmc_logger.set_loglevel(Loglevel.DEBUG)
tmc.set_movement_abs_rel(MovementAbsRel.ABSOLUTE)
tmc.tmc_logger.loglevel = Loglevel.DEBUG
tmc.movement_abs_rel = MovementAbsRel.ABSOLUTE



Expand All @@ -59,7 +65,7 @@
#-----------------------------------------------------------------------
print("---\n---")

tmc.test_uart()
tmc.test_com()


print("---\n---")
Expand All @@ -69,7 +75,7 @@


#-----------------------------------------------------------------------
# deinitiate the TMC_2209 class
# deinitiate the Tmc2209 class
#-----------------------------------------------------------------------
del tmc

Expand Down
24 changes: 11 additions & 13 deletions demo/demo_script_01_uart_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,41 @@

import time
try:
from src.TMC_2209.TMC_2209_StepperDriver import *
from src.TMC_2209._TMC_2209_GPIO_board import Board
from src.tmc_driver.tmc_2209 import *
except ModuleNotFoundError:
from TMC_2209.TMC_2209_StepperDriver import *
from TMC_2209._TMC_2209_GPIO_board import Board
from tmc_driver.tmc_2209 import *


print("---")
print("SCRIPT START")
print("---")



tmc:Tmc2209 = None


#-----------------------------------------------------------------------
# initiate the TMC_2209 class
# initiate the Tmc2209 class
# use your pins for pin_en, pin_step, pin_dir here
#-----------------------------------------------------------------------
if BOARD == Board.RASPBERRY_PI:
tmc = TMC_2209(21, 16, 20)
tmc = Tmc2209(21, 16, 20, TmcUart("/dev/serial0"))
elif BOARD == Board.RASPBERRY_PI5:
tmc = TMC_2209(21, 16, 20, serialport="/dev/ttyAMA0")
tmc = Tmc2209(21, 16, 20, TmcUart("/dev/ttyAMA0"))
elif BOARD == Board.NVIDIA_JETSON:
tmc = TMC_2209(13, 6, 5, serialport="/dev/ttyTHS1")
tmc = Tmc2209(13, 6, 5, TmcUart("/dev/ttyTHS1"))
else:
# just in case
tmc = TMC_2209(21, 16, 20)
tmc = Tmc2209(21, 16, 20, TmcUart("/dev/serial0"))


#-----------------------------------------------------------------------
# set the loglevel of the libary (currently only printed)
# set whether the movement should be relative or absolute
# both optional
#-----------------------------------------------------------------------
tmc.tmc_logger.set_loglevel(Loglevel.DEBUG)
tmc.set_movement_abs_rel(MovementAbsRel.ABSOLUTE)
tmc.tmc_logger.loglevel = Loglevel.DEBUG
tmc.movement_abs_rel = MovementAbsRel.ABSOLUTE



Expand Down Expand Up @@ -82,7 +80,7 @@


#-----------------------------------------------------------------------
# deinitiate the TMC_2209 class
# deinitiate the Tmc2209 class
#-----------------------------------------------------------------------
del tmc

Expand Down
Loading

0 comments on commit 42e1aec

Please sign in to comment.