Skip to content

Commit

Permalink
Merge pull request #2 from colde/main
Browse files Browse the repository at this point in the history
Change order of function definitions to appease PlatformIO's default use of .cpp
  • Loading branch information
jonnybergdahl authored Feb 12, 2024
2 parents d851c06 + 3f58785 commit 073f8c8
Showing 1 changed file with 103 additions and 103 deletions.
206 changes: 103 additions & 103 deletions examples/JBWopr_Firmware/JBWopr_Firmware.ino
Original file line number Diff line number Diff line change
Expand Up @@ -53,124 +53,124 @@ int32_t effectIndex = 0; // Keeps track of the currently selected effect
std::vector<JBWoprEffectBase*> effects; // List of all registered effects
bool showEffectName = false; // Used to show the effect name when the effect stopped running

void setup() {
// Setup serial
Serial.begin(115200);

// Wait for serial to be ready
uint64_t timeout = millis() + 4000;
while (!Serial && millis() < timeout)
{
delay(100);
}

Serial.println("=====================");
Serial.println("Setting up WOPRDevice");
// Set log level
wopr.setLogLevel(LOG_LEVEL);

// Load and get the list of registered effects
registerEffects();

// Initialize wopr
wopr.begin(JBWoprBoardVariant::HAXORZ);

// Attach button callback methods
wopr.buttonFrontRightSetClickCallback(buttonFrontRightClick);
wopr.buttonFrontLeftSetClickCallback(buttonFrontLeftClick);
wopr.buttonBackTopSetClickCallback(buttonBackTopClick);
wopr.buttonBackBottomSetClickCallback(buttonBackBottomClick);

// Show instructions
wopr.displayScrollText("Left - Select effect, Right - Run effect");
Serial.println("Use back top/front left button to select next effect");
Serial.println("Use back bottom button to select previous effect");
Serial.println("Use front right button to start selected effect");

// Display first choice
wopr.displayShowText(effects[effectIndex]->getName());
Serial.println("Setup done");
}

void loop() {
// Run the device loop
wopr.loop();

if (wopr.effectsCurrentEffectIsRunning() && !showEffectName) {
// Show the effect name when the effect stopped running
showEffectName = true;
}
if (!wopr.effectsCurrentEffectIsRunning() && showEffectName) {
// Show the effect name
showEffectName = false;
wopr.displayShowText(effects[effectIndex]->getName());
}
}

void displayEffectChanged() {
// Stop the current effect
wopr.effectsStopCurrentEffect();

// Select the next effect in the list
if (effectIndex >= effects.size()) {
effectIndex = 0;
}
if (effectIndex < 0) {
effectIndex = effects.size() - 1;
}

// Show the current effect name
wopr.displayShowText(effects[effectIndex]->getName());
// Stop the current effect
wopr.effectsStopCurrentEffect();

// Select the next effect in the list
if (effectIndex >= effects.size()) {
effectIndex = 0;
}
if (effectIndex < 0) {
effectIndex = effects.size() - 1;
}

// Show the current effect name
wopr.displayShowText(effects[effectIndex]->getName());
}

void buttonFrontRightClick() {
Serial.println("Front right button clicked");
wopr.effectsStartEffect(effects[effectIndex]);
Serial.println("Front right button clicked");
wopr.effectsStartEffect(effects[effectIndex]);
}

void buttonFrontLeftClick() {
Serial.println("Front left button clicked");
effectIndex++;
displayEffectChanged();
Serial.println("Front left button clicked");
effectIndex++;
displayEffectChanged();
}

void buttonBackTopClick() {
Serial.println("Back top button clicked");
effectIndex++;
displayEffectChanged();
Serial.println("Back top button clicked");
effectIndex++;
displayEffectChanged();
}

void buttonBackBottomClick() {
Serial.println("Back bottom button clicked");
effectIndex--;
displayEffectChanged();
Serial.println("Back bottom button clicked");
effectIndex--;
displayEffectChanged();
}

// This method register all effects in the library
void registerEffects() {
// Set Date/Time as the default effect
wopr.effectsRegisterDefaultEffect(new JBWoprDateTimeDisplayEffect(&wopr));

wopr.effectsRegisterEffect(new JBWoprXmasSecondsDisplayEffect(&wopr,
200,
0));
wopr.effectsRegisterEffect(new JBWoprMissileCodeSolveEffect(&wopr,
CodeSolveVariant::MOVIE,
1000,
"Movie solve"));
wopr.effectsRegisterEffect(new JBWoprMissileCodeSolveEffect(&wopr,
CodeSolveVariant::MESSAGE,
1000,
"Msg solve"));
wopr.effectsRegisterEffect(new JBWoprMissileCodeSolveEffect(&wopr,
CodeSolveVariant::RANDOM,
1000,
"Random solve"));
wopr.effectsRegisterEffect(new JBWoprDefconRainbowEffect(&wopr,
1000));
wopr.effectsRegisterEffect(new JBWoprNokiaTuneEffect(&wopr,
180,
0));
wopr.effectsRegisterEffect(new JBWoprTheRickEffect(&wopr));
effects = wopr.effectsGetRegisteredEffects();
// Set Date/Time as the default effect
wopr.effectsRegisterDefaultEffect(new JBWoprDateTimeDisplayEffect(&wopr));

wopr.effectsRegisterEffect(new JBWoprXmasSecondsDisplayEffect(&wopr,
200,
0));
wopr.effectsRegisterEffect(new JBWoprMissileCodeSolveEffect(&wopr,
CodeSolveVariant::MOVIE,
1000,
"Movie solve"));
wopr.effectsRegisterEffect(new JBWoprMissileCodeSolveEffect(&wopr,
CodeSolveVariant::MESSAGE,
1000,
"Msg solve"));
wopr.effectsRegisterEffect(new JBWoprMissileCodeSolveEffect(&wopr,
CodeSolveVariant::RANDOM,
1000,
"Random solve"));
wopr.effectsRegisterEffect(new JBWoprDefconRainbowEffect(&wopr,
1000));
wopr.effectsRegisterEffect(new JBWoprNokiaTuneEffect(&wopr,
180,
0));
wopr.effectsRegisterEffect(new JBWoprTheRickEffect(&wopr));
effects = wopr.effectsGetRegisteredEffects();
}

void setup() {
// Setup serial
Serial.begin(115200);

// Wait for serial to be ready
uint64_t timeout = millis() + 4000;
while (!Serial && millis() < timeout)
{
delay(100);
}

Serial.println("=====================");
Serial.println("Setting up WOPRDevice");
// Set log level
wopr.setLogLevel(LOG_LEVEL);

// Load and get the list of registered effects
registerEffects();

// Initialize wopr
wopr.begin(JBWoprBoardVariant::HAXORZ);

// Attach button callback methods
wopr.buttonFrontRightSetClickCallback(buttonFrontRightClick);
wopr.buttonFrontLeftSetClickCallback(buttonFrontLeftClick);
wopr.buttonBackTopSetClickCallback(buttonBackTopClick);
wopr.buttonBackBottomSetClickCallback(buttonBackBottomClick);

// Show instructions
wopr.displayScrollText("Left - Select effect, Right - Run effect");
Serial.println("Use back top/front left button to select next effect");
Serial.println("Use back bottom button to select previous effect");
Serial.println("Use front right button to start selected effect");

// Display first choice
wopr.displayShowText(effects[effectIndex]->getName());
Serial.println("Setup done");
}

void loop() {
// Run the device loop
wopr.loop();

if (wopr.effectsCurrentEffectIsRunning() && !showEffectName) {
// Show the effect name when the effect stopped running
showEffectName = true;
}
if (!wopr.effectsCurrentEffectIsRunning() && showEffectName) {
// Show the effect name
showEffectName = false;
wopr.displayShowText(effects[effectIndex]->getName());
}
}

0 comments on commit 073f8c8

Please sign in to comment.