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

Cleanup debug #1048

Merged
merged 3 commits into from
Nov 19, 2024
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
1 change: 0 additions & 1 deletion boards/atreus62/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
keyboard.modules = [layers, encoder, macros]

keyboard.tap_time = 250
keyboard.debug_enabled = False


# custom keys
Expand Down
2 changes: 0 additions & 2 deletions boards/crowboard/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,5 @@
# ((KC.VOLD, KC.VOLU),(KC.VOLD, KC.VOLU),), # Layer 4
# ]

# keyboard.debug_enabled = True

if __name__ == '__main__':
keyboard.go()
1 change: 0 additions & 1 deletion boards/fingerpunch/ffkb/nice_nano/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

keyboard = kb.KMKKeyboard()
keyboard.modules = [combos, dyn_seq, layers, sticky_keys]
keyboard.debug_enabled = False

# Convenience variables for the Keymap
_______ = KC.TRNS
Expand Down
1 change: 0 additions & 1 deletion boards/fingerpunch/ffkb/other_pro_micro/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

keyboard = KMKKeyboard()
keyboard.tap_time = 150
keyboard.debug_enabled = False

# Cleaner key names
_______ = KC.TRNS
Expand Down
1 change: 0 additions & 1 deletion boards/keebio/iris/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

keyboard = KMKKeyboard()

keyboard.debug_enabled = False
keyboard.tap_time = 750

_______ = KC.TRNS
Expand Down
1 change: 0 additions & 1 deletion boards/kyria/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from kmk.modules.split import Split, SplitType

keyboard = KMKKeyboard()
keyboard.debug_enabled = True

keyboard.modules.append(Layers())
keyboard.modules.append(HoldTap())
Expand Down
1 change: 0 additions & 1 deletion boards/splitkb/aurora/lily58/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from kmk.modules.split import Split

keyboard = KMKKeyboard()
# keyboard.debug_enabled = True

# Adding modules
# Using drive names (LILY58L, LILY58R) to recognize sides; use split_side arg if you're not doing it
Expand Down
4 changes: 0 additions & 4 deletions docs/en/config_and_keymap.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ keyboard.keymap = [[KC.A, KC.B]]

You can further define a bunch of other stuff:

- `keyboard.debug_enabled` which will spew a ton of debugging information to the serial
console. This is very rarely needed, but can provide very valuable information
if you need to open an issue.

- `keyboard.tap_time` which defines how long `KC.TT` and `KC.LT` will wait before
considering a key "held" (see `layers.md`).

24 changes: 22 additions & 2 deletions docs/en/debugging.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
# 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:
general.

## KMK's Debug Utility

KMK has a convenient debug utility that adds a timestamp in milliseconds since boot and a message origin to distinguish subsystems to debug statements.

```python
keyboard.debug_enabled = True
from kmk.utils import Debug

# Create a debug source with the current file as message origin
debug = Debug(__name__)

# For completeness: Force enable/disable debug output. This is handled
# automatically -- you will most likely never have to use this:
# debug.enabled = True/False

# KMK idiomatic debug with guard clause
var = 'concatenate'
if debug.enabled:
debug('Arguments ', var, '!')
```

## Connecting to the Serial Console

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)
1 change: 0 additions & 1 deletion docs/en/encoder.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ keyboard.diode_orientation = DiodeOrientation.COLUMNS
encoder_handler.pins = ((board.GP17, board.GP15, board.GP14, False),)

keyboard.tap_time = 250
keyboard.debug_enabled = False


# Filler keys
Expand Down
6 changes: 1 addition & 5 deletions docs/en/extension_stringy_keymaps.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,10 @@ keyboard.keymap = [[ 'A' , 'B', 'RESET' ]]

stringyKeymaps = StringyKeymaps()

# Enabling debug will show each replacement or failure.
# This is recommended during the initial development of a keyboard.
# stringyKeymaps.debug_enable = True

