Skip to content

Commit

Permalink
Revert "Cleanup debug (#1048)"
Browse files Browse the repository at this point in the history
This reverts commit 8fa5259.
  • Loading branch information
regicidalplutophage authored Nov 19, 2024
1 parent 8fa5259 commit 4411d16
Show file tree
Hide file tree
Showing 24 changed files with 78 additions and 103 deletions.
1 change: 1 addition & 0 deletions boards/atreus62/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
keyboard.modules = [layers, encoder, macros]

keyboard.tap_time = 250
keyboard.debug_enabled = False


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

# keyboard.debug_enabled = True

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

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: 1 addition & 0 deletions boards/fingerpunch/ffkb/other_pro_micro/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

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

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

keyboard = KMKKeyboard()

keyboard.debug_enabled = False
keyboard.tap_time = 750

_______ = KC.TRNS
Expand Down
1 change: 1 addition & 0 deletions boards/kyria/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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: 1 addition & 0 deletions boards/splitkb/aurora/lily58/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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: 4 additions & 0 deletions docs/en/config_and_keymap.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ 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: 2 additions & 22 deletions docs/en/debugging.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,13 @@
# 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.

## 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.

general:
```python
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, '!')
keyboard.debug_enabled = True
```

## 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: 1 addition & 0 deletions docs/en/encoder.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ 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: 5 additions & 1 deletion docs/en/extension_stringy_keymaps.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ 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: 2 additions & 5 deletions kmk/extensions/led.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@

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

debug = Debug(__name__)
from kmk.utils import clamp


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

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

debug = Debug(__name__)


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

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


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

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


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

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

return keyboard

Expand Down
1 change: 1 addition & 0 deletions kmk/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ 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: 8 additions & 0 deletions kmk/kmk_keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@ 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: 8 additions & 11 deletions kmk/modules/adns9800.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
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 @@ -180,17 +177,17 @@ def during_bootup(self, keyboard):
self.adns_write(REG.Configuration_I, 0x10)
microcontroller.delay_us(self.tsww)

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

return

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

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

def after_matrix_scan(self, keyboard):
return
Expand Down
13 changes: 4 additions & 9 deletions kmk/modules/encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
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 @@ -110,6 +107,7 @@ 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 @@ -180,8 +178,7 @@ def __init__(self, i2c, address, is_inverted=False):
try:
from adafruit_seesaw import digitalio, neopixel, rotaryio, seesaw
except ImportError:
if debug.enabled:
debug('seesaw missing')
print('seesaw missing')
return

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

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

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

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

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 @@ -76,8 +73,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:
debug('No midi device found.')
# if debug_enabled:
print('No midi device found.')

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

0 comments on commit 4411d16

Please sign in to comment.