diff options
author | Jakob Odersky <jodersky@gmail.com> | 2014-10-28 16:53:12 +0100 |
---|---|---|
committer | Jakob Odersky <jodersky@gmail.com> | 2014-10-28 16:53:41 +0100 |
commit | fe210f522d7a7e69419fb1a9ffdb946455fc7bc3 (patch) | |
tree | 659f9d72e31ceb765e6fdab59775d30614e53e15 /include/controller.h | |
parent | fa91766c740a238d17b9cd556b34c8ee054486cb (diff) | |
download | maverick-fe210f522d7a7e69419fb1a9ffdb946455fc7bc3.tar.gz maverick-fe210f522d7a7e69419fb1a9ffdb946455fc7bc3.tar.bz2 maverick-fe210f522d7a7e69419fb1a9ffdb946455fc7bc3.zip |
use mavlink
Diffstat (limited to 'include/controller.h')
-rw-r--r-- | include/controller.h | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/include/controller.h b/include/controller.h new file mode 100644 index 0000000..a74d035 --- /dev/null +++ b/include/controller.h @@ -0,0 +1,38 @@ +#ifndef CONTROLLER_H +#define CONTROLLER_H + +#include <stdbool.h> +#include <stddef.h> +#include <stdint.h> + +#define AXIS_MIN -32768 +#define AXIS_MAX 32767 + +#define CHANNEL_UNUSED 65535 +#define CHANNELS 8 + +typedef uint16_t channel_t; + +inline channel_t channel_clamp(channel_t channel, channel_t min, channel_t max) { + channel_t upper = (channel < max) ? channel : max; + return (min < upper) ? upper : min; +} + +inline void channel_step(channel_t* channels, size_t channel_index, char step, channel_t min, channel_t max) { + int current = (int) channels[channel_index]; + int next = current + step; + if (next > (int) max) { + next = max; + } + if (next < (int) min) { + next = min; + } + channels[channel_index] = (channel_t) next; +} + +void channel_reset(channel_t* channels); +void event_axis(channel_t* channels, int axis, int value); +void event_button(channel_t* channels, int button, bool value); + + +#endif
\ No newline at end of file |