Skip to content
Snippets Groups Projects
Commit b2f87465 authored by Fabrice Weinberg's avatar Fabrice Weinberg
Browse files

Use a typedef to simplify function signatures

parent cdc6f17d
No related branches found
No related tags found
No related merge requests found
...@@ -63,13 +63,13 @@ void SSD1306Ui::setInactiveSymbole(const char* symbole) { ...@@ -63,13 +63,13 @@ void SSD1306Ui::setInactiveSymbole(const char* symbole) {
void SSD1306Ui::setFrameAnimation(AnimationDirection dir) { void SSD1306Ui::setFrameAnimation(AnimationDirection dir) {
this->frameAnimationDirection = dir; this->frameAnimationDirection = dir;
} }
void SSD1306Ui::setFrames(bool (*frameFunctions[])(SSD1306 *display, SSD1306UiState* state, int x, int y), int frameCount) { void SSD1306Ui::setFrames(FrameCallback* frameFunctions, int frameCount) {
this->frameCount = frameCount; this->frameCount = frameCount;
this->frameFunctions = frameFunctions; this->frameFunctions = frameFunctions;
} }
// -/----- Overlays ------\- // -/----- Overlays ------\-
void SSD1306Ui::setOverlays(bool (*overlayFunctions[])(SSD1306 *display, SSD1306UiState* state), int overlayCount){ void SSD1306Ui::setOverlays(OverlayCallback* overlayFunctions, int overlayCount){
this->overlayCount = overlayCount; this->overlayCount = overlayCount;
this->overlayFunctions = overlayFunctions; this->overlayFunctions = overlayFunctions;
} }
...@@ -176,12 +176,12 @@ void SSD1306Ui::drawFrame(){ ...@@ -176,12 +176,12 @@ void SSD1306Ui::drawFrame(){
int dir = frameTransitionDirection >= 0 ? 1 : -1; int dir = frameTransitionDirection >= 0 ? 1 : -1;
x *= dir; y *= dir; x1 *= dir; y1 *= dir; x *= dir; y *= dir; x1 *= dir; y1 *= dir;
this->dirty |= (*this->frameFunctions[this->state.currentFrame])(this->display, &this->state, x, y); this->dirty |= (this->frameFunctions[this->state.currentFrame])(this->display, &this->state, x, y);
this->dirty |= (*this->frameFunctions[this->getNextFrameNumber()])(this->display, &this->state, x1, y1); this->dirty |= (this->frameFunctions[this->getNextFrameNumber()])(this->display, &this->state, x1, y1);
break; break;
} }
case FIXED: case FIXED:
this->dirty |= (*this->frameFunctions[this->state.currentFrame])(this->display, &this->state, 0, 0); this->dirty |= (this->frameFunctions[this->state.currentFrame])(this->display, &this->state, 0, 0);
break; break;
} }
} }
...@@ -200,12 +200,12 @@ void SSD1306Ui::drawIndicator() { ...@@ -200,12 +200,12 @@ void SSD1306Ui::drawIndicator() {
for (byte i = 0; i < this->frameCount; i++) { for (byte i = 0; i < this->frameCount; i++) {
const char *xbm; const char *image;
if (posOfCurrentFrame == i) { if (posOfCurrentFrame == i) {
xbm = this->activeSymbole; image = this->activeSymbole;
} else { } else {
xbm = this->inactiveSymbole; image = this->inactiveSymbole;
} }
int x,y; int x,y;
...@@ -228,13 +228,13 @@ void SSD1306Ui::drawIndicator() { ...@@ -228,13 +228,13 @@ void SSD1306Ui::drawIndicator() {
break; break;
} }
this->display->drawXbm(x, y, 8, 8, xbm); this->display->drawFastImage(x, y, 8, 8, image);
} }
} }
void SSD1306Ui::drawOverlays() { void SSD1306Ui::drawOverlays() {
for (int i=0;i<this->overlayCount;i++){ for (int i=0;i<this->overlayCount;i++){
this->dirty |= (*this->overlayFunctions[i])(this->display, &this->state); this->dirty |= (this->overlayFunctions[i])(this->display, &this->state);
} }
} }
......
...@@ -70,6 +70,9 @@ struct SSD1306UiState { ...@@ -70,6 +70,9 @@ struct SSD1306UiState {
int currentFrame = 0; int currentFrame = 0;
}; };
typedef bool (*FrameCallback)(SSD1306 *display, SSD1306UiState* state, int x, int y);
typedef bool (*OverlayCallback)(SSD1306 *display, SSD1306UiState* state);
class SSD1306Ui { class SSD1306Ui {
private: private:
SSD1306 *display; SSD1306 *display;
...@@ -94,11 +97,11 @@ class SSD1306Ui { ...@@ -94,11 +97,11 @@ class SSD1306Ui {
bool autoTransition = true; bool autoTransition = true;
bool (**frameFunctions)(SSD1306 *display, SSD1306UiState* state, int x, int y); FrameCallback* frameFunctions;
int frameCount = 0; int frameCount = 0;
// Values for Overlays // Values for Overlays
bool (**overlayFunctions)(SSD1306 *display, SSD1306UiState* state); OverlayCallback* overlayFunctions;
int overlayCount = 0; int overlayCount = 0;
// UI State // UI State
...@@ -185,14 +188,14 @@ class SSD1306Ui { ...@@ -185,14 +188,14 @@ class SSD1306Ui {
/** /**
* Add frame drawing functions * Add frame drawing functions
*/ */
void setFrames(bool (*frameFunctions[])(SSD1306 *display, SSD1306UiState* state, int x, int y), int frameCount); void setFrames(FrameCallback* frameFunctions, int frameCount);
// Overlay // Overlay
/** /**
* Add overlays drawing functions that are draw independent of the Frames * Add overlays drawing functions that are draw independent of the Frames
*/ */
void setOverlays(bool (*overlayFunctions[])(SSD1306 *display, SSD1306UiState* state), int overlayCount); void setOverlays(OverlayCallback* overlayFunctions, int overlayCount);
// Manuell Controll // Manuell Controll
void nextFrame(); void nextFrame();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment