[API-PY] Moved some variables to constants.py
This commit is contained in:
@ -4,7 +4,7 @@ local and free way to interact with CaiXianlin shock collars.
|
||||
"""
|
||||
|
||||
from .driver import Transmitter
|
||||
from .driver import MODES
|
||||
from .constants import MODES
|
||||
from . import exceptions
|
||||
from . import utils
|
||||
|
||||
|
||||
18
src/pythonAPI/whspah/constants.py
Normal file
18
src/pythonAPI/whspah/constants.py
Normal file
@ -0,0 +1,18 @@
|
||||
"""
|
||||
Holds constants used throughout WHSPAH.
|
||||
"""
|
||||
|
||||
from enum import Enum
|
||||
|
||||
# The hardware magic string.
|
||||
HARDWARE_MAGIC = b'/WHSPAH\x00'
|
||||
|
||||
class MODES(Enum):
|
||||
"""
|
||||
The different commands or "modes" of the shockers.
|
||||
"""
|
||||
|
||||
SHOCK = 1
|
||||
VIBRATE = 2
|
||||
BEEP = 3
|
||||
LIGHT = 4
|
||||
@ -13,6 +13,7 @@ import os
|
||||
|
||||
import serial
|
||||
|
||||
from whspah.constants import MODES, HARDWARE_MAGIC
|
||||
import whspah.exceptions as exceptions
|
||||
import whspah.utils as utils
|
||||
|
||||
@ -20,17 +21,6 @@ CONNECTION_READ_TIMEOUT = 2.5
|
||||
TX_PING_INTERVAL = 1
|
||||
RX_PING_TIMEOUT = 5
|
||||
|
||||
|
||||
class MODES(Enum):
|
||||
"""
|
||||
The different commands or "modes" of the shockers.
|
||||
"""
|
||||
|
||||
SHOCK = 1
|
||||
VIBRATE = 2
|
||||
BEEP = 3
|
||||
LIGHT = 4
|
||||
|
||||
class STATES(Enum):
|
||||
"""
|
||||
The different states of the transmitter object.
|
||||
@ -184,7 +174,7 @@ class Transmitter:
|
||||
select.select([self._ser], [], [], CONNECTION_READ_TIMEOUT)
|
||||
st = time.perf_counter()
|
||||
# Wait for WHSPAH message
|
||||
while (self._ser.read_until(b'\x00') != utils.HARDWARE_MAGIC) and\
|
||||
while (self._ser.read_until(b'\x00') != HARDWARE_MAGIC) and\
|
||||
time.perf_counter() - st < CONNECTION_READ_TIMEOUT:
|
||||
time.sleep(0.1)
|
||||
|
||||
@ -214,7 +204,7 @@ class Transmitter:
|
||||
receivedChecksum = buffer[-2]
|
||||
expectedChecksum = calculateChecksum(buffer[:-2])
|
||||
|
||||
if cmdID == ord('/') and buffer != utils.HARDWARE_MAGIC:
|
||||
if cmdID == ord('/') and buffer != HARDWARE_MAGIC:
|
||||
message = buffer[1:-1].decode()
|
||||
self._log.info('<- %s', message)
|
||||
else:
|
||||
|
||||
@ -11,11 +11,7 @@ import io
|
||||
import serial.tools.list_ports
|
||||
import serial
|
||||
|
||||
# The hardware magic string.
|
||||
# I couldn't really think of a better place to put this,
|
||||
# so I figured utils is the closest we have to a globals.py file.
|
||||
# I don't want to create a globals.py file for this one variable.
|
||||
HARDWARE_MAGIC = b'/WHSPAH\x00'
|
||||
from whspah.constants import HARDWARE_MAGIC
|
||||
|
||||
def _testPortForWHSPAH(resultList: list, port: os.PathLike, baud: int, timeout: float) -> None:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user