MouseWrapper: static-ification

Mark most of the things static, to save a couple of bytes in program-space.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/365/head
Gergely Nagy 8 years ago
parent ba1a8604a0
commit ce734dbd37

@ -4,6 +4,13 @@
// //
#include "MouseWrapper.h" #include "MouseWrapper.h"
uint16_t MouseWrapper_::next_width;
uint16_t MouseWrapper_::next_height;
uint16_t MouseWrapper_::section_top;
uint16_t MouseWrapper_::section_left;
boolean MouseWrapper_::is_warping;
uint8_t MouseWrapper_::mouseActiveForCycles;
MouseWrapper_::MouseWrapper_(void) { MouseWrapper_::MouseWrapper_(void) {
Mouse.begin(); Mouse.begin();
@ -20,17 +27,12 @@ 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;
@ -48,14 +50,12 @@ void MouseWrapper_::warp(uint8_t warp_cmd) {
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) {
@ -73,10 +73,8 @@ void MouseWrapper_::warp(uint8_t warp_cmd) {
} }
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;
@ -92,14 +90,14 @@ uint8_t MouseWrapper_::acceleration(uint8_t cycles) {
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 ) {

@ -11,8 +11,6 @@
#define WARP_LEFT 8 #define WARP_LEFT 8
#define WARP_RIGHT 16 #define WARP_RIGHT 16
// apparently, the mac discards 15% of the value space for mouse movement. // apparently, the mac discards 15% of the value space for mouse movement.
// need to test this on other platforms // need to test this on other platforms
@ -29,28 +27,27 @@
#define ACCELERATION_FLOOR 2 #define ACCELERATION_FLOOR 2
#define ACCELERATION_CEIL 50 #define ACCELERATION_CEIL 50
class MouseWrapper_ { class MouseWrapper_ {
public: public:
MouseWrapper_(void); MouseWrapper_(void);
void move( int8_t x, int8_t y);
void warp(uint8_t warp_cmd);
void press_button(uint8_t button);
void release_button(uint8_t button);
uint8_t mouseActiveForCycles = 0;
private: static void move(int8_t x, int8_t y);
uint16_t next_width = 0; static void warp(uint8_t warp_cmd);
uint16_t next_height = 0; static void press_button(uint8_t button);
uint16_t section_top = 0; static void release_button(uint8_t button);
uint16_t section_left = 0; static uint8_t mouseActiveForCycles;
boolean is_warping = false;
uint8_t acceleration (uint8_t cycles);
void begin_warping();
void end_warping();
void warp_jump(uint16_t left, uint16_t top, uint16_t height, uint16_t width);
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; extern MouseWrapper_ MouseWrapper;

Loading…
Cancel
Save