Skip to content

Commit

Permalink
Fix camel case of updateKey and wires up boot button
Browse files Browse the repository at this point in the history
  • Loading branch information
cgreening committed Nov 26, 2024
1 parent dd50dba commit 0e23c0b
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 24 deletions.
2 changes: 2 additions & 0 deletions firmware/src/Emulator/keyboard_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ enum SpecKeys
// special pseudo keys
SPECKEY_DEL,
SPECKEY_BREAK,
// special keys for the emulator
SPECKEY_MENU,
};

const std::unordered_map<SpecKeys, char> specKeyToLetter = {
Expand Down
2 changes: 1 addition & 1 deletion firmware/src/Emulator/spectrum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void ZXSpectrum::interrupt()
Z80Interrupt(z80Regs, 0x38);
}

void ZXSpectrum::updatekey(SpecKeys key, uint8_t state)
void ZXSpectrum::updateKey(SpecKeys key, uint8_t state)
{
// Bit pattern: XXXFULDR
switch (key)
Expand Down
2 changes: 1 addition & 1 deletion firmware/src/Emulator/spectrum.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class ZXSpectrum
}

void interrupt();
void updatekey(SpecKeys key, uint8_t state);
void updateKey(SpecKeys key, uint8_t state);

inline uint8_t z80_peek(uint16_t address)
{
Expand Down
5 changes: 2 additions & 3 deletions firmware/src/Screens/EmulatorScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ EmulatorScreen::EmulatorScreen(TFTDisplay &tft, AudioOutput *audioOutput, IFiles
Serial.println("ROM loading routine hit");
triggerLoadTape(); });
gameLoader = new GameLoader(machine, renderer, audioOutput);
pinMode(0, INPUT_PULLUP);
}

void EmulatorScreen::run(std::string filename, models_enum model)
Expand Down Expand Up @@ -102,7 +101,7 @@ void EmulatorScreen::resume()
machine->resume();
}

void EmulatorScreen::updatekey(SpecKeys key, uint8_t state)
void EmulatorScreen::updateKey(SpecKeys key, uint8_t state)
{
// TODO audio capture
// if (key == SPECKEY_0)
Expand All @@ -116,7 +115,7 @@ void EmulatorScreen::updatekey(SpecKeys key, uint8_t state)
// Serial.printf("Audio file closed\n");
// }
// }
machine->updatekey(key, state);
machine->updateKey(key, state);
}

void EmulatorScreen::showSaveSnapshotScreen()
Expand Down
2 changes: 1 addition & 1 deletion firmware/src/Screens/EmulatorScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class EmulatorScreen : public Screen
bool isLoading = false;
public:
EmulatorScreen(TFTDisplay &tft, AudioOutput *audioOutput, IFiles *files);
void updatekey(SpecKeys key, uint8_t state);
void updateKey(SpecKeys key, uint8_t state);
void run(std::string filename, models_enum model);
void pause();
void resume();
Expand Down
12 changes: 6 additions & 6 deletions firmware/src/Screens/EmulatorScreen/Machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ Machine::Machine(Renderer *renderer, AudioOutput *audioOutput, std::function<voi
timeTravel = new TimeTravel();
}

