Updates to wire up 5 way switch to gui slice UI on config screen

This commit is contained in:
KemoNine 2020-09-11 00:35:56 -04:00
parent 3479fec85d
commit aabfb0bd6b

View file

@ -58,6 +58,7 @@ BBQ10Keyboard keyboard;
#define KBD_SW_LF 0x03
#define KBD_SW_RT 0x04
#define KBD_SW_OK 0x05
CircularBuffer<int16_t,8> uiKeyBuffer;
// Upstream keyboard definitions that will be really important later
#define _REG_CFG 2
@ -92,6 +93,10 @@ gslc_tsElemRef* m_pElemStatusText = NULL;
gslc_tsElemRef* m_pElemText = NULL;
//<Save_References !End!>
// Keyboard map related
#define MAX_INPUT_MAP 5
gslc_tsInputMap m_asInputMap[MAX_INPUT_MAP];
// Define debug message function
static int16_t DebugOut(char ch) { if (ch == (char)'\n') Serial.println(""); else Serial.write(ch); return 0; }
@ -115,10 +120,30 @@ static int16_t DebugOut(char ch) { if (ch == (char)'\n') Serial.println(""); els
//<Tick Callback !Start!>
//<Tick Callback !End!>
// Keyboard Input polling callback function
bool CbKbdPoll(void* pvGui, int16_t* pnPinInd, int16_t* pnPinVal) {
// Check for new keyboard events just in case
handlerKeyboard();
// If the key buffer is empty no events to process
if (uiKeyBuffer.isEmpty()) {
return false;
}
// Process a key that's on the key buffer for the UI event(s)
*pnPinInd = uiKeyBuffer.pop();
*pnPinVal = 1;
return true;
}
void setup() {
Serial.begin(115200);
// GUI Slice debugging
gslc_InitDebug(&DebugOut);
// Setup red LED to indicate device is on (in case we disable NeoPixel battery level later)
pinMode(3, OUTPUT);
digitalWrite(3, HIGH);
@ -145,12 +170,21 @@ void setup() {
Wire.begin();
keyboard.begin();
keyboard.writeRegister(_REG_CFG, CFG_OVERFLOW_INT | CFG_KEY_INT | CFG_USE_MODS | CFG_REPORT_MODS);
keyboard.setBacklight(0.5f);
// GUI Slice (TFT is setup through GUI Slice)
gslc_InitDebug(&DebugOut);
// Init GUI Slicle
InitGUIslice_gen();
// Set the pin poll callback function
gslc_SetPinPollFunc(&m_gui, CbKbdPoll);
// Create the GUI input mapping (pin event to GUI action)
gslc_InitInputMap(&m_gui, m_asInputMap, MAX_INPUT_MAP);
gslc_InputMapAdd(&m_gui, GSLC_INPUT_PIN_ASSERT, KBD_SW_UP, GSLC_ACTION_FOCUS_NEXT, 0);
gslc_InputMapAdd(&m_gui, GSLC_INPUT_PIN_ASSERT, KBD_SW_DN, GSLC_ACTION_FOCUS_PREV, 0);
gslc_InputMapAdd(&m_gui, GSLC_INPUT_PIN_ASSERT, KBD_SW_LF, GSLC_ACTION_FOCUS_NEXT, 0);
gslc_InputMapAdd(&m_gui, GSLC_INPUT_PIN_ASSERT, KBD_SW_RT, GSLC_ACTION_FOCUS_PREV, 0);
gslc_InputMapAdd(&m_gui, GSLC_INPUT_PIN_ASSERT, KBD_SW_OK, GSLC_ACTION_SELECT, 0);
}
// -----------------------------------
@ -170,6 +204,7 @@ void loop() {
if (textChanged) {
processRingBuffer();
}
gslc_Update(&m_gui);
}
@ -195,17 +230,26 @@ void handlerKeyboard() {
// Get keyboard event
const BBQ10Keyboard::KeyEvent key = keyboard.keyEvent();
// Add key code to display ring buffer *if* it's pressed ; no need for other events presently
// Process key press events
if (key.state == BBQ10Keyboard::StatePress) {
if (gslc_GetPageCur(&m_gui) == E_PG_MAIN) {
// Flip to config UI if the right most button is pressed when on home screen
if (gslc_GetPageCur(&m_gui) == E_PG_MAIN && key.key == KBD_BTN_4) {
gslc_SetPageCur(&m_gui,E_CONF_RPI);
}
else {
// Flip to main screen if the right most button is pressed when in config UI
else if (gslc_GetPageCur(&m_gui) == E_CONF_RPI && key.key == KBD_BTN_4) {
gslc_SetPageCur(&m_gui,E_PG_MAIN);
}
// Add keys to the key buffer that are mapped to UI functions (only for config screens)
else if (key.key == KBD_SW_UP
|| key.key == KBD_SW_DN
|| key.key == KBD_SW_LF
|| key.key == KBD_SW_RT
|| key.key == KBD_SW_OK) {
uiKeyBuffer.push(key.key);
}
// Process keys 'normally'
else {
char output[28];
snprintf(output, 28, "key: '%c' (dec %d, hex %02x)", key.key, key.key, key.key);
textChanged = true;
@ -216,7 +260,7 @@ void handlerKeyboard() {
}
else if (toPush == '\0') {
textBuffer.push('\n');
break;
}
}
}
}