python_code
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| python_code [2025/03/26 19:57] – brandon | python_code [2025/05/15 03:28] (current) – add notes about how to use this page brandon | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Python Code ====== | ====== Python Code ====== | ||
| + | |||
| + | This a hub page for Python code linked to other pages using the '' | ||
| + | |||
| + | Example of how to embed a code section in another page in DokuWiki: \\ | ||
| + | '' | ||
| + | <wrap lo> | ||
| + | |||
| + | Any script with dependencies should use [[https:// | ||
| + | |||
| + | ===== Create Button Flag ===== | ||
| + | |||
| + | --> Python Create Button Flag # | ||
| + | <code python asi_create_button_flag.py> | ||
| + | def create_button_code(at: | ||
| + | assert at in range(4), "Must be in the range 0-3." | ||
| + | assert home in range(4), "Must be in the range 0-3." | ||
| + | assert joystick in range(4), "Must be in the range 0-3." | ||
| + | assert zero_halt == 0 or zero_halt == 1, "Must be 0 or 1." | ||
| + | |||
| + | button_code = 0 | ||
| + | |||
| + | # bit masks | ||
| + | BITMASK_AT | ||
| + | BITMASK_HOME = 0x0C # 00001100 | ||
| + | BITMASK_JS | ||
| + | BITMASK_ZERO = 0xC0 # 11000000 | ||
| + | |||
| + | # set bits | ||
| + | button_code &= ~BITMASK_AT | ||
| + | button_code |= at & BITMASK_AT | ||
| + | |||
| + | button_code &= ~BITMASK_HOME | ||
| + | button_code |= (home << 2) & BITMASK_HOME | ||
| + | |||
| + | button_code &= ~BITMASK_JS | ||
| + | button_code |= (joystick << 4) & BITMASK_JS | ||
| + | |||
| + | button_code &= ~BITMASK_ZERO | ||
| + | button_code |= (zero_halt << 6) & BITMASK_ZERO | ||
| + | |||
| + | return button_code | ||
| + | |||
| + | def main(): | ||
| + | button_code = create_button_code(at=1, | ||
| + | print(button_code) | ||
| + | # prints 5 | ||
| + | | ||
| + | if __name__ == " | ||
| + | main() | ||
| + | |||
| + | </ | ||
| + | <-- | ||
| + | |||
| + | ===== Parse Button Flag ===== | ||
| + | |||
| + | --> Python Parse Button Flag | ||
| + | <code python asi_parse_button_flag.py> | ||
| + | # the value returned from EXTRA M? | ||
| + | button_flag_byte = 127 | ||
| + | |||
| + | # bit masks | ||
| + | mask_at | ||
| + | mask_home = 0x0C # 00001100 | ||
| + | mask_js | ||
| + | mask_zero = 0xC0 # 11000000 | ||
| + | |||
| + | # get the button states from button_flag_byte | ||
| + | btn_at | ||
| + | btn_home = (button_flag_byte & mask_home) >> 2 | ||
| + | btn_js | ||
| + | btn_zero = (button_flag_byte & mask_zero) >> 6 | ||
| + | |||
| + | # show the results in decimal and binary | ||
| + | print(f" | ||
| + | print(f" | ||
| + | print(f" | ||
| + | print(f" | ||
| + | print(f" | ||
| + | |||
| + | # console output: | ||
| + | # button_flag_byte = 127 (binary 01111111) | ||
| + | # btn_at = 3 (binary 11) | ||
| + | # btn_home = 3 (binary 11) | ||
| + | # btn_js = 3 (binary 11) | ||
| + | # btn_zero = 1 (binary 01) | ||
| + | </ | ||
| + | <-- | ||
| ===== Status Byte ===== | ===== Status Byte ===== | ||
| Line 5: | Line 92: | ||
| --> Python Status Byte | --> Python Status Byte | ||
| - | <code python | + | <code python |
| # /// script | # /// script | ||
| # dependencies = [" | # dependencies = [" | ||
| Line 86: | Line 173: | ||
| --> Python User String | --> Python User String | ||
| - | <code python | + | <code python |
| # /// script | # /// script | ||
| # dependencies = [" | # dependencies = [" | ||
Address: 29391 W Enid Rd. Eugene, OR 97402, USA | Phone: +1 (541) 461-8181
python_code.1743033434.txt.gz · Last modified: by brandon
