1
- # pylint: disable=invalid-name
2
1
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
3
2
#
4
3
# SPDX-License-Identifier: MIT
5
- # pylint: enable=invalid-name
4
+
6
5
""" PWMOut Class for lgpio lg library tx_pwm library """
7
6
8
7
import lgpio
9
- import board # need board to get access to the CHIP object in the pin module
8
+ from adafruit_blinka . microcontroller . bcm283x . pin import CHIP
10
9
11
10
12
- # pylint: disable=unnecessary-pass
13
11
class PWMError (IOError ):
14
12
"""Base class for PWM errors."""
15
13
16
- pass
17
-
18
-
19
- # pylint: enable=unnecessary-pass
20
14
21
-
22
- class PWMOut : # pylint: disable=invalid-name
15
+ class PWMOut :
23
16
"""Pulse Width Modulation Output Class"""
24
17
25
18
def __init__ (self , pin , * , frequency = 500 , duty_cycle = 0 , variable_frequency = False ):
26
19
if variable_frequency :
27
20
print ("Variable Frequency is not supported, ignoring..." )
28
21
self ._pin = pin
29
- result = lgpio .gpio_claim_output (
30
- board .pin .CHIP , self ._pin .id , lFlags = lgpio .SET_PULL_NONE
31
- )
22
+ result = lgpio .gpio_claim_output (CHIP , self ._pin .id , lFlags = lgpio .SET_PULL_NONE )
32
23
if result < 0 :
33
24
raise RuntimeError (lgpio .error_text (result ))
34
25
self ._enabled = False
@@ -46,7 +37,7 @@ def __del__(self):
46
37
def __enter__ (self ):
47
38
return self
48
39
49
- def __exit__ (self , exc_type , exc_val , exc_tb ):
40
+ def __exit__ (self , _exc_type , _exc_val , _exc_tb ):
50
41
self .deinit ()
51
42
52
43
def deinit (self ):
@@ -154,7 +145,7 @@ def enabled(self, value):
154
145
frequency = self ._frequency if value else 0
155
146
duty_cycle = round (self ._duty_cycle * 100 )
156
147
self ._enabled = value
157
- result = lgpio .tx_pwm (board . pin . CHIP , self ._pin .id , frequency , duty_cycle )
148
+ result = lgpio .tx_pwm (CHIP , self ._pin .id , frequency , duty_cycle )
158
149
if result < 0 :
159
150
raise RuntimeError (lgpio .error_text (result ))
160
151
return result
0 commit comments