keyboard.extensions.append(stringyKeymaps)
```

It should be noted that these are **not** ASCII. The string is **not** what
will be sent to the computer. The examples above have no functional difference.

When utilizing argumented keys, such as `KC.MO(layer)`, it's not possible to use a string like `'MO(layer)'` instead employ the standard notation of e.g. `KC.MO(1)` in your keymap.
When utilizing argumented keys, such as `KC.MO(layer)`, it's not possible to use a string like `'MO(layer)'` instead employ the standard notation of e.g. `KC.MO(1)` in your keymap.
2 changes: 1 addition & 1 deletion docs/en/keycodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
|-------------------------|------------------------------------------------------------------------|
| `KC.RESET` | Restarts the keyboard |
| `KC.RELOAD`, `KC.RLD` | Reloads the keyboard software, preserving any serial connections |
| `KC.DEBUG` | Toggle `debug_enabled`, which enables log spew to serial console |
| `KC.DEBUG` | Toggle `debug.enabled`, which enables log spew to serial console |
| `KC.ANY` | Any key between `A` and `/` |
| `KC.GESC` | Escape when tapped, <code>&#96;</code> when pressed with Shift or GUI |
| `KC.BKDL` | Backspace when tapped, Delete when pressed with GUI |
Expand Down
7 changes: 5 additions & 2 deletions kmk/extensions/led.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

from kmk.extensions import Extension, InvalidExtensionEnvironment
from kmk.keys import Key, make_argumented_key, make_key
from kmk.utils import clamp
from kmk.utils import Debug, clamp

debug = Debug(__name__)


class LEDKey(Key):
Expand Down Expand Up @@ -46,7 +48,8 @@ def __init__(
try:
self._leds = [pwmio.PWMOut(pin) for pin in pins_iter]
except Exception as e:
print(e)
if debug.enabled:
debug(e)
raise InvalidExtensionEnvironment(
'Unable to create pwmio.PWMOut() instance with provided led_pin'
)
Expand Down
12 changes: 9 additions & 3 deletions kmk/extensions/peg_rgb_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

from kmk.extensions import Extension
from kmk.keys import make_key
from kmk.utils import Debug

debug = Debug(__name__)


class Color:
Expand All @@ -26,10 +29,12 @@ class Color:
class Rgb_matrix_data:
def __init__(self, keys=[], underglow=[]):
if len(keys) == 0:
print('No colors passed for your keys')
if debug.enabled:
debug('No colors passed for your keys')
return
if len(underglow) == 0:
print('No colors passed for your underglow')
if debug.enabled:
debug('No colors passed for your underglow')
return
self.data = keys + underglow

Expand All @@ -39,7 +44,8 @@ def generate_led_map(
):
keys = [key_color] * number_of_keys
underglow = [underglow_color] * number_of_underglow
print(f'Rgb_matrix_data(keys={keys},\nunderglow={underglow})')
if debug.enabled:
debug('Rgb_matrix_data(keys=', keys, ', nunderglow=', underglow, ')')


class Rgb_matrix(Extension):
Expand Down
6 changes: 5 additions & 1 deletion kmk/extensions/statusled.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

from kmk.extensions import Extension, InvalidExtensionEnvironment
from kmk.keys import make_key
from kmk.utils import Debug

debug = Debug(__name__)


class statusLED(Extension):
Expand All @@ -20,7 +23,8 @@ def __init__(
try:
self._leds.append(pwmio.PWMOut(led))
except Exception as e:
print(e)
if debug.enabled:
debug(e)
raise InvalidExtensionEnvironment(
'Unable to create pulseio.PWMOut() instance with provided led_pin'
)
Expand Down
8 changes: 3 additions & 5 deletions kmk/handlers/stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ def bootloader(*args, **kwargs):


def debug_pressed(key, keyboard, KC, *args, **kwargs):
if keyboard.debug_enabled:
print('DebugDisable()')
else:
print('DebugEnable()')
from kmk.utils import Debug

keyboard.debug_enabled = not keyboard.debug_enabled
debug = Debug()
debug.enabled = not debug.enabled

return keyboard

Expand Down
1 change: 0 additions & 1 deletion kmk/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ def maybe_make_firmware_key(candidate: str) -> Optional[Key]:
((('BLE_REFRESH',), handlers.ble_refresh)),
((('BLE_DISCONNECT',), handlers.ble_disconnect)),
((('BOOTLOADER',), handlers.bootloader)),
((('DEBUG', 'DBG'), handlers.debug_pressed)),
((('HID_SWITCH', 'HID'), handlers.hid_switch)),
((('RELOAD', 'RLD'), handlers.reload)),
((('RESET',), handlers.reset)),
Expand Down
8 changes: 0 additions & 8 deletions kmk/kmk_keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,6 @@ def _process_resume_buffer(self):

self._resume_buffer_x = buffer

@property
def debug_enabled(self) -> bool:
return debug.enabled

@debug_enabled.setter
def debug_enabled(self, enabled: bool):
debug.enabled = enabled

def pre_process_key(
self,
key: Key,
Expand Down
19 changes: 11 additions & 8 deletions kmk/modules/adns9800.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
from kmk.keys import AX
from kmk.modules import Module
from kmk.modules.adns9800_firmware import firmware
from kmk.utils import Debug

debug = Debug(__name__)


class REG:
Expand Down Expand Up @@ -177,17 +180,17 @@ def during_bootup(self, keyboard):
self.adns_write(REG.Configuration_I, 0x10)
microcontroller.delay_us(self.tsww)

if keyboard.debug_enabled:
print('ADNS: Product ID ', hex(self.adns_read(REG.Product_ID)))
if debug.enabled:
debug('ADNS: Product ID ', hex(self.adns_read(REG.Product_ID)))
microcontroller.delay_us(self.tsrr)
print('ADNS: Revision ID ', hex(self.adns_read(REG.Revision_ID)))
debug('ADNS: Revision ID ', hex(self.adns_read(REG.Revision_ID)))
microcontroller.delay_us(self.tsrr)
print('ADNS: SROM ID ', hex(self.adns_read(REG.SROM_ID)))
debug('ADNS: SROM ID ', hex(self.adns_read(REG.SROM_ID)))
microcontroller.delay_us(self.tsrr)
if self.adns_read(REG.Observation) & 0x20:
print('ADNS: Sensor is running SROM')
debug('ADNS: Sensor is running SROM')
else:
print('ADNS: Error! Sensor is not running SROM!')
debug('ADNS: Error! Sensor is not running SROM!')

return

Expand All @@ -208,8 +211,8 @@ def before_matrix_scan(self, keyboard):
if delta_y:
AX.Y.move(keyboard, delta_y)

if keyboard.debug_enabled:
print('Delta: ', delta_x, ' ', delta_y)
if debug.enabled:
debug('Delta: ', delta_x, ' ', delta_y)

def after_matrix_scan(self, keyboard):
return
Expand Down
13 changes: 9 additions & 4 deletions kmk/modules/encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
from supervisor import ticks_ms

from kmk.modules import Module
from kmk.utils import Debug

debug = Debug(__name__)

# NB : not using rotaryio as it requires the pins to be consecutive

Expand Down Expand Up @@ -107,7 +110,6 @@ def button_event(self):
# return knob velocity as milliseconds between position changes (detents)
# for backwards compatibility
def vel_report(self):
# print(self._velocity)
return self._velocity


Expand Down Expand Up @@ -178,7 +180,8 @@ def __init__(self, i2c, address, is_inverted=False):
try:
from adafruit_seesaw import digitalio, neopixel, rotaryio, seesaw
except ImportError:
print('seesaw missing')
if debug.enabled:
debug('seesaw missing')
return

super().__init__(is_inverted)
Expand All @@ -189,7 +192,8 @@ def __init__(self, i2c, address, is_inverted=False):

seesaw_product = (self.seesaw.get_version() >> 16) & 0xFFFF
if seesaw_product != 4991:
print('Wrong firmware loaded? Expected 4991')
if debug.enabled:
debug('Wrong firmware loaded? Expected 4991')

self.encoder = rotaryio.IncrementalEncoder(self.seesaw)
self.seesaw.pin_mode(24, self.seesaw.INPUT_PULLUP)
Expand Down Expand Up @@ -281,7 +285,8 @@ def during_bootup(self, keyboard):
)
self.encoders.append(new_encoder)
except Exception as e:
print(e)
if debug.enabled:
debug(e)
return

def on_move_do(self, keyboard, encoder_id, state):
Expand Down
7 changes: 5 additions & 2 deletions kmk/modules/midi.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

from kmk.keys import Key, make_argumented_key
from kmk.modules import Module
from kmk.utils import Debug

debug = Debug(__name__)


class MidiKey(Key):
Expand Down Expand Up @@ -73,8 +76,8 @@ def __init__(self):
self.midi = adafruit_midi.MIDI(midi_out=usb_midi.ports[1], out_channel=0)
except IndexError:
self.midi = None
# if debug_enabled:
print('No midi device found.')
if debug.enabled:
debug('No midi device found.')

def during_bootup(self, keyboard):
return None
Expand Down
Loading
Loading