Skip to content

Commit

Permalink
Add ability to set melody in settings
Browse files Browse the repository at this point in the history
  • Loading branch information
lo1ol committed Jul 10, 2024
1 parent fbe811d commit 84fe7ac
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/Melody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,24 @@ class AlarmMelody : public Melody {
uint32_t m_timer;
};

Melody* Melody::getMelody(Name) {
return new AlarmMelody;
Melody* Melody::getMelody(Name name) {
switch(name) {
case Name::alarm:
return new AlarmMelody;
case Name::nice:
return new NiceMelody;
}

return nullptr;
}

const char* Melody::getMelodyName(Name name) {
switch(name) {
case Name::alarm:
return "alarm";
case Name::nice:
return "nice";
}

return nullptr;
}
1 change: 1 addition & 0 deletions src/Melody.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Melody {
enum Name { alarm, nice, last_ };

static Melody* getMelody(Name);
static const char* getMelodyName(Name);

virtual void init() = 0;
virtual bool end() const = 0;
Expand Down
3 changes: 3 additions & 0 deletions src/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Settings::Settings() {
GET_SETTING(startWithSettings);
GET_SETTING(logViewInTests);
GET_SETTING(logViewInMasks);
GET_SETTING(melody);

uint32_t hash = crc32.finalize();
uint32_t storedHash;
Expand All @@ -36,6 +37,7 @@ Settings::Settings() {
startWithSettings = false;
logViewInTests = true;
logViewInMasks = true;
melody = Melody::nice;
updateEEPROM();
return;
}
Expand All @@ -57,6 +59,7 @@ void Settings::updateEEPROM() {
PUT_SETTING(startWithSettings);
PUT_SETTING(logViewInTests);
PUT_SETTING(logViewInMasks);
PUT_SETTING(melody);
PUT_SETTING(crc32.finalize());
#undef PUT_SETTING
}
2 changes: 2 additions & 0 deletions src/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <stdint.h>

#include "Time.h"
#include "Melody.h"

struct Settings {
Settings();
Expand All @@ -16,4 +17,5 @@ struct Settings {
bool logViewInTests;
bool logViewInMasks;
bool confirmAlarm;
Melody::Name melody;
};
24 changes: 24 additions & 0 deletions src/SettingsSetter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,22 @@ void SettingsSetter::processSetViewInMasks() const {
gDisplay[1] << "Log";
}

void SettingsSetter::processSetMelody() const {
gDisplay[0] << "Notify melody";
uint8_t choice = gSettings.melody;
bool changed = getInt(choice, 0, Melody::last_ - 1);

gDisplay[1] << Melody::getMelodyName(gSettings.melody);

if (!changed)
return;

gSettings.melody = static_cast<Melody::Name>(choice);

gBeeper.setMelody(gSettings.melody);
gBeeper.alarm();
}

void SettingsSetter::process() {
if (m_timer.state() != Timer::RUNNING) {
int8_t shift = 0;
Expand All @@ -127,6 +143,11 @@ void SettingsSetter::process() {
else
gBeeper.stop();

if (m_step == Step::setMelody)
gBeeper.alarm();
else
gBeeper.stop();

gSettings.lagTime = m_lagTime;
gSettings.updateEEPROM();
}
Expand Down Expand Up @@ -157,6 +178,9 @@ void SettingsSetter::process() {
case Step::setViewInMasks:
processSetViewInMasks();
break;
case Step::setMelody:
processSetMelody();
break;
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/SettingsSetter.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class SettingsSetter final {
setStartWithSettings,
setViewInTests,
setViewInMasks,
setMelody,
last_
};

Expand All @@ -34,6 +35,7 @@ class SettingsSetter final {
void processStartWithSettings() const;
void processSetViewInTests() const;
void processSetViewInMasks() const;
void processSetMelody() const;

Step m_step = Step::setLagTime;
Time m_lagTime;
Expand Down

0 comments on commit 84fe7ac

Please sign in to comment.