Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
88 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
"""LEGO Power Functions RC v1.20""" | ||
|
||
import power_functions.extended as extended | ||
import power_functions.combo_direct as direct | ||
import power_functions.single_output as single | ||
import power_functions.combo_pwm as pwm | ||
import power_functions.combo_direct as combo_direct | ||
import power_functions.single_output as single_output | ||
import power_functions.combo_pwm as combo_pwm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,35 @@ | ||
"""LEGO Power Functions RC v1.20 - Combo Direct Mode""" | ||
|
||
import power_functions.pf_rc_protocol as rc | ||
import power_functions.rc_protocol as pf_rc | ||
|
||
# Output Data | ||
OUTPUT = ["FLT", # Float | ||
"FWD", # Forward | ||
"REV", # Backward | ||
"BRK"] # Brake | ||
|
||
def payload(_ch, _red, _blue, _esc=rc.ESC.MODE, _addr=rc.ADDR.DEF): | ||
def payload(channel, red, blue, _esc=pf_rc.ESC.MODE, _addr=pf_rc.ADDR.DEF): | ||
"""Returns the payload for a Combo Direct Mode command.""" | ||
nibble1 = _esc | _ch | ||
nibble2 = _addr | rc.MODE.DIR | ||
nibble3 = _red | (_blue << 2) | ||
nibble4 = rc.lrc(nibble1, nibble2, nibble3) | ||
nibble1 = _esc | channel | ||
nibble2 = _addr | pf_rc.MODE.DIR | ||
nibble3 = red | (blue << 2) | ||
nibble4 = pf_rc.lrc(nibble1, nibble2, nibble3) | ||
return nibble1, nibble2, nibble3, nibble4 | ||
|
||
def button(_ch, _red, _blue): | ||
def button(channel, red, blue): | ||
"""Returns the button for a Combo Direct Mode command.""" | ||
return (rc.CHANNEL[_ch], OUTPUT[_red], OUTPUT[_blue]) | ||
return (pf_rc.CHANNEL[channel], OUTPUT[red], OUTPUT[blue]) | ||
|
||
def button_string(ch_, red, blue): | ||
def button_string(channel, red, blue): | ||
"""Returns the string representation of Combo Direct Mode button.""" | ||
return 'CH{:s}_{:s}_{:s}'.format(ch_, red, blue) | ||
return 'CH{:s}_{:s}_{:s}'.format(channel, red, blue) | ||
|
||
def lirc_codes(): | ||
"""Prints LIRC codes for Combo Direct Mode.""" | ||
for i in range(0, 4): | ||
for k in range(0, 16): | ||
red = k & 0x3 | ||
blue = k >> 2 | ||
hex_codes = rc.payload_string(*payload(i, red, blue)) | ||
hex_codes = pf_rc.payload_string(*payload(i, red, blue)) | ||
lirc_patterns = button_string(*button(i, red, blue)) | ||
print "\t{}\t\t{}".format(lirc_patterns, hex_codes) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,46 @@ | ||
"""LEGO Power Functions RC v1.20 - Combo PWM Mode""" | ||
|
||
import power_functions.pf_rc_protocol as rc | ||
import power_functions.rc_protocol as pf_rc | ||
|
||
# Data (PWM Steps) | ||
STEPS = ["FLT", # Float | ||
"FWD1", # PWM forward, step 1 | ||
"FWD2", # PWM forward, step 2 | ||
"FWD3", # PWM forward, step 3 | ||
"FWD4", # PWM forward, step 4 | ||
"FWD5", # PWM forward, step 5 | ||
"FWD6", # PWM forward, step 6 | ||
"FWD7", # PWM forward, step 7 | ||
"BRK", # Brake then float | ||
"REV7", # PWM backward, step 7 | ||
"REV6", # PWM backward, step 6 | ||
"REV5", # PWM backward, step 5 | ||
"REV4", # PWM backward, step 4 | ||
"REV3", # PWM backward, step 3 | ||
"REV2", # PWM backward, step 2 | ||
"REV1"] # PWM backward, step 1 | ||
PWM_STEP = ["FLT", # Float | ||
"FWD1", # PWM forward, step 1 | ||
"FWD2", # PWM forward, step 2 | ||
"FWD3", # PWM forward, step 3 | ||
"FWD4", # PWM forward, step 4 | ||
"FWD5", # PWM forward, step 5 | ||
"FWD6", # PWM forward, step 6 | ||
"FWD7", # PWM forward, step 7 | ||
"BRK", # Brake then float | ||
"REV7", # PWM backward, step 7 | ||
"REV6", # PWM backward, step 6 | ||
"REV5", # PWM backward, step 5 | ||
"REV4", # PWM backward, step 4 | ||
"REV3", # PWM backward, step 3 | ||
"REV2", # PWM backward, step 2 | ||
"REV1"] # PWM backward, step 1 | ||
|
||
def payload(_ch, _red, _blue, _esc=rc.ESC.PWM, _addr=rc.ADDR.DEF): | ||
def payload(channel, red, blue, _esc=pf_rc.ESC.PWM, _addr=pf_rc.ADDR.DEF): | ||
"""Returns the payload for a Combo PWM Mode command.""" | ||
nibble1 = _addr | _esc | _ch | ||
nibble2 = _blue | ||
nibble3 = _red | ||
nibble4 = rc.lrc(nibble1, nibble2, nibble3) | ||
nibble1 = _addr | _esc | channel | ||
nibble2 = blue | ||
nibble3 = red | ||
nibble4 = pf_rc.lrc(nibble1, nibble2, nibble3) | ||
return nibble1, nibble2, nibble3, nibble4 | ||
|
||
def button(_ch, _red, _blue): | ||
def button(channel, red, blue): | ||
"""Returns the button for a Combo PWM Mode command.""" | ||
return (rc.CHANNEL[_ch], STEPS[_red], STEPS[_blue]) | ||
return (pf_rc.CHANNEL[channel], PWM_STEP[red], PWM_STEP[blue]) | ||
|
||
def button_string(ch_, red, blue): | ||
def button_string(channel, red, blue): | ||
"""Returns the string representation of a Combo PWM Mode button.""" | ||
return 'CH{:s}_{:s}_{:s}'.format(ch_, red, blue) | ||
return 'CH{:s}_{:s}_{:s}'.format(channel, red, blue) | ||
|
||
def lirc_codes(): | ||
"""Prints LIRC codes for Combo PWM Mode.""" | ||
for i in range(0, 4): | ||
for j in range(0, 16): | ||
for k in range(0, 16): | ||
hex_codes = rc.payload_string(*payload(i, j, k)) | ||
hex_codes = pf_rc.payload_string(*payload(i, j, k)) | ||
lirc_pattern = button_string(*button(i, j, k)) | ||
print "\t{}\t\t{}".format(lirc_pattern, hex_codes) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,40 @@ | ||
"""LEGO Power Functions RC v1.20 - Extended Mode""" | ||
|
||
import power_functions.pf_rc_protocol as rc | ||
import power_functions.rc_protocol as pf_rc | ||
|
||
# Function Data | ||
FUNCTIONS = ["BRK_A", # Brake then float A | ||
"INC_A", # Increment speed on A | ||
"DEC_A", # Decrement speed on A | ||
"NOT_USED", # ... | ||
"TGL_B", # Toggle forward/float on B | ||
"NOT_USED", # ... | ||
"TGL_ADR", # Toggle address bit | ||
"ALN_TGL", # Align toggle bit (get in sync) | ||
"RESERVED"] # ... | ||
FUNCTION = ["BRK_A", # Brake then float A | ||
"INC_A", # Increment speed on A | ||
"DEC_A", # Decrement speed on A | ||
"NOT_USED", # ... | ||
"TGL_B", # Toggle forward/float on B | ||
"NOT_USED", # ... | ||
"TGL_ADR", # Toggle address bit | ||
"ALN_TGL", # Align toggle bit (get in sync) | ||
"RESERVED"] # ... | ||
|
||
def payload(_ch, _fn, _esc=rc.ESC.MODE, _addr=rc.ADDR.DEF): | ||
def payload(channel, function, _esc=pf_rc.ESC.MODE, _addr=pf_rc.ADDR.DEF): | ||
"""Returns the payload for an Extended Mode command.""" | ||
nibble1 = _esc | _ch | ||
nibble2 = _addr | rc.MODE.EXT | ||
nibble3 = _fn | ||
nibble4 = rc.lrc(nibble1, nibble2, nibble3) | ||
nibble1 = _esc | channel | ||
nibble2 = _addr | pf_rc.MODE.EXT | ||
nibble3 = function | ||
nibble4 = pf_rc.lrc(nibble1, nibble2, nibble3) | ||
return nibble1, nibble2, nibble3, nibble4 | ||
|
||
def button(_ch, _fn): | ||
def button(channel, function): | ||
""" Returns the button for an Extended Mode command.""" | ||
return (rc.CHANNEL[_ch], FUNCTIONS[_fn]) | ||
return (pf_rc.CHANNEL[channel], FUNCTION[function]) | ||
|
||
def button_string(ch_, fn_): | ||
def button_string(channel, function): | ||
"""Returns the string representation of an Extended Mode button.""" | ||
return 'CH{:s}_{:s}'.format(ch_, fn_) | ||
return 'CH{:s}_{:s}'.format(channel, function) | ||
|
||
def lirc_codes(): | ||
"""Prints LIRC codes for Extended Mode.""" | ||
for i in range(0, 4): | ||
for k, func in enumerate(FUNCTIONS): | ||
for k, func in enumerate(FUNCTION): | ||
if func == "NOT_USED" or func == "RESERVED": | ||
continue | ||
hex_codes = rc.payload_string(*payload(i, k)) | ||
hex_codes = pf_rc.payload_string(*payload(i, k)) | ||
lirc_patterns = button_string(*button(i, k)) | ||
print "\t{}\t\t{}".format(lirc_patterns, hex_codes) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
from context import pf | ||
from context import power_functions as pf | ||
|
||
pf.extended.lirc_codes() | ||
pf.direct.lirc_codes() | ||
pf.single.lirc_codes() | ||
pf.pwm.lirc_codes() | ||
pf.combo_direct.lirc_codes() | ||
pf.single_output.lirc_codes() | ||
pf.combo_pwm.lirc_codes() |