~ruther/CTU-FEE-B0B35APO-Semestral-project

ref: e2a97607349d7348b7c5ff38944c8c1d642ddf0f CTU-FEE-B0B35APO-Semestral-project/image-viewer/include/input.h -rw-r--r-- 1.1 KiB
e2a97607 — František Boháček feat: add image region move 3 years ago
                                                                                
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <stdint.h>
#include <stdbool.h>
#include <time.h>

#define ROTATION_ENCODERS_COUNT 3

typedef void (*command_fun)(void *state, int delta);

typedef enum {
  IN_KEYBOARD,
  IN_ENCODER_ROTATE,
  IN_ENCODER_CLICK,
} input_type_t;

typedef struct {
  input_type_t type;
  char filter;
} input_t;

typedef struct {
  uint8_t absolute;
  int8_t delta;

  bool button;
  bool button_prev;

  time_t pressed_time;
} rotation_encoder_state_t;

typedef struct {
  void* base_address;
  rotation_encoder_state_t encoders_state[ROTATION_ENCODERS_COUNT];
} rotation_encoders_t;

typedef struct {
  command_fun cmd;
  input_t input;
  void *state;
} command_t;

typedef struct {
  command_t *commands;
  uint8_t count;
  uint8_t size;

  rotation_encoders_t encoders;
} commands_t;

commands_t commands_create(command_t *array, uint8_t size,
                           void *reg_knobs_base);

bool commands_register(commands_t *commands, input_type_t type,
                       char filter, command_fun fun, void *state);

bool commands_unregister(commands_t *commands, command_t *command);

short commands_check_input(commands_t *commands);
Do not follow this link