Skip to content

Commit

Permalink
chore: adjust style
Browse files Browse the repository at this point in the history
  • Loading branch information
fcrespel committed May 9, 2024
1 parent f0432c4 commit ec1c165
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 16 deletions.
2 changes: 2 additions & 0 deletions app/chacon54662/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from .protocol import transmit

__all__ = ["main"]


def parse_args():
parser = argparse.ArgumentParser(description="Chacon 54662 remote control")
Expand Down
12 changes: 7 additions & 5 deletions app/chacon54662/protocol.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import odroid_wiringpi as wiringpi

__all__ = ["transmit"]

TIME_HIGH_LOCK = 290
TIME_LOW_LOCK = 2400

Expand All @@ -10,7 +12,7 @@
TIME_LOW_1 = 1250


def sendBit(pin: int, b: bool):
def send_bit(pin: int, b: bool):
if b:
wiringpi.digitalWrite(pin, wiringpi.HIGH)
wiringpi.delayMicroseconds(TIME_HIGH_1)
Expand All @@ -23,18 +25,18 @@ def sendBit(pin: int, b: bool):
wiringpi.delayMicroseconds(TIME_LOW_0)


def sendWord(pin: int, word: int, bits: int):
def send_word(pin: int, word: int, bits: int):
for bit in reversed(range(bits)):
if word & (1 << bit):
sendBit(pin, True)
send_bit(pin, True)
else:
sendBit(pin, False)
send_bit(pin, False)


def transmit(pin: int, word: int):
for _ in range(4):
# Code word (24 bits)
sendWord(pin, word, 24)
send_word(pin, word, 24)

# End lock
wiringpi.digitalWrite(pin, wiringpi.HIGH)
Expand Down
2 changes: 2 additions & 0 deletions app/chacon54662/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from .protocol import transmit

__all__ = ["router"]

router = APIRouter(prefix="/chacon54662", tags=["chacon54662"])


Expand Down
2 changes: 2 additions & 0 deletions app/chacondio10/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from .protocol import transmit

__all__ = ["main"]


def parse_args():
parser = argparse.ArgumentParser(description="Chacon DIO 1.0 remote control")
Expand Down
24 changes: 13 additions & 11 deletions app/chacondio10/protocol.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import odroid_wiringpi as wiringpi

__all__ = ["transmit"]

TIME_HIGH_LOCK = 275
TIME_LOW_LOCK1 = 9900
TIME_LOW_LOCK2 = 2675
Expand All @@ -9,7 +11,7 @@
TIME_LOW_DATA_SHORT = 275 # 310 or 275 or 350


def sendBit(pin: int, b: bool):
def send_bit(pin: int, b: bool):
if b:
wiringpi.digitalWrite(pin, wiringpi.HIGH)
wiringpi.delayMicroseconds(TIME_HIGH_DATA)
Expand All @@ -22,17 +24,17 @@ def sendBit(pin: int, b: bool):
wiringpi.delayMicroseconds(TIME_LOW_DATA_SHORT)


def sendPair(pin: int, b: bool):
sendBit(pin, b)
sendBit(pin, not b)
def send_pair(pin: int, b: bool):
send_bit(pin, b)
send_bit(pin, not b)


def sendWord(pin: int, word: int, bits: int):
def send_word(pin: int, word: int, bits: int):
for bit in reversed(range(bits)):
if word & (1 << bit):
sendPair(pin, True)
send_pair(pin, True)
else:
sendPair(pin, False)
send_pair(pin, False)


def transmit(pin: int, sender: int, group: bool, button: int, onoff: bool):
Expand All @@ -48,16 +50,16 @@ def transmit(pin: int, sender: int, group: bool, button: int, onoff: bool):
wiringpi.digitalWrite(pin, wiringpi.HIGH)

# Sender code (26 bits)
sendWord(pin, sender, 26)
send_word(pin, sender, 26)

# Group bit
sendPair(pin, group)
send_pair(pin, group)

# On/off bit
sendPair(pin, onoff)
send_pair(pin, onoff)

# Button number (4 bits)
sendWord(pin, button, 4)
send_word(pin, button, 4)

# End lock
wiringpi.digitalWrite(pin, wiringpi.HIGH)
Expand Down
2 changes: 2 additions & 0 deletions app/chacondio10/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from .protocol import transmit

__all__ = ["router"]

router = APIRouter(prefix="/chacondio10", tags=["chacondio10"])


Expand Down

0 comments on commit ec1c165

Please sign in to comment.