Skip to content

Commit

Permalink
Merge pull request #9 from pietwauters/Auto-increase-points-on-redcard
Browse files Browse the repository at this point in the history
Auto increase points on redcard
  • Loading branch information
pietwauters authored Jun 11, 2022
2 parents e811b67 + 98cf48d commit ed413ff
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 25 deletions.
1 change: 1 addition & 0 deletions EventDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ union mix_t
#define UI_INPUT_RED_CARD_LEFT 0x00000015
#define UI_INPUT_RED_CARD_RIGHT 0x00000016
#define UI_INPUT_P_CARD 0x00000017
#define UI_INPUT_RESTORE_UW2F_TIMER 0x00000019
#define UI_BUZZ 0x00000018


Expand Down
51 changes: 37 additions & 14 deletions FencingStateMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ void FencingStateMachine::update (UDPIOHandler *subject, uint32_t eventtype)
uint32_t event_data = eventtype & SUB_TYPE_MASK;;
uint32_t maineventtype = eventtype & MAIN_TYPE_MASK ;
uint32_t card_event;
m_IsConnectedToRemote = true;

if(EVENT_UI_INPUT != maineventtype)
return;
Expand Down Expand Up @@ -261,6 +262,16 @@ void FencingStateMachine::update (UDPIOHandler *subject, uint32_t eventtype)
StateChanged(EVENT_TOGGLE_BUZZER);
break;

case UI_INPUT_RESTORE_UW2F_TIMER:

m_UW2FTimer.RestorePreviousState();
m_UW2FSeconds = m_UW2FTimer.GetIntermediateTime();
StateChanged(EVENT_UW2F_TIMER | (m_UW2FSeconds/60)<<16 | (m_UW2FSeconds%60)<<8);

break;



case UI_INPUT_CYCLE_WEAPON:

switch(m_MachineWeapon)
Expand Down Expand Up @@ -375,7 +386,31 @@ uint32_t FencingStateMachine::MakeTimerEvent()
temp |= EVENT_TIMER;
return temp;
}
void FencingStateMachine::ClearAllCards()
{
m_YellowCardLeft =0;
m_YellowCardRight =0;
m_RedCardLeft =0;
m_RedCardRight =0;
m_BlackCardLeft =0;
m_BlackCardRight =0;
m_YellowPCardLeft =0;
m_YellowPCardRight =0;
m_RedPCardLeft =0;
m_RedPCardRight =0;
m_BlackPCardLeft =0;
m_BlackPCardRight =0;
m_PCardLeft = 0;
m_PCardRight = 0;
StateChanged(EVENT_P_CARD);
StateChanged(EVENT_YELLOW_CARD_RIGHT);
StateChanged(EVENT_RED_CARD_RIGHT);
StateChanged(EVENT_BLACK_CARD_RIGHT);
StateChanged(EVENT_YELLOW_CARD_LEFT);
StateChanged(EVENT_RED_CARD_LEFT);
StateChanged(EVENT_BLACK_CARD_LEFT);

}
void FencingStateMachine::ResetAll()
{
m_Timer.StopTimer();
Expand All @@ -390,20 +425,7 @@ void FencingStateMachine::ResetAll()
m_currentRound = 1;
//m_nrOfRounds = 1; // a "simple reset should not change the nr of rounds"
m_Priority = NO_PRIO;
m_YellowCardLeft =0;
m_YellowCardRight =0;
m_RedCardLeft =0;
m_RedCardRight =0;
m_BlackCardLeft =0;
m_BlackCardRight =0;
m_YellowPCardLeft =0;
m_YellowPCardRight =0;
m_RedPCardLeft =0;
m_RedPCardRight =0;
m_BlackPCardLeft =0;
m_BlackPCardRight =0;
m_PCardLeft = 0;
m_PCardRight = 0;
ClearAllCards();
m_ScoreLeft =0;
m_ScoreRight =0;

Expand Down Expand Up @@ -465,6 +487,7 @@ void FencingStateMachine::SetNextTimerStateAndRoundAndNewTimeOnTimerZero()
m_UW2FTimer.Reset();
m_UW2FSeconds = 0;
StateChanged(EVENT_UW2F_TIMER);
ClearAllCards();
m_currentRound++;
}
}
Expand Down
5 changes: 4 additions & 1 deletion FencingStateMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ class FencingStateMachine : public Subject<FencingStateMachine> , public Observe
void ResetAll();
uint32_t MakeTimerEvent();
void GetFormattedStringTime(char *Destination, int MinutePrecision, int HundredthsPrecision){m_Timer.GetFormattedStringTime(Destination, MinutePrecision, HundredthsPrecision);};

