Skip to content
Merged
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
9 changes: 6 additions & 3 deletions device/src/bt_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -981,9 +981,6 @@ void BtConn_Init(void) {
void num_comp_reply(int passkey) {
struct bt_conn *conn;

#if DEVICE_HAS_OLED
NotificationScreen_NotifyFor("Pairing...", 10000);
#endif

if (!auth_conn) {
return;
Expand All @@ -994,8 +991,14 @@ void num_comp_reply(int passkey) {
if (passkey >= 0) {
bt_conn_auth_passkey_entry(conn, passkey);
LOG_INF("Sending passkey to conn %s", GetPeerStringByConn(conn));
#if DEVICE_HAS_OLED
NotificationScreen_NotifyFor("Pairing...", 10000);
#endif
} else {
conn = unsetAuthConn(true);
#if DEVICE_HAS_OLED
PairingScreen_Feedback(false);
#endif
}
}

Expand Down
13 changes: 7 additions & 6 deletions device/src/keyboard/oled/screens/pairing_screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ const rgb_t* PairingScreen_ActionColor(key_action_t* action) {
static const rgb_t black = { 0, 0, 0 };
static const rgb_t green = { 0, 0xff, 0 };
static const rgb_t red = { 0xff, 0, 0 };
static const rgb_t blue = { 0, 0, 0xff };

if (
action->type != KeyActionType_Keystroke
Expand All @@ -86,16 +85,18 @@ const rgb_t* PairingScreen_ActionColor(key_action_t* action) {
}

switch (action->keystroke.scancode) {
case HID_KEYBOARD_SC_ESCAPE:
return &red;
case HID_KEYBOARD_SC_DELETE:
case HID_KEYBOARD_SC_BACKSPACE:
return &blue;
// Numbers are green
case HID_KEYBOARD_SC_1_AND_EXCLAMATION ... HID_KEYBOARD_SC_9_AND_OPENING_PARENTHESIS:
case HID_KEYBOARD_SC_0_AND_CLOSING_PARENTHESIS:
case HID_KEYBOARD_SC_KEYPAD_1_AND_END ... HID_KEYBOARD_SC_KEYPAD_9_AND_PAGE_UP:
case HID_KEYBOARD_SC_KEYPAD_0_AND_INSERT:
return &green;
// Control keys (esc, backspace) are red
case HID_KEYBOARD_SC_ESCAPE:
case HID_KEYBOARD_SC_DELETE:
case HID_KEYBOARD_SC_BACKSPACE:
return &red;
// Everything else is black
default:
return &black;
}
Expand Down
3 changes: 3 additions & 0 deletions device/src/keyboard/oled/screens/screen_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "timer.h"
#include "event_scheduler.h"
#include "ledmap.h"
#include "keymap_pairing.h"

screen_id_t ActiveScreen = ScreenId_Main;

Expand All @@ -18,6 +19,7 @@ static void onExit(screen_id_t screen) {
switch(screen) {
case ScreenId_Pairing:
InteractivePairingInProgress = false;
Keymap_DeactivatePairingKeymap();
Ledmap_ResetTemporaryLedBacklightingMode();
EventVector_Set(EventVector_LedManagerFullUpdateNeeded);
break;
Expand All @@ -36,6 +38,7 @@ void ScreenManager_ActivateScreen(screen_id_t screen)
case ScreenId_Pairing:
InteractivePairingInProgress = true;
screenPtr = PairingScreen;
Keymap_ActivatePairingKeymap();
Ledmap_SetTemporaryLedBacklightingMode(BacklightingMode_Numpad);
EventVector_Set(EventVector_LedManagerFullUpdateNeeded);
Ledmap_UpdateBacklightLeds();
Expand Down
1 change: 1 addition & 0 deletions right/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ target_sources(${PROJECT_NAME} PRIVATE
$<$<BOOL:${IS_MCUX_SDK}>:${CMAKE_CURRENT_SOURCE_DIR}/init_peripherals.c>
key_states.c
keymap.c
keymap_pairing.c
layer.c
layer_stack.c
layer_switcher.c
Expand Down
1 change: 1 addition & 0 deletions right/src/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -640,3 +640,4 @@ key_action_t CurrentKeymap[LayerId_Count][SLOT_COUNT][MAX_KEY_COUNT_PER_MODULE]

},
};

70 changes: 70 additions & 0 deletions right/src/keymap_pairing.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include <string.h>
#include "keymap_pairing.h"
#include "keymap.h"
#include "key_action.h"
#include "layer.h"
#include "event_scheduler.h"
#include "lufa/HIDClassCommon.h"
#include "macros/keyid_parser.h"

#define PAIRING_KEYMAP_INDEX 0xFF

#define KEYID_TO_SLOT(keyId) ((keyId) / 64)
#define KEYID_TO_INDEX(keyId) ((keyId) % 64)

static uint8_t savedKeymapIndex = 0;

static void setPairingKey(const char* keyIdStr, uint16_t scancode)
{
uint8_t keyId = KeyIdParser_KeyIdFromString(keyIdStr);
if (keyId == 255) {
return;
}
uint8_t slotId = KEYID_TO_SLOT(keyId);
uint8_t keyIndex = KEYID_TO_INDEX(keyId);
CurrentKeymap[LayerId_Base][slotId][keyIndex] = (key_action_t){
.type = KeyActionType_Keystroke,
.keystroke = { .keystrokeType = KeystrokeType_Basic, .scancode = scancode }
};
}

void Keymap_ActivatePairingKeymap(void)
{
if (CurrentKeymapIndex == PAIRING_KEYMAP_INDEX) {
return;
}

savedKeymapIndex = CurrentKeymapIndex;
CurrentKeymapIndex = PAIRING_KEYMAP_INDEX;

// Clear entire keymap to KeyActionType_None
memset(CurrentKeymap, 0, sizeof(CurrentKeymap));

// Set up number keys at default locations
setPairingKey("0", HID_KEYBOARD_SC_0_AND_CLOSING_PARENTHESIS);
setPairingKey("1", HID_KEYBOARD_SC_1_AND_EXCLAMATION);
setPairingKey("2", HID_KEYBOARD_SC_2_AND_AT);
setPairingKey("3", HID_KEYBOARD_SC_3_AND_HASHMARK);
setPairingKey("4", HID_KEYBOARD_SC_4_AND_DOLLAR);
setPairingKey("5", HID_KEYBOARD_SC_5_AND_PERCENTAGE);
setPairingKey("6", HID_KEYBOARD_SC_6_AND_CARET);
setPairingKey("7", HID_KEYBOARD_SC_7_AND_AMPERSAND);
setPairingKey("8", HID_KEYBOARD_SC_8_AND_ASTERISK);
setPairingKey("9", HID_KEYBOARD_SC_9_AND_OPENING_PARENTHESIS);

// Set up control keys
setPairingKey("backspace", HID_KEYBOARD_SC_BACKSPACE);
setPairingKey("escape", HID_KEYBOARD_SC_ESCAPE);
setPairingKey("capsLock", HID_KEYBOARD_SC_ESCAPE);

EventVector_Set(EventVector_LedMapUpdateNeeded);
}

void Keymap_DeactivatePairingKeymap(void)
{
if (CurrentKeymapIndex != PAIRING_KEYMAP_INDEX) {
return;
}

SwitchKeymapById(savedKeymapIndex, true);
}
7 changes: 7 additions & 0 deletions right/src/keymap_pairing.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef __KEYMAP_PAIRING_H__
#define __KEYMAP_PAIRING_H__

void Keymap_ActivatePairingKeymap(void);
void Keymap_DeactivatePairingKeymap(void);

#endif
7 changes: 7 additions & 0 deletions right/src/macros/keyid_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "str_utils.h"
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include "debug.h"


Expand Down Expand Up @@ -197,3 +198,9 @@ const char* MacroKeyIdParser_KeyIdToAbbreviation(uint8_t keyId)
}
return "?";
}

uint8_t KeyIdParser_KeyIdFromString(const char* str)
{
const lookup_record_t* record = lookup(0, lookup_size-1, str, str + strlen(str));
return record ? record->keyId : 255;
}
1 change: 1 addition & 0 deletions right/src/macros/keyid_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

void KeyIdParser_initialize();
uint8_t MacroKeyIdParser_TryConsumeKeyId(parser_context_t* ctx);
uint8_t KeyIdParser_KeyIdFromString(const char* str);
const char* MacroKeyIdParser_KeyIdToAbbreviation(uint8_t keyId) ;


Expand Down