Skip to content

Commit 9ef192c

Browse files
committed
Add automatic debug logs
1 parent 12bca2c commit 9ef192c

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

docs/en/debugging.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# Debugging
2-
Debug will output most of the useful state to the console. This can be enable in your firmware
3-
by setting this in your keymap. NOTE that it will be slower, so only enable this when you
4-
need debugging.
2+
KMK's debug output is written to CircuitPython's serial console -- the one that's
3+
used for the REPL -- and is automatically enabled if it detects a connection to
4+
that console.
5+
It can also be enabled manually, though that shouldn't be necessary in
6+
general:
57
```python
68
keyboard.debug_enabled = True
79
```
810

9-
The output can be viewed by connecting to the serial port of the keybord. Please refer to [THIS](https://learn.adafruit.com/welcome-to-circuitpython/kattni-connecting-to-the-serial-console) for
10-
more information when connecting to serial console. For Linux users, we recommend [picocom](https://github.com/npat-efault/picocom) or
11-
[screen](https://www.gnu.org/software/screen/manual/screen.html)
11+
Follow for example Adafruit's beginners guide on [how to connect to the serial console](https://learn.adafruit.com/welcome-to-circuitpython/kattni-connecting-to-the-serial-console).
12+
For Linux users, we recommend [picocom](https://github.com/npat-efault/picocom)
13+
or [screen](https://www.gnu.org/software/screen/manual/screen.html)

kmk/utils.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55

66
from supervisor import ticks_ms
77

8+
from usb_cdc import console
9+
810

911
def clamp(x: int, bottom: int = 0, top: int = 100) -> int:
1012
return min(max(bottom, x), top)
1113

1214

13-
_debug_enabled = False
15+
_debug_enabled = None
1416

1517

1618
class Debug:
@@ -31,7 +33,14 @@ def __call__(self, *message: str, name: Optional[str] = None) -> None:
3133
@property
3234
def enabled(self) -> bool:
3335
global _debug_enabled
34-
return _debug_enabled
36+
if (
37+
_debug_enabled is None
38+
and console
39+
and console.connected
40+
and console.out_waiting == 0
41+
):
42+
return True
43+
return bool(_debug_enabled)
3544

3645
@enabled.setter
3746
def enabled(self, enabled: bool):

tests/mocks.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def init_circuit_python_modules_mocks():
3131

3232
sys.modules['supervisor'] = Mock()
3333
sys.modules['supervisor'].ticks_ms = ticks_ms
34+
sys.modules['usb_cdc'] = Mock()
3435

3536
from . import task
3637

util/aspell.en.pws

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
personal_ws-1.1 en 345
1+
personal_ws-1.1 en 347
22
ADNS
33
AMS
44
ANAVI
55
APA
66
AVR
77
Adafruit
8+
Adafruit's
89
Affero
910
BT
1011
BYO

0 commit comments

Comments
 (0)