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);
|
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 SetDebugBufferUint16(uint32_t offset, uint16_t value);
|
||||||
void SetDebugBufferUint32(uint32_t offset, uint32_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
|
#endif
|
||||||
|
|||||||
@@ -25,8 +25,8 @@
|
|||||||
uint8_t buttons;
|
uint8_t buttons;
|
||||||
int16_t x;
|
int16_t x;
|
||||||
int16_t y;
|
int16_t y;
|
||||||
int8_t wheelX;
|
|
||||||
int8_t wheelY;
|
int8_t wheelY;
|
||||||
|
int8_t wheelX;
|
||||||
} ATTR_PACKED usb_mouse_report_t;
|
} ATTR_PACKED usb_mouse_report_t;
|
||||||
|
|
||||||
// Variables:
|
// Variables:
|
||||||
|
|||||||
@@ -15,14 +15,13 @@
|
|||||||
#include "timer.h"
|
#include "timer.h"
|
||||||
#include "key_debouncer.h"
|
#include "key_debouncer.h"
|
||||||
#include "config_parser/parse_keymap.h"
|
#include "config_parser/parse_keymap.h"
|
||||||
|
#include "usb_commands/usb_command_get_debug_buffer.h"
|
||||||
|
|
||||||
uint32_t UsbReportUpdateTime = 0;
|
uint32_t UsbReportUpdateTime = 0;
|
||||||
static uint32_t elapsedTime;
|
static uint32_t elapsedTime;
|
||||||
|
|
||||||
static uint16_t doubleTapSwitchLayerTimeout = 300;
|
static uint16_t doubleTapSwitchLayerTimeout = 300;
|
||||||
|
|
||||||
static float mouseScrollSpeed = 0.1;
|
|
||||||
|
|
||||||
static bool activeMouseStates[ACTIVE_MOUSE_STATES_COUNT];
|
static bool activeMouseStates[ACTIVE_MOUSE_STATES_COUNT];
|
||||||
|
|
||||||
static mouse_kinetic_state_t mouseMoveState = {
|
static mouse_kinetic_state_t mouseMoveState = {
|
||||||
@@ -36,7 +35,18 @@ static mouse_kinetic_state_t mouseMoveState = {
|
|||||||
.baseSpeed = 500,
|
.baseSpeed = 500,
|
||||||
.acceleratedSpeed = 1000,
|
.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)
|
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]) {
|
if (activeMouseStates[kineticState->leftState]) {
|
||||||
kineticState->xSum -= distance;
|
kineticState->xSum -= distance;
|
||||||
@@ -100,6 +111,8 @@ void processMouseKineticState(mouse_kinetic_state_t *kineticState)
|
|||||||
float ySumFrac = modff(kineticState->ySum, &ySumInt);
|
float ySumFrac = modff(kineticState->ySum, &ySumInt);
|
||||||
kineticState->ySum = ySumFrac;
|
kineticState->ySum = ySumFrac;
|
||||||
kineticState->yOut = ySumInt;
|
kineticState->yOut = ySumInt;
|
||||||
|
} else {
|
||||||
|
kineticState->currentSpeed = 0; // to be removed
|
||||||
}
|
}
|
||||||
|
|
||||||
kineticState->prevMouseSpeed = mouseSpeed;
|
kineticState->prevMouseSpeed = mouseSpeed;
|
||||||
@@ -114,34 +127,17 @@ void processMouseActions()
|
|||||||
mouseMoveState.xOut = 0;
|
mouseMoveState.xOut = 0;
|
||||||
mouseMoveState.yOut = 0;
|
mouseMoveState.yOut = 0;
|
||||||
|
|
||||||
bool isScrollAction = activeMouseStates[SerializedMouseAction_ScrollUp] ||
|
processMouseKineticState(&mouseScrollState);
|
||||||
activeMouseStates[SerializedMouseAction_ScrollDown] ||
|
ActiveUsbMouseReport->wheelX = mouseScrollState.xOut;
|
||||||
activeMouseStates[SerializedMouseAction_ScrollLeft] ||
|
*(float*)(DebugBuffer + 50) = mouseScrollState.currentSpeed;
|
||||||
activeMouseStates[SerializedMouseAction_ScrollRight];
|
*(uint16_t*)(DebugBuffer + 54) = mouseScrollState.xOut;
|
||||||
|
*(float*)(DebugBuffer + 56) = mouseScrollState.xSum;
|
||||||
static float mouseScrollDistanceSum = 0;
|
*(float*)(DebugBuffer + 60) = mouseScrollState.distance;
|
||||||
if (isScrollAction) {
|
// SetDebugBufferFloat(60, mouseScrollState.currentSpeed);
|
||||||
mouseScrollDistanceSum += mouseScrollSpeed;
|
ActiveUsbMouseReport->wheelY = mouseScrollState.yOut;
|
||||||
float mouseScrollDistanceIntegerSum;
|
// SetDebugBufferFloat(62, mouseScrollState.ySum);
|
||||||
float mouseScrollDistanceFractionSum = modff(mouseScrollDistanceSum, &mouseScrollDistanceIntegerSum);
|
mouseScrollState.xOut = 0;
|
||||||
|
mouseScrollState.yOut = 0;
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (activeMouseStates[SerializedMouseAction_LeftClick]) {
|
if (activeMouseStates[SerializedMouseAction_LeftClick]) {
|
||||||
ActiveUsbMouseReport->buttons |= MouseButton_Left;
|
ActiveUsbMouseReport->buttons |= MouseButton_Left;
|
||||||
@@ -152,7 +148,6 @@ void processMouseActions()
|
|||||||
if (activeMouseStates[SerializedMouseAction_RightClick]) {
|
if (activeMouseStates[SerializedMouseAction_RightClick]) {
|
||||||
ActiveUsbMouseReport->buttons |= MouseButton_Right;
|
ActiveUsbMouseReport->buttons |= MouseButton_Right;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static layer_id_t previousLayer = LayerId_Base;
|
static layer_id_t previousLayer = LayerId_Base;
|
||||||
|
|||||||
@@ -50,6 +50,7 @@
|
|||||||
serialized_mouse_action_t rightState;
|
serialized_mouse_action_t rightState;
|
||||||
mouse_speed_t prevMouseSpeed;
|
mouse_speed_t prevMouseSpeed;
|
||||||
float currentSpeed;
|
float currentSpeed;
|
||||||
|
float distance;
|
||||||
float targetSpeed;
|
float targetSpeed;
|
||||||
float initialSpeed;
|
float initialSpeed;
|
||||||
float acceleration;
|
float acceleration;
|
||||||
|
|||||||
@@ -45,6 +45,21 @@ void SetBufferUint32(uint8_t *buffer, uint32_t offset, uint32_t value)
|
|||||||
*(uint32_t*)(buffer + offset) = 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)
|
void SetBufferUint8Be(uint8_t *buffer, uint32_t offset, uint8_t value)
|
||||||
{
|
{
|
||||||
buffer[offset] = 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+2] = (value >> 8) & 0xff;
|
||||||
buffer[offset+3] = (value >> 0) & 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 SetBufferUint16(uint8_t *buffer, uint32_t offset, uint16_t value);
|
||||||
void SetBufferUint32(uint8_t *buffer, uint32_t offset, uint32_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 SetBufferUint8Be(uint8_t *buffer, uint32_t offset, uint8_t value);
|
||||||
void SetBufferUint16Be(uint8_t *buffer, uint32_t offset, uint16_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 SetBufferUint32Be(uint8_t *buffer, uint32_t offset, uint32_t value);
|
||||||
|
|
||||||
|
void SetBufferFloat(uint8_t *buffer, uint32_t offset, float value);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user