@@ -46,58 +46,37 @@ type Arena struct {
46
46
TbaClient * partner.TbaClient
47
47
StemTvClient * partner.StemTvClient
48
48
AllianceStations map [string ]* AllianceStation
49
- CurrentMatch * model. Match
49
+ ArenaNotifiers
50
50
MatchState
51
- lastMatchState MatchState
52
- MatchStartTime time.Time
53
- LastMatchTimeSec float64
54
- RedRealtimeScore * RealtimeScore
55
- BlueRealtimeScore * RealtimeScore
56
- lastDsPacketTime time.Time
57
- FieldVolunteers bool
58
- FieldReset bool
59
- AudienceDisplayScreen string
60
- SavedMatch * model.Match
61
- SavedMatchResult * model.MatchResult
62
- AllianceStationDisplays map [string ]string
63
- AllianceStationDisplayScreen string
64
- MuteMatchSounds bool
65
- matchAborted bool
66
- matchStateNotifier * Notifier
67
- MatchTimeNotifier * Notifier
68
- RobotStatusNotifier * Notifier
69
- MatchLoadTeamsNotifier * Notifier
70
- ScoringStatusNotifier * Notifier
71
- RealtimeScoreNotifier * Notifier
72
- ScorePostedNotifier * Notifier
73
- AudienceDisplayNotifier * Notifier
74
- PlaySoundNotifier * Notifier
75
- AllianceStationDisplayNotifier * Notifier
76
- AllianceSelectionNotifier * Notifier
77
- LowerThirdNotifier * Notifier
78
- ReloadDisplaysNotifier * Notifier
79
- Scale * game.Seesaw
80
- RedSwitch * game.Seesaw
81
- BlueSwitch * game.Seesaw
82
- RedVault * game.Vault
83
- BlueVault * game.Vault
84
- ScaleLeds led.Controller
85
- RedSwitchLeds led.Controller
86
- BlueSwitchLeds led.Controller
87
- RedVaultLeds vaultled.Controller
88
- BlueVaultLeds vaultled.Controller
89
- warmupLedMode led.Mode
90
- lastRedAllianceReady bool
91
- lastBlueAllianceReady bool
92
- }
93
-
94
- type ArenaStatus struct {
95
- AllianceStations map [string ]* AllianceStation
96
- MatchState
97
- CanStartMatch bool
98
- PlcIsHealthy bool
99
- FieldEstop bool
100
- GameSpecificData string
51
+ lastMatchState MatchState
52
+ CurrentMatch * model.Match
53
+ MatchStartTime time.Time
54
+ LastMatchTimeSec float64
55
+ RedRealtimeScore * RealtimeScore
56
+ BlueRealtimeScore * RealtimeScore
57
+ lastDsPacketTime time.Time
58
+ FieldVolunteers bool
59
+ FieldReset bool
60
+ AudienceDisplayMode string
61
+ SavedMatch * model.Match
62
+ SavedMatchResult * model.MatchResult
63
+ AllianceStationDisplays map [string ]string
64
+ AllianceStationDisplayMode string
65
+ MuteMatchSounds bool
66
+ matchAborted bool
67
+ Scale * game.Seesaw
68
+ RedSwitch * game.Seesaw
69
+ BlueSwitch * game.Seesaw
70
+ RedVault * game.Vault
71
+ BlueVault * game.Vault
72
+ ScaleLeds led.Controller
73
+ RedSwitchLeds led.Controller
74
+ BlueSwitchLeds led.Controller
75
+ RedVaultLeds vaultled.Controller
76
+ BlueVaultLeds vaultled.Controller
77
+ warmupLedMode led.Mode
78
+ lastRedAllianceReady bool
79
+ lastBlueAllianceReady bool
101
80
}
102
81
103
82
type AllianceStation struct {
@@ -130,32 +109,20 @@ func NewArena(dbPath string) (*Arena, error) {
130
109
arena .AllianceStations ["B2" ] = new (AllianceStation )
131
110
arena .AllianceStations ["B3" ] = new (AllianceStation )
132
111
133
- arena .matchStateNotifier = NewNotifier ()
134
- arena .MatchTimeNotifier = NewNotifier ()
135
- arena .RobotStatusNotifier = NewNotifier ()
136
- arena .MatchLoadTeamsNotifier = NewNotifier ()
137
- arena .ScoringStatusNotifier = NewNotifier ()
138
- arena .RealtimeScoreNotifier = NewNotifier ()
139
- arena .ScorePostedNotifier = NewNotifier ()
140
- arena .AudienceDisplayNotifier = NewNotifier ()
141
- arena .PlaySoundNotifier = NewNotifier ()
142
- arena .AllianceStationDisplayNotifier = NewNotifier ()
143
- arena .AllianceSelectionNotifier = NewNotifier ()
144
- arena .LowerThirdNotifier = NewNotifier ()
145
- arena .ReloadDisplaysNotifier = NewNotifier ()
112
+ arena .configureNotifiers ()
146
113
147
114
// Load empty match as current.
148
115
arena .MatchState = PreMatch
149
116
arena .LoadTestMatch ()
150
- arena .lastMatchState = - 1
151
117
arena .LastMatchTimeSec = 0
118
+ arena .lastMatchState = - 1
152
119
153
120
// Initialize display parameters.
154
- arena .AudienceDisplayScreen = "blank"
121
+ arena .AudienceDisplayMode = "blank"
155
122
arena .SavedMatch = & model.Match {}
156
123
arena .SavedMatchResult = model .NewMatchResult ()
157
124
arena .AllianceStationDisplays = make (map [string ]string )
158
- arena .AllianceStationDisplayScreen = "match"
125
+ arena .AllianceStationDisplayMode = "match"
159
126
160
127
return arena , nil
161
128
}
@@ -257,10 +224,10 @@ func (arena *Arena) LoadMatch(match *model.Match) error {
257
224
arena .BlueSwitchLeds .SetSidedness (true )
258
225
259
226
// Notify any listeners about the new match.
260
- arena .MatchLoadTeamsNotifier .Notify (nil )
261
- arena .RealtimeScoreNotifier .Notify (nil )
262
- arena .AllianceStationDisplayScreen = "match"
263
- arena .AllianceStationDisplayNotifier .Notify (nil )
227
+ arena .MatchLoadNotifier .Notify ()
228
+ arena .RealtimeScoreNotifier .Notify ()
229
+ arena .AllianceStationDisplayMode = "match"
230
+ arena .AllianceStationDisplayModeNotifier .Notify ()
264
231
265
232
// Set the initial state of the lights.
266
233
arena .ScaleLeds .SetMode (led .OffMode , led .OffMode )
@@ -325,7 +292,7 @@ func (arena *Arena) SubstituteTeam(teamId int, station string) error {
325
292
arena .CurrentMatch .Blue3 = teamId
326
293
}
327
294
arena .setupNetwork ()
328
- arena .MatchLoadTeamsNotifier .Notify (nil )
295
+ arena .MatchLoadNotifier .Notify ()
329
296
330
297
if arena .CurrentMatch .Type != "test" {
331
298
arena .Database .SaveMatch (arena .CurrentMatch )
@@ -379,12 +346,14 @@ func (arena *Arena) AbortMatch() error {
379
346
return fmt .Errorf ("Cannot abort match when it is not in progress." )
380
347
}
381
348
if ! arena .MuteMatchSounds && arena .MatchState != WarmupPeriod {
382
- arena .PlaySoundNotifier .Notify ("match-abort" )
349
+ arena .PlaySoundNotifier .NotifyWithMessage ("match-abort" )
383
350
}
384
351
arena .MatchState = PostMatch
385
352
arena .matchAborted = true
386
- arena .AudienceDisplayScreen = "blank"
387
- arena .AudienceDisplayNotifier .Notify (nil )
353
+ arena .AudienceDisplayMode = "blank"
354
+ arena .AudienceDisplayModeNotifier .Notify ()
355
+ arena .AllianceStationDisplayMode = "logo"
356
+ arena .AllianceStationDisplayModeNotifier .Notify ()
388
357
return nil
389
358
}
390
359
@@ -432,11 +401,13 @@ func (arena *Arena) Update() {
432
401
arena .LastMatchTimeSec = - 1
433
402
auto = true
434
403
enabled = false
435
- arena .AudienceDisplayScreen = "match"
436
- arena .AudienceDisplayNotifier .Notify (nil )
404
+ arena .AudienceDisplayMode = "match"
405
+ arena .AudienceDisplayModeNotifier .Notify ()
406
+ arena .AllianceStationDisplayMode = "match"
407
+ arena .AllianceStationDisplayModeNotifier .Notify ()
437
408
arena .sendGameSpecificDataPacket ()
438
409
if ! arena .MuteMatchSounds {
439
- arena .PlaySoundNotifier .Notify ("match-warmup" )
410
+ arena .PlaySoundNotifier .NotifyWithMessage ("match-warmup" )
440
411
}
441
412
// Pick an LED warmup mode at random to keep things interesting.
442
413
allWarmupModes := []led.Mode {led .WarmupMode , led .Warmup2Mode , led .Warmup3Mode , led .Warmup4Mode }
@@ -450,7 +421,7 @@ func (arena *Arena) Update() {
450
421
enabled = true
451
422
sendDsPacket = true
452
423
if ! arena .MuteMatchSounds {
453
- arena .PlaySoundNotifier .Notify ("match-start" )
424
+ arena .PlaySoundNotifier .NotifyWithMessage ("match-start" )
454
425
}
455
426
}
456
427
case AutoPeriod :
@@ -462,7 +433,7 @@ func (arena *Arena) Update() {
462
433
enabled = false
463
434
sendDsPacket = true
464
435
if ! arena .MuteMatchSounds {
465
- arena .PlaySoundNotifier .Notify ("match-end" )
436
+ arena .PlaySoundNotifier .NotifyWithMessage ("match-end" )
466
437
}
467
438
}
468
439
case PausePeriod :
@@ -475,7 +446,7 @@ func (arena *Arena) Update() {
475
446
enabled = true
476
447
sendDsPacket = true
477
448
if ! arena .MuteMatchSounds {
478
- arena .PlaySoundNotifier .Notify ("match-resume" )
449
+ arena .PlaySoundNotifier .NotifyWithMessage ("match-resume" )
479
450
}
480
451
}
481
452
case TeleopPeriod :
@@ -486,7 +457,7 @@ func (arena *Arena) Update() {
486
457
arena .MatchState = EndgamePeriod
487
458
sendDsPacket = false
488
459
if ! arena .MuteMatchSounds {
489
- arena .PlaySoundNotifier .Notify ("match-endgame" )
460
+ arena .PlaySoundNotifier .NotifyWithMessage ("match-endgame" )
490
461
}
491
462
}
492
463
case EndgamePeriod :
@@ -501,38 +472,32 @@ func (arena *Arena) Update() {
501
472
go func () {
502
473
// Leave the scores on the screen briefly at the end of the match.
503
474
time .Sleep (time .Second * matchEndScoreDwellSec )
504
- arena .AudienceDisplayScreen = "blank"
505
- arena .AudienceDisplayNotifier .Notify (nil )
506
- arena .AllianceStationDisplayScreen = "logo"
507
- arena .AllianceStationDisplayNotifier .Notify (nil )
475
+ arena .AudienceDisplayMode = "blank"
476
+ arena .AudienceDisplayModeNotifier .Notify ()
477
+ arena .AllianceStationDisplayMode = "logo"
478
+ arena .AllianceStationDisplayModeNotifier .Notify ()
508
479
}()
509
480
if ! arena .MuteMatchSounds {
510
- arena .PlaySoundNotifier .Notify ("match-end" )
481
+ arena .PlaySoundNotifier .NotifyWithMessage ("match-end" )
511
482
}
512
483
}
513
484
}
514
485
515
- // Send a notification if the match state has changed.
516
- if arena .MatchState != arena .lastMatchState {
517
- arena .matchStateNotifier .Notify (arena .MatchState )
518
- }
519
- arena .lastMatchState = arena .MatchState
520
-
521
- // Send a match tick notification if passing an integer second threshold.
522
- if int (matchTimeSec ) != int (arena .LastMatchTimeSec ) {
523
- arena .MatchTimeNotifier .Notify (int (matchTimeSec ))
486
+ // Send a match tick notification if passing an integer second threshold or if the match state changed.
487
+ if int (matchTimeSec ) != int (arena .LastMatchTimeSec ) || arena .MatchState != arena .lastMatchState {
488
+ arena .MatchTimeNotifier .Notify ()
524
489
}
525
490
arena .LastMatchTimeSec = matchTimeSec
491
+ arena .lastMatchState = arena .MatchState
526
492
527
493
// Send a packet if at a period transition point or if it's been long enough since the last one.
528
494
if sendDsPacket || time .Since (arena .lastDsPacketTime ).Seconds ()* 1000 >= dsPacketPeriodMs {
529
495
arena .sendDsPacket (auto , enabled )
530
- arena .RobotStatusNotifier .Notify (nil )
496
+ arena .ArenaStatusNotifier .Notify ()
531
497
}
532
498
533
499
// Handle field sensors/lights/motors.
534
500
arena .handlePlcInput ()
535
- arena .handlePlcOutput ()
536
501
arena .handleLeds ()
537
502
}
538
503
@@ -560,11 +525,6 @@ func (arena *Arena) BlueScoreSummary() *game.ScoreSummary {
560
525
return arena .BlueRealtimeScore .CurrentScore .Summarize (arena .RedRealtimeScore .CurrentScore .Fouls )
561
526
}
562
527
563
- func (arena * Arena ) GetStatus () * ArenaStatus {
564
- return & ArenaStatus {arena .AllianceStations , arena .MatchState , arena .checkCanStartMatch () == nil ,
565
- arena .Plc .IsHealthy , arena .Plc .GetFieldEstop (), arena .CurrentMatch .GameSpecificData }
566
- }
567
-
568
528
// Loads a team into an alliance station, cleaning up the previous team there if there is one.
569
529
func (arena * Arena ) assignTeam (teamId int , station string ) error {
570
530
// Reject invalid station values.
@@ -766,23 +726,18 @@ func (arena *Arena) handlePlcInput() {
766
726
// Check if a power up has been newly played and trigger the accompanying sound effect if so.
767
727
newRedPowerUp := arena .RedVault .CheckForNewlyPlayedPowerUp ()
768
728
if newRedPowerUp != "" && ! arena .MuteMatchSounds {
769
- arena .PlaySoundNotifier .Notify ("match-" + newRedPowerUp )
729
+ arena .PlaySoundNotifier .NotifyWithMessage ("match-" + newRedPowerUp )
770
730
}
771
731
newBluePowerUp := arena .BlueVault .CheckForNewlyPlayedPowerUp ()
772
732
if newBluePowerUp != "" && ! arena .MuteMatchSounds {
773
- arena .PlaySoundNotifier .Notify ("match-" + newBluePowerUp )
733
+ arena .PlaySoundNotifier .NotifyWithMessage ("match-" + newBluePowerUp )
774
734
}
775
735
776
736
if ! oldRedScore .Equals (redScore ) || ! oldBlueScore .Equals (blueScore ) || ownershipChanged {
777
- arena .RealtimeScoreNotifier .Notify (nil )
737
+ arena .RealtimeScoreNotifier .Notify ()
778
738
}
779
739
}
780
740
781
- // Writes light/motor commands to the field PLC.
782
- func (arena * Arena ) handlePlcOutput () {
783
- // TODO(patrick): Update for 2018.
784
- }
785
-
786
741
func (arena * Arena ) handleLeds () {
787
742
switch arena .MatchState {
788
743
case PreMatch :
0 commit comments