astyle with current project style guidelines

pull/365/head
Jesse Vincent 7 years ago
parent fbe4c44179
commit 8786adbc84
No known key found for this signature in database
GPG Key ID: 122F5DF7108E4046

@ -20,100 +20,99 @@ uint32_t MouseKeys_::endTime;
uint32_t MouseKeys_::wheelEndTime; uint32_t MouseKeys_::wheelEndTime;
void MouseKeys_::scrollWheel(uint8_t keyCode) { void MouseKeys_::scrollWheel(uint8_t keyCode) {
if (millis() < wheelEndTime) if (millis() < wheelEndTime)
return; return;
wheelEndTime = millis() + wheelDelay; wheelEndTime = millis() + wheelDelay;
if (keyCode & KEY_MOUSE_UP) if (keyCode & KEY_MOUSE_UP)
Mouse.move(0, 0, wheelSpeed); Mouse.move(0, 0, wheelSpeed);
else if (keyCode & KEY_MOUSE_DOWN) else if (keyCode & KEY_MOUSE_DOWN)
Mouse.move(0, 0, -wheelSpeed); Mouse.move(0, 0, -wheelSpeed);
} }
void MouseKeys_::loopHook(bool postClear) { void MouseKeys_::loopHook(bool postClear) {
if (postClear) { if (postClear) {
mouseMoveIntent = 0; mouseMoveIntent = 0;
return; return;
} }
if (mouseMoveIntent == 0) { if (mouseMoveIntent == 0) {
MouseWrapper.accelStep = 0; MouseWrapper.accelStep = 0;
endTime = 0; endTime = 0;
accelEndTime = 0; accelEndTime = 0;
return; return;
} }
if (millis() < endTime) if (millis() < endTime)
return; return;
endTime = millis() + speedDelay; endTime = millis() + speedDelay;
int8_t moveX = 0, moveY = 0; int8_t moveX = 0, moveY = 0;
if (millis() >= accelEndTime) { if (millis() >= accelEndTime) {
if (MouseWrapper.accelStep < 255 - accelSpeed) if (MouseWrapper.accelStep < 255 - accelSpeed)
MouseWrapper.accelStep += accelSpeed; MouseWrapper.accelStep += accelSpeed;
} }
if (mouseMoveIntent & KEY_MOUSE_UP) if (mouseMoveIntent & KEY_MOUSE_UP)
moveY = -speed; moveY = -speed;
else if (mouseMoveIntent & KEY_MOUSE_DOWN) else if (mouseMoveIntent & KEY_MOUSE_DOWN)
moveY = speed; moveY = speed;
if (mouseMoveIntent & KEY_MOUSE_LEFT) if (mouseMoveIntent & KEY_MOUSE_LEFT)
moveX = -speed; moveX = -speed;
else if (mouseMoveIntent & KEY_MOUSE_RIGHT) else if (mouseMoveIntent & KEY_MOUSE_RIGHT)
moveX = speed; moveX = speed;
MouseWrapper.move(moveX, moveY); MouseWrapper.move(moveX, moveY);
} }
Key MouseKeys_::eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyState) { Key MouseKeys_::eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyState) {
if (mappedKey.flags != (SYNTHETIC | IS_MOUSE_KEY)) if (mappedKey.flags != (SYNTHETIC | IS_MOUSE_KEY))
return mappedKey; return mappedKey;
if (mappedKey.keyCode & KEY_MOUSE_BUTTON && !(mappedKey.keyCode & KEY_MOUSE_WARP)) { if (mappedKey.keyCode & KEY_MOUSE_BUTTON && !(mappedKey.keyCode & KEY_MOUSE_WARP)) {
uint8_t button = mappedKey.keyCode & ~KEY_MOUSE_BUTTON; uint8_t button = mappedKey.keyCode & ~KEY_MOUSE_BUTTON;
if (key_toggled_on(keyState)) { if (key_toggled_on(keyState)) {
MouseWrapper.press_button(button); MouseWrapper.press_button(button);
} else if (key_toggled_off(keyState)) { } else if (key_toggled_off(keyState)) {
MouseWrapper.release_button(button); MouseWrapper.release_button(button);
} }
} else if (!(mappedKey.keyCode & KEY_MOUSE_WARP)) { } else if (!(mappedKey.keyCode & KEY_MOUSE_WARP)) {
if (key_toggled_on(keyState)) { if (key_toggled_on(keyState)) {
endTime = millis() + speedDelay; endTime = millis() + speedDelay;
accelEndTime = millis() + accelDelay; accelEndTime = millis() + accelDelay;
wheelEndTime = 0; wheelEndTime = 0;
} }
if (key_is_pressed(keyState)) { if (key_is_pressed(keyState)) {
if (mappedKey.keyCode & KEY_MOUSE_WHEEL) { if (mappedKey.keyCode & KEY_MOUSE_WHEEL) {
scrollWheel (mappedKey.keyCode); scrollWheel(mappedKey.keyCode);
} } else
else mouseMoveIntent |= mappedKey.keyCode;
mouseMoveIntent |= mappedKey.keyCode; }
} } else if (key_toggled_on(keyState)) {
} else if (key_toggled_on(keyState)) { if (mappedKey.keyCode & KEY_MOUSE_WARP && mappedKey.flags & IS_MOUSE_KEY) {
if (mappedKey.keyCode & KEY_MOUSE_WARP && mappedKey.flags & IS_MOUSE_KEY) { // we don't pass in the left and up values because those are the
// we don't pass in the left and up values because those are the // default, "no-op" conditionals
// default, "no-op" conditionals MouseWrapper.warp(((mappedKey.keyCode & KEY_MOUSE_WARP_END) ? WARP_END : 0x00) |
MouseWrapper.warp( ((mappedKey.keyCode & KEY_MOUSE_WARP_END) ? WARP_END : 0x00) | ((mappedKey.keyCode & KEY_MOUSE_DOWN) ? WARP_DOWN : 0x00) |
((mappedKey.keyCode & KEY_MOUSE_DOWN) ? WARP_DOWN : 0x00) | ((mappedKey.keyCode & KEY_MOUSE_RIGHT) ? WARP_RIGHT : 0x00));
((mappedKey.keyCode & KEY_MOUSE_RIGHT) ? WARP_RIGHT : 0x00) );
}
} }
}
return Key_NoKey; return Key_NoKey;
} }
MouseKeys_::MouseKeys_(void) { MouseKeys_::MouseKeys_(void) {
} }
void void
MouseKeys_::begin (void) { MouseKeys_::begin(void) {
event_handler_hook_use(eventHandlerHook); event_handler_hook_use(eventHandlerHook);
loop_hook_use(loopHook); loop_hook_use(loopHook);
} }
MouseKeys_ MouseKeys; MouseKeys_ MouseKeys;

