@@ -22,10 +22,10 @@ void SSD1306Ui::setTargetFPS(byte fps){
2222// -/------ Automatic controll ------\-
2323
2424void SSD1306Ui::enableAutoTransition (){
25- autoTransition = true ;
25+ this -> autoTransition = true ;
2626}
2727void SSD1306Ui::disableAutoTransition (){
28- autoTransition = false ;
28+ this -> autoTransition = false ;
2929}
3030void SSD1306Ui::setAutoTransitionForwards (){
3131 this ->frameTransitionDirection = 1 ;
@@ -54,100 +54,100 @@ void SSD1306Ui::setActiveSymbole(const char* symbole) {
5454 this ->dirty = true ;
5555}
5656void SSD1306Ui::setInactiveSymbole (const char * symbole) {
57- this ->inactiveSymbole = symbole;
57+ this ->inactiveSymbole = symbole;
5858 this ->dirty = true ;
5959}
6060
6161
6262// -/----- Frame settings -----\-
63- void SSD1306Ui::setFrameAnimation (AnimationDirection dir) {
63+ void SSD1306Ui::setFrameAnimation (AnimationDirection dir) {
6464 this ->frameAnimationDirection = dir;
6565}
66- void SSD1306Ui::setFrames (bool (*frameFunctions[])(SSD1306 *display, int x, int y), int frameCount) {
66+ void SSD1306Ui::setFrames (bool (*frameFunctions[])(SSD1306 *display, SSD1306UiState* state, int x, int y), int frameCount) {
6767 this ->frameCount = frameCount;
6868 this ->frameFunctions = frameFunctions;
6969}
7070
7171// -/----- Overlays ------\-
72- void SSD1306Ui::setOverlays (bool (*overlayFunctions[])(SSD1306 *display), int overlayCount){
72+ void SSD1306Ui::setOverlays (bool (*overlayFunctions[])(SSD1306 *display, SSD1306UiState* state ), int overlayCount){
7373 this ->overlayCount = overlayCount;
7474 this ->overlayFunctions = overlayFunctions;
7575}
7676
7777
7878// -/----- Manuel control -----\-
7979void SSD1306Ui::nextFrame () {
80- this ->frameState = IN_TRANSITION;
81- this ->ticksSinceLastStateSwitch = 0 ;
80+ this ->state . frameState = IN_TRANSITION;
81+ this ->state . ticksSinceLastStateSwitch = 0 ;
8282 this ->frameTransitionDirection = 1 ;
8383}
8484void SSD1306Ui::previousFrame () {
85- this ->frameState = IN_TRANSITION;
86- this ->ticksSinceLastStateSwitch = 0 ;
85+ this ->state . frameState = IN_TRANSITION;
86+ this ->state . ticksSinceLastStateSwitch = 0 ;
8787 this ->frameTransitionDirection = -1 ;
8888}
8989
9090
9191// -/----- State information -----\-
9292FrameState SSD1306Ui::getFrameState (){
93- return this ->frameState ;
93+ return this ->state . frameState ;
9494}
95+
9596int SSD1306Ui::getCurrentFrame (){
96- return this ->currentFrame ;
97+ return this ->state . currentFrame ;
9798}
9899
99100
100101int SSD1306Ui::update (){
101- int timeBudget = this ->updateInterval - (millis () - this ->lastUpdate );
102+ int timeBudget = this ->updateInterval - (millis () - this ->state . lastUpdate );
102103 if ( timeBudget <= 0 ) {
103-
104104 // Implement frame skipping to ensure time budget is keept
105- if (this ->autoTransition && this ->lastUpdate != 0 ) this ->ticksSinceLastStateSwitch += abs ( timeBudget) / this ->updateInterval ;
106-
107- this ->lastUpdate = millis ();
105+ if (this ->autoTransition && this ->state . lastUpdate != 0 ) this ->state . ticksSinceLastStateSwitch += ceil (- timeBudget / this ->updateInterval ) ;
106+
107+ this ->state . lastUpdate = millis ();
108108 this ->tick ();
109- }
109+ }
110110 return timeBudget;
111111}
112112
113113
114114void SSD1306Ui::tick () {
115- this ->ticksSinceLastStateSwitch ++;
115+ this ->state . ticksSinceLastStateSwitch ++;
116116
117- switch (this ->frameState ) {
117+ switch (this ->state . frameState ) {
118118 case IN_TRANSITION:
119119 this ->dirty = true ;
120- if (this ->ticksSinceLastStateSwitch >= this ->ticksPerTransition ){
121- this ->frameState = FIXED;
122- this ->currentFrame = getNextFrameNumber ();
123- this ->ticksSinceLastStateSwitch = 0 ;
120+ if (this ->state . ticksSinceLastStateSwitch >= this ->ticksPerTransition ){
121+ this ->state . frameState = FIXED;
122+ this ->state . currentFrame = getNextFrameNumber ();
123+ this ->state . ticksSinceLastStateSwitch = 0 ;
124124 }
125125 break ;
126126 case FIXED:
127- if (this ->ticksSinceLastStateSwitch >= this ->ticksPerFrame ){
127+ if (this ->state . ticksSinceLastStateSwitch >= this ->ticksPerFrame ){
128128 if (this ->autoTransition ){
129- this ->frameState = IN_TRANSITION;
129+ this ->state . frameState = IN_TRANSITION;
130130 this ->dirty = true ;
131131 }
132- this ->ticksSinceLastStateSwitch = 0 ;
132+ this ->state . ticksSinceLastStateSwitch = 0 ;
133133 }
134134 break ;
135135 }
136-
136+
137137 if (this ->dirty ) {
138138 this ->dirty = false ;
139139 this ->display ->clear ();
140- this ->drawIndicator ();
140+ this ->drawIndicator ();
141141 this ->drawFrame ();
142142 this ->drawOverlays ();
143143 this ->display ->display ();
144144 }
145145}
146146
147147void SSD1306Ui::drawFrame (){
148- switch (this ->frameState ){
148+ switch (this ->state . frameState ){
149149 case IN_TRANSITION: {
150- float progress = (float ) this ->ticksSinceLastStateSwitch / (float ) this ->ticksPerTransition ;
150+ float progress = (float ) this ->state . ticksSinceLastStateSwitch / (float ) this ->ticksPerTransition ;
151151 int x, y, x1, y1;
152152 switch (this ->frameAnimationDirection ){
153153 case SLIDE_LEFT:
@@ -180,36 +180,36 @@ void SSD1306Ui::drawFrame(){
180180 int dir = frameTransitionDirection >= 0 ? 1 : -1 ;
181181 x *= dir; y *= dir; x1 *= dir; y1 *= dir;
182182
183- this ->dirty |= (*this ->frameFunctions [this ->currentFrame ])(this ->display , x, y);
184- this ->dirty |= (*this ->frameFunctions [this ->getNextFrameNumber ()])(this ->display , x1, y1);
183+ this ->dirty |= (*this ->frameFunctions [this ->state . currentFrame ])(this ->display , & this -> state , x, y);
184+ this ->dirty |= (*this ->frameFunctions [this ->getNextFrameNumber ()])(this ->display , & this -> state , x1, y1);
185185 break ;
186186 }
187187 case FIXED:
188- this ->dirty |= (*this ->frameFunctions [this ->currentFrame ])(this ->display , 0 , 0 );
188+ this ->dirty |= (*this ->frameFunctions [this ->state . currentFrame ])(this ->display , & this -> state , 0 , 0 );
189189 break ;
190190 }
191191}
192192
193193void SSD1306Ui::drawIndicator () {
194- byte posOfCurrentFrame;
195-
194+ byte posOfCurrentFrame;
195+
196196 switch (this ->indicatorDirection ){
197197 case LEFT_RIGHT:
198- posOfCurrentFrame = this ->currentFrame ;
198+ posOfCurrentFrame = this ->state . currentFrame ;
199199 break ;
200200 case RIGHT_LEFT:
201- posOfCurrentFrame = (this ->frameCount - 1 ) - this ->currentFrame ;
201+ posOfCurrentFrame = (this ->frameCount - 1 ) - this ->state . currentFrame ;
202202 break ;
203203 }
204-
204+
205205 for (byte i = 0 ; i < this ->frameCount ; i++) {
206-
206+
207207 const char *xbm;
208-
208+
209209 if (posOfCurrentFrame == i) {
210210 xbm = this ->activeSymbole ;
211211 } else {
212- xbm = this ->inactiveSymbole ;
212+ xbm = this ->inactiveSymbole ;
213213 }
214214
215215 int x,y;
@@ -231,24 +231,23 @@ void SSD1306Ui::drawIndicator() {
231231 y = 32 - (12 * frameCount / 2 ) + 12 * i;
232232 break ;
233233 }
234-
234+
235235 this ->display ->drawXbm (x, y, 8 , 8 , xbm);
236- }
236+ }
237237}
238238
239239void SSD1306Ui::drawOverlays () {
240240 for (int i=0 ;i<this ->overlayCount ;i++){
241- this ->dirty |= (*this ->overlayFunctions [i])(this ->display );
241+ this ->dirty |= (*this ->overlayFunctions [i])(this ->display , & this -> state );
242242 }
243243}
244244
245245int SSD1306Ui::getNextFrameNumber (){
246- int nextFrame = (this ->currentFrame + this ->frameTransitionDirection ) % this ->frameCount ;
246+ int nextFrame = (this ->state . currentFrame + this ->frameTransitionDirection ) % this ->frameCount ;
247247 if (nextFrame < 0 ){
248248 nextFrame = this ->frameCount + nextFrame;
249249 }
250- return nextFrame;
250+ return nextFrame;
251251}
252252
253253
254-
0 commit comments