@@ -8,16 +8,23 @@ TimerData _timerData;
88
99TimerData *timerData () { return &_timerData; }
1010
11- ActiveSegment calculateCurrentSegment (TIME timeOffset) {
12- if (!_timerData.valid || timeOffset == 0 ) {
13- return {0 , 0xfff , " " , 0 };
11+ TIME calculateTimeInCurrentRound (TIME currentTime) {
12+
13+ if (currentTime < _timerData.start_at &&
14+ _timerData.display_options .pre_start_behaviour ==
15+ PreStartBehaviour::SHOW_FIRST_SEGMENT) {
16+ return 1 ;
17+ }
18+
19+ long totalTimePerRound = 0 ;
20+ for (int i = 0 ; i < 10 && _timerData.segments [i].valid ; i++) {
21+ totalTimePerRound += _timerData.segments [i].time ;
1422 }
1523
16- TIME currentTime = (TIME)millis () + timeOffset;
1724 if (currentTime < _timerData.start_at &&
1825 _timerData.display_options .pre_start_behaviour ==
19- PreStartBehaviour::SHOW_ZERO ) {
20- return { 0 , 0xfff , " " , currentTime} ;
26+ PreStartBehaviour::SHOW_LAST_SEGMENT ) {
27+ return totalTimePerRound ;
2128 }
2229
2330 long elapsedTime = currentTime - _timerData.start_at ;
@@ -26,16 +33,20 @@ ActiveSegment calculateCurrentSegment(TIME timeOffset) {
2633 elapsedTime = _timerData.stop_at - _timerData.start_at ;
2734 }
2835
29- long totalTimePerRound = 0 ;
30- for (int i = 0 ; i < 10 && _timerData.segments [i].valid ; i++) {
31- totalTimePerRound += _timerData.segments [i].time ;
36+ if (!_timerData.repeat && elapsedTime > totalTimePerRound) {
37+ return totalTimePerRound;
3238 }
3339
34- if (!_timerData.repeat && elapsedTime > totalTimePerRound) {
35- return {0 , 0xfff , " " , currentTime};
40+ return elapsedTime % totalTimePerRound;
41+ }
42+
43+ ActiveSegment calculateCurrentSegment (TIME timeOffset) {
44+ if (!_timerData.valid || timeOffset == 0 ) {
45+ return {0 , 0xfff , " " , 0 };
3646 }
3747
38- long timeInCurrentRound = elapsedTime % totalTimePerRound;
48+ TIME currentTime = (TIME)millis () + timeOffset;
49+ long timeInCurrentRound = calculateTimeInCurrentRound (currentTime);
3950
4051 int currentSegmentIndex = 0 ;
4152 long timeInCurrentSegment = 0 ;
0 commit comments