@ -4,27 +4,27 @@
#include "MouseKeyDefs.h" #include "MouseKeyDefs.h"
class MouseKeys_ : public KaleidoscopePlugin { class MouseKeys_ : public KaleidoscopePlugin {
public: public:
MouseKeys_ (void); MouseKeys_(void);
virtual void begin(void) final; virtual void begin(void) final;
static uint8_t speed; static uint8_t speed;
static uint16_t speedDelay; static uint16_t speedDelay;
static uint8_t accelSpeed; static uint8_t accelSpeed;
static uint16_t accelDelay; static uint16_t accelDelay;
static uint8_t wheelSpeed; static uint8_t wheelSpeed;
static uint16_t wheelDelay; static uint16_t wheelDelay;
private: private:
static uint8_t mouseMoveIntent; static uint8_t mouseMoveIntent;
static uint32_t endTime; static uint32_t endTime;
static uint32_t accelEndTime; static uint32_t accelEndTime;
static uint32_t wheelEndTime; static uint32_t wheelEndTime;
static void scrollWheel(uint8_t keyCode); static void scrollWheel(uint8_t keyCode);
static void loopHook(bool postClear); static void loopHook(bool postClear);
static Key eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyState); static Key eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyState);
}; };
extern MouseKeys_ MouseKeys; extern MouseKeys_ MouseKeys;

@ -13,102 +13,102 @@ boolean MouseWrapper_::is_warping;
uint8_t MouseWrapper_::accelStep; uint8_t MouseWrapper_::accelStep;
MouseWrapper_::MouseWrapper_(void) { MouseWrapper_::MouseWrapper_(void) {
Mouse.begin(); Mouse.begin();
AbsoluteMouse.begin(); AbsoluteMouse.begin();
} }
void MouseWrapper_::press_button(uint8_t button) { void MouseWrapper_::press_button(uint8_t button) {
Mouse.press(button); Mouse.press(button);
end_warping(); end_warping();
} }
void MouseWrapper_::release_button(uint8_t button) { void MouseWrapper_::release_button(uint8_t button) {
Mouse.release(button); Mouse.release(button);
} }
void MouseWrapper_::warp_jump(uint16_t left, uint16_t top, uint16_t height, uint16_t width) { void MouseWrapper_::warp_jump(uint16_t left, uint16_t top, uint16_t height, uint16_t width) {
uint16_t x_center = left + width/2; uint16_t x_center = left + width/2;
uint16_t y_center = top + height/2; uint16_t y_center = top + height/2;
AbsoluteMouse.moveTo(x_center, y_center); AbsoluteMouse.moveTo(x_center, y_center);
} }
void MouseWrapper_::begin_warping() { void MouseWrapper_::begin_warping() {
section_left = WARP_ABS_LEFT; section_left = WARP_ABS_LEFT;
section_top = WARP_ABS_TOP; section_top = WARP_ABS_TOP;
next_width = MAX_WARP_WIDTH; next_width = MAX_WARP_WIDTH;
next_height = MAX_WARP_HEIGHT; next_height = MAX_WARP_HEIGHT;
is_warping = true; is_warping = true;
} }
void MouseWrapper_::end_warping() { void MouseWrapper_::end_warping() {
is_warping= false; is_warping= false;
} }
void MouseWrapper_::warp(uint8_t warp_cmd) { void MouseWrapper_::warp(uint8_t warp_cmd) {
if (is_warping == false) { if (is_warping == false) {
begin_warping(); begin_warping();
} }
if (warp_cmd & WARP_END) { if (warp_cmd & WARP_END) {
end_warping(); end_warping();
return; return;
} }
next_width = next_width/2; next_width = next_width/2;
next_height = next_height/2; next_height = next_height/2;
if (warp_cmd & WARP_UP) { if (warp_cmd & WARP_UP) {
// Serial.print(" - up "); // Serial.print(" - up ");
} else if (warp_cmd & WARP_DOWN) { } else if (warp_cmd & WARP_DOWN) {
// Serial.print(" - down "); // Serial.print(" - down ");
section_top = section_top + next_height; section_top = section_top + next_height;
} }
if (warp_cmd & WARP_LEFT) { if (warp_cmd & WARP_LEFT) {
// Serial.print(" - left "); // Serial.print(" - left ");
} else if (warp_cmd & WARP_RIGHT) { } else if (warp_cmd & WARP_RIGHT) {
// Serial.print(" - right "); // Serial.print(" - right ");
section_left = section_left + next_width; section_left = section_left + next_width;
} }
warp_jump(section_left, section_top, next_height,next_width); warp_jump(section_left, section_top, next_height,next_width);
} }
// cubic wave function based on code from FastLED // cubic wave function based on code from FastLED
uint8_t MouseWrapper_::acceleration(uint8_t cycles) { uint8_t MouseWrapper_::acceleration(uint8_t cycles) {
uint8_t i = cycles; uint8_t i = cycles;
if( i & 0x80) { if (i & 0x80) {
i = 255 - i; i = 255 - i;
} }
i = i << 1; i = i << 1;
uint8_t ii = (i*i) >> 8; uint8_t ii = (i*i) >> 8;
uint8_t iii = (ii*i) >> 8; uint8_t iii = (ii*i) >> 8;
i = (( (3 * (uint16_t)(ii)) - ( 2 * (uint16_t)(iii))) / 2) + ACCELERATION_FLOOR; i = (((3 * (uint16_t)(ii)) - (2 * (uint16_t)(iii))) / 2) + ACCELERATION_FLOOR;
if (i > ACCELERATION_CEIL) { if (i > ACCELERATION_CEIL) {
i = ACCELERATION_CEIL; i = ACCELERATION_CEIL;
} }
return i; return i;
} }
void MouseWrapper_::move(int8_t x, int8_t y) { void MouseWrapper_::move(int8_t x, int8_t y) {
int16_t moveX =0; int16_t moveX =0;
int16_t moveY = 0; int16_t moveY = 0;
if (x != 0 ) { if (x != 0) {
moveX = (x * acceleration(accelStep)); moveX = (x * acceleration(accelStep));
} }
if (y != 0) { if (y != 0) {
moveY = (y * acceleration(accelStep)); moveY = (y * acceleration(accelStep));
} }
end_warping(); end_warping();
Mouse.move(moveX, moveY, 0); Mouse.move(moveX, moveY, 0);
} }
MouseWrapper_ MouseWrapper; MouseWrapper_ MouseWrapper;

@ -28,26 +28,26 @@
#define ACCELERATION_CEIL 50 #define ACCELERATION_CEIL 50
class MouseWrapper_ { class MouseWrapper_ {
public: public:
MouseWrapper_(void); MouseWrapper_(void);
static void move(int8_t x, int8_t y); static void move(int8_t x, int8_t y);
static void warp(uint8_t warp_cmd); static void warp(uint8_t warp_cmd);
static void press_button(uint8_t button); static void press_button(uint8_t button);
static void release_button(uint8_t button); static void release_button(uint8_t button);
static uint8_t accelStep; static uint8_t accelStep;
private: private:
static uint16_t next_width; static uint16_t next_width;
static uint16_t next_height; static uint16_t next_height;
static uint16_t section_top; static uint16_t section_top;
static uint16_t section_left; static uint16_t section_left;
static boolean is_warping; static boolean is_warping;
static uint8_t acceleration(uint8_t cycles); static uint8_t acceleration(uint8_t cycles);
static void begin_warping(); static void begin_warping();
static void end_warping(); static void end_warping();
static void warp_jump(uint16_t left, uint16_t top, uint16_t height, uint16_t width); static void warp_jump(uint16_t left, uint16_t top, uint16_t height, uint16_t width);
}; };
extern MouseWrapper_ MouseWrapper; extern MouseWrapper_ MouseWrapper;

Loading…
Cancel
Save