bool IsConnectedToRemote(){return m_IsConnectedToRemote;};
void SetConnectedToRemote(bool value){m_IsConnectedToRemote = value;};
void ClearAllCards();

protected:

Expand Down Expand Up @@ -205,6 +207,7 @@ class FencingStateMachine : public Subject<FencingStateMachine> , public Observe
hw_timer_t * timer_FSMPeriod = NULL;
MultiWeaponSensor *m_TheSensor = NULL;
long m_NextIdleTime = 0;
bool m_IsConnectedToRemote = false;

};

Expand Down
10 changes: 6 additions & 4 deletions TimeScoreDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ uint8_t numbers[][9]= {{5,62,81,73,69,62,0,0,0},
};


#define TIME_SCORE_PERIOD_INTERVAL_MS 2000

TimeScoreDisplay::TimeScoreDisplay()
{
//ctor
Expand Down Expand Up @@ -371,25 +373,25 @@ void TimeScoreDisplay::CycleScoreMatchAndTimeWhenNotFighting()
case 0:
ShowTime();
m_objectshown = 1;
NextTimeToSwitchBetweenScoreAndTime = millis() + 2500;
NextTimeToSwitchBetweenScoreAndTime = millis() + TIME_SCORE_PERIOD_INTERVAL_MS;
break;

case 1:
ShowScore();
m_objectshown = 2;
NextTimeToSwitchBetweenScoreAndTime = millis() + 2500;
NextTimeToSwitchBetweenScoreAndTime = millis() + TIME_SCORE_PERIOD_INTERVAL_MS;
break;

case 2:
DisplayMatchCount(m_round, m_maxround);
m_objectshown = 0;
NextTimeToSwitchBetweenScoreAndTime = millis() + 750;
NextTimeToSwitchBetweenScoreAndTime = millis() + TIME_SCORE_PERIOD_INTERVAL_MS / 3;
break;

case 3:
ShowTime();
m_objectshown = 1;
NextTimeToSwitchBetweenScoreAndTime = millis() + 2500;
NextTimeToSwitchBetweenScoreAndTime = millis() + TIME_SCORE_PERIOD_INTERVAL_MS;
break;

}
Expand Down
6 changes: 4 additions & 2 deletions UW2FTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ void UW2FTimer::Stop()
{
m_TotalTime += m_TimeStopped - m_TimeStarted;
}

m_IsRunning = false;
}

void UW2FTimer::Reset()
{
Stop();
if(m_TotalTime > 0)
m_TotalTime_backup = m_TotalTime;
m_TotalTime = 0;
m_IsRunning = false;
}
Expand All @@ -39,5 +41,5 @@ long UW2FTimer::GetIntermediateTime()
if(m_IsRunning)
return((m_TotalTime + millis() - m_TimeStarted)/1000);
else
return m_TotalTime;
return m_TotalTime/1000;
}
2 changes: 2 additions & 0 deletions UW2FTimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ class UW2FTimer
void Start();
void Stop();
void Reset();
void RestorePreviousState(){m_TotalTime = m_TotalTime_backup;};
long GetIntermediateTime();


protected:

private:
long m_TotalTime =0;
long m_TotalTime_backup =0;
long m_TimeStarted =0;
long m_TimeStopped =0;
bool m_IsRunning = false;
Expand Down
11 changes: 7 additions & 4 deletions esp32-scoring-device.ino
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ void setup() {
esp_task_wdt_add(LedStripTask);
delay(100);
MyStatemachine.ResetAll();

MyStatemachine.StateChanged(EVENT_WEAPON | WEAPON_MASK_EPEE);
}


Expand All @@ -256,9 +256,12 @@ void loop() {
delay(1);
MyTimeScoreDisplay.ProcessEvents();
delay(1);
MyTimeScoreDisplay.CycleScoreMatchAndTimeWhenNotFighting();
delay(1);
MyLedStrip.AnimatePrio();
if(MyStatemachine.IsConnectedToRemote())
{
MyTimeScoreDisplay.CycleScoreMatchAndTimeWhenNotFighting();
delay(1);
MyLedStrip.AnimatePrio();
}
esp_task_wdt_reset();

}

0 comments on commit ed413ff

Please sign in to comment.