mirror of https://github.com/JorjBauer/aiie
wired in mouse support; left-apple is the mouse button on the teensy for now
parent
93746ed8d3
commit
bab3560273
@ -0,0 +1,62 @@
|
||||
#include "sdl-mouse.h"
|
||||
|
||||
#include "globals.h"
|
||||
|
||||
SDLMouse::SDLMouse() : PhysicalMouse()
|
||||
{
|
||||
xpos = ypos = 0;
|
||||
button = false;
|
||||
}
|
||||
|
||||
SDLMouse::~SDLMouse()
|
||||
{
|
||||
}
|
||||
|
||||
void SDLMouse::gotMouseEvent(uint32_t buttonState, int32_t x, int32_t y)
|
||||
{
|
||||
xpos += x; ypos += y;
|
||||
|
||||
if (xpos < lowClamp[XCLAMP]) xpos=lowClamp[XCLAMP];
|
||||
if (xpos > highClamp[XCLAMP]) xpos=highClamp[XCLAMP];
|
||||
if (ypos < lowClamp[YCLAMP]) ypos = lowClamp[YCLAMP];
|
||||
if (ypos > highClamp[YCLAMP]) ypos = highClamp[YCLAMP];
|
||||
}
|
||||
|
||||
void SDLMouse::mouseButtonEvent(bool state)
|
||||
{
|
||||
button = state;
|
||||
}
|
||||
|
||||
void SDLMouse::maintainMouse()
|
||||
{
|
||||
}
|
||||
|
||||
void SDLMouse::setPosition(uint16_t x, uint16_t y)
|
||||
{
|
||||
xpos = x;
|
||||
ypos = y;
|
||||
|
||||
if (xpos < lowClamp[XCLAMP]) xpos=lowClamp[XCLAMP];
|
||||
if (xpos > highClamp[XCLAMP]) xpos=highClamp[XCLAMP];
|
||||
if (ypos < lowClamp[YCLAMP]) ypos = lowClamp[YCLAMP];
|
||||
if (ypos > highClamp[YCLAMP]) ypos = highClamp[YCLAMP];
|
||||
}
|
||||
|
||||
void SDLMouse::getPosition(uint16_t *x, uint16_t *y)
|
||||
{
|
||||
if (xpos < lowClamp[XCLAMP]) xpos=lowClamp[XCLAMP];
|
||||
if (xpos > highClamp[XCLAMP]) xpos=highClamp[XCLAMP];
|
||||
if (ypos < lowClamp[YCLAMP]) ypos = lowClamp[YCLAMP];
|
||||
if (ypos > highClamp[YCLAMP]) ypos = highClamp[YCLAMP];
|
||||
|
||||
uint16_t outx = xpos;
|
||||
uint16_t outy = ypos;
|
||||
|
||||
*x = outx;
|
||||
*y = outy;
|
||||
}
|
||||
|
||||
bool SDLMouse::getButton()
|
||||
{
|
||||
return button;
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
#ifndef __SDL_MOUSE_H
|
||||
#define __SDL_MOUSE_H
|
||||
|
||||
#include "physicalmouse.h"
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
class SDLMouse : public PhysicalMouse {
|
||||
public:
|
||||
SDLMouse();
|
||||
virtual ~SDLMouse();
|
||||
|
||||
virtual void maintainMouse();
|
||||
|
||||
virtual void setPosition(uint16_t x, uint16_t y);
|
||||
virtual void getPosition(uint16_t *x, uint16_t *y);
|
||||
virtual bool getButton();
|
||||
|
||||
void gotMouseEvent(uint32_t buttonState, int32_t x, int32_t y);
|
||||
void mouseButtonEvent(bool state);
|
||||
private:
|
||||
int32_t xpos, ypos;
|
||||
bool button;
|
||||
};
|
||||
|
||||
#endif
|
@ -0,0 +1 @@
|
||||
../apple/mouse.cpp
|
@ -0,0 +1 @@
|
||||
../apple/mouse.h
|
@ -0,0 +1 @@
|
||||
../physicalmouse.h
|
@ -0,0 +1,81 @@
|
||||
#include <Arduino.h>
|
||||
#include "teensy-mouse.h"
|
||||
|
||||
#include "globals.h"
|
||||
|
||||
TeensyMouse::TeensyMouse() : PhysicalMouse()
|
||||
{
|
||||
xpos = ypos = 0;
|
||||
button = false;
|
||||
}
|
||||
|
||||
TeensyMouse::~TeensyMouse()
|
||||
{
|
||||
}
|
||||
|
||||
void TeensyMouse::gotMouseEvent(uint32_t buttonState, int32_t x, int32_t y)
|
||||
{
|
||||
xpos += x; ypos += y;
|
||||
|
||||
if (xpos < lowClamp[XCLAMP]) xpos=lowClamp[XCLAMP];
|
||||
if (xpos > highClamp[XCLAMP]) xpos=highClamp[XCLAMP];
|
||||
if (ypos < lowClamp[YCLAMP]) ypos = lowClamp[YCLAMP];
|
||||
if (ypos > highClamp[YCLAMP]) ypos = highClamp[YCLAMP];
|
||||
}
|
||||
|
||||
void TeensyMouse::mouseButtonEvent(bool state)
|
||||
{
|
||||
button = state;
|
||||
}
|
||||
|
||||
void TeensyMouse::maintainMouse()
|
||||
{
|
||||
// FIXME: only do this if the mouse card is enabled, so we're not incurring
|
||||
// analogRead delays constantly
|
||||
uint8_t paddle0 = g_paddles->paddle0();
|
||||
uint8_t paddle1 = g_paddles->paddle1();
|
||||
int16_t dx=0, dy=0;
|
||||
if (paddle0 <= 25) {
|
||||
dx = -1;
|
||||
} else if (paddle0 >= 245) {
|
||||
dx = 1;
|
||||
}
|
||||
if (paddle1 <= 25) {
|
||||
dy = -1;
|
||||
} else if (paddle1 >= 245) {
|
||||
dy = 1;
|
||||
}
|
||||
if (dx || dy) {
|
||||
gotMouseEvent(button, dx, dy);
|
||||
}
|
||||
}
|
||||
|
||||
void TeensyMouse::setPosition(uint16_t x, uint16_t y)
|
||||
{
|
||||
xpos = x;
|
||||
ypos = y;
|
||||
|
||||
if (xpos < lowClamp[XCLAMP]) xpos=lowClamp[XCLAMP];
|
||||
if (xpos > highClamp[XCLAMP]) xpos=highClamp[XCLAMP];
|
||||
if (ypos < lowClamp[YCLAMP]) ypos = lowClamp[YCLAMP];
|
||||
if (ypos > highClamp[YCLAMP]) ypos = highClamp[YCLAMP];
|
||||
}
|
||||
|
||||
void TeensyMouse::getPosition(uint16_t *x, uint16_t *y)
|
||||
{
|
||||
if (xpos < lowClamp[XCLAMP]) xpos=lowClamp[XCLAMP];
|
||||
if (xpos > highClamp[XCLAMP]) xpos=highClamp[XCLAMP];
|
||||
if (ypos < lowClamp[YCLAMP]) ypos = lowClamp[YCLAMP];
|
||||
if (ypos > highClamp[YCLAMP]) ypos = highClamp[YCLAMP];
|
||||
|
||||
uint16_t outx = xpos;
|
||||
uint16_t outy = ypos;
|
||||
|
||||
*x = outx;
|
||||
*y = outy;
|
||||
}
|
||||
|
||||
bool TeensyMouse::getButton()
|
||||
{
|
||||
return button;
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
#ifndef __TEENSY_MOUSE_H
|
||||
#define __TEENSY_MOUSE_H
|
||||
|
||||
#include "physicalmouse.h"
|
||||
|
||||
class TeensyMouse : public PhysicalMouse {
|
||||
public:
|
||||
TeensyMouse();
|
||||
virtual ~TeensyMouse();
|
||||
|
||||
virtual void maintainMouse();
|
||||
|
||||
virtual void setPosition(uint16_t x, uint16_t y);
|
||||
virtual void getPosition(uint16_t *x, uint16_t *y);
|
||||
virtual bool getButton();
|
||||
|
||||
void gotMouseEvent(uint32_t buttonState, int32_t x, int32_t y);
|
||||
void mouseButtonEvent(bool state);
|
||||
private:
|
||||
int32_t xpos, ypos;
|
||||
bool button;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue