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

[BUG] Title #880

Closed
hxse opened this issue Sep 14, 2023 · 3 comments
Closed

[BUG] Title #880

hxse opened this issue Sep 14, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@hxse
Copy link

hxse commented Sep 14, 2023

I use helios rp2040, when i use SerialACE send text on Pc, i get result out of my expetation.

send_kmk: bytearray(b'switch_layer 0\n')
result_kmk: b'code.py | 8.2.6\x1b\\'

I get 8.2.6\x1b\\, It seems to be a runtime version, it is so strange, out of my expetation.
Any suggestion, Why return this thing?

my serialace2.py

from usb_cdc import data

from kmk.modules import Module

# from kmk.utils import Debug
from kmk.keys import KC

# debug = Debug(__name__)


def callback(keyboard, data: bytearray):
    print("receive", data)
    text: str = "".join([chr(i) for i in data])
    args = text.split(" ")

    if args[0] == "switch_layer":
        num = int(args[1])
        keyboard.tap_key(KC.TO(num))
        return f"success: {text}"
    return


class SerialACE(Module):
    buffer = bytearray()

    def during_bootup(self, keyboard):
        keyboard.tap_key(KC.DF(1))
        try:
            data.timeout = 0
        except AttributeError:
            pass

    def before_matrix_scan(self, keyboard):
        pass

    def after_matrix_scan(self, keyboard):
        # keyboard.tap_key(KC.DF(1))
        pass

    def process_key(self, keyboard, key, is_pressed, int_coord):
        return key

    def before_hid_send(self, keyboard):
        # Serial.data isn't initialized.
        if not data:
            return

        # Nothing to parse.
        if data.in_waiting == 0:
            return

        self.buffer.extend(data.read())
        idx = self.buffer.find(b"\n")

        # No full command yet.
        if idx == -1:
            return

        # Split off command and evaluate.
        line = self.buffer[:idx]
        self.buffer = self.buffer[idx + 1 :]

        try:
            # if debug.enabled:
            # debug(f"eval({line})")

            # ret = eval(line, {'keyboard': keyboard,'KC':KC})
            # eval so danger, run in callback

            res = callback(keyboard, line)

            data.write(bytearray(str(res) + "\n"))
        except Exception as err:
            # if debug.enabled:
            # debug(f"error: {err}")
            data.write(bytearray("error: " + str(err) + "\n"))

    def after_hid_send(self, keyboard):
        pass

    def on_powersave_enable(self, keyboard):
        pass

    def on_powersave_disable(self, keyboard):
        pass

@hxse hxse added the bug Something isn't working label Sep 14, 2023
@xs5871
Copy link
Collaborator

xs5871 commented Sep 15, 2023

If you submit a bug, please:

  1. Use the bug report template and actually fill it out as intended. There's a reason we're asking for specific information. This bug report doesn't even have a title...
  2. Make sure it's actually a bug. Asking for help or support is not a bug. If in doubt, bring up your issue in the zulip chat first.

That being said, looks like you're connected to the wrong serial interface.

@hxse
Copy link
Author

hxse commented Sep 15, 2023

@xs5871 sorry, I lost my head

@hxse
Copy link
Author

hxse commented Sep 21, 2023

import usb_cdc
usb_cdc.enable(data=True)

add code to boot.py and connect to the another port, solved my question.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants