Skip to content

Commit

Permalink
finishes mapping the sk80
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNotary committed Sep 10, 2024
1 parent 4df6a19 commit fd85677
Show file tree
Hide file tree
Showing 13 changed files with 155 additions and 118 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ add_executable(main "src/demo/main.cpp"
"src/demo/blink_loader.cpp" "src/demo/blink_loader.h"
"src/demo/activities/push_to_light.cpp" "src/demo/activities/push_to_light.h"
"src/demo/activities/cycle_keyids.cpp" "src/demo/activities/cycle_keyids.h"
"include/main/misc.h" "src/demo/choose_keyboard.cpp" "src/demo/choose_keyboard.h" "src/demo/choose_activity.cpp" "src/demo/choose_activity.h" "src/demo/util.cpp" "src/demo/util.h" "src/demo/activities/test_single_key.cpp" "src/demo/activities/test_single_key.h")
"include/main/misc.h" "src/demo/choose_keyboard.cpp" "src/demo/choose_keyboard.h"
"src/demo/choose_activity.cpp" "src/demo/choose_activity.h"
"src/demo/util.cpp" "src/demo/util.h"
"src/demo/activities/test_single_key.cpp" "src/demo/activities/test_single_key.h")
target_include_directories(main PRIVATE "${CMAKE_SOURCE_DIR}/src/demo")


Expand Down
5 changes: 0 additions & 5 deletions TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,3 @@

- SendBufferToDeviceAndGetResp et. al. use a hard-coded message_length value of 65. Technically not currently an issue but should be possible to make it more dynamic

- Map sk80
- define SetKeysOnOff for the SK80

- Begin mapping all the keys
- turn on the escape key
1 change: 1 addition & 0 deletions include/blink.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "misc.h"

