Status led (#109)

* add SW reset

* adds watchdog

* add status led
This commit is contained in:
tomaszduda23 2022-09-13 11:58:08 +02:00 committed by GitHub
parent fa01d92dde
commit 967361f775
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 78 additions and 3 deletions

View File

@ -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;
};
}

View File

@ -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) {}
};
}

View File

@ -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;