Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proposal] Add layerDelayedLock capability #144

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Macro/PartialMap/capabilities.kll
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Date = 2016-04-08;
layerState => Macro_layerState_capability( layer : 2, state : 1 );
layerLatch => Macro_layerLatch_capability( layer : 2 );
layerLock => Macro_layerLock_capability( layer : 2 );
layerDelayedLock => Macro_layerDelayedLock_capability( layer : 2 );
layerShift => Macro_layerShift_capability( layer : 2 );
# By default, rotate to the next layer
# The current rotating layer is stored separately to the layer stack
Expand Down
29 changes: 29 additions & 0 deletions Macro/PartialMap/macro.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,35 @@ void Macro_layerLock_capability( uint8_t state, uint8_t stateType, uint8_t *args
Macro_layerState( state, stateType, layer, 0x04 );
}

uint32_t layerDelayedLock_timer = 0;
uint8_t layerDelayedLock_alreadySwitched = 0;
// Locks given layer after it's been pressed for 500 milliseconds
// Argument #1: Layer Index -> uint16_t
void Macro_layerDelayedLock_capability( uint8_t state, uint8_t stateType, uint8_t *args ) {
// Display capability name
if ( stateType == 0xFF && state == 0xFF ) {
print("Macro_layerDelayedLock_capability(layerIndex)");
return;
}

uint32_t currentTime = systick_millis_count;
if ( stateType == 0x00 && state == 0x01 ) { // Pressed
layerDelayedLock_timer = currentTime; // Set start timestamp
layerDelayedLock_alreadySwitched = 0;
} else if ( stateType == 0x00 && state == 0x02 && !layerDelayedLock_alreadySwitched) { // Hold
int32_t diff = (int32_t)(currentTime - layerDelayedLock_timer);
if (diff > 500) { // TODO: Make customizable
// We reached the threshold
// Get layer index from arguments
// Cast pointer to uint8_t to uint16_t then access that memory location
uint16_t layer = *(uint16_t*)(&args[0]);
Macro_layerState( state, stateType, layer, 0x04 );
layerDelayedLock_alreadySwitched = 1;
layerDelayedLock_timer = 0;
}
}
}


// Shifts given layer
// Argument #1: Layer Index -> uint16_t
Expand Down