add Key_LayeredKeysBase and Key_LayeredKeys1
This commit is contained in:
parent
f62d956918
commit
04e2752b0b
@ -53,7 +53,10 @@ Keybrd library class inheritance diagram
|
|||||||
Key
|
Key
|
||||||
|____
|
|____
|
||||||
| \
|
| \
|
||||||
| Key_LayeredKeys
|
| Key_LayeredKeysBase
|
||||||
|
| \____________________
|
||||||
|
| / \
|
||||||
|
| Key_LayeredKeys Key_LayeredKeys1
|
||||||
|
|
|
|
||||||
|___________________________
|
|___________________________
|
||||||
| \ \
|
| \ \
|
||||||
|
@ -1,13 +1,6 @@
|
|||||||
#include "Key_LayeredKeys.h"
|
#include "Key_LayeredKeys.h"
|
||||||
|
|
||||||
void Key_LayeredKeys::press()
|
uint8_t Key_LayeredKeys::getActiveLayer()
|
||||||
{
|
{
|
||||||
layerId = refLayerState.getActiveLayer();
|
return refLayerState.getActiveLayer();
|
||||||
|
|
||||||
ptrsKeys[layerId]->press();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Key_LayeredKeys::release()
|
|
||||||
{
|
|
||||||
ptrsKeys[layerId]->release();
|
|
||||||
}
|
}
|
||||||
|
@ -4,22 +4,16 @@
|
|||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <LayerStateInterface.h>
|
#include <LayerStateInterface.h>
|
||||||
#include <Key.h>
|
#include <Key.h>
|
||||||
|
#include <Key_LayeredKeysBase.h>
|
||||||
|
|
||||||
/* Class Key_LayeredKeys contains an array of Key pointers, one pointer per layer.
|
/* Most of the Key_LayeredKeys functionality is in Key_LayeredKeysBase.
|
||||||
Codes are a kind of Key, so the Key pointers can point to Codes or Keys.
|
|
||||||
|
|
||||||
When the key is pressed, active layerId is retreived from refLayerState and
|
|
||||||
the Key object of the active layerId is called.
|
|
||||||
*/
|
*/
|
||||||
class Key_LayeredKeys : public Key
|
class Key_LayeredKeys : public Key_LayeredKeysBase
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
Key*const *const ptrsKeys; //array of Key pointers, one Key per layer
|
|
||||||
uint8_t layerId; //active layer when key was pressed
|
|
||||||
static LayerStateInterface& refLayerState;
|
static LayerStateInterface& refLayerState;
|
||||||
public:
|
public:
|
||||||
Key_LayeredKeys(Key* const ptrsKeys[]): ptrsKeys(ptrsKeys) {}
|
Key_LayeredKeys(Key* const ptrsKeys[]) : Key_LayeredKeysBase(ptrsKeys) {}
|
||||||
virtual void press();
|
virtual uint8_t getActiveLayer(); //get active layer from refLayerState
|
||||||
virtual void release();
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
6
src/Key_LayeredKeys1.cpp
Normal file
6
src/Key_LayeredKeys1.cpp
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include "Key_LayeredKeys1.h"
|
||||||
|
|
||||||
|
uint8_t Key_LayeredKeys1::getActiveLayer()
|
||||||
|
{
|
||||||
|
return refLayerState.getActiveLayer();
|
||||||
|
}
|
21
src/Key_LayeredKeys1.h
Normal file
21
src/Key_LayeredKeys1.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#ifndef KEY_LAYEREDKEYS1_H
|
||||||
|
#define KEY_LAYEREDKEYS1_H
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <LayerStateInterface.h>
|
||||||
|
#include <Key.h>
|
||||||
|
#include <Key_LayeredKeysBase.h>
|
||||||
|
|
||||||
|
/* Most of the Key_LayeredKeys1 functionality is in Key_LayeredKeysBase.
|
||||||
|
Key_LayeredKeys1 is just like Key_LayeredKeys, but with a distinct refLayerState.
|
||||||
|
Key_LayeredKeys1 and Key_LayeredKeys can have different size ptrsKeys[].
|
||||||
|
*/
|
||||||
|
class Key_LayeredKeys1 : public Key_LayeredKeysBase
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
static LayerStateInterface& refLayerState;
|
||||||
|
public:
|
||||||
|
Key_LayeredKeys1(Key* const ptrsKeys[]) : Key_LayeredKeysBase(ptrsKeys) {}
|
||||||
|
virtual uint8_t getActiveLayer(); //get active layer from refLayerState
|
||||||
|
};
|
||||||
|
#endif
|
13
src/Key_LayeredKeysBase.cpp
Normal file
13
src/Key_LayeredKeysBase.cpp
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#include "Key_LayeredKeysBase.h"
|
||||||
|
|
||||||
|
void Key_LayeredKeysBase::press()
|
||||||
|
{
|
||||||
|
layerId = getActiveLayer();
|
||||||
|
|
||||||
|
ptrsKeys[layerId]->press();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Key_LayeredKeysBase::release()
|
||||||
|
{
|
||||||
|
ptrsKeys[layerId]->release();
|
||||||
|
}
|
31
src/Key_LayeredKeysBase.h
Normal file
31
src/Key_LayeredKeysBase.h
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#ifndef KEY_LAYEREDKEYSBASE_H
|
||||||
|
#define KEY_LAYEREDKEYSBASE_H
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <LayerStateInterface.h>
|
||||||
|
#include <Key.h>
|
||||||
|
|
||||||
|
/* Class Key_LayeredKeysBase contains an array of Key pointers, one pointer per layer.
|
||||||
|
Codes are a kind of Key, so the Key pointers can point to Codes or Keys.
|
||||||
|
|
||||||
|
When the key is pressed, active layerId is retreived and the Key object of that layer is called.
|
||||||
|
|
||||||
|
Design note:
|
||||||
|
Child classes (Key_LayeredKeys and Key_LayeredKeys1) have distinct static refLayerState
|
||||||
|
and different size ptrsKeys[].
|
||||||
|
That way Key_LayeredKeys instantiations don't need a LayerState argument,
|
||||||
|
which is significant for a sketch with 100 keys.
|
||||||
|
*/
|
||||||
|
class Key_LayeredKeysBase : public Key
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
Key*const *const ptrsKeys; //array of Key pointers, one Key per layer
|
||||||
|
uint8_t layerId; //active layer when key was pressed
|
||||||
|
static LayerStateInterface& refLayerState;
|
||||||
|
public:
|
||||||
|
Key_LayeredKeysBase(Key* const ptrsKeys[]): ptrsKeys(ptrsKeys) {}
|
||||||
|
virtual uint8_t getActiveLayer()=0;
|
||||||
|
virtual void press();
|
||||||
|
virtual void release();
|
||||||
|
};
|
||||||
|
#endif
|
Reference in New Issue
Block a user