Skip to content
This repository was archived by the owner on May 3, 2026. It is now read-only.

Commit 3fd4a54

Browse files
committed
use vexcode-style competition callbacks
1 parent 7499f08 commit 3fd4a54

11 files changed

Lines changed: 224 additions & 648 deletions

File tree

include/api.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,9 @@
3939
#include <unistd.h>
4040
#endif /* __cplusplus */
4141

42-
#include "pros/misc.h"
4342
#include "pros/rtos.h"
4443

4544
#ifdef __cplusplus
46-
#include "pros/misc.hpp"
4745
#include "pros/rtos.hpp"
4846
#endif
4947

include/pros/competition.hpp

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#pragma once
2+
3+
#include <functional>
4+
5+
namespace zest::competition {
6+
/**
7+
* @brief the competition mode (disabled, driver control, autonomous)
8+
*
9+
*/
10+
enum class Mode {
11+
Disabled,
12+
DriverControl,
13+
Autonomous,
14+
};
15+
16+
/**
17+
* @brief the competition system being used
18+
*
19+
*/
20+
enum class System {
21+
FieldControl,
22+
CompetitionSwitch,
23+
None,
24+
};
25+
26+
/**
27+
* @brief Get the competition mode (disabled, driver control, autonomous)
28+
*
29+
* @return Status
30+
*/
31+
Mode get_mode();
32+
33+
/**
34+
* @brief Get the system type being used (field control, competition switch, or none)
35+
*
36+
* @return System
37+
*/
38+
System get_system();
39+
40+
/**
41+
* @brief Whether field control or a competition switch is connected
42+
*
43+
* @return true
44+
* @return false
45+
*/
46+
bool is_connected();
47+
48+
/**
49+
* @brief register the callable that will be called when the autonomous period starts.
50+
*
51+
* The callable is called whenever the competition state changes to autonomous. The task that runs
52+
* it is killed as soon as the competition state changes to driver control or disabled.
53+
*
54+
* @param callable
55+
*/
56+
void register_autonomous(std::function<void()> callable);
57+
58+
/**
59+
* @brief register the callable that will be called when the driver control period starts.
60+
*
61+
* The callable is called whenever the competition state changes to autonomous. The task that runs
62+
* it is killed as soon as the competition state changes to driver control or disabled.
63+
*
64+
* @param callable
65+
*/
66+
void register_driver_control(std::function<void()> callable);
67+
68+
/**
69+
* @brief register the callable that will be called when the disabled period starts.
70+
*
71+
* The callable is called whenever the competition state changes to autonomous. The task that
72+
* runs it is killed as soon as the competition state changes to driver control or disabled.
73+
*
74+
* @param callable
75+
*/
76+
void register_disabled(std::function<void()> callable);
77+
} // namespace zest::competition

0 commit comments

Comments
 (0)