diff --git a/doc-dev/user-guide.md b/doc-dev/user-guide.md index b50ea8a35..5d3873c28 100644 --- a/doc-dev/user-guide.md +++ b/doc-dev/user-guide.md @@ -714,7 +714,7 @@ setVar qActive 1 // toggle fn layer and keep it active for 5 seconds or until some recordKey instance starts recording a macro toggleLayer fn -ifNotRecording ifNotPlaytime 5000 if ($qActive) goTo @0 +ifNotRecording ifNotPlaytime 5000 if ($qActive) goTo $currentAddress untoggleLayer setVar qActive 0 ``` diff --git a/right/src/debug.c b/right/src/debug.c index 6bd9eb87a..2b97117df 100644 --- a/right/src/debug.c +++ b/right/src/debug.c @@ -3,14 +3,12 @@ #ifdef WATCHES -#include "led_display.h" #include "timer.h" #include "key_states.h" #include #include "usb_interfaces/usb_interface_basic_keyboard.h" -#include "macros/core.h" #include "macros/status_buffer.h" -#include "keymap.h" +#include "segment_display.h" uint8_t CurrentWatch = 0; @@ -140,4 +138,43 @@ void WatchValueMax(int v, uint8_t n) } +void WatchFloatValue(float v, uint8_t n) +{ + if (CurrentTime - lastWatch > watchInterval) { + SegmentDisplay_SetFloat(v, SegmentDisplaySlot_Debug); + lastWatch = CurrentTime; + } +} + +void WatchFloatValueMin(float v, uint8_t n) +{ + static float m = 0; + + if (v < m) { + m = v; + } + + if (CurrentTime - lastWatch > watchInterval) { + SegmentDisplay_SetFloat(m, SegmentDisplaySlot_Debug); + lastWatch = CurrentTime; + m = (float)INT_MAX; + } +} + +void WatchFloatValueMax(float v, uint8_t n) +{ + static float m = 0; + + if (v > m) { + m = v; + } + + if (CurrentTime - lastWatch > watchInterval) { + SegmentDisplay_SetFloat(m, SegmentDisplaySlot_Debug); + lastWatch = CurrentTime; + m = (float)INT_MIN; + } +} + + #endif diff --git a/right/src/debug.h b/right/src/debug.h index c6c9e152d..5b0a23cdd 100644 --- a/right/src/debug.h +++ b/right/src/debug.h @@ -2,6 +2,7 @@ #define WATCHES #endif + #ifdef WATCHES #ifndef SRC_UTILS_DBG_H_ #define SRC_UTILS_DBG_H_ @@ -41,6 +42,15 @@ // Watches value V in slot N. #define WATCH_VALUE_MAX(V, N) if(CurrentWatch == N) { WatchValueMax(V, N); } + // Watches value V in slot N. + #define WATCH_FLOAT_VALUE(V, N) if(CurrentWatch == N) { WatchFloatValue(V, N); } + + // Watches value V in slot N. + #define WATCH_FLOAT_VALUE_MIN(V, N) if(CurrentWatch == N) { WatchFloatValueMin(V, N); } + + // Watches value V in slot N. + #define WATCH_FLOAT_VALUE_MAX(V, N) if(CurrentWatch == N) { WatchFloatValueMax(V, N); } + // Watches string V in slot N. #define WATCH_STRING(V, N) if(CurrentWatch == N) { WatchString(V, N); } @@ -71,6 +81,9 @@ void WatchValue(int v, uint8_t n); void WatchValueMin(int v, uint8_t n); void WatchValueMax(int v, uint8_t n); + void WatchFloatValue(float v, uint8_t n); + void WatchFloatValueMin(float, uint8_t n); + void WatchFloatValueMax(float, uint8_t n); void WatchString(char const * v, uint8_t n); void ShowValue(int v, uint8_t n); void ShowString(char const * v, uint8_t n); @@ -89,6 +102,9 @@ #define WATCH_VALUE(V, N) #define WATCH_VALUE_MIN(V, N) #define WATCH_VALUE_MAX(V, N) + #define WATCH_FLOAT_VALUE(V, N) + #define WATCH_FLOAT_VALUE_MIN(V, N) + #define WATCH_FLOAT_VALUE_MAX(V, N) #define WATCH_STRING(V, N) #define SHOW_STRING(V, N) #define SHOW_VALUE(V, N) diff --git a/right/src/mouse_controller.c b/right/src/mouse_controller.c index e602ecb0e..ce54eb9bc 100644 --- a/right/src/mouse_controller.c +++ b/right/src/mouse_controller.c @@ -1,16 +1,11 @@ #include #include "key_action.h" -#include "led_display.h" #include "layer.h" +#include "slave_protocol.h" #include "usb_interfaces/usb_interface_mouse.h" -#include "peripherals/test_led.h" -#include "slave_drivers/is31fl3xxx_driver.h" #include "slave_drivers/uhk_module_driver.h" #include "timer.h" #include "config_parser/parse_keymap.h" -#include "usb_commands/usb_command_get_debug_buffer.h" -#include "arduino_hid/ConsumerAPI.h" -#include "secondary_role_driver.h" #include "slave_drivers/touchpad_driver.h" #include "mouse_controller.h" #include "mouse_keys.h" @@ -18,12 +13,9 @@ #include "layer_switcher.h" #include "usb_report_updater.h" #include "caret_config.h" -#include "keymap.h" -#include "macros/core.h" #include "debug.h" #include "postponer.h" #include "layer.h" -#include "secondary_role_driver.h" typedef struct { float x; @@ -709,6 +701,7 @@ void MouseController_ProcessMouseActions() for (uint8_t moduleSlotId=0; moduleSlotIdmoduleId == ModuleId_Unavailable || moduleState->pointerCount == 0) { continue; } diff --git a/right/src/segment_display.c b/right/src/segment_display.c index 687792aa9..1756e5071 100644 --- a/right/src/segment_display.c +++ b/right/src/segment_display.c @@ -117,6 +117,7 @@ void SegmentDisplay_SerializeFloat(char* buffer, float num) { if (num <= -10.0f || 10.0f <= num ) { SegmentDisplay_SerializeInt(buffer, num); + return; } int mag = 0; @@ -127,7 +128,7 @@ void SegmentDisplay_SerializeFloat(char* buffer, float num) negative = true; } - while (num < 10.0f) { + while (num < 10.0f && mag < 10) { mag++; num *= 10; } @@ -178,6 +179,13 @@ void SegmentDisplay_SetInt(int32_t a, segment_display_slot_t slot) SegmentDisplay_SetText(3, b, slot); } +void SegmentDisplay_SetFloat(float a, segment_display_slot_t slot) +{ + char b[3]; + SegmentDisplay_SerializeFloat(b, a); + SegmentDisplay_SetText(3, b, slot); +} + bool SegmentDisplay_SlotIsActive(segment_display_slot_t slot) { return slots[slot].active; diff --git a/right/src/segment_display.h b/right/src/segment_display.h index c0959beb8..1ae37e292 100644 --- a/right/src/segment_display.h +++ b/right/src/segment_display.h @@ -5,7 +5,6 @@ #include #include - #include "timer.h" #include "macros/vars.h" // Macros: @@ -36,6 +35,7 @@ void SegmentDisplay_Update(); void SegmentDisplay_SetText(uint8_t len, const char* text, segment_display_slot_t slot); void SegmentDisplay_SetInt(int32_t a, segment_display_slot_t slot); + void SegmentDisplay_SetFloat(float a, segment_display_slot_t slot); void SegmentDisplay_SerializeInt(char* buffer, int32_t a); void SegmentDisplay_SerializeFloat(char* buffer, float f); void SegmentDisplay_SerializeVar(char* buffer, macro_variable_t var); diff --git a/right/src/slave_drivers/uhk_module_driver.c b/right/src/slave_drivers/uhk_module_driver.c index c70da712a..2980bd02f 100644 --- a/right/src/slave_drivers/uhk_module_driver.c +++ b/right/src/slave_drivers/uhk_module_driver.c @@ -362,6 +362,7 @@ slave_result_t UhkModuleSlaveDriver_Update(uint8_t uhkModuleDriverId) pointer_delta_t *pointerDelta = (pointer_delta_t*)(rxMessage->data + keyStatesLength); uhkModuleState->pointerDelta.x += pointerDelta->x; uhkModuleState->pointerDelta.y += pointerDelta->y; + uhkModuleState->pointerDelta.debugInfo = pointerDelta->debugInfo; } } res.status = kStatus_Uhk_IdleCycle; diff --git a/shared/module/slave_protocol_handler.c b/shared/module/slave_protocol_handler.c index 77b6a0be0..42be2766e 100644 --- a/shared/module/slave_protocol_handler.c +++ b/shared/module/slave_protocol_handler.c @@ -134,6 +134,7 @@ void SlaveTxHandler(void) // (This handler can be interrupted by sensor interrupts.) pointerDelta->x = PointerDelta.x; pointerDelta->y = PointerDelta.y; + pointerDelta->debugInfo = PointerDelta.debugInfo; PointerDelta.x = 0; PointerDelta.y = 0; __enable_irq(); diff --git a/shared/slave_protocol.h b/shared/slave_protocol.h index d18192fbe..518d1a5ed 100644 --- a/shared/slave_protocol.h +++ b/shared/slave_protocol.h @@ -64,9 +64,13 @@ uint8_t data[I2C_MESSAGE_MAX_PAYLOAD_LENGTH]; } ATTR_PACKED i2c_message_t; + typedef struct { + } ATTR_PACKED pointer_debug_info_t; + typedef struct { int16_t x; int16_t y; + pointer_debug_info_t debugInfo; } ATTR_PACKED pointer_delta_t; // Variables: diff --git a/trackpoint/src/module.c b/trackpoint/src/module.c index 58f3f6d39..0efde035b 100644 --- a/trackpoint/src/module.c +++ b/trackpoint/src/module.c @@ -1,5 +1,6 @@ #include "fsl_gpio.h" #include "module.h" +#include pointer_delta_t PointerDelta; @@ -147,7 +148,62 @@ static bool readByte() return false; } -void PS2_CLOCK_IRQ_HANDLER(void) { +#define AXIS_COUNT 2 +#define WINDOW_LENGTH 16 +#define ABS(x) ((x) < 0 ? -(x) : (x)) +#define DRIFT_RESET_PERIOD 2000 +#define TRACKPOINT_UPDATE_PERIOD 10 +#define DRIFT_TOLERANCE 1 + +static uint16_t window[AXIS_COUNT][WINDOW_LENGTH]; +static uint8_t windowIndex = 0; +static uint16_t windowSum[AXIS_COUNT]; + +void recognizeDrifts(int16_t x, int16_t y) +{ + uint16_t deltas[AXIS_COUNT] = {ABS(x), ABS(y)}; + + // compute average speed across the window + for (uint8_t axis=0; axis DRIFT_TOLERANCE + 1) { + drifting = false; + } + } + + if (windowSum[0] < 1 && windowSum[1] < 1) { + drifting = false; + } + + // handle drift detection logic + if (drifting) { + driftLength++; + if (driftLength > DRIFT_RESET_PERIOD / TRACKPOINT_UPDATE_PERIOD) { + driftLength = 0; + shouldReset = true; + } + } else { + driftLength = 0; + for (uint8_t axis=0; axis