diff --git a/.gitignore b/.gitignore index c51a0ea..b2d534d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -*.sublime-workspace \ No newline at end of file +*.sublime-workspace +.pioenvs +.piolibdeps \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 557489b..cb3284e 100644 --- a/platformio.ini +++ b/platformio.ini @@ -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 \ No newline at end of file diff --git a/src/ScreenCountdown.cpp b/src/ScreenCountdown.cpp index 8779439..f19290f 100644 --- a/src/ScreenCountdown.cpp +++ b/src/ScreenCountdown.cpp @@ -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(); } diff --git a/src/ScreenManager.h b/src/ScreenManager.h index d0dce59..f0340b8 100644 --- a/src/ScreenManager.h +++ b/src/ScreenManager.h @@ -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 void ScreenManager::show() + } + + + template void show() { if (mCurrent != NULL) { mCurrent->onHide(); delete(mCurrent); } - + mCurrent = new T(this); mCurrent->onShow(); } diff --git a/src/main.cpp b/src/main.cpp index a98b0d5..526ccab 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,7 @@ +#include #include #include #include -#include #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; }