Fixed code for PlatformIO

This commit is contained in:
Mark van Renswoude 2017-11-27 15:51:32 +01:00
parent 3d68f483ce
commit bd7a616e2b
5 changed files with 33 additions and 25 deletions

4
.gitignore vendored
View File

@ -1 +1,3 @@
*.sublime-workspace
*.sublime-workspace
.pioenvs
.piolibdeps

View File

@ -10,11 +10,15 @@
[env:attiny85]
platform = atmelavr
board = atmega328p
board = pro16MHzatmega328
framework = arduino
upload_protocol = stk500v1
upload_flags = -P$UPLOAD_PORT -b$UPLOAD_SPEED
board_f_cpu = 1000000L
lib_deps =
Bounce2
Encoder
upload_port = COM7
upload_speed = 19200

View File

@ -13,14 +13,14 @@ void ScreenCountdown::printRemainingTime()
void ScreenCountdown::onShow()
{
{
mLastDisplayed = -1;
getDisplay()->setCursor(0, 0);
getDisplay()->print("Exposing... ");
printRemainingTime();
digitalWrite(PinLED, HIGH);
digitalWrite(PinLED, HIGH);
}
@ -40,24 +40,24 @@ void ScreenCountdown::onButton()
void ScreenCountdown::onEncoder(long lastPosition, long newPosition)
{
// TODO Allow adding / removing time?
// TODO Allow adding / removing time?
}
void ScreenCountdown::onTick()
{
int elapsed = (getCurrentTime() - ExposureTimerStart) / 1000;
long elapsed = (getCurrentTime() - ExposureTimerStart) / 1000;
if (elapsed >= ExposureTime)
{
getDisplay()->setCursor(0, 0);
getDisplay()->print("Done! ");
printRemainingTime();
digitalWrite(PinLED, LOW);
buzzCompleted();
ExposureTimerStart = 0;
getScreenManager()->show<ScreenSetTime>();
}

View File

@ -13,22 +13,24 @@ class BaseScreen
ScreenManager* mScreenManager;
protected:
ScreenManager* getScreenManager();
ScreenManager* getScreenManager();
unsigned long getCurrentTime();
LiquidCrystal* getDisplay();
void printTime(int value);
public:
BaseScreen(ScreenManager* screenManager)
{
mScreenManager = screenManager;
}
virtual ~BaseScreen() {}
virtual void onShow() = 0;
virtual void onHide() = 0;
virtual void onButton() = 0;
virtual void onEncoder(long lastPosition, long newPosition) = 0;
virtual void onTick() = 0;
@ -41,17 +43,17 @@ class ScreenManager
private:
LiquidCrystal* mDisplay;
unsigned long* mCurrentTime;
BaseScreen* mCurrent = NULL;
public:
ScreenManager(LiquidCrystal* display, unsigned long* currentTime)
{
mDisplay = display;
mCurrentTime = currentTime;
}
inline BaseScreen* getCurrent()
{
return mCurrent;
@ -66,17 +68,17 @@ class ScreenManager
inline LiquidCrystal* getDisplay()
{
return mDisplay;
}
template<class T> void ScreenManager::show()
}
template<class T> void show()
{
if (mCurrent != NULL)
{
mCurrent->onHide();
delete(mCurrent);
}
mCurrent = new T(this);
mCurrent->onShow();
}

View File

@ -1,7 +1,7 @@
#include <Arduino.h>
#include <Bounce2.h>
#include <Encoder.h>
#include <LiquidCrystal.h>
#include <EEPROM.h>
#include "Config.h"
#include "ScreenManager.h"
#include "ScreenSetTime.h"
@ -54,11 +54,11 @@ void loop()
{
currentTime = millis();
button.update();
long newPosition = encoder.read();
if (abs(newPosition - lastPosition) >= EncoderSensitivity)
{
screenManager->getCurrent()->onEncoder(lastPosition, newPosition);
screenManager->getCurrent()->onEncoder(lastPosition, newPosition);
lastPosition = newPosition;
}