Skip to content

Commit

Permalink
Make hub port show up in the Monitor tab
Browse files Browse the repository at this point in the history
  • Loading branch information
jfedor2 committed Apr 9, 2024
1 parent 154fb33 commit 0043826
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
15 changes: 12 additions & 3 deletions config-tool-web/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const NEXPRESSIONS = 8;
const MACRO_ITEMS_IN_PACKET = 6;
const IGNORE_AUTH_DEV_INPUTS_FLAG = 1 << 4;
const GPIO_OUTPUT_MODE_FLAG = 1 << 5;
const HUB_PORT_NONE = 255;

const QUIRK_FLAG_RELATIVE_MASK = 0b10000000;
const QUIRK_FLAG_SIGNED_MASK = 0b01000000;
Expand Down Expand Up @@ -1426,15 +1427,23 @@ function input_report_received(event) {
}

function update_monitor_ui(usage, value, hub_port) {
let element = document.getElementById('monitor_usage_' + usage);
const element_id = 'monitor_usage_' + usage + '_' + hub_port;
let element = document.getElementById(element_id);
if (element == null) {
const template = document.getElementById("monitor_template");
const container = document.getElementById("monitor_container");
element = template.content.cloneNode(true).firstElementChild;
element.querySelector('.monitor_usage').innerText = usage;
element.querySelector('.monitor_usage .usage_label').innerText = usage;
const port_badge = element.querySelector('.monitor_usage .hub_port_badge');
port_badge.innerText = hub_port;
if ((hub_port == 0) || (hub_port == HUB_PORT_NONE)) {
port_badge.classList.add('d-none');
} else {
port_badge.classList.remove('d-none');
}
element.querySelector('.monitor_readable_name').innerText = readable_usage_name(usage, false);
element.querySelector('.map_this_button').addEventListener("click", map_this_onclick(usage));
element.id = 'monitor_usage_' + usage;
element.id = element_id;
container.appendChild(element);
}

Expand Down
5 changes: 4 additions & 1 deletion config-tool-web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,10 @@ <h2 class="accordion-header">
<template id="monitor_template">
<div class="row monitor_row p-1 my-2 rounded">
<div class="col-1"><button type="button" title="map this" class="btn btn-sm btn-primary map_this_button" style="padding: 0rem 0.4rem;">+</button></div>
<div class="col-2 text-center monitor_usage font-monospace"></div>
<div class="col-2 text-center monitor_usage position-relative">
<span class="position-absolute top-50 start-0 translate-middle badge bg-info rounded-pill hub_port_badge">0</span>
<span class="font-monospace usage_label"></span>
</div>
<div class="col-3 text-center monitor_readable_name"></div>
<div class="col-2 text-end monitor_last_value"></div>
<div class="col-2 text-end monitor_min_value"></div>
Expand Down
18 changes: 13 additions & 5 deletions firmware/src/remapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ uint8_t port_register = 0;

uint64_t frame_counter = 0;

#define HUB_PORT_NONE 255
#define NPORTS 15
std::unordered_map<uint8_t, uint8_t> hub_ports; // dev_addr -> hub_port

Expand Down Expand Up @@ -1193,9 +1194,11 @@ inline void read_input_range(const uint8_t* report, int len, uint32_t source_usa
if (state_ptr_0 != NULL) {
*state_ptr_0 |= 1 << interface_idx;
}
int32_t* state_ptr_n = get_state_ptr(actual_usage, hub_port);
if (state_ptr_n != NULL) {
*state_ptr_n = 1 << interface_idx; // set the bit because in do_handle_received_report we clear it not knowing if it's "0" or "n"
if (hub_port != HUB_PORT_NONE) {
int32_t* state_ptr_n = get_state_ptr(actual_usage, hub_port);
if (state_ptr_n != NULL) {
*state_ptr_n = 1 << interface_idx; // set the bit because in do_handle_received_report we clear it not knowing if it's "0" or "n"
}
}
}
}
Expand Down Expand Up @@ -1333,6 +1336,9 @@ void do_handle_received_report(const uint8_t* report, int len, uint16_t interfac
}

void handle_received_midi(uint8_t hub_port, uint8_t* midi_msg) {
if (hub_port == 0) {
hub_port = HUB_PORT_NONE;
}
uint32_t usage = 0;
int32_t val = 0;
// ignore cable number and CIN
Expand Down Expand Up @@ -1361,7 +1367,9 @@ void handle_received_midi(uint8_t hub_port, uint8_t* midi_msg) {
}
if (usage != 0) {
set_input_state(usage, val, 0);
set_input_state(usage, val, hub_port);
if (hub_port != HUB_PORT_NONE) {
set_input_state(usage, val, hub_port);
}
if (monitor_enabled) {
monitor_usage(usage, val, hub_port);
}
Expand Down Expand Up @@ -1573,7 +1581,7 @@ void set_monitor_enabled(bool enabled) {
}

void device_connected_callback(uint16_t interface, uint16_t vid, uint16_t pid, uint8_t hub_port) {
hub_ports[interface >> 8] = (hub_port != 0) ? hub_port : 1;
hub_ports[interface >> 8] = (hub_port != 0) ? hub_port : HUB_PORT_NONE;
if (our_descriptor->device_connected != nullptr) {
our_descriptor->device_connected(interface, vid, pid);
}
Expand Down

0 comments on commit 0043826

Please sign in to comment.