Skip to content

Commit

Permalink
Increase number of layers to 8
Browse files Browse the repository at this point in the history
This increases the number of layers to 8 internally.

The additional layers are currently hidden in the configuration UI.
  • Loading branch information
jfedor2 committed Apr 9, 2024
1 parent afd8d06 commit 154fb33
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 46 deletions.
18 changes: 9 additions & 9 deletions config-tool-web/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const DEFAULT_GPIO_DEBOUNCE_TIME = 5;
const DEFAULT_SCALING = 1000;
const DEFAULT_MACRO_ENTRY_DURATION = 1;

const NLAYERS = 4;
const NLAYERS = 8;
const NMACROS = 32;
const NEXPRESSIONS = 8;
const MACRO_ITEMS_IN_PACKET = 6;
Expand Down Expand Up @@ -111,7 +111,7 @@ let target_modal = null;
let extra_usages = { 'source': [], 'target': [] };
let config = {
'version': CONFIG_VERSION,
'unmapped_passthrough_layers': [0, 1, 2, 3],
'unmapped_passthrough_layers': [0, 1, 2, 3, 4, 5, 6, 7],
'partial_scroll_timeout': DEFAULT_PARTIAL_SCROLL_TIMEOUT,
'tap_hold_threshold': DEFAULT_TAP_HOLD_THRESHOLD,
'gpio_debounce_time_ms': DEFAULT_GPIO_DEBOUNCE_TIME,
Expand Down Expand Up @@ -231,12 +231,12 @@ async function load_from_device() {

try {
await send_feature_command(GET_CONFIG);
const [config_version, flags, partial_scroll_timeout, mapping_count, our_usage_count, their_usage_count, interval_override, tap_hold_threshold, gpio_debounce_time_ms, our_descriptor_number, macro_entry_duration, quirk_count] =
await read_config_feature([UINT8, UINT8, UINT32, UINT32, UINT32, UINT32, UINT8, UINT32, UINT8, UINT8, UINT8, UINT16]);
const [config_version, flags, unmapped_passthrough_layer_mask, partial_scroll_timeout, mapping_count, our_usage_count, their_usage_count, interval_override, tap_hold_threshold, gpio_debounce_time_ms, our_descriptor_number, macro_entry_duration, quirk_count] =
await read_config_feature([UINT8, UINT8, UINT8, UINT32, UINT16, UINT32, UINT32, UINT8, UINT32, UINT8, UINT8, UINT8, UINT16]);
check_received_version(config_version);

config['version'] = config_version;
config['unmapped_passthrough_layers'] = mask_to_layer_list(flags & ((1 << NLAYERS) - 1));
config['unmapped_passthrough_layers'] = mask_to_layer_list(unmapped_passthrough_layer_mask);
config['partial_scroll_timeout'] = partial_scroll_timeout;
config['tap_hold_threshold'] = tap_hold_threshold;
config['gpio_debounce_time_ms'] = gpio_debounce_time_ms;
Expand Down Expand Up @@ -362,11 +362,11 @@ async function save_to_device() {

try {
await send_feature_command(SUSPEND);
const flags = layer_list_to_mask(config['unmapped_passthrough_layers']) |
(config['ignore_auth_dev_inputs'] ? IGNORE_AUTH_DEV_INPUTS_FLAG : 0) |
const flags = (config['ignore_auth_dev_inputs'] ? IGNORE_AUTH_DEV_INPUTS_FLAG : 0) |
(config['gpio_output_mode'] ? GPIO_OUTPUT_MODE_FLAG : 0);
await send_feature_command(SET_CONFIG, [
[UINT8, flags],
[UINT8, layer_list_to_mask(config['unmapped_passthrough_layers'])],
[UINT32, config['partial_scroll_timeout']],
[UINT8, config['interval_override']],
[UINT32, config['tap_hold_threshold']],
Expand Down Expand Up @@ -504,8 +504,8 @@ async function do_get_usages_from_device(command, rle_count) {
async function get_usages_from_device() {
try {
await send_feature_command(GET_CONFIG);
const [config_version, flags, partial_scroll_timeout, mapping_count, our_usage_count, their_usage_count, tap_hold_threshold, gpio_debounce_time_ms, our_descriptor_number, macro_entry_duration] =
await read_config_feature([UINT8, UINT8, UINT32, UINT32, UINT32, UINT32, UINT32, UINT8, UINT8, UINT8]);
const [config_version, flags, unmapped_passthrough_layer_mask, partial_scroll_timeout, mapping_count, our_usage_count, their_usage_count, interval_override, tap_hold_threshold, gpio_debounce_time_ms, our_descriptor_number, macro_entry_duration, quirk_count] =
await read_config_feature([UINT8, UINT8, UINT8, UINT32, UINT16, UINT32, UINT32, UINT8, UINT32, UINT8, UINT8, UINT8, UINT16]);
check_received_version(config_version);

extra_usages['target'] =
Expand Down
68 changes: 52 additions & 16 deletions config-tool-web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,43 @@ <h1 class="mt-sm-5 mt-3">HID Remapper Configuration</h1>

<div class="tab-pane" id="nav-settings" role="tabpanel" tabindex="0">

<div class="mt-4">
<span class="me-3">Unmapped inputs passthrough on layer:</span>
<div class="form-check form-check-inline">
<input type="checkbox" id="unmapped_passthrough_checkbox0" class="form-check-input">
<label for="unmapped_passthrough_checkbox0" class="form-check-label">0</label>
</div>
<div class="form-check form-check-inline">
<input type="checkbox" id="unmapped_passthrough_checkbox1" class="form-check-input">
<label for="unmapped_passthrough_checkbox1" class="form-check-label">1</label>
</div>
<div class="form-check form-check-inline">
<input type="checkbox" id="unmapped_passthrough_checkbox2" class="form-check-input">
<label for="unmapped_passthrough_checkbox2" class="form-check-label">2</label>
<div class="row mt-4">
<div class="col-4 text-end">
Unmapped inputs passthrough on layer
</div>
<div class="form-check form-check-inline">
<input type="checkbox" id="unmapped_passthrough_checkbox3" class="form-check-input">
<label for="unmapped_passthrough_checkbox3" class="form-check-label">3</label>
<div class="col-8">
<div class="form-check form-check-inline">
<input type="checkbox" id="unmapped_passthrough_checkbox0" class="form-check-input">
<label for="unmapped_passthrough_checkbox0" class="form-check-label">0</label>
</div>
<div class="form-check form-check-inline">
<input type="checkbox" id="unmapped_passthrough_checkbox1" class="form-check-input">
<label for="unmapped_passthrough_checkbox1" class="form-check-label">1</label>
</div>
<div class="form-check form-check-inline">
<input type="checkbox" id="unmapped_passthrough_checkbox2" class="form-check-input">
<label for="unmapped_passthrough_checkbox2" class="form-check-label">2</label>
</div>
<div class="form-check form-check-inline">
<input type="checkbox" id="unmapped_passthrough_checkbox3" class="form-check-input">
<label for="unmapped_passthrough_checkbox3" class="form-check-label">3</label>
</div>
<div class="form-check form-check-inline d-none">
<input type="checkbox" id="unmapped_passthrough_checkbox4" class="form-check-input">
<label for="unmapped_passthrough_checkbox4" class="form-check-label">4</label>
</div>
<div class="form-check form-check-inline d-none">
<input type="checkbox" id="unmapped_passthrough_checkbox5" class="form-check-input">
<label for="unmapped_passthrough_checkbox5" class="form-check-label">5</label>
</div>
<div class="form-check form-check-inline d-none">
<input type="checkbox" id="unmapped_passthrough_checkbox6" class="form-check-input">
<label for="unmapped_passthrough_checkbox6" class="form-check-label">6</label>
</div>
<div class="form-check form-check-inline d-none">
<input type="checkbox" id="unmapped_passthrough_checkbox7" class="form-check-input">
<label for="unmapped_passthrough_checkbox7" class="form-check-label">7</label>
</div>
</div>
</div>
<div class="row mt-3">
Expand Down Expand Up @@ -323,6 +343,22 @@ <h5 class="mt-4">Custom usages</h5>
<input class="form-check-input layer_checkbox3" type="checkbox" value="">
<br><span class="text-muted small">3</span>
</div>
<div class="col-auto d-none">
<input class="form-check-input layer_checkbox4" type="checkbox" value="">
<br><span class="text-muted small">4</span>
</div>
<div class="col-auto d-none">
<input class="form-check-input layer_checkbox5" type="checkbox" value="">
<br><span class="text-muted small">5</span>
</div>
<div class="col-auto d-none">
<input class="form-check-input layer_checkbox6" type="checkbox" value="">
<br><span class="text-muted small">6</span>
</div>
<div class="col-auto d-none">
<input class="form-check-input layer_checkbox7" type="checkbox" value="">
<br><span class="text-muted small">7</span>
</div>
</div>
<div class="row gx-1">
<div class="col-auto ms-1" title="Sticky">
Expand Down
4 changes: 4 additions & 0 deletions config-tool-web/usages.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,10 @@ const common_target_usages = {
"0xfff10001": { 'name': 'Layer 1', 'class': 'other' },
"0xfff10002": { 'name': 'Layer 2', 'class': 'other' },
"0xfff10003": { 'name': 'Layer 3', 'class': 'other' },
"0xfff10004": { 'name': 'Layer 4', 'class': 'other' },
"0xfff10005": { 'name': 'Layer 5', 'class': 'other' },
"0xfff10006": { 'name': 'Layer 6', 'class': 'other' },
"0xfff10007": { 'name': 'Layer 7', 'class': 'other' },
"0xfff20001": { 'name': 'Macro 1', 'class': 'other' },
"0xfff20002": { 'name': 'Macro 2', 'class': 'other' },
"0xfff20003": { 'name': 'Macro 3', 'class': 'other' },
Expand Down
2 changes: 1 addition & 1 deletion config-tool/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
DEFAULT_SCALING = 1000
DEFAULT_MACRO_ENTRY_DURATION = 1

NLAYERS = 4
NLAYERS = 8

RESET_INTO_BOOTSEL = 1
SET_CONFIG = 2
Expand Down
6 changes: 4 additions & 2 deletions config-tool/get_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
report_id,
version,
flags,
unmapped_passthrough_layer_mask,
partial_scroll_timeout,
mapping_count,
our_usage_count,
Expand All @@ -26,13 +27,14 @@
our_descriptor_number,
macro_entry_duration,
quirk_count,
*_,
crc,
) = struct.unpack("<BBBLLLLBLBBBHL", data)
) = struct.unpack("<BBBBLHLLBLBBBHBL", data)
check_crc(data, crc)

config = {
"version": version,
"unmapped_passthrough_layers": mask_to_layer_list(flags & ((1 << NLAYERS) - 1)),
"unmapped_passthrough_layers": mask_to_layer_list(unmapped_passthrough_layer_mask),
"partial_scroll_timeout": partial_scroll_timeout,
"interval_override": interval_override,
"tap_hold_threshold": tap_hold_threshold,
Expand Down
13 changes: 6 additions & 7 deletions config-tool/set_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,24 @@
macro_entry_duration = config.get("macro_entry_duration", 1) - 1
gpio_output_mode = config.get("gpio_output_mode", 0)

flags = (
unmapped_passthrough_layer_mask
| (IGNORE_AUTH_DEV_INPUTS_FLAG if ignore_auth_dev_inputs else 0)
| (GPIO_OUTPUT_MODE_FLAG if gpio_output_mode == 1 else 0)
)
flags = 0
flags |= IGNORE_AUTH_DEV_INPUTS_FLAG if ignore_auth_dev_inputs else 0
flags |= GPIO_OUTPUT_MODE_FLAG if gpio_output_mode == 1 else 0

data = struct.pack(
"<BBBBLBLBBB13B",
"<BBBBBLBLBBB12B",
REPORT_ID_CONFIG,
CONFIG_VERSION,
SET_CONFIG,
flags,
unmapped_passthrough_layer_mask,
partial_scroll_timeout,
interval_override,
tap_hold_threshold,
gpio_debounce_time_ms,
our_descriptor_number,
macro_entry_duration,
*([0] * 13)
*([0] * 12)
)
device.send_feature_report(add_crc(data))

Expand Down
12 changes: 4 additions & 8 deletions firmware/src/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,7 @@ void load_config(const uint8_t* persisted_config) {
}

persist_config_v12_t* config = (persist_config_v12_t*) persisted_config;
unmapped_passthrough_layer_mask =
(config->flags & CONFIG_FLAG_UNMAPPED_PASSTHROUGH_MASK) >> CONFIG_FLAG_UNMAPPED_PASSTHROUGH_BIT;
unmapped_passthrough_layer_mask = config->unmapped_passthrough_layer_mask;
ignore_auth_dev_inputs = config->flags & (1 << CONFIG_FLAG_IGNORE_AUTH_DEV_INPUTS_BIT);
gpio_output_mode = !!(config->flags & (1 << CONFIG_FLAG_GPIO_OUTPUT_MODE_BIT));
partial_scroll_timeout = config->partial_scroll_timeout;
Expand Down Expand Up @@ -524,10 +523,9 @@ void load_config(const uint8_t* persisted_config) {
void fill_get_config(get_config_t* config) {
config->version = CONFIG_VERSION;
config->flags = 0;
config->flags |=
(unmapped_passthrough_layer_mask << CONFIG_FLAG_UNMAPPED_PASSTHROUGH_BIT) & CONFIG_FLAG_UNMAPPED_PASSTHROUGH_MASK;
config->flags |= ignore_auth_dev_inputs << CONFIG_FLAG_IGNORE_AUTH_DEV_INPUTS_BIT;
config->flags |= gpio_output_mode << CONFIG_FLAG_GPIO_OUTPUT_MODE_BIT;
config->unmapped_passthrough_layer_mask = unmapped_passthrough_layer_mask;
config->partial_scroll_timeout = partial_scroll_timeout;
config->tap_hold_threshold = tap_hold_threshold;
config->gpio_debounce_time_ms = gpio_debounce_time / 1000;
Expand All @@ -545,10 +543,9 @@ void fill_get_config(get_config_t* config) {
void fill_persist_config(persist_config_t* config) {
config->version = CONFIG_VERSION;
config->flags = 0;
config->flags |=
(unmapped_passthrough_layer_mask << CONFIG_FLAG_UNMAPPED_PASSTHROUGH_BIT) & CONFIG_FLAG_UNMAPPED_PASSTHROUGH_MASK;
config->flags |= ignore_auth_dev_inputs << CONFIG_FLAG_IGNORE_AUTH_DEV_INPUTS_BIT;
config->flags |= gpio_output_mode << CONFIG_FLAG_GPIO_OUTPUT_MODE_BIT;
config->unmapped_passthrough_layer_mask = unmapped_passthrough_layer_mask;
config->partial_scroll_timeout = partial_scroll_timeout;
config->tap_hold_threshold = tap_hold_threshold;
config->gpio_debounce_time_ms = gpio_debounce_time / 1000;
Expand Down Expand Up @@ -756,8 +753,7 @@ void handle_set_report1(uint8_t report_id, uint8_t const* buffer, uint16_t bufsi
break;
case ConfigCommand::SET_CONFIG: {
set_config_t* config = (set_config_t*) config_buffer->data;
unmapped_passthrough_layer_mask =
(config->flags & CONFIG_FLAG_UNMAPPED_PASSTHROUGH_MASK) >> CONFIG_FLAG_UNMAPPED_PASSTHROUGH_BIT;
unmapped_passthrough_layer_mask = config->unmapped_passthrough_layer_mask;
ignore_auth_dev_inputs = config->flags & (1 << CONFIG_FLAG_IGNORE_AUTH_DEV_INPUTS_BIT);
gpio_output_mode = !!(config->flags & (1 << CONFIG_FLAG_GPIO_OUTPUT_MODE_BIT));
partial_scroll_timeout = config->partial_scroll_timeout;
Expand Down
2 changes: 1 addition & 1 deletion firmware/src/globals.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ volatile bool their_descriptor_updated = false;
volatile bool suspended = false;
volatile bool config_updated = false;

uint8_t unmapped_passthrough_layer_mask = 0b00001111;
uint8_t unmapped_passthrough_layer_mask = 0b11111111;
uint32_t partial_scroll_timeout = 1000000;
uint32_t tap_hold_threshold = 200000;
uint64_t gpio_debounce_time = 5000;
Expand Down
7 changes: 5 additions & 2 deletions firmware/src/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,9 @@ struct __attribute__((packed)) quirk_t {
struct __attribute__((packed)) persist_config_v12_t {
uint8_t version;
uint8_t flags;
uint8_t unmapped_passthrough_layer_mask;
uint32_t partial_scroll_timeout;
uint32_t mapping_count;
uint16_t mapping_count;
uint8_t interval_override;
uint32_t tap_hold_threshold;
uint8_t gpio_debounce_time_ms;
Expand All @@ -282,8 +283,9 @@ typedef persist_config_v12_t persist_config_t;
struct __attribute__((packed)) get_config_t {
uint8_t version;
uint8_t flags;
uint8_t unmapped_passthrough_layer_mask;
uint32_t partial_scroll_timeout;
uint32_t mapping_count;
uint16_t mapping_count;
uint32_t our_usage_count;
uint32_t their_usage_count;
uint8_t interval_override;
Expand All @@ -296,6 +298,7 @@ struct __attribute__((packed)) get_config_t {

struct __attribute__((packed)) set_config_t {
uint8_t flags;
uint8_t unmapped_passthrough_layer_mask;
uint32_t partial_scroll_timeout;
uint8_t interval_override;
uint32_t tap_hold_threshold;
Expand Down

0 comments on commit 154fb33

Please sign in to comment.