CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/ArduSub/script_button.cpp
Views: 1798
1
#include "AP_Scripting/AP_Scripting_config.h"
2
3
#if AP_SCRIPTING_ENABLED
4
5
#include <limits>
6
#include "script_button.h"
7
8
void ScriptButton::press()
9
{
10
if (!pressed) {
11
pressed = true;
12
13
// The count will max out at 255, but it won't roll over to 0.
14
if (count < std::numeric_limits<uint8_t>::max()) {
15
count++;
16
}
17
}
18
}
19
20
void ScriptButton::release()
21
{
22
pressed = false;
23
}
24
25
bool ScriptButton::is_pressed() const
26
{
27
return pressed;
28
}
29
30
uint8_t ScriptButton::get_count() const
31
{
32
return count;
33
}
34
35
void ScriptButton::clear_count()
36
{
37
count = 0;
38
}
39
40
uint8_t ScriptButton::get_and_clear_count()
41
{
42
auto result = get_count();
43
clear_count();
44
return result;
45
}
46
47
#endif // AP_SCRIPTING_ENABLED
48
49