summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomaszduda23 <[email protected]>2022-09-13 11:58:08 +0200
committerGitHub <[email protected]>2022-09-13 12:58:08 +0300
commit967361f775dfba46ef0219e7f5d56d0f8253ef3d (patch)
tree13f6bc1e7720798d4473fc3e5fb4c2be36e8d264
parentfa01d92dde2d4c199c8f6b394a72a4f41c28cfe9 (diff)
Status led (#109)
* add SW reset * adds watchdog * add status led
-rw-r--r--hid/lib/drivers-stm32/board-stm32.h61
-rw-r--r--hid/lib/drivers/board.h7
-rw-r--r--hid/src/main.cpp13
3 files changed, 78 insertions, 3 deletions
diff --git a/hid/lib/drivers-stm32/board-stm32.h b/hid/lib/drivers-stm32/board-stm32.h
index 118138ad..b4164766 100644
--- a/hid/lib/drivers-stm32/board-stm32.h
+++ b/hid/lib/drivers-stm32/board-stm32.h
@@ -32,14 +32,73 @@ namespace DRIVERS {
BoardStm32() : Board(BOARD){
//2 sec timeout
iwdg_init(IWDG_PRE_16, 0xFFF);
+ pinMode(LED_BUILTIN, OUTPUT);
}
void reset() override {
nvic_sys_reset();
}
- void periodic() {
+ void periodic() override {
iwdg_feed();
+ if (is_micros_timed_out(_prev_ts, 100000)) {
+ switch(_state)
+ {
+ case 0:
+ digitalWrite(LED_BUILTIN, LOW);
+ break;
+ case 2:
+ if(_rx_data) {
+ _rx_data = false;
+ digitalWrite(LED_BUILTIN, LOW);
+ }
+ break;
+ case 4:
+ if(_keyboard_online) {
+ _keyboard_online = false;
+ digitalWrite(LED_BUILTIN, LOW);
+ }
+ break;
+ case 8:
+ if(_mouse_online) {
+ _mouse_online = false;
+ digitalWrite(LED_BUILTIN, LOW);
+ }
+ break;
+ case 1: // heartbeat off
+ case 3: // _rx_data off
+ case 7: // _keyboard_online off
+ case 11: // _mouse_online off
+ digitalWrite(LED_BUILTIN, HIGH);
+ break;
+ case 19:
+ _state = -1;
+ break;
+ }
+ ++_state;
+ _prev_ts = micros();
+ }
}
+
+ void updateStatus(status status) override {
+ switch (status)
+ {
+ case RX_DATA:
+ _rx_data = true;
+ break;
+ case KEYBOARD_ONLINE:
+ _keyboard_online = true;
+ break;
+ case MOUSE_ONLINE:
+ _mouse_online = true;
+ break;
+ }
+ }
+ private:
+ unsigned long _prev_ts = 0;
+ uint8_t _state = 0;
+ bool _rx_data = false;
+ bool _keyboard_online = false;
+ bool _mouse_online = false;
};
}
diff --git a/hid/lib/drivers/board.h b/hid/lib/drivers/board.h
index 50730ee1..2f9bcad7 100644
--- a/hid/lib/drivers/board.h
+++ b/hid/lib/drivers/board.h
@@ -26,9 +26,16 @@
namespace DRIVERS {
+ enum status {
+ RX_DATA = 0,
+ KEYBOARD_ONLINE,
+ MOUSE_ONLINE,
+ };
+
struct Board : public Driver {
using Driver::Driver;
virtual void reset() {}
virtual void periodic() {}
+ virtual void updateStatus(status status) {}
};
}
diff --git a/hid/src/main.cpp b/hid/src/main.cpp
index 802abc15..376d8a68 100644
--- a/hid/src/main.cpp
+++ b/hid/src/main.cpp
@@ -120,6 +120,7 @@ static void _cmdMouseWheelEvent(const uint8_t *data) { // 2 bytes
}
static uint8_t _handleRequest(const uint8_t *data) { // 8 bytes
+ _board->updateStatus(DRIVERS::RX_DATA);
if (PROTO::crc16(data, 6) == PROTO::merge8(data[6], data[7])) {
# define HANDLE(_handler) { _handler(data + 2); return PROTO::PONG::OK; }
switch (data[1]) {
@@ -165,7 +166,11 @@ static void _sendResponse(uint8_t code) {
response[2] = PROTO::OUTPUTS1::DYNAMIC;
# endif
if (_out.kbd->getType() != DRIVERS::DUMMY) {
- response[1] |= (_out.kbd->isOffline() ? PROTO::PONG::KEYBOARD_OFFLINE : 0);
+ if(_out.kbd->isOffline()) {
+ response[1] |= PROTO::PONG::KEYBOARD_OFFLINE;
+ } else {
+ _board->updateStatus(DRIVERS::KEYBOARD_ONLINE);
+ }
DRIVERS::KeyboardLedsState leds = _out.kbd->getLeds();
response[1] |= (leds.caps ? PROTO::PONG::CAPS : 0);
response[1] |= (leds.num ? PROTO::PONG::NUM : 0);
@@ -180,7 +185,11 @@ static void _sendResponse(uint8_t code) {
}
}
if (_out.mouse->getType() != DRIVERS::DUMMY) {
- response[1] |= (_out.mouse->isOffline() ? PROTO::PONG::MOUSE_OFFLINE : 0);
+ if(_out.mouse->isOffline()) {
+ response[1] |= PROTO::PONG::MOUSE_OFFLINE;
+ } else {
+ _board->updateStatus(DRIVERS::MOUSE_ONLINE);
+ }
switch (_out.mouse->getType()) {
case DRIVERS::USB_MOUSE_ABSOLUTE_WIN98:
response[2] |= PROTO::OUTPUTS1::MOUSE::USB_WIN98;