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

Periodic hang of MSEADVUARTUSBH firmware #4

Open
ATMakersBill opened this issue Mar 28, 2022 · 0 comments
Open

Periodic hang of MSEADVUARTUSBH firmware #4

ATMakersBill opened this issue Mar 28, 2022 · 0 comments

Comments

@ATMakersBill
Copy link

Hello gdsports,

Thanks again for all this work.

The Mouse firmware is hanging for me. It sends reports across the UART for movements with appropriate start and end markers. I'm able to decode them and pull the horizontal, vertical, and mouse button bytes from the report. However, after between 10 and 100 seconds into sending them it just stops. I get no response from the coprocessor until it is reset. I suspect a seg fault on the M0, but have no way to debug it.

I have tried your .UF2 file as well as compiling my own with some tweaks like turning on debugging and changing the UART speed to no avail... it eventually just hangs. Oddly, it seems to fail more quickly if I click the mouse or simulate "dragging" the mouse. Also, it seems like click events (without motion) are not reported.

Do you have any ideas on this? I am trying to make a mouse filter so that I can remove shakes, force orthogonality (vert/hor motion only), and remap buttons on arbitrary devices. When it works the code below actually does an interesting job of removing impulse movements.

Here's the code I'm using - it's a variant of your keyboard parser in CP

import board
import busio
import time
import usb_hid
import math
from adafruit_hid.mouse import Mouse
mouse = Mouse(usb_hid.devices)


def applyTransform(hor, vert):
    LOGSTYLE=1
    style=LOGSTYLE
    print((hor, vert))
    if (style == LOGSTYLE):
        hor *= 6
        vert *= 6
        if (hor > 0):
            hor = math.log(hor)
        elif (hor < 0):
            hor = -1*math.log(-1*hor)
        if (vert > 0):
            vert = math.log(vert)
        elif (vert < 0):
            vert = -1*math.log(-1*vert)
    return (int(hor), int(vert))

STX=0x02
ETX=0x03

uart = busio.UART(board.TX, board.RX, baudrate=921600)
while True:
#    time.sleep(.01)
    data = uart.read(7)

    if data is not None:
        if (len(data) == 7) and (data[0] == STX) and (True or data[1] == 36) and (data[6] == ETX):
            #print("good", data[1], data[2:6])
            buttons = data[2]
            hor = data[3]
            if (hor > 127):
                hor = hor - 255
            vert = data[4]
            if (vert > 127):
                vert = vert - 255
            vert = vert
#            print((buttons, hor, vert))
            (hor, vert) = applyTransform(hor, vert)
            mouse.move(hor, vert)

        else:
            # Scan for STX ... ETX to resync
            print("sync", data)
            report = bytearray(7)
            for i in range(0, len(data)):
                if data[i] == STX:
                    report = data[i:len(data)] + uart.read(7-(len(data)-i))
#                    print("sync2", report)
#                    if (len(report) == 7) and (report[0] == STX) and (True or report[1] == 0x08) and (report[6] == ETX):
#                        print("sync3",report[2:6])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant