Go to the source code of this file.
◆ KEYBOARD_WITH_PRESSED
| #define KEYBOARD_WITH_PRESSED |
Enables the KEY_PRESSED Event.
◆ KEYBOARD_WITH_REPEAT
| #define KEYBOARD_WITH_REPEAT |
Enables the KEY_REPEAT Event.
◆ KEYBOARD_WITH_LONG
| #define KEYBOARD_WITH_LONG |
Enables KEY_PRESSED_LONG Event.
◆ KEYBOARD_WITH_RELEASE
| #define KEYBOARD_WITH_RELEASE |
Enables KEY_RELEASED Event.
◆ KEYBUFSIZE
The Size of the Keyboad Buffer. It can keep up to KEYBUFSIZE-1 keys pending.
◆ KEYSCANPORT
| #define KEYSCANPORT PORTB |
◆ KEYSCANDDR
◆ KEYRETPORT
◆ KEYRETPIN
◆ KEYRETDDR
◆ KEY_SCANLINES
◆ KEY_RETLINES
◆ ROTPORT
◆ ROTPIN
◆ ROTBUTTON
| #define ROTBUTTON (PIND & (1<<PIND5)) |
◆ KEY_INVALID
more than one key pressed
◆ KEY_ENTER
◆ KEY_CANCEL
◆ KEY_ROTUP
Rotary Encoder turned right.
◆ KEY_ROTDOWN
Rotary Encoder turned left.
◆ KEY_NONE
No Key pressed. Due to the nature of scanKeyboard(), this value has to be >3.
◆ KEY_CHAR_t
◆ PutCharReturn_t
| Enumerator |
|---|
| PUTKEY_DONE | The return value of Putkey() if the Key has been successfully placed in the Keyboard Queue.
|
| PUTKEY_ERROR_BUFFER_FULL | The return value of PutKey() if no space available. The Character has been discarded.
|
| PUTKEY_ERROR_KEYBOARD_LOCKED | The return value of PutKey() if the Keyboard is locked. The Character has been discarded.
|
◆ GetKey()
Gets the next key from the keyboard buffer.
- Returns
- The key
If the keyboard buffer is empty the function returns KEY_NONE. Be sure to define KEY_NONE to a value not included in your decode matrix!
- Note
- You can test the keyboard buffer with keyStat() wich will return true if keystrokes are pending without actually calling GetKey().
◆ keyStat()
| static bool keyStat |
( |
void |
| ) |
|
|
inlinestatic |
Returns True if Keystrokes are pending.
- Returns
- False if Keyboard Buffer is empty, True if not.
◆ InitKeyboard()
| static void InitKeyboard |
( |
| ) |
|
|
inlinestatic |
Initializes the keyboard.
Must be called once on startup
◆ PutKey()
Puts a key into the keyboard buffer.
- Parameters
-
- Returns
- PUTKEY_DONE on success, PUTKEY_ERROR_BUFFER_FULL if the character has been discarded due to buffer full, PUTKEY_ERROR_KEYBOARD_LOCKED if keyboard is locked.
If the buffer is full or the keyboard is locked, the character is discarded. Check the return value of PutKey() if desirable.
You can call this routine from anywhere in your program to simulate keyboard events but be aware of the keyboard buffer length. It is good policy to honor the return value to make sure the key has actually been placed in the queue.
◆ scanRotaryEncoder()
| static void scanRotaryEncoder |
( |
void |
| ) |
|
|
inlinestatic |
Scans the rotary encoder.
This routine is declared inline since it is only used once in your project inside the timer interrupt.
It is kept separate from scanKeyboard so you can call it asynchronously, let's say every 5ms you call scanRotaryEncoder and every other 5ms you call scanKeyboard to minimize the timer interrupt load. But both functions have to be called at frequent intervals!
◆ scanKeyboard()
| static void scanKeyboard |
( |
| ) |
|
|
inlinestatic |
Reads the Return Lines and sets the next Scan Line active.
This routine is declared inline since it is only used once in your project inside the timer interrupt.
If a key is newly pressed its code is placed into the keyboard buffer. The scan counter is advanced to the next scan line and the next scan line is set active. So, even with week pull-ups the return lines will stabilize until the next call. Must be called from 10ms-timer interrupt.
◆ KEY_REPEAT_DELAY
| const uint8_t KEY_REPEAT_DELAY =60 |
|
static |
◆ KEY_REPEAT_RATE
| const uint8_t KEY_REPEAT_RATE =5 |
|
static |
◆ KEY_ACTION_MASK
| const uint8_t KEY_ACTION_MASK =0xc0 |
|
static |
The upper two Bits of a Key are Flags.
◆ KEY_PRESSED
| const uint8_t KEY_PRESSED =0 |
|
static |
The Key has just been pressed.
◆ KEY_REPEAT
| const uint8_t KEY_REPEAT =0x40 |
|
static |
The Key is repeated due to long press time.
◆ KEY_PRESSED_LONG
| const uint8_t KEY_PRESSED_LONG =0x80 |
|
static |
The Key is pressed for at least KEY_REPEAT_DELAY.
◆ KEY_RELEASED
| const uint8_t KEY_RELEASED =0xc0 |
|
static |
The Key has just been released.
◆ keyPressed
| volatile unsigned char keyPressed |
Contains the key pressed. Set it to KEY_NONE after usage.
Normally, the getKey-function should be used. This variable has been introduced to wait for keys although the keyboard is locked. When locked, keys will not be written into the keyboard buffer but keyPressed is set to the value of the key.
◆ keyboardLocked
| volatile uint8_t keyboardLocked |
Lock status of the keyboard.
If !=0, keys and encoder actions are no longer placed into the keyboard buffer. Alternatively, the keyPressed- variable is set to allow a "wait-for-any-key".
This is used when running test programs to avoid user interference. The keyboard can be locked by USB-commands to prevent user actions to interfere with program activity.
◆ bufReadPtr
Read Pointer Index of the keyboard buffer. The buffer is defined to be empty if Read PTR == Write PTR.
◆ bufWritePtr
Write Pointer Index of the keyboard buffer. The buffer is defined to be empty if Read PTR == Write PTR.
◆ keynum
Scancode of a key (0..11 or 255)
◆ rot
Current value of the rotary encoder (0..3)
◆ lastRot
Last value of the rotary encoder (0..3)
◆ rotButton
Current value of the rotary encoder pushbutton (0 or 1)
◆ lastRotButton
Last value of the rotary encoder pushbutton (0 or 1)
◆ rotMatrix
Initial value:= {
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0 }
#define KEY_ROTDOWN
Rotary Encoder turned left.
Definition: keyboard.h:45
#define KEY_ROTUP
Rotary Encoder turned right.
Definition: keyboard.h:44
Matrix for decoding the rotary encoder.
The index is (lastRot<<2 | rot). A 0 means no (valid) transition.
◆ scancnt
Counter for current scan line.
◆ keyTimer
Starts counting at 0 as soon as a Key is pressed. Topped at KEY_REPEAT_DELAY.
◆ decodeMatrix
| const char decodeMatrix[] |
◆ repeatRateCnt
Counts as long as a Key is pressed from 0 to KEY_REPEAT_RATE and issues the key again on overflow.