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] [env:attiny85]
platform = atmelavr platform = atmelavr
board = atmega328p board = pro16MHzatmega328
framework = arduino framework = arduino
upload_protocol = stk500v1 upload_protocol = stk500v1
upload_flags = -P$UPLOAD_PORT -b$UPLOAD_SPEED upload_flags = -P$UPLOAD_PORT -b$UPLOAD_SPEED
board_f_cpu = 1000000L board_f_cpu = 1000000L
lib_deps =
Bounce2
Encoder
upload_port = COM7 upload_port = COM7
upload_speed = 19200 upload_speed = 19200

View File

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

View File

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

View File

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