|
| 1 | +# |
| 2 | +# @file scripts/example.py |
| 3 | +# @brief Example Python file demonstrating usage of the superkey library. |
| 4 | +# |
| 5 | +# @author Chris Vig (chris@invictus.so) |
| 6 | +# @date 2025-08-30 |
| 7 | +# @cpyrt © 2025 by Chris Vig. Licensed under the GNU General Public License v3 (GPLv3). |
| 8 | +# |
| 9 | + |
| 10 | +# ------------------------------------------------------ IMPORTS ------------------------------------------------------- |
| 11 | + |
| 12 | +import time |
| 13 | + |
| 14 | +from superkey import * |
| 15 | + |
| 16 | +# ----------------------------------------------------- PROCEDURES ----------------------------------------------------- |
| 17 | + |
| 18 | +def demo_autokey(): |
| 19 | + """ |
| 20 | + Demonstrates the "autokey" command. |
| 21 | + """ |
| 22 | + with superkey_intf.SuperKeyInterface() as intf: |
| 23 | + print('Keying "cq cq"...') |
| 24 | + intf.autokey('cq cq') |
| 25 | + time.sleep(6.) |
| 26 | + |
| 27 | +def demo_panic(): |
| 28 | + """ |
| 29 | + Demonstrates the "panic" command. |
| 30 | + """ |
| 31 | + with superkey_intf.SuperKeyInterface() as intf: |
| 32 | + print('Keying a very long string...') |
| 33 | + intf.autokey('very long string that will not get fully keyed') |
| 34 | + time.sleep(2.) |
| 35 | + print('Sending panic command...') |
| 36 | + intf.panic() |
| 37 | + time.sleep(2.) |
| 38 | + |
| 39 | +def demo_ping(): |
| 40 | + """ |
| 41 | + Demonstrates the "ping" command. |
| 42 | + """ |
| 43 | + with superkey_intf.SuperKeyInterface() as intf: |
| 44 | + intf.ping() |
| 45 | + print('Ping succeeded!') |
| 46 | + time.sleep(2.) |
| 47 | + |
| 48 | +def demo_restore_default_config(): |
| 49 | + """ |
| 50 | + Demonstrates the "restore default configuration" command. |
| 51 | + """ |
| 52 | + with superkey_intf.SuperKeyInterface() as intf: |
| 53 | + # Set buzzer frequency |
| 54 | + print('Setting frequency to 900 Hz...') |
| 55 | + intf.set_buzzer_frequency(900) |
| 56 | + intf.autokey('cq') |
| 57 | + time.sleep(3.) |
| 58 | + # Restore config |
| 59 | + print('Restoring default configuration...') |
| 60 | + intf.restore_default_config() |
| 61 | + intf.autokey('cq') |
| 62 | + time.sleep(3.) |
| 63 | + |
| 64 | +def demo_set_buzzer_enabled(): |
| 65 | + """ |
| 66 | + Demonstrates the "set buzzer enabled" command. |
| 67 | + """ |
| 68 | + with superkey_intf.SuperKeyInterface() as intf: |
| 69 | + # Buzzer disabled |
| 70 | + print('Disabling buzzer...') |
| 71 | + intf.set_buzzer_enabled(False) |
| 72 | + intf.autokey('cq') |
| 73 | + time.sleep(3.) |
| 74 | + # Buzzer enabled |
| 75 | + print('Enabling buzzer...') |
| 76 | + intf.set_buzzer_enabled(True) |
| 77 | + intf.autokey('cq') |
| 78 | + time.sleep(3.) |
| 79 | + |
| 80 | +def demo_set_buzzer_frequency(): |
| 81 | + """ |
| 82 | + Demonstrates the "set buzzer frequency" command. |
| 83 | + """ |
| 84 | + with superkey_intf.SuperKeyInterface() as intf: |
| 85 | + intf.set_buzzer_enabled(True) |
| 86 | + # Frequency 800 Hz |
| 87 | + print('Setting frequency to 800 Hz...') |
| 88 | + intf.set_buzzer_frequency(800) |
| 89 | + intf.autokey('cq') |
| 90 | + time.sleep(3.) |
| 91 | + # Frequency 700 Hz |
| 92 | + print('Setting frequency to 700 Hz...') |
| 93 | + intf.set_buzzer_frequency(700) |
| 94 | + intf.autokey('cq') |
| 95 | + time.sleep(3.) |
| 96 | + |
| 97 | +# --------------------------------------------------- MAIN PROCEDURE --------------------------------------------------- |
| 98 | + |
| 99 | +if __name__ == '__main__': |
| 100 | + # Run all demos |
| 101 | + demo_autokey() |
| 102 | + demo_panic() |
| 103 | + demo_ping() |
| 104 | + demo_restore_default_config() |
| 105 | + demo_set_buzzer_enabled() |
| 106 | + demo_set_buzzer_frequency() |
0 commit comments