Skip to content

Commit 723e294

Browse files
author
Gin
committed
m
1 parent 3338ca1 commit 723e294

File tree

2 files changed

+41
-16
lines changed

2 files changed

+41
-16
lines changed

CodingAgentContext/AutomationProgramPatterns.md

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,22 +78,6 @@ send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH);
7878
send_program_fatal_error_notification(env, NOTIFICATION_ERROR_FATAL, "Error message");
7979
```
8080

81-
## Error Handling
82-
83-
### Standard Pattern
84-
```cpp
85-
try{
86-
// Main program logic
87-
send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH);
88-
}catch(ProgramFinishedException&){
89-
send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH);
90-
throw;
91-
}catch(std::exception& e){
92-
send_program_fatal_error_notification(env, NOTIFICATION_ERROR_FATAL, e.what());
93-
throw;
94-
}
95-
```
96-
9781
## Controller Input
9882

9983
### Button Presses
@@ -108,6 +92,45 @@ context.wait_for_all_requests(); // wait for button to finish execution
10892
context.wait_for(std::chrono::milliseconds(1000));
10993
```
11094

95+
## Main Program Function Pattern
96+
97+
### Simplest Program
98+
```cpp
99+
void ProgramName::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
100+
// button presses and inference routines
101+
}
102+
```
103+
104+
## Looping Program with Ability to Recover from Minor Error
105+
106+
```cpp
107+
while(true){
108+
try{
109+
// Initialization logic
110+
111+
env.update_stats();
112+
send_program_status_notification(env, NOTIFICATION_STATUS_UPDATE);
113+
114+
// Main program logic
115+
116+
send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH);
117+
}catch(ProgramFinishedException&){ // an exception indicating the program has finished
118+
env.update_stats();
119+
send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH);
120+
throw;
121+
}catch(ScreenshotException& e){ // an exception indicating an error somewhere in the loop
122+
if(...){ // if we can recover from it
123+
// execute recover logic (usually is restarting the game)
124+
continue;
125+
}
126+
// we cannot recover from the exception. Throw the exception to the higher level to
127+
// trigger fatal error noticiation and cleanup.
128+
throw;
129+
}
130+
}
131+
```
132+
133+
111134
## Program Registration
112135

113136
### In GameName_Panels.cpp

SerialPrograms/Source/CommonFramework/Exceptions/ScreenshotException.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ enum class ErrorReport{
2626
};
2727

2828

29+
// Base class for program exception holding a screenshot.
30+
//
2931
// Do not use this class directly. It is just to reuse the screenshot holding
3032
// logic that's shared by multiple exception types.
3133
class ScreenshotException : public Exception{

0 commit comments

Comments
 (0)