Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions OpenFIREmain/OpenFIREcommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#endif // ARDUINO_ARCH_RP2040

#include "OpenFIREcommon.h"
#include "OpenFIREFeedback.h"
#include "OpenFIRElights.h"
#include "OpenFIREserial.h"

Expand Down Expand Up @@ -215,6 +216,10 @@ void FW_Common::SetMode(const FW_Const::GunMode_e &newMode)
switch(gunMode) {
case FW_Const::GunMode_Run:
stateFlags |= FW_Const::StateFlag_PrintPreferences;
// MAKE SURE EVERYTHING IS DISENGAGED:
OF_FFB::FFBShutdown();
buttons.ReleaseAll();
buttons.ReportDisable();
break;
case FW_Const::GunMode_Pause:
break;
Expand Down
41 changes: 21 additions & 20 deletions OpenFIREmain/OpenFIREmain.ino
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ void setup1()
// currently handles all button & serial processing when Core 0 is in ExecRunMode()
void loop1()
{
rp2040.fifo.pop();
while(FW_Common::gunMode == FW_Const::GunMode_Run) {
// All buttons' outputs except for the trigger are processed here.
FW_Common::buttons.Poll(0);
Expand Down Expand Up @@ -314,25 +315,25 @@ void loop1()
} else if(pauseHoldStarted) {
unsigned long t = millis();
if(t - pauseHoldStartstamp > OF_Prefs::settings[OF_Const::holdToPauseLength]) {
// MAKE SURE EVERYTHING IS DISENGAGED:
OF_FFB::FFBShutdown();
FW_Common::buttons.ReportDisable();
// Signal the main core to set mode, since it's more stable there.
// Pop blocks until we get the okay from the main core (the value returned doesn't matter atm)
rp2040.fifo.push(FW_Const::GunMode_Pause);
rp2040.fifo.pop();
// in the infinitely tiny chance that this happens at the same time as a serial-pinged Dock request:
if(FW_Common::gunMode == FW_Const::GunMode_Run) {
// Signal the main core to set mode, since it's more stable there.
// Pop blocks until we get the okay from the main core (the value returned doesn't matter atm)
rp2040.fifo.push(FW_Const::GunMode_Pause);
rp2040.fifo.pop();
}
}
}
} else {
if(FW_Common::buttons.pressedReleased == FW_Const::EnterPauseModeBtnMask ||
FW_Common::buttons.pressedReleased == FW_Const::BtnMask_Home) {
// MAKE SURE EVERYTHING IS DISENGAGED:
OF_FFB::FFBShutdown();
FW_Common::buttons.ReportDisable();
// Signal the main core to set mode, since it's more stable there.
// Pop blocks until we get the okay from the main core (the value returned doesn't matter atm)
rp2040.fifo.push(FW_Const::GunMode_Pause);
rp2040.fifo.pop();
// in the infinitely tiny chance that this happens at the same time as a serial-pinged Dock request:
if(FW_Common::gunMode == FW_Const::GunMode_Run) {
// Signal the main core to set mode, since it's more stable there.
// Pop blocks until we get the okay from the main core (the value returned doesn't matter atm)
rp2040.fifo.push(FW_Const::GunMode_Pause);
rp2040.fifo.pop();
}
}
}
}
Expand Down Expand Up @@ -639,6 +640,11 @@ void ExecRunMode()
FW_Common::justBooted = false;
}

#if defined(ARDUINO_ARCH_RP2040) && defined(DUAL_CORE)
// wake up second core
rp2040.fifo.push(0);
#endif // ARDUINO_ARCH_RP2040 && DUAL_CORE

for(;;) {
// Setting the state of our toggles, if used.
// Only sets these values if the switches are mapped to valid pins.
Expand Down Expand Up @@ -759,26 +765,21 @@ void ExecRunMode()
// MAKE SURE EVERYTHING IS DISENGAGED:
OF_FFB::FFBShutdown();
FW_Common::SetMode(FW_Const::GunMode_Pause);
FW_Common::buttons.ReleaseAll();
FW_Common::buttons.ReportDisable();
return;
}
}
} else {
if(FW_Common::buttons.pressedReleased == FW_Const::EnterPauseModeBtnMask || FW_Common::buttons.pressedReleased == FW_Const::BtnMask_Home) {
// MAKE SURE EVERYTHING IS DISENGAGED:
OF_FFB::FFBShutdown();
FW_Common::SetMode(FW_Const::GunMode_Pause);
FW_Common::buttons.ReleaseAll();
FW_Common::buttons.ReportDisable();
FW_Common::SetMode(FW_Const::GunMode_Pause);
return;
}
}
#else // if we're using dual cores, check the fifo.
if(rp2040.fifo.pop_nb(&fifoData)) {
FW_Common::SetMode((FW_Const::GunMode_e)fifoData);
fifoData = 0;
FW_Common::buttons.ReleaseAll();
// the value doesn't matter; all core1 is doing is waiting for any signal from the FIFO.
rp2040.fifo.push(true);
return;
Expand Down
9 changes: 6 additions & 3 deletions OpenFIREmain/OpenFIREserial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,15 @@ void OF_Serial::SerialProcessing()
// Enter Docked Mode
case OF_Const::sDock1:
if(Serial.read() == OF_Const::sDock2) {
#ifdef DUAL_CORE // This may be being run from Core 1, so signal if running in main Run Mode.
if(FW_Common::gunMode == FW_Const::GunMode_Run)
#if defined(ARDUINO_ARCH_RP2040) && defined(DUAL_CORE) // This may be being run from Core 1, so signal if running in main Run Mode.
if(FW_Common::gunMode == FW_Const::GunMode_Run) {
rp2040.fifo.push(FW_Const::GunMode_Docked);
rp2040.fifo.pop();
}
else FW_Common::SetMode(FW_Const::GunMode_Docked);
#else
FW_Common::SetMode(FW_Const::GunMode_Docked);
#endif // DUAL_CORE
#endif // ARDUINO_ARCH_RP2040 && DUAL_CORE
}
break;
// Force Feedback
Expand Down Expand Up @@ -1064,6 +1066,7 @@ void OF_Serial::SerialProcessingDocked()
case OF_Const::serialTerminator:
// Assumed failed/aborting save, so roll back to what's in flash.
OF_Prefs::Load();
FW_Common::buttons.Begin();
exit = true;
break;

Expand Down