You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
trying to make high resolution scroll wheel I know it should be using the wheel 0x09, 0x38, but i can get it to scroll but not smoothly i also know the resolution can be set with : 0x09, 0x48, // USAGE (Resolution Multiplier) but i cannot get it to work
this is what i have so far it works just not high res or smooth
float mapFloat(float value, float fromLow, float fromHigh, float toLow, float toHigh, float offset) { // Map the value to the new range float mappedValue = (value - fromLow) * (toHigh - toLow) / (fromHigh - fromLow) + toLow;
// Apply the offset after scaling mappedValue += offset; // Clamp the result within the target range if (toLow < toHigh) { return fmax(toLow, fmin(mappedValue, toHigh)); } else { return fmax(toHigh, fmin(mappedValue, toLow)); }
struct attribute((packed)) reportHID_t { //uint8_t id = 1; uint32_t buttons = 0; int16_t X = 0; int16_t Y = 0; int16_t Z = 0; int16_t RX = 0; int16_t RY = 0; int16_t RZ = 0; int16_t wheel = 0; int16_t Slider = 0; };
reportHID_t reportHID;
// USB HID object. For ESP32 these values cannot be changed after this declaration // desc report, desc len, protocol, interval (1= 1000hz, 2= 500hz, 3= 333hz), use out endpoint Adafruit_USBD_HID HID(sixteen_bit_desc, sizeof(sixteen_bit_desc), HID_ITF_PROTOCOL_NONE, 1, false);
void setup() { delay (1);
HID.begin();
//Serial.begin(115200); Wire.setSDA(0); // SDA on GPIO 0 Wire.setSCL(1); // SCL on GPIO 1 Wire.begin(); // Initialize first I2C bus and AS5600
encoder.initializeI2C();
}
void loop() { if (!HID.ready()) return;
static float prevAngle = 0; int buttons = 0; int pulse = 0;
float angle = encoder.angleRead();
// --- Compute delta with wrap-around correction --- float delta = angle - prevAngle; if (delta > 180.0) delta -= 360.0; if (delta < -180.0) delta += 360.0;
// --- Convert delta to pulse direction --- if (delta > 0.5) { // small threshold to avoid jitter pulse = 1; } else if (delta < -0.5) { pulse = -1; } else { pulse = 0; }
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
trying to make high resolution scroll wheel I know it should be using the wheel 0x09, 0x38,
but i can get it to scroll but not smoothly i also know the resolution can be set with :
0x09, 0x48, // USAGE (Resolution Multiplier)
but i cannot get it to work
this is what i have so far it works just not high res or smooth
`#include <Adafruit_TinyUSB.h>
#include <SimpleKalmanFilter.h>
#include <Wire.h>
#include "MT6701.h"
MT6701 encoder;
const int16_t MAX_JOYSTICK_VALUE = 32767;
const int16_t MIN_JOYSTICK_VALUE = -32768;
int counter = 0;
unsigned long lastDebounceTime = 0;
const unsigned long debounceDelay = 2; // ms (filter contact noise)
uint8_t lastEncoded = 0;
uint8_t encoderValue = 0;
unsigned long lastButtonPress = 0;
float pulse=0;
float mapFloat(float value, float fromLow, float fromHigh, float toLow, float toHigh, float offset) {
// Map the value to the new range
float mappedValue = (value - fromLow) * (toHigh - toLow) / (fromHigh - fromLow) + toLow;
}
uint8_t const sixteen_bit_desc[] =
{
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x01, // USAGE (Joystick)
0xa1, 0x01, // COLLECTION (Application)
0xa1, 0x00, // COLLECTION (Physical)
0x85, 0x01, // REPORT_ID (1)
};
struct attribute((packed)) reportHID_t {
//uint8_t id = 1;
uint32_t buttons = 0;
int16_t X = 0;
int16_t Y = 0;
int16_t Z = 0;
int16_t RX = 0;
int16_t RY = 0;
int16_t RZ = 0;
int16_t wheel = 0;
int16_t Slider = 0;
};
reportHID_t reportHID;
// USB HID object. For ESP32 these values cannot be changed after this declaration
// desc report, desc len, protocol, interval (1= 1000hz, 2= 500hz, 3= 333hz), use out endpoint
Adafruit_USBD_HID HID(sixteen_bit_desc, sizeof(sixteen_bit_desc), HID_ITF_PROTOCOL_NONE, 1, false);
void setup() {
delay (1);
//Serial.begin(115200);
Wire.setSDA(0); // SDA on GPIO 0
Wire.setSCL(1); // SCL on GPIO 1
Wire.begin();
// Initialize first I2C bus and AS5600
encoder.initializeI2C();
}
void loop() {
if (!HID.ready()) return;
static float prevAngle = 0;
int buttons = 0;
int pulse = 0;
float angle = encoder.angleRead();
// --- Compute delta with wrap-around correction ---
float delta = angle - prevAngle;
if (delta > 180.0) delta -= 360.0;
if (delta < -180.0) delta += 360.0;
// --- Convert delta to pulse direction ---
if (delta > 0.5) { // small threshold to avoid jitter
pulse = 1;
} else if (delta < -0.5) {
pulse = -1;
} else {
pulse = 0;
}
prevAngle = angle;
// --- Debug ---
Serial.print("Angle: "); Serial.print(angle);
Serial.print(" | Delta: "); Serial.print(delta);
Serial.print(" | Pulse: "); Serial.println(pulse);
// --- Send HID report ---
reportHID.wheel = delta;
reportHID.buttons = buttons;
reportHID.RX = 0;
reportHID.RY = 0;
reportHID.RZ = 0;
reportHID.X = 0;
reportHID.Y = 0;
reportHID.Z = 0;
HID.sendReport(1, &reportHID, sizeof(reportHID_t));
delay(10); // small debounce delay
}
`
Beta Was this translation helpful? Give feedback.
All reactions