diff options
author | tomaszduda23 <[email protected]> | 2022-09-12 11:53:52 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2022-09-12 12:53:52 +0300 |
commit | 615863a84846a5a26e5505bdd5e0d63d3baee6e0 (patch) | |
tree | 7d3c8e672dd4356d5b6e3c480c77d284e2845ba7 /hid/src | |
parent | ce43938d2810fb0bf5d9c89116cf5fc2d02ca40c (diff) |
add SW reset (#107)
Diffstat (limited to 'hid/src')
-rw-r--r-- | hid/src/main.cpp | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/hid/src/main.cpp b/hid/src/main.cpp index 5e01c6ed..791ec3ad 100644 --- a/hid/src/main.cpp +++ b/hid/src/main.cpp @@ -41,27 +41,35 @@ #ifdef AUM # include "aum.h" #endif +#include "board.h" #include "outputs.h" - +static DRIVERS::Board* _board; static Outputs _out; #ifdef HID_DYNAMIC static bool _reset_required = false; +static unsigned long _reset_timestamp; +#define RESET_TIMEOUT (500000) #endif // ----------------------------------------------------------------------------- +static void _resetRequest() { + _reset_required = true; + _reset_timestamp = micros(); +} + static void _cmdSetKeyboard(const uint8_t *data) { // 1 bytes # ifdef HID_DYNAMIC _out.writeOutputs(PROTO::OUTPUTS1::KEYBOARD::MASK, data[0], false); - _reset_required = true; + _resetRequest(); # endif } static void _cmdSetMouse(const uint8_t *data) { // 1 bytes # ifdef HID_DYNAMIC _out.writeOutputs(PROTO::OUTPUTS1::MOUSE::MASK, data[0], false); - _reset_required = true; + _resetRequest(); # endif } @@ -150,6 +158,9 @@ static void _sendResponse(uint8_t code) { # ifdef HID_DYNAMIC if (_reset_required) { response[1] |= PROTO::PONG::RESET_REQUIRED; + if (is_micros_timed_out(_reset_timestamp, RESET_TIMEOUT)) { + _board->reset(); + } } response[2] = PROTO::OUTPUTS1::DYNAMIC; # endif @@ -221,6 +232,7 @@ void setup() { # elif defined(CMD_SPI) spiBegin(); # endif + _board = DRIVERS::Factory::makeBoard(DRIVERS::BOARD); } void loop() { |