Skip to content

Commit 0a6c0e8

Browse files
authored
♻️ User Competition Functions (#65)
2 parents a0a8e51 + b15bde0 commit 0a6c0e8

19 files changed

Lines changed: 324 additions & 908 deletions

docs/STRUCTURE.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ Looking at the file structure of a project like this can feel intimidating. This
1414
- `include/rtos` headers for the scheduler (FreeRTOS)
1515
- `include/system` headers for low-level system functionality
1616
- `include/system/dev` headers for serial I/O and file management
17-
- `include/system/user_functions` a horrifying mess that should be destroyed
1817

1918
- `scripts` contains scripts used for building ZestCode and projects that use ZestCode
2019

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: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
78+
/**
79+
* @brief initialize the competition control task
80+
*
81+
* TODO: figure out how to hide this from the user
82+
*
83+
* This function is called after `int main` is called.
84+
*/
85+
void initialize();
86+
} // namespace zest::competition

0 commit comments

Comments
 (0)