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

Option to change HID descriptor to use absolute coordinates #154

Open
willwade opened this issue Dec 29, 2023 · 1 comment
Open

Option to change HID descriptor to use absolute coordinates #154

willwade opened this issue Dec 29, 2023 · 1 comment

Comments

@willwade
Copy link
Contributor

willwade commented Dec 29, 2023

Is your feature request related to a problem? Please describe.
When we use Macros its hard to be really useful - e,g. drawing a circle or clicking on screen elements, because mouse is only relative. It needs to be absolute to be useful

Describe the solution you'd like
An option - I'm not sure where - that the mouse is set to be absolute rather than relative. It needs to be not the default - it can go wrong if you use this with a different screen resolution to what the user is used to

Describe alternatives you've considered
Software on the recieving device to change relative to absolute. This wouldnt work for iOS/Android

**NB: See this for inspiration. Look at the readme and mouse section - https://github.com/hrvach/deskhop) **

So heres the thinking. It's possible to accumulate the relative movements internally to maintain an accurate tally of the position, essentially creating a virtual absolute coordinate system. This method wouldn't require you to know the physical screen size but rather work within a predefined coordinate space. Here's how it could work:

Change the HID Report Descriptor: Alter the HID report descriptor on the nRF52840 to indicate that it's sending absolute coordinate data.
Accumulate Movements: Implement firmware to accumulate the relative movements from the mouse. As the mouse sends its relative movements, the firmware would add these to a running total, which represents the current position in your virtual coordinate space.

I havent read the code of deskhop very well but I imagine its doing something like this in the code - maybe in the mouse section https://github.com/hrvach/deskhop/tree/main/src

@willwade
Copy link
Contributor Author

willwade commented Dec 29, 2023

Dump of code snippets...

// Global variables for absolute positioning
int absolute_x = 0;
int absolute_y = 0;
int screen_width = 800;  // Adjust as per your screen resolution NB: I wonder whether we can set this via serial command once per session.  I'd ideally like to not have to give these dimensions. how does the desktophop thing do it?
int screen_height = 600; // Adjust as per your screen resolution


void sendBLEMouseMove(char *line) {
    // ... existing code ...

    // Convert relative movements to absolute
    x += strtol(p, NULL, 10); // Accumulate the x movement
    y += strtol(p, NULL, 10); // Accumulate the y movement

    // Clamp the values to the screen size
    if (x < 0) x = 0;
    if (y < 0) y = 0;
    if (x > screen_width) x = screen_width;
    if (y > screen_height) y = screen_height;

    // Update the global absolute position
    absolute_x = x;
    absolute_y = y;

    // ... existing code to send the movement ...
}


bool absolute_mode = false; // Default to relative mode

void toggleAbsoluteMode() {
    absolute_mode = !absolute_mode;
    if (absolute_mode) {
        // Reset the position to the center of the screen or a known position
        absolute_x = screen_width / 2;
        absolute_y = screen_height / 2;
    }
}

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