Skip to content

Commit

Permalink
Play melody after printing base in split grade
Browse files Browse the repository at this point in the history
  • Loading branch information
lo1ol committed Jul 8, 2024
1 parent 0a86483 commit b32f71f
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
2. Linear test mode: simple mode for linear testing
3. Print mode: ability to stop printing at any time. Usefull for getting fast masking values
4. Mask mode: for printing with accurate masks
4. Split grade test modes: the same as fstop and linear test modes, but allows to set base time
5. Split grade test modes: the same as fstop and linear test modes, but allows to set base time. After printing base, the melody is playing to not forget change filter

## Killer features:

Expand Down
2 changes: 1 addition & 1 deletion README_RU.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
2. Линейный тест: Задается начальное значение и шаг
3. Режим печати: можете задать время и печатать с ним. Дополнительно есть возможность остановки печати и печати по удержанию кнопки (удобно для маскирования и коротких выдержках).
4. Режим маскирования: задайте количество масок и время, которое нужено для засветки определенной маски
4. Сплит грейд тесты: аналогичны тестам F стопами и линейным тестам, но с возможностью выставить начальное время экспонирования (время засветки первым фильтром)
5. Сплит грейд тесты: аналогичны тестам F стопами и линейным тестам, но с возможностью выставить начальное время экспонирования (время засветки первым фильтром). После печати базового времени играет мелодия, чтобы вы не забыли сменить фильтр

## Killer фичи:

Expand Down
53 changes: 43 additions & 10 deletions src/Beeper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "Tools.h"

constexpr uint16_t kMelodySwitchTimes[] = { 250, 250, 125, 125, 60, 60, 400 };

void Beeper::tick() {
uint32_t currentTime = millis();
switch (m_state) {
Expand All @@ -22,12 +24,12 @@ void Beeper::tick() {
m_pinState = false;
}
break;
case State::melody:
processMelody();
break;
}

if (m_pinState)
analogWrite(m_pin, gSettings.beepVolume);
else
analogWrite(m_pin, 0);
processPin();
}

void Beeper::setup() {
Expand All @@ -40,7 +42,7 @@ void Beeper::beep() {

m_pinState = true;
m_timer = millis() + 100;
analogWrite(m_pinState, gSettings.beepVolume);
processPin();
}

void Beeper::start(bool silentStart) {
Expand All @@ -54,13 +56,44 @@ void Beeper::start(bool silentStart) {
m_timer = millis() + 100;
}

if (m_pinState)
analogWrite(m_pin, gSettings.beepVolume);
else
analogWrite(m_pin, 0);
processPin();
}

void Beeper::stop() {
m_state = State::off;
analogWrite(m_pinState, 0);
processPin();
}

void Beeper::melody() {
m_state = State::melody;

m_timer = millis() + kMelodySwitchTimes[0];
m_melodyPhase = 0;
m_pinState = true;

processMelody();
processPin();
}

void Beeper::processMelody() {
if (m_timer > millis())
return;

++m_melodyPhase;

if (m_melodyPhase == sizeof(kMelodySwitchTimes) / sizeof(kMelodySwitchTimes[0])) {
m_pinState = false;
m_state = State::off;
return;
}

m_pinState = !m_pinState;
m_timer = millis() + kMelodySwitchTimes[m_melodyPhase];
}

void Beeper::processPin() const {
if (m_pinState)
analogWrite(m_pin, gSettings.beepVolume);
else
analogWrite(m_pin, 0);
}
7 changes: 6 additions & 1 deletion src/Beeper.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ class Beeper {
public:
Beeper(uint8_t pin) : m_pin(pin) {}

enum class State { off, on, single };
enum class State { off, on, single, melody };

void beep();
void melody();

// start beep every second
void start(bool silentStart = false);
Expand All @@ -18,7 +19,11 @@ class Beeper {
void tick();

private:
void processMelody();
void processPin() const;

bool m_pinState = false;
uint8_t m_melodyPhase;
State m_state = State::off;
uint8_t m_pin;
uint32_t m_timer;
Expand Down
4 changes: 3 additions & 1 deletion src/Modes/FStopTestMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ void FStopTestMode::process() {
gTimer.start(getPrintTime());

if (gTimer.stopped()) {
if (m_currentRun == 0) // don't take into account base time
if (m_currentRun == 0) { // don't take into account base time
gTimer.reset();
gBeeper.melody();
}
++m_currentRun;
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/Modes/LinearTestMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ void LinearTestMode::process() {
gTimer.start(getPrintTime());

if (gTimer.stopped()) {
if (m_currentRun == 0)
if (m_currentRun == 0) {
gTimer.reset();
gBeeper.melody();
}
++m_currentRun;
}
}
Expand Down

0 comments on commit b32f71f

Please sign in to comment.