Skip to content

Commit 7d43cc0

Browse files
authored
Initial implementation of interface serial port and Python module. (#23)
1 parent e7f4fed commit 7d43cc0

16 files changed

Lines changed: 931 additions & 16 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@
1111
.vscode/*
1212
!.vscode/c_cpp_properties.json
1313

14+
# Ignore Python cache
15+
__pycache__/
16+
1417
# Ignore build directory
1518
build/

.vscode/c_cpp_properties.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
"${workspaceFolder}/src/main"
88
],
99
"defines": [
10+
"_FEATURE_ON=1",
11+
"_FEATURE_OFF=0",
1012
"MCU=\"atmega1284p\"",
1113
"F_CPU=16000000",
12-
"_DEBUG=1",
14+
"_DEBUG=_FEATURE_ON",
1315
"_BUILD_TYPE=\"Debug\"",
14-
"_FEATURE_ON=1",
15-
"_FEATURE_OFF=0",
1616
"_FEATURE_ENABLE_DEBUG_PORT=_FEATURE_ON",
17-
"_FEATURE_OPT_DEBUG_PORT_BAUD=USART_BAUD_38400",
17+
"_FEATURE_OPT_INTF_PORT_BAUD=USART_BAUD_19200",
18+
"_FEATURE_OPT_DEBUG_PORT_BAUD=USART_BAUD_19200",
1819
"_CONFIG_DFLT_WPM=200",
1920
"_CONFIG_DFLT_WPM_ELEMENT_SCALE=1.0f",
2021
"_CONFIG_DFLT_BUZZER_ENABLED=true",

CMakeLists.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,21 @@ set(CMAKE_CXX_FLAGS_MINSIZEREL "" CACHE STRING "" FORCE)
7070

7171
# Set preprocessor defines
7272
add_compile_definitions(
73+
# Flags for features
74+
_FEATURE_ON=1
75+
_FEATURE_OFF=0
7376
# Device information
7477
MCU="${DEVICE_MCU}"
7578
F_CPU=${DEVICE_F_CPU}
7679
# Build type
7780
_BUILD_TYPE="${CMAKE_BUILD_TYPE}"
78-
$<$<CONFIG:Debug>:_DEBUG=1>
81+
$<$<CONFIG:Debug>:_DEBUG=_FEATURE_ON>
7982
$<$<CONFIG:Release>:NDEBUG>
80-
$<$<CONFIG:Release>:_DEBUG=0>
83+
$<$<CONFIG:Release>:_DEBUG=_FEATURE_OFF>
8184
$<$<CONFIG:RelWithDebInfo>:NDEBUG>
82-
$<$<CONFIG:RelWithDebuInfo>:_DEBUG=0>
85+
$<$<CONFIG:RelWithDebuInfo>:_DEBUG=_FEATURE_OFF>
8386
$<$<CONFIG:MinSizeRel>:NDEBUG>
84-
$<$<CONFIG:MinSizeRel>:_DEBUG=0>
85-
# Flags for features
86-
_FEATURE_ON=1
87-
_FEATURE_OFF=0
87+
$<$<CONFIG:MinSizeRel>:_DEBUG=_FEATURE_OFF>
8888
)
8989

9090
# Set compiler options

configuration.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@ add_compile_definitions(
2121
# -- Feature Options --
2222

2323
# Define values
24+
set(FEATURE_OPT_INTF_PORT_BAUD USART_BAUD_19200
25+
CACHE STRING "Baud rate for interface port. (usart_baud_t)")
2426
set(FEATURE_OPT_DEBUG_PORT_BAUD USART_BAUD_19200
2527
CACHE STRING "Baud rate for debug port. (usart_baud_t)")
2628

2729
# Set compile definitions
2830
add_compile_definitions(
31+
_FEATURE_OPT_INTF_PORT_BAUD=${FEATURE_OPT_INTF_PORT_BAUD}
2932
_FEATURE_OPT_DEBUG_PORT_BAUD=${FEATURE_OPT_DEBUG_PORT_BAUD}
3033
)
3134

scripts/example.py

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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()

scripts/readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# SuperKey Python Scripts
2+
3+
This file will describe the SuperKey Python scripts.

scripts/superkey/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#
2+
# @file scripts/superkey/__init__.py
3+
# @brief Init file for the superkey module.
4+
#
5+
# @author Chris Vig (chris@invictus.so)
6+
# @date 2025-08-29
7+
# @cpyrt © 2025 by Chris Vig. Licensed under the GNU General Public License v3 (GPLv3).
8+
#
9+
10+
# ------------------------------------------------------ EXPORTS -------------------------------------------------------
11+
12+
__all__ = [
13+
'superkey_intf',
14+
'superkey_types'
15+
]

0 commit comments

Comments
 (0)