void Machine::updatekey(SpecKeys key, uint8_t state) {
void Machine::updateKey(SpecKeys key, uint8_t state) {
if (isRunning) {
machine->updatekey(key, state);
machine->updateKey(key, state);
}
}

Expand All @@ -73,12 +73,12 @@ void Machine::start(FILE *audioFile) {

void Machine::tapKey(SpecKeys key)
{
machine->updatekey(key, 1);
machine->updateKey(key, 1);
for (int i = 0; i < 10; i++)
{
machine->runForFrame(nullptr, nullptr);
}
machine->updatekey(key, 0);
machine->updateKey(key, 0);
for (int i = 0; i < 10; i++)
{
machine->runForFrame(nullptr, nullptr);
Expand All @@ -97,10 +97,10 @@ void Machine::startLoading()
if (machine->hwopt.hw_model == SPECMDL_48K)
{
tapKey(SPECKEY_J);
machine->updatekey(SPECKEY_SYMB, 1);
machine->updateKey(SPECKEY_SYMB, 1);
tapKey(SPECKEY_P);
tapKey(SPECKEY_P);
machine->updatekey(SPECKEY_SYMB, 0);
machine->updateKey(SPECKEY_SYMB, 0);
tapKey(SPECKEY_ENTER);
}
else
Expand Down
2 changes: 1 addition & 1 deletion firmware/src/Screens/EmulatorScreen/Machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class Machine {
std::function<void()> romLoadingRoutineHitCallback;
public:
Machine(Renderer *renderer, AudioOutput *audioOutput, std::function<void()> romLoadingRoutineHitCallback);
void updatekey(SpecKeys key, uint8_t state);
void updateKey(SpecKeys key, uint8_t state);
void setup(models_enum model);
void start(FILE *audioFile);
void pause() {
Expand Down
2 changes: 1 addition & 1 deletion firmware/src/Screens/ErrorScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ErrorScreen : public Screen
updateDisplay();
}

void updatekey(SpecKeys key, uint8_t state)
void updateKey(SpecKeys key, uint8_t state)
{
if (state == 1)
{
Expand Down
4 changes: 2 additions & 2 deletions firmware/src/Screens/NavigationStack.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ class NavigationStack
}
}
}
void updatekey(SpecKeys key, uint8_t state) {
void updateKey(SpecKeys key, uint8_t state) {
Screen *top = getTop();
if (top) {
top->updatekey(key, state);
top->updateKey(key, state);
}
};
void pressKey(SpecKeys key) {
Expand Down
2 changes: 1 addition & 1 deletion firmware/src/Screens/Screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Screen {
public:
Screen(TFTDisplay &tft, AudioOutput *audioOutput) : m_tft(tft), m_audioOutput(audioOutput) {}
// input
virtual void updatekey(SpecKeys key, uint8_t state) {};
virtual void updateKey(SpecKeys key, uint8_t state) {};
virtual void pressKey(SpecKeys key) {};
void playKeyClick() {
if (m_audioOutput) {
Expand Down
2 changes: 1 addition & 1 deletion firmware/src/Screens/USBKeyboardScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class USBKeyboardScreen : public Screen
USB.begin();
}

void updatekey(SpecKeys key, uint8_t state)
void updateKey(SpecKeys key, uint8_t state)
{
// map from the spectrum key to a hid_key
int hid_key = 0;
Expand Down
25 changes: 19 additions & 6 deletions firmware/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void setup(void)
[&](SpecKeys key, bool down)
{
{
navigationStack->updatekey(key, down);
navigationStack->updateKey(key, down);
}
});
touchKeyboard->calibrate();
Expand All @@ -114,7 +114,7 @@ void setup(void)
#ifdef TOUCH_KEYBOARD_V2
TouchKeyboardV2 *touchKeyboard = new TouchKeyboardV2(
[&](SpecKeys key, bool down)
{ navigationStack->updatekey(key, down); },
{ navigationStack->updateKey(key, down); },
[&](SpecKeys key)
{ navigationStack->pressKey(key); });
touchKeyboard->start();
Expand All @@ -138,29 +138,42 @@ void setup(void)
navigationStack->push(&menuPicker);
// start off the keyboard and feed keys into the active scene
SerialKeyboard *keyboard = new SerialKeyboard([&](SpecKeys key, bool down)
{ navigationStack->updatekey(key, down); if (down) { navigationStack->pressKey(key); } });
{ navigationStack->updateKey(key, down); if (down) { navigationStack->pressKey(key); } });

// start up the nunchuk controller and feed events into the active screen
#ifdef NUNCHUK_CLOCK
Nunchuck *nunchuck = new Nunchuck([&](SpecKeys key, bool down)
{ navigationStack->updatekey(key, down); },
{ navigationStack->updateKey(key, down); },
[&](SpecKeys key)
{ navigationStack->pressKey(key); },
NUNCHUK_CLOCK, NUNCHUK_DATA);
#endif
#ifdef SEESAW_CLOCK
AdafruitSeeSaw *seeSaw = new AdafruitSeeSaw([&](SpecKeys key, bool down)
{ navigationStack->updatekey(key, down); },
{ navigationStack->updateKey(key, down); },
[&](SpecKeys key)
{ navigationStack->pressKey(key); });
seeSaw->begin(SEESAW_DATA, SEESAW_CLOCK);
#endif

Serial.println("Running on core: " + String(xPortGetCoreID()));
// use the boot pin to open the emulator menu
pinMode(0, INPUT_PULLUP);
// just keep running
bool bootButtonWasPressed = false;
while (true)
{
vTaskDelay(10000);
vTaskDelay(100 / portTICK_PERIOD_MS);
if (digitalRead(0) == LOW)
{
navigationStack->updateKey(SPECKEY_MENU, true);
}
else if (bootButtonWasPressed)
{
navigationStack->updateKey(SPECKEY_MENU, false);
navigationStack->pressKey(SPECKEY_MENU);
bootButtonWasPressed = false;
}
}
}

Expand Down

0 comments on commit 0e23c0b

Please sign in to comment.