extern "C" {
DLL_EXPORT void PrintMessagesInBufferA(const unsigned char* buffer, size_t message_count, size_t message_length);
DLL_EXPORT void HelloDll();
DLL_EXPORT int BlinkKeys(char* keyIds, int nKeys);
DLL_EXPORT int TurnOnKeyIdsD(char* key_ids, UINT8 n_keys, unsigned char* messages_sent, KeyboardInfo keyboard);
Expand Down
2 changes: 1 addition & 1 deletion include/main/keyboards/sk80/constants_sk80.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace sk80 {

const short VID = 0x05ac;
const short PID = 0x024f;
const UINT8 max_key_id = 79;
const UINT8 max_key_id = 121;
const UINT8 MESSAGE_LENGTH = 65;
const UINT8 BULK_LED_VALUE_MESSAGES_COUNT = 9;
const UINT8 BULK_LED_HEADER_MESSAGES_COUNT = 2;
Expand Down
175 changes: 86 additions & 89 deletions include/main/keyboards/sk80/key_mappings_sk80.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,102 +5,99 @@

namespace sk80 {

const std::unordered_map<std::string, char> keyname_keyid_mappings = {
{
{"esc", 1},
{"f1" , 2},
{"f2" , 3},
{"f3" , 4},
{"f4" , 5},
{"f5" , 6},
{"f6" , 7},
{"f7" , 8},
{"f8" , 9},
{"f9" , 10},
{"f10", 11},
{"f11", 12},
{"f12", 13},
const std::unordered_map<std::string, char> keyname_keyid_mappings = {
{
{"esc", 1},
{"f1" , 2},
{"f2" , 3},
{"f3" , 4},
{"f4" , 5},
{"f5" , 6},
{"f6" , 7},
{"f7" , 8},
{"f8" , 9},
{"f9" , 10},
{"f10", 11},
{"f11", 12},
{"f12", 13},

{"~", 16},
{"`", 19},
{"1", 20},
{"2", 21},
{"3", 22},
{"4", 23},
{"5", 24},
{"6", 25},
{"7", 26},
{"8", 27},
{"9", 28},
{"0", 29},
{"-", 30},
{"=", 31},
{"backspace", 2},

{"tab", 3}, // this is wrong
{"tab", 37},
{"q", 38},
{"w", 39},
{"e", 40},
{"r", 41},
{"t", 42},
{"y", 43},
{"u", 44},
{"i", 45},
{"o", 46},
{"p", 47},
{"[", 48},
{"]", 49},

{"caps", 55},
{"a", 56},
{"s", 57},
{"d", 58},
{"f", 59},
{"g", 60},
{"h", 61},
{"j", 62},
{"k", 63},
{"l", 64},
{";", 65},
{"'", 66},
{"\\", 67},

/*
{"1", 8},
{"2", 14},
{"3", 20},
{"4", 26},
{"5", 32},
{"6", 38},
{"7", 44},
{"8", 50},
{"9", 56},
{"0", 62},
{"-", 68},
{"=", 74},
{"backspace", 80},
{"home", 92},

{"tab", 3},
{"q", 9},
{"w", 15},
{"e", 21},
{"r", 27},
{"t", 33},
{"y", 39},
{"u", 45},
{"i", 51},
{"o", 57},
{"p", 63},
{"[", 69},
{"]", 75},
{"\\", 81},
{"end", 93},
{"lshift", 73},
{"z", 74},
{"x", 75},
{"c", 76},
{"v", 77},
{"b", 78},
{"n", 79},
{"m", 80},
{",", 81},
{".", 82},
{"/", 83},
{"shift", 84},
{"enter", 85},
{"lctrl", 91},
{"meta", 92},
{"lalt", 93},
{"space", 94},
{"ralt", 95},
{"fn", 96},
{"rctrl", 98},

{"caps", 4},
{"a", 10},
{"s", 16},
{"d", 22},
{"f", 28},
{"g", 34},
{"h", 40},
{"j", 46},
{"k", 52},
{"l", 58},
{";", 64},
{"'", 70},
{"enter", 82},
{"pageup", 94},
{"left", 99},
{"down", 100},
{"up", 101},
{"right", 102},
{"backspace", 103},

{"lshift", 5},
{"z", 11},
{"x", 17},
{"c", 23},
{"v", 29},
{"b", 35},
{"n", 41},
{"m", 47},
{",", 53},
{".", 59},
{"/", 65},
{"rshift", 71},
{"up", 83},
{"pagedown", 95},
{"insert", 116},
{"pageup", 118},
{"delete", 119},
{"pagedown", 121},

{"lctrl", 6},
{"lmeta", 12},
{"lalt", 18},
{"space", 36},
{"ralt", 54},
{"fn", 60},
{"rctrl", 66},
{"left", 72},
{"down", 84},
{"right", 96},
*/
}
};
}
};

}
5 changes: 3 additions & 2 deletions include/main/keyboards/sk80/messages_sk80.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ const unsigned char BULK_LED_FOOTER_MESSAGES[BULK_LED_FOOTER_MESSAGES_COUNT][MES
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
},
/*{ // These look like they're kicking off a new message type...
/*
{ // These look like they're kicking off a new message type...
0x00,
0x04, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Expand Down Expand Up @@ -158,7 +159,7 @@ const unsigned char BULK_LED_VALUE_MESSAGES[BULK_LED_VALUE_MESSAGES_COUNT][MESSA
0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, // 0x25 == 37u
0x26, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00,
0x28, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x00,
0x2a, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x00, 0x00,
Expand Down
2 changes: 1 addition & 1 deletion include/main/usb_functions.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include <windows.h>
#include <vector>
#include <windows.h>
#include "misc.h"


Expand Down
5 changes: 5 additions & 0 deletions src/blink/blink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ int TurnKeyIds(char* key_ids, UINT8 n_keys, KeyValue onOrOff, KeyboardInfo keybo
}

extern "C" {

void PrintMessagesInBufferA(const unsigned char* buffer, size_t message_count, size_t message_length) {
PrintMessagesInBuffer(buffer, message_count, message_length);
}

void HelloDll() {
printf("Hello from the DLL!\n");
}
Expand Down
17 changes: 6 additions & 11 deletions src/blink/keyboards/sk80/sk80.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,10 @@ namespace sk80::internal {
throw("SK80 does not support keyIds greater than " + sk80::max_key_id);
}

// assume 0x0f, 15, which is 4 * 15 + 1 = index:61
// Also consider 0x10, 16, which is message_index:2

UINT8 n_keys_in_first_packet = 15;
UINT8 n_keys_in_first_packet = 16;
UINT8 width_of_key = 4;
UINT8 message_index = (active_key - 1) / n_keys_in_first_packet; // when active_key = 1, 0 % 15 is zero, so 0 * 4
UINT8 offset_to_message = ((active_key - 1) % 15) * width_of_key + 1; // when active_key = 16, 15 % 15 is zero, so 0 * width_of_key = 0
if (message_index == 0)
offset_to_message += 4; // we'll count the first packet as zero indexed and everything will work out, but this register massaging is because they did their math in creative ways
UINT8 message_index = active_key / n_keys_in_first_packet;
UINT8 offset_to_message = (active_key % 16) * width_of_key + 1;

// This allows for C++17 destructuring via the auto keyword
return { static_cast<UINT8>(message_index), static_cast<UINT8>(offset_to_message) };
Expand All @@ -53,8 +48,8 @@ namespace sk80 {

void SK80::SetBytesInValuePackets(unsigned char* messages_ptr, KeyValue key_value)
{
// Cast the flat buffer to a 3x65 array
unsigned char (*messages)[sk80::MESSAGE_LENGTH] = reinterpret_cast<unsigned char (*)[sk80::MESSAGE_LENGTH]>(messages_ptr);
// A 9x65 array cast from the flat buffer
unsigned char (&messages)[sk80::BULK_LED_VALUE_MESSAGES_COUNT][sk80::MESSAGE_LENGTH] = *reinterpret_cast<unsigned char (*)[sk80::BULK_LED_VALUE_MESSAGES_COUNT][sk80::MESSAGE_LENGTH]>(messages_ptr);

std::memcpy(messages, sk80::BULK_LED_VALUE_MESSAGES, sk80::BULK_LED_VALUE_MESSAGES_COUNT * sk80::MESSAGE_LENGTH);

Expand Down Expand Up @@ -98,7 +93,7 @@ namespace sk80 {
SendBufferToDevice(this->device_handle, messages, sk80::BULK_LED_VALUE_MESSAGES_COUNT, sk80::MESSAGE_LENGTH);

//PrintMessagesInBuffer(*sk80::BULK_LED_FOOTER_MESSAGES, sk80::BULK_LED_FOOTER_MESSAGES_COUNT, sk80::MESSAGE_LENGTH);
SendBufferToDevice(this->device_handle, *sk80::BULK_LED_FOOTER_MESSAGES, sk80::BULK_LED_FOOTER_MESSAGES_COUNT, sk80::MESSAGE_LENGTH);
SendBufferToDeviceAndGetResp(this->device_handle, *sk80::BULK_LED_FOOTER_MESSAGES, sk80::BULK_LED_FOOTER_MESSAGES_COUNT, sk80::MESSAGE_LENGTH);
}

void SK80::SetKeyRGB(char key_id, unsigned char r, unsigned char g, unsigned char b) {
Expand Down
8 changes: 6 additions & 2 deletions src/demo/activities/cycle_keyids.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#include <windows.h>
#include "cycle_keyids.h"

#include <iostream>
#include <vector>

#include <windows.h>

#include "blink_loader.h"

using std::cout;
Expand Down Expand Up @@ -73,7 +77,7 @@ int CycleKeyIds(KeyboardInfo keyboard) {
}

if (GetAsyncKeyState(VK_SPACE) & 0x8000) { // print packet buffer
CallPrintMessagesInBuffer(messages_sent, 3, 65);
CallPrintMessagesInBuffer(messages_sent, keyboard.BULK_LED_VALUE_MESSAGES_COUNT, keyboard.MESSAGE_LENGTH);

Sleep(200);
}
Expand Down
1 change: 1 addition & 0 deletions src/demo/activities/cycle_keyids.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#include "misc.h"


namespace demo {
Expand Down
2 changes: 1 addition & 1 deletion src/demo/blink_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void CallPrintMessagesInBuffer(unsigned char* buffer, size_t message_count, size
return;
}

char funcName[] = "PrintMessagesInBuffer";
char funcName[] = "PrintMessagesInBufferA";
typedef void (*Func)(unsigned char* buffer, size_t message_count, size_t message_length);

Func dll_func = GetFunction<Func>(&hModule, funcName);
Expand Down
Loading

0 comments on commit fd85677

Please sign in to comment.