Skip to content

Commit

Permalink
change timeout management
Browse files Browse the repository at this point in the history
Clarified the demarcation point about Auto Mouse Layer

* don't provide wrappers for functions which QMK auto mouse layer provides
* store/restore timeout to EEPROM in very simple way
  • Loading branch information
koron committed Mar 23, 2024
1 parent 724e199 commit 9f7c5c4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 69 deletions.
65 changes: 14 additions & 51 deletions qmk_firmware/keyboards/keyball/lib/keyball/keyball.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ const uint8_t CPI_DEFAULT = KEYBALL_CPI_DEFAULT / 100;
const uint8_t CPI_MAX = pmw3360_MAXCPI + 1;
const uint8_t SCROLL_DIV_MAX = 7;

const uint16_t AML_TIMEOUT_DEFAULT = 9;
const uint16_t AML_TIMEOUT_MAX = 15;
const uint16_t AML_TIMEOUT_MIN = 100;
const uint16_t AML_TIMEOUT_MAX = 1000;
const uint16_t AML_TIMEOUT_QU = 50; // Quantization Unit

keyball_t keyball = {
.this_have_ball = false,
Expand All @@ -47,10 +48,6 @@ keyball_t keyball = {
.scroll_div = 0,

.pressing_keys = {' ', ' ', ' ', 0},

#ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE
.aml_timeout = 0,
#endif
};

//////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -129,15 +126,6 @@ static void add_scroll_div(int8_t delta) {
keyball_set_scroll_div(v < 1 ? 1 : v);
}


#ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE
static void add_aml_timeout(int8_t delta) {
int8_t v = keyball_get_aml_timeout() + delta;
keyball_set_aml_timeout(v < 1 ? 1 : v);
}
#endif


//////////////////////////////////////////////////////////////////////////////
// Pointing device driver

Expand Down Expand Up @@ -469,7 +457,7 @@ void keyball_oled_render_amlinfo(void) {
oled_write_P(PSTR("AML:"), false);
oled_write_char((get_auto_mouse_enable() ? 'o' : 'x'), false);
oled_write_char(' ', false);
oled_write(format_4d(keyball.aml_timeout), false);
oled_write(format_4d(get_auto_mouse_timeout()), false);
oled_write_P(PSTR(" "), false);
#endif
}
Expand Down Expand Up @@ -512,37 +500,6 @@ void keyball_set_cpi(uint8_t cpi) {
}
}

#ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE

// This method returns current timeout value.
// It will return 1 to 15.
//
// 1=( 1-1)*50+250=250ms
// 2=( 2-1)*50+250=300ms
// ...
// 9=( 9-1)*50+250=650ms
// 10=(10-1)*50+250=700ms
// 11=(11-1)*50+250=750ms
// 12=(12-1)*50+250=800ms
// 13=(13-1)*50+250=850ms
// 14=(14-1)*50+250=900ms
// 15=(15-1)*50+250=950ms
uint8_t keyball_get_aml_timeout(void) {
return keyball.aml_timeout == 0 ? AML_TIMEOUT_DEFAULT : keyball.aml_timeout;
}

void keyball_set_aml_timeout(uint8_t timeout) {
if (timeout > AML_TIMEOUT_MAX) {
timeout = AML_TIMEOUT_MAX;
}
keyball.aml_timeout = timeout;
if (timeout == 0) {
timeout = AML_TIMEOUT_DEFAULT;
}
set_auto_mouse_timeout((timeout-1)*50+250);
}
#endif

//////////////////////////////////////////////////////////////////////////////
// Keyboard hooks

Expand All @@ -563,7 +520,7 @@ void keyboard_post_init_kb(void) {
keyball_set_scroll_div(c.sdiv);
#ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE
set_auto_mouse_enable(c.amle);
keyball_set_aml_timeout(c.amlto);
set_auto_mouse_timeout(c.amlto == 0 ? AUTO_MOUSE_TIME : (c.amlto + 1) * AML_TIMEOUT_QU);
#endif
}

Expand Down Expand Up @@ -649,7 +606,7 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
.sdiv = keyball.scroll_div,
#ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE
.amle = get_auto_mouse_enable(),
.amlto = keyball.aml_timeout,
.amlto = (get_auto_mouse_timeout() / AML_TIMEOUT_QU) - 1,
#endif
};
eeconfig_update_kb(c.raw);
Expand Down Expand Up @@ -683,10 +640,16 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
set_auto_mouse_enable(!get_auto_mouse_enable());
break;
case AML_I50:
add_aml_timeout(1);
{
uint16_t v = get_auto_mouse_timeout() + 50;
set_auto_mouse_timeout(MIN(v, AML_TIMEOUT_MAX));
}
break;
case AML_D50:
add_aml_timeout(-1);
{
uint16_t v = get_auto_mouse_timeout() - 50;
set_auto_mouse_timeout(MAX(v, AML_TIMEOUT_MIN));
}
break;
#endif

Expand Down
19 changes: 1 addition & 18 deletions qmk_firmware/keyboards/keyball/lib/keyball/keyball.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ typedef union {
uint8_t sdiv : 3; // scroll divider
#ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE
uint8_t amle : 1; // automatic mouse layer enabled
uint8_t amlto : 4; // automatic mouse layer timeout
uint16_t amlto : 5; // automatic mouse layer timeout
#endif
};
} keyball_config_t;
Expand Down Expand Up @@ -146,10 +146,6 @@ typedef struct {
uint32_t scroll_snap_last;
int8_t scroll_snap_tension_h;

#ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE
uint8_t aml_timeout;
#endif

uint16_t last_kc;
keypos_t last_pos;
report_mouse_t last_mouse;
Expand Down Expand Up @@ -208,16 +204,3 @@ uint8_t keyball_get_cpi(void);

// TODO: document
void keyball_set_cpi(uint8_t cpi);

#ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE

// This function is used to get the current timeout value for the automatic mouse layer (AML).
// The returned value is the number of milliseconds the system will wait before automatically activating the mouse layer.
// The return value is a number between 0 and 15, which corresponds to a range between 250ms and 950ms in intervals of 50ms.
uint8_t keyball_get_aml_timeout(void);

// This function is used to set the automatic mouse layer (AML) timeout value.
// The argument is a number between 0 and 15, which corresponds to a range between 250ms and 950ms in intervals of 50ms.
// This value sets how long (in milliseconds) the system should wait before automatically activating the mouse layer when a key is pressed.
void keyball_set_aml_timeout(uint8_t timeout);
#endif

0 comments on commit 9f7c5c4

Please sign in to comment.