change name of method getOfflineAs->isOffline to simplyfy the interface (#92)

This commit is contained in:
tomaszduda23
2022-07-07 01:11:55 +02:00
committed by GitHub
parent c09567c1a9
commit dd251eeaf9
3 changed files with 21 additions and 21 deletions

View File

@@ -284,23 +284,23 @@ static void _sendResponse(uint8_t code) {
response[2] = PROTO::OUTPUTS1::DYNAMIC; response[2] = PROTO::OUTPUTS1::DYNAMIC;
# endif # endif
if (_usb_kbd) { if (_usb_kbd) {
response[1] |= _usb_kbd->getOfflineAs(PROTO::PONG::KEYBOARD_OFFLINE); response[1] |= _usb_kbd->isOffline() ? PROTO::PONG::KEYBOARD_OFFLINE : 0;
response[1] |= _usb_kbd->getLedsAs(PROTO::PONG::CAPS, PROTO::PONG::SCROLL, PROTO::PONG::NUM); response[1] |= _usb_kbd->getLedsAs(PROTO::PONG::CAPS, PROTO::PONG::SCROLL, PROTO::PONG::NUM);
response[2] |= PROTO::OUTPUTS1::KEYBOARD::USB; response[2] |= PROTO::OUTPUTS1::KEYBOARD::USB;
} else if (_ps2_kbd) { } else if (_ps2_kbd) {
response[1] |= _ps2_kbd->getOfflineAs(PROTO::PONG::KEYBOARD_OFFLINE); response[1] |= _ps2_kbd->isOffline() ? PROTO::PONG::KEYBOARD_OFFLINE : 0;
response[1] |= _ps2_kbd->getLedsAs(PROTO::PONG::CAPS, PROTO::PONG::SCROLL, PROTO::PONG::NUM); response[1] |= _ps2_kbd->getLedsAs(PROTO::PONG::CAPS, PROTO::PONG::SCROLL, PROTO::PONG::NUM);
response[2] |= PROTO::OUTPUTS1::KEYBOARD::PS2; response[2] |= PROTO::OUTPUTS1::KEYBOARD::PS2;
} }
if (_usb_mouse_abs) { if (_usb_mouse_abs) {
response[1] |= _usb_mouse_abs->getOfflineAs(PROTO::PONG::MOUSE_OFFLINE); response[1] |= _usb_mouse_abs->isOffline() ? PROTO::PONG::MOUSE_OFFLINE : 0;
if (_usb_mouse_abs->isWin98FixEnabled()) { if (_usb_mouse_abs->isWin98FixEnabled()) {
response[2] |= PROTO::OUTPUTS1::MOUSE::USB_WIN98; response[2] |= PROTO::OUTPUTS1::MOUSE::USB_WIN98;
} else { } else {
response[2] |= PROTO::OUTPUTS1::MOUSE::USB_ABS; response[2] |= PROTO::OUTPUTS1::MOUSE::USB_ABS;
} }
} else if (_usb_mouse_rel) { } else if (_usb_mouse_rel) {
response[1] |= _usb_mouse_rel->getOfflineAs(PROTO::PONG::MOUSE_OFFLINE); response[1] |= _usb_mouse_rel->isOffline() ? PROTO::PONG::MOUSE_OFFLINE : 0;
response[2] |= PROTO::OUTPUTS1::MOUSE::USB_REL; response[2] |= PROTO::OUTPUTS1::MOUSE::USB_REL;
} // TODO: ps2 } // TODO: ps2
# ifdef AUM # ifdef AUM

View File

@@ -74,8 +74,8 @@ class Ps2Keyboard {
} }
} }
uint8_t getOfflineAs(uint8_t offline) { bool isOffline() {
return 0; return false;
} }
uint8_t getLedsAs(uint8_t caps, uint8_t scroll, uint8_t num) { uint8_t getLedsAs(uint8_t caps, uint8_t scroll, uint8_t num) {

View File

@@ -37,12 +37,12 @@
// https://github.com/arduino/ArduinoCore-avr/blob/2f67c916f6ab6193c404eebe22efe901e0f9542d/cores/arduino/USBCore.cpp#L249 // https://github.com/arduino/ArduinoCore-avr/blob/2f67c916f6ab6193c404eebe22efe901e0f9542d/cores/arduino/USBCore.cpp#L249
// https://sourceforge.net/p/arduinomidilib/svn/41/tree/branch/3.1/Teensy/teensy_core/usb_midi/usb_api.cpp#l103 // https://sourceforge.net/p/arduinomidilib/svn/41/tree/branch/3.1/Teensy/teensy_core/usb_midi/usb_api.cpp#l103
# ifdef AUM # ifdef AUM
# define CHECK_AUM_USB { if (!aumIsUsbConnected()) { return offline; } } # define CHECK_AUM_USB { if (!aumIsUsbConnected()) { return true; } }
# else # else
# define CHECK_AUM_USB # define CHECK_AUM_USB
# endif # endif
# define CLS_GET_OFFLINE_AS(_hid) \ # define CLS_IS_OFFLINE(_hid) \
uint8_t getOfflineAs(uint8_t offline) { \ bool isOffline() { \
CHECK_AUM_USB; \ CHECK_AUM_USB; \
uint8_t ep = _hid.getPluggedEndpoint(); \ uint8_t ep = _hid.getPluggedEndpoint(); \
uint8_t intr_state = SREG; \ uint8_t intr_state = SREG; \
@@ -51,16 +51,16 @@
bool rw_allowed = UEINTX & (1 << RWAL); \ bool rw_allowed = UEINTX & (1 << RWAL); \
SREG = intr_state; \ SREG = intr_state; \
if (rw_allowed) { \ if (rw_allowed) { \
return 0; \ return false; \
} \ } \
return offline; \ return true; \
} }
# define CHECK_HID_EP { if (getOfflineAs(1)) return; } # define CHECK_HID_EP { if (isOffline()) return; }
#else #else
# define CLS_GET_OFFLINE_AS(_hid) \ # define CLS_IS_OFFLINE(_hid) \
uint8_t getOfflineAs(uint8_t offline) { \ bool isOffline() { \
return 0; \ return false; \
} }
# define CHECK_HID_EP # define CHECK_HID_EP
@@ -79,7 +79,7 @@ class UsbKeyboard {
static unsigned long prev_ts = 0; static unsigned long prev_ts = 0;
if (is_micros_timed_out(prev_ts, 50000)) { if (is_micros_timed_out(prev_ts, 50000)) {
static bool prev_online = true; static bool prev_online = true;
bool online = !getOfflineAs(1); bool online = !isOffline();
if (!_sent || (online && !prev_online)) { if (!_sent || (online && !prev_online)) {
_sendCurrent(); _sendCurrent();
} }
@@ -102,7 +102,7 @@ class UsbKeyboard {
} }
} }
CLS_GET_OFFLINE_AS(_kbd) CLS_IS_OFFLINE(_kbd)
uint8_t getLedsAs(uint8_t caps, uint8_t scroll, uint8_t num) { uint8_t getLedsAs(uint8_t caps, uint8_t scroll, uint8_t num) {
uint8_t leds = _kbd.getLeds(); uint8_t leds = _kbd.getLeds();
@@ -119,7 +119,7 @@ class UsbKeyboard {
void _sendCurrent() { void _sendCurrent() {
# ifdef HID_USB_CHECK_ENDPOINT # ifdef HID_USB_CHECK_ENDPOINT
if (getOfflineAs(1)) { if (isOffline()) {
_sent = false; _sent = false;
} else { } else {
# endif # endif
@@ -175,7 +175,7 @@ class UsbMouseAbsolute {
_mouse.move(0, 0, delta_y); _mouse.move(0, 0, delta_y);
} }
CLS_GET_OFFLINE_AS(_mouse) CLS_IS_OFFLINE(_mouse)
private: private:
SingleAbsoluteMouse_ _mouse; SingleAbsoluteMouse_ _mouse;
@@ -212,7 +212,7 @@ class UsbMouseRelative {
_mouse.move(0, 0, delta_y); _mouse.move(0, 0, delta_y);
} }
CLS_GET_OFFLINE_AS(_mouse) CLS_IS_OFFLINE(_mouse)
private: private:
BootMouse_ _mouse; BootMouse_ _mouse;
@@ -225,5 +225,5 @@ class UsbMouseRelative {
}; };
#undef CLS_SEND_BUTTONS #undef CLS_SEND_BUTTONS
#undef CLS_GET_OFFLINE_AS #undef CLS_IS_OFFLINE
#undef CHECK_HID_EP #undef CHECK_HID_EP