Skip to content

Commit 42e1aec

Browse files
authored
Merge pull request #91 from Chr157i4n/dev
version 0.6
2 parents 9bac6f9 + 30adda1 commit 42e1aec

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+3487
-2675
lines changed

.github/workflows/test.yml

+139-61
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,139 @@
1-
name: Test
2-
3-
on: [push, pull_request]
4-
5-
jobs:
6-
markdownlint:
7-
runs-on: ubuntu-latest
8-
steps:
9-
- uses: actions/checkout@v4
10-
- uses: DavidAnson/markdownlint-cli2-action@v14
11-
with:
12-
globs: |
13-
README.md
14-
CHANGELOG.md
15-
docs/*.md
16-
17-
pylint:
18-
runs-on: ubuntu-latest
19-
strategy:
20-
matrix:
21-
python-version: ["3.9", "3.12", "3.13"]
22-
steps:
23-
- uses: actions/checkout@v3
24-
- name: Set up Python ${{ matrix.python-version }}
25-
uses: actions/setup-python@v3
26-
with:
27-
python-version: ${{ matrix.python-version }}
28-
- name: Install dependencies
29-
run: |
30-
python -m pip install --upgrade pip
31-
pip install pylint
32-
pip install gpiozero
33-
pip install RPi.GPIO
34-
pip install Mock.GPIO
35-
pip install mock
36-
pip install pyserial
37-
- name: Analysing the code with pylint
38-
run: |
39-
pylint $(git ls-files '*.py') --disable=C0103 --disable=W0511 --disable=W0012 --extension-pkg-whitelist=RPi --max-line-length=160
40-
41-
unittest:
42-
runs-on: ubuntu-latest
43-
strategy:
44-
matrix:
45-
python-version: ["3.9", "3.12", "3.13"]
46-
steps:
47-
- uses: actions/checkout@v3
48-
- name: Set up Python ${{ matrix.python-version }}
49-
uses: actions/setup-python@v3
50-
with:
51-
python-version: ${{ matrix.python-version }}
52-
- name: Install dependencies
53-
run: |
54-
python -m pip install --upgrade pip
55-
pip install gpiozero
56-
pip install RPi.GPIO
57-
pip install Mock.GPIO
58-
pip install pyserial
59-
- name: Run unittests
60-
run: |
61-
python -m unittest
1+
name: Test
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
markdownlint:
7+
name: Markdown-Lint
8+
runs-on: ubuntu-latest
9+
permissions:
10+
contents: read
11+
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: DavidAnson/markdownlint-cli2-action@v14
15+
with:
16+
globs: |
17+
README.md
18+
CHANGELOG.md
19+
docs/*.md
20+
21+
22+
pylint:
23+
name: Pylint
24+
runs-on: ubuntu-latest
25+
permissions:
26+
contents: read
27+
28+
strategy:
29+
matrix:
30+
python-version: ["3.9", "3.12", "3.13"]
31+
32+
steps:
33+
- uses: actions/checkout@v3
34+
- name: Set up Python ${{ matrix.python-version }}
35+
uses: actions/setup-python@v3
36+
with:
37+
python-version: ${{ matrix.python-version }}
38+
- name: Install dependencies
39+
run: |
40+
python -m pip install --upgrade pip
41+
pip install pylint
42+
pip install gpiozero
43+
pip install RPi.GPIO
44+
pip install git+https://github.com/Chr157i4n/Mock.GPIO
45+
pip install mock
46+
pip install pyserial
47+
- name: Analysing the code with pylint
48+
run: |
49+
pylint $(git ls-files '*.py') --disable=C0103 --disable=W0511 --disable=W0012 --extension-pkg-whitelist=RPi --max-line-length=160
50+
51+
52+
unittest:
53+
name: Unittests
54+
runs-on: ubuntu-latest
55+
permissions:
56+
contents: read
57+
58+
strategy:
59+
matrix:
60+
python-version: ["3.9", "3.12", "3.13"]
61+
62+
steps:
63+
- uses: actions/checkout@v3
64+
- name: Set up Python ${{ matrix.python-version }}
65+
uses: actions/setup-python@v3
66+
with:
67+
python-version: ${{ matrix.python-version }}
68+
- name: Install dependencies
69+
run: |
70+
python -m pip install --upgrade pip
71+
pip install gpiozero
72+
pip install RPi.GPIO
73+
pip install git+https://github.com/Chr157i4n/Mock.GPIO
74+
pip install pyserial
75+
- name: Run unittests
76+
run: |
77+
python -m unittest
78+
79+
80+
codeql:
81+
name: Analyze (${{ matrix.language }})
82+
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
83+
permissions:
84+
security-events: write
85+
packages: read
86+
actions: read
87+
contents: read
88+
89+
strategy:
90+
fail-fast: false
91+
matrix:
92+
include:
93+
- language: python
94+
build-mode: none
95+
steps:
96+
- name: Checkout repository
97+
uses: actions/checkout@v4
98+
- name: Initialize CodeQL
99+
uses: github/codeql-action/init@v3
100+
with:
101+
languages: ${{ matrix.language }}
102+
build-mode: ${{ matrix.build-mode }}
103+
- name: Perform CodeQL Analysis
104+
uses: github/codeql-action/analyze@v3
105+
with:
106+
category: "/language:${{matrix.language}}"
107+
108+
109+
grype-scan:
110+
permissions:
111+
contents: write # for actions/checkout to fetch code
112+
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
113+
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
114+
runs-on: ubuntu-latest
115+
116+
steps:
117+
- name: Check out the code
118+
uses: actions/checkout@v4
119+
- name: Create SBOM
120+
run: |
121+
npm install -g @cyclonedx/cdxgen
122+
cdxgen -r . -o bom.json
123+
- name: Upload SBOM Artifact
124+
uses: actions/upload-artifact@v4
125+
with:
126+
name: sbom
127+
path: bom.json
128+
- name: Scan project
129+
uses: anchore/scan-action@v6.1.0
130+
id: scan
131+
with:
132+
sbom: "bom.json"
133+
fail-build: true
134+
severity-cutoff: critical
135+
add-cpes-if-none: true
136+
- name: Upload vulnerability report
137+
uses: github/codeql-action/upload-sarif@v3
138+
with:
139+
sarif_file: ${{ steps.scan.outputs.sarif }}

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## version 0.6
4+
5+
- refactored deserialisation and serialisation of register values to use classes
6+
- changed file names according to PEP8
7+
- changed class names according to PEP8
8+
39
## version 0.5.7
410

511
- refactored GPIO access to use inherited classes

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ So you don't need to connect anything to the Vio pin of the driver.
158158
## Usage
159159
160160
```python
161-
from TMC_2209.TMC_2209_StepperDriver import *
162-
tmc = TMC_2209(21, 16, 20)
161+
from tmc_driver.tmc_2209 import *
162+
tmc = Tmc2209(21, 16, 20, TmcUart("/dev/serial0"))
163163
164164
tmc.set_direction_reg(False)
165165
tmc.set_current(300)

demo/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
#pylint: disable=invalid-name

demo/debug_script_01_uart_connection.py

+19-13
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88

99
import time
1010
try:
11-
from src.TMC_2209.TMC_2209_StepperDriver import *
12-
from src.TMC_2209._TMC_2209_GPIO_board import Board
11+
from src.tmc_driver.tmc_2209 import *
1312
except ModuleNotFoundError:
14-
from TMC_2209.TMC_2209_StepperDriver import *
15-
from TMC_2209._TMC_2209_GPIO_board import Board
13+
from tmc_driver.tmc_2209 import *
1614

1715

1816
print("---")
@@ -24,29 +22,37 @@
2422

2523

2624
#-----------------------------------------------------------------------
27-
# initiate the TMC_2209 class
25+
# initiate the Tmc2209 class
2826
# use your pins for pin_en, pin_step, pin_dir here
2927
#-----------------------------------------------------------------------
3028
if BOARD == Board.RASPBERRY_PI:
31-
tmc = TMC_2209(21, 16, 20, skip_uart_init=True)
29+
tmc = Tmc2209(21, 16, 20, None)
3230
elif BOARD == Board.RASPBERRY_PI5:
33-
tmc = TMC_2209(21, 16, 20, serialport="/dev/ttyAMA0", skip_uart_init=True)
31+
tmc = Tmc2209(21, 16, 20, None)
3432
elif BOARD == Board.NVIDIA_JETSON:
35-
tmc = TMC_2209(13, 6, 5, serialport="/dev/ttyTHS1", skip_uart_init=True)
33+
tmc = Tmc2209(13, 6, 5, None)
3634
else:
3735
# just in case
38-
tmc = TMC_2209(21, 16, 20, skip_uart_init=True)
36+
tmc = Tmc2209(21, 16, 20, TmcUart("/dev/serial0"))
3937

4038

39+
if BOARD == Board.RASPBERRY_PI:
40+
tmc.tmc_com = TmcUart("/dev/serial0")
41+
elif BOARD == Board.RASPBERRY_PI5:
42+
tmc.tmc_com = TmcUart("/dev/ttyAMA0")
43+
elif BOARD == Board.NVIDIA_JETSON:
44+
tmc.tmc_com = TmcUart("/dev/ttyTHS1")
45+
46+
tmc.tmc_com.tmc_logger = tmc.tmc_logger
4147

4248

4349
#-----------------------------------------------------------------------
4450
# set the loglevel of the libary (currently only printed)
4551
# set whether the movement should be relative or absolute
4652
# both optional
4753
#-----------------------------------------------------------------------
48-
tmc.tmc_logger.set_loglevel(Loglevel.DEBUG)
49-
tmc.set_movement_abs_rel(MovementAbsRel.ABSOLUTE)
54+
tmc.tmc_logger.loglevel = Loglevel.DEBUG
55+
tmc.movement_abs_rel = MovementAbsRel.ABSOLUTE
5056

5157

5258

@@ -59,7 +65,7 @@
5965
#-----------------------------------------------------------------------
6066
print("---\n---")
6167

62-
tmc.test_uart()
68+
tmc.test_com()
6369

6470

6571
print("---\n---")
@@ -69,7 +75,7 @@
6975

7076

7177
#-----------------------------------------------------------------------
72-
# deinitiate the TMC_2209 class
78+
# deinitiate the Tmc2209 class
7379
#-----------------------------------------------------------------------
7480
del tmc
7581

demo/demo_script_01_uart_connection.py

+11-13
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,41 @@
88

99
import time
1010
try:
11-
from src.TMC_2209.TMC_2209_StepperDriver import *
12-
from src.TMC_2209._TMC_2209_GPIO_board import Board
11+
from src.tmc_driver.tmc_2209 import *
1312
except ModuleNotFoundError:
14-
from TMC_2209.TMC_2209_StepperDriver import *
15-
from TMC_2209._TMC_2209_GPIO_board import Board
13+
from tmc_driver.tmc_2209 import *
1614

1715

1816
print("---")
1917
print("SCRIPT START")
2018
print("---")
2119

2220

23-
21+
tmc:Tmc2209 = None
2422

2523

2624
#-----------------------------------------------------------------------
27-
# initiate the TMC_2209 class
25+
# initiate the Tmc2209 class
2826
# use your pins for pin_en, pin_step, pin_dir here
2927
#-----------------------------------------------------------------------
3028
if BOARD == Board.RASPBERRY_PI:
31-
tmc = TMC_2209(21, 16, 20)
29+
tmc = Tmc2209(21, 16, 20, TmcUart("/dev/serial0"))
3230
elif BOARD == Board.RASPBERRY_PI5:
33-
tmc = TMC_2209(21, 16, 20, serialport="/dev/ttyAMA0")
31+
tmc = Tmc2209(21, 16, 20, TmcUart("/dev/ttyAMA0"))
3432
elif BOARD == Board.NVIDIA_JETSON:
35-
tmc = TMC_2209(13, 6, 5, serialport="/dev/ttyTHS1")
33+
tmc = Tmc2209(13, 6, 5, TmcUart("/dev/ttyTHS1"))
3634
else:
3735
# just in case
38-
tmc = TMC_2209(21, 16, 20)
36+
tmc = Tmc2209(21, 16, 20, TmcUart("/dev/serial0"))
3937

4038

4139
#-----------------------------------------------------------------------
4240
# set the loglevel of the libary (currently only printed)
4341
# set whether the movement should be relative or absolute
4442
# both optional
4543
#-----------------------------------------------------------------------
46-
tmc.tmc_logger.set_loglevel(Loglevel.DEBUG)
47-
tmc.set_movement_abs_rel(MovementAbsRel.ABSOLUTE)
44+
tmc.tmc_logger.loglevel = Loglevel.DEBUG
45+
tmc.movement_abs_rel = MovementAbsRel.ABSOLUTE
4846

4947

5048

@@ -82,7 +80,7 @@
8280

8381

8482
#-----------------------------------------------------------------------
85-
# deinitiate the TMC_2209 class
83+
# deinitiate the Tmc2209 class
8684
#-----------------------------------------------------------------------
8785
del tmc
8886

0 commit comments

Comments
 (0)