79 lines
1.4 KiB
C++
79 lines
1.4 KiB
C++
#include "countdown.h"
|
|
#include "screen/menu.h"
|
|
#include "display.h"
|
|
#include "state.h"
|
|
#include "config.h"
|
|
#include "buzzer.h"
|
|
|
|
|
|
inline uint32_t intDivCeil(uint32_t x, uint32_t y)
|
|
{
|
|
return x / y + (x % y != 0);
|
|
}
|
|
|
|
|
|
void CountdownScreen::printRemainingTime()
|
|
{
|
|
LCDPrintLineCentered(getDisplay(), 1, FormatTime(mLastDisplayed));
|
|
}
|
|
|
|
|
|
void CountdownScreen::onShow()
|
|
{
|
|
LCDPrintLineCentered(getDisplay(), 0, "Exposing...");
|
|
|
|
uint32_t remaining = GetExposureTimeRemaining(getCurrentTime());
|
|
mLastDisplayed = intDivCeil(remaining, 1000);
|
|
|
|
printRemainingTime();
|
|
|
|
analogWrite(PinLED, map(GetExposureIntensity(), 0, 100, 0, 255));
|
|
}
|
|
|
|
|
|
void CountdownScreen::onHide()
|
|
{
|
|
digitalWrite(PinLED, LOW);
|
|
}
|
|
|
|
|
|
void CountdownScreen::onButton()
|
|
{
|
|
// TODO Confirmation?
|
|
Buzzer::click();
|
|
getScreenManager()->show<MenuScreen>();
|
|
}
|
|
|
|
|
|
void CountdownScreen::onEncoder(int32_t lastPosition, int32_t newPosition)
|
|
{
|
|
// TODO Allow adding / removing time?
|
|
}
|
|
|
|
|
|
void CountdownScreen::onTick()
|
|
{
|
|
uint32_t remaining = GetExposureTimeRemaining(getCurrentTime());
|
|
remaining = intDivCeil(remaining, 1000);
|
|
|
|
if (remaining == 0)
|
|
{
|
|
mLastDisplayed = 0;
|
|
|
|
LCDPrintLineCentered(getDisplay(), 0, "Done!");
|
|
printRemainingTime();
|
|
digitalWrite(PinLED, LOW);
|
|
|
|
Buzzer::completed();
|
|
|
|
ResetExposureTimer();
|
|
getScreenManager()->show<MenuScreen>();
|
|
}
|
|
else if (remaining != mLastDisplayed)
|
|
{
|
|
mLastDisplayed = remaining;
|
|
printRemainingTime();
|
|
}
|
|
}
|
|
|