Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add automatic debug logs #912

Merged
merged 1 commit into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions docs/en/debugging.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# Debugging
Debug will output most of the useful state to the console. This can be enable in your firmware
by setting this in your keymap. NOTE that it will be slower, so only enable this when you
need debugging.
KMK's debug output is written to CircuitPython's serial console -- the one that's
used for the REPL -- and is automatically enabled if it detects a connection to
that console.
It can also be enabled manually, though that shouldn't be necessary in
general:
```python
keyboard.debug_enabled = True
```

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
more information when connecting to serial console. For Linux users, we recommend [picocom](https://github.com/npat-efault/picocom) or
[screen](https://www.gnu.org/software/screen/manual/screen.html)
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).
For Linux users, we recommend [picocom](https://github.com/npat-efault/picocom)
or [screen](https://www.gnu.org/software/screen/manual/screen.html)
13 changes: 11 additions & 2 deletions kmk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@

from supervisor import ticks_ms

from usb_cdc import console


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


_debug_enabled = False
_debug_enabled = None


class Debug:
Expand All @@ -31,7 +33,14 @@ def __call__(self, *message: str, name: Optional[str] = None) -> None:
@property
def enabled(self) -> bool:
global _debug_enabled
return _debug_enabled
if (
_debug_enabled is None
and console
and console.connected
and console.out_waiting == 0
):
return True
return bool(_debug_enabled)

@enabled.setter
def enabled(self, enabled: bool):
Expand Down
1 change: 1 addition & 0 deletions tests/mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def init_circuit_python_modules_mocks():

sys.modules['supervisor'] = Mock()
sys.modules['supervisor'].ticks_ms = ticks_ms
sys.modules['usb_cdc'] = Mock()

from . import task

Expand Down
3 changes: 2 additions & 1 deletion util/aspell.en.pws
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
personal_ws-1.1 en 345
personal_ws-1.1 en 347
ADNS
AMS
ANAVI
APA
AVR
Adafruit
Adafruit's
Affero
BT
BYO
Expand Down
Loading