mirror of
https://github.com/JorjBauer/aiie.git
synced 2024-11-29 16:49:26 +00:00
abstracting and refactoring around new first-gen hardware
This commit is contained in:
parent
1bb73c959f
commit
ddd4fc2eb3
@ -7,15 +7,17 @@
|
|||||||
* C070: "start reading paddle data" - "may take up to 3 milliseconds"
|
* C070: "start reading paddle data" - "may take up to 3 milliseconds"
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define PADDLE0 A24
|
|
||||||
#define PADDLE1 A23
|
|
||||||
|
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
|
|
||||||
TeensyPaddles::TeensyPaddles()
|
TeensyPaddles::TeensyPaddles(uint8_t p0pin, uint8_t p1pin, bool p0rev, bool p1rev)
|
||||||
{
|
{
|
||||||
pinMode(PADDLE0, INPUT);
|
this->p0pin = p0pin;
|
||||||
pinMode(PADDLE1, INPUT);
|
this->p1pin = p1pin;
|
||||||
|
this->p0rev = p0rev;
|
||||||
|
this->p1rev = p1rev;
|
||||||
|
|
||||||
|
pinMode(p0pin, INPUT);
|
||||||
|
pinMode(p1pin, INPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
TeensyPaddles::~TeensyPaddles()
|
TeensyPaddles::~TeensyPaddles()
|
||||||
@ -24,26 +26,20 @@ TeensyPaddles::~TeensyPaddles()
|
|||||||
|
|
||||||
uint8_t TeensyPaddles::paddle0()
|
uint8_t TeensyPaddles::paddle0()
|
||||||
{
|
{
|
||||||
uint8_t raw = 255 - analogRead(PADDLE0);
|
uint8_t raw = analogRead(p0pin);
|
||||||
|
if (p0rev) {
|
||||||
|
raw = 255 - raw;
|
||||||
|
}
|
||||||
return raw;
|
return raw;
|
||||||
|
|
||||||
// 40 .. 200 on the old joystick
|
|
||||||
if (raw >200) raw = 200;
|
|
||||||
if (raw < 40) raw = 40;
|
|
||||||
|
|
||||||
return map(raw, 40, 200, 0, 255);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t TeensyPaddles::paddle1()
|
uint8_t TeensyPaddles::paddle1()
|
||||||
{
|
{
|
||||||
uint8_t raw = analogRead(PADDLE1);
|
uint8_t raw = analogRead(p1pin);
|
||||||
|
if (p1rev) {
|
||||||
|
raw = 255 - raw;
|
||||||
|
}
|
||||||
return raw;
|
return raw;
|
||||||
|
|
||||||
// 60..200 on the old joystick
|
|
||||||
if (raw >200) raw = 200;
|
|
||||||
if (raw < 60) raw = 60;
|
|
||||||
|
|
||||||
return map(raw, 60, 200, 0, 255);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TeensyPaddles::startReading()
|
void TeensyPaddles::startReading()
|
||||||
|
@ -4,10 +4,15 @@
|
|||||||
|
|
||||||
class TeensyPaddles : public PhysicalPaddles {
|
class TeensyPaddles : public PhysicalPaddles {
|
||||||
public:
|
public:
|
||||||
TeensyPaddles();
|
TeensyPaddles(uint8_t p0pin, uint8_t p1pin, bool p0rev, bool p1rev);
|
||||||
virtual ~TeensyPaddles();
|
virtual ~TeensyPaddles();
|
||||||
|
|
||||||
virtual uint8_t paddle0();
|
virtual uint8_t paddle0();
|
||||||
virtual uint8_t paddle1();
|
virtual uint8_t paddle1();
|
||||||
virtual void startReading();
|
virtual void startReading();
|
||||||
|
|
||||||
|
uint8_t p0pin;
|
||||||
|
uint8_t p1pin;
|
||||||
|
bool p0rev;
|
||||||
|
bool p1rev;
|
||||||
};
|
};
|
||||||
|
@ -36,7 +36,7 @@ enum {
|
|||||||
D_SHOWBATTERY = 6,
|
D_SHOWBATTERY = 6,
|
||||||
D_SHOWTIME = 7
|
D_SHOWTIME = 7
|
||||||
};
|
};
|
||||||
uint8_t debugMode = D_SHOWFPS;
|
uint8_t debugMode = D_NONE;
|
||||||
|
|
||||||
static time_t getTeensy3Time() { return Teensy3Clock.get(); }
|
static time_t getTeensy3Time() { return Teensy3Clock.get(); }
|
||||||
|
|
||||||
@ -77,6 +77,7 @@ void setup()
|
|||||||
Serial.println("Error while setting RTC");
|
Serial.println("Error while setting RTC");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
spi.setPins(RF_MISO, RF_MOSI, RF_SCK);
|
spi.setPins(RF_MISO, RF_MOSI, RF_SCK);
|
||||||
if (!nrf24.init())
|
if (!nrf24.init())
|
||||||
Serial.println("init failed");
|
Serial.println("init failed");
|
||||||
@ -86,6 +87,7 @@ void setup()
|
|||||||
if (!nrf24.setRF(RH_NRF24::DataRate2Mbps, RH_NRF24::TransmitPower0dBm))
|
if (!nrf24.setRF(RH_NRF24::DataRate2Mbps, RH_NRF24::TransmitPower0dBm))
|
||||||
Serial.println("setRF failed");
|
Serial.println("setRF failed");
|
||||||
Serial.println("nrf24 initialized");
|
Serial.println("nrf24 initialized");
|
||||||
|
#endif
|
||||||
|
|
||||||
TCHAR *device = (TCHAR *)_T("0:/");
|
TCHAR *device = (TCHAR *)_T("0:/");
|
||||||
f_mount (&fatfs, device, 0); /* Mount/Unmount a logical drive */
|
f_mount (&fatfs, device, 0); /* Mount/Unmount a logical drive */
|
||||||
@ -136,7 +138,7 @@ void setup()
|
|||||||
g_keyboard = new TeensyKeyboard(g_vm->getKeyboard());
|
g_keyboard = new TeensyKeyboard(g_vm->getKeyboard());
|
||||||
|
|
||||||
Serial.println(" paddles");
|
Serial.println(" paddles");
|
||||||
g_paddles = new TeensyPaddles();
|
g_paddles = new TeensyPaddles(A23, A24, 1, 1);
|
||||||
|
|
||||||
// Now that all the virtual hardware is glued together, reset the VM
|
// Now that all the virtual hardware is glued together, reset the VM
|
||||||
Serial.println("Resetting VM");
|
Serial.println("Resetting VM");
|
||||||
|
Loading…
Reference in New Issue
Block a user