Make scrolling utilize mouse_kinetic_state_t, just like mouse movements. Fix scrolling issue by making distance float. Add new debug functions for ints and float.
This commit is contained in:
@@ -39,3 +39,23 @@ void SetDebugBufferUint32(uint32_t offset, uint32_t value)
|
||||
{
|
||||
SetBufferUint32(DebugBuffer, offset, value);
|
||||
}
|
||||
|
||||
void SetDebugBufferInt8(uint32_t offset, int8_t value)
|
||||
{
|
||||
SetBufferInt8(DebugBuffer, offset, value);
|
||||
}
|
||||
|
||||
void SetDebugBufferInt16(uint32_t offset, int16_t value)
|
||||
{
|
||||
SetBufferInt16(DebugBuffer, offset, value);
|
||||
}
|
||||
|
||||
void SetDebugBufferInt32(uint32_t offset, int32_t value)
|
||||
{
|
||||
SetBufferInt32(DebugBuffer, offset, value);
|
||||
}
|
||||
|
||||
void SetDebugBufferFloat(uint32_t offset, float value)
|
||||
{
|
||||
*(float*)(DebugBuffer + offset) = value;
|
||||
}
|
||||
|
||||
@@ -17,4 +17,10 @@
|
||||
void SetDebugBufferUint16(uint32_t offset, uint16_t value);
|
||||
void SetDebugBufferUint32(uint32_t offset, uint32_t value);
|
||||
|
||||
void SetDebugBufferInt8(uint32_t offset, int8_t value);
|
||||
void SetDebugBufferInt16(uint32_t offset, int16_t value);
|
||||
void SetDebugBufferInt32(uint32_t offset, int32_t value);
|
||||
|
||||
void SetDebugBufferFloat(uint32_t offset, float value);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -25,8 +25,8 @@
|
||||
uint8_t buttons;
|
||||
int16_t x;
|
||||
int16_t y;
|
||||
int8_t wheelX;
|
||||
int8_t wheelY;
|
||||
int8_t wheelX;
|
||||
} ATTR_PACKED usb_mouse_report_t;
|
||||
|
||||
// Variables:
|
||||
|
||||
@@ -15,14 +15,13 @@
|
||||
#include "timer.h"
|
||||
#include "key_debouncer.h"
|
||||
#include "config_parser/parse_keymap.h"
|
||||
#include "usb_commands/usb_command_get_debug_buffer.h"
|
||||
|
||||
uint32_t UsbReportUpdateTime = 0;
|
||||
static uint32_t elapsedTime;
|
||||
|
||||
static uint16_t doubleTapSwitchLayerTimeout = 300;
|
||||
|
||||
static float mouseScrollSpeed = 0.1;
|
||||
|
||||
static bool activeMouseStates[ACTIVE_MOUSE_STATES_COUNT];
|
||||
|
||||
static mouse_kinetic_state_t mouseMoveState = {
|
||||
@@ -36,7 +35,18 @@ static mouse_kinetic_state_t mouseMoveState = {
|
||||
.baseSpeed = 500,
|
||||
.acceleratedSpeed = 1000,
|
||||
};
|
||||
//static mouse_kinetic_state_t mouseScrollState;
|
||||
|
||||
static mouse_kinetic_state_t mouseScrollState = {
|
||||
.upState = SerializedMouseAction_ScrollDown,
|
||||
.downState = SerializedMouseAction_ScrollUp,
|
||||
.leftState = SerializedMouseAction_ScrollLeft,
|
||||
.rightState = SerializedMouseAction_ScrollRight,
|
||||
.initialSpeed = 6,
|
||||
.acceleration = 6,
|
||||
.deceleratedSpeed = 6,
|
||||
.baseSpeed = 12,
|
||||
.acceleratedSpeed = 24,
|
||||
};
|
||||
|
||||
void processMouseKineticState(mouse_kinetic_state_t *kineticState)
|
||||
{
|
||||
@@ -77,7 +87,8 @@ void processMouseKineticState(mouse_kinetic_state_t *kineticState)
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t distance = kineticState->currentSpeed * elapsedTime / 1000;
|
||||
float distance = kineticState->currentSpeed * elapsedTime / 1000;
|
||||
kineticState->distance = distance;
|
||||
|
||||
if (activeMouseStates[kineticState->leftState]) {
|
||||
kineticState->xSum -= distance;
|
||||
@@ -100,6 +111,8 @@ void processMouseKineticState(mouse_kinetic_state_t *kineticState)
|
||||
float ySumFrac = modff(kineticState->ySum, &ySumInt);
|
||||
kineticState->ySum = ySumFrac;
|
||||
kineticState->yOut = ySumInt;
|
||||
} else {
|
||||
kineticState->currentSpeed = 0; // to be removed
|
||||
}
|
||||
|
||||
kineticState->prevMouseSpeed = mouseSpeed;
|
||||
@@ -114,34 +127,17 @@ void processMouseActions()
|
||||
mouseMoveState.xOut = 0;
|
||||
mouseMoveState.yOut = 0;
|
||||
|
||||
bool isScrollAction = activeMouseStates[SerializedMouseAction_ScrollUp] ||
|
||||
activeMouseStates[SerializedMouseAction_ScrollDown] ||
|
||||
activeMouseStates[SerializedMouseAction_ScrollLeft] ||
|
||||
activeMouseStates[SerializedMouseAction_ScrollRight];
|
||||
|
||||
static float mouseScrollDistanceSum = 0;
|
||||
if (isScrollAction) {
|
||||
mouseScrollDistanceSum += mouseScrollSpeed;
|
||||
float mouseScrollDistanceIntegerSum;
|
||||
float mouseScrollDistanceFractionSum = modff(mouseScrollDistanceSum, &mouseScrollDistanceIntegerSum);
|
||||
|
||||
if (mouseScrollDistanceIntegerSum) {
|
||||
if (activeMouseStates[SerializedMouseAction_ScrollUp]) {
|
||||
ActiveUsbMouseReport->wheelX = mouseScrollDistanceIntegerSum;
|
||||
} else if (activeMouseStates[SerializedMouseAction_ScrollDown]) {
|
||||
ActiveUsbMouseReport->wheelX = -mouseScrollDistanceIntegerSum;
|
||||
}
|
||||
|
||||
if (activeMouseStates[SerializedMouseAction_ScrollRight]) {
|
||||
ActiveUsbMouseReport->wheelY = mouseScrollDistanceIntegerSum;
|
||||
} else if (activeMouseStates[SerializedMouseAction_ScrollLeft]) {
|
||||
ActiveUsbMouseReport->wheelY = -mouseScrollDistanceIntegerSum;
|
||||
}
|
||||
mouseScrollDistanceSum = mouseScrollDistanceFractionSum;
|
||||
}
|
||||
} else {
|
||||
mouseScrollDistanceSum = 0;
|
||||
}
|
||||
processMouseKineticState(&mouseScrollState);
|
||||
ActiveUsbMouseReport->wheelX = mouseScrollState.xOut;
|
||||
*(float*)(DebugBuffer + 50) = mouseScrollState.currentSpeed;
|
||||
*(uint16_t*)(DebugBuffer + 54) = mouseScrollState.xOut;
|
||||
*(float*)(DebugBuffer + 56) = mouseScrollState.xSum;
|
||||
*(float*)(DebugBuffer + 60) = mouseScrollState.distance;
|
||||
// SetDebugBufferFloat(60, mouseScrollState.currentSpeed);
|
||||
ActiveUsbMouseReport->wheelY = mouseScrollState.yOut;
|
||||
// SetDebugBufferFloat(62, mouseScrollState.ySum);
|
||||
mouseScrollState.xOut = 0;
|
||||
mouseScrollState.yOut = 0;
|
||||
|
||||
if (activeMouseStates[SerializedMouseAction_LeftClick]) {
|
||||
ActiveUsbMouseReport->buttons |= MouseButton_Left;
|
||||
@@ -152,7 +148,6 @@ void processMouseActions()
|
||||
if (activeMouseStates[SerializedMouseAction_RightClick]) {
|
||||
ActiveUsbMouseReport->buttons |= MouseButton_Right;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static layer_id_t previousLayer = LayerId_Base;
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
serialized_mouse_action_t rightState;
|
||||
mouse_speed_t prevMouseSpeed;
|
||||
float currentSpeed;
|
||||
float distance;
|
||||
float targetSpeed;
|
||||
float initialSpeed;
|
||||
float acceleration;
|
||||
|
||||
@@ -45,6 +45,21 @@ void SetBufferUint32(uint8_t *buffer, uint32_t offset, uint32_t value)
|
||||
*(uint32_t*)(buffer + offset) = value;
|
||||
}
|
||||
|
||||
void SetBufferInt8(uint8_t *buffer, uint32_t offset, int8_t value)
|
||||
{
|
||||
*(int8_t*)(buffer + offset) = value;
|
||||
}
|
||||
|
||||
void SetBufferInt16(uint8_t *buffer, uint32_t offset, int16_t value)
|
||||
{
|
||||
*(int16_t*)(buffer + offset) = value;
|
||||
}
|
||||
|
||||
void SetBufferInt32(uint8_t *buffer, uint32_t offset, int32_t value)
|
||||
{
|
||||
*(int32_t*)(buffer + offset) = value;
|
||||
}
|
||||
|
||||
void SetBufferUint8Be(uint8_t *buffer, uint32_t offset, uint8_t value)
|
||||
{
|
||||
buffer[offset] = value;
|
||||
@@ -63,3 +78,8 @@ void SetBufferUint32Be(uint8_t *buffer, uint32_t offset, uint32_t value)
|
||||
buffer[offset+2] = (value >> 8) & 0xff;
|
||||
buffer[offset+3] = (value >> 0) & 0xff;
|
||||
}
|
||||
|
||||
void SetBufferFloat(uint8_t *buffer, uint32_t offset, float value)
|
||||
{
|
||||
*(float*)(buffer + offset) = value;
|
||||
}
|
||||
|
||||
@@ -19,8 +19,14 @@
|
||||
void SetBufferUint16(uint8_t *buffer, uint32_t offset, uint16_t value);
|
||||
void SetBufferUint32(uint8_t *buffer, uint32_t offset, uint32_t value);
|
||||
|
||||
void SetBufferInt8(uint8_t *buffer, uint32_t offset, int8_t value);
|
||||
void SetBufferInt16(uint8_t *buffer, uint32_t offset, int16_t value);
|
||||
void SetBufferInt32(uint8_t *buffer, uint32_t offset, int32_t value);
|
||||
|
||||
void SetBufferUint8Be(uint8_t *buffer, uint32_t offset, uint8_t value);
|
||||
void SetBufferUint16Be(uint8_t *buffer, uint32_t offset, uint16_t value);
|
||||
void SetBufferUint32Be(uint8_t *buffer, uint32_t offset, uint32_t value);
|
||||
|
||||
void SetBufferFloat(uint8_t *buffer, uint32_t offset, float value);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user