Skip to content

Commit

Permalink
Improve encode/decode comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pvcraven committed Feb 2, 2021
1 parent 9a3a7c6 commit 0792009
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions decode_message_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
CLOCK_CHANNEL = 16
DATA_CHANNEL = 23


# This is a callback function that will be called whenever we have a high/low
# or low/high change in the signal.
def my_callback(channel):
Expand All @@ -20,6 +21,7 @@ def my_callback(channel):
my_callback.counter = 0
my_callback.result_byte = 0


my_callback.counter = 0
my_callback.result_byte = 0

Expand Down
12 changes: 10 additions & 2 deletions encode_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,17 @@
# significant bit 7, down to 0.
for bit_pos in range(bits_in_a_byte - 1, -1, -1):

# Next line is complicated.
# Use a single 1, and bit shift it with << to the
# spot we are interested in. Then use a bitwise
# and to see if that spot has a value
# spot we are interested in. Then use a bitwise and (&)
# and to see if that spot has a value.
# if bit pos = 6 then
# 1 << 6 = 0100 0000 = 64
# if my_byte = 'H' which ASCII 72 = 0100 1000 binary
# H = 0100 1000
# 1 << 6 = 0100 0000
# ---------
# & = 0100 0000 = 64 (result of bit-wise 'and')
bit = (1 << bit_pos) & my_byte

if bit != 0:
Expand Down

0 comments on commit 0792009

Please sign in to comment.