librfn
An ad-hoc utility library
rotenc.h
Go to the documentation of this file.
1 /*
2  * rotenc.h
3  *
4  * Part of librfn (a general utility library from redfelineninja.org.uk)
5  *
6  * Copyright (C) 2016 Daniel Thompson <daniel@redfelineninja.org.uk>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License as published
10  * by the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  */
13 
14 #ifndef RF_ROTENC_H_
15 #define RF_ROTENC_H_
16 
17 #include <stdint.h>
18 
30 typedef struct rotenc {
31  uint8_t last_state;
32  uint8_t count;
33  uint16_t internal_count;
34 } rotenc_t;
35 
39 #define ROTENC_VAR_INIT { 0 }
40 
49 void rotenc_decode(rotenc_t *r, uint8_t state);
50 
51 
57 uint16_t rotenc_count14(rotenc_t *r);
58 
64 static inline uint8_t rotenc_count(rotenc_t *r)
65 {
66  return r->count;
67 }
68 
70 #endif // RF_ROTENC_H_
struct rotenc rotenc_t
Rotary encoder click counts and state tracking.
uint8_t last_state
Definition: rotenc.h:31
void rotenc_decode(rotenc_t *r, uint8_t state)
Handle a state update.
Definition: rotenc.c:16
fibre_state_t state
Definition: fibre.c:30
uint16_t internal_count
Definition: rotenc.h:33
uint16_t rotenc_count14(rotenc_t *r)
Read a 14-bit count of the current knob position.
Definition: rotenc.c:45
uint8_t count
Definition: rotenc.h:32
Rotary encoder click counts and state tracking.
Definition: rotenc.h:30