2017-12-07 15:49:57 +00:00
|
|
|
#include "countdown.h"
|
|
|
|
#include "screen/menu.h"
|
|
|
|
#include "display.h"
|
|
|
|
#include "state.h"
|
|
|
|
#include "config.h"
|
|
|
|
#include "buzzer.h"
|
2017-11-26 19:22:15 +00:00
|
|
|
|
|
|
|
|
2017-12-08 21:32:04 +00:00
|
|
|
inline uint32_t intDivCeil(uint32_t x, uint32_t y)
|
|
|
|
{
|
|
|
|
return x / y + (x % y != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-03 20:27:45 +00:00
|
|
|
void CountdownScreen::printRemainingTime()
|
2017-11-26 19:22:15 +00:00
|
|
|
{
|
2017-12-07 16:32:59 +00:00
|
|
|
LCDPrintLineCentered(getDisplay(), 1, FormatTime(mLastDisplayed));
|
2017-11-26 19:22:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-03 20:27:45 +00:00
|
|
|
void CountdownScreen::onShow()
|
2017-11-27 14:51:32 +00:00
|
|
|
{
|
2017-12-08 10:08:53 +00:00
|
|
|
LCDPrintLineCentered(getDisplay(), 0, "Exposing...");
|
2017-12-07 16:32:59 +00:00
|
|
|
|
2017-12-08 21:32:04 +00:00
|
|
|
uint32_t remaining = GetExposureTimeRemaining(getCurrentTime());
|
|
|
|
mLastDisplayed = intDivCeil(remaining, 1000);
|
|
|
|
|
2017-11-26 19:22:15 +00:00
|
|
|
printRemainingTime();
|
2017-12-07 15:49:57 +00:00
|
|
|
|
2017-12-08 21:32:04 +00:00
|
|
|
analogWrite(PinLED, map(GetExposureIntensity(), 0, 100, 0, 255));
|
2017-11-26 19:22:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-03 20:27:45 +00:00
|
|
|
void CountdownScreen::onHide()
|
2017-11-26 19:22:15 +00:00
|
|
|
{
|
|
|
|
digitalWrite(PinLED, LOW);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-03 20:27:45 +00:00
|
|
|
void CountdownScreen::onButton()
|
2017-11-26 19:22:15 +00:00
|
|
|
{
|
|
|
|
// TODO Confirmation?
|
2017-12-07 15:49:57 +00:00
|
|
|
Buzzer::click();
|
|
|
|
getScreenManager()->show<MenuScreen>();
|
2017-11-26 19:22:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-08 21:32:04 +00:00
|
|
|
void CountdownScreen::onEncoder(int32_t lastPosition, int32_t newPosition)
|
2017-11-26 19:22:15 +00:00
|
|
|
{
|
2017-11-27 14:51:32 +00:00
|
|
|
// TODO Allow adding / removing time?
|
2017-11-26 19:22:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-03 20:27:45 +00:00
|
|
|
void CountdownScreen::onTick()
|
2017-11-26 19:22:15 +00:00
|
|
|
{
|
2017-12-08 21:32:04 +00:00
|
|
|
uint32_t remaining = GetExposureTimeRemaining(getCurrentTime());
|
|
|
|
remaining = intDivCeil(remaining, 1000);
|
2017-11-26 19:22:15 +00:00
|
|
|
|
2017-12-07 16:32:59 +00:00
|
|
|
if (remaining == 0)
|
2017-11-26 19:22:15 +00:00
|
|
|
{
|
2017-12-07 16:32:59 +00:00
|
|
|
mLastDisplayed = 0;
|
2017-11-27 14:51:32 +00:00
|
|
|
|
2017-12-08 21:32:04 +00:00
|
|
|
LCDPrintLineCentered(getDisplay(), 0, "Done!");
|
2017-11-26 19:22:15 +00:00
|
|
|
printRemainingTime();
|
|
|
|
digitalWrite(PinLED, LOW);
|
2017-11-27 14:51:32 +00:00
|
|
|
|
2017-12-07 15:49:57 +00:00
|
|
|
Buzzer::completed();
|
2017-11-27 14:51:32 +00:00
|
|
|
|
2017-12-07 16:32:59 +00:00
|
|
|
ResetExposureTimer();
|
2017-12-07 15:49:57 +00:00
|
|
|
getScreenManager()->show<MenuScreen>();
|
2017-11-26 19:22:15 +00:00
|
|
|
}
|
2017-12-07 16:32:59 +00:00
|
|
|
else if (remaining != mLastDisplayed)
|
2017-11-26 19:22:15 +00:00
|
|
|
{
|
2017-12-07 16:32:59 +00:00
|
|
|
mLastDisplayed = remaining;
|
2017-11-26 19:22:15 +00:00
|
|
|
printRemainingTime();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|