mirror of
https://github.com/KevinMidboe/python-gpiozero.git
synced 2025-10-29 17:50:37 +00:00
Reverse order of MCP300X arguments, close #92
This commit is contained in:
@@ -210,29 +210,22 @@ with MCP3008() as pot:
|
|||||||
#### Initialisation options
|
#### Initialisation options
|
||||||
|
|
||||||
```python
|
```python
|
||||||
MCP3008(device=0, channel=0)
|
MCP3008(channel=0, device=0)
|
||||||
```
|
```
|
||||||
|
|
||||||
| Argument | Description | Values | Default |
|
| Argument | Description | Values | Default |
|
||||||
| -------- | ----------- | ------ | ------- |
|
| -------- | ----------- | ------ | ------- |
|
||||||
| `device` | Which of the two Chip Select SPI pins to access. | Integer: `0` or `1` | `0` |
|
|
||||||
| `channel` | Which of the 8 ADC channels to access. | Integer: `0` to `7` | `0` |
|
| `channel` | Which of the 8 ADC channels to access. | Integer: `0` to `7` | `0` |
|
||||||
|
| `device` | Which of the two Chip Select SPI pins to access. | Integer: `0` or `1` | `0` |
|
||||||
#### Methods
|
|
||||||
|
|
||||||
| Method | Description | Arguments |
|
|
||||||
| ------ | ----------- | --------- |
|
|
||||||
| `wait_for_light()` | Halt the program until light is detected. | `timeout` - The number of seconds to wait before proceeding if light is not detected. **Default: `None`** |
|
|
||||||
| `wait_for_dark()` | Halt the program until darkness is detected. | `timeout` - The number of seconds to wait before proceeding if darkness is not detected. **Default: `None`** |
|
|
||||||
|
|
||||||
#### Properties
|
#### Properties
|
||||||
|
|
||||||
| Property | Description | Type |
|
| Property | Description | Type |
|
||||||
| -------- | ----------- | ---- |
|
| -------- | ----------- | ---- |
|
||||||
| `pin` | The GPIO pin number the sensor is connected to. | Integer |
|
| `channel` | The ADC channel the device is connected to. | Integer |
|
||||||
| `light_detected` | The current state of the sensor (`True` if light; otherwise `False`). | Boolean |
|
| `device` | The chip select pin the device is connected to. | Integer |
|
||||||
| `when_light` | A reference to the function to be called when light is detected. | `None` or Function |
|
| `value` | The current value of the device. | Float |
|
||||||
| `when_dark` | A reference to the function to be called when darkness is detected. | `None` or Function |
|
| `values` | A generator continuously yielding the device's current value. | Generator |
|
||||||
|
|
||||||
## MCP3004 Analogue-to-Digital Converter
|
## MCP3004 Analogue-to-Digital Converter
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from __future__ import (
|
|||||||
print_function,
|
print_function,
|
||||||
absolute_import,
|
absolute_import,
|
||||||
division,
|
division,
|
||||||
)
|
)
|
||||||
|
|
||||||
import inspect
|
import inspect
|
||||||
import warnings
|
import warnings
|
||||||
@@ -20,7 +20,7 @@ from .devices import (
|
|||||||
GPIODevice,
|
GPIODevice,
|
||||||
CompositeDevice,
|
CompositeDevice,
|
||||||
GPIOQueue,
|
GPIOQueue,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class InputDeviceError(GPIODeviceError):
|
class InputDeviceError(GPIODeviceError):
|
||||||
@@ -554,7 +554,7 @@ class AnalogInputDevice(CompositeDevice):
|
|||||||
|
|
||||||
|
|
||||||
class MCP3008(AnalogInputDevice):
|
class MCP3008(AnalogInputDevice):
|
||||||
def __init__(self, device=0, channel=0):
|
def __init__(self, channel=0, device=0):
|
||||||
if not 0 <= channel < 8:
|
if not 0 <= channel < 8:
|
||||||
raise InputDeviceError('channel must be between 0 and 7')
|
raise InputDeviceError('channel must be between 0 and 7')
|
||||||
super(MCP3008, self).__init__(device=device, bits=10)
|
super(MCP3008, self).__init__(device=device, bits=10)
|
||||||
@@ -590,9 +590,9 @@ class MCP3008(AnalogInputDevice):
|
|||||||
|
|
||||||
|
|
||||||
class MCP3004(MCP3008):
|
class MCP3004(MCP3008):
|
||||||
def __init__(self, device=0, channel=0):
|
def __init__(self, channel=0, device=0):
|
||||||
# MCP3004 protocol is identical to MCP3008 but the top bit of the
|
# MCP3004 protocol is identical to MCP3008 but the top bit of the
|
||||||
# channel number must be 0 (effectively restricting it to 4 channels)
|
# channel number must be 0 (effectively restricting it to 4 channels)
|
||||||
if not 0 <= channel < 4:
|
if not 0 <= channel < 4:
|
||||||
raise InputDeviceError('channel must be between 0 and 3')
|
raise InputDeviceError('channel must be between 0 and 3')
|
||||||
super(MCP3004, self).__init__(device, channel)
|
super(MCP3004, self).__init__(channel, device)
|
||||||
|
|||||||
Reference in New Issue
Block a user