aiie/teensy/teensy-paddles.cpp

56 lines
1.1 KiB
C++
Raw Normal View History

2017-02-20 18:55:16 +00:00
#include "teensy-paddles.h"
/* C061: Open Apple (Paddle 0 button pressed if &= 0x80)
* C062: Closed Apple (Paddle 1 button pressed if &= 0x80)
* C064: PADDLE0 (sets bit 0x80 when value reached, increments of 11 us)
* C065: PADDLE1 (sets bit 0x80 when value reached, increments of 11 us)
* C070: "start reading paddle data" - "may take up to 3 milliseconds"
*/
#include "globals.h"
TeensyPaddles::TeensyPaddles(uint8_t p0pin, uint8_t p1pin, bool p0rev, bool p1rev)
2017-02-20 18:55:16 +00:00
{
this->p0pin = p0pin;
this->p1pin = p1pin;
this->p0rev = p0rev;
this->p1rev = p1rev;
pinMode(p0pin, INPUT);
pinMode(p1pin, INPUT);
2017-02-20 18:55:16 +00:00
}
TeensyPaddles::~TeensyPaddles()
{
}
uint8_t TeensyPaddles::paddle0()
{
uint8_t raw = analogRead(p0pin);
if (p0rev) {
raw = 255 - raw;
}
2017-02-20 18:55:16 +00:00
return raw;
}
uint8_t TeensyPaddles::paddle1()
{
uint8_t raw = analogRead(p1pin);
if (p1rev) {
raw = 255 - raw;
}
2017-02-20 18:55:16 +00:00
return raw;
}
void TeensyPaddles::startReading()
{
g_vm->triggerPaddleInCycles(0, 12 * paddle0());
g_vm->triggerPaddleInCycles(1, 12 * paddle1());
}
void TeensyPaddles::setRev(bool p0rev, bool p1rev)
{
this->p0rev = p0rev;
this->p1rev = p1rev;
}