Sensitivity Converter now working! Rough sensitivity values for now
This commit is contained in:
66
src/main.cpp
66
src/main.cpp
@ -1,19 +1,75 @@
|
||||
#include <Arduino.h>
|
||||
#include <USB.h>
|
||||
#include <USBHIDMouse.h>
|
||||
#include <tusb.h>
|
||||
|
||||
USBHIDMouse Mouse;
|
||||
|
||||
#define LED_BUILTIN 48
|
||||
|
||||
const int buttonPin = 0;
|
||||
int previousButtonState = HIGH;
|
||||
|
||||
void smoothMouseMove(int xOffset, int yOffset, unsigned long durationMs, float steps) {
|
||||
if (steps <= 0) {
|
||||
// Avoid division by zero or infinite loop if steps is non-positive
|
||||
Mouse.move(xOffset, yOffset); // Fallback to instant move
|
||||
return;
|
||||
}
|
||||
|
||||
// Calculate the movement per step for X and Y
|
||||
float xStep = (float)xOffset / steps;
|
||||
float yStep = (float)yOffset / steps;
|
||||
|
||||
// Calculate the delay between each step
|
||||
unsigned long delayPerStep = durationMs / steps;
|
||||
|
||||
// Perform the movement in small steps
|
||||
for (int i = 0; i < steps; i++) {
|
||||
// Move the mouse by the calculated step amount.
|
||||
// We cast to int because Mouse.move expects integers,
|
||||
// but float calculations ensure more accurate distribution over steps.
|
||||
Mouse.move((int)xStep, (int)yStep);
|
||||
delay(delayPerStep); // Pause for a short duration
|
||||
}
|
||||
|
||||
// Handle any remaining fractional movement due to integer casting
|
||||
// This ensures the mouse ends up exactly at the target offset
|
||||
int remainingX = xOffset - (int)(xStep * steps);
|
||||
int remainingY = yOffset - (int)(yStep * steps);
|
||||
if (remainingX != 0 || remainingY != 0) {
|
||||
Mouse.move(remainingX, remainingY);
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
delay(1000);
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.println("ESP32-S3 Blink Starting...");
|
||||
Serial.println("Starting ESP32-S3 USB Mouse");
|
||||
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
|
||||
USB.begin();
|
||||
Mouse.begin();
|
||||
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Serial.println("Beep Beep...");
|
||||
int buttonState = digitalRead(buttonPin);
|
||||
const int purepixels = 8182;
|
||||
const int kiripurepixels = 27300;
|
||||
|
||||
const int input = purepixels;
|
||||
|
||||
if ((buttonState != previousButtonState) && (buttonState == LOW)) {
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
smoothMouseMove(input, 0, 1000, (input / 10));
|
||||
delay(500);
|
||||
Serial.println("Button Pressed - Mouse should have sent event.");
|
||||
}
|
||||
previousButtonState = buttonState;
|
||||
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
delay(500);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
delay(1000);
|
||||
}
|
||||
Reference in New Issue
Block a user