astyle with current project style guidelines

pull/365/head
Jesse Vincent 8 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;
void MouseKeys_::scrollWheel(uint8_t keyCode) {
if (millis() < wheelEndTime)
return;
if (millis() < wheelEndTime)
return;
wheelEndTime = millis() + wheelDelay;
wheelEndTime = millis() + wheelDelay;
if (keyCode & KEY_MOUSE_UP)
Mouse.move(0, 0, wheelSpeed);
else if (keyCode & KEY_MOUSE_DOWN)
Mouse.move(0, 0, -wheelSpeed);
if (keyCode & KEY_MOUSE_UP)
Mouse.move(0, 0, wheelSpeed);
else if (keyCode & KEY_MOUSE_DOWN)
Mouse.move(0, 0, -wheelSpeed);
}
void MouseKeys_::loopHook(bool postClear) {
if (postClear) {
mouseMoveIntent = 0;
return;
}
if (postClear) {
mouseMoveIntent = 0;
return;
}
if (mouseMoveIntent == 0) {
MouseWrapper.accelStep = 0;
endTime = 0;
accelEndTime = 0;
return;
}
if (mouseMoveIntent == 0) {
MouseWrapper.accelStep = 0;
endTime = 0;
accelEndTime = 0;
return;
}
if (millis() < endTime)
return;
if (millis() < endTime)
return;
endTime = millis() + speedDelay;
endTime = millis() + speedDelay;
int8_t moveX = 0, moveY = 0;
int8_t moveX = 0, moveY = 0;
if (millis() >= accelEndTime) {
if (MouseWrapper.accelStep < 255 - accelSpeed)
MouseWrapper.accelStep += accelSpeed;
}
if (millis() >= accelEndTime) {
if (MouseWrapper.accelStep < 255 - accelSpeed)
MouseWrapper.accelStep += accelSpeed;
}
if (mouseMoveIntent & KEY_MOUSE_UP)
moveY = -speed;
else if (mouseMoveIntent & KEY_MOUSE_DOWN)
moveY = speed;
if (mouseMoveIntent & KEY_MOUSE_UP)
moveY = -speed;
else if (mouseMoveIntent & KEY_MOUSE_DOWN)
moveY = speed;
if (mouseMoveIntent & KEY_MOUSE_LEFT)
moveX = -speed;
else if (mouseMoveIntent & KEY_MOUSE_RIGHT)
moveX = speed;
if (mouseMoveIntent & KEY_MOUSE_LEFT)
moveX = -speed;
else if (mouseMoveIntent & KEY_MOUSE_RIGHT)
moveX = speed;
MouseWrapper.move(moveX, moveY);
MouseWrapper.move(moveX, moveY);
}
Key MouseKeys_::eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyState) {
if (mappedKey.flags != (SYNTHETIC | IS_MOUSE_KEY))
return mappedKey;
if (mappedKey.keyCode & KEY_MOUSE_BUTTON && !(mappedKey.keyCode & KEY_MOUSE_WARP)) {
uint8_t button = mappedKey.keyCode & ~KEY_MOUSE_BUTTON;
if (key_toggled_on(keyState)) {
MouseWrapper.press_button(button);
} else if (key_toggled_off(keyState)) {
MouseWrapper.release_button(button);
}
} else if (!(mappedKey.keyCode & KEY_MOUSE_WARP)) {
if (key_toggled_on(keyState)) {
endTime = millis() + speedDelay;
accelEndTime = millis() + accelDelay;
wheelEndTime = 0;
}
if (key_is_pressed(keyState)) {
if (mappedKey.keyCode & KEY_MOUSE_WHEEL) {
scrollWheel (mappedKey.keyCode);
}
else
mouseMoveIntent |= mappedKey.keyCode;
}
} else if (key_toggled_on(keyState)) {
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
// default, "no-op" conditionals
MouseWrapper.warp( ((mappedKey.keyCode & KEY_MOUSE_WARP_END) ? WARP_END : 0x00) |
((mappedKey.keyCode & KEY_MOUSE_DOWN) ? WARP_DOWN : 0x00) |
((mappedKey.keyCode & KEY_MOUSE_RIGHT) ? WARP_RIGHT : 0x00) );
}
if (mappedKey.flags != (SYNTHETIC | IS_MOUSE_KEY))
return mappedKey;
if (mappedKey.keyCode & KEY_MOUSE_BUTTON && !(mappedKey.keyCode & KEY_MOUSE_WARP)) {
uint8_t button = mappedKey.keyCode & ~KEY_MOUSE_BUTTON;
if (key_toggled_on(keyState)) {
MouseWrapper.press_button(button);
} else if (key_toggled_off(keyState)) {
MouseWrapper.release_button(button);
}
} else if (!(mappedKey.keyCode & KEY_MOUSE_WARP)) {
if (key_toggled_on(keyState)) {
endTime = millis() + speedDelay;
accelEndTime = millis() + accelDelay;
wheelEndTime = 0;
}
if (key_is_pressed(keyState)) {
if (mappedKey.keyCode & KEY_MOUSE_WHEEL) {
scrollWheel(mappedKey.keyCode);
} else
mouseMoveIntent |= mappedKey.keyCode;
}
} else if (key_toggled_on(keyState)) {
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
// default, "no-op" conditionals
MouseWrapper.warp(((mappedKey.keyCode & KEY_MOUSE_WARP_END) ? WARP_END : 0x00) |
((mappedKey.keyCode & KEY_MOUSE_DOWN) ? WARP_DOWN : 0x00) |
((mappedKey.keyCode & KEY_MOUSE_RIGHT) ? WARP_RIGHT : 0x00));
}
}
return Key_NoKey;
return Key_NoKey;
}
MouseKeys_::MouseKeys_(void) {
}
void
MouseKeys_::begin (void) {
event_handler_hook_use(eventHandlerHook);
loop_hook_use(loopHook);
MouseKeys_::begin(void) {
event_handler_hook_use(eventHandlerHook);
loop_hook_use(loopHook);
}
MouseKeys_ MouseKeys;

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

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

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

Loading…
Cancel
Save