More jolly refactoring
This commit is contained in:
parent
5efc605d1d
commit
4551744a7c
@ -2,15 +2,49 @@
|
||||
#include "config.h"
|
||||
|
||||
|
||||
void LCDPrintLine(LiquidCrystal* display, uint8_t y, char* value, uint8_t margin)
|
||||
void LCDPrintLine(LiquidCrystal* display, uint8_t y, const char* value, uint8_t margin)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void LCDPrintLineCentered(LiquidCrystal* display, uint8_t y, char* value, uint8_t margin)
|
||||
void LCDPrintLineCentered(LiquidCrystal* display, uint8_t y, const char* value, uint8_t margin)
|
||||
{
|
||||
/*
|
||||
const char* title = mItems[mSelected]->getTitle();
|
||||
uint8_t titleLength = strlen(title);
|
||||
uint8_t maxWidth = LCDWidth - 2;
|
||||
|
||||
display->setCursor(1, 0);
|
||||
|
||||
if (titleLength >= maxWidth)
|
||||
{
|
||||
// Title too long, cut off
|
||||
char* character = (char*)title;
|
||||
for (uint8_t i = 0; i < maxWidth; i++)
|
||||
{
|
||||
display->write(byte(*character));
|
||||
character++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Center title
|
||||
uint8_t offset = (maxWidth - titleLength) / 2;
|
||||
|
||||
for (uint8_t i = 0; i < offset; i++)
|
||||
display->write(' ');
|
||||
|
||||
display->print(title);
|
||||
offset += titleLength;
|
||||
|
||||
while (offset < LCDWidth - 2)
|
||||
{
|
||||
display->print(' ');
|
||||
offset++;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "intensity.h"
|
||||
#include "state.h"
|
||||
|
||||
/*
|
||||
LiquidCrystal* display = getDisplay();
|
||||
@ -24,15 +25,22 @@
|
||||
|
||||
*/
|
||||
|
||||
char* IntensityMenuItem::getTitle()
|
||||
const char* IntensityMenuItem::getTitle()
|
||||
{
|
||||
return NULL;
|
||||
return "Intensity";
|
||||
}
|
||||
|
||||
|
||||
char* IntensityMenuItem::getValue()
|
||||
const char* IntensityMenuItem::getValue()
|
||||
{
|
||||
return NULL;
|
||||
char value[5];
|
||||
itoa(GetExposureIntensity(), value, 10);
|
||||
|
||||
uint8_t length = strlen(value);
|
||||
value[length] = '%';
|
||||
value[length + 1] = 0;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
|
@ -8,8 +8,8 @@ class IntensityMenuItem : public MenuItem
|
||||
public:
|
||||
IntensityMenuItem() : MenuItem() { }
|
||||
|
||||
char* getTitle();
|
||||
char* getValue();
|
||||
const char* getTitle();
|
||||
const char* getValue();
|
||||
|
||||
bool editable() { return true; }
|
||||
|
||||
|
@ -32,13 +32,13 @@
|
||||
ExposureTime -= ExposureTime > LargeStepTreshold ? LargeStep : SmallStep;
|
||||
*/
|
||||
|
||||
char* TimeMenuItem::getTitle()
|
||||
const char* TimeMenuItem::getTitle()
|
||||
{
|
||||
return NULL;
|
||||
return "Time";
|
||||
}
|
||||
|
||||
|
||||
char* TimeMenuItem::getValue()
|
||||
const char* TimeMenuItem::getValue()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
@ -8,8 +8,8 @@ class TimeMenuItem : public MenuItem
|
||||
public:
|
||||
TimeMenuItem() : MenuItem() { }
|
||||
|
||||
char* getTitle();
|
||||
char* getValue();
|
||||
const char* getTitle();
|
||||
const char* getValue();
|
||||
|
||||
bool editable() { return true; }
|
||||
|
||||
|
@ -8,18 +8,15 @@
|
||||
|
||||
void CountdownScreen::printRemainingTime()
|
||||
{
|
||||
const char* time = FormatTime(ExposureTime - ((getCurrentTime() - ExposureTimerStart) / 1000));
|
||||
|
||||
// TODO blank out, center, etc
|
||||
LCDPrintLineCentered(getDisplay(), 1, time);
|
||||
LCDPrintLineCentered(getDisplay(), 1, FormatTime(mLastDisplayed));
|
||||
}
|
||||
|
||||
|
||||
void CountdownScreen::onShow()
|
||||
{
|
||||
mLastDisplayed = (uint32_t)-1;
|
||||
|
||||
LCDPrintLine(getDisplay(), 0, "Exposing...");
|
||||
|
||||
mLastDisplayed = GetExposureTimeRemaining(getCurrentTime()) / 1000;
|
||||
printRemainingTime();
|
||||
|
||||
digitalWrite(PinLED, HIGH);
|
||||
@ -48,25 +45,25 @@ void CountdownScreen::onEncoder(long lastPosition, long newPosition)
|
||||
|
||||
void CountdownScreen::onTick()
|
||||
{
|
||||
uint32_t elapsed = (getCurrentTime() - ExposureTimerStart) / 1000;
|
||||
uint32_t remaining = GetExposureTimeRemaining(getCurrentTime()) / 1000;
|
||||
|
||||
if (elapsed >= ExposureTime)
|
||||
if (remaining == 0)
|
||||
{
|
||||
getDisplay()->setCursor(0, 0);
|
||||
getDisplay()->print("Done! ");
|
||||
mLastDisplayed = 0;
|
||||
|
||||
LCDPrintLine(getDisplay(), 0, "Done!");
|
||||
printRemainingTime();
|
||||
digitalWrite(PinLED, LOW);
|
||||
|
||||
Buzzer::completed();
|
||||
|
||||
ExposureTimerStart = 0;
|
||||
ResetExposureTimer();
|
||||
getScreenManager()->show<MenuScreen>();
|
||||
}
|
||||
else if (elapsed != mLastDisplayed)
|
||||
else if (remaining != mLastDisplayed)
|
||||
{
|
||||
mLastDisplayed = remaining;
|
||||
printRemainingTime();
|
||||
mLastDisplayed = elapsed;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "screen/menu.h"
|
||||
#include "config.h"
|
||||
#include "buzzer.h"
|
||||
#include "display.h"
|
||||
|
||||
#include "menu/time.h"
|
||||
|
||||
@ -46,41 +47,7 @@ void MenuScreen::printFullUpdate()
|
||||
|
||||
void MenuScreen::printTitle()
|
||||
{
|
||||
LiquidCrystal* display = getDisplay();
|
||||
|
||||
const char* title = mItems[mSelected]->getTitle();
|
||||
uint8_t titleLength = strlen(title);
|
||||
uint8_t maxWidth = LCDWidth - 2;
|
||||
|
||||
display->setCursor(1, 0);
|
||||
|
||||
if (titleLength >= maxWidth)
|
||||
{
|
||||
// Title too long, cut off
|
||||
char* character = (char*)title;
|
||||
for (uint8_t i = 0; i < maxWidth; i++)
|
||||
{
|
||||
display->write(byte(*character));
|
||||
character++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Center title
|
||||
uint8_t offset = (maxWidth - titleLength) / 2;
|
||||
|
||||
for (uint8_t i = 0; i < offset; i++)
|
||||
display->write(' ');
|
||||
|
||||
display->print(title);
|
||||
offset += titleLength;
|
||||
|
||||
while (offset < LCDWidth - 2)
|
||||
{
|
||||
display->print(' ');
|
||||
offset++;
|
||||
}
|
||||
}
|
||||
LCDPrintLineCentered(getDisplay(), 0, mItems[mSelected]->getTitle(), 1);
|
||||
}
|
||||
|
||||
|
||||
|
@ -8,8 +8,8 @@ class MenuItem
|
||||
public:
|
||||
virtual ~MenuItem() { }
|
||||
|
||||
virtual char* getTitle() = 0;
|
||||
virtual char* getValue() { return NULL; }
|
||||
virtual const char* getTitle() = 0;
|
||||
virtual const char* getValue() { return NULL; }
|
||||
|
||||
virtual bool editable() { return false; }
|
||||
|
||||
|
@ -7,6 +7,30 @@ uint8_t ExposureIntensity = DefaultExposureIntensity;
|
||||
uint32_t ExposureTimerStart = 0;
|
||||
|
||||
|
||||
uint32_t GetExposureTime()
|
||||
{
|
||||
return ExposureTime;
|
||||
}
|
||||
|
||||
|
||||
void SetExposureTime(uint32_t value)
|
||||
{
|
||||
ExposureTime = value;
|
||||
}
|
||||
|
||||
|
||||
uint8_t GetExposureIntensity()
|
||||
{
|
||||
return ExposureIntensity;
|
||||
}
|
||||
|
||||
|
||||
void SetExposureIntensity(uint8_t value)
|
||||
{
|
||||
ExposureIntensity = (value <= 100) ? value : 100;
|
||||
}
|
||||
|
||||
|
||||
void LoadSettings()
|
||||
{
|
||||
uint16_t offset = 0;
|
||||
@ -31,4 +55,17 @@ void StartExposureTimer(unsigned long currentTime)
|
||||
{
|
||||
SaveSettings();
|
||||
ExposureTimerStart = currentTime;
|
||||
}
|
||||
|
||||
|
||||
void ResetExposureTimer()
|
||||
{
|
||||
ExposureTimerStart = 0;
|
||||
}
|
||||
|
||||
|
||||
uint32_t GetExposureTimeRemaining(unsigned long currentTime)
|
||||
{
|
||||
uint32_t elapsed = (currentTime - ExposureTimerStart);
|
||||
return elapsed <= ExposureTime ? ExposureTime - elapsed : 0;
|
||||
}
|
@ -3,15 +3,18 @@
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
extern uint32_t ExposureTime;
|
||||
extern uint8_t ExposureIntensity;
|
||||
uint32_t GetExposureTime();
|
||||
void SetExposureTime(uint32_t value);
|
||||
|
||||
extern uint32_t ExposureTimerStart;
|
||||
uint8_t GetExposureIntensity();
|
||||
void SetExposureIntensity(uint8_t value);
|
||||
|
||||
|
||||
void LoadSettings();
|
||||
void SaveSettings();
|
||||
|
||||
void StartExposureTimer(unsigned long currentTime);
|
||||
void ResetExposureTimer();
|
||||
uint32_t GetExposureTimeRemaining(unsigned long currentTime);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user