Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,10 @@ void setFont(const uint8_t* fontData);

## Ui Library (OLEDDisplayUi)

The Ui Library is used to provide a basic set of Ui elements called, `Frames` and `Overlays`. A `Frame` is used to provide
information the default behaviour is to display a `Frame` for a defined time and than move to the next. The library also provides an `Indicator` that will be updated accordingly. An `Overlay` on the other hand is a pieces of information (e.g. a clock) that is displayed always at the same position.

The Ui Library is used to provide a basic set of user interface elements called `Frames` and `Overlays`. A `Frame` is used to provide
information to the user. The default behaviour is to display a `Frame` for a defined time and than move to the next `Frame`. The library also
provides an `Indicator` element that will be updated accordingly. An `Overlay` on the other hand is a piece of information (e.g. a clock) that
is always displayed at the same position.

```C++
/**
Expand Down Expand Up @@ -371,7 +372,7 @@ void setLoadingDrawFunction(LoadingDrawFunction loadingDrawFunction);
*/
void runLoadingProcess(LoadingStage* stages, uint8_t stagesCount);

// Manuell Controll
// Manual control
void nextFrame();
void previousFrame();

Expand All @@ -381,7 +382,7 @@ void previousFrame();
void switchToFrame(uint8_t frame);

/**
* Transition to frame `frame`, when the `frame` number is bigger than the current
* Transition to frame `frame`. When the `frame` number is bigger than the current
* frame the forward animation will be used, otherwise the backwards animation is used.
*/
void transitionToFrame(uint8_t frame);
Expand All @@ -401,8 +402,8 @@ int8_t update();
![DemoFrame1](https://github.com/squix78/esp8266-oled-ssd1306/raw/master/resources/DemoFrame1.jpg)

This frame shows three things:
* How to draw an xbm image
* How to draw a static text which is not moved by the frame transition
* How to draw an XMB image
* How to draw static text which is not moved by the frame transition
* The active/inactive frame indicators

### Frame 2
Expand Down
52 changes: 26 additions & 26 deletions src/OLEDDisplayUi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ OLEDDisplayUi::OLEDDisplayUi(OLEDDisplay *display) {
state.frameState = FIXED;
state.currentFrame = 0;
state.frameTransitionDirection = 1;
state.isIndicatorDrawen = true;
state.manuelControll = false;
state.isIndicatorDrawn = true;
state.manualControl = false;
state.userData = NULL;
shouldDrawIndicators = true;
autoTransition = true;
Expand Down Expand Up @@ -106,11 +106,11 @@ void OLEDDisplayUi::setTimePerTransition(uint16_t time){

// -/------ Customize indicator position and style -------\-
void OLEDDisplayUi::enableIndicator(){
this->state.isIndicatorDrawen = true;
this->state.isIndicatorDrawn = true;
}

void OLEDDisplayUi::disableIndicator(){
this->state.isIndicatorDrawen = false;
this->state.isIndicatorDrawn = false;
}

void OLEDDisplayUi::enableAllIndicators(){
Expand Down Expand Up @@ -179,10 +179,10 @@ void OLEDDisplayUi::runLoadingProcess(LoadingStage* stages, uint8_t stagesCount)
delay(150);
}

// -/----- Manuel control -----\-
// -/----- Manual control -----\-
void OLEDDisplayUi::nextFrame() {
if (this->state.frameState != IN_TRANSITION) {
this->state.manuelControll = true;
this->state.manualControl = true;
this->state.frameState = IN_TRANSITION;
this->state.ticksSinceLastStateSwitch = 0;
this->lastTransitionDirection = this->state.frameTransitionDirection;
Expand All @@ -191,7 +191,7 @@ void OLEDDisplayUi::nextFrame() {
}
void OLEDDisplayUi::previousFrame() {
if (this->state.frameState != IN_TRANSITION) {
this->state.manuelControll = true;
this->state.manualControl = true;
this->state.frameState = IN_TRANSITION;
this->state.ticksSinceLastStateSwitch = 0;
this->lastTransitionDirection = this->state.frameTransitionDirection;
Expand All @@ -205,7 +205,7 @@ void OLEDDisplayUi::switchToFrame(uint8_t frame) {
if (frame == this->state.currentFrame) return;
this->state.frameState = FIXED;
this->state.currentFrame = frame;
this->state.isIndicatorDrawen = true;
this->state.isIndicatorDrawn = true;
}

void OLEDDisplayUi::transitionToFrame(uint8_t frame) {
Expand All @@ -214,7 +214,7 @@ void OLEDDisplayUi::transitionToFrame(uint8_t frame) {
if (frame == this->state.currentFrame) return;
this->nextFrameNumber = frame;
this->lastTransitionDirection = this->state.frameTransitionDirection;
this->state.manuelControll = true;
this->state.manualControl = true;
this->state.frameState = IN_TRANSITION;
this->state.frameTransitionDirection = frame < this->state.currentFrame ? -1 : 1;
}
Expand All @@ -237,7 +237,7 @@ int16_t OLEDDisplayUi::update(){
#endif
int32_t timeBudget = this->updateInterval - (frameStart - this->state.lastUpdate);
if ( timeBudget <= 0) {
// Implement frame skipping to ensure time budget is keept
// Implement frame skipping to ensure time budget is kept
if (this->autoTransition && this->state.lastUpdate != 0) this->state.ticksSinceLastStateSwitch += ceil((double)-timeBudget / (double)this->updateInterval);

this->state.lastUpdate = frameStart;
Expand Down Expand Up @@ -266,10 +266,10 @@ void OLEDDisplayUi::tick() {
}
break;
case FIXED:
// Revert manuelControll
if (this->state.manuelControll) {
// Revert manualControl
if (this->state.manualControl) {
this->state.frameTransitionDirection = this->lastTransitionDirection;
this->state.manuelControll = false;
this->state.manualControl = false;
}
if (this->state.ticksSinceLastStateSwitch >= this->ticksPerFrame){
if (this->autoTransition){
Expand All @@ -294,7 +294,7 @@ void OLEDDisplayUi::resetState() {
this->state.ticksSinceLastStateSwitch = 0;
this->state.frameState = FIXED;
this->state.currentFrame = 0;
this->state.isIndicatorDrawen = true;
this->state.isIndicatorDrawn = true;
}

void OLEDDisplayUi::drawFrame(){
Expand Down Expand Up @@ -337,32 +337,32 @@ void OLEDDisplayUi::drawFrame(){
int8_t dir = this->state.frameTransitionDirection >= 0 ? 1 : -1;
x *= dir; y *= dir; x1 *= dir; y1 *= dir;

bool drawenCurrentFrame;
bool drawnCurrentFrame;


// Prope each frameFunction for the indicator Drawen state
// Probe each frameFunction for the indicator drawn state
this->enableIndicator();
(this->frameFunctions[this->state.currentFrame])(this->display, &this->state, x, y);
drawenCurrentFrame = this->state.isIndicatorDrawen;
drawnCurrentFrame = this->state.isIndicatorDrawn;

this->enableIndicator();
(this->frameFunctions[this->getNextFrameNumber()])(this->display, &this->state, x1, y1);

// Build up the indicatorDrawState
if (drawenCurrentFrame && !this->state.isIndicatorDrawen) {
// Drawen now but not next
if (drawnCurrentFrame && !this->state.isIndicatorDrawn) {
// Drawn now but not next
this->indicatorDrawState = 2;
} else if (!drawenCurrentFrame && this->state.isIndicatorDrawen) {
// Not drawen now but next
} else if (!drawnCurrentFrame && this->state.isIndicatorDrawn) {
// Not drawn now but next
this->indicatorDrawState = 1;
} else if (!drawenCurrentFrame && !this->state.isIndicatorDrawen) {
// Not drawen in both frames
} else if (!drawnCurrentFrame && !this->state.isIndicatorDrawn) {
// Not drawn in both frames
this->indicatorDrawState = 3;
}

// If the indicator isn't draw in the current frame
// reflect it in state.isIndicatorDrawen
if (!drawenCurrentFrame) this->state.isIndicatorDrawen = false;
// reflect it in state.isIndicatorDrawn
if (!drawnCurrentFrame) this->state.isIndicatorDrawn = false;

break;
}
Expand All @@ -381,7 +381,7 @@ void OLEDDisplayUi::drawIndicator() {
// Only draw if the indicator is invisible
// for both frames or
// the indiactor is shown and we are IN_TRANSITION
if (this->indicatorDrawState == 3 || (!this->state.isIndicatorDrawen && this->state.frameState != IN_TRANSITION)) {
if (this->indicatorDrawState == 3 || (!this->state.isIndicatorDrawn && this->state.frameState != IN_TRANSITION)) {
return;
}

Expand Down
14 changes: 7 additions & 7 deletions src/OLEDDisplayUi.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ struct OLEDDisplayUiState {
FrameState frameState;
uint8_t currentFrame;

bool isIndicatorDrawen;
bool isIndicatorDrawn;

// Normal = 1, Inverse = -1;
int8_t frameTransitionDirection;

bool manuelControll;
bool manualControl;

// Custom data that can be used by the user
void* userData;
Expand Down Expand Up @@ -143,10 +143,10 @@ class OLEDDisplayUi {
OverlayCallback* overlayFunctions;
uint8_t overlayCount;

// Will the Indicator be drawen
// Will the Indicator be drawn
// 3 Not drawn in both frames
// 2 Drawn this frame but not next
// 1 Not drown this frame but next
// 1 Not drawn this frame but next
// 0 Not known yet
uint8_t indicatorDrawState;

Expand Down Expand Up @@ -183,7 +183,7 @@ class OLEDDisplayUi {
*/
void setTargetFPS(uint8_t fps);

// Automatic Controll
// Automatic Control
/**
* Enable automatic transition to next frame after the some time can be configured with `setTimePerFrame` and `setTimePerTransition`.
*/
Expand All @@ -201,12 +201,12 @@ class OLEDDisplayUi {
void setAutoTransitionBackwards();

/**
* Set the approx. time a frame is displayed
* Set the approximate time a frame is displayed
*/
void setTimePerFrame(uint16_t time);

/**
* Set the approx. time a transition will take
* Set the approximate time a transition will take
*/
void setTimePerTransition(uint16_t time);

Expand Down