Skip to content

Commit

Permalink
Add new song to new event on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelcruzpb committed Dec 25, 2022
1 parent 859d8cf commit 535f811
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
2 changes: 2 additions & 0 deletions include/addons/buzzerspeaker.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,15 @@ class BuzzerSpeakerAddon : public GPAddon
private:
void processBuzzer();
void play(Song *song);
void playIntro();
void stop();
uint32_t pwmSetFreqDuty(uint slice, uint channel, uint32_t frequency, float duty);
uint8_t buzzerPinSlice;
uint8_t buzzerPinChannel;
uint8_t buzzerVolume;
uint32_t startedSongMils;
Song *currentSong;
bool introPlayed;
public:
virtual bool available(); // GPAddon
virtual void setup();
Expand Down
13 changes: 12 additions & 1 deletion include/songs.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "addons/buzzerspeaker.h"

// Intro example
Song intro{
Song introSong{
100,
{
D5,
Expand All @@ -21,4 +21,15 @@ Song intro{
D8,
DS8,
}
};

Song configModeSong{
150,
{
E5,
E5,
G4,
FS5,
E5
}
};
19 changes: 17 additions & 2 deletions src/addons/buzzerspeaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "pico/stdlib.h"
#include "bitmaps.h"
#include "math.h"
#include "usb_driver.h"

bool BuzzerSpeakerAddon::available() {
BoardOptions boardOptions = Storage::getInstance().getBoardOptions();
Expand All @@ -20,14 +21,28 @@ void BuzzerSpeakerAddon::setup() {
buzzerPinSlice = pwm_gpio_to_slice_num (boardOptions.buzzerPin);
buzzerPinChannel = pwm_gpio_to_channel (boardOptions.buzzerPin);
buzzerVolume = boardOptions.buzzerVolume;

play(&intro);
introPlayed = false;
}

void BuzzerSpeakerAddon::process() {
if (!introPlayed) playIntro();

processBuzzer();
}

void BuzzerSpeakerAddon::playIntro() {
if (getMillis() < 1000) return;

bool isConfigMode = Storage::getInstance().GetConfigMode();

if (!get_usb_mounted() || isConfigMode) {
play(&configModeSong);
} else {
play(&introSong);
}
introPlayed = true;
}

void BuzzerSpeakerAddon::processBuzzer() {

if (currentSong == NULL) {
Expand Down

0 comments on commit 535f811

Please sign in to comment.