Skip to content

Commit b2f8746

Browse files
committed
Use a typedef to simplify function signatures
1 parent cdc6f17 commit b2f8746

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

SSD1306Ui.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ void SSD1306Ui::setInactiveSymbole(const char* symbole) {
6363
void SSD1306Ui::setFrameAnimation(AnimationDirection dir) {
6464
this->frameAnimationDirection = dir;
6565
}
66-
void SSD1306Ui::setFrames(bool (*frameFunctions[])(SSD1306 *display, SSD1306UiState* state, int x, int y), int frameCount) {
66+
void SSD1306Ui::setFrames(FrameCallback* frameFunctions, int frameCount) {
6767
this->frameCount = frameCount;
6868
this->frameFunctions = frameFunctions;
6969
}
7070

7171
// -/----- Overlays ------\-
72-
void SSD1306Ui::setOverlays(bool (*overlayFunctions[])(SSD1306 *display, SSD1306UiState* state), int overlayCount){
72+
void SSD1306Ui::setOverlays(OverlayCallback* overlayFunctions, int overlayCount){
7373
this->overlayCount = overlayCount;
7474
this->overlayFunctions = overlayFunctions;
7575
}
@@ -176,12 +176,12 @@ void SSD1306Ui::drawFrame(){
176176
int dir = frameTransitionDirection >= 0 ? 1 : -1;
177177
x *= dir; y *= dir; x1 *= dir; y1 *= dir;
178178

179-
this->dirty |= (*this->frameFunctions[this->state.currentFrame])(this->display, &this->state, x, y);
180-
this->dirty |= (*this->frameFunctions[this->getNextFrameNumber()])(this->display, &this->state, x1, y1);
179+
this->dirty |= (this->frameFunctions[this->state.currentFrame])(this->display, &this->state, x, y);
180+
this->dirty |= (this->frameFunctions[this->getNextFrameNumber()])(this->display, &this->state, x1, y1);
181181
break;
182182
}
183183
case FIXED:
184-
this->dirty |= (*this->frameFunctions[this->state.currentFrame])(this->display, &this->state, 0, 0);
184+
this->dirty |= (this->frameFunctions[this->state.currentFrame])(this->display, &this->state, 0, 0);
185185
break;
186186
}
187187
}
@@ -200,12 +200,12 @@ void SSD1306Ui::drawIndicator() {
200200

201201
for (byte i = 0; i < this->frameCount; i++) {
202202

203-
const char *xbm;
203+
const char *image;
204204

205205
if (posOfCurrentFrame == i) {
206-
xbm = this->activeSymbole;
206+
image = this->activeSymbole;
207207
} else {
208-
xbm = this->inactiveSymbole;
208+
image = this->inactiveSymbole;
209209
}
210210

211211
int x,y;
@@ -228,13 +228,13 @@ void SSD1306Ui::drawIndicator() {
228228
break;
229229
}
230230

231-
this->display->drawXbm(x, y, 8, 8, xbm);
231+
this->display->drawFastImage(x, y, 8, 8, image);
232232
}
233233
}
234234

235235
void SSD1306Ui::drawOverlays() {
236236
for (int i=0;i<this->overlayCount;i++){
237-
this->dirty |= (*this->overlayFunctions[i])(this->display, &this->state);
237+
this->dirty |= (this->overlayFunctions[i])(this->display, &this->state);
238238
}
239239
}
240240

SSD1306Ui.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ struct SSD1306UiState {
7070
int currentFrame = 0;
7171
};
7272

73+
typedef bool (*FrameCallback)(SSD1306 *display, SSD1306UiState* state, int x, int y);
74+
typedef bool (*OverlayCallback)(SSD1306 *display, SSD1306UiState* state);
75+
7376
class SSD1306Ui {
7477
private:
7578
SSD1306 *display;
@@ -94,11 +97,11 @@ class SSD1306Ui {
9497

9598
bool autoTransition = true;
9699

97-
bool (**frameFunctions)(SSD1306 *display, SSD1306UiState* state, int x, int y);
100+
FrameCallback* frameFunctions;
98101
int frameCount = 0;
99102

100103
// Values for Overlays
101-
bool (**overlayFunctions)(SSD1306 *display, SSD1306UiState* state);
104+
OverlayCallback* overlayFunctions;
102105
int overlayCount = 0;
103106

104107
// UI State
@@ -185,14 +188,14 @@ class SSD1306Ui {
185188
/**
186189
* Add frame drawing functions
187190
*/
188-
void setFrames(bool (*frameFunctions[])(SSD1306 *display, SSD1306UiState* state, int x, int y), int frameCount);
191+
void setFrames(FrameCallback* frameFunctions, int frameCount);
189192

190193
// Overlay
191194

192195
/**
193196
* Add overlays drawing functions that are draw independent of the Frames
194197
*/
195-
void setOverlays(bool (*overlayFunctions[])(SSD1306 *display, SSD1306UiState* state), int overlayCount);
198+
void setOverlays(OverlayCallback* overlayFunctions, int overlayCount);
196199

197200
// Manuell Controll
198201
void nextFrame();

0 commit comments

Comments
 (0)