parent
01cdada1a0
commit
acfd229fd0
@ -0,0 +1,63 @@
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "debouncing.h"
|
||||
// switch debouncing and status
|
||||
|
||||
|
||||
boolean key_was_pressed (byte keyState)
|
||||
{
|
||||
if ( byte((keyState >> 4)) ^ B00001111 ) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
boolean key_was_not_pressed (byte keyState)
|
||||
{
|
||||
if ( byte((keyState >> 4)) ^ B00000000 ) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
boolean key_is_pressed (byte keyState)
|
||||
{
|
||||
|
||||
if ( byte((keyState << 4)) ^ B11110000 ) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
boolean key_is_not_pressed (byte keyState)
|
||||
{
|
||||
|
||||
if ( byte((keyState << 4)) ^ B00000000 ) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
boolean key_toggled_on(byte keyState)
|
||||
{
|
||||
if (key_is_pressed(keyState) && key_was_not_pressed(keyState)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boolean key_toggled_off(byte keyState)
|
||||
{
|
||||
if (key_was_pressed(keyState) && key_is_not_pressed(keyState)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
#ifndef debouncing_h
|
||||
#define debouncing_h
|
||||
|
||||
// switch debouncing and status
|
||||
|
||||
|
||||
boolean key_was_pressed (byte keyState);
|
||||
boolean key_was_not_pressed (byte keyState);
|
||||
boolean key_is_pressed (byte keyState);
|
||||
boolean key_is_not_pressed (byte keyState);
|
||||
boolean key_toggled_on(byte keyState);
|
||||
boolean key_toggled_off(byte keyState);
|
||||
|
||||
#endif
|
@ -0,0 +1,158 @@
|
||||
|
||||
// Mouse-related methods
|
||||
//
|
||||
//
|
||||
#include "Arduino.h"
|
||||
#include "key_defs.h"
|
||||
#include "mouse_movement.h"
|
||||
#include "debouncing.h"
|
||||
|
||||
void _warp_jump(long left, long top, long height, long width) {
|
||||
long x_center = left + width/2;
|
||||
long y_center = top + height/2;
|
||||
Mouse.moveAbsolute(x_center,y_center);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int last_x;
|
||||
int last_y;
|
||||
|
||||
// apparently, the mac discards 15% of the value space for mouse movement.
|
||||
// need to test this on other platforms
|
||||
//
|
||||
|
||||
#define HALF_WIDTH 16384
|
||||
#define HALF_HEIGHT 16384
|
||||
|
||||
|
||||
|
||||
int abs_left = 0;
|
||||
int abs_top = 0;
|
||||
|
||||
int next_width;
|
||||
int next_height;
|
||||
int section_top;
|
||||
int section_left;
|
||||
boolean is_warping = false;
|
||||
|
||||
void begin_warping() {
|
||||
section_left = abs_left;
|
||||
section_top = abs_top;
|
||||
next_width = 32767;
|
||||
next_height = 32767;
|
||||
is_warping = true;
|
||||
}
|
||||
|
||||
void end_warping() {
|
||||
is_warping= false;
|
||||
}
|
||||
|
||||
void warp_mouse(Key ninth) {
|
||||
if (is_warping == false) {
|
||||
begin_warping();
|
||||
}
|
||||
|
||||
|
||||
if ( ninth.rawKey & MOUSE_END_WARP) {
|
||||
end_warping();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
next_width = next_width / 2;
|
||||
next_height = next_height/2;
|
||||
|
||||
if (ninth.rawKey & MOUSE_UP) {
|
||||
// Serial.print(" - up ");
|
||||
} else if (ninth.rawKey & MOUSE_DN) {
|
||||
// Serial.print(" - down ");
|
||||
section_top = section_top + next_height;
|
||||
}
|
||||
|
||||
if (ninth.rawKey & MOUSE_L) {
|
||||
// Serial.print(" - left ");
|
||||
} else if (ninth.rawKey & MOUSE_R) {
|
||||
// Serial.print(" - right ");
|
||||
section_left = section_left + next_width;
|
||||
}
|
||||
|
||||
_warp_jump(section_left, section_top, next_height,next_width);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// we want the whole s curve, not just the bit
|
||||
// that's usually above the x and y axes;
|
||||
#define ATAN_LIMIT 1.57079633
|
||||
#define ACCELERATION_FLOOR 0.25
|
||||
#define ACCELERATION_MULTIPLIER 5
|
||||
#define ACCELERATION_RUNWAY 5
|
||||
// Climb speed is how fast we get to max speed
|
||||
// 1 is "instant"
|
||||
// 0.05 is just right
|
||||
// 0.001 is insanely slow
|
||||
|
||||
#define ACCELERATION_CLIMB_SPEED 0.05
|
||||
|
||||
double mouse_accel (double cycles)
|
||||
{
|
||||
double accel = (atan((cycles * ACCELERATION_CLIMB_SPEED)-ACCELERATION_RUNWAY) + ATAN_LIMIT) * ACCELERATION_MULTIPLIER;
|
||||
if (accel < ACCELERATION_FLOOR) {
|
||||
accel = ACCELERATION_FLOOR;
|
||||
}
|
||||
return accel;
|
||||
}
|
||||
|
||||
void handle_mouse_movement( char x, char y)
|
||||
{
|
||||
|
||||
if (x != 0 || y != 0) {
|
||||
mouseActiveForCycles++;
|
||||
double accel = (double) mouse_accel(mouseActiveForCycles);
|
||||
float moveX = 0;
|
||||
float moveY = 0;
|
||||
if (x > 0) {
|
||||
moveX = (x * accel) + carriedOverX;
|
||||
carriedOverX = moveX - floor(moveX);
|
||||
} else if (x < 0) {
|
||||
moveX = (x * accel) - carriedOverX;
|
||||
carriedOverX = ceil(moveX) - moveX;
|
||||
}
|
||||
|
||||
if (y > 0) {
|
||||
moveY = (y * accel) + carriedOverY;
|
||||
carriedOverY = moveY - floor(moveY);
|
||||
} else if (y < 0) {
|
||||
moveY = (y * accel) - carriedOverY;
|
||||
carriedOverY = ceil(moveY) - moveY;
|
||||
}
|
||||
end_warping();
|
||||
|
||||
Mouse.move(moveX, moveY, 0);
|
||||
} else {
|
||||
mouseActiveForCycles = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void handle_mouse_key_press(byte switchState, Key mappedKey, char &x, char &y) {
|
||||
|
||||
if (key_is_pressed(switchState)) {
|
||||
if (mappedKey.rawKey & MOUSE_UP) {
|
||||
y -= 1;
|
||||
}
|
||||
if (mappedKey.rawKey & MOUSE_DN) {
|
||||
y += 1;
|
||||
}
|
||||
if (mappedKey.rawKey & MOUSE_L) {
|
||||
x -= 1;
|
||||
}
|
||||
|
||||
if (mappedKey.rawKey & MOUSE_R) {
|
||||
x += 1 ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,7 @@
|
||||
#ifndef mouse_movement_h
|
||||
#define mouse_movement_h
|
||||
double mouseActiveForCycles = 0;
|
||||
float carriedOverX = 0;
|
||||
float carriedOverY = 0;
|
||||
|
||||
#endif
|
Loading…
Reference in new issue