Skip to content

Commit

Permalink
Reset internal state on config save
Browse files Browse the repository at this point in the history
We now reset registers, frame counter ("time") and accumulated
fractional relative usage values on configuration save.

This should make it easier to test certain configurations without
having to unplug the device every time.
  • Loading branch information
jfedor2 committed Dec 2, 2024
1 parent fcc8c6c commit cb88733
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion firmware/src/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ void handle_set_report1(uint8_t report_id, uint8_t const* buffer, uint16_t bufsi
case ConfigCommand::RESUME:
resume_pending = true;
config_updated = true;
// XXX clear input_state, sticky_state, accumulated?
reset_state();
break;
case ConfigCommand::PAIR_NEW_DEVICE:
pair_new_device();
Expand Down
7 changes: 7 additions & 0 deletions firmware/src/remapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1918,6 +1918,13 @@ void print_stats() {
processing_time = 0;
}

void reset_state() {
memset(registers, 0, sizeof(registers));
accumulated.clear();
layer_state_mask = 1;
frame_counter = 0;
}

void set_monitor_enabled(bool enabled) {
if (monitor_enabled != enabled) {
monitor_input_state.clear();
Expand Down
1 change: 1 addition & 0 deletions firmware/src/remapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ void queue_get_feature_report(uint16_t interface, uint8_t report_id, uint8_t len
void send_out_report();
bool send_monitor_report(send_report_t do_send_report);
void print_stats();
void reset_state();

void set_monitor_enabled(bool enabled);
void monitor_usage(uint32_t usage, int32_t value, uint8_t hub_port);
Expand Down

0 comments on commit cb88733

Please sign in to comment.