aboutsummaryrefslogtreecommitdiff
path: root/src/controller.h
blob: 4712dcc7a44bf2be1a2678cc58c3ceb3b3e59aee (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#ifndef CONTROLLER_H
#define CONTROLLER_H

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

#define CHANNEL_UNUSED 65535
#define CHANNELS 8

#define AXIS_MIN -32768
#define AXIS_MAX 32767

typedef uint16_t channel_t;

struct controller {
	void (*reset)(struct controller* cont);
	void (*axis)(struct controller* cont, int axis_id, int value);
	void (*button)(struct controller* cont, int button_id, bool down);
	channel_t channels[CHANNELS];
};

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;
